Mesa (main): gallium: change pipe_draw_info::mode to uint8_t on MSVC to make it 1 byte large

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Aug 24 15:23:06 UTC 2021


Module: Mesa
Branch: main
Commit: 625f00d37cd00b13adcf059ae7dbe434d54c6f41
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=625f00d37cd00b13adcf059ae7dbe434d54c6f41

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Thu Aug 19 22:51:11 2021 -0400

gallium: change pipe_draw_info::mode to uint8_t on MSVC to make it 1 byte large

needed by u_threaded_context

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12480>

---

 src/gallium/auxiliary/util/u_prim.c            |  5 +++++
 src/gallium/drivers/d3d12/d3d12_compiler.cpp   |  2 +-
 src/gallium/drivers/d3d12/d3d12_draw.cpp       | 12 ++++++------
 src/gallium/drivers/radeonsi/si_state_draw.cpp |  2 +-
 src/gallium/drivers/zink/zink_draw.cpp         |  2 +-
 src/gallium/include/pipe/p_state.h             |  8 +++++++-
 6 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_prim.c b/src/gallium/auxiliary/util/u_prim.c
index 707757eb27b..9646a639ea7 100644
--- a/src/gallium/auxiliary/util/u_prim.c
+++ b/src/gallium/auxiliary/util/u_prim.c
@@ -21,6 +21,7 @@
  */
 
 #include "u_prim.h"
+#include "pipe/p_state.h"
 
 
 /** Return string name of given primitive type */
@@ -32,6 +33,10 @@ u_prim_name(enum pipe_prim_type prim)
    STATIC_ASSERT(sizeof(enum pipe_prim_type) == 1);
 #endif
 
