瀏覽代碼

[spirv] Fixes for DrefGather tests.

Ehsan Nasiri 6 年之前
父節點
當前提交
e93d86693b

+ 6 - 2
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -835,7 +835,7 @@ SpirvInstruction *SPIRVEmitter::loadIfGLValue(const Expr *expr) {
 SpirvInstruction *SPIRVEmitter::loadIfGLValue(const Expr *expr,
                                               SpirvInstruction *info) {
   // Do nothing if this is already rvalue
-  if (info->isRValue())
+  if (!info || info->isRValue())
     return info;
 
   // Check whether we are trying to load an array of opaque objects as a whole.
@@ -1811,6 +1811,9 @@ void SPIRVEmitter::doReturnStmt(const ReturnStmt *stmt) {
     tryToAssignCounterVar(curFunction, retVal);
 
     auto *retInfo = loadIfGLValue(retVal);
+    if (!retInfo)
+      return;
+
     auto retType = retVal->getType();
     if (retInfo->getStorageClass() != spv::StorageClass::Function &&
         retType->isStructureType()) {
@@ -3912,7 +3915,8 @@ SPIRVEmitter::processIntrinsicMemberCall(const CXXMemberCallExpr *expr,
     return nullptr;
   }
 
-  retVal->setRValue();
+  if(retVal)
+    retVal->setRValue();
   return retVal;
 }
 

+ 5 - 0
tools/clang/lib/SPIRV/SpirvBuilder.cpp

@@ -539,6 +539,11 @@ SpirvInstruction *SpirvBuilder::createImageGather(
                           : (residencyCode ? spv::Op::OpImageSparseGather
                                            : spv::Op::OpImageGather);
 
+  // Note: OpImageSparseDrefGather and OpImageDrefGather do not take the
+  // component parameter.
+  if (compareVal)
+    component = nullptr;
+
   auto *imageInstruction = new (context) SpirvImageOp(
       op, texelType, /*id*/ 0, loc, sampledImage, coordinate, mask, compareVal,
       /*bias*/ nullptr, /*lod*/ nullptr, /*gradDx*/ nullptr,

+ 3 - 5
tools/clang/test/CodeGenSPIRV/texture.array.gather-cmp-red.hlsl

@@ -9,18 +9,16 @@ TextureCubeArray<int4> tCubeArray : register(t3);
 
 // CHECK: OpCapability SparseResidency
 
+// CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4uint
+// CHECK: %SparseResidencyStruct_0 = OpTypeStruct %uint %v4int
+
 // CHECK:      [[c12:%\d+]] = OpConstantComposite %v2int %int_1 %int_2
 // CHECK:      [[c34:%\d+]] = OpConstantComposite %v2int %int_3 %int_4
 // CHECK:      [[c56:%\d+]] = OpConstantComposite %v2int %int_5 %int_6
 // CHECK:      [[c78:%\d+]] = OpConstantComposite %v2int %int_7 %int_8
 // CHECK:    [[c1to8:%\d+]] = OpConstantComposite %_arr_v2int_uint_4 [[c12]] [[c34]] [[c56]] [[c78]]
-
-// CHECK: %SparseResidencyStruct = OpTypeStruct %uint %v4uint
-
 // CHECK: [[cv4f_1_5:%\d+]] = OpConstantComposite %v4float %float_1_5 %float_1_5 %float_1_5 %float_1_5
 
-// CHECK: %SparseResidencyStruct_0 = OpTypeStruct %uint %v4int
-
 float4 main(float3 location: A, float comparator: B) : SV_Target {
 // CHECK:            [[t2f4:%\d+]] = OpLoad %type_2d_image_array %t2f4
 // CHECK-NEXT:   [[gSampler:%\d+]] = OpLoad %type_sampler %gSampler