Mesa (main): d3d12: Properly set HS input control point count

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 9 17:22:50 UTC 2022


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

Author: Jesse Natalie <jenatali at microsoft.com>
Date:   Tue Jun  7 14:49:59 2022 -0700

d3d12: Properly set HS input control point count

Looks like some hardware needs this info in the shader to match the
topology. Since there's no spot in the shader info for it, we're
currently using the array size of the TCS input vars to store it.

Cc: mesa-stable
Reviewed-by: Paul Dodzweit <paul.dodzweit at amd.com>
Tested-by: Paul Dodzweit <paul.dodzweit at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16920>

---

 src/gallium/drivers/d3d12/d3d12_compiler.cpp |  4 ++++
 src/gallium/drivers/d3d12/d3d12_compiler.h   |  1 +
 src/microsoft/compiler/dxil_nir.h            |  1 +
 src/microsoft/compiler/dxil_nir_tess.c       | 32 ++++++++++++++++++++++++++++
 4 files changed, 38 insertions(+)

diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.cpp b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
index cef712712e3..f48c94f41ba 100644
--- a/src/gallium/drivers/d3d12/d3d12_compiler.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_compiler.cpp
@@ -743,6 +743,7 @@ d3d12_compare_shader_keys(const d3d12_shader_key *expect, const d3d12_shader_key
           expect->hs.ccw != have->hs.ccw ||
           expect->hs.point_mode != have->hs.point_mode ||
           expect->hs.spacing != have->hs.spacing ||
+          expect->hs.patch_vertices_in != have->hs.patch_vertices_in ||
           memcmp(&expect->hs.required_patch_outputs, &have->hs.required_patch_outputs,
                  sizeof(struct d3d12_varying_info)) ||
           expect->hs.next_patch_inputs != have->hs.next_patch_inputs)
@@ -978,6 +979,7 @@ d3d12_fill_shader_key(struct d3d12_selection_context *sel_ctx,
          key->hs.point_mode = false;
          key->hs.spacing = TESS_SPACING_EQUAL;
       }
+      key->hs.patch_vertices_in = MAX2(sel_ctx->ctx->patch_vertices, 1);
    } else if (stage == PIPE_SHADER_TESS_EVAL) {
       if (prev && prev->current->nir->info.stage == MESA_SHADER_TESS_CTRL)
          key->ds.tcs_vertices_out = prev->current->nir->info.tess.tcs_vertices_out;
@@ -1147,6 +1149,8 @@ select_shader_variant(struct d3d12_selection_context *sel_ctx, d3d12_shader_sele
       new_nir_variant->info.tess.ccw = key.hs.ccw;
       new_nir_variant->info.tess.point_mode = key.hs.point_mode;
       new_nir_variant->info.tess.spacing = key.hs.spacing;
+
+      NIR_PASS_V(new_nir_variant, dxil_nir_set_tcs_patches_in, key.hs.patch_vertices_in);
    } else if (new_nir_variant->info.stage == MESA_SHADER_TESS_EVAL) {
       new_nir_variant->info.tess.tcs_vertices_out = key.ds.tcs_vertices_out;
    }
diff --git a/src/gallium/drivers/d3d12/d3d12_compiler.h b/src/gallium/drivers/d3d12/d3d12_compiler.h
index 823d395d578..aed79f95c1e 100644
--- a/src/gallium/drivers/d3d12/d3d12_compiler.h
+++ b/src/gallium/drivers/d3d12/d3d12_compiler.h
@@ -120,6 +120,7 @@ struct d3d12_shader_key {
       unsigned ccw:1;
       unsigned point_mode:1;
       unsigned spacing:2;
+      unsigned patch_vertices_in:5;
       struct d3d12_varying_info required_patch_outputs;
       uint32_t next_patch_inputs;
    } hs;
diff --git a/src/microsoft/compiler/dxil_nir.h b/src/microsoft/compiler/dxil_nir.h
index fe4ecf56aed..1d04fe73c95 100644
--- a/src/microsoft/compiler/dxil_nir.h
+++ b/src/microsoft/compiler/dxil_nir.h
@@ -70,6 +70,7 @@ dxil_reassign_driver_locations(nir_shader* s, nir_variable_mode modes,
 
 void dxil_nir_split_tess_ctrl(nir_shader *nir, nir_function **patch_const_func);
 bool dxil_nir_fixup_tess_level_for_domain(nir_shader *nir);
+bool dxil_nir_set_tcs_patches_in(nir_shader *nir, unsigned num_control_points);
 bool dxil_nir_lower_ubo_array_one_to_static(nir_shader *s);
 
 #ifdef __cplusplus
diff --git a/src/microsoft/compiler/dxil_nir_tess.c b/src/microsoft/compiler/dxil_nir_tess.c
index 21ddd25b542..2adf3f8bc59 100644
--- a/src/microsoft/compiler/dxil_nir_tess.c
+++ b/src/microsoft/compiler/dxil_nir_tess.c
@@ -355,3 +355,35 @@ dxil_nir_fixup_tess_level_for_domain(nir_shader *nir)
    }
    return progress;
 }
+
+static bool
+tcs_update_deref_input_types(nir_builder *b, nir_instr *instr, void *data)
+{
+   if (instr->type != nir_instr_type_deref)
+      return false;
+
+   nir_deref_instr *deref = nir_instr_as_deref(instr);
+   if (deref->deref_type != nir_deref_type_var)
+      return false;
+
+   nir_variable *var = deref->var;
+   deref->type = var->type;
+   return true;
+}
+
+bool
+dxil_nir_set_tcs_patches_in(nir_shader *nir, unsigned num_control_points)
+{
+   bool progress = false;
+   nir_foreach_variable_with_modes(var, nir, nir_var_shader_in) {
+      if (nir_is_arrayed_io(var, MESA_SHADER_TESS_CTRL)) {
+         var->type = glsl_array_type(glsl_get_array_element(var->type), num_control_points, 0);
+         progress = true;
+      }
+   }
+
+   if (progress)
+      nir_shader_instructions_pass(nir, tcs_update_deref_input_types, nir_metadata_all, NULL);
+
+   return progress;
+}



More information about the mesa-commit mailing list