diff options
author | Vyacheslav Levytskyy <vyacheslav.levytskyy@intel.com> | 2025-02-24 16:53:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-24 16:53:36 +0100 |
commit | 16f9c5da45b88ace429064b4823e94491b0ea9b1 (patch) | |
tree | bbca9ac29125bbd99a77164ed2804a63d12fd5fb /llvm/lib | |
parent | 0b52aa1bdbc7416592e9c81d9a44ce411c21e081 (diff) | |
download | llvm-16f9c5da45b88ace429064b4823e94491b0ea9b1.zip llvm-16f9c5da45b88ace429064b4823e94491b0ea9b1.tar.gz llvm-16f9c5da45b88ace429064b4823e94491b0ea9b1.tar.bz2 |
[SPIR-V] Stop generating StorageImageReadWithoutFormat and StorageImageWriteWithoutFormat for the Unknown image format in the OpenCL environment (#128497)
This PR resolves the issue of the SPIR-V specification, requiring
Shader-coupled capabilities to read/write images in the OpenCL SPIR-V
environment, from the perspective of the LLVM SPIR-V backend. See
https://github.com/KhronosGroup/SPIRV-Headers/issues/487 for details and
discussion.
Current implementation correctly reproduces requirements of the SPIR-V
specification, however, since the requirements are problematic, out
current implementation blocks generation of valid SPIR-V code for
compute environments. This PR is to implement a solution discussed at
the SPIR-V WG to allow proceeding with generation of valid SPIR-V code
for the OpenCL environment and do not impact Vulkan environment at the
same time.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp index fea3965..b2c1241 100644 --- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp @@ -1723,7 +1723,12 @@ 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; } @@ -1731,7 +1736,12 @@ void addInstrRequirements(const MachineInstr &MI, 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; } |