Browse Source

[spirv] Handle invalid arg for residency code. (#3064)

* [spirv] Handle invalid arg for residency code.

Fixes #3045

* add comments about residencyCode.
Ehsan 5 years ago
parent
commit
0e04763f9e

+ 9 - 0
tools/clang/lib/SPIRV/SpirvEmitter.cpp

@@ -3225,6 +3225,15 @@ SpirvInstruction *SpirvEmitter::processBufferTextureLoad(
     return nullptr;
   }
 
+  // If residencyCode is nullptr, we are dealing with a Load method with 2
+  // arguments which does not return the operation status.
+  if (residencyCode && residencyCode->isRValue()) {
+    emitError(
+        "an lvalue argument should be used for returning the operation status",
+        loc);
+    return nullptr;
+  }
+
   // OpImageFetch and OpImageRead can only fetch a vector of 4 elements.
   const QualType texelType = astContext.getExtVectorType(elemType, 4u);
   auto *texel = spvBuilder.createImageFetchOrRead(

+ 12 - 0
tools/clang/test/CodeGenSPIRV/method.rwtexture.load.invalid-residency-arg.hlsl

@@ -0,0 +1,12 @@
+// Run: %dxc -T cs_6_0 -E main
+
+RWStructuredBuffer<uint> g_output : register(u1, space0);
+RWTexture2D<uint> g_rwtexture2d : register(u1, space3);
+[numthreads(64, 1, 1)] void main(int threadId : SV_DispatchThreadID)
+{
+  // The second argument for Load must be a variable where the function can
+  // write the operation result Status.
+  //
+  // CHECK: 11:24: error: an lvalue argument should be used for returning the operation status
+  g_output[threadId] = g_rwtexture2d.Load(0, 0);
+}

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

@@ -980,6 +980,13 @@ TEST_F(FileTest, BufferGetDimensions) {
 
 // For RWTexture methods
 TEST_F(FileTest, RWTextureLoad) { runFileTest("method.rwtexture.load.hlsl"); }
+
+TEST_F(FileTest, RWTextureLoadInvalidResidencyCode) {
+
+  runFileTest("method.rwtexture.load.invalid-residency-arg.hlsl",
+              Expect::Failure);
+}
+
 TEST_F(FileTest, RWTextureGetDimensions) {
   runFileTest("method.rwtexture.get-dimensions.hlsl");
 }