From: Chad Versace Date: Sat, 27 May 2017 01:48:28 +0000 (-0700) Subject: i965: Replace 0 with ISL_FORMAT_UNSUPPORTED in format table (v2) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e9f5004d5ea38a21019e0affcd63d353b98d499a;p=mesa.git i965: Replace 0 with ISL_FORMAT_UNSUPPORTED in format table (v2) When given an *unsupported* mesa_format, brw_isl_format_for_mesa_format() returned 0, a *valid* isl_format, ISL_FORMAT_R32G32B32A32_FLOAT. The problem is that brw_isl_format_for_mesa_format's inner table used 0 instead of ISL_FORMAT_UNSUPPORTED to indicate unsupported mesa formats. Some callers of brw_isl_format_for_mesa_format() were aware of this weirdness, and worked around it. This patch removes those workarounds. v2: Ensure that all array elements are initialized to ISL_FORMAT_UNSUPPORTED, even when new formats are added to enum mesa_format, by using an designated range initializer. Reviewed-by: Matt Turner --- diff --git a/src/mesa/drivers/dri/i965/brw_surface_formats.c b/src/mesa/drivers/dri/i965/brw_surface_formats.c index 52d3acbb377..f878317e923 100644 --- a/src/mesa/drivers/dri/i965/brw_surface_formats.c +++ b/src/mesa/drivers/dri/i965/brw_surface_formats.c @@ -36,31 +36,19 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format) * staying in sync, so we initialize to 0 even though * ISL_FORMAT_R32G32B32A32_FLOAT happens to also be 0. */ - static const uint32_t table[MESA_FORMAT_COUNT] = - { - [MESA_FORMAT_A8B8G8R8_UNORM] = 0, + static const enum isl_format table[MESA_FORMAT_COUNT] = { + [0 ... MESA_FORMAT_COUNT-1] = ISL_FORMAT_UNSUPPORTED, + [MESA_FORMAT_R8G8B8A8_UNORM] = ISL_FORMAT_R8G8B8A8_UNORM, [MESA_FORMAT_B8G8R8A8_UNORM] = ISL_FORMAT_B8G8R8A8_UNORM, - [MESA_FORMAT_A8R8G8B8_UNORM] = 0, - [MESA_FORMAT_X8B8G8R8_UNORM] = 0, [MESA_FORMAT_R8G8B8X8_UNORM] = ISL_FORMAT_R8G8B8X8_UNORM, [MESA_FORMAT_B8G8R8X8_UNORM] = ISL_FORMAT_B8G8R8X8_UNORM, - [MESA_FORMAT_X8R8G8B8_UNORM] = 0, - [MESA_FORMAT_BGR_UNORM8] = 0, [MESA_FORMAT_RGB_UNORM8] = ISL_FORMAT_R8G8B8_UNORM, [MESA_FORMAT_B5G6R5_UNORM] = ISL_FORMAT_B5G6R5_UNORM, - [MESA_FORMAT_R5G6B5_UNORM] = 0, [MESA_FORMAT_B4G4R4A4_UNORM] = ISL_FORMAT_B4G4R4A4_UNORM, - [MESA_FORMAT_A4R4G4B4_UNORM] = 0, - [MESA_FORMAT_A1B5G5R5_UNORM] = 0, [MESA_FORMAT_B5G5R5A1_UNORM] = ISL_FORMAT_B5G5R5A1_UNORM, - [MESA_FORMAT_A1R5G5B5_UNORM] = 0, - [MESA_FORMAT_L4A4_UNORM] = 0, [MESA_FORMAT_L8A8_UNORM] = ISL_FORMAT_L8A8_UNORM, - [MESA_FORMAT_A8L8_UNORM] = 0, [MESA_FORMAT_L16A16_UNORM] = ISL_FORMAT_L16A16_UNORM, - [MESA_FORMAT_A16L16_UNORM] = 0, - [MESA_FORMAT_B2G3R3_UNORM] = 0, [MESA_FORMAT_A_UNORM8] = ISL_FORMAT_A8_UNORM, [MESA_FORMAT_A_UNORM16] = ISL_FORMAT_A16_UNORM, [MESA_FORMAT_L_UNORM8] = ISL_FORMAT_L8_UNORM, @@ -71,29 +59,16 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format) [MESA_FORMAT_YCBCR] = ISL_FORMAT_YCRCB_SWAPUVY, [MESA_FORMAT_R_UNORM8] = ISL_FORMAT_R8_UNORM, [MESA_FORMAT_R8G8_UNORM] = ISL_FORMAT_R8G8_UNORM, - [MESA_FORMAT_G8R8_UNORM] = 0, [MESA_FORMAT_R_UNORM16] = ISL_FORMAT_R16_UNORM, [MESA_FORMAT_R16G16_UNORM] = ISL_FORMAT_R16G16_UNORM, - [MESA_FORMAT_G16R16_UNORM] = 0, [MESA_FORMAT_B10G10R10A2_UNORM] = ISL_FORMAT_B10G10R10A2_UNORM, - [MESA_FORMAT_S8_UINT_Z24_UNORM] = 0, - [MESA_FORMAT_Z24_UNORM_S8_UINT] = 0, - [MESA_FORMAT_Z_UNORM16] = 0, - [MESA_FORMAT_Z24_UNORM_X8_UINT] = 0, - [MESA_FORMAT_X8_UINT_Z24_UNORM] = 0, - [MESA_FORMAT_Z_UNORM32] = 0, [MESA_FORMAT_S_UINT8] = ISL_FORMAT_R8_UINT, - [MESA_FORMAT_BGR_SRGB8] = 0, - [MESA_FORMAT_A8B8G8R8_SRGB] = 0, [MESA_FORMAT_B8G8R8A8_SRGB] = ISL_FORMAT_B8G8R8A8_UNORM_SRGB, - [MESA_FORMAT_A8R8G8B8_SRGB] = 0, [MESA_FORMAT_R8G8B8A8_SRGB] = ISL_FORMAT_R8G8B8A8_UNORM_SRGB, - [MESA_FORMAT_X8R8G8B8_SRGB] = 0, [MESA_FORMAT_B8G8R8X8_SRGB] = ISL_FORMAT_B8G8R8X8_UNORM_SRGB, [MESA_FORMAT_L_SRGB8] = ISL_FORMAT_L8_UNORM_SRGB, [MESA_FORMAT_L8A8_SRGB] = ISL_FORMAT_L8A8_UNORM_SRGB, - [MESA_FORMAT_A8L8_SRGB] = 0, [MESA_FORMAT_SRGB_DXT1] = ISL_FORMAT_BC1_UNORM_SRGB, [MESA_FORMAT_SRGBA_DXT1] = ISL_FORMAT_BC1_UNORM_SRGB, [MESA_FORMAT_SRGBA_DXT3] = ISL_FORMAT_BC2_UNORM_SRGB, @@ -109,7 +84,6 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format) [MESA_FORMAT_RGBA_FLOAT32] = ISL_FORMAT_R32G32B32A32_FLOAT, [MESA_FORMAT_RGBA_FLOAT16] = ISL_FORMAT_R16G16B16A16_FLOAT, [MESA_FORMAT_RGB_FLOAT32] = ISL_FORMAT_R32G32B32_FLOAT, - [MESA_FORMAT_RGB_FLOAT16] = 0, [MESA_FORMAT_A_FLOAT32] = ISL_FORMAT_A32_FLOAT, [MESA_FORMAT_A_FLOAT16] = ISL_FORMAT_A16_FLOAT, [MESA_FORMAT_L_FLOAT32] = ISL_FORMAT_L32_FLOAT, @@ -123,34 +97,6 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format) [MESA_FORMAT_RG_FLOAT32] = ISL_FORMAT_R32G32_FLOAT, [MESA_FORMAT_RG_FLOAT16] = ISL_FORMAT_R16G16_FLOAT, - [MESA_FORMAT_A_UINT8] = 0, - [MESA_FORMAT_A_UINT16] = 0, - [MESA_FORMAT_A_UINT32] = 0, - [MESA_FORMAT_A_SINT8] = 0, - [MESA_FORMAT_A_SINT16] = 0, - [MESA_FORMAT_A_SINT32] = 0, - - [MESA_FORMAT_I_UINT8] = 0, - [MESA_FORMAT_I_UINT16] = 0, - [MESA_FORMAT_I_UINT32] = 0, - [MESA_FORMAT_I_SINT8] = 0, - [MESA_FORMAT_I_SINT16] = 0, - [MESA_FORMAT_I_SINT32] = 0, - - [MESA_FORMAT_L_UINT8] = 0, - [MESA_FORMAT_L_UINT16] = 0, - [MESA_FORMAT_L_UINT32] = 0, - [MESA_FORMAT_L_SINT8] = 0, - [MESA_FORMAT_L_SINT16] = 0, - [MESA_FORMAT_L_SINT32] = 0, - - [MESA_FORMAT_LA_UINT8] = 0, - [MESA_FORMAT_LA_UINT16] = 0, - [MESA_FORMAT_LA_UINT32] = 0, - [MESA_FORMAT_LA_SINT8] = 0, - [MESA_FORMAT_LA_SINT16] = 0, - [MESA_FORMAT_LA_SINT32] = 0, - [MESA_FORMAT_R_SINT8] = ISL_FORMAT_R8_SINT, [MESA_FORMAT_RG_SINT8] = ISL_FORMAT_R8G8_SINT, [MESA_FORMAT_RGB_SINT8] = ISL_FORMAT_R8G8B8_SINT, @@ -179,8 +125,6 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format) [MESA_FORMAT_R_SNORM8] = ISL_FORMAT_R8_SNORM, [MESA_FORMAT_R8G8_SNORM] = ISL_FORMAT_R8G8_SNORM, - [MESA_FORMAT_X8B8G8R8_SNORM] = 0, - [MESA_FORMAT_A8B8G8R8_SNORM] = 0, [MESA_FORMAT_R8G8B8A8_SNORM] = ISL_FORMAT_R8G8B8A8_SNORM, [MESA_FORMAT_R_SNORM16] = ISL_FORMAT_R16_SNORM, [MESA_FORMAT_R16G16_SNORM] = ISL_FORMAT_R16G16_SNORM, @@ -193,11 +137,6 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format) [MESA_FORMAT_RG_RGTC2_UNORM] = ISL_FORMAT_BC5_UNORM, [MESA_FORMAT_RG_RGTC2_SNORM] = ISL_FORMAT_BC5_SNORM, - [MESA_FORMAT_L_LATC1_UNORM] = 0, - [MESA_FORMAT_L_LATC1_SNORM] = 0, - [MESA_FORMAT_LA_LATC2_UNORM] = 0, - [MESA_FORMAT_LA_LATC2_SNORM] = 0, - [MESA_FORMAT_ETC1_RGB8] = ISL_FORMAT_ETC1_RGB8, [MESA_FORMAT_ETC2_RGB8] = ISL_FORMAT_ETC2_RGB8, [MESA_FORMAT_ETC2_SRGB8] = ISL_FORMAT_ETC2_SRGB8, @@ -244,43 +183,21 @@ brw_isl_format_for_mesa_format(mesa_format mesa_format) [MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10] = ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB, [MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12] = ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB, - [MESA_FORMAT_A_SNORM8] = 0, - [MESA_FORMAT_L_SNORM8] = 0, - [MESA_FORMAT_L8A8_SNORM] = 0, - [MESA_FORMAT_A8L8_SNORM] = 0, - [MESA_FORMAT_I_SNORM8] = 0, - [MESA_FORMAT_A_SNORM16] = 0, - [MESA_FORMAT_L_SNORM16] = 0, - [MESA_FORMAT_LA_SNORM16] = 0, - [MESA_FORMAT_I_SNORM16] = 0, - [MESA_FORMAT_R9G9B9E5_FLOAT] = ISL_FORMAT_R9G9B9E5_SHAREDEXP, [MESA_FORMAT_R11G11B10_FLOAT] = ISL_FORMAT_R11G11B10_FLOAT, - [MESA_FORMAT_Z_FLOAT32] = 0, - [MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = 0, - [MESA_FORMAT_R10G10B10A2_UNORM] = ISL_FORMAT_R10G10B10A2_UNORM, [MESA_FORMAT_B10G10R10A2_UINT] = ISL_FORMAT_B10G10R10A2_UINT, [MESA_FORMAT_R10G10B10A2_UINT] = ISL_FORMAT_R10G10B10A2_UINT, - [MESA_FORMAT_B4G4R4X4_UNORM] = 0, [MESA_FORMAT_B5G5R5X1_UNORM] = ISL_FORMAT_B5G5R5X1_UNORM, - [MESA_FORMAT_R8G8B8X8_SNORM] = 0, [MESA_FORMAT_R8G8B8X8_SRGB] = ISL_FORMAT_R8G8B8X8_UNORM_SRGB, - [MESA_FORMAT_X8B8G8R8_SRGB] = 0, - [MESA_FORMAT_RGBX_UINT8] = 0, - [MESA_FORMAT_RGBX_SINT8] = 0, [MESA_FORMAT_B10G10R10X2_UNORM] = ISL_FORMAT_B10G10R10X2_UNORM, [MESA_FORMAT_RGBX_UNORM16] = ISL_FORMAT_R16G16B16X16_UNORM, - [MESA_FORMAT_RGBX_SNORM16] = 0, [MESA_FORMAT_RGBX_FLOAT16] = ISL_FORMAT_R16G16B16X16_FLOAT, - [MESA_FORMAT_RGBX_UINT16] = 0, - [MESA_FORMAT_RGBX_SINT16] = 0, [MESA_FORMAT_RGBX_FLOAT32] = ISL_FORMAT_R32G32B32X32_FLOAT, - [MESA_FORMAT_RGBX_UINT32] = 0, - [MESA_FORMAT_RGBX_SINT32] = 0, }; + assert(mesa_format < MESA_FORMAT_COUNT); return table[mesa_format]; } @@ -305,10 +222,7 @@ brw_init_surface_formats(struct brw_context *brw) render = texture = brw_isl_format_for_mesa_format(format); - /* The value of ISL_FORMAT_R32G32B32A32_FLOAT is 0, so don't skip - * it. - */ - if (texture == 0 && format != MESA_FORMAT_RGBA_FLOAT32) + if (texture == ISL_FORMAT_UNSUPPORTED) continue; /* Don't advertise 8 and 16-bit RGB formats to core mesa. This ensures diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index e9a1c9bd709..3d54c141d0b 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -713,7 +713,7 @@ brw_update_buffer_texture_surface(struct gl_context *ctx, */ size = MIN2(size, ctx->Const.MaxTextureBufferSize * (unsigned) texel_size); - if (isl_format == 0 && format != MESA_FORMAT_RGBA_FLOAT32) { + if (isl_format == ISL_FORMAT_UNSUPPORTED) { _mesa_problem(NULL, "bad format %s for texture buffer\n", _mesa_get_format_name(format)); }