Skip to content

Commit 31a8319

Browse files
[Backport to 16] Add updated SPV_INTEL_bindless_images preview extension (#2559) (#3008)
The updated SPV_INTEL_bindless_images spec can be seen in this PR: intel/llvm#13753
1 parent 13d9eb5 commit 31a8319

File tree

11 files changed

+41
-3
lines changed

11 files changed

+41
-3
lines changed

lib/SPIRV/OCLTypeToSPIRV.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ void OCLTypeToSPIRVBase::adaptArgumentsBySamplerUse(Module &M) {
195195
StringRef DemangledName;
196196
if (!oclIsBuiltin(MangledName, DemangledName, false))
197197
continue;
198-
if (DemangledName.find(kSPIRVName::SampledImage) == std::string::npos)
198+
// Note: kSPIRVName::ConvertHandleToSampledImageINTEL contains
199+
// kSPIRVName::SampledImage as a substring, but we still want to continue in
200+
// this case.
201+
if (DemangledName.find(kSPIRVName::SampledImage) == std::string::npos ||
202+
DemangledName.find(kSPIRVName::ConvertHandleToSampledImageINTEL) !=
203+
std::string::npos)
199204
continue;
200205

201206
TraceArg(&F, 1);

lib/SPIRV/SPIRVInternal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ const static char TranslateSPIRVMemOrder[] = "__translate_spirv_memory_order";
368368
const static char TranslateSPIRVMemScope[] = "__translate_spirv_memory_scope";
369369
const static char TranslateSPIRVMemFence[] = "__translate_spirv_memory_fence";
370370
const static char EntrypointPrefix[] = "__spirv_entry_";
371+
const static char ConvertHandleToImageINTEL[] = "ConvertHandleToImageINTEL";
372+
const static char ConvertHandleToSamplerINTEL[] = "ConvertHandleToSamplerINTEL";
373+
const static char ConvertHandleToSampledImageINTEL[] =
374+
"ConvertHandleToSampledImageINTEL";
371375
} // namespace kSPIRVName
372376

373377
namespace kSPIRVPostfix {

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,7 @@ class SPIRVFriendlyIRMangleInfo : public BuiltinFuncMangleInfo {
24642464
}
24652465
case internal::OpConvertHandleToImageINTEL:
24662466
case internal::OpConvertHandleToSamplerINTEL:
2467+
case internal::OpConvertHandleToSampledImageINTEL:
24672468
addUnsignedArg(0);
24682469
break;
24692470
default:;

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5261,7 +5261,12 @@ void LLVMToSPIRVBase::oclGetMutatedArgumentTypesByBuiltin(
52615261
StringRef Demangled;
52625262
if (!oclIsBuiltin(F->getName(), Demangled))
52635263
return;
5264-
if (Demangled.find(kSPIRVName::SampledImage) == std::string::npos)
5264+
// Note: kSPIRVName::ConvertHandleToSampledImageINTEL contains
5265+
// kSPIRVName::SampledImage as a substring, but we still want to return in
5266+
// this case.
5267+
if (Demangled.find(kSPIRVName::SampledImage) == std::string::npos ||
5268+
Demangled.find(kSPIRVName::ConvertHandleToSampledImageINTEL) !=
5269+
std::string::npos)
52655270
return;
52665271
if (FT->getParamType(1)->isIntegerTy())
52675272
ChangedType[1] = getSPIRVType(OpTypeSampler, true);

lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3892,7 +3892,9 @@ template <Op OC> class SPIRVBindlessImagesInstBase : public SPIRVUnaryInst<OC> {
38923892
SPVErrLog.checkError(
38933893
(ResTy->isTypeImage() && OC == internal::OpConvertHandleToImageINTEL) ||
38943894
(ResTy->isTypeSampler() &&
3895-
OC == internal::OpConvertHandleToSamplerINTEL),
3895+
OC == internal::OpConvertHandleToSamplerINTEL) ||
3896+
(ResTy->isTypeSampledImage() &&
3897+
OC == internal::OpConvertHandleToSampledImageINTEL),
38963898
SPIRVEC_InvalidInstruction,
38973899
InstName + "\nIncorrect return type of the instruction must be "
38983900
"image/sampler\n");
@@ -3902,6 +3904,7 @@ template <Op OC> class SPIRVBindlessImagesInstBase : public SPIRVUnaryInst<OC> {
39023904
typedef SPIRVBindlessImagesInstBase<internal::Op##x> SPIRV##x;
39033905
_SPIRV_OP(ConvertHandleToImageINTEL)
39043906
_SPIRV_OP(ConvertHandleToSamplerINTEL)
3907+
_SPIRV_OP(ConvertHandleToSampledImageINTEL)
39053908
#undef _SPIRV_OP
39063909

39073910
class SPIRVSubgroup2DBlockIOINTELInst : public SPIRVInstTemplateBase {

lib/SPIRV/libSPIRV/SPIRVOpCodeEnumInternal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ _SPIRV_OP_INTERNAL(ConvertHandleToImageINTEL,
2929
internal::ConvertHandleToImageINTEL)
3030
_SPIRV_OP_INTERNAL(ConvertHandleToSamplerINTEL,
3131
internal::ConvertHandleToSamplerINTEL)
32+
_SPIRV_OP_INTERNAL(ConvertHandleToSampledImageINTEL,
33+
internal::ConvertHandleToSampledImageINTEL)

lib/SPIRV/libSPIRV/SPIRVType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ bool SPIRVType::isTypeSampler() const { return OpCode == OpTypeSampler; }
197197

198198
bool SPIRVType::isTypeImage() const { return OpCode == OpTypeImage; }
199199

200+
bool SPIRVType::isTypeSampledImage() const {
201+
return OpCode == OpTypeSampledImage;
202+
}
203+
200204
bool SPIRVType::isTypeStruct() const { return OpCode == OpTypeStruct; }
201205

202206
bool SPIRVType::isTypeVector() const { return OpCode == OpTypeVector; }

lib/SPIRV/libSPIRV/SPIRVType.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class SPIRVType : public SPIRVEntry {
9393
bool isTypeOpaque() const;
9494
bool isTypePointer() const;
9595
bool isTypeSampler() const;
96+
bool isTypeSampledImage() const;
9697
bool isTypeStruct() const;
9798
bool isTypeVector() const;
9899
bool isTypeJointMatrixINTEL() const;

lib/SPIRV/libSPIRV/spirv_internal.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ enum InternalOp {
8080
IOpMaskedScatterINTEL = 6429,
8181
IOpConvertHandleToImageINTEL = 6529,
8282
IOpConvertHandleToSamplerINTEL = 6530,
83+
IOpConvertHandleToSampledImageINTEL = 6531,
8384
IOpPrev = OpMax - 2,
8485
IOpForward
8586
};
@@ -194,6 +195,7 @@ _SPIRV_OP(Capability, CacheControlsINTEL)
194195
_SPIRV_OP(Capability, BindlessImagesINTEL)
195196
_SPIRV_OP(Op, ConvertHandleToImageINTEL)
196197
_SPIRV_OP(Op, ConvertHandleToSamplerINTEL)
198+
_SPIRV_OP(Op, ConvertHandleToSampledImageINTEL)
197199
#undef _SPIRV_OP
198200

199201
constexpr SourceLanguage SourceLanguagePython =

test/extensions/INTEL/SPV_INTEL_bindless_images/bindless_images_generic.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,33 @@ target triple = "spir64-unknown-unknown"
1818
; CHECK-SPIRV-DAG: TypeVoid [[#VoidTy:]]
1919
; CHECK-SPIRV-DAG: TypeInt [[#Int64Ty:]] 64
2020
; CHECK-SPIRV-DAG: Constant [[#Int64Ty]] [[#Const42:]] 42 0
21+
; CHECK-SPIRV-DAG: Constant [[#Int64Ty]] [[#Const43:]] 43 0
2122
; CHECK-SPIRV-DAG: TypeImage [[#IntImgTy:]] [[#Int64Ty]]
2223
; CHECK-SPIRV-DAG: TypeSampler [[#SamplerTy:]]
24+
; CHECK-SPIRV-DAG: TypeImage [[#IntSmpImgTy:]] [[#Int64Ty]]
25+
; CHECK-SPIRV-DAG: TypeSampledImage [[#SampImageTy:]] [[#IntSmpImgTy]]
2326
; CHECK-SPIRV: FunctionParameter [[#Int64Ty]] [[#Input:]]
2427
; CHECK-SPIRV: ConvertHandleToImageINTEL [[#IntImgTy]] [[#]] [[#Input]]
2528
; CHECK-SPIRV: ConvertHandleToSamplerINTEL [[#SamplerTy]] [[#]] [[#Const42]]
29+
; CHECK-SPIRV: ConvertHandleToSampledImageINTEL [[#SampImageTy]] [[#]] [[#Const43]]
2630

2731
; CHECK-LLVM: call spir_func %spirv.Image._long_2_0_0_0_0_0_0 addrspace(1)* @_Z76__spirv_ConvertHandleToImageINTEL_RPU3AS133__spirv_Image__long_2_0_0_0_0_0_0m(i64 %{{.*}})
2832
; CHECK-LLVM: call spir_func %spirv.Sampler addrspace(2)* @_Z35__spirv_ConvertHandleToSamplerINTELm(i64 42)
33+
; CHECK-LLVM: call spir_func %spirv.SampledImage._long_1_0_0_0_0_0_0 addrspace(1)* @_Z40__spirv_ConvertHandleToSampledImageINTELm(i64 43)
2934

3035
define spir_func void @foo(i64 %in) {
3136
%img = call spir_func target("spirv.Image", i64, 2, 0, 0, 0, 0, 0, 0) @_Z33__spirv_ConvertHandleToImageINTELl(i64 %in)
3237
%samp = call spir_func target("spirv.Sampler") @_Z35__spirv_ConvertHandleToSamplerINTELl(i64 42)
38+
%sampImage = call spir_func target("spirv.SampledImage", i64, 1, 0, 0, 0, 0, 0, 0) @_Z40__spirv_ConvertHandleToSampledImageINTELl(i64 43)
3339
ret void
3440
}
3541

3642
declare spir_func target("spirv.Image", i64, 2, 0, 0, 0, 0, 0, 0) @_Z33__spirv_ConvertHandleToImageINTELl(i64)
3743

3844
declare spir_func target("spirv.Sampler") @_Z35__spirv_ConvertHandleToSamplerINTELl(i64)
3945

46+
declare spir_func target("spirv.SampledImage", i64, 1, 0, 0, 0, 0, 0, 0) @_Z40__spirv_ConvertHandleToSampledImageINTELl(i64)
47+
4048
!opencl.spir.version = !{!0}
4149
!spirv.Source = !{!1}
4250
!llvm.ident = !{!2}

0 commit comments

Comments
 (0)