Skip to content

Commit 997e2f4

Browse files
authored
[SPIR-V][vk::SampledTexture] #10. Add tests for each SampledTexture function overloads. (#8287)
Part of #7979 Restructured to test each function overloads.
1 parent 54afd2c commit 997e2f4

67 files changed

Lines changed: 1611 additions & 398 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6208,7 +6208,23 @@ class HLSLExternalSource : public ExternalSemaSource {
62086208
if (IsBuiltinTable(tableName) && intrinOp == IntrinsicOp::MOP_SampleBias) {
62096209
// Remove this when update intrinsic table not affect other things.
62106210
// Change vector<float,1> into float for bias.
6211-
const unsigned biasOperandID = 3; // return type, sampler, coord, bias.
6211+
// The bias operand is the 3rd operand for normal texture types, but 2nd
6212+
// operand for sampledtexture types.
6213+
const bool firstArgIsSampler =
6214+
intrinsic->uNumArgs > 1 && ([&]() {
6215+
switch (intrinsic->pArgs[1].uLegalComponentTypes) {
6216+
case LICOMPTYPE_SAMPLER1D:
6217+
case LICOMPTYPE_SAMPLER2D:
6218+
case LICOMPTYPE_SAMPLER3D:
6219+
case LICOMPTYPE_SAMPLERCUBE:
6220+
case LICOMPTYPE_SAMPLERCMP:
6221+
case LICOMPTYPE_SAMPLER:
6222+
return true;
6223+
default:
6224+
return false;
6225+
}
6226+
})();
6227+
const unsigned biasOperandID = firstArgIsSampler ? 3 : 2;
62126228
DXASSERT(parameterTypeCount > biasOperandID,
62136229
"else operation was misrecognized");
62146230
if (const ExtVectorType *VecTy =

tools/clang/test/CodeGenSPIRV/vk.sampledtexture.access.hlsl renamed to tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.access.hlsl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
66
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
7-
// CHECK: [[type_2d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 0 1 Unknown
8-
// CHECK: [[type_2d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_array]]
97

108
vk::SampledTexture2D<float4> tex2d;
11-
vk::SampledTexture2DArray<float4> tex2dArray;
129

1310
void main() {
1411
// CHECK: OpStore %pos1 [[cu12]]
@@ -20,11 +17,4 @@ void main() {
2017
uint2 pos1 = uint2(1,2);
2118
float4 a1 = tex2d[pos1];
2219

23-
// CHECK: [[pos2:%[0-9]+]] = OpLoad %v3uint %pos2
24-
// CHECK-NEXT: [[tex2_load:%[a-zA-Z0-9_]+]] = OpLoad [[type_2d_sampled_image_array]] %tex2dArray
25-
// CHECK-NEXT: [[tex2_img:%[0-9]+]] = OpImage [[type_2d_image_array]] [[tex2_load]]
26-
// CHECK-NEXT: [[result2:%[0-9]+]] = OpImageFetch %v4float [[tex2_img]] [[pos2]] Lod %uint_0
27-
// CHECK-NEXT: OpStore %a2 [[result2]]
28-
uint3 pos2 = uint3(1,2,3);
29-
float4 a2 = tex2dArray[pos2];
3020
}

tools/clang/test/CodeGenSPIRV/vk.sampledtexture.calculate-lod-unclamped.hlsl renamed to tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.calculate-lod-unclamped.hlsl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
66
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
7-
// CHECK: [[type_2d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 0 1 Unknown
8-
// CHECK: [[type_2d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_array]]
97

108
vk::SampledTexture2D<float4> tex2d;
11-
vk::SampledTexture2DArray<float4> tex2dArray;
129

1310
void main() {
1411
float2 xy = float2(0.5, 0.5);
@@ -19,9 +16,4 @@ void main() {
1916
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query]] 1
2017
float lod1 = tex2d.CalculateLevelOfDetailUnclamped(xy);
2118

22-
//CHECK: [[tex2_load:%[a-zA-Z0-9_]+]] = OpLoad [[type_2d_sampled_image_array]] %tex2dArray
23-
//CHECK-NEXT: [[xy_load_2:%[a-zA-Z0-9_]+]] = OpLoad %v2float %xy
24-
//CHECK-NEXT: [[query2:%[a-zA-Z0-9_]+]] = OpImageQueryLod %v2float [[tex2_load]] [[xy_load_2]]
25-
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query2]] 1
26-
float lod2 = tex2dArray.CalculateLevelOfDetailUnclamped(xy);
2719
}

tools/clang/test/CodeGenSPIRV/vk.sampledtexture.calculate-lod.hlsl renamed to tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.calculate-lod.hlsl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
66
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
7-
// CHECK: [[type_2d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 0 1 Unknown
8-
// CHECK: [[type_2d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_array]]
97

108
vk::SampledTexture2D<float4> tex2d;
11-
vk::SampledTexture2DArray<float4> tex2dArray;
129

1310
void main() {
1411
float2 xy = float2(0.5, 0.5);
@@ -19,9 +16,4 @@ void main() {
1916
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query]] 0
2017
float lod = tex2d.CalculateLevelOfDetail(xy);
2118

22-
//CHECK: [[tex2:%[a-zA-Z0-9_]+]] = OpLoad [[type_2d_sampled_image_array]] %tex2dArray
23-
//CHECK-NEXT: [[xy_load_2:%[a-zA-Z0-9_]+]] = OpLoad %v2float %xy
24-
//CHECK-NEXT: [[query2:%[a-zA-Z0-9_]+]] = OpImageQueryLod %v2float [[tex2]] [[xy_load_2]]
25-
//CHECK-NEXT: {{%[0-9]+}} = OpCompositeExtract %float [[query2]] 0
26-
float lod2 = tex2dArray.CalculateLevelOfDetail(xy);
2719
}

