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

Author: Dave Airlie <airl...@redhat.com>
Date:   Tue Sep 26 17:10:04 2023 +1000

gallivm/lp: move sampler index around to reduce struct

I'm not sure this is 100% correct, but it does reduce the
struct size to 256 which is conformant

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

---

 src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c  |  2 +-
 src/gallium/auxiliary/gallivm/lp_bld_jit_types.c   |  1 +
 src/gallium/auxiliary/gallivm/lp_bld_jit_types.h   |  3 +-
 .../frontends/lavapipe/lvp_descriptor_set.c        | 34 +++++++++++-----------
 src/gallium/frontends/lavapipe/lvp_device.c        |  2 +-
 src/gallium/frontends/lavapipe/lvp_execute.c       |  2 +-
 6 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c 
b/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c
index 10ecc191bae..a1b3a3a8478 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_sample.c
@@ -201,7 +201,7 @@ lp_bld_llvm_sampler_soa_emit_fetch_texel(const struct 
lp_build_sampler_soa *base
       } else {
          sampler_desc_ptr = lp_llvm_descriptor_base(gallivm, consts, 
params->sampler_resource, LP_MAX_TGSI_CONST_BUFFERS);
 
-         LLVMValueRef sampler_index_offset = lp_build_const_int64(gallivm, 
offsetof(struct lp_descriptor, sampler_index));
+         LLVMValueRef sampler_index_offset = lp_build_const_int64(gallivm, 
offsetof(struct lp_descriptor, texture.sampler_index));
          LLVMValueRef sampler_index_ptr = LLVMBuildAdd(builder, 
sampler_desc_ptr, sampler_index_offset, "");
 
          LLVMTypeRef sampler_index_type = 
LLVMInt32TypeInContext(gallivm->context);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c 
b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c
index 0d9faef2ca9..df070f28495 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.c
@@ -146,6 +146,7 @@ lp_build_create_jit_texture_type(struct gallivm_state 
*gallivm)
    LLVMTypeRef elem_types[LP_JIT_TEXTURE_NUM_FIELDS];
 
    /* struct lp_jit_texture */
+   elem_types[LP_JIT_SAMPLER_INDEX_DUMMY] =
    elem_types[LP_JIT_TEXTURE_WIDTH] = LLVMInt32TypeInContext(lc);
    elem_types[LP_JIT_TEXTURE_HEIGHT] =
    elem_types[LP_JIT_TEXTURE_DEPTH] = LLVMInt16TypeInContext(lc);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h 
b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h
index 957b80f4542..962c6965905 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_jit_types.h
@@ -73,6 +73,7 @@ struct lp_jit_texture
    uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS];
    uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS];
    uint32_t mip_offsets[PIPE_MAX_TEXTURE_LEVELS]; /* sample stride is in 
mip_offsets[15] */
+   uint32_t sampler_index;
 };
 
 enum {
@@ -85,6 +86,7 @@ enum {
    LP_JIT_TEXTURE_ROW_STRIDE,
    LP_JIT_TEXTURE_IMG_STRIDE,
    LP_JIT_TEXTURE_MIP_OFFSETS,
+   LP_JIT_SAMPLER_INDEX_DUMMY,
    LP_JIT_TEXTURE_NUM_FIELDS  /* number of fields above */
 };
 
@@ -239,7 +241,6 @@ struct lp_descriptor {
    /* Store sample/image functions in the same location since some d3d12 games
     * rely on mismatched descriptor types with null descriptors.
     */
-   uint32_t sampler_index;
    void *functions;
 };
 
diff --git a/src/gallium/frontends/lavapipe/lvp_descriptor_set.c 
b/src/gallium/frontends/lavapipe/lvp_descriptor_set.c
index 41d02af97b1..fa198f3e575 100644
--- a/src/gallium/frontends/lavapipe/lvp_descriptor_set.c
+++ b/src/gallium/frontends/lavapipe/lvp_descriptor_set.c
@@ -467,7 +467,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_UpdateDescriptorSets(
 
                for (unsigned k = 0; k < bind_layout->stride; k++) {
                   desc[didx + k].sampler = sampler->desc.sampler;
-                  desc[didx + k].sampler_index = sampler->desc.sampler_index;
+                  desc[didx + k].texture.sampler_index = 
sampler->desc.texture.sampler_index;
                }
             }
          }
