Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,15 +1723,25 @@ void addInstrRequirements(const MachineInstr &MI,
Register ImageReg = MI.getOperand(2).getReg();
SPIRVType *TypeDef = ST.getSPIRVGlobalRegistry()->getResultType(
ImageReg, const_cast<MachineFunction *>(MI.getMF()));
if (isImageTypeWithUnknownFormat(TypeDef))
// OpImageRead and OpImageWrite can use Unknown Image Formats
// when the Kernel capability is declared. In the OpenCL environment we are
// not allowed to produce
// StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat, see
// https://github.com/KhronosGroup/SPIRV-Headers/issues/487
if (isImageTypeWithUnknownFormat(TypeDef) && !ST.isOpenCLEnv())
Reqs.addCapability(SPIRV::Capability::StorageImageReadWithoutFormat);
break;
}
case SPIRV::OpImageWrite: {
Register ImageReg = MI.getOperand(0).getReg();
SPIRVType *TypeDef = ST.getSPIRVGlobalRegistry()->getResultType(
ImageReg, const_cast<MachineFunction *>(MI.getMF()));
if (isImageTypeWithUnknownFormat(TypeDef))
// OpImageRead and OpImageWrite can use Unknown Image Formats
// when the Kernel capability is declared. In the OpenCL environment we are
// not allowed to produce
// StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat, see
// https://github.com/KhronosGroup/SPIRV-Headers/issues/487
if (isImageTypeWithUnknownFormat(TypeDef) && !ST.isOpenCLEnv())
Reqs.addCapability(SPIRV::Capability::StorageImageWriteWithoutFormat);
break;
}
Expand Down
9 changes: 8 additions & 1 deletion llvm/test/CodeGen/SPIRV/read_image.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV

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

; CHECK-SPIRV: %[[#IntTy:]] = OpTypeInt
; CHECK-SPIRV: %[[#IVecTy:]] = OpTypeVector %[[#IntTy]]
Expand Down
10 changes: 9 additions & 1 deletion llvm/test/CodeGen/SPIRV/transcoding/OpImageReadMS.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV

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

; CHECK-SPIRV: %[[#]] = OpImageRead %[[#]] %[[#]] %[[#]] Sample %[[#]]

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) {
Expand Down
Loading