Skip to content

Commit 221e286

Browse files
Stop generating StorageImageReadWithoutFormat and StorageImageWriteWithoutFormat for the Unknown image format in the OpenCL environment
1 parent 61fb954 commit 221e286

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,15 +1723,25 @@ void addInstrRequirements(const MachineInstr &MI,
17231723
Register ImageReg = MI.getOperand(2).getReg();
17241724
SPIRVType *TypeDef = ST.getSPIRVGlobalRegistry()->getResultType(
17251725
ImageReg, const_cast<MachineFunction *>(MI.getMF()));
1726-
if (isImageTypeWithUnknownFormat(TypeDef))
1726+
// OpImageRead and OpImageWrite can use Unknown Image Formats
1727+
// when the Kernel capability is declared. In the OpenCL environment we are
1728+
// not allowed to produce
1729+
// StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat, see
1730+
// https://github.com/KhronosGroup/SPIRV-Headers/issues/487
1731+
if (isImageTypeWithUnknownFormat(TypeDef) && !ST.isOpenCLEnv())
17271732
Reqs.addCapability(SPIRV::Capability::StorageImageReadWithoutFormat);
17281733
break;
17291734
}
17301735
case SPIRV::OpImageWrite: {
17311736
Register ImageReg = MI.getOperand(0).getReg();
17321737
SPIRVType *TypeDef = ST.getSPIRVGlobalRegistry()->getResultType(
17331738
ImageReg, const_cast<MachineFunction *>(MI.getMF()));
1734-
if (isImageTypeWithUnknownFormat(TypeDef))
1739+
// OpImageRead and OpImageWrite can use Unknown Image Formats
1740+
// when the Kernel capability is declared. In the OpenCL environment we are
1741+
// not allowed to produce
1742+
// StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat, see
1743+
// https://github.com/KhronosGroup/SPIRV-Headers/issues/487
1744+
if (isImageTypeWithUnknownFormat(TypeDef) && !ST.isOpenCLEnv())
17351745
Reqs.addCapability(SPIRV::Capability::StorageImageWriteWithoutFormat);
17361746
break;
17371747
}

llvm/test/CodeGen/SPIRV/read_image.ll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
22

3-
; CHECK-SPIRV: OpCapability StorageImageReadWithoutFormat
3+
; StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat implicitly
4+
; declare Shader, causing a SPIR-V module to be rejected by the OpenCL
5+
; run-time. See https://github.com/KhronosGroup/SPIRV-Headers/issues/487
6+
; De-facto, OpImageRead and OpImageWrite are allowed to use Unknown Image
7+
; Formats when the Kernel capability is declared. We reflect this behavior
8+
; in the test case, and leave the check under CHECK-SPIRV-NOT to track
9+
; the issue and follow-up its final resolution when ready.
10+
; CHECK-SPIRV-NOT: OpCapability StorageImageReadWithoutFormat
411

512
; CHECK-SPIRV: %[[#IntTy:]] = OpTypeInt
613
; CHECK-SPIRV: %[[#IVecTy:]] = OpTypeVector %[[#IntTy]]

llvm/test/CodeGen/SPIRV/transcoding/OpImageReadMS.ll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
22

3-
; CHECK-SPIRV: OpCapability StorageImageReadWithoutFormat
3+
; StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat implicitly
4+
; declare Shader, causing a SPIR-V module to be rejected by the OpenCL
5+
; run-time. See https://github.com/KhronosGroup/SPIRV-Headers/issues/487
6+
; De-facto, OpImageRead and OpImageWrite are allowed to use Unknown Image
7+
; Formats when the Kernel capability is declared. We reflect this behavior
8+
; in the test case, and leave the check under CHECK-SPIRV-NOT to track
9+
; the issue and follow-up its final resolution when ready.
10+
; CHECK-SPIRV-NOT: OpCapability StorageImageReadWithoutFormat
11+
412
; CHECK-SPIRV: %[[#]] = OpImageRead %[[#]] %[[#]] %[[#]] Sample %[[#]]
513

614
define spir_kernel void @sample_test(target("spirv.Image", void, 1, 0, 0, 1, 0, 0, 0) %source, i32 %sampler, <4 x float> addrspace(1)* nocapture %results) {

0 commit comments

Comments
 (0)