gallivm: consolidate llvmpipe/draw sampler types.
authorDave Airlie <airlied@redhat.com>
Fri, 26 Aug 2022 06:43:18 +0000 (16:43 +1000)
committerMarge Bot <emma+marge@anholt.net>
Sat, 29 Apr 2023 02:57:19 +0000 (02:57 +0000)
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18265>

src/gallium/auxiliary/draw/draw_llvm.c
src/gallium/auxiliary/draw/draw_llvm.h
src/gallium/auxiliary/draw/draw_llvm_sample.c
src/gallium/auxiliary/gallivm/lp_bld_jit_types.c
src/gallium/auxiliary/gallivm/lp_bld_jit_types.h
src/gallium/drivers/llvmpipe/lp_jit.c
src/gallium/drivers/llvmpipe/lp_jit.h

index 07dd648..3af278f 100644 (file)
@@ -145,49 +145,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
  */
 static LLVMTypeRef
@@ -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);
 
index 042d806..81f5c0d 100644 (file)
@@ -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;
@@ -88,16 +77,6 @@ struct draw_jit_image
 };
 
 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,
    DRAW_JIT_VERTEX_DATA
@@ -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];
index 79c7925..5e6d8c8 100644 (file)
@@ -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 \
index 969c384..dd89bf3 100644 (file)
@@ -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;
+}
index 3fc79db..5fe6718 100644 (file)
@@ -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
index 7715e7f..e38a10c 100644 (file)
 #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)
 {
    LLVMContextRef lc = gallivm->context;
@@ -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 */
index a94a562..a0f61e0 100644 (file)
@@ -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 */
@@ -80,16 +69,6 @@ struct lp_jit_image
 };
 
 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,
    LP_JIT_VIEWPORT_NUM_FIELDS /* number of fields above */