spirv: Let spirv_to_nir() users turn sysvals into input varyings
authorBoris Brezillon <boris.brezillon@collabora.com>
Mon, 27 Sep 2021 13:05:44 +0000 (15:05 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 7 Oct 2021 19:45:35 +0000 (19:45 +0000)
This is an attempt at simplifying the spirv_to_nir() backend when it
comes to choosing between system values and input varyings. Let's patch
drivers to do the sysval to input varying conversion on their own so we
can get rid of the frag_coord_is_varying field in spirv_to_nir_options
and unconditionally create create sysvals for FragCoord, FrontFacing and
PointCoord inputs instead of adding new xxx_is_{sysval,varying} flags.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Suggested-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Hyunjun Ko <zzoon@igalia.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13017>

src/amd/vulkan/radv_shader.c
src/broadcom/vulkan/v3dv_pipeline.c
src/freedreno/vulkan/tu_shader.c
src/gallium/drivers/freedreno/ir3/ir3_cmdline.c
src/gallium/frontends/lavapipe/lvp_pipeline.c
src/intel/vulkan/anv_pipeline.c
src/mesa/main/glspirv.c
src/panfrost/vulkan/panvk_vX_shader.c

index 33d68f6..5de1d48 100644 (file)
@@ -536,6 +536,11 @@ radv_shader_compile_to_nir(struct radv_device *device, struct vk_shader_module *
 
       free(spec_entries);
 
+      const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+         .point_coord = true,
+      };
+      NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
       /* We have to lower away local constant initializers right before we
        * inline functions.  That way they get properly initialized at the top
        * of the function and not at the top of its caller.
index c65120b..42e3032 100644 (file)
@@ -467,6 +467,12 @@ shader_module_compile_to_nir(struct v3dv_device *device,
    }
    assert(nir->info.stage == broadcom_shader_stage_to_gl(stage->stage));
 
+   const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+      .frag_coord = true,
+      .point_coord = true,
+   };
+   NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
    if (unlikely(V3D_DEBUG & (V3D_DEBUG_NIR |
                              v3d_debug_flag_for_shader_stage(
                                 broadcom_shader_stage_to_gl(stage->stage))))) {
index a1671e2..f4d4e07 100644 (file)
@@ -112,6 +112,11 @@ tu_spirv_to_nir(struct tu_device *dev,
    assert(nir->info.stage == stage);
    nir_validate_shader(nir, "after spirv_to_nir");
 
+   const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+      .point_coord = true,
+   };
+   NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
    if (unlikely(dev->physical_device->instance->debug_flags & TU_DEBUG_NIR)) {
       fprintf(stderr, "translated nir:\n");
       nir_print_shader(nir, stderr);
index 3a33f15..88ff834 100644 (file)
@@ -251,6 +251,12 @@ load_spirv(const char *filename, const char *entry, gl_shader_stage stage)
                       stage, entry, &spirv_options,
                       ir3_get_compiler_options(compiler));
 
+   const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+      .frag_coord = true,
+      .point_coord = true,
+   };
+   NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
    nir_print_shader(nir, stdout);
 
    return nir;
index 227ba68..ea3972c 100644 (file)
@@ -529,6 +529,12 @@ lvp_shader_compile_to_ir(struct lvp_pipeline *pipeline,
 
    free(spec_entries);
 
+   const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+      .frag_coord = true,
+      .point_coord = true,
+   };
+   NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
    NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
    NIR_PASS_V(nir, nir_lower_returns);
    NIR_PASS_V(nir, nir_inline_functions);
index 0ca0568..61e6cdd 100644 (file)
@@ -194,6 +194,11 @@ anv_shader_compile_to_nir(struct anv_device *device,
 
    free(spec_entries);
 
+   const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+      .point_coord = true,
+   };
+   NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
    if (INTEL_DEBUG & intel_debug_flag_for_shader_stage(stage)) {
       fprintf(stderr, "NIR (from SPIR-V) for %s shader:\n",
               gl_shader_stage_name(stage));
index 1668be0..eecb91a 100644 (file)
@@ -279,6 +279,14 @@ _mesa_spirv_to_nir(struct gl_context *ctx,
 
    nir->info.separate_shader = linked_shader->Program->info.separate_shader;
 
+   /* Convert some sysvals to input varyings. */
+   const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+      .frag_coord = !ctx->Const.GLSLFragCoordIsSysVal,
+      .point_coord = !ctx->Const.GLSLPointCoordIsSysVal,
+      .front_face = !ctx->Const.GLSLFrontFacingIsSysVal,
+   };
+   NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
    /* We have to lower away local constant initializers right before we
     * inline functions.  That way they get properly initialized at the top
     * of the function and not at the top of its caller.
index c679b95..4cab9aa 100644 (file)
@@ -69,6 +69,13 @@ panvk_spirv_to_nir(const void *code,
    assert(nir->info.stage == stage);
    nir_validate_shader(nir, "after spirv_to_nir");
 
+   const struct nir_lower_sysvals_to_varyings_options sysvals_to_varyings = {
+      .frag_coord = PAN_ARCH <= 5,
+      .point_coord = PAN_ARCH <= 5,
+      .front_face = PAN_ARCH <= 5,
+   };
+   NIR_PASS_V(nir, nir_lower_sysvals_to_varyings, &sysvals_to_varyings);
+
    return nir;
 }