Skip to content

Commit e5801bd

Browse files
authored
[spirv] support SPV_EXT_shader_image_int64 extension for 64-bit integer resource (#3787)
This commit adds `Int64ImageEXT` capability and `SPV_EXT_shader_image_int64` extension to the SPIRV backend when 64-bit integer types are used on an image resource.
1 parent dc943d3 commit e5801bd

6 files changed

Lines changed: 48 additions & 1 deletion

File tree

tools/clang/include/clang/SPIRV/FeatureManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ enum class Extension {
5151
NV_ray_tracing,
5252
NV_mesh_shader,
5353
KHR_ray_query,
54+
EXT_shader_image_int64,
5455
Unknown,
5556
};
5657

tools/clang/lib/SPIRV/CapabilityVisitor.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,16 @@ void CapabilityVisitor::addCapabilityForType(const SpirvType *type,
171171
if (imageType->isArrayedImage() && imageType->isMSImage())
172172
addCapability(spv::Capability::ImageMSArray);
173173

174-
addCapabilityForType(imageType->getSampledType(), loc, sc);
174+
if (const auto *sampledType = imageType->getSampledType()) {
175+
addCapabilityForType(sampledType, loc, sc);
176+
if (const auto *sampledIntType = dyn_cast<IntegerType>(sampledType)) {
177+
if (sampledIntType->getBitwidth() == 64) {
178+
addCapability(spv::Capability::Int64ImageEXT);
179+
addExtension(Extension::EXT_shader_image_int64,
180+
"64-bit image types in resource", loc);
181+
}
182+
}
183+
}
175184
}
176185
// Sampled image type
177186
else if (const auto *sampledImageType = dyn_cast<SampledImageType>(type)) {

tools/clang/lib/SPIRV/FeatureManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Extension FeatureManager::getExtensionSymbol(llvm::StringRef name) {
142142
.Case("SPV_KHR_ray_query", Extension::KHR_ray_query)
143143
.Case("SPV_KHR_fragment_shading_rate",
144144
Extension::KHR_fragment_shading_rate)
145+
.Case("SPV_EXT_shader_image_int64", Extension::EXT_shader_image_int64)
145146
.Default(Extension::Unknown);
146147
}
147148

@@ -193,6 +194,8 @@ const char *FeatureManager::getExtensionName(Extension symbol) {
193194
return "SPV_KHR_ray_query";
194195
case Extension::KHR_fragment_shading_rate:
195196
return "SPV_KHR_fragment_shading_rate";
197+
case Extension::EXT_shader_image_int64:
198+
return "SPV_EXT_shader_image_int64";
196199
default:
197200
break;
198201
}

tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,12 @@ LowerTypeVisitor::translateSampledTypeToImageFormat(QualType sampledType,
758758
return elemCount == 1 ? spv::ImageFormat::R32f
759759
: elemCount == 2 ? spv::ImageFormat::Rg32f
760760
: spv::ImageFormat::Rgba32f;
761+
case BuiltinType::LongLong:
762+
if (elemCount == 1)
763+
return spv::ImageFormat::R64i;
764+
case BuiltinType::ULongLong:
765+
if (elemCount == 1)
766+
return spv::ImageFormat::R64ui;
761767
default:
762768
// Other sampled types unimplemented or irrelevant.
763769
break;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Run: %dxc -T cs_6_0 -E main
2+
3+
// CHECK: %type_2d_image = OpTypeImage %ulong 2D 2 0 0 2 R64ui
4+
// CHECK: %_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
5+
6+
// CHECK: %type_2d_image_0 = OpTypeImage %long 2D 2 0 0 2 R64i
7+
// CHECK: %_ptr_UniformConstant_type_2d_image_0 = OpTypePointer UniformConstant %type_2d_image_0
8+
9+
// CHECK: %type_2d_image_1 = OpTypeImage %int 2D 2 0 0 2 Rgba32i
10+
// CHECK: %_ptr_UniformConstant_type_2d_image_1 = OpTypePointer UniformConstant %type_2d_image_1
11+
12+
// CHECK: %tex_ui = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
13+
RWTexture2D<uint64_t> tex_ui;
14+
15+
// CHECK: %tex_i = OpVariable %_ptr_UniformConstant_type_2d_image_0 UniformConstant
16+
RWTexture2D<int64_t> tex_i;
17+
18+
// CHECK: %texout = OpVariable %_ptr_UniformConstant_type_2d_image_1 UniformConstant
19+
RWTexture2D<min12int4> texout;
20+
21+
[numthreads(8, 8, 1)]
22+
void main(uint2 id : SV_DispatchThreadID)
23+
{
24+
texout[id] = tex_i[id] + tex_ui[id];
25+
};

tools/clang/unittests/SPIRV/CodeGenSpirvTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ TEST_F(FileTest, RWTextureTypes) { runFileTest("type.rwtexture.hlsl"); }
7272
TEST_F(FileTest, RWTextureTypesWithMinPrecisionScalarTypes) {
7373
runFileTest("type.rwtexture.with.min.precision.scalar.hlsl");
7474
}
75+
TEST_F(FileTest, RWTextureTypesWith64bitsScalarTypes) {
76+
runFileTest("type.rwtexture.with.64bit.scalar.hlsl");
77+
}
7578
TEST_F(FileTest, BufferType) { runFileTest("type.buffer.hlsl"); }
7679
TEST_F(FileTest, BufferTypeStructError1) {
7780
runFileTest("type.buffer.struct.error1.hlsl", Expect::Failure);

0 commit comments

Comments
 (0)