[Mesa-dev] [PATCH 34/36] isl: Add enum conversions that assert on invalid enums
Jason Ekstrand
jason at jlekstrand.net
Thu Jun 30 00:37:53 UTC 2016
---
src/intel/isl/isl_surface_state.c | 124 +++++++++++++++++++++++---------------
1 file changed, 74 insertions(+), 50 deletions(-)
diff --git a/src/intel/isl/isl_surface_state.c b/src/intel/isl/isl_surface_state.c
index 1b269a3..0a2d877 100644
--- a/src/intel/isl/isl_surface_state.c
+++ b/src/intel/isl/isl_surface_state.c
@@ -41,67 +41,91 @@ __gen_combine_address(void *data, void *loc, uint64_t addr, uint32_t delta)
#define __PASTE(x, y) __PASTE2(x, y)
#define isl_genX(x) __PASTE(isl_, genX(x))
+static inline uint8_t
+isl_to_gen_halign(unsigned halign)
+{
+ switch (halign) {
#if GEN_GEN >= 8
-static const uint8_t isl_to_gen_halign[] = {
- [4] = HALIGN4,
- [8] = HALIGN8,
- [16] = HALIGN16,
-};
+ case 4: return HALIGN4;
+ case 8: return HALIGN8;
+ case 16: return HALIGN16;
#elif GEN_GEN >= 7
-static const uint8_t isl_to_gen_halign[] = {
- [4] = HALIGN_4,
- [8] = HALIGN_8,
-};
+ case 4: return HALIGN_4;
+ case 8: return HALIGN_8;
#endif
+ default:
+ unreachable("Invalid horizontal alignment");
+ }
+}
+static inline uint8_t
+isl_to_gen_valign(unsigned valign)
+{
+ switch (valign) {
#if GEN_GEN >= 8
-static const uint8_t isl_to_gen_valign[] = {
- [4] = VALIGN4,
- [8] = VALIGN8,
- [16] = VALIGN16,
-};
+ case 4: return VALIGN4;
+ case 8: return VALIGN8;
+ case 16: return VALIGN16;
#elif GEN_GEN >= 6
-static const uint8_t isl_to_gen_valign[] = {
- [2] = VALIGN_2,
- [4] = VALIGN_4,
-};
+ case 2: return VALIGN_2;
+ case 4: return VALIGN_4;
#endif
+ default:
+ unreachable("Invalid horizontal alignment");
+ }
+}
#if GEN_GEN >= 8
-static const uint8_t isl_to_gen_tiling[] = {
- [ISL_TILING_LINEAR] = LINEAR,
- [ISL_TILING_X] = XMAJOR,
- [ISL_TILING_Y0] = YMAJOR,
- [ISL_TILING_Yf] = YMAJOR,
- [ISL_TILING_Ys] = YMAJOR,
- [ISL_TILING_W] = WMAJOR,
+static inline uint8_t
+isl_to_gen_tiling(enum isl_tiling tiling)
+{
+ switch (tiling) {
+ case ISL_TILING_LINEAR: return LINEAR;
+ case ISL_TILING_X: return XMAJOR;
+ case ISL_TILING_Y0: return YMAJOR;
+ case ISL_TILING_Yf: return YMAJOR;
+ case ISL_TILING_Ys: return YMAJOR;
+ case ISL_TILING_W: return WMAJOR;
+ default:
+ unreachable("Invalid tiling");
+ }
};
#endif
#if GEN_GEN >= 7
-static const uint32_t isl_to_gen_multisample_layout[] = {
- [ISL_MSAA_LAYOUT_NONE] = MSFMT_MSS,
- [ISL_MSAA_LAYOUT_INTERLEAVED] = MSFMT_DEPTH_STENCIL,
- [ISL_MSAA_LAYOUT_ARRAY] = MSFMT_MSS,
-};
+static inline uint32_t
+isl_to_gen_msaa_layout(enum isl_msaa_layout layout)
+{
+ switch (layout) {
+ case ISL_MSAA_LAYOUT_NONE: return MSFMT_MSS;
+ case ISL_MSAA_LAYOUT_INTERLEAVED: return MSFMT_DEPTH_STENCIL;
+ case ISL_MSAA_LAYOUT_ARRAY: return MSFMT_MSS;
+ default:
+ unreachable("Invalid msaa_layout");
+ }
+}
#endif
+static inline uint32_t
+isl_to_gen_aux_usage(enum isl_aux_usage usage)
+{
+ switch (usage) {
#if GEN_GEN >= 9
-static const uint32_t isl_to_gen_aux_mode[] = {
- [ISL_AUX_USAGE_NONE] = AUX_NONE,
- [ISL_AUX_USAGE_HIZ] = AUX_HIZ,
- [ISL_AUX_USAGE_MCS] = AUX_CCS_D,
- [ISL_AUX_USAGE_CCS_D] = AUX_CCS_D,
- [ISL_AUX_USAGE_CCS_E] = AUX_CCS_E,
-};
+ case ISL_AUX_USAGE_NONE: return AUX_NONE;
+ case ISL_AUX_USAGE_HIZ: return AUX_HIZ;
+ case ISL_AUX_USAGE_MCS: return AUX_CCS_D;
+ case ISL_AUX_USAGE_CCS_D: return AUX_CCS_D;
+ case ISL_AUX_USAGE_CCS_E: return AUX_CCS_E;
#elif GEN_GEN >= 8
-static const uint32_t isl_to_gen_aux_mode[] = {
- [ISL_AUX_USAGE_NONE] = AUX_NONE,
- [ISL_AUX_USAGE_HIZ] = AUX_HIZ,
- [ISL_AUX_USAGE_MCS] = AUX_MCS,
- [ISL_AUX_USAGE_CCS_D] = AUX_MCS,
-};
+ case ISL_AUX_USAGE_NONE: return AUX_NONE;
+ case ISL_AUX_USAGE_HIZ: return AUX_HIZ;
+ case ISL_AUX_USAGE_MCS: return AUX_MCS;
+ case ISL_AUX_USAGE_CCS_D: return AUX_MCS;
#endif
+ default:
+ unreachable("Invalid aux usage");
+ }
+}
static uint8_t
get_surftype(enum isl_surf_dim dim, isl_surf_usage_flags_t usage)
@@ -334,9 +358,9 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
#if GEN_GEN >= 6
const struct isl_extent3d image_align = get_image_alignment(info->surf);
- s.SurfaceVerticalAlignment = isl_to_gen_valign[image_align.height];
+ s.SurfaceVerticalAlignment = isl_to_gen_valign(image_align.height);
#if GEN_GEN >= 7
- s.SurfaceHorizontalAlignment = isl_to_gen_halign[image_align.width];
+ s.SurfaceHorizontalAlignment = isl_to_gen_halign(image_align.width);
#endif
#endif
@@ -364,7 +388,7 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
#endif
#if GEN_GEN >= 8
- s.TileMode = isl_to_gen_tiling[info->surf->tiling];
+ s.TileMode = isl_to_gen_tiling(info->surf->tiling);
#else
s.TiledSurface = info->surf->tiling != ISL_TILING_LINEAR,
s.TileWalk = info->surf->tiling == ISL_TILING_Y0 ? TILEWALK_YMAJOR :
@@ -394,7 +418,7 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
s.NumberofMultisamples = ffs(info->surf->samples) - 1;
#if GEN_GEN >= 7
s.MultisampledSurfaceStorageFormat =
- isl_to_gen_multisample_layout[info->surf->msaa_layout];
+ isl_to_gen_msaa_layout(info->surf->msaa_layout);
#endif
#endif
@@ -460,7 +484,7 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state,
s.AuxiliarySurfacePitch = pitch_in_tiles - 1;
s.AuxiliarySurfaceQPitch = get_qpitch(info->aux_surf) >> 2;
s.AuxiliarySurfaceBaseAddress = info->aux_address;
- s.AuxiliarySurfaceMode = isl_to_gen_aux_mode[info->aux_usage];
+ s.AuxiliarySurfaceMode = isl_to_gen_aux_usage(info->aux_usage);
#else
assert(info->aux_usage == ISL_AUX_USAGE_MCS ||
info->aux_usage == ISL_AUX_USAGE_CCS_D);
@@ -549,9 +573,9 @@ isl_genX(buffer_fill_state_s)(void *state,
s.SurfaceFormat = info->format;
#if GEN_GEN >= 6
- s.SurfaceVerticalAlignment = isl_to_gen_valign[4];
+ s.SurfaceVerticalAlignment = isl_to_gen_valign(4);
#if GEN_GEN >= 7
- s.SurfaceHorizontalAlignment = isl_to_gen_halign[4];
+ s.SurfaceHorizontalAlignment = isl_to_gen_halign(4);
s.SurfaceArray = false;
#endif
#endif
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list