Mesa (main): microsoft/compiler: Allow vulkan users to handle varyings linking

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 8 15:57:27 UTC 2022


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

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Thu Apr 28 15:05:18 2022 +0200

microsoft/compiler: Allow vulkan users to handle varyings linking

Letting the compiler decide which slot should be used for varyings when
it doesn't know about the varyings written/read by the previous/next
stage doesn't work well. So let's the caller decide when it wants
automatic index/register assignment through a dedicated parameter,
instead of assuming Vulkan users always want that.

Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16221>

---

 src/microsoft/compiler/dxil_signature.c     | 42 ++++++++++++++---------------
 src/microsoft/compiler/dxil_signature.h     |  2 +-
 src/microsoft/compiler/nir_to_dxil.c        |  2 +-
 src/microsoft/compiler/nir_to_dxil.h        |  1 +
 src/microsoft/spirv_to_dxil/spirv_to_dxil.c |  5 +++-
 5 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/src/microsoft/compiler/dxil_signature.c b/src/microsoft/compiler/dxil_signature.c
index b96e92c14fd..29e432c9647 100644
--- a/src/microsoft/compiler/dxil_signature.c
+++ b/src/microsoft/compiler/dxil_signature.c
@@ -183,13 +183,13 @@ get_additional_semantic_info(nir_shader *s, nir_variable *var, struct semantic_i
    return next_row;
 }
 
-typedef void (*semantic_info_proc)(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool vulkan);
+typedef void (*semantic_info_proc)(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool auto_link);
 
 static void
