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

Author: Connor Abbott <[email protected]>
Date:   Fri Nov 25 12:41:46 2022 +0100

nir, spirv: Add support for VK_EXT_fragment_density_map

This involves two new system values.

Reviewed-by: Faith Ekstrand <[email protected]>
Reviewed-by: Emma Anholt <[email protected]>
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20303>

---

 src/compiler/nir/nir.c             | 8 ++++++++
 src/compiler/nir/nir_intrinsics.py | 2 ++
 src/compiler/shader_enums.c        | 2 ++
 src/compiler/shader_enums.h        | 7 +++++++
 src/compiler/shader_info.h         | 1 +
 src/compiler/spirv/spirv_to_nir.c  | 4 ++++
 src/compiler/spirv/vtn_variables.c | 8 ++++++++
 7 files changed, 32 insertions(+)

diff --git a/src/compiler/nir/nir.c b/src/compiler/nir/nir.c
index b19c5487194..279cc571c37 100644
--- a/src/compiler/nir/nir.c
+++ b/src/compiler/nir/nir.c
@@ -2503,6 +2503,10 @@ nir_intrinsic_from_system_value(gl_system_value val)
       return nir_intrinsic_load_frag_shading_rate;
    case SYSTEM_VALUE_FULLY_COVERED:
       return nir_intrinsic_load_fully_covered;
+   case SYSTEM_VALUE_FRAG_SIZE:
+      return nir_intrinsic_load_frag_size;
+   case SYSTEM_VALUE_FRAG_INVOCATION_COUNT:
+      return nir_intrinsic_load_frag_invocation_count;
    default:
       unreachable("system value does not directly correspond to intrinsic");
    }
@@ -2652,6 +2656,10 @@ nir_system_value_from_intrinsic(nir_intrinsic_op intrin)
       return SYSTEM_VALUE_MESH_VIEW_COUNT;
    case nir_intrinsic_load_fully_covered:
       return SYSTEM_VALUE_FULLY_COVERED;
+   case nir_intrinsic_load_frag_size:
+      return SYSTEM_VALUE_FRAG_SIZE;
+   case nir_intrinsic_load_frag_invocation_count:
+      return SYSTEM_VALUE_FRAG_INVOCATION_COUNT;
    default:
       unreachable("intrinsic doesn't produce a system value");
    }
diff --git a/src/compiler/nir/nir_intrinsics.py 
b/src/compiler/nir/nir_intrinsics.py
index 3fecd17f07b..fcb8a9885c0 100644
--- a/src/compiler/nir/nir_intrinsics.py
+++ b/src/compiler/nir/nir_intrinsics.py
@@ -866,6 +866,8 @@ system_value("shared_base_ptr", 0, bit_sizes=[32,64])
 system_value("global_base_ptr", 0, bit_sizes=[32,64])
 # Address of a transform feedback buffer, indexed by BASE
 system_value("xfb_address", 1, bit_sizes=[32,64], indices=[BASE])
+system_value("frag_size", 2)
+system_value("frag_invocation_count", 1)
 
 # System values for ray tracing.
 system_value("ray_launch_id", 3)
diff --git a/src/compiler/shader_enums.c b/src/compiler/shader_enums.c
index 1778d7cf56c..9d22432960a 100644
--- a/src/compiler/shader_enums.c
+++ b/src/compiler/shader_enums.c
@@ -339,6 +339,8 @@ gl_system_value_name(gl_system_value sysval)
      ENUM(SYSTEM_VALUE_REL_PATCH_ID_IR3),
      ENUM(SYSTEM_VALUE_FRAG_SHADING_RATE),
      ENUM(SYSTEM_VALUE_FULLY_COVERED),
+     ENUM(SYSTEM_VALUE_FRAG_SIZE),
+     ENUM(SYSTEM_VALUE_FRAG_INVOCATION_COUNT),
    };
    STATIC_ASSERT(ARRAY_SIZE(names) == SYSTEM_VALUE_MAX);
    return NAME(sysval);
diff --git a/src/compiler/shader_enums.h b/src/compiler/shader_enums.h
index 004e733e79b..2dfca1d7651 100644
--- a/src/compiler/shader_enums.h
+++ b/src/compiler/shader_enums.h
@@ -875,6 +875,13 @@ typedef enum
     */
    SYSTEM_VALUE_FULLY_COVERED,
 
+   /*
+    * Fragment size and invocation count used for
+    * EXT_fragment_invocation_density (Vulkan).
+    */
+   SYSTEM_VALUE_FRAG_SIZE,
+   SYSTEM_VALUE_FRAG_INVOCATION_COUNT,
+
    SYSTEM_VALUE_MAX             /**< Number of values */
 } gl_system_value;
 
diff --git a/src/compiler/shader_info.h b/src/compiler/shader_info.h
index d3a978b5c45..c511b401a82 100644
--- a/src/compiler/shader_info.h
+++ b/src/compiler/shader_info.h
@@ -63,6 +63,7 @@ struct spirv_supported_capabilities {
    bool float64_atomic_add;
    bool float64_atomic_min_max;
    bool float64;
+   bool fragment_density;
    bool fragment_fully_covered;
    bool fragment_shader_pixel_interlock;
    bool fragment_shader_sample_interlock;
diff --git a/src/compiler/spirv/spirv_to_nir.c 
b/src/compiler/spirv/spirv_to_nir.c
index a2c0bd623bb..5cb7691506e 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -4893,6 +4893,10 @@ vtn_handle_preamble_instruction(struct vtn_builder *b, 
SpvOp opcode,
          spv_check_supported(fragment_fully_covered, cap);
          break;
 
+      case SpvCapabilityFragmentDensityEXT:
+         spv_check_supported(fragment_density, cap);
+         break;
+
       default:
          vtn_fail("Unhandled capability: %s (%u)",
                   spirv_capability_to_string(cap), cap);
diff --git a/src/compiler/spirv/vtn_variables.c 
b/src/compiler/spirv/vtn_variables.c
index a666bedf9bd..805831eb568 100644
--- a/src/compiler/spirv/vtn_variables.c
+++ b/src/compiler/spirv/vtn_variables.c
@@ -1174,6 +1174,14 @@ vtn_get_builtin_location(struct vtn_builder *b,
       *location = SYSTEM_VALUE_FULLY_COVERED;
       set_mode_system_value(b, mode);
       break;
+   case SpvBuiltInFragSizeEXT:
+      *location = SYSTEM_VALUE_FRAG_SIZE;
+      set_mode_system_value(b, mode);
+      break;
+   case SpvBuiltInFragInvocationCountEXT:
+      *location = SYSTEM_VALUE_FRAG_INVOCATION_COUNT;
+      set_mode_system_value(b, mode);
+      break;
 
    default:
       vtn_fail("Unsupported builtin: %s (%u)",

Reply via email to