Skip to content

Commit 639ac4c

Browse files
committed
[SPIRV] Expand RWBuffer load and store from HLSL
The code pattern that clang will generate for HLSL has changed from the original plan. This allows the SPIR-V backend to generate code for the current code generation. It looks for patterns of the form: ``` %1 = @llvm.spv.resource.handlefrombinding %2 = @llvm.spv.resource.getpointer(%1, index) load/store %2 ``` These three llvm-ir instruction are treated as a single unit that will 1. Generate or find the global variable identified by the call to `resource.handlefrombinding`. 2. Generate an OpLoad of the variable to get the handle to the image. 3. Generate an OpImageRead or OpImageWrite using that handle with the given index. This will generate the OpLoad in the same BB as the read/write. Note: Now that `resource.handlefrombinding` is not processed on its own, many existing tests had to be removed. We do not have intrinsics that are able to use handles to sampled images, input attachments, etc., so we cannot generate the load of the handle. These tests are removed for now, and will be added when those resource types are fully implemented.
1 parent 6518b12 commit 639ac4c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,14 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
731731
if (Ty)
732732
break;
733733
}
734+
} else if (auto *II = dyn_cast<IntrinsicInst>(I)) {
735+
if (II->getIntrinsicID() == Intrinsic::spv_resource_getpointer) {
736+
auto *ImageType = cast<TargetExtType>(II->getOperand(0)->getType());
737+
assert(ImageType->getTargetExtName() == "spirv.Image");
738+
Ty = ImageType->getTypeParameter(0);
739+
// TODO: Need to look at the use to see if it needs to be a vector of the
740+
// type.
741+
}
734742
} else if (auto *CI = dyn_cast<CallInst>(I)) {
735743
static StringMap<unsigned> ResTypeByArg = {
736744
{"to_global", 0},

0 commit comments

Comments
 (0)