nir, spirv: Add support for VK_EXT_fragment_density_map
authorConnor Abbott <cwabbott0@gmail.com>
Fri, 25 Nov 2022 11:41:46 +0000 (12:41 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 4 Apr 2023 13:14:35 +0000 (13:14 +0000)
This involves two new system values.

Reviewed-by: Faith Ekstrand <faith@gfxstrand.net>
Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20303>

src/compiler/nir/nir.c
src/compiler/nir/nir_intrinsics.py
src/compiler/shader_enums.c
src/compiler/shader_enums.h
src/compiler/shader_info.h
src/compiler/spirv/spirv_to_nir.c
src/compiler/spirv/vtn_variables.c

index b19c548..279cc57 100644 (file)
@@ -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");
    }
index 3fecd17..fcb8a98 100644 (file)
@@ -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)
index 1778d7c..9d22432 100644 (file)
@@ -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);
index 004e733..2dfca1d 100644 (file)
@@ -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;
 
index d3a978b..c511b40 100644 (file)
@@ -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;
index a2c0bd6..5cb7691 100644 (file)
@@ -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);
index a666bed..805831e 100644 (file)
@@ -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)",