Description
Certain SPIR-V instructions are supported only with the OpenCL extended instruction set but not the GLSL extended instruction set, and vice-versa.
For example, the reflect
instruction is supported in GLSL, but not OpenCL. Without adding a check that the extended instruction set is usable by the current SPIR-V target, the compiler will simply crash when attempting to select G_INTRINSIC intrinsic(@llvm.spv.reflect)
in an OpenCL SPIR-V target.
#122992 implements the check as follows in llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
:
bool SPIRVInstructionSelector::selectExtInst(Register ResVReg,
const SPIRVType *ResType,
MachineInstr &I,
GL::GLSLExtInst GLInst) const {
if (!STI.canUseExtInstSet(
SPIRV::InstructionSet::InstructionSet::GLSL_std_450)) {
std::string DiagMsg;
raw_string_ostream OS(DiagMsg);
I.print(OS, true, false, false, false);
DiagMsg += " is only supported with the GLSL extended instruction set.\n";
report_fatal_error(DiagMsg.c_str(), false);
}
return selectExtInst(ResVReg, ResType, I,
{{SPIRV::InstructionSet::GLSL_std_450, GLInst}});
}
There should be similar checks made for the other overloaded versions of the selectExtInst
to keep things consistent.
bool selectExtInst(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, CL::OpenCLExtInst CLInst) const;
bool selectExtInst(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, CL::OpenCLExtInst CLInst,
GL::GLSLExtInst GLInst) const;
bool selectExtInst(Register ResVReg, const SPIRVType *ResType,
MachineInstr &I, const ExtInstList &ExtInsts) const;
A non-exhaustive list of OpenCL-only instructions:
vstoren
vloadn
shuffle
(Note: AFAIK, these OpenCL-only instructions do not have corresponding HLSL intrinsics. I am not sure if there are any OpenCL-only instructions that have a direct HLSL intrinsic equivalent.)
A non-exhaustive list of GLSL-only instructions:
Reflect
Refract
FaceForward
A full list of exclusive instructions may be constructed by comparing the OpenCL extended instruction set and GLSL extended instruction set specifications.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status