From e002f5a086c7fc8314d3c28a603875f5ec5e5cef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Fri, 28 May 2021 15:22:03 -0400 Subject: [PATCH] gallium: change pipe_vertex_element::src_format to uint8_t This removes the bitfield packing/unpacking. pipe_format entries are reordered to have vertex formats first because vertex formats must be <= 255. Reviewed-by: Alyssa Rosenzweig Part-of: --- src/gallium/drivers/d3d12/d3d12_context.cpp | 6 +- src/gallium/drivers/swr/swr_state.cpp | 6 +- src/gallium/include/pipe/p_format.h | 135 ++++++++++++++-------------- src/gallium/include/pipe/p_state.h | 9 +- src/mesa/main/varray.c | 2 + 5 files changed, 82 insertions(+), 76 deletions(-) diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp index 8661b28..6167f9b 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.cpp +++ b/src/gallium/drivers/d3d12/d3d12_context.cpp @@ -102,10 +102,12 @@ d3d12_create_vertex_elements_state(struct pipe_context *pctx, cso->elements[i].SemanticName = "TEXCOORD"; cso->elements[i].SemanticIndex = i; - enum pipe_format format_helper = d3d12_emulated_vtx_format(elements[i].src_format); + enum pipe_format format_helper = + d3d12_emulated_vtx_format((enum pipe_format)elements[i].src_format); bool needs_emulation = format_helper != elements[i].src_format; cso->needs_format_emulation |= needs_emulation; - cso->format_conversion[i] = needs_emulation ? elements[i].src_format : PIPE_FORMAT_NONE; + cso->format_conversion[i] = + needs_emulation ? (enum pipe_format)elements[i].src_format : PIPE_FORMAT_NONE; cso->elements[i].Format = d3d12_get_format(format_helper); assert(cso->elements[i].Format != DXGI_FORMAT_UNKNOWN); diff --git a/src/gallium/drivers/swr/swr_state.cpp b/src/gallium/drivers/swr/swr_state.cpp index bea1c1e..6a56e22 100644 --- a/src/gallium/drivers/swr/swr_state.cpp +++ b/src/gallium/drivers/swr/swr_state.cpp @@ -596,11 +596,11 @@ swr_create_vertex_elements_state(struct pipe_context *pipe, // XXX: we should do this keyed on the VS usage info const struct util_format_description *desc = - util_format_description(attribs[i].src_format); + util_format_description((enum pipe_format)attribs[i].src_format); velems->fsState.layout[i].AlignedByteOffset = attribs[i].src_offset; velems->fsState.layout[i].Format = - mesa_to_swr_format(attribs[i].src_format); + mesa_to_swr_format((enum pipe_format)attribs[i].src_format); velems->fsState.layout[i].StreamIndex = attribs[i].vertex_buffer_index; velems->fsState.layout[i].InstanceEnable = @@ -627,7 +627,7 @@ swr_create_vertex_elements_state(struct pipe_context *pipe, /* Calculate the pitch of each stream */ const SWR_FORMAT_INFO &swr_desc = GetFormatInfo( - mesa_to_swr_format(attribs[i].src_format)); + mesa_to_swr_format((enum pipe_format)attribs[i].src_format)); velems->stream_pitch[attribs[i].vertex_buffer_index] += swr_desc.Bpp; if (attribs[i].instance_divisor != 0) { diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h index 0c93d7d..f2d4be7 100644 --- a/src/gallium/include/pipe/p_format.h +++ b/src/gallium/include/pipe/p_format.h @@ -40,32 +40,7 @@ extern "C" { */ enum pipe_format { PIPE_FORMAT_NONE, - PIPE_FORMAT_B8G8R8A8_UNORM, - PIPE_FORMAT_B8G8R8X8_UNORM, - PIPE_FORMAT_A8R8G8B8_UNORM, - PIPE_FORMAT_X8R8G8B8_UNORM, - PIPE_FORMAT_B5G5R5A1_UNORM, - PIPE_FORMAT_R4G4B4A4_UNORM, - PIPE_FORMAT_B4G4R4A4_UNORM, - PIPE_FORMAT_R5G6B5_UNORM, - PIPE_FORMAT_B5G6R5_UNORM, - PIPE_FORMAT_R10G10B10A2_UNORM, - PIPE_FORMAT_L8_UNORM, /**< ubyte luminance */ - PIPE_FORMAT_A8_UNORM, /**< ubyte alpha */ - PIPE_FORMAT_I8_UNORM, /**< ubyte intensity */ - PIPE_FORMAT_L8A8_UNORM, /**< ubyte alpha, luminance */ - PIPE_FORMAT_L16_UNORM, /**< ushort luminance */ - PIPE_FORMAT_UYVY, - PIPE_FORMAT_YUYV, - PIPE_FORMAT_Z16_UNORM, - PIPE_FORMAT_Z16_UNORM_S8_UINT, - PIPE_FORMAT_Z32_UNORM, - PIPE_FORMAT_Z32_FLOAT, - PIPE_FORMAT_Z24_UNORM_S8_UINT, - PIPE_FORMAT_S8_UINT_Z24_UNORM, - PIPE_FORMAT_Z24X8_UNORM, - PIPE_FORMAT_X8Z24_UNORM, - PIPE_FORMAT_S8_UINT, /**< ubyte stencil */ + /* Vertex formats must be first and must be <= 255. */ PIPE_FORMAT_R64_FLOAT, PIPE_FORMAT_R64G64_FLOAT, PIPE_FORMAT_R64G64B64_FLOAT, @@ -109,9 +84,8 @@ enum pipe_format { PIPE_FORMAT_R8_UNORM, PIPE_FORMAT_R8G8_UNORM, PIPE_FORMAT_R8G8B8_UNORM, - PIPE_FORMAT_B8G8R8_UNORM, PIPE_FORMAT_R8G8B8A8_UNORM, - PIPE_FORMAT_X8B8G8R8_UNORM, + PIPE_FORMAT_B8G8R8A8_UNORM, PIPE_FORMAT_R8_USCALED, PIPE_FORMAT_R8G8_USCALED, PIPE_FORMAT_R8G8B8_USCALED, @@ -132,6 +106,7 @@ enum pipe_format { PIPE_FORMAT_R8G8B8A8_SSCALED, PIPE_FORMAT_B8G8R8A8_SSCALED, PIPE_FORMAT_A8B8G8R8_SSCALED, + PIPE_FORMAT_A8R8G8B8_UNORM, PIPE_FORMAT_R32_FIXED, PIPE_FORMAT_R32G32_FIXED, PIPE_FORMAT_R32G32B32_FIXED, @@ -140,6 +115,70 @@ enum pipe_format { PIPE_FORMAT_R16G16_FLOAT, PIPE_FORMAT_R16G16B16_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT, + PIPE_FORMAT_R8_UINT, + PIPE_FORMAT_R8G8_UINT, + PIPE_FORMAT_R8G8B8_UINT, + PIPE_FORMAT_R8G8B8A8_UINT, + PIPE_FORMAT_R8_SINT, + PIPE_FORMAT_R8G8_SINT, + PIPE_FORMAT_R8G8B8_SINT, + PIPE_FORMAT_R8G8B8A8_SINT, + PIPE_FORMAT_R16_UINT, + PIPE_FORMAT_R16G16_UINT, + PIPE_FORMAT_R16G16B16_UINT, + PIPE_FORMAT_R16G16B16A16_UINT, + PIPE_FORMAT_R16_SINT, + PIPE_FORMAT_R16G16_SINT, + PIPE_FORMAT_R16G16B16_SINT, + PIPE_FORMAT_R16G16B16A16_SINT, + PIPE_FORMAT_R32_UINT, + PIPE_FORMAT_R32G32_UINT, + PIPE_FORMAT_R32G32B32_UINT, + PIPE_FORMAT_R32G32B32A32_UINT, + PIPE_FORMAT_R32_SINT, + PIPE_FORMAT_R32G32_SINT, + PIPE_FORMAT_R32G32B32_SINT, + PIPE_FORMAT_R32G32B32A32_SINT, + + PIPE_FORMAT_R10G10B10A2_UNORM, + PIPE_FORMAT_R10G10B10A2_SNORM, + PIPE_FORMAT_R10G10B10A2_USCALED, + PIPE_FORMAT_R10G10B10A2_SSCALED, + + PIPE_FORMAT_B10G10R10A2_UNORM, + PIPE_FORMAT_B10G10R10A2_SNORM, + PIPE_FORMAT_B10G10R10A2_USCALED, + PIPE_FORMAT_B10G10R10A2_SSCALED, + + PIPE_FORMAT_R11G11B10_FLOAT, + /* End of vertex formats. */ + + /* Texture-only formats are below. */ + PIPE_FORMAT_B8G8R8_UNORM, + PIPE_FORMAT_B8G8R8X8_UNORM, + PIPE_FORMAT_X8B8G8R8_UNORM, + PIPE_FORMAT_X8R8G8B8_UNORM, + PIPE_FORMAT_B5G5R5A1_UNORM, + PIPE_FORMAT_R4G4B4A4_UNORM, + PIPE_FORMAT_B4G4R4A4_UNORM, + PIPE_FORMAT_R5G6B5_UNORM, + PIPE_FORMAT_B5G6R5_UNORM, + PIPE_FORMAT_L8_UNORM, /**< ubyte luminance */ + PIPE_FORMAT_A8_UNORM, /**< ubyte alpha */ + PIPE_FORMAT_I8_UNORM, /**< ubyte intensity */ + PIPE_FORMAT_L8A8_UNORM, /**< ubyte alpha, luminance */ + PIPE_FORMAT_L16_UNORM, /**< ushort luminance */ + PIPE_FORMAT_UYVY, + PIPE_FORMAT_YUYV, + PIPE_FORMAT_Z16_UNORM, + PIPE_FORMAT_Z16_UNORM_S8_UINT, + PIPE_FORMAT_Z32_UNORM, + PIPE_FORMAT_Z32_FLOAT, + PIPE_FORMAT_Z24_UNORM_S8_UINT, + PIPE_FORMAT_S8_UINT_Z24_UNORM, + PIPE_FORMAT_Z24X8_UNORM, + PIPE_FORMAT_X8Z24_UNORM, + PIPE_FORMAT_S8_UINT, /**< ubyte stencil */ /* sRGB formats */ PIPE_FORMAT_L8_SRGB, @@ -184,8 +223,6 @@ enum pipe_format { /* TODO: re-order these */ PIPE_FORMAT_A8B8G8R8_UNORM, PIPE_FORMAT_B5G5R5X1_UNORM, - PIPE_FORMAT_R10G10B10A2_USCALED, - PIPE_FORMAT_R11G11B10_FLOAT, PIPE_FORMAT_R9G9B9E5_FLOAT, PIPE_FORMAT_Z32_FLOAT_S8X24_UINT, PIPE_FORMAT_R1_UNORM, @@ -194,7 +231,6 @@ enum pipe_format { PIPE_FORMAT_L4A4_UNORM, PIPE_FORMAT_A2R10G10B10_UNORM, PIPE_FORMAT_A2B10G10R10_UNORM, - PIPE_FORMAT_B10G10R10A2_UNORM, PIPE_FORMAT_R10SG10SB10SA2U_NORM, PIPE_FORMAT_R8G8Bx_SNORM, PIPE_FORMAT_R8G8B8X8_UNORM, @@ -257,43 +293,6 @@ enum pipe_format { PIPE_FORMAT_R8A8_UNORM, PIPE_FORMAT_A8R8_UNORM, - PIPE_FORMAT_R10G10B10A2_SSCALED, - PIPE_FORMAT_R10G10B10A2_SNORM, - - PIPE_FORMAT_B10G10R10A2_USCALED, - PIPE_FORMAT_B10G10R10A2_SSCALED, - PIPE_FORMAT_B10G10R10A2_SNORM, - - PIPE_FORMAT_R8_UINT, - PIPE_FORMAT_R8G8_UINT, - PIPE_FORMAT_R8G8B8_UINT, - PIPE_FORMAT_R8G8B8A8_UINT, - - PIPE_FORMAT_R8_SINT, - PIPE_FORMAT_R8G8_SINT, - PIPE_FORMAT_R8G8B8_SINT, - PIPE_FORMAT_R8G8B8A8_SINT, - - PIPE_FORMAT_R16_UINT, - PIPE_FORMAT_R16G16_UINT, - PIPE_FORMAT_R16G16B16_UINT, - PIPE_FORMAT_R16G16B16A16_UINT, - - PIPE_FORMAT_R16_SINT, - PIPE_FORMAT_R16G16_SINT, - PIPE_FORMAT_R16G16B16_SINT, - PIPE_FORMAT_R16G16B16A16_SINT, - - PIPE_FORMAT_R32_UINT, - PIPE_FORMAT_R32G32_UINT, - PIPE_FORMAT_R32G32B32_UINT, - PIPE_FORMAT_R32G32B32A32_UINT, - - PIPE_FORMAT_R32_SINT, - PIPE_FORMAT_R32G32_SINT, - PIPE_FORMAT_R32G32B32_SINT, - PIPE_FORMAT_R32G32B32A32_SINT, - PIPE_FORMAT_R64_UINT, PIPE_FORMAT_R64_SINT, diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h index 8e56f8e..788a74f 100644 --- a/src/gallium/include/pipe/p_state.h +++ b/src/gallium/include/pipe/p_state.h @@ -674,14 +674,17 @@ struct pipe_stream_output_target struct pipe_vertex_element { /** Offset of this attribute, in bytes, from the start of the vertex */ - unsigned src_offset:16; + uint16_t src_offset; /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does * this attribute live in? */ - unsigned vertex_buffer_index:5; + uint8_t vertex_buffer_index; - enum pipe_format src_format:11; + /** + * This has only 8 bits because all vertex formats should be <= 255. + */ + uint8_t src_format; /* low 8 bits of enum pipe_format. */ /** Instance data rate divisor. 0 means this is per-vertex data, * n means per-instance data used for n consecutive instances (n > 0). diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index ad34e44..50bae00 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -545,6 +545,8 @@ _mesa_set_vertex_format(struct gl_vertex_format *vertex_format, vertex_format->_PipeFormat = vertex_format_to_pipe_format(size, type, format, normalized, integer, doubles); + /* pipe_vertex_element::src_format has only 8 bits, assuming a signed enum */ + assert(vertex_format->_PipeFormat <= 255); } -- 2.7.4