Ver código fonte

Remove binding number overlap. (#2592)

We should not be reporting the binding number overlap as some overlaps
may be resolved by variables that are optimized away by spirv-opt.
Ehsan 5 anos atrás
pai
commit
6b925dbcbe

+ 6 - 8
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -756,7 +756,7 @@ SpirvVariable *DeclResultIdMapper::createStructOrStructArrayVarOfExplicitLayout(
   llvm::SmallVector<HybridStructType::FieldInfo, 4> fields;
   for (const auto *subDecl : declGroup) {
     // 'groupshared' variables should not be placed in $Globals cbuffer.
-    if(forGlobals && subDecl->hasAttr<HLSLGroupSharedAttr>())
+    if (forGlobals && subDecl->hasAttr<HLSLGroupSharedAttr>())
       continue;
 
     // The field can only be FieldDecl (for normal structs) or VarDecl (for
@@ -981,7 +981,7 @@ void DeclResultIdMapper::createGlobalsCBuffer(const VarDecl *var) {
   uint32_t index = 0;
   for (const auto *decl : collectDeclsInDeclContext(context)) {
     // 'groupshared' variables should not be placed in $Globals cbuffer.
-    if(decl->hasAttr<HLSLGroupSharedAttr>())
+    if (decl->hasAttr<HLSLGroupSharedAttr>())
       continue;
     if (const auto *varDecl = dyn_cast<VarDecl>(decl)) {
       if (!spirvOptions.noWarnIgnoredFeatures) {
@@ -1611,12 +1611,10 @@ bool DeclResultIdMapper::decorateResourceBindings() {
 
     for (uint32_t i = 0; i < numBindingsToUse; ++i) {
       bool success = bindingSet.useBinding(bindingNo + i, setNo);
-      if (!success && spirvOptions.flattenResourceArrays) {
-        emitError("ran into binding number conflict when assigning binding "
-                  "number %0 in set %1",
-                  {})
-            << bindingNo << setNo;
-      }
+      // We will not emit an error if we find a set/binding overlap because it
+      // is possible that the optimizer optimizes away a resource which resolves
+      // the overlap.
+      (void)success;
     }
 
     // No need to decorate multiple binding numbers for arrays. It will be done

+ 0 - 19
tools/clang/test/CodeGenSPIRV/vk.binding.cl.flatten-arrays.error.hlsl

@@ -1,19 +0,0 @@
-// Run: %dxc -T ps_6_0 -E main -fspv-flatten-resource-arrays
-
-// CHECK: error: ran into binding number conflict when assigning binding number 3 in set 0
-
-Texture2D    MyTextures[5] : register(t0); // Forced use of binding numbers 0, 1, 2, 3, 4.
-Texture2D    AnotherTexture : register(t3); // Error: Forced use of binding number 3.
-SamplerState MySampler;
-
-float4 main(float2 TexCoord : TexCoord) : SV_Target0 {
-  float4 result =
-    MyTextures[0].Sample(MySampler, TexCoord) +
-    MyTextures[1].Sample(MySampler, TexCoord) +
-    MyTextures[2].Sample(MySampler, TexCoord) +
-    MyTextures[3].Sample(MySampler, TexCoord) +
-    MyTextures[4].Sample(MySampler, TexCoord) +
-    AnotherTexture.Sample(MySampler, TexCoord);
-  return result;
-}
-

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

@@ -1690,9 +1690,6 @@ TEST_F(FileTest, FlattenResourceArrayBindings2Optimized) {
 TEST_F(FileTest, FlattenResourceArrayBindings3) {
   runFileTest("vk.binding.cl.flatten-arrays.example3.hlsl");
 }
-TEST_F(FileTest, FlattenResourceArrayBindingsOverlapError) {
-  runFileTest("vk.binding.cl.flatten-arrays.error.hlsl", Expect::Failure);
-}
 
 // For testing the "-auto-binding-space" command line option which specifies the
 // "default space" for resources.