@@ -492,13 +492,13 @@ VKAPI_ATTR void VKAPI_CALL lvp_UpdateDescriptorSets(
 
                   for (unsigned p = 0; p < plane_count; p++) {
                      desc[didx + p].sampler = sampler->desc.sampler;
-                     desc[didx + p].sampler_index = 
sampler->desc.sampler_index;
+                     desc[didx + p].texture.sampler_index = 
sampler->desc.texture.sampler_index;
                   }
                }
             } else {
                for (unsigned k = 0; k < bind_layout->stride; k++) {
                   desc[didx + k].functions = 
device->null_texture_handle->functions;
-                  desc[didx + k].sampler_index = 0;
+                  desc[didx + k].texture.sampler_index = 0;
                }
             }
          }
@@ -519,7 +519,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_UpdateDescriptorSets(
             } else {
                for (unsigned k = 0; k < bind_layout->stride; k++) {
                   desc[didx + k].functions = 
device->null_texture_handle->functions;
-                  desc[didx + k].sampler_index = 0;
+                  desc[didx + k].texture.sampler_index = 0;
                }
             }
          }
@@ -554,7 +554,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_UpdateDescriptorSets(
                desc[j].functions = bview->texture_handle->functions;
             } else {
                desc[j].functions = device->null_texture_handle->functions;
-               desc[j].sampler_index = 0;
+               desc[j].texture.sampler_index = 0;
             }
          }
          break;
@@ -851,7 +851,7 @@ lvp_descriptor_set_update_with_template(VkDevice _device, 
VkDescriptorSet descri
 
             for (unsigned k = 0; k < bind_layout->stride; k++) {
                desc[idx + k].sampler = sampler->desc.sampler;
-               desc[idx + k].sampler_index = sampler->desc.sampler_index;
+               desc[idx + k].texture.sampler_index = 
sampler->desc.texture.sampler_index;
             }
             break;
          }
@@ -870,13 +870,13 @@ lvp_descriptor_set_update_with_template(VkDevice _device, 
VkDescriptorSet descri
 
                   for (unsigned p = 0; p < iview->plane_count; p++) {
                      desc[idx + p].sampler = sampler->desc.sampler;
-                     desc[idx + p].sampler_index = sampler->desc.sampler_index;
+                     desc[idx + p].texture.sampler_index = 
sampler->desc.texture.sampler_index;
                   }
                }
             } else {
                for (unsigned k = 0; k < bind_layout->stride; k++) {
                   desc[idx + k].functions = 
device->null_texture_handle->functions;
-                  desc[idx + k].sampler_index = 0;
+                  desc[idx + k].texture.sampler_index = 0;
                }
             }
             break;
@@ -893,7 +893,7 @@ lvp_descriptor_set_update_with_template(VkDevice _device, 
VkDescriptorSet descri
             } else {
                for (unsigned k = 0; k < bind_layout->stride; k++) {
                   desc[idx + k].functions = 
device->null_texture_handle->functions;
-                  desc[idx + k].sampler_index = 0;
+                  desc[idx + k].texture.sampler_index = 0;
                }
             }
             break;
@@ -923,7 +923,7 @@ lvp_descriptor_set_update_with_template(VkDevice _device, 
VkDescriptorSet descri
                desc[idx].functions = bview->texture_handle->functions;
             } else {
                desc[j].functions = device->null_texture_handle->functions;
-               desc[j].sampler_index = 0;
+               desc[j].texture.sampler_index = 0;
             }
             break;
          }