-get_semantic_vs_in_name(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool vulkan)
+get_semantic_vs_in_name(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool auto_link)
 {
    strcpy(info->name, "TEXCOORD");
-   if (vulkan) {
+   if (auto_link) {
       info->index = var->data.location >= VERT_ATTRIB_GENERIC0 ?
          var->data.location - VERT_ATTRIB_GENERIC0 :
          var->data.location;
@@ -200,7 +200,7 @@ get_semantic_vs_in_name(nir_variable *var, struct semantic_info *info, gl_shader
 }
 
 static void
-get_semantic_sv_name(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool _vulkan)
+get_semantic_sv_name(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool auto_link)
 {
    if (stage != MESA_SHADER_VERTEX)
       info->interpolation = get_interpolation(var);
@@ -272,7 +272,7 @@ get_semantic_ps_outname(nir_variable *var, struct semantic_info *info)
 
 static void
 get_semantic_name(nir_variable *var, struct semantic_info *info,
-                  const struct glsl_type *type, bool vulkan)
+                  const struct glsl_type *type, bool auto_link)
 {
    info->kind = DXIL_SEM_INVALID;
    info->interpolation = get_interpolation(var);
@@ -324,7 +324,7 @@ get_semantic_name(nir_variable *var, struct semantic_info *info,
       break;
 
    default: {
-         info->index =  vulkan ?
+         info->index =  auto_link ?
             var->data.location - VARYING_SLOT_VAR0 :
             var->data.driver_location;
          strcpy(info->name, "TEXCOORD");
@@ -334,14 +334,14 @@ get_semantic_name(nir_variable *var, struct semantic_info *info,
 }
 
 static void
-get_semantic_in_name(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool vulkan)
+get_semantic_in_name(nir_variable *var, struct semantic_info *info, gl_shader_stage stage, bool auto_link)
 {
    const struct glsl_type *type = var->type;
    if (nir_is_arrayed_io(var, stage) &&
        glsl_type_is_array(type))
       type = glsl_get_array_element(type);
 
-   get_semantic_name(var, info, type, vulkan);
+   get_semantic_name(var, info, type, auto_link);
    info->sysvalue_name = in_sysvalue_name(var);
 }
 
@@ -538,7 +538,7 @@ static unsigned
 get_input_signature_group(struct dxil_module *mod, const struct dxil_mdnode **inputs,
                           unsigned num_inputs,
                           nir_shader *s, nir_variable_mode modes,
-                          semantic_info_proc get_semantics, unsigned *row_iter, bool vulkan,
+                          semantic_info_proc get_semantics, unsigned *row_iter, bool auto_link,
                           unsigned input_clip_size)
 {
    nir_foreach_variable_with_modes(var, s, modes) {
@@ -546,7 +546,7 @@ get_input_signature_group(struct dxil_module *mod, const struct dxil_mdnode **in
          continue;
 
       struct semantic_info semantic = {0};
-      get_semantics(var, &semantic, s->info.stage, vulkan);
+      get_semantics(var, &semantic, s->info.stage, auto_link);
       mod->inputs[num_inputs].sysvalue = semantic.sysvalue_name;
       *row_iter = get_additional_semantic_info(s, var, &semantic, *row_iter, input_clip_size);
 
@@ -571,7 +571,7 @@ get_input_signature_group(struct dxil_module *mod, const struct dxil_mdnode **in
 }
 
 static const struct dxil_mdnode *
-get_input_signature(struct dxil_module *mod, nir_shader *s, bool vulkan, unsigned input_clip_size)
+get_input_signature(struct dxil_module *mod, nir_shader *s, bool auto_link, unsigned input_clip_size)
 {
    if (s->info.stage == MESA_SHADER_KERNEL)
       return NULL;
@@ -583,12 +583,12 @@ get_input_signature(struct dxil_module *mod, nir_shader *s, bool vulkan, unsigne
                                                    s, nir_var_shader_in,
                                                    s->info.stage == MESA_SHADER_VERTEX ?
                                                       get_semantic_vs_in_name : get_semantic_in_name,
-                                                   &next_row, vulkan, input_clip_size);
+                                                   &next_row, auto_link, input_clip_size);
 
    mod->num_sig_inputs = get_input_signature_group(mod, inputs, mod->num_sig_inputs,
                                                    s, nir_var_system_value,
                                                    get_semantic_sv_name,
-                                                   &next_row, vulkan, input_clip_size);
+                                                   &next_row, auto_link, input_clip_size);
 
    if (!mod->num_sig_inputs && !mod->num_sig_inputs)
       return NULL;
@@ -617,7 +617,7 @@ static const char *out_sysvalue_name(nir_variable *var)
 }
 
 static const struct dxil_mdnode *
-get_output_signature(struct dxil_module *mod, nir_shader *s, bool vulkan)
+get_output_signature(struct dxil_module *mod, nir_shader *s, bool auto_link)
 {
    const struct dxil_mdnode *outputs[VARYING_SLOT_MAX];
    unsigned num_outputs = 0;
@@ -634,7 +634,7 @@ get_output_signature(struct dxil_module *mod, nir_shader *s, bool vulkan)
          const struct glsl_type *type = var->type;
          if (nir_is_arrayed_io(var, s->info.stage))
             type = glsl_get_array_element(type);
-         get_semantic_name(var, &semantic, type, vulkan);
+         get_semantic_name(var, &semantic, type, auto_link);
          mod->outputs[num_outputs].sysvalue = out_sysvalue_name(var);
       }
       next_row = get_additional_semantic_info(s, var, &semantic, next_row, s->info.clip_distance_array_size);
@@ -707,7 +707,7 @@ patch_sysvalue_name(nir_variable *var)
 }
 
 static const struct dxil_mdnode *
-get_patch_const_signature(struct dxil_module *mod, nir_shader *s, bool vulkan)
+get_patch_const_signature(struct dxil_module *mod, nir_shader *s, bool auto_link)
 {
    if (s->info.stage != MESA_SHADER_TESS_CTRL &&
        s->info.stage != MESA_SHADER_TESS_EVAL)
@@ -724,7 +724,7 @@ get_patch_const_signature(struct dxil_module *mod, nir_shader *s, bool vulkan)
          continue;
 
       const struct glsl_type *type = var->type;
-      get_semantic_name(var, &semantic, type, vulkan);
+      get_semantic_name(var, &semantic, type, auto_link);
 
       mod->patch_consts[num_consts].sysvalue = patch_sysvalue_name(var);
       next_row = get_additional_semantic_info(s, var, &semantic, next_row, 0);
@@ -763,15 +763,15 @@ get_patch_const_signature(struct dxil_module *mod, nir_shader *s, bool vulkan)
 }
 
 const struct dxil_mdnode *
-get_signatures(struct dxil_module *mod, nir_shader *s, bool vulkan, unsigned input_clip_size)
+get_signatures(struct dxil_module *mod, nir_shader *s, bool auto_link, unsigned input_clip_size)
 {
    /* DXC does the same: Add an empty string before everything else */
    mod->sem_string_table = _mesa_string_buffer_create(mod->ralloc_ctx, 1024);
    copy_semantic_name_to_string(mod->sem_string_table, "");
 
-   const struct dxil_mdnode *input_signature = get_input_signature(mod, s, vulkan, input_clip_size);
-   const struct dxil_mdnode *output_signature = get_output_signature(mod, s, vulkan);
-   const struct dxil_mdnode *patch_const_signature = get_patch_const_signature(mod, s, vulkan);
+   const struct dxil_mdnode *input_signature = get_input_signature(mod, s, auto_link, input_clip_size);
+   const struct dxil_mdnode *output_signature = get_output_signature(mod, s, auto_link);
+   const struct dxil_mdnode *patch_const_signature = get_patch_const_signature(mod, s, auto_link);
 
    const struct dxil_mdnode *SV_nodes[3] = {
       input_signature,
diff --git a/src/microsoft/compiler/dxil_signature.h b/src/microsoft/compiler/dxil_signature.h
index fbae0f506b5..3a651b5c2e6 100644
--- a/src/microsoft/compiler/dxil_signature.h
+++ b/src/microsoft/compiler/dxil_signature.h
@@ -144,7 +144,7 @@ struct dxil_mdnode;
 struct dxil_module;
 
 const struct dxil_mdnode *
-get_signatures(struct dxil_module *mod, nir_shader *s, bool vulkan, unsigned input_clip_size);
+get_signatures(struct dxil_module *mod, nir_shader *s, bool auto_link, unsigned input_clip_size);
 
 #ifdef __cplusplus
 }
diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c
index 9ba770325f0..94d678e4009 100644
--- a/src/microsoft/compiler/nir_to_dxil.c
+++ b/src/microsoft/compiler/nir_to_dxil.c
@@ -5408,7 +5408,7 @@ emit_module(struct ntd_context *ctx, const struct nir_to_dxil_options *opts)
    unsigned input_clip_size = ctx->mod.shader_kind == DXIL_PIXEL_SHADER ?
       ctx->shader->info.clip_distance_array_size : ctx->opts->input_clip_size;
    const struct dxil_mdnode *signatures = get_signatures(&ctx->mod, ctx->shader,
-                                                         ctx->opts->environment == DXIL_ENVIRONMENT_VULKAN,
+                                                         ctx->opts->auto_link,
                                                          input_clip_size);
 
    nir_foreach_function(func, ctx->shader) {
diff --git a/src/microsoft/compiler/nir_to_dxil.h b/src/microsoft/compiler/nir_to_dxil.h
index 2ae412418d7..97221119577 100644
--- a/src/microsoft/compiler/nir_to_dxil.h
+++ b/src/microsoft/compiler/nir_to_dxil.h
@@ -90,6 +90,7 @@ struct nir_to_dxil_options {
    unsigned num_kernel_globals;
    unsigned input_clip_size;
    enum dxil_environment environment;
+   bool auto_link;
 };
 
 bool
diff --git a/src/microsoft/spirv_to_dxil/spirv_to_dxil.c b/src/microsoft/spirv_to_dxil/spirv_to_dxil.c
index dce41ad2327..4564e67726f 100644
--- a/src/microsoft/spirv_to_dxil/spirv_to_dxil.c
+++ b/src/microsoft/spirv_to_dxil/spirv_to_dxil.c
@@ -134,7 +134,10 @@ spirv_to_dxil(const uint32_t *words, size_t word_count,
    if (dgb_opts->dump_nir)
       nir_print_shader(nir, stderr);
 
-   struct nir_to_dxil_options opts = {.environment = DXIL_ENVIRONMENT_VULKAN};
+   struct nir_to_dxil_options opts = {
+      .environment = DXIL_ENVIRONMENT_VULKAN,
+      .auto_link = true,
+   };
    struct blob dxil_blob;
    if (!nir_to_dxil(nir, &opts, &dxil_blob)) {
       if (dxil_blob.allocated)



More information about the mesa-commit mailing list