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

Author: Dave Airlie <[email protected]>
Date:   Fri Aug 26 16:43:18 2022 +1000

gallivm: consolidate llvmpipe/draw sampler types.

Reviewed-by: Roland Scheidegger <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18265>

---

 src/gallium/auxiliary/draw/draw_llvm.c           | 59 ++++--------------------
 src/gallium/auxiliary/draw/draw_llvm.h           | 29 ++----------
 src/gallium/auxiliary/draw/draw_llvm_sample.c    | 10 ++--
 src/gallium/auxiliary/gallivm/lp_bld_jit_types.c | 36 +++++++++++++++
 src/gallium/auxiliary/gallivm/lp_bld_jit_types.h | 21 +++++++++
 src/gallium/drivers/llvmpipe/lp_jit.c            | 40 +---------------
 src/gallium/drivers/llvmpipe/lp_jit.h            | 21 ---------
 7 files changed, 76 insertions(+), 140 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_llvm.c 
b/src/gallium/auxiliary/draw/draw_llvm.c
index 07dd648867c..3af278f7b11 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -144,49 +144,6 @@ create_jit_dvbuffer_type(struct gallivm_state *gallivm,
 }
 
 
-/**
- * Create LLVM type for struct draw_jit_sampler
- */
-static LLVMTypeRef
-create_jit_sampler_type(struct gallivm_state *gallivm, const char *struct_name)
-{
-   LLVMTargetDataRef target = gallivm->target;
-   LLVMTypeRef sampler_type;
-   LLVMTypeRef elem_types[DRAW_JIT_SAMPLER_NUM_FIELDS];
-
-   elem_types[DRAW_JIT_SAMPLER_MIN_LOD] =
-   elem_types[DRAW_JIT_SAMPLER_MAX_LOD] =
-   elem_types[DRAW_JIT_SAMPLER_LOD_BIAS] =
-   elem_types[DRAW_JIT_SAMPLER_MAX_ANISO] = 
LLVMFloatTypeInContext(gallivm->context);
-   elem_types[DRAW_JIT_SAMPLER_BORDER_COLOR] =
-      LLVMArrayType(LLVMFloatTypeInContext(gallivm->context), 4);
-
-   sampler_type = LLVMStructTypeInContext(gallivm->context, elem_types,
-                                          ARRAY_SIZE(elem_types), 0);
-
-   (void) target; /* silence unused var warning for non-debug build */
-   LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, min_lod,
-                          target, sampler_type,
-                          DRAW_JIT_SAMPLER_MIN_LOD);
-   LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, max_lod,
-                          target, sampler_type,
-                          DRAW_JIT_SAMPLER_MAX_LOD);
-   LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, lod_bias,
-                          target, sampler_type,
-                          DRAW_JIT_SAMPLER_LOD_BIAS);
-   LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, border_color,
-                          target, sampler_type,
-                          DRAW_JIT_SAMPLER_BORDER_COLOR);
-   LP_CHECK_MEMBER_OFFSET(struct draw_jit_sampler, max_aniso,
-                          target, sampler_type,
-                          DRAW_JIT_SAMPLER_MAX_ANISO);
-
-   LP_CHECK_STRUCT_SIZE(struct draw_jit_sampler, target, sampler_type);
-
-   return sampler_type;
-}
-
-
 /**
  * Create LLVM type for struct draw_jit_texture
  */
