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

Author: Marek Olšák <[email protected]>
Date:   Sat Nov 18 22:44:56 2023 -0500

nir: add lowering from FS LAYER input to LAYER_ID sysval

Reviewed-by: Qiang Yu <[email protected]>
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26274>

---

 src/compiler/nir/nir.c                     | 4 ++++
 src/compiler/nir/nir.h                     | 3 +++
 src/compiler/nir/nir_lower_system_values.c | 8 ++++++++
 src/compiler/shader_enums.c                | 1 +
 src/compiler/shader_enums.h                | 1 +
 5 files changed, 17 insertions(+)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index a5922284e2f..00860a06a86 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -2195,6 +2195,8 @@ nir_intrinsic_from_system_value(gl_system_value val)
       return nir_intrinsic_load_sample_pos_or_center;
    case SYSTEM_VALUE_SAMPLE_MASK_IN:
       return nir_intrinsic_load_sample_mask_in;
+   case SYSTEM_VALUE_LAYER_ID:
+      return nir_intrinsic_load_layer_id;
    case SYSTEM_VALUE_LOCAL_INVOCATION_ID:
       return nir_intrinsic_load_local_invocation_id;
    case SYSTEM_VALUE_LOCAL_INVOCATION_INDEX:
@@ -2348,6 +2350,8 @@ nir_system_value_from_intrinsic(nir_intrinsic_op intrin)
       return SYSTEM_VALUE_SAMPLE_POS_OR_CENTER;
    case nir_intrinsic_load_sample_mask_in:
       return SYSTEM_VALUE_SAMPLE_MASK_IN;
+   case nir_intrinsic_load_layer_id:
+      return SYSTEM_VALUE_LAYER_ID;
    case nir_intrinsic_load_local_invocation_id:
       return SYSTEM_VALUE_LOCAL_INVOCATION_ID;
    case nir_intrinsic_load_local_invocation_index:
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 44aea715501..40417cdfb09 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -4019,6 +4019,9 @@ typedef struct nir_shader_compiler_options {
 
    /** Lower f2f16 to f2f16_rtz when execution mode is not rtne. */
    bool force_f2f16_rtz;
+
+   /** Lower VARYING_SLOT_LAYER in FS to SYSTEM_VALUE_LAYER_ID. */
+   bool lower_layer_fs_input_to_sysval;
 } nir_shader_compiler_options;
 
 typedef struct nir_shader {
diff --git a/src/compiler/nir/nir_lower_system_values.c 
b/src/compiler/nir/nir_lower_system_values.c
index b419b9cf0c6..c2e919af18b 100644
--- a/src/compiler/nir/nir_lower_system_values.c
+++ b/src/compiler/nir/nir_lower_system_values.c
@@ -146,6 +146,14 @@ lower_system_value_instr(nir_builder *b, nir_instr *instr, 
void *_state)
       }
    }
 
+   case nir_intrinsic_load_input:
+      if (b->shader->options->lower_layer_fs_input_to_sysval &&
+          b->shader->info.stage == MESA_SHADER_FRAGMENT &&
+          nir_intrinsic_io_semantics(intrin).location == VARYING_SLOT_LAYER)
+         return nir_load_layer_id(b);
+      else
+         return NULL;
+
    case nir_intrinsic_load_deref: {
       nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
       if (!nir_deref_mode_is(deref, nir_var_system_value))
diff --git a/src/compiler/shader_enums.c b/src/compiler/shader_enums.c
index 0981614ecbd..712f3b1cc26 100644
--- a/src/compiler/shader_enums.c
+++ b/src/compiler/shader_enums.c
@@ -333,6 +333,7 @@ gl_system_value_name(gl_system_value sysval)
      ENUM(SYSTEM_VALUE_SAMPLE_ID),
      ENUM(SYSTEM_VALUE_SAMPLE_POS),
      ENUM(SYSTEM_VALUE_SAMPLE_MASK_IN),
+     ENUM(SYSTEM_VALUE_LAYER_ID),
      ENUM(SYSTEM_VALUE_HELPER_INVOCATION),
      ENUM(SYSTEM_VALUE_COLOR0),
      ENUM(SYSTEM_VALUE_COLOR1),
diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index 45c89d49d65..62a0bb207c0 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -788,6 +788,7 @@ typedef enum
    SYSTEM_VALUE_SAMPLE_POS,
    SYSTEM_VALUE_SAMPLE_POS_OR_CENTER,
    SYSTEM_VALUE_SAMPLE_MASK_IN,
+   SYSTEM_VALUE_LAYER_ID,
    SYSTEM_VALUE_HELPER_INVOCATION,
    SYSTEM_VALUE_COLOR0,
    SYSTEM_VALUE_COLOR1,

Reply via email to