draw: add a max stage define and use it in a few places
authorDave Airlie <airlied@redhat.com>
Wed, 7 Jun 2023 05:33:34 +0000 (15:33 +1000)
committerMarge Bot <emma+marge@anholt.net>
Thu, 8 Jun 2023 02:10:54 +0000 (02:10 +0000)
This should decrease the size of some memory allocations.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23487>

src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_llvm.h
src/gallium/auxiliary/draw/draw_private.h

index 1745a4e..bc1ee04 100644 (file)
@@ -1047,7 +1047,7 @@ draw_set_sampler_views(struct draw_context *draw,
                        struct pipe_sampler_view **views,
                        unsigned num)
 {
-   assert(shader_stage < PIPE_SHADER_TYPES);
+   assert(shader_stage < DRAW_MAX_SHADER_STAGE);
    assert(num <= PIPE_MAX_SHADER_SAMPLER_VIEWS);
 
    draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE);
@@ -1067,7 +1067,7 @@ draw_set_samplers(struct draw_context *draw,
                   struct pipe_sampler_state **samplers,
                   unsigned num)
 {
-   assert(shader_stage < PIPE_SHADER_TYPES);
+   assert(shader_stage < DRAW_MAX_SHADER_STAGE);
    assert(num <= PIPE_MAX_SAMPLERS);
 
    draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE);
@@ -1092,7 +1092,7 @@ draw_set_images(struct draw_context *draw,
                 struct pipe_image_view *views,
                 unsigned num)
 {
-   assert(shader_stage < PIPE_SHADER_TYPES);
+   assert(shader_stage < DRAW_MAX_SHADER_STAGE);
    assert(num <= PIPE_MAX_SHADER_IMAGES);
 
    draw_do_flush(draw, DRAW_FLUSH_STATE_CHANGE);
index 6867f5a..02c5853 100644 (file)
@@ -2156,8 +2156,7 @@ draw_llvm_set_mapped_texture(struct draw_context *draw,
 {
    struct lp_jit_texture *jit_tex;
 
-   assert (shader_stage >= PIPE_SHADER_VERTEX &&
-           shader_stage <= PIPE_SHADER_GEOMETRY);
+   assert(shader_stage < DRAW_MAX_SHADER_STAGE);
    assert(sview_idx < ARRAY_SIZE(draw->llvm->jit_resources[shader_stage].textures));
 
    jit_tex = &draw->llvm->jit_resources[shader_stage].textures[sview_idx];
@@ -2191,8 +2190,7 @@ draw_llvm_set_mapped_image(struct draw_context *draw,
 {
    struct lp_jit_image *jit_image;
 
-   assert (shader_stage >= PIPE_SHADER_VERTEX &&
-           shader_stage <= PIPE_SHADER_GEOMETRY);
+   assert(shader_stage < DRAW_MAX_SHADER_STAGE);
    assert(idx < ARRAY_SIZE(draw->llvm->jit_resources[shader_stage].images));
 
    jit_image = &draw->llvm->jit_resources[shader_stage].images[idx];
@@ -2213,8 +2211,7 @@ void
 draw_llvm_set_sampler_state(struct draw_context *draw,
                             enum pipe_shader_type shader_type)
 {
-   assert (shader_type >= PIPE_SHADER_VERTEX &&
-           shader_type <= PIPE_SHADER_GEOMETRY);
+   assert(shader_type < DRAW_MAX_SHADER_STAGE);
    for (unsigned i = 0; i < draw->num_samplers[shader_type]; i++) {
       struct lp_jit_sampler *jit_sam = &draw->llvm->jit_resources[shader_type].samplers[i];
 
index 2d4a32b..6c6cf41 100644 (file)
@@ -547,7 +547,7 @@ struct draw_llvm {
    struct draw_vs_jit_context vs_jit_context;
    struct draw_gs_jit_context gs_jit_context;
 
-   struct lp_jit_resources jit_resources[PIPE_SHADER_GEOMETRY + 1];
+   struct lp_jit_resources jit_resources[DRAW_MAX_SHADER_STAGE];
 
    struct draw_llvm_variant_list_item vs_variants_list;
    int nr_variants;
index b425604..e0cc8b5 100644 (file)
 struct gallivm_state;
 #endif
 
+/**
+ * The max stage the draw stores resources for.
+ * i.e. vs, tcs, tes, gs. no fs/cs/ms/ts.
+ */
+#define DRAW_MAX_SHADER_STAGE (PIPE_SHADER_GEOMETRY + 1)
 
 /**
  * The largest possible index of a vertex that can be fetched.
@@ -222,8 +227,8 @@ struct draw_context
          struct draw_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS];
 
          /** constant buffers for each shader stage */
-         struct draw_buffer_info constants[PIPE_SHADER_GEOMETRY + 1][PIPE_MAX_CONSTANT_BUFFERS];
-         struct draw_buffer_info ssbos[PIPE_SHADER_GEOMETRY + 1][PIPE_MAX_SHADER_BUFFERS];
+         struct draw_buffer_info constants[DRAW_MAX_SHADER_STAGE][PIPE_MAX_CONSTANT_BUFFERS];
+         struct draw_buffer_info ssbos[DRAW_MAX_SHADER_STAGE][PIPE_MAX_SHADER_BUFFERS];
 
          /* pointer to planes */
          float (*planes)[DRAW_TOTAL_CLIP_PLANES][4];
@@ -367,13 +372,13 @@ struct draw_context
     * we only handle vertex and geometry shaders in the draw module, but
     * there may be more in the future (ex: hull and tessellation).
     */
-   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
-   unsigned num_sampler_views[PIPE_SHADER_TYPES];
-   const struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
-   unsigned num_samplers[PIPE_SHADER_TYPES];
+   struct pipe_sampler_view *sampler_views[DRAW_MAX_SHADER_STAGE][PIPE_MAX_SHADER_SAMPLER_VIEWS];
+   unsigned num_sampler_views[DRAW_MAX_SHADER_STAGE];
+   const struct pipe_sampler_state *samplers[DRAW_MAX_SHADER_STAGE][PIPE_MAX_SAMPLERS];
+   unsigned num_samplers[DRAW_MAX_SHADER_STAGE];
 
-   struct pipe_image_view *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
-   unsigned num_images[PIPE_SHADER_TYPES];
+   struct pipe_image_view *images[DRAW_MAX_SHADER_STAGE][PIPE_MAX_SHADER_IMAGES];
+   unsigned num_images[DRAW_MAX_SHADER_STAGE];
 
    struct pipe_query_data_pipeline_statistics statistics;
    boolean collect_statistics;