+   /* Draw merging in u_threaded_context requires that sizeof(mode) == 1. */
+   struct pipe_draw_info info;
+   STATIC_ASSERT(sizeof(info.mode) == 1);
+
    static const struct debug_named_value names[] = {
       DEBUG_NAMED_VALUE(PIPE_PRIM_POINTS),
       DEBUG_NAMED_VALUE(PIPE_PRIM_LINES),
diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
index 5e24fe96a16..ca3e8a9119c 100644
--- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
@@ -400,7 +400,7 @@ get_provoking_vertex(struct d3d12_selection_context *sel_ctx, bool *alternate)
       mode = (enum pipe_prim_type)last_vertex_stage->current->nir->info.gs.output_primitive;
       break;
    case PIPE_SHADER_VERTEX:
-      mode = sel_ctx->dinfo ? sel_ctx->dinfo->mode : PIPE_PRIM_TRIANGLES;
+      mode = sel_ctx->dinfo ? (enum pipe_prim_type)sel_ctx->dinfo->mode : PIPE_PRIM_TRIANGLES;
       break;
    default:
       unreachable("Tesselation shaders are not supported");
diff --git a/src/gallium/drivers/d3d12/d3d12_draw.cpp b/src/gallium/drivers/d3d12/d3d12_draw.cpp
index 1a2f0b98c44..0dcb0c51dd4 100644
--- a/src/gallium/drivers/d3d12/d3d12_draw.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_draw.cpp
@@ -461,16 +461,16 @@ d3d12_draw_vbo(struct pipe_context *pctx,
    unsigned index_offset = 0;
    enum d3d12_surface_conversion_mode conversion_modes[PIPE_MAX_COLOR_BUFS] = {};
 
-   if (!prim_supported(dinfo->mode) ||
+   if (!prim_supported((enum pipe_prim_type)dinfo->mode) ||
        dinfo->index_size == 1 ||
        (dinfo->primitive_restart && dinfo->restart_index != 0xffff &&
         dinfo->restart_index != 0xffffffff)) {
 
       if (!dinfo->primitive_restart &&
-          !u_trim_pipe_prim(dinfo->mode, (unsigned *)&draws[0].count))
+          !u_trim_pipe_prim((enum pipe_prim_type)dinfo->mode, (unsigned *)&draws[0].count))
          return;
 
-      ctx->initial_api_prim = dinfo->mode;
+      ctx->initial_api_prim = (enum pipe_prim_type)dinfo->mode;
       util_primconvert_save_rasterizer_state(ctx->primconvert, &ctx->gfx_pipeline_state.rast->base);
       util_primconvert_draw_vbo(ctx->primconvert, dinfo, drawid_offset, indirect, draws, num_draws);
       return;
@@ -497,13 +497,13 @@ d3d12_draw_vbo(struct pipe_context *pctx,
                                                  D3D12_SHADER_DIRTY_SAMPLERS;
 
    /* this should *really* be fixed at a higher level than here! */
-   enum pipe_prim_type reduced_prim = u_reduced_prim(dinfo->mode);
+   enum pipe_prim_type reduced_prim = u_reduced_prim((enum pipe_prim_type)dinfo->mode);
    if (reduced_prim == PIPE_PRIM_TRIANGLES &&
        ctx->gfx_pipeline_state.rast->base.cull_face == PIPE_FACE_FRONT_AND_BACK)
       return;
 
    if (ctx->gfx_pipeline_state.prim_type != dinfo->mode) {
-      ctx->gfx_pipeline_state.prim_type = dinfo->mode;
+      ctx->gfx_pipeline_state.prim_type = (enum pipe_prim_type)dinfo->mode;
       ctx->state_dirty |= D3D12_DIRTY_PRIM_MODE;
    }
 
@@ -640,7 +640,7 @@ d3d12_draw_vbo(struct pipe_context *pctx,
       ctx->cmdlist->OMSetStencilRef(ctx->stencil_ref.ref_value[0]);
 
    if (ctx->cmdlist_dirty & D3D12_DIRTY_PRIM_MODE)
-      ctx->cmdlist->IASetPrimitiveTopology(topology(dinfo->mode));
+      ctx->cmdlist->IASetPrimitiveTopology(topology((enum pipe_prim_type)dinfo->mode));
 
    for (unsigned i = 0; i < ctx->num_vbs; ++i) {
       if (ctx->vbs[i].buffer.resource) {
diff --git a/src/gallium/drivers/radeonsi/si_state_draw.cpp b/src/gallium/drivers/radeonsi/si_state_draw.cpp
index 0e321a0ffdf..60b37190537 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.cpp
+++ b/src/gallium/drivers/radeonsi/si_state_draw.cpp
@@ -1787,7 +1787,7 @@ static void si_draw_vbo(struct pipe_context *ctx,
       }
    }
 
-   enum pipe_prim_type prim = info->mode;
+   enum pipe_prim_type prim = (enum pipe_prim_type)info->mode;
    unsigned instance_count = info->instance_count;
 
    /* GFX6-GFX7 treat instance_count==0 as instance_count==1. There is
diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index b4bd2b7b7cb..4a5f52ff112 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -425,7 +425,7 @@ zink_draw_vbo(struct pipe_context *pctx,
    bool reads_drawid = ctx->shader_reads_drawid;
    bool reads_basevertex = ctx->shader_reads_basevertex;
    unsigned work_count = ctx->batch.work_count;
-   enum pipe_prim_type mode = dinfo->mode;
+   enum pipe_prim_type mode = (enum pipe_prim_type)dinfo->mode;
 
    update_barriers(ctx, false);
 
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index 4354d93055b..b210fd70813 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -764,7 +764,13 @@ struct pipe_draw_start_count_bias {
  */
 struct pipe_draw_info
 {
-   enum pipe_prim_type mode:8;  /**< the mode of the primitive */
+#if defined(__GNUC__)
+   /* sizeof(mode) == 1 because it's a packed enum. */
+   enum pipe_prim_type mode;  /**< the mode of the primitive */
+#else
+   /* sizeof(mode) == 1 is required by draw merging in u_threaded_context. */
+   uint8_t mode;              /**< the mode of the primitive */
+#endif
    uint8_t index_size;        /**< if 0, the draw is not indexed. */
    uint8_t view_mask;         /**< mask of multiviews for this draw */
    bool primitive_restart:1;



More information about the mesa-commit mailing list