Skip to content

Commit 0dbc1e2

Browse files
authored
[SPIRV] Added constraint for SPV_INTEL_bindless_image extension (#160249)
Added constraints related to Addressing model as specified in the specification. It conforms with the implementation in translator Same as PR #160089 Solved all issues
1 parent 5d85d54 commit 0dbc1e2

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,9 @@ static bool isBFloat16Type(const SPIRVType *TypeDef) {
12551255
}
12561256

12571257
void addInstrRequirements(const MachineInstr &MI,
1258-
SPIRV::RequirementHandler &Reqs,
1258+
SPIRV::ModuleAnalysisInfo &MAI,
12591259
const SPIRVSubtarget &ST) {
1260+
SPIRV::RequirementHandler &Reqs = MAI.Reqs;
12601261
switch (MI.getOpcode()) {
12611262
case SPIRV::OpMemoryModel: {
12621263
int64_t Addr = MI.getOperand(0).getImm();
@@ -1812,15 +1813,45 @@ void addInstrRequirements(const MachineInstr &MI,
18121813
break;
18131814
case SPIRV::OpConvertHandleToImageINTEL:
18141815
case SPIRV::OpConvertHandleToSamplerINTEL:
1815-
case SPIRV::OpConvertHandleToSampledImageINTEL:
1816+
case SPIRV::OpConvertHandleToSampledImageINTEL: {
18161817
if (!ST.canUseExtension(SPIRV::Extension::SPV_INTEL_bindless_images))
18171818
report_fatal_error("OpConvertHandleTo[Image/Sampler/SampledImage]INTEL "
18181819
"instructions require the following SPIR-V extension: "
18191820
"SPV_INTEL_bindless_images",
18201821
false);
1822+
SPIRVGlobalRegistry *GR = ST.getSPIRVGlobalRegistry();
1823+
SPIRV::AddressingModel::AddressingModel AddrModel = MAI.Addr;
1824+
SPIRVType *TyDef = GR->getSPIRVTypeForVReg(MI.getOperand(1).getReg());
1825+
if (MI.getOpcode() == SPIRV::OpConvertHandleToImageINTEL &&
1826+
TyDef->getOpcode() != SPIRV::OpTypeImage) {
1827+
report_fatal_error("Incorrect return type for the instruction "
1828+
"OpConvertHandleToImageINTEL",
1829+
false);
1830+
} else if (MI.getOpcode() == SPIRV::OpConvertHandleToSamplerINTEL &&
1831+
TyDef->getOpcode() != SPIRV::OpTypeSampler) {
1832+
report_fatal_error("Incorrect return type for the instruction "
1833+
"OpConvertHandleToSamplerINTEL",
1834+
false);
1835+
} else if (MI.getOpcode() == SPIRV::OpConvertHandleToSampledImageINTEL &&
1836+
TyDef->getOpcode() != SPIRV::OpTypeSampledImage) {
1837+
report_fatal_error("Incorrect return type for the instruction "
1838+
"OpConvertHandleToSampledImageINTEL",
1839+
false);
1840+
}
1841+
SPIRVType *SpvTy = GR->getSPIRVTypeForVReg(MI.getOperand(2).getReg());
1842+
unsigned Bitwidth = GR->getScalarOrVectorBitWidth(SpvTy);
1843+
if (!(Bitwidth == 32 && AddrModel == SPIRV::AddressingModel::Physical32) &&
1844+
!(Bitwidth == 64 && AddrModel == SPIRV::AddressingModel::Physical64)) {
1845+
report_fatal_error(
1846+
"Parameter value must be a 32-bit scalar in case of "
1847+
"Physical32 addressing model or a 64-bit scalar in case of "
1848+
"Physical64 addressing model",
1849+
false);
1850+
}
18211851
Reqs.addExtension(SPIRV::Extension::SPV_INTEL_bindless_images);
18221852
Reqs.addCapability(SPIRV::Capability::BindlessImagesINTEL);
18231853
break;
1854+
}
18241855
case SPIRV::OpSubgroup2DBlockLoadINTEL:
18251856
case SPIRV::OpSubgroup2DBlockLoadTransposeINTEL:
18261857
case SPIRV::OpSubgroup2DBlockLoadTransformINTEL:
@@ -1958,7 +1989,7 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
19581989
continue;
19591990
for (const MachineBasicBlock &MBB : *MF)
19601991
for (const MachineInstr &MI : MBB)
1961-
addInstrRequirements(MI, MAI.Reqs, ST);
1992+
addInstrRequirements(MI, MAI, ST);
19621993
}
19631994
// Collect requirements for OpExecutionMode instructions.
19641995
auto Node = M.getNamedMetadata("spirv.ExecutionMode");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: not llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_bindless_images %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
2+
3+
; CHECK-ERROR: LLVM ERROR: Parameter value must be a 32-bit scalar in case of Physical32 addressing model or a 64-bit scalar in case of Physical64 addressing model
4+
5+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
6+
target triple = "spir64-unknown-unknown"
7+
8+
define spir_func void @foo(i32 %in) {
9+
%img = call spir_func target("spirv.Image", i32, 2, 0, 0, 0, 0, 0, 0) @_Z33__spirv_ConvertHandleToImageINTELi(i32 %in)
10+
%samp = call spir_func target("spirv.Sampler") @_Z35__spirv_ConvertHandleToSamplerINTELl(i64 42)
11+
%sampImage = call spir_func target("spirv.SampledImage", i64, 1, 0, 0, 0, 0, 0, 0) @_Z40__spirv_ConvertHandleToSampledImageINTELl(i64 43)
12+
ret void
13+
}
14+
15+
declare spir_func target("spirv.Image", i32, 2, 0, 0, 0, 0, 0, 0) @_Z33__spirv_ConvertHandleToImageINTELi(i32)
16+
17+
declare spir_func target("spirv.Sampler") @_Z35__spirv_ConvertHandleToSamplerINTELl(i64)
18+
19+
declare spir_func target("spirv.SampledImage", i64, 1, 0, 0, 0, 0, 0, 0) @_Z40__spirv_ConvertHandleToSampledImageINTELl(i64)

0 commit comments

Comments
 (0)