Skip to content

Commit 39b6d89

Browse files
authored
[SPIRV] Add StorageImageExtendedFormats to available list for Vulkan (#192512)
Some image formats used in OpTypeImage require the StorageImageExtendedFormats capability. When it is not in the available list, it is not emitted, causing invalid SPIR-V. The solution is to add it to the list. It is available for all versions of Vulkan. Fixes #192486
1 parent d2f080f commit 39b6d89

7 files changed

Lines changed: 143 additions & 1 deletion

File tree

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,8 @@ void RequirementHandler::initAvailableCapabilitiesForVulkan(
965965
Capability::StorageImageArrayDynamicIndexing,
966966
Capability::DerivativeControl, Capability::MinLod,
967967
Capability::ImageQuery, Capability::ImageGatherExtended,
968-
Capability::Addresses, Capability::VulkanMemoryModelKHR});
968+
Capability::Addresses, Capability::VulkanMemoryModelKHR,
969+
Capability::StorageImageExtendedFormats});
969970

970971
// Became core in Vulkan 1.2
971972
if (ST.isAtLeastSPIRVVer(VersionTuple(1, 5))) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.6-vulkan1.3-library %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-vulkan1.3-library %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3+
4+
; CHECK-DAG: OpCapability StorageImageExtendedFormats
5+
; CHECK-DAG: %[[#float:]] = OpTypeFloat 32
6+
; CHECK-DAG: %[[#image:]] = OpTypeImage %[[#float]] Buffer 2 0 0 2 R11fG11fB10f
7+
; CHECK-DAG: %[[#ptr:]] = OpTypePointer UniformConstant %[[#image]]
8+
; CHECK-DAG: %[[#var:]] = OpVariable %[[#ptr]] UniformConstant
9+
10+
@.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
11+
12+
define void @main() #0 {
13+
%buffer = call target("spirv.Image", float, 5, 2, 0, 0, 2, 8)
14+
@llvm.spv.resource.handlefrombinding.tspirv.Image_f32_5_2_0_0_2_8(
15+
i32 16, i32 7, i32 1, i32 0, ptr nonnull @.str)
16+
%data = call <4 x float> @llvm.spv.resource.load.typedbuffer(
17+
target("spirv.Image", float, 5, 2, 0, 0, 2, 8) %buffer, i32 0)
18+
ret void
19+
}
20+
21+
declare <4 x float> @llvm.spv.resource.load.typedbuffer(target("spirv.Image", float, 5, 2, 0, 0, 2, 8), i32)
22+
23+
attributes #0 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.6-vulkan1.3-library %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-vulkan1.3-library %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3+
4+
; CHECK-DAG: OpCapability StorageImageExtendedFormats
5+
; CHECK-DAG: %[[#float:]] = OpTypeFloat 32
6+
; CHECK-DAG: %[[#image:]] = OpTypeImage %[[#float]] Buffer 2 0 0 2 Rg32f
7+
; CHECK-DAG: %[[#ptr:]] = OpTypePointer UniformConstant %[[#image]]
8+
; CHECK-DAG: %[[#var:]] = OpVariable %[[#ptr]] UniformConstant
9+
10+
@.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
11+
12+
define void @main() #0 {
13+
%buffer = call target("spirv.Image", float, 5, 2, 0, 0, 2, 6)
14+
@llvm.spv.resource.handlefrombinding.tspirv.Image_f32_5_2_0_0_2_6(
15+
i32 16, i32 7, i32 1, i32 0, ptr nonnull @.str)
16+
%data = call <4 x float> @llvm.spv.resource.load.typedbuffer(
17+
target("spirv.Image", float, 5, 2, 0, 0, 2, 6) %buffer, i32 0)
18+
ret void
19+
}
20+
21+
declare <4 x float> @llvm.spv.resource.load.typedbuffer(target("spirv.Image", float, 5, 2, 0, 0, 2, 6), i32)
22+
23+
attributes #0 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.6-vulkan1.3-library %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-vulkan1.3-library %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3+
4+
; CHECK-DAG: OpCapability StorageImageExtendedFormats
5+
; CHECK-DAG: %[[#int:]] = OpTypeInt 32 0
6+
; CHECK-DAG: %[[#image:]] = OpTypeImage %[[#int]] Buffer 2 0 0 2 Rg32i
7+
; CHECK-DAG: %[[#ptr:]] = OpTypePointer UniformConstant %[[#image]]
8+
; CHECK-DAG: %[[#var:]] = OpVariable %[[#ptr]] UniformConstant
9+
10+
@.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
11+
12+
define void @main() #0 {
13+
%buffer = call target("spirv.SignedImage", i32, 5, 2, 0, 0, 2, 25)
14+
@llvm.spv.resource.handlefrombinding.tspirv.SignedImage_i32_5_2_0_0_2_25(
15+
i32 16, i32 7, i32 1, i32 0, ptr nonnull @.str)
16+
%data = call <4 x i32> @llvm.spv.resource.load.typedbuffer(
17+
target("spirv.SignedImage", i32, 5, 2, 0, 0, 2, 25) %buffer, i32 0)
18+
ret void
19+
}
20+
21+
declare <4 x i32> @llvm.spv.resource.load.typedbuffer(target("spirv.SignedImage", i32, 5, 2, 0, 0, 2, 25), i32)
22+
23+
attributes #0 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.6-vulkan1.3-library %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-vulkan1.3-library %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3+
4+
; CHECK-DAG: OpCapability StorageImageExtendedFormats
5+
; CHECK-DAG: %[[#uint:]] = OpTypeInt 32 0
6+
; CHECK-DAG: %[[#image:]] = OpTypeImage %[[#uint]] Buffer 2 0 0 2 Rg32ui
7+
; CHECK-DAG: %[[#ptr:]] = OpTypePointer UniformConstant %[[#image]]
8+
; CHECK-DAG: %[[#var:]] = OpVariable %[[#ptr]] UniformConstant
9+
10+
@.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
11+
12+
define void @main() #0 {
13+
%buffer = call target("spirv.Image", i32, 5, 2, 0, 0, 2, 35)
14+
@llvm.spv.resource.handlefrombinding.tspirv.Image_i32_5_2_0_0_2_35(
15+
i32 16, i32 7, i32 1, i32 0, ptr nonnull @.str)
16+
%data = call <4 x i32> @llvm.spv.resource.load.typedbuffer(
17+
target("spirv.Image", i32, 5, 2, 0, 0, 2, 35) %buffer, i32 0)
18+
ret void
19+
}
20+
21+
declare <4 x i32> @llvm.spv.resource.load.typedbuffer(target("spirv.Image", i32, 5, 2, 0, 0, 2, 35), i32)
22+
23+
attributes #0 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.6-vulkan1.3-library %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-vulkan1.3-library %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3+
4+
; CHECK-DAG: OpCapability Shader
5+
; CHECK-NOT: OpCapability StorageImageExtendedFormats
6+
; CHECK-DAG: %[[#float:]] = OpTypeFloat 32
7+
; CHECK-DAG: %[[#image:]] = OpTypeImage %[[#float]] Buffer 2 0 0 2 Rgba32f
8+
; CHECK-DAG: %[[#ptr:]] = OpTypePointer UniformConstant %[[#image]]
9+
; CHECK-DAG: %[[#var:]] = OpVariable %[[#ptr]] UniformConstant
10+
11+
@.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
12+
13+
define void @main() #0 {
14+
%buffer = call target("spirv.Image", float, 5, 2, 0, 0, 2, 1)
15+
@llvm.spv.resource.handlefrombinding.tspirv.Image_f32_5_2_0_0_2_1(
16+
i32 16, i32 7, i32 1, i32 0, ptr nonnull @.str)
17+
%data = call <4 x float> @llvm.spv.resource.load.typedbuffer(
18+
target("spirv.Image", float, 5, 2, 0, 0, 2, 1) %buffer, i32 0)
19+
ret void
20+
}
21+
22+
declare <4 x float> @llvm.spv.resource.load.typedbuffer(target("spirv.Image", float, 5, 2, 0, 0, 2, 1), i32)
23+
24+
25+
attributes #0 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.6-vulkan1.3-library %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv1.6-vulkan1.3-library %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3+
4+
; CHECK-DAG: OpCapability Shader
5+
; CHECK-NOT: OpCapability StorageImageExtendedFormats
6+
; CHECK-DAG: %[[#uint:]] = OpTypeInt 32 0
7+
; CHECK-DAG: %[[#image:]] = OpTypeImage %[[#uint]] Buffer 2 0 0 2 Rgba32ui
8+
; CHECK-DAG: %[[#ptr:]] = OpTypePointer UniformConstant %[[#image]]
9+
; CHECK-DAG: %[[#var:]] = OpVariable %[[#ptr]] UniformConstant
10+
11+
@.str = private unnamed_addr constant [2 x i8] c"B\00", align 1
12+
13+
define void @main() #0 {
14+
%buffer = call target("spirv.Image", i32, 5, 2, 0, 0, 2, 30)
15+
@llvm.spv.resource.handlefrombinding.tspirv.Image_i32_5_2_0_0_2_30(
16+
i32 16, i32 7, i32 1, i32 0, ptr nonnull @.str)
17+
%data = call <4 x i32> @llvm.spv.resource.load.typedbuffer(
18+
target("spirv.Image", i32, 5, 2, 0, 0, 2, 30) %buffer, i32 0)
19+
ret void
20+
}
21+
22+
declare <4 x i32> @llvm.spv.resource.load.typedbuffer(target("spirv.Image", i32, 5, 2, 0, 0, 2, 30), i32)
23+
24+
attributes #0 = { convergent noinline norecurse "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }

0 commit comments

Comments
 (0)