[llvm] [SPIRV] Add reads from image buffer for shaders. (PR #115178)
Nathan Gauër via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 8 04:31:32 PST 2024
================
@@ -2803,6 +2816,83 @@ void SPIRVInstructionSelector::selectHandleFromBinding(Register &ResVReg,
.addUse(VarReg);
}
+void SPIRVInstructionSelector::selectReadImageIntrinsic(
+ Register &ResVReg, const SPIRVType *ResType, MachineInstr &I) const {
+
+ // If the load of the image is in a different basic block, then
+ // this will generate invalid code. A proper solution is to move
+ // the OpLoad from selectHandleFromBinding here. However, to do
+ // that we will need to change the return type of the intrinsic.
+ // We will do that when we can, but for now trying to move forward with other
+ // issues.
+ Register ImageReg = I.getOperand(2).getReg();
+
+ SPIRVType *ReadType = getCorrespondingVec4Type(ResType, I);
+ Register ReadReg = MRI->createVirtualRegister(GR.getRegClass(ReadType));
+ BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(SPIRV::OpImageRead))
+ .addDef(ReadReg)
+ .addUse(GR.getSPIRVTypeID(ReadType))
+ .addUse(ImageReg)
+ .addUse(I.getOperand(3).getReg());
+
+ extractScalarOrVectorFromVector(ResVReg, ResType, ReadReg, I);
+}
+
+void SPIRVInstructionSelector::extractScalarOrVectorFromVector(
----------------
Keenuts wrote:
I find this function a bit too specific/weird. Since it's only used in `selectReadImage`, could we have:
- `extractScalarFromVector(SrcVector, Index) -> Scalar`
- `composeVectorFromVector(SrcVector, ComponentCount) -> DstVector`
And in the `selectReadImageIntrinsic` have a:
`
if (isVector(ResType))
return composeVectorFromVector(ReadReg, ResType->componentCount());
return extractScalarFromVector(ReadReg, 0);
`
https://github.com/llvm/llvm-project/pull/115178
More information about the llvm-commits
mailing list