@@ -1057,10 +1057,10 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorEXT(
       if (pCreateInfo->data.pSampler) {
          LVP_FROM_HANDLE(lvp_sampler, sampler, pCreateInfo->data.pSampler[0]);
          desc->sampler = sampler->desc.sampler;
-         desc->sampler_index = sampler->desc.sampler_index;
+         desc->texture.sampler_index = sampler->desc.texture.sampler_index;
       } else {
          lp_jit_sampler_from_pipe(&desc->sampler, &sampler);
-         desc->sampler_index = 0;
+         desc->texture.sampler_index = 0;
       }
       break;
    }
@@ -1076,14 +1076,14 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorEXT(
          if (info->sampler) {
             LVP_FROM_HANDLE(lvp_sampler, sampler, info->sampler);
             desc->sampler = sampler->desc.sampler;
-            desc->sampler_index = sampler->desc.sampler_index;
+            desc->texture.sampler_index = sampler->desc.texture.sampler_index;
          } else {
             lp_jit_sampler_from_pipe(&desc->sampler, &sampler);
-            desc->sampler_index = 0;
+            desc->texture.sampler_index = 0;
          }
       } else {
          desc->functions = device->null_texture_handle->functions;
-         desc->sampler_index = 0;
+         desc->texture.sampler_index = 0;
       }
 
       break;
@@ -1096,7 +1096,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorEXT(
          desc->functions = iview->planes[0].texture_handle->functions;
       } else {
          desc->functions = device->null_texture_handle->functions;
-         desc->sampler_index = 0;
+         desc->texture.sampler_index = 0;
       }
       break;
    }
@@ -1121,7 +1121,7 @@ VKAPI_ATTR void VKAPI_CALL lvp_GetDescriptorEXT(
          desc->functions = get_texture_handle_bda(device, bda, 
pformat).functions;
       } else {
          desc->functions = device->null_texture_handle->functions;
-         desc->sampler_index = 0;
+         desc->texture.sampler_index = 0;
       }
       break;
    }
diff --git a/src/gallium/frontends/lavapipe/lvp_device.c 
b/src/gallium/frontends/lavapipe/lvp_device.c
index f84b7e5d06e..ca064f9982c 100644
--- a/src/gallium/frontends/lavapipe/lvp_device.c
+++ b/src/gallium/frontends/lavapipe/lvp_device.c
@@ -2252,7 +2252,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateSampler(
    simple_mtx_unlock(&device->queue.lock);
 
    lp_jit_sampler_from_pipe(&sampler->desc.sampler, &state);
-   sampler->desc.sampler_index = sampler->texture_handle->sampler_index;
+   sampler->desc.texture.sampler_index = 
sampler->texture_handle->sampler_index;
 
    *pSampler = lvp_sampler_to_handle(sampler);
 
diff --git a/src/gallium/frontends/lavapipe/lvp_execute.c 
b/src/gallium/frontends/lavapipe/lvp_execute.c
index cdbaf64ce3a..3c01563442b 100644
--- a/src/gallium/frontends/lavapipe/lvp_execute.c
+++ b/src/gallium/frontends/lavapipe/lvp_execute.c
@@ -4097,7 +4097,7 @@ bind_db_samplers(struct rendering_state *state, enum 
lvp_pipeline_type pipeline_
          if (bind_layout->immutable_samplers[sampler_index]) {
             struct lp_descriptor *immutable_desc = 
&bind_layout->immutable_samplers[sampler_index]->desc;
             desc[sampler_index].sampler = immutable_desc->sampler;
-            desc[sampler_index].sampler_index = immutable_desc->sampler_index;
+            desc[sampler_index].texture.sampler_index = 
immutable_desc->texture.sampler_index;
             u_foreach_bit(stage, set_layout->shader_stages)
                did_update |= BITFIELD_BIT(vk_to_mesa_shader_stage(1<<stage));
          }

Reply via email to