Skip to content

Commit d5eacdf

Browse files
committed
SampledTexture3d
1 parent 0c75800 commit d5eacdf

7 files changed

Lines changed: 66 additions & 17 deletions

File tree

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") ? spv::Dim::Dim1D : (suffix.startswith("2D")
868+
? spv::Dim::Dim2D
869+
: 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: 20 additions & 3 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,7 +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
575-
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
576+
BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_VK_SAMPLED_TEXTURE3D
576577
#endif // ENABLE_SPIRV_CODEGEN
577578
// SPIRV change ends
578579

@@ -1293,6 +1294,8 @@ static const ArBasicKind g_VKSampledTexture2DMSCT[] = {
12931294
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS, AR_BASIC_UNKNOWN};
12941295
static const ArBasicKind g_VKSampledTexture2DMSArrayCT[] = {
12951296
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY, AR_BASIC_UNKNOWN};
1297+
static const ArBasicKind g_VKSampledTexture3DCT[] = {
1298+
AR_OBJECT_VK_SAMPLED_TEXTURE3D, AR_BASIC_UNKNOWN};
12961299
#endif
12971300

12981301
// Basic kinds, indexed by a LEGAL_INTRINSIC_COMPTYPES value.
@@ -1362,6 +1365,7 @@ const ArBasicKind *g_LegalIntrinsicCompTypes[] = {
13621365
g_VKSampledTexture2DArrayCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2D_ARRAY
13631366
g_VKSampledTexture2DMSCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS
13641367
g_VKSampledTexture2DMSArrayCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE2DMS_ARRAY
1368+
g_VKSampledTexture3DCT, // LICOMPTYPE_VK_SAMPLED_TEXTURE3D
13651369
#endif
13661370
};
13671371
static_assert(
@@ -1424,7 +1428,7 @@ static const ArBasicKind g_ArBasicKindsAsTypes[] = {
14241428
AR_OBJECT_VK_BUFFER_POINTER, AR_OBJECT_VK_SAMPLED_TEXTURE1D,
14251429
AR_OBJECT_VK_SAMPLED_TEXTURE1D_ARRAY, AR_OBJECT_VK_SAMPLED_TEXTURE2D,
14261430
AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY, AR_OBJECT_VK_SAMPLED_TEXTURE2DMS,
1427-
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY,
1431+
AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY, AR_OBJECT_VK_SAMPLED_TEXTURE3D,
14281432
#endif // ENABLE_SPIRV_CODEGEN
14291433
// SPIRV change ends
14301434

@@ -1542,6 +1546,7 @@ static const uint8_t g_ArBasicKindsTemplateCount[] = {
15421546
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
15431547
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
15441548
1, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
1549+
1, // AR_OBJECT_VK_SAMPLED_TEXTURE3D
15451550
#endif // ENABLE_SPIRV_CODEGEN
15461551
// SPIRV change ends
15471552

@@ -1701,6 +1706,7 @@ static const SubscriptOperatorRecord g_ArBasicKindsSubscripts[] = {
17011706
{3, MipsTrue, SampleFalse}, // AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY
17021707
{2, MipsFalse, SampleTrue}, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS
17031708
{3, MipsFalse, SampleTrue}, // AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY
1709+
{3, MipsTrue, SampleFalse}, // AR_OBJECT_VK_SAMPLED_TEXTURE3D
17041710
#endif // ENABLE_SPIRV_CODEGEN
17051711
// SPIRV change ends
17061712

@@ -1876,6 +1882,7 @@ static const char *g_ArBasicTypeNames[] = {
18761882
"SampledTexture2DArray",
18771883
"SampledTexture2DMS",
18781884
"SampledTexture2DMSArray",
1885+
"SampledTexture3D",
18791886
#endif // ENABLE_SPIRV_CODEGEN
18801887
// SPIRV change ends
18811888

@@ -2556,6 +2563,10 @@ static void GetIntrinsicMethods(ArBasicKind kind,
25562563
*intrinsics = g_VkSampledTexture2DMSArrayMethods;
25572564
*intrinsicCount = _countof(g_VkSampledTexture2DMSArrayMethods);
25582565
break;
2566+
case AR_OBJECT_VK_SAMPLED_TEXTURE3D:
2567+
*intrinsics = g_VkSampledTexture3DMethods;
2568+
*intrinsicCount = _countof(g_VkSampledTexture3DMethods);
2569+
break;
25592570
#endif
25602571
case AR_OBJECT_HIT_OBJECT:
25612572
*intrinsics = g_DxHitObjectMethods;
@@ -4166,7 +4177,8 @@ class HLSLExternalSource : public ExternalSemaSource {
41664177
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2D ||
41674178
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2D_ARRAY ||
41684179
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS ||
4169-
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY) {
4180+
kind == AR_OBJECT_VK_SAMPLED_TEXTURE2DMS_ARRAY ||
4181+
kind == AR_OBJECT_VK_SAMPLED_TEXTURE3D) {
41704182
if (!m_vkNSDecl)
41714183
continue;
41724184
QualType float4Type =
@@ -5004,6 +5016,7 @@ class HLSLExternalSource : public ExternalSemaSource {
50045016
#endif
50055017
case AR_OBJECT_TEXTURE2D:
50065018
case AR_OBJECT_TEXTURE2D_ARRAY:
5019+
case AR_OBJECT_VK_SAMPLED_TEXTURE3D:
50075020
case AR_OBJECT_TEXTURE3D:
50085021
case AR_OBJECT_TEXTURECUBE:
50095022
case AR_OBJECT_TEXTURECUBE_ARRAY:
@@ -5154,6 +5167,9 @@ class HLSLExternalSource : public ExternalSemaSource {
51545167
ResClass = DXIL::ResourceClass::UAV;
51555168
return true;
51565169
case AR_OBJECT_TEXTURE3D:
5170+
#ifdef ENABLE_SPIRV_CODEGEN
5171+
case AR_OBJECT_VK_SAMPLED_TEXTURE3D:
5172+
#endif
51575173
ResKind = DXIL::ResourceKind::Texture3D;
51585174
ResClass = DXIL::ResourceClass::SRV;
51595175
return true;
@@ -11735,6 +11751,7 @@ void hlsl::DiagnoseRegisterType(clang::Sema *self, clang::SourceLocation loc,
1173511751
#endif
1173611752
case AR_OBJECT_TEXTURE2D:
1173711753
case AR_OBJECT_TEXTURE2D_ARRAY:
11754+
case AR_OBJECT_VK_SAMPLED_TEXTURE3D:
1173811755
case AR_OBJECT_TEXTURE3D:
1173911756
case AR_OBJECT_TEXTURECUBE:
1174011757
case AR_OBJECT_TEXTURECUBE_ARRAY:

tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.get-dimensions.hlsl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33

44
// CHECK: OpCapability ImageQuery
55

6-
// CHECK: [[type_1d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 1D 0 0 0 1 Unknown
7-
// CHECK: [[type_1d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_1d_image]]
8-
// CHECK: [[type_1d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 1D 0 1 0 1 Unknown
9-
// CHECK: [[type_1d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_1d_image_array]]
106
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
117
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
128

13-
vk::SampledTexture1D<float4> tex1d;
14-
vk::SampledTexture1DArray<float4> tex1dArray;
159
vk::SampledTexture2D<float4> tex2d;
1610

1711
void main() {
@@ -108,6 +102,13 @@ void main() {
108102
// CHECK-NEXT: OpStore %i_numLevels [[query_level_2_int]]
109103
tex2d.GetDimensions(mipLevel, i_width, i_height, i_numLevels);
110104

105+
// CHECK: [[t3d_load:%[0-9]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
106+
// CHECK-NEXT: [[image3d:%[0-9]+]] = OpImage [[type_3d_image]] [[t3d_load]]
107+
// CHECK-NEXT: [[query3d:%[0-9]+]] = OpImageQuerySizeLod %v3uint [[image3d]] %int_0
108+
// CHECK-NEXT: [[query3d_0:%[0-9]+]] = OpCompositeExtract %uint [[query3d]] 0
109+
// CHECK-NEXT: OpStore %width [[query3d_0]]
110+
tex3d.GetDimensions(width, height, elements);
111+
111112
#ifdef ERROR
112113
// ERROR: error: Output argument must be an l-value
113114
tex2d.GetDimensions(mipLevel, 0, height, numLevels);

tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.sample-bias.hlsl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66
// CHECK: [[v2fc:%[0-9]+]] = OpConstantComposite %v2float %float_0_5 %float_0_25
77
// CHECK: [[v2ic:%[0-9]+]] = OpConstantComposite %v2int %int_2 %int_3
88

9-
// CHECK: [[type_1d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 1D 0 0 0 1 Unknown
10-
// CHECK: [[type_1d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_1d_image]]
11-
// CHECK: [[type_1d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 1D 0 1 0 1 Unknown
12-
// CHECK: [[type_1d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_1d_image_array]]
139
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
1410
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
1511

16-
vk::SampledTexture1D<float4> tex1d;
17-
vk::SampledTexture1DArray<float4> tex1dArray;
1812
vk::SampledTexture2D<float4> tex2d;
1913

2014
float4 main() : SV_Target {
@@ -45,5 +39,9 @@ float4 main() : SV_Target {
4539
// CHECK: [[sampled_1da:%[a-zA-Z0-9_]+]] = OpImageSampleImplicitLod %v4float [[tex1da_load]] {{%[0-9]+}} Bias|ConstOffset %float_0_5 %int_1
4640
float4 val6 = tex1dArray.SampleBias(float2(0.5, 0), 0.5f, 1);
4741

42+
// CHECK: [[tex3d_load:%[a-zA-Z0-9_]+]] = OpLoad [[type_3d_sampled_image]] %tex3d
43+
// CHECK: [[sampled_3d:%[a-zA-Z0-9_]+]] = OpImageSampleImplicitLod %v4float [[tex3d_load]] [[v3fc]] Bias|ConstOffset %float_0_5 [[v3ic]]
44+
float4 val7 = tex3d.SampleBias(float3(0.5, 0.25, 0), 0.5f, int3(1, 2, 3));
45+
4846
return 1.0;
4947
}

utils/hct/gen_intrin_main.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,4 +1512,33 @@ namespace VkSampledTexture2DMSArrayMethods {
15121512
$classT [[]] Load(in int<3> x, in int s, in int<2> o, out uint_only status) : texture2darray_ms_o_s;
15131513
} namespace
15141514

1515+
namespace VkSampledTexture3DMethods {
1516+
1517+
float [[ro]] CalculateLevelOfDetail(in float<3> x) : tex3d_t_calc_lod;
1518+
float [[ro]] CalculateLevelOfDetailUnclamped(in float<3> x) : tex3d_t_calc_lod_unclamped;
1519+
void [[]] GetDimensions(in uint x, out uint_only width, out $type2 height, out $type2 depth, out $type2 levels) : resinfo_uint;
1520+
void [[]] GetDimensions(in uint x, out float_like width, out $type2 height, out $type2 depth, out $type2 levels) : resinfo;
1521+
void [[]] GetDimensions(out uint_only width, out $type1 height, out $type1 depth) : resinfo_uint_o;
1522+
void [[]] GetDimensions(out float_like width, out $type1 height, out $type1 depth) : resinfo_o;
1523+
$classT [[ro]] Load(in int<4> x) : tex3d_t_load;
1524+
$classT [[ro]] Load(in int<4> x, in int<3> o) : tex3d_t_load_o;
1525+
$classT [[]] Load(in int<4> x, in int<3> o, out uint_only status) : tex3d_t_load_o_s;
1526+
$classT [[ro]] Sample(in float<3> x) : tex3d_t;
1527+
$classT [[ro]] Sample(in float<3> x, in int<3> o) : tex3d_t_o;
1528+
$classT [[ro]] SampleBias(in float<3> x, in float bias) : tex3d_t_bias;
1529+
$classT [[ro]] SampleBias(in float<3> x, in float bias, in int<3> o) : tex3d_t_bias_o;
1530+
$classT [[ro]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy) : tex3d_t_dd;
1531+
$classT [[ro]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy, in int<3> o) : tex3d_t_dd_o;
1532+
$classT [[ro]] SampleLevel(in float<3> x, in float lod) : tex3d_t_lod;
1533+
$classT [[ro]] SampleLevel(in float<3> x, in float lod, in int<3> o) : tex3d_t_lod_o;
1534+
$classT [[ro]] Sample(in float<3> x, in int<3> o, in float clamp) : tex3d_t_o_cl;
1535+
$classT [[]] Sample(in float<3> x, in int<3> o, in float clamp, out uint_only status) : tex3d_t_o_cl_s;
1536+
$classT [[]] SampleLevel(in float<3> x, in float lod, in int<3> o, out uint_only status) : tex3d_t_lod_o_s;
1537+
$classT [[ro]] SampleBias(in float<3> x, in float bias, in int<3> o, in float clamp) : tex3d_t_bias_o_cl;
1538+
$classT [[]] SampleBias(in float<3> x, in float bias, in int<3> o, in float clamp, out uint_only status) : tex3d_t_bias_o_cl_s;
1539+
$classT [[]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy, in int<3> o, in float clamp) : tex3d_t_dd_o_cl;
1540+
$classT [[]] SampleGrad(in float<3> x, in $type1 ddx, in $type1 ddy, in int<3> o, in float clamp, out uint_only status) : tex3d_t_dd_o_cl_s;
1541+
} namespace
1542+
1543+
15151544
// SPIRV Change Ends

0 commit comments

Comments
 (0)