tools/clang/test/CodeGenSPIRV/vk.sampledtexture.gather-alpha.hlsl renamed to tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.gather-alpha.hlsl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44

55
// CHECK: [[v2fc:%[0-9]+]] = OpConstantComposite %v2float %float_0_5 %float_0_25
66
// CHECK: [[v2ic:%[0-9]+]] = OpConstantComposite %v2int %int_2 %int_3
7-
// CHECK: [[v3fc:%[0-9]+]] = OpConstantComposite %v3float %float_0_5 %float_0_25 %float_0
87

98
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
109
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
11-
// CHECK: [[type_2d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 0 1 Unknown
12-
// CHECK: [[type_2d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_array]]
1310

1411
vk::SampledTexture2D<float4> tex2d;
15-
vk::SampledTexture2DArray<float4> tex2dArray;
1612

1713
float4 main() : SV_Target {
1814
uint status;
@@ -49,9 +45,5 @@ float4 main() : SV_Target {
4945
// CHECK: OpStore %val [[res_alpha_o4_s]]
5046
val = tex2d.GatherAlpha(float2(0.5, 0.25), int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8), status);
5147

52-
// CHECK: [[tex2_load:%[a-zA-Z0-9_]+]] = OpLoad [[type_2d_sampled_image_array]] %tex2dArray
53-
// CHECK: [[val_alpha_array:%[a-zA-Z0-9_]+]] = OpImageGather %v4float [[tex2_load]] [[v3fc]] %int_3 None
54-
val = tex2dArray.GatherAlpha(float3(0.5, 0.25, 0));
55-
5648
return val;
5749
}

tools/clang/test/CodeGenSPIRV/vk.sampledtexture.gather-blue.hlsl renamed to tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.gather-blue.hlsl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44

55
// CHECK: [[v2fc:%[0-9]+]] = OpConstantComposite %v2float %float_0_5 %float_0_25
66
// CHECK: [[v2ic:%[0-9]+]] = OpConstantComposite %v2int %int_2 %int_3
7-
// CHECK: [[v3fc:%[0-9]+]] = OpConstantComposite %v3float %float_0_5 %float_0_25 %float_0
87

98
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
109
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
11-
// CHECK: [[type_2d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 0 1 Unknown
12-
// CHECK: [[type_2d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_array]]
1310

1411
vk::SampledTexture2D<float4> tex2d;
15-
vk::SampledTexture2DArray<float4> tex2dArray;
16-
1712

