瀏覽代碼

[spirv] Handle resource templated by vecc1. (#3098)

Ehsan 5 年之前
父節點
當前提交
fd65d32733
共有 2 個文件被更改,包括 14 次插入3 次删除
  1. 9 3
      tools/clang/lib/SPIRV/SpirvEmitter.cpp
  2. 5 0
      tools/clang/test/CodeGenSPIRV/method.rwtexture.load.hlsl

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

@@ -3262,9 +3262,15 @@ SpirvInstruction *SpirvEmitter::processBufferTextureLoad(
     }
   }
 
-  if (!elemType->isFloatingType() && !elemType->isIntegerType()) {
-    emitError("loading %0 value unsupported", object->getExprLoc()) << type;
-    return nullptr;
+  {
+    // Treat a vector of size 1 the same as a scalar.
+    if (hlsl::IsHLSLVecType(elemType) && hlsl::GetHLSLVecSize(elemType) == 1)
+      elemType = hlsl::GetHLSLVecElementType(elemType);
+
+    if (!elemType->isFloatingType() && !elemType->isIntegerType()) {
+      emitError("loading %0 value unsupported", object->getExprLoc()) << type;
+      return nullptr;
+    }
   }
 
   // If residencyCode is nullptr, we are dealing with a Load method with 2

+ 5 - 0
tools/clang/test/CodeGenSPIRV/method.rwtexture.load.hlsl

@@ -5,6 +5,7 @@ RWTexture2D<uint2> uint2buf;
 RWTexture3D<float3> float3buf;
 RWTexture1DArray<float4> float4buf;
 RWTexture2DArray<int3> int3buf;
+RWTexture2D<float> vec1buf;
 
 // CHECK: OpCapability SparseResidency
 
@@ -43,6 +44,10 @@ void main() {
 // CHECK-NEXT: OpStore %e [[r5]]
   int3 e   = int3buf.Load(0);
 
+// CHECK:      [[img6:%\d+]] = OpLoad %type_2d_image_0 %vec1buf
+// CHECK-NEXT:      {{%\d+}} = OpImageRead %v4float [[img6]] {{%\d+}} None
+  float f = vec1buf.Load(0);
+
   uint status;
 // CHECK:              [[img1:%\d+]] = OpLoad %type_1d_image %intbuf
 // CHECK-NEXT: [[structResult:%\d+]] = OpImageSparseRead %SparseResidencyStruct [[img1]] %int_0 None