Skip to content

Commit 47e11af

Browse files
authored
[spirv] Handles rvalue as implicit object argument of vk::BufferPointer::Get(). (microsoft#7313)
[spirv] Handles rvalue as implicit object argument of vk::BufferPointer::Get(). Fixes microsoft#7302.
1 parent b5a9cd5 commit 47e11af

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10932,6 +10932,12 @@ SpirvInstruction *SpirvEmitter::processIntrinsicGetBufferContents(
1093210932
SpirvInstruction *bufferPointer = doExpr(obj);
1093310933
if (!bufferPointer)
1093410934
return nullptr;
10935+
if (bufferPointer->isRValue()) {
10936+
bufferPointer->setRValue(false);
10937+
bufferPointer->setStorageClass(spv::StorageClass::PhysicalStorageBuffer);
10938+
return bufferPointer;
10939+
}
10940+
1093510941
unsigned align = hlsl::GetVKBufferPointerAlignment(obj->getType());
1093610942
lowerTypeVisitor.visitInstruction(bufferPointer);
1093710943

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %dxc -spirv -HV 202x -Od -T cs_6_9 %s | FileCheck %s
2+
3+
// Issue #7302: implicit object argument of Get() evaluates to rvalue
4+
5+
template<class T, class U>
6+
[[vk::ext_instruction(/*spv::OpBitcast*/124)]]
7+
T bitcast(U);
8+
9+
struct Content
10+
{
11+
int a;
12+
};
13+
14+
// CHECK: [[INT:%[_0-9A-Za-z]*]] = OpTypeInt 32 1
15+
// CHECK-DAG: [[I1:%[_0-9A-Za-z]*]] = OpConstant [[INT]] 1
16+
// CHECK-DAG: [[IO:%[_0-9A-Za-z]*]] = OpConstant [[INT]] 0
17+
// CHECK: [[UINT:%[_0-9A-Za-z]*]] = OpTypeInt 32 0
18+
// CHECK-DAG: [[UDEADBEEF:%[_0-9A-Za-z]*]] = OpConstant [[UINT]] 3735928559
19+
// CHECK-DAG: [[U0:%[_0-9A-Za-z]*]] = OpConstant [[UINT]] 0
20+
// CHECK: [[V2UINT:%[_0-9A-Za-z]*]] = OpTypeVector [[UINT]] 2
21+
// CHECK: [[VECTOR:%[_0-9A-Za-z]*]] = OpConstantComposite [[V2UINT]] [[UDEADBEEF]] [[U0]]
22+
// CHECK: [[CONTENT:%[_0-9A-Za-z]*]] = OpTypeStruct [[INT]]
23+
// CHECK: [[PPCONTENT:%[_0-9A-Za-z]*]] = OpTypePointer PhysicalStorageBuffer [[CONTENT]]
24+
// CHECK: [[PPINT:%[_0-9A-Za-z]*]] = OpTypePointer PhysicalStorageBuffer [[INT]]
25+
26+
[numthreads(1, 1, 1)]
27+
void main()
28+
{
29+
bitcast<vk::BufferPointer<Content> >(uint32_t2(0xdeadbeefu,0x0u)).Get().a = 1;
30+
}
31+
32+
// CHECK: [[BITCAST:%[0-9]*]] = OpBitcast [[PPCONTENT]] [[VECTOR]]
33+
// CHECK: [[PTR:%[0-9]*]] = OpAccessChain [[PPINT]] [[BITCAST]] [[IO]]
34+
// CHECK: OpStore [[PTR]] [[I1]] Aligned 4
35+

0 commit comments

Comments
 (0)