1813
float4 main() : SV_Target {
1914
uint status;
@@ -50,9 +45,5 @@ float4 main() : SV_Target {
5045
// CHECK: OpStore %val [[res_blue_o4_s]]
5146
val = tex2d.GatherBlue(float2(0.5, 0.25), int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8), status);
5247

53-
// CHECK: [[tex2_load:%[a-zA-Z0-9_]+]] = OpLoad [[type_2d_sampled_image_array]] %tex2dArray
54-
// CHECK: [[val_blue_array:%[a-zA-Z0-9_]+]] = OpImageGather %v4float [[tex2_load]] [[v3fc]] %int_2 None
55-
val = tex2dArray.GatherBlue(float3(0.5, 0.25, 0));
56-
5748
return val;
5849
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s
2+
3+
vk::SampledTexture2D<float4> myTexture : register(t1);
4+
5+
float4 main(float2 location: A, float comparator: B) : SV_Target {
6+
return myTexture.GatherCmpAlpha(location, comparator, int2(1, 2));
7+
}
8+
9+
// CHECK: :6:22: error: no equivalent for GatherCmpAlpha intrinsic method in Vulkan
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s
2+
3+
vk::SampledTexture2D<float4> myTexture : register(t1);
4+
5+
float4 main(float2 location: A, float comparator: B) : SV_Target {
6+
return myTexture.GatherCmpBlue(location, comparator, int2(1, 2));
7+
}
8+
9+
// CHECK: :6:22: error: no equivalent for GatherCmpBlue intrinsic method in Vulkan
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: not %dxc -T ps_6_0 -E main -fcgl %s -spirv 2>&1 | FileCheck %s
2+
3+
vk::SampledTexture2D<float4> myTexture : register(t1);
4+
5+
float4 main(float2 location: A, float comparator: B) : SV_Target {
6+
return myTexture.GatherCmpGreen(location, comparator, int2(1, 2));
7+
}
8+
9+
// CHECK: :6:22: error: no equivalent for GatherCmpGreen intrinsic method in Vulkan

tools/clang/test/CodeGenSPIRV/vk.sampledtexture.gather-cmp-red.hlsl renamed to tools/clang/test/CodeGenSPIRV/SampledTexture/SampledTexture2D/vk.sampledtexture2d.gather-cmp-red.hlsl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44

55
// CHECK: [[v2fc:%[0-9]+]] = OpConstantComposite %v2float %float_0_5 %float_0_25
66
// CHECK: [[v2ic:%[0-9]+]] = OpConstantComposite %v2int %int_2 %int_3
7-
// CHECK: [[v3fc:%[0-9]+]] = OpConstantComposite %v3float %float_0_5 %float_0_25 %float_0
87

98
// CHECK: [[type_2d_image:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 0 0 1 Unknown
109
// CHECK: [[type_2d_sampled_image:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image]]
11-
// CHECK: [[type_2d_image_array:%[a-zA-Z0-9_]+]] = OpTypeImage %float 2D 0 1 0 1 Unknown
12-
// CHECK: [[type_2d_sampled_image_array:%[a-zA-Z0-9_]+]] = OpTypeSampledImage [[type_2d_image_array]]
1310

1411
vk::SampledTexture2D<float4> tex2d;
15-
vk::SampledTexture2DArray<float4> tex2dArray;
1612

1713
float4 main() : SV_Target {
1814
uint status;
@@ -49,10 +45,5 @@ float4 main() : SV_Target {
4945
// CHECK: OpStore %val [[res_cmp_o4_s]]
5046
val = tex2d.GatherCmpRed(float2(0.5, 0.25), 0.5, int2(1, 2), int2(3, 4), int2(5, 6), int2(7, 8), status);
5147

52-
// CHECK: [[tex2_load:%[a-zA-Z0-9_]+]] = OpLoad [[type_2d_sampled_image_array]] %tex2dArray
53-
// CHECK: [[val_red_array:%[a-zA-Z0-9_]+]] = OpImageDrefGather %v4float [[tex2_load]] [[v3fc]] %float_0_5 None
54-
// CHECK: OpStore %val [[val_red_array]]
55-
val = tex2dArray.GatherCmpRed(float3(0.5, 0.25, 0), 0.5);
56-
5748
return val;
5849
}

0 commit comments

Comments
 (0)