Ver código fonte

[spirv] Fix [[vk::push_constant]] on ConstantBuffer part II (#3216)

I wasn't noticing that the last fix #3215 only fixed the error-checking. It was generating an OpTypeStruct without any member.

This commit fixes that push constant should use the templated type of constant buffer to create the struct.
Junda Liu 4 anos atrás
pai
commit
6c34f5f7f5

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

@@ -1090,7 +1090,14 @@ SpirvVariable *DeclResultIdMapper::createCTBuffer(const VarDecl *decl) {
 
 SpirvVariable *DeclResultIdMapper::createPushConstant(const VarDecl *decl) {
   // The front-end errors out if non-struct type push constant is used.
-  const auto *recordType = decl->getType()->getAs<RecordType>();
+  const QualType type = decl->getType();
+  const auto *recordType = type->getAs<RecordType>();
+
+  if (isConstantBuffer(type)) {
+    // Get the templated type for ConstantBuffer.
+    recordType = hlsl::GetHLSLResourceResultType(type)->getAs<RecordType>();
+  }
+
   assert(recordType);
 
   const std::string structName =

+ 2 - 1
tools/clang/test/CodeGenSPIRV/vk.push-constant.constantbuffer.hlsl

@@ -6,7 +6,8 @@ struct StructA
     float3 two;
 };
 
-// CHECK: %PushConstants = OpVariable %_ptr_PushConstant_type_PushConstant_ConstantBuffer PushConstant
+// CHECK: %type_PushConstant_StructA = OpTypeStruct %v3float %v3float
+// CHECK: %PushConstants = OpVariable %_ptr_PushConstant_type_PushConstant_StructA PushConstant
 [[vk::push_constant]] ConstantBuffer<StructA> PushConstants;
 
 void main()

+ 1 - 1
tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

@@ -1869,7 +1869,7 @@ TEST_F(FileTest, VulkanMultiplePushConstant) {
   runFileTest("vk.push-constant.multiple.hlsl", Expect::Failure);
 }
 
-TEST_F(FileTest, VulkanPushCOnstantOnConstantBuffer) {
+TEST_F(FileTest, VulkanPushConstantOnConstantBuffer) {
   runFileTest("vk.push-constant.constantbuffer.hlsl");
 }