freedreno: Extract common helper macros

De-duplicate some macros that had been copy/pasta'd around, etc.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17817>
This commit is contained in:
Rob Clark 2022-07-17 08:11:49 -07:00 committed by Marge Bot
parent f1503e34df
commit 8e8b7562c6
5 changed files with 66 additions and 35 deletions

View file

@ -0,0 +1,59 @@
/*
* Copyright © 2022 Google, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef FREEDRENO_COMMON_H_
#define FREEDRENO_COMMON_H_
/**
* Helper macro to get around c++ being cranky about an enum that is a bitmask
*/
#ifdef __cplusplus
#define or_mask(d, mask) \
do { \
decltype(mask) _d = (d); \
d = (decltype(mask))(_d | (mask)); \
} while (0)
#else
#define or_mask(d, mask) \
do { \
d |= (mask); \
} while (0)
#endif
/*
* swap - swap value of @a and @b
*/
#define swap(a, b) \
do { \
__typeof(a) __tmp = (a); \
(a) = (b); \
(b) = __tmp; \
} while (0)
/* for conditionally setting boolean flag(s): */
#define COND(bool, val) ((bool) ? (val) : 0)
#define BIT(bit) BITFIELD_BIT(bit)
#endif /* FREEDRENO_COMMON_H_ */

View file

@ -76,6 +76,7 @@
#include "a6xx.xml.h"
#include "fdl/freedreno_layout.h"
#include "common/freedreno_dev_info.h"
#include "common/freedreno_common.h"
#include "perfcntrs/freedreno_perfcntr.h"
#include "tu_descriptor_set.h"
@ -138,9 +139,6 @@ typedef uint32_t xcb_window_t;
#define A6XX_TEX_CONST_DWORDS 16
#define A6XX_TEX_SAMP_DWORDS 4
#define COND(bool, val) ((bool) ? (val) : 0)
#define BIT(bit) (1u << (bit))
/* Whenever we generate an error, pass it through this function. Useful for
* debugging, where we can break on it. Only call at error site, not when
* propagating errors. Might be useful to plug in a stack trace here.

View file

@ -590,19 +590,6 @@ fd_context_dirty_resource(enum fd_dirty_3d_state dirty)
FD_DIRTY_TEX | FD_DIRTY_STREAMOUT);
}
#ifdef __cplusplus
#define or_dirty(d, mask) \
do { \
decltype(mask) _d = (d); \
d = (decltype(mask))(_d | (mask)); \
} while (0)
#else
#define or_dirty(d, mask) \
do { \
d |= (mask); \
} while (0)
#endif
/* Mark specified non-shader-stage related state as dirty: */
static inline void
fd_context_dirty(struct fd_context *ctx, enum fd_dirty_3d_state dirty) assert_dt
@ -613,9 +600,9 @@ fd_context_dirty(struct fd_context *ctx, enum fd_dirty_3d_state dirty) assert_dt
ctx->gen_dirty |= ctx->gen_dirty_map[ffs(dirty) - 1];
if (fd_context_dirty_resource(dirty))
or_dirty(dirty, FD_DIRTY_RESOURCE);
or_mask(dirty, FD_DIRTY_RESOURCE);
or_dirty(ctx->dirty, dirty);
or_mask(ctx->dirty, dirty);
}
static inline void
@ -639,7 +626,7 @@ fd_context_dirty_shader(struct fd_context *ctx, enum pipe_shader_type shader,
ctx->gen_dirty |= ctx->gen_dirty_shader_map[shader][ffs(dirty) - 1];
or_dirty(ctx->dirty_shader[shader], dirty);
or_mask(ctx->dirty_shader[shader], dirty);
fd_context_dirty(ctx, map[ffs(dirty) - 1]);
}

View file

@ -244,7 +244,7 @@ fd_resource_set_usage(struct pipe_resource *prsc, enum fd_dirty_3d_state usage)
if (likely(rsc->dirty & usage))
return;
fd_resource_lock(rsc);
rsc->dirty |= usage;
or_mask(rsc->dirty, usage);
fd_resource_unlock(rsc);
}

View file

@ -27,6 +27,8 @@
#ifndef FREEDRENO_UTIL_H_
#define FREEDRENO_UTIL_H_
#include "common/freedreno_common.h"
#include "drm/freedreno_drmif.h"
#include "drm/freedreno_ringbuffer.h"
@ -225,9 +227,6 @@ fd_context_access_end(struct fd_context *ctx) release_cap(fd_context_access_cap)
{
}
/* for conditionally setting boolean flag(s): */
#define COND(bool, val) ((bool) ? (val) : 0)
#define CP_REG(reg) ((0x4 << 16) | ((unsigned int)((reg) - (0x2000))))
static inline uint32_t
@ -421,18 +420,6 @@ pack_rgba(enum pipe_format format, const float *rgba)
return uc.ui[0];
}
/*
* swap - swap value of @a and @b
*/
#define swap(a, b) \
do { \
__typeof(a) __tmp = (a); \
(a) = (b); \
(b) = __tmp; \
} while (0)
#define BIT(bit) (1u << bit)
/*
* a3xx+ helpers:
*/