Skip to content

Commit 212d85b

Browse files
authored
[SPIR-V][vk::SampledTexture] #12. Support vk::SampledTexture3D type. (#8213)
Part of #7979 The function definitions are equivalent to that of Texture3D counterparts, just without Sampler argument.
1 parent b13e386 commit 212d85b

15 files changed

+447
-4
lines changed

include/dxc/dxcapi.internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ enum LEGAL_INTRINSIC_COMPTYPES {
146146
LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY = 60,
147147
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS = 61,
148148
LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY = 62,
149-
LICOMPTYPE_COUNT = 63
149+
LICOMPTYPE_VK_SAMPLED_TEXTURE3D = 63,
150+
LICOMPTYPE_COUNT = 64
150151
#else
151152
LICOMPTYPE_COUNT = 56
152153
#endif

tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,9 @@ const SpirvType *LowerTypeVisitor::lowerVkTypeInVkNamespace(
864864
constexpr size_t sampledTexturePrefixLength = sizeof("SampledTexture") - 1;
865865
StringRef suffix = name.drop_front(sampledTexturePrefixLength);
866866
const spv::Dim dimension =
867-
suffix.startswith("1D") ? spv::Dim::Dim1D : spv::Dim::Dim2D;
867+
suffix.startswith("1D")
868+
? spv::Dim::Dim1D
869+
: (suffix.startswith("2D") ? spv::Dim::Dim2D : spv::Dim::Dim3D);
868870
const bool isArray = suffix.endswith("Array");
869871
const bool isMS = suffix.find("MS") != StringRef::npos;
870872

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4417,6 +4417,7 @@ SpirvEmitter::processBufferTextureGetDimensions(const CXXMemberCallExpr *expr) {
44174417
(typeName == "SampledTexture1DArray" && numArgs > 2) ||
44184418
(typeName == "SampledTexture2D" && numArgs > 2) ||
44194419
(typeName == "SampledTexture2DArray" && numArgs > 3) ||
4420+
(typeName == "SampledTexture3D" && numArgs > 3) ||
44204421
(typeName == "TextureCube" && numArgs > 2) ||
44214422
(typeName == "Texture3D" && numArgs > 3) ||
44224423
(typeName == "Texture1DArray" && numArgs > 2) ||

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ enum ArBasicKind {
206206
AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY,
207207
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS,
208208
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY,
209+
AR_OBJECT_VK_SAMPLED_TEXTURE3D,
209210
#endif // ENABLE_SPIRV_CODEGEN
210211
// SPIRV change ends
211212

@@ -572,6 +573,7 @@ const UINT g_uBasicKindProps[] = {
572573
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
573574
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
574575
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
576+
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE3D
575577
#endif // ENABLE_SPIRV_CODEGEN
576578
// SPIRV change ends
577579

@@ -1292,6 +1294,8 @@ static const ArBasicKind g_VKSampledTexture2DMSCT[] = {
12921294
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS, AR_BASIC_UNKNOWN};
12931295
static const ArBasicKind g_VKSampledTexture2DMSArrayCT[] = {
12941296
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY, AR_BASIC_UNKNOWN};
1297+
static const ArBasicKind g_VKSampledTexture3DCT[] = {
1298+
AR_OBJECT_VK_SAMPLED_TEXTURE3D, AR_BASIC_UNKNOWN};
12951299
#endif
12961300

12971301
// Basic kinds, indexed by a LEGAL_INTRINSIC_COMPTYPES value.
@@ -1361,6 +1365,7 @@ const ArBasicKind *g_LegalIntrinsicCompTypes[] = {
13611365
g_VKSampledTexture2DArrayCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY
13621366
g_VKSampledTexture2DMSCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS
13631367
g_VKSampledTexture2DMSArrayCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY
1368+
g_VKSampledTexture3DCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE3D
13641369
#endif
13651370
};
13661371
static_assert(
@@ -1423,7 +1428,7 @@ static const ArBasicKind g_ArBasicKindsAsTypes[] = {
14231428
AR_OBJECT_VK_BUFFER_POINTER, AR_OBJECT_VK_SAMPLED_TEXTURE1D,
14241429
AR_OBJECT_VK_SAMPLED_TEXTURE1D_ARRAY, AR_OBJECT_VK_SAMPLED_TEXTURE2D,
14251430
AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY, AR_OBJECT_VK_SAMPLED_TEXTURE2DMS,
1426-
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY,
1431+
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY, AR_OBJECT_VK_SAMPLED_TEXTURE3D,
14271432
#endif // ENABLE_SPIRV_CODEGEN
14281433
// SPIRV change ends
14291434

@@ -1541,6 +1546,7 @@ static const uint8_t g_ArBasicKindsTemplateCount[] = {
15411546
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
15421547
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
15431548
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
1549+
1, // AR_OBJECT_VK_SAMPLED_TEXTURE3D
15441550
#endif // ENABLE_SPIRV_CODEGEN
15451551
// SPIRV change ends
15461552

@@ -1700,6 +1706,7 @@ static const SubscriptOperatorRecord g_ArBasicKindsSubscripts[] = {
17001706
{3, MipsTrue, SampleFalse}, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
17011707
{2, MipsFalse, SampleTrue}, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
17021708
{3, MipsFalse, SampleTrue}, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
1709+
{3, MipsTrue, SampleFalse}, // AR_OBJECT_VK_SAMPLED_TEXTURE3D
17031710
#endif // ENABLE_SPIRV_CODEGEN
17041711
// SPIRV change ends
17051712

@@ -1875,6 +1882,7 @@ static const char *g_ArBasicTypeNames[] = {
18751882
"SampledTexture2DArray",
18761883
"SampledTexture2DMS",
18771884
"SampledTexture2DMSArray",
1885+
"SampledTexture3D",
18781886
#endif // ENABLE_SPIRV_CODEGEN
18791887
// SPIRV change ends
18801888

@@ -2555,6 +2563,10 @@ static void GetIntrinsicMethods(ArBasicKind kind,
25552563
*intrinsics = g_VkSampledTexture2DMSArrayMethods;
25562564
*intrinsicCount = _countof(g_VkSampledTexture2DMSArrayMethods);
25572565
break;
2566+
case AR_OBJECT_VK_SAMPLED_TEXTURE3D:
2567+
*intrinsics = g_VkSampledTexture3DMethods;
2568+
*intrinsicCount = _countof(g_VkSampledTexture3DMethods);
2569+
break;
25582570
#endif
25592571
case AR_OBJECT_HIT_OBJECT:
25602572
*intrinsics = g_DxHitObjectMethods;
@@ -4165,7 +4177,8 @@ class HLSLExternalSource : public ExternalSemaSource {
41654177
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2D ||
41664178
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY ||
41674179
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS ||
4168-
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY) {
4180+
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY ||
4181+
kind == AR_OBJECT_VK_SAMPLED_TEXTURE3D) {
41694182
if (!m_vkNSDecl)
41704183
continue;
41714184
QualType float4Type =
@@ -5153,6 +5166,9 @@ class HLSLExternalSource : public ExternalSemaSource {
51535166
ResClass = DXIL::ResourceClass::UAV;
51545167
return true;
51555168
case AR_OBJECT_TEXTURE3D:
5169+
#ifdef ENABLE_SPIRV_CODEGEN
5170+
case AR_OBJECT_VK_SAMPLED_TEXTURE3D:
5171+
#endif
51565172
ResKind = DXIL::ResourceKind::Texture3D;
51575173
ResClass = DXIL::ResourceClass::SRV;
51585174
return true;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %dxc -T ps_6_7 -E main -fcgl %s -spirv | FileCheck %s
2+
// RUN: not %dxc -T ps_6_7 -E main -fcgl %s -spirv -DERROR 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR
3+
4+
// CHECK: %type_3d_image = OpTypeImage %float 3D 0 0 0 1 Unknown
5+
// CHECK: %type_sampled_image = OpTypeSampledImage %type_3d_image
6+
7+
vk::SampledTexture3D<float4> tex3d;
8+
9+
struct S { int a; };
10+
11+
void main() {
12+
uint3 pos1 = uint3(1, 2, 3);
13+
14+
// CHECK: [[pos1:%[a-zA-Z0-9_]+]] = OpLoad %v3uint %pos1
15+
// CHECK: [[tex1_load:%[a-zA-Z0-9_]+]] = OpLoad %type_sampled_image %tex3d
16+
// CHECK: [[tex_image:%[a-zA-Z0-9_]+]] = OpImage %type_3d_image [[tex1_load]]
17+
// CHECK: [[fetch_result:%[a-zA-Z0-9_]+]] = OpImageFetch %v4float [[tex_image]] [[pos1]] Lod %uint_0
18+
// CHECK: OpStore %a1 [[fetch_result]]
19+
float4 a1 = tex3d[pos1];
20+
21+
#ifdef ERROR
22+
S s = { 1 };
23+
// CHECK-ERROR: error: no viable overloaded operator[]
24+
float4 val2 = tex3d[s];
25+
26+
int2 i2 = int2(1, 2);
27+
// CHECK-ERROR: error: no viable overloaded operator[]
28+
float4 val3 = tex3d[i2];
29+
30+
int i1 = 1;
31+
// CHECK-ERROR: error: no viable overloaded operator[]
32+
float4 val4 = tex3d[i1];
33+
#endif
34+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %dxc -T ps_6_8 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: OpCapability ImageQuery
4+
5+
// CHECK: [[type_3d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 3D 0 0 0 1 Unknown
6+
// CHECK: [[type_3d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_3d_image]]
7+
8+
vk::SampledTexture3D<float4> tex3d;
9+
10+
void main() {
11+
float3 xyz = float3(0.5, 0.5, 0.5);
12+
13+
// CHECK: [[tex1_load:%[a-zA-Z0-9_]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
14+
// CHECK-NEXT: [[xyz_load:%[a-zA-Z0-9_]+]] = OpLoad %v3float %xyz
15+
// CHECK-NEXT: [[query:%[a-zA-Z0-9_]+]] = OpImageQueryLod %v2float [[tex1_load]] [[xyz_load]]
16+
// CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query]] 1
17+
float lod1 = tex3d.CalculateLevelOfDetailUnclamped(xyz);
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: OpCapability ImageQuery
4+
5+
// CHECK: [[type_3d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 3D 0 0 0 1 Unknown
6+
// CHECK: [[type_3d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_3d_image]]
7+
8+
vk::SampledTexture3D<float4> tex3d;
9+
10+
void main() {
11+
float3 xyz = float3(0.5, 0.5, 0.5);
12+
13+
// CHECK: [[tex1:%[a-zA-Z0-9_]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
14+
// CHECK-NEXT: [[xyz_load:%[a-zA-Z0-9_]+]] = OpLoad %v3float %xyz
15+
// CHECK-NEXT: [[query:%[a-zA-Z0-9_]+]] = OpImageQueryLod %v2float [[tex1]] [[xyz_load]]
16+
// CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query]] 0
17+
float lod = tex3d.CalculateLevelOfDetail(xyz);
18+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv -DERROR 2>&1 | FileCheck %s --check-prefix=ERROR
3+
4+
// CHECK: OpCapability ImageQuery
5+
6+
// CHECK: [[type_3d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 3D 0 0 0 1 Unknown
7+
// CHECK: [[type_3d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_3d_image]]
8+
9+
vk::SampledTexture3D<float4> tex3d;
10+
11+
void main() {
12+
uint mipLevel = 1;
13+
uint width, height, depth, numLevels;
14+
15+
// CHECK: [[t1_load:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
16+
// CHECK-NEXT: [[image1:%[0-9]+]] = OpImage [[type_3d_image]] [[t1_load]]
17+
// CHECK-NEXT: [[query1:%[0-9]+]] = OpImageQuerySizeLod %v3uint [[image1]] %int_0
18+
// CHECK-NEXT: [[query1_0:%[0-9]+]] = OpCompositeExtract %uint [[query1]] 0
19+
// CHECK-NEXT: OpStore %width [[query1_0]]
20+
// CHECK-NEXT: [[query1_1:%[0-9]+]] = OpCompositeExtract %uint [[query1]] 1
21+
// CHECK-NEXT: OpStore %height [[query1_1]]
22+
// CHECK-NEXT: [[query1_2:%[0-9]+]] = OpCompositeExtract %uint [[query1]] 2
23+
// CHECK-NEXT: OpStore %depth [[query1_2]]
24+
tex3d.GetDimensions(width, height, depth);
25+
26+
// CHECK: [[t2_load:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
27+
// CHECK-NEXT: [[image2:%[0-9]+]] = OpImage [[type_3d_image]] [[t2_load]]
28+
// CHECK-NEXT: [[mip:%[0-9]+]] = OpLoad %uint %mipLevel
29+
// CHECK-NEXT: [[query2:%[0-9]+]] = OpImageQuerySizeLod %v3uint [[image2]] [[mip]]
30+
// CHECK-NEXT: [[query2_0:%[0-9]+]] = OpCompositeExtract %uint [[query2]] 0
31+
// CHECK-NEXT: OpStore %width [[query2_0]]
32+
// CHECK-NEXT: [[query2_1:%[0-9]+]] = OpCompositeExtract %uint [[query2]] 1
33+
// CHECK-NEXT: OpStore %height [[query2_1]]
34+
// CHECK-NEXT: [[query2_2:%[0-9]+]] = OpCompositeExtract %uint [[query2]] 2
35+
// CHECK-NEXT: OpStore %depth [[query2_2]]
36+
// CHECK-NEXT: [[query_level_2:%[0-9]+]] = OpImageQueryLevels %uint [[image2]]
37+
// CHECK-NEXT: OpStore %numLevels [[query_level_2]]
38+
tex3d.GetDimensions(mipLevel, width, height, depth, numLevels);
39+
40+
float f_width, f_height, f_depth, f_numLevels;
41+
// CHECK: [[t3_load:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
42+
// CHECK-NEXT: [[image3:%[0-9]+]] = OpImage [[type_3d_image]] [[t3_load]]
43+
// CHECK-NEXT: [[query3:%[0-9]+]] = OpImageQuerySizeLod %v3uint [[image3]] %int_0
44+
// CHECK-NEXT: [[query3_0:%[0-9]+]] = OpCompositeExtract %uint [[query3]] 0
45+
// CHECK-NEXT: [[f_query3_0:%[0-9]+]] = OpConvertUToF %float [[query3_0]]
46+
// CHECK-NEXT: OpStore %f_width [[f_query3_0]]
47+
// CHECK-NEXT: [[query3_1:%[0-9]+]] = OpCompositeExtract %uint [[query3]] 1
48+
// CHECK-NEXT: [[f_query3_1:%[0-9]+]] = OpConvertUToF %float [[query3_1]]
49+
// CHECK-NEXT: OpStore %f_height [[f_query3_1]]
50+
// CHECK-NEXT: [[query3_2:%[0-9]+]] = OpCompositeExtract %uint [[query3]] 2
51+
// CHECK-NEXT: [[f_query3_2:%[0-9]+]] = OpConvertUToF %float [[query3_2]]
52+
// CHECK-NEXT: OpStore %f_depth [[f_query3_2]]
53+
tex3d.GetDimensions(f_width, f_height, f_depth);
54+
55+
// CHECK: [[t4_load:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
56+
// CHECK-NEXT: [[image4:%[0-9]+]] = OpImage [[type_3d_image]] [[t4_load]]
57+
// CHECK-NEXT: [[mip4:%[0-9]+]] = OpLoad %uint %mipLevel
58+
// CHECK-NEXT: [[query4:%[0-9]+]] = OpImageQuerySizeLod %v3uint [[image4]] [[mip4]]
59+
// CHECK-NEXT: [[query4_0:%[0-9]+]] = OpCompositeExtract %uint [[query4]] 0
60+
// CHECK-NEXT: [[f_query4_0:%[0-9]+]] = OpConvertUToF %float [[query4_0]]
61+
// CHECK-NEXT: OpStore %f_width [[f_query4_0]]
62+
// CHECK-NEXT: [[query4_1:%[0-9]+]] = OpCompositeExtract %uint [[query4]] 1
63+
// CHECK-NEXT: [[f_query4_1:%[0-9]+]] = OpConvertUToF %float [[query4_1]]
64+
// CHECK-NEXT: OpStore %f_height [[f_query4_1]]
65+
// CHECK-NEXT: [[query4_2:%[0-9]+]] = OpCompositeExtract %uint [[query4]] 2
66+
// CHECK-NEXT: [[f_query4_2:%[0-9]+]] = OpConvertUToF %float [[query4_2]]
67+
// CHECK-NEXT: OpStore %f_depth [[f_query4_2]]
68+
// CHECK-NEXT: [[query_level_4:%[0-9]+]] = OpImageQueryLevels %uint [[image4]]
69+
// CHECK-NEXT: [[f_query_level_4:%[0-9]+]] = OpConvertUToF %float [[query_level_4]]
70+
// CHECK-NEXT: OpStore %f_numLevels [[f_query_level_4]]
71+
tex3d.GetDimensions(mipLevel, f_width, f_height, f_depth, f_numLevels);
72+
73+
int i_width, i_height, i_depth, i_numLevels;
74+
// CHECK: [[t5_load:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
75+
// CHECK-NEXT: [[image5:%[0-9]+]] = OpImage [[type_3d_image]] [[t5_load]]
76+
// CHECK-NEXT: [[query5:%[0-9]+]] = OpImageQuerySizeLod %v3uint [[image5]] %int_0
77+
// CHECK-NEXT: [[query5_0:%[0-9]+]] = OpCompositeExtract %uint [[query5]] 0
78+
// CHECK-NEXT: [[query5_0_i:%[0-9]+]] = OpBitcast %int [[query5_0]]
79+
// CHECK-NEXT: OpStore %i_width [[query5_0_i]]
80+
// CHECK-NEXT: [[query5_1:%[0-9]+]] = OpCompositeExtract %uint [[query5]] 1
81+
// CHECK-NEXT: [[query5_1_i:%[0-9]+]] = OpBitcast %int [[query5_1]]
82+
// CHECK-NEXT: OpStore %i_height [[query5_1_i]]
83+
// CHECK-NEXT: [[query5_2:%[0-9]+]] = OpCompositeExtract %uint [[query5]] 2
84+
// CHECK-NEXT: [[query5_2_i:%[0-9]+]] = OpBitcast %int [[query5_2]]
85+
// CHECK-NEXT: OpStore %i_depth [[query5_2_i]]
86+
tex3d.GetDimensions(i_width, i_height, i_depth);
87+
88+
// CHECK: [[t6_load:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
89+
// CHECK-NEXT: [[image6:%[0-9]+]] = OpImage [[type_3d_image]] [[t6_load]]
90+
// CHECK-NEXT: [[mip6:%[0-9]+]] = OpLoad %uint %mipLevel
91+
// CHECK-NEXT: [[query6:%[0-9]+]] = OpImageQuerySizeLod %v3uint [[image6]] [[mip6]]
92+
// CHECK-NEXT: [[query6_0:%[0-9]+]] = OpCompositeExtract %uint [[query6]] 0
93+
// CHECK-NEXT: [[query6_0_i:%[0-9]+]] = OpBitcast %int [[query6_0]]
94+
// CHECK-NEXT: OpStore %i_width [[query6_0_i]]
95+
// CHECK-NEXT: [[query6_1:%[0-9]+]] = OpCompositeExtract %uint [[query6]] 1
96+
// CHECK-NEXT: [[query6_1_i:%[0-9]+]] = OpBitcast %int [[query6_1]]
97+
// CHECK-NEXT: OpStore %i_height [[query6_1_i]]
98+
// CHECK-NEXT: [[query6_2:%[0-9]+]] = OpCompositeExtract %uint [[query6]] 2
99+
// CHECK-NEXT: [[query6_2_i:%[0-9]+]] = OpBitcast %int [[query6_2]]
100+
// CHECK-NEXT: OpStore %i_depth [[query6_2_i]]
101+
// CHECK-NEXT: [[query_level_6:%[0-9]+]] = OpImageQueryLevels %uint [[image6]]
102+
// CHECK-NEXT: [[query_level_6_i:%[0-9]+]] = OpBitcast %int [[query_level_6]]
103+
// CHECK-NEXT: OpStore %i_numLevels [[query_level_6_i]]
104+
tex3d.GetDimensions(mipLevel, i_width, i_height, i_depth, i_numLevels);
105+
106+
#ifdef ERROR
107+
// ERROR: error: Output argument must be an l-value
108+
tex3d.GetDimensions(mipLevel, 0, height, depth, numLevels);
109+
110+
// ERROR: error: Output argument must be an l-value
111+
tex3d.GetDimensions(width, 20, depth);
112+
#endif
113+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %dxc -T ps_6_0 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: [[v3ic:%[0-9]+]] = OpConstantComposite %v3int %int_1 %int_2 %int_3
4+
5+
// CHECK: [[type_3d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 3D 0 0 0 1 Unknown
6+
// CHECK: [[type_3d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_3d_image]]
7+
8+
vk::SampledTexture3D<float4> tex3d;
9+
10+
float4 main(int4 location4: A) : SV_Target {
11+
uint status;
12+
13+
// CHECK: [[loc:%[0-9]+]] = OpLoad %v4int %location4
14+
// CHECK-NEXT: [[coord_0:%[0-9]+]] = OpVectorShuffle %v3int [[loc]] [[loc]] 0 1 2
15+
// CHECK-NEXT: [[lod_0:%[0-9]+]] = OpCompositeExtract %int [[loc]] 3
16+
// CHECK-NEXT: [[tex:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
17+
// CHECK-NEXT: [[tex_img:%[0-9]+]] = OpImage [[type_3d_image]] [[tex]]
18+
// CHECK-NEXT: {{%[0-9]+}} = OpImageFetch %v4float [[tex_img]] [[coord_0]] Lod [[lod_0]]
19+
float4 val1 = tex3d.Load(location4);
20+
21+
// CHECK: [[loc:%[0-9]+]] = OpLoad %v4int %location4
22+
// CHECK-NEXT: [[coord_0:%[0-9]+]] = OpVectorShuffle %v3int [[loc]] [[loc]] 0 1 2
23+
// CHECK-NEXT: [[lod_0:%[0-9]+]] = OpCompositeExtract %int [[loc]] 3
24+
// CHECK-NEXT: [[tex:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
25+
// CHECK-NEXT: [[tex_img:%[0-9]+]] = OpImage [[type_3d_image]] [[tex]]
26+
// CHECK-NEXT: {{%[0-9]+}} = OpImageFetch %v4float [[tex_img]] [[coord_0]] Lod|ConstOffset [[lod_0]] [[v3ic]]
27+
float4 val2 = tex3d.Load(location4, int3(1, 2, 3));
28+
29+
/////////////////////////////////
30+
/// Using the Status argument ///
31+
/////////////////////////////////
32+
33+
// CHECK: [[loc:%[0-9]+]] = OpLoad %v4int %location4
34+
// CHECK-NEXT: [[coord_0:%[0-9]+]] = OpVectorShuffle %v3int [[loc]] [[loc]] 0 1 2
35+
// CHECK-NEXT: [[lod_0:%[0-9]+]] = OpCompositeExtract %int [[loc]] 3
36+
// CHECK-NEXT: [[tex:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
37+
// CHECK-NEXT: [[tex_img:%[0-9]+]] = OpImage [[type_3d_image]] [[tex]]
38+
// CHECK-NEXT:[[structResult:%[0-9]+]] = OpImageSparseFetch %SparseResidencyStruct [[tex_img]] [[coord_0]] Lod|ConstOffset [[lod_0]] [[v3ic]]
39+
// CHECK-NEXT: [[status:%[0-9]+]] = OpCompositeExtract %uint [[structResult]] 0
40+
// CHECK-NEXT: OpStore %status [[status]]
41+
// CHECK-NEXT: [[v4result:%[0-9]+]] = OpCompositeExtract %v4float [[structResult]] 1
42+
// CHECK-NEXT: OpStore %val3 [[v4result]]
43+
float4 val3 = tex3d.Load(location4, int3(1, 2, 3), status);
44+
45+
return 1.0;
46+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %dxc -T ps_6_7 -E main -fcgl %s -spirv | FileCheck %s
2+
3+
// CHECK: %type_3d_image = OpTypeImage %float 3D 0 0 0 1 Unknown
4+
// CHECK: %type_sampled_image = OpTypeSampledImage %type_3d_image
5+
6+
vk::SampledTexture3D<float4> tex3d;
7+
8+
void main() {
9+
uint3 pos1 = uint3(1, 2, 3);
10+
11+
// CHECK: [[pos1:%[a-zA-Z0-9_]+]] = OpLoad %v3uint %pos1
12+
// CHECK: [[tex1_load:%[a-zA-Z0-9_]+]] = OpLoad %type_sampled_image %tex3d
13+
// CHECK: [[tex_image:%[a-zA-Z0-9_]+]] = OpImage %type_3d_image [[tex1_load]]
14+
// CHECK: [[fetch_result:%[a-zA-Z0-9_]+]] = OpImageFetch %v4float [[tex_image]] [[pos1]] Lod %uint_2
15+
// CHECK: OpStore %a1 [[fetch_result]]
16+
float4 a1 = tex3d.mips[2][pos1];
17+
}

0 commit comments

Comments
 (0)