2
0
Эх сурвалжийг харах

[spirv] Support for post_depth_coverage extension. (#1461)

Ehsan 7 жил өмнө
parent
commit
f9882c84a7

+ 2 - 0
docs/SPIR-V.rst

@@ -261,6 +261,8 @@ The namespace ``vk`` will be used for all Vulkan attributes:
   and struct fields.
 - ``index(X)``: For specifying the index at a specific pixel shader output
   location. Used for dual-source blending.
+- ``post_depth_coverage``: The input variable decorated with SampleMask will
+  reflect the result of the EarlyFragmentTests. Only valid on pixel shader entry points.
 
 Only ``vk::`` attributes in the above list are supported. Other attributes will
 result in warnings and be ignored by the compiler. All C++11 attributes will

+ 7 - 0
tools/clang/include/clang/Basic/Attr.td

@@ -961,6 +961,13 @@ def VKConstantId : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def VKPostDepthCoverage : InheritableAttr {
+  let Spellings = [CXX11<"vk", "post_depth_coverage">];
+  let Subjects = SubjectList<[Function], ErrorDiag>;
+  let LangOpts = [SPIRV];
+  let Documentation = [Undocumented];
+}
+
 // SPIRV Change Ends
 
 def C11NoReturn : InheritableAttr {

+ 1 - 0
tools/clang/include/clang/SPIRV/FeatureManager.h

@@ -34,6 +34,7 @@ enum class Extension {
   KHR_device_group,
   KHR_multiview,
   KHR_shader_draw_parameters,
+  KHR_post_depth_coverage,
   EXT_descriptor_indexing,
   EXT_fragment_fully_covered,
   EXT_shader_stencil_export,

+ 4 - 0
tools/clang/lib/SPIRV/FeatureManager.cpp

@@ -113,6 +113,8 @@ Extension FeatureManager::getExtensionSymbol(llvm::StringRef name) {
             Extension::AMD_shader_explicit_vertex_parameter)
       .Case("SPV_GOOGLE_hlsl_functionality1",
             Extension::GOOGLE_hlsl_functionality1)
+      .Case("SPV_KHR_post_depth_coverage",
+            Extension::KHR_post_depth_coverage)
       .Default(Extension::Unknown);
 }
 
@@ -128,6 +130,8 @@ const char *FeatureManager::getExtensionName(Extension symbol) {
     return "SPV_KHR_multiview";
   case Extension::KHR_shader_draw_parameters:
     return "SPV_KHR_shader_draw_parameters";
+  case Extension::KHR_post_depth_coverage:
+    return "SPV_KHR_post_depth_coverage";
   case Extension::EXT_descriptor_indexing:
     return "SPV_EXT_descriptor_indexing";
   case Extension::EXT_fragment_fully_covered:

+ 7 - 0
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -9233,6 +9233,13 @@ void SPIRVEmitter::processPixelShaderAttributes(const FunctionDecl *decl) {
     theBuilder.addExecutionMode(entryFunctionId,
                                 spv::ExecutionMode::EarlyFragmentTests, {});
   }
+  if (decl->getAttr<VKPostDepthCoverageAttr>()) {
+    theBuilder.addExtension(Extension::KHR_post_depth_coverage,
+                            "[[vk::post_depth_coverage]]", decl->getLocation());
+    theBuilder.requireCapability(spv::Capability::SampleMaskPostDepthCoverage);
+    theBuilder.addExecutionMode(entryFunctionId,
+                                spv::ExecutionMode::PostDepthCoverage, {});
+  }
 }
 
 void SPIRVEmitter::processComputeShaderAttributes(const FunctionDecl *decl) {

+ 3 - 0
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -10552,6 +10552,9 @@ void hlsl::HandleDeclAttributeForHLSL(Sema &S, Decl *D, const AttributeList &A,
     declAttr = ::new (S.Context) VKConstantIdAttr(A.getRange(), S.Context,
       ValidateAttributeIntArg(S, A), A.getAttributeSpellingListIndex());
     break;
+  case AttributeList::AT_VKPostDepthCoverage:
+    declAttr = ::new (S.Context) VKPostDepthCoverageAttr(A.getRange(), S.Context, A.getAttributeSpellingListIndex());
+    break;
   default:
     Handled = false;
     return;

+ 8 - 0
tools/clang/test/CodeGenSPIRV/attribute.postdepthcoverage.ps.hlsl

@@ -0,0 +1,8 @@
+// Run: %dxc -T ps_6_0 -E main
+
+// CHECK: OpCapability SampleMaskPostDepthCoverage
+// CHECK: OpExtension "SPV_KHR_post_depth_coverage"
+// CHECK: OpExecutionMode %main PostDepthCoverage
+
+[[vk::post_depth_coverage]]
+float4 main() : SV_Target { return 1.0; }

+ 3 - 0
tools/clang/unittests/SPIRV/CodeGenSPIRVTest.cpp

@@ -1008,6 +1008,9 @@ TEST_F(FileTest, IntrinsicsNonUniformResourceIndex) {
 TEST_F(FileTest, AttributeEarlyDepthStencil) {
   runFileTest("attribute.earlydepthstencil.ps.hlsl");
 }
+TEST_F(FileTest, AttributePostDepthCoverage) {
+  runFileTest("attribute.postdepthcoverage.ps.hlsl");
+}
 TEST_F(FileTest, AttributeNumThreads) {
   runFileTest("attribute.numthreads.hlsl");
 }