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

Author: Giancarlo Devich <[email protected]>
Date:   Tue Mar 14 11:38:53 2023 -0700

d3d12: Use context-level sampler_state array for filling shader keys

This significantly reduces the size of d3d12_shader_key

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21909>

---

 src/gallium/drivers/d3d12/d3d12_compiler.cpp | 15 ++++++++++++++-
 src/gallium/drivers/d3d12/d3d12_compiler.h   |  2 +-
 src/gallium/drivers/d3d12/d3d12_context.h    |  3 +++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp 
b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
index d7d9c34e1f8..7f3eaf2fa15 100644
--- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
@@ -97,6 +97,13 @@ compile_nir(struct d3d12_context *ctx, struct 
d3d12_shader_selector *sel,
    struct d3d12_shader *shader = rzalloc(sel, d3d12_shader);
    shader->key = *key;
 
+   if (shader->key.n_texture_states > 0) {
+      shader->key.tex_wrap_states = (dxil_wrap_sampler_state*)ralloc_size(sel, 
sizeof(dxil_wrap_sampler_state) * shader->key.n_texture_states);
+      memcpy(shader->key.tex_wrap_states, key->tex_wrap_states, 
sizeof(dxil_wrap_sampler_state) * shader->key.n_texture_states);
+   }
+   else
+      shader->key.tex_wrap_states = nullptr;
+
    shader->output_vars_fs = nullptr;
    shader->output_vars_gs = nullptr;
    shader->output_vars_default = nullptr;
@@ -837,7 +844,8 @@ d3d12_compare_shader_keys(struct d3d12_selection_context* 
sel_ctx, const d3d12_s
    if (expect->n_images != have->n_images)
       return false;
 
-   if (memcmp(expect->tex_wrap_states, have->tex_wrap_states,
+   if (expect->n_texture_states > 0 && 
+       memcmp(expect->tex_wrap_states, have->tex_wrap_states,
               expect->n_texture_states * sizeof(dxil_wrap_sampler_state)))
       return false;
 
@@ -949,6 +957,7 @@ d3d12_fill_shader_key(struct d3d12_selection_context 
*sel_ctx,
    }
 
    key->n_texture_states = 0;
+   key->tex_wrap_states = sel_ctx->ctx->tex_wrap_states_shader_key;
    key->n_images = 0;
 
    if (prev) {
@@ -1122,6 +1131,8 @@ d3d12_fill_shader_key(struct d3d12_selection_context 
*sel_ctx,
             memcpy(&key->tex_wrap_states[i], &wrap_state, sizeof(wrap_state));
             key->swizzle_state[i] = sel_ctx->ctx->tex_swizzle_state[stage][i];
          }
+         else
+            memset(&key->tex_wrap_states[i], 0, 
sizeof(key->tex_wrap_states[i]));
       }
    }
 
@@ -1144,6 +1155,8 @@ d3d12_fill_shader_key(struct d3d12_selection_context 
*sel_ctx,
              key->n_texture_states * sizeof(enum compare_func));
       memcpy(key->swizzle_state, sel_ctx->ctx->tex_swizzle_state[stage],
              key->n_texture_states * sizeof(dxil_texture_swizzle_state));
+      if (!sel->samples_int_textures) 
+         memset(key->tex_wrap_states, 0, sizeof(key->tex_wrap_states[0]) * 
key->n_texture_states);
    }
 
    if (stage == PIPE_SHADER_VERTEX && sel_ctx->ctx->gfx_pipeline_state.ves) {
diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.h 
b/src/gallium/drivers/d3d12/d3d12_compiler.h
index 30b90adb55c..6cf4c97bd81 100644
--- a/src/gallium/drivers/d3d12/d3d12_compiler.h
+++ b/src/gallium/drivers/d3d12/d3d12_compiler.h
@@ -177,7 +177,7 @@ struct d3d12_shader_key {
    };
 
    int n_texture_states;
-   dxil_wrap_sampler_state tex_wrap_states[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+   dxil_wrap_sampler_state *tex_wrap_states;
    dxil_texture_swizzle_state swizzle_state[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    enum compare_func sampler_compare_funcs[PIPE_MAX_SHADER_SAMPLER_VIEWS];
 
diff --git a/src/gallium/drivers/d3d12/d3d12_context.h 
b/src/gallium/drivers/d3d12/d3d12_context.h
index 4bf9d56b924..19b1720e100 100644
--- a/src/gallium/drivers/d3d12/d3d12_context.h
+++ b/src/gallium/drivers/d3d12/d3d12_context.h
@@ -215,7 +215,10 @@ struct d3d12_context {
    struct d3d12_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
    unsigned num_samplers[PIPE_SHADER_TYPES];
    D3D12_INDEX_BUFFER_VIEW ibv;
+
    dxil_wrap_sampler_state 
tex_wrap_states[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
+   dxil_wrap_sampler_state 
tex_wrap_states_shader_key[PIPE_MAX_SHADER_SAMPLER_VIEWS];
+
    dxil_texture_swizzle_state 
tex_swizzle_state[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
    enum compare_func 
tex_compare_func[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
 

Reply via email to