@@ -251,7 +208,7 @@ create_jit_context_type(struct gallivm_state *gallivm, 
const char *struct_name)
 {
    LLVMTypeRef buffer_type = lp_build_create_jit_buffer_type(gallivm);
    LLVMTypeRef texture_type = lp_build_create_jit_texture_type(gallivm);
-   LLVMTypeRef sampler_type = create_jit_sampler_type(gallivm, "sampler");
+   LLVMTypeRef sampler_type = lp_build_create_jit_sampler_type(gallivm);
    LLVMTypeRef image_type = create_jit_image_type(gallivm, "image");
 
    LLVMTargetDataRef target = gallivm->target;
@@ -2534,7 +2491,7 @@ draw_llvm_set_sampler_state(struct draw_context *draw,
    switch (shader_type) {
    case PIPE_SHADER_VERTEX:
       for (unsigned i = 0; i < draw->num_samplers[PIPE_SHADER_VERTEX]; i++) {
-         struct draw_jit_sampler *jit_sam = 
&draw->llvm->jit_context.samplers[i];
+         struct lp_jit_sampler *jit_sam = &draw->llvm->jit_context.samplers[i];
 
          if (draw->samplers[PIPE_SHADER_VERTEX][i]) {
             const struct pipe_sampler_state *s
@@ -2549,7 +2506,7 @@ draw_llvm_set_sampler_state(struct draw_context *draw,
       break;
    case PIPE_SHADER_GEOMETRY:
       for (unsigned i = 0; i < draw->num_samplers[PIPE_SHADER_GEOMETRY]; i++) {
-         struct draw_jit_sampler *jit_sam = 
&draw->llvm->gs_jit_context.samplers[i];
+         struct lp_jit_sampler *jit_sam = 
&draw->llvm->gs_jit_context.samplers[i];
 
          if (draw->samplers[PIPE_SHADER_GEOMETRY][i]) {
             const struct pipe_sampler_state *s
@@ -2564,7 +2521,7 @@ draw_llvm_set_sampler_state(struct draw_context *draw,
       break;
    case PIPE_SHADER_TESS_CTRL:
       for (unsigned i = 0; i < draw->num_samplers[PIPE_SHADER_TESS_CTRL]; i++) 
{
-         struct draw_jit_sampler *jit_sam = 
&draw->llvm->tcs_jit_context.samplers[i];
+         struct lp_jit_sampler *jit_sam = 
&draw->llvm->tcs_jit_context.samplers[i];
 
          if (draw->samplers[PIPE_SHADER_TESS_CTRL][i]) {
             const struct pipe_sampler_state *s
@@ -2579,7 +2536,7 @@ draw_llvm_set_sampler_state(struct draw_context *draw,
       break;
    case PIPE_SHADER_TESS_EVAL:
       for (unsigned i = 0; i < draw->num_samplers[PIPE_SHADER_TESS_EVAL]; i++) 
{
-         struct draw_jit_sampler *jit_sam = 
&draw->llvm->tes_jit_context.samplers[i];
+         struct lp_jit_sampler *jit_sam = 
&draw->llvm->tes_jit_context.samplers[i];
 
          if (draw->samplers[PIPE_SHADER_TESS_EVAL][i]) {
             const struct pipe_sampler_state *s
@@ -2629,7 +2586,7 @@ create_gs_jit_types(struct draw_gs_llvm_variant *var)
    LLVMTypeRef texture_type, sampler_type, image_type, buffer_type;
 
    texture_type = lp_build_create_jit_texture_type(gallivm);
-   sampler_type = create_jit_sampler_type(gallivm, "sampler");
+   sampler_type = lp_build_create_jit_sampler_type(gallivm);
    image_type = create_jit_image_type(gallivm, "image");
    buffer_type = lp_build_create_jit_buffer_type(gallivm);
 
@@ -3015,7 +2972,7 @@ create_tcs_jit_types(struct draw_tcs_llvm_variant *var)
    LLVMTypeRef texture_type, sampler_type, image_type, buffer_type;
 
    texture_type = lp_build_create_jit_texture_type(gallivm);
-   sampler_type = create_jit_sampler_type(gallivm, "sampler");
+   sampler_type = lp_build_create_jit_sampler_type(gallivm);
    image_type = create_jit_image_type(gallivm, "image");
    buffer_type = lp_build_create_jit_buffer_type(gallivm);
 
@@ -3674,7 +3631,7 @@ create_tes_jit_types(struct draw_tes_llvm_variant *var)
    LLVMTypeRef texture_type, sampler_type, image_type, buffer_type;
 
    texture_type = lp_build_create_jit_texture_type(gallivm);
-   sampler_type = create_jit_sampler_type(gallivm, "sampler");
+   sampler_type = lp_build_create_jit_sampler_type(gallivm);
    image_type = create_jit_image_type(gallivm, "image");
    buffer_type = lp_build_create_jit_buffer_type(gallivm);
 
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h 
b/src/gallium/auxiliary/draw/draw_llvm.h
index 042d806401c..81f5c0d30c5 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -64,17 +64,6 @@ struct draw_image_static_state
    struct lp_static_texture_state image_state;
 };
 
-
-struct draw_jit_sampler
-{
-   float min_lod;
-   float max_lod;
-   float lod_bias;
-   float border_color[4];
-   float max_aniso;
-};
-
-
 struct draw_jit_image
 {
    uint32_t width;
@@ -87,16 +76,6 @@ struct draw_jit_image
    uint32_t sample_stride;
 };
 
-enum {
-   DRAW_JIT_SAMPLER_MIN_LOD,
-   DRAW_JIT_SAMPLER_MAX_LOD,
-   DRAW_JIT_SAMPLER_LOD_BIAS,
-   DRAW_JIT_SAMPLER_BORDER_COLOR,
-   DRAW_JIT_SAMPLER_MAX_ANISO,
-   DRAW_JIT_SAMPLER_NUM_FIELDS  /* number of fields above */
-};
-
-
 enum {
    DRAW_JIT_VERTEX_VERTEX_ID = 0,
    DRAW_JIT_VERTEX_CLIP_POS,
@@ -133,7 +112,7 @@ struct draw_jit_context
    struct pipe_viewport_state *viewports;
 
    struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
-   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
+   struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
 
    struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
@@ -218,7 +197,7 @@ struct draw_gs_jit_context
    /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
     * DRAW_JIT_CTX_SAMPLERS positions in the struct */
    struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
-   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
+   struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
 
    int **prim_lengths;
@@ -274,7 +253,7 @@ struct draw_tcs_jit_context {
    /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
     * DRAW_JIT_CTX_SAMPLERS positions in the struct */
    struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
-   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
+   struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
 
    struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
@@ -311,7 +290,7 @@ struct draw_tes_jit_context {
    /* There two need to be exactly at DRAW_JIT_CTX_TEXTURES and
     * DRAW_JIT_CTX_SAMPLERS positions in the struct */
    struct lp_jit_texture textures[PIPE_MAX_SHADER_SAMPLER_VIEWS];
-   struct draw_jit_sampler samplers[PIPE_MAX_SAMPLERS];
+   struct lp_jit_sampler samplers[PIPE_MAX_SAMPLERS];
    struct draw_jit_image images[PIPE_MAX_SHADER_IMAGES];
 
    struct lp_jit_buffer ssbos[LP_MAX_TGSI_SHADER_BUFFERS];
diff --git a/src/gallium/auxiliary/draw/draw_llvm_sample.c 
b/src/gallium/auxiliary/draw/draw_llvm_sample.c
index 79c79255826..5e6d8c8b3b7 100644
--- a/src/gallium/auxiliary/draw/draw_llvm_sample.c
+++ b/src/gallium/auxiliary/draw/draw_llvm_sample.c
@@ -312,11 +312,11 @@ DRAW_LLVM_TEXTURE_MEMBER(sample_stride, 
LP_JIT_TEXTURE_SAMPLE_STRIDE, TRUE)
    }
 
 
-DRAW_LLVM_SAMPLER_MEMBER(min_lod,    DRAW_JIT_SAMPLER_MIN_LOD, TRUE)
-DRAW_LLVM_SAMPLER_MEMBER(max_lod,    DRAW_JIT_SAMPLER_MAX_LOD, TRUE)
-DRAW_LLVM_SAMPLER_MEMBER(lod_bias,   DRAW_JIT_SAMPLER_LOD_BIAS, TRUE)
-DRAW_LLVM_SAMPLER_MEMBER(border_color, DRAW_JIT_SAMPLER_BORDER_COLOR, FALSE)
-DRAW_LLVM_SAMPLER_MEMBER(max_aniso,  DRAW_JIT_SAMPLER_MAX_ANISO, TRUE)
+DRAW_LLVM_SAMPLER_MEMBER(min_lod,    LP_JIT_SAMPLER_MIN_LOD, TRUE)
+DRAW_LLVM_SAMPLER_MEMBER(max_lod,    LP_JIT_SAMPLER_MAX_LOD, TRUE)
+DRAW_LLVM_SAMPLER_MEMBER(lod_bias,   LP_JIT_SAMPLER_LOD_BIAS, TRUE)
+DRAW_LLVM_SAMPLER_MEMBER(border_color, LP_JIT_SAMPLER_BORDER_COLOR, FALSE)
+DRAW_LLVM_SAMPLER_MEMBER(max_aniso,  LP_JIT_SAMPLER_MAX_ANISO, TRUE)
 
 #define DRAW_LLVM_IMAGE_MEMBER(_name, _index, _emit_load)  \
    static LLVMValueRef \
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c 
b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c
index 969c38447f0..dd89bf37687 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c
@@ -157,3 +157,39 @@ lp_build_create_jit_texture_type(struct gallivm_state 
*gallivm)
                         gallivm->target, texture_type);
    return texture_type;
 }
+
+LLVMTypeRef
+lp_build_create_jit_sampler_type(struct gallivm_state *gallivm)
+{
+   LLVMContextRef lc = gallivm->context;
+   LLVMTypeRef sampler_type;
+   LLVMTypeRef elem_types[LP_JIT_SAMPLER_NUM_FIELDS];
+   elem_types[LP_JIT_SAMPLER_MIN_LOD] =
+   elem_types[LP_JIT_SAMPLER_MAX_LOD] =
+   elem_types[LP_JIT_SAMPLER_LOD_BIAS] =
+   elem_types[LP_JIT_SAMPLER_MAX_ANISO] = LLVMFloatTypeInContext(lc);
+   elem_types[LP_JIT_SAMPLER_BORDER_COLOR] =
+      LLVMArrayType(LLVMFloatTypeInContext(lc), 4);
+
+   sampler_type = LLVMStructTypeInContext(lc, elem_types,
+                                          ARRAY_SIZE(elem_types), 0);
+
+   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, min_lod,
+                          gallivm->target, sampler_type,
+                          LP_JIT_SAMPLER_MIN_LOD);
+   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, max_lod,
+                          gallivm->target, sampler_type,
+                          LP_JIT_SAMPLER_MAX_LOD);
+   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, lod_bias,
+                          gallivm->target, sampler_type,
+                          LP_JIT_SAMPLER_LOD_BIAS);
+   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, border_color,
+                          gallivm->target, sampler_type,
+                          LP_JIT_SAMPLER_BORDER_COLOR);
+   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, max_aniso,
+                          gallivm->target, sampler_type,
+                          LP_JIT_SAMPLER_MAX_ANISO);
+   LP_CHECK_STRUCT_SIZE(struct lp_jit_sampler,
+                        gallivm->target, sampler_type);
+   return sampler_type;
+}
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h 
b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h
index 3fc79db3ba4..5fe671818de 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h
@@ -85,4 +85,25 @@ enum {
 LLVMTypeRef
 lp_build_create_jit_texture_type(struct gallivm_state *gallivm);
 
+struct lp_jit_sampler
+{
+   float min_lod;
+   float max_lod;
+   float lod_bias;
+   float border_color[4];
+   float max_aniso;
+};
+
+enum {
+   LP_JIT_SAMPLER_MIN_LOD,
+   LP_JIT_SAMPLER_MAX_LOD,
+   LP_JIT_SAMPLER_LOD_BIAS,
+   LP_JIT_SAMPLER_BORDER_COLOR,
+   LP_JIT_SAMPLER_MAX_ANISO,
+   LP_JIT_SAMPLER_NUM_FIELDS  /* number of fields above */
+};
+
+LLVMTypeRef
+lp_build_create_jit_sampler_type(struct gallivm_state *gallivm);
+
 #endif
diff --git a/src/gallium/drivers/llvmpipe/lp_jit.c 
b/src/gallium/drivers/llvmpipe/lp_jit.c
index 7715e7f52c7..e38a10c75f5 100644
--- a/src/gallium/drivers/llvmpipe/lp_jit.c
+++ b/src/gallium/drivers/llvmpipe/lp_jit.c
@@ -42,42 +42,6 @@
 #include "lp_screen.h"
 #include "lp_jit.h"
 
-static LLVMTypeRef
-create_jit_sampler_type(struct gallivm_state *gallivm)
-{
-   LLVMContextRef lc = gallivm->context;
-   LLVMTypeRef sampler_type;
-   LLVMTypeRef elem_types[LP_JIT_SAMPLER_NUM_FIELDS];
-   elem_types[LP_JIT_SAMPLER_MIN_LOD] =
-   elem_types[LP_JIT_SAMPLER_MAX_LOD] =
-   elem_types[LP_JIT_SAMPLER_LOD_BIAS] =
-   elem_types[LP_JIT_SAMPLER_MAX_ANISO] = LLVMFloatTypeInContext(lc);
-   elem_types[LP_JIT_SAMPLER_BORDER_COLOR] =
-      LLVMArrayType(LLVMFloatTypeInContext(lc), 4);
-
-   sampler_type = LLVMStructTypeInContext(lc, elem_types,
-                                          ARRAY_SIZE(elem_types), 0);
-
-   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, min_lod,
-                          gallivm->target, sampler_type,
-                          LP_JIT_SAMPLER_MIN_LOD);
-   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, max_lod,
-                          gallivm->target, sampler_type,
-                          LP_JIT_SAMPLER_MAX_LOD);
-   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, lod_bias,
-                          gallivm->target, sampler_type,
-                          LP_JIT_SAMPLER_LOD_BIAS);
-   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, border_color,
-                          gallivm->target, sampler_type,
-                          LP_JIT_SAMPLER_BORDER_COLOR);
-   LP_CHECK_MEMBER_OFFSET(struct lp_jit_sampler, max_aniso,
-                          gallivm->target, sampler_type,
-                          LP_JIT_SAMPLER_MAX_ANISO);
-   LP_CHECK_STRUCT_SIZE(struct lp_jit_sampler,
-                        gallivm->target, sampler_type);
-   return sampler_type;
-}
-
 static LLVMTypeRef
 create_jit_image_type(struct gallivm_state *gallivm)
 {
@@ -152,7 +116,7 @@ lp_jit_create_types(struct lp_fragment_shader_variant *lp)
 
    buffer_type = lp_build_create_jit_buffer_type(gallivm);
    texture_type = lp_build_create_jit_texture_type(gallivm);
-   sampler_type = create_jit_sampler_type(gallivm);
+   sampler_type = lp_build_create_jit_sampler_type(gallivm);
    image_type = create_jit_image_type(gallivm);
 
    /* struct lp_jit_context */
@@ -358,7 +322,7 @@ lp_jit_create_cs_types(struct lp_compute_shader_variant *lp)
 
    buffer_type = lp_build_create_jit_buffer_type(gallivm);
    texture_type = lp_build_create_jit_texture_type(gallivm);
-   sampler_type = create_jit_sampler_type(gallivm);
+   sampler_type = lp_build_create_jit_sampler_type(gallivm);
    image_type = create_jit_image_type(gallivm);
 
    /* struct lp_jit_cs_thread_data */
diff --git a/src/gallium/drivers/llvmpipe/lp_jit.h 
b/src/gallium/drivers/llvmpipe/lp_jit.h
index a94a562819f..a0f61e0e6df 100644
--- a/src/gallium/drivers/llvmpipe/lp_jit.h
+++ b/src/gallium/drivers/llvmpipe/lp_jit.h
@@ -50,23 +50,12 @@ struct lp_compute_shader_variant;
 struct lp_rast_state;
 struct llvmpipe_screen;
 
-struct lp_jit_sampler
-{
-   float min_lod;
-   float max_lod;
-   float lod_bias;
-   float border_color[4];
-   float max_aniso;
-};
-
-
 struct lp_jit_viewport
 {
    float min_depth;
    float max_depth;
 };
 
-
 struct lp_jit_image
 {
    uint32_t width;        /* same as number of elements */
@@ -79,16 +68,6 @@ struct lp_jit_image
    uint32_t sample_stride;
 };
 
-enum {
-   LP_JIT_SAMPLER_MIN_LOD,
-   LP_JIT_SAMPLER_MAX_LOD,
-   LP_JIT_SAMPLER_LOD_BIAS,
-   LP_JIT_SAMPLER_BORDER_COLOR,
-   LP_JIT_SAMPLER_MAX_ANISO,
-   LP_JIT_SAMPLER_NUM_FIELDS  /* number of fields above */
-};
-
-
 enum {
    LP_JIT_VIEWPORT_MIN_DEPTH,
    LP_JIT_VIEWPORT_MAX_DEPTH,

Reply via email to