Skip to content

Commit 81e86e5

Browse files
committed
Texture2DMS fixes: missing ResProp data; reflection default NumSamples = 0 (#3578)
- Fix missing component type and count for Texture2DMS in ResProps - Fix reflection for Texture2DMS with default NumSamples
1 parent 402b54e commit 81e86e5

8 files changed

Lines changed: 162 additions & 12 deletions

File tree

lib/DXIL/DxilResourceProperties.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ DxilResourceProperties loadPropsFromResourceBase(const DxilResourceBase *Res) {
159159
break;
160160
case DXIL::ResourceKind::Texture2DMS:
161161
case DXIL::ResourceKind::Texture2DMSArray:
162-
break;
163162
case DXIL::ResourceKind::TypedBuffer:
164163
case DXIL::ResourceKind::Texture1D:
165164
case DXIL::ResourceKind::Texture2D:

lib/HLSL/DxilContainerReflection.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,9 @@ void DxilModuleReflection::CreateReflectionObjectForResource(DxilResourceBase *R
16311631
if (inputBind.NumSamples == 0) {
16321632
if (R->IsStructuredBuffer()) {
16331633
inputBind.NumSamples = CalcResTypeSize(*m_pDxilModule, *R);
1634-
} else if (!R->IsRawBuffer() && !R->IsTBuffer()) {
1634+
} else if (!R->IsRawBuffer() && !R->IsTBuffer() &&
1635+
R->GetKind() != DXIL::ResourceKind::Texture2DMS &&
1636+
R->GetKind() != DXIL::ResourceKind::Texture2DMSArray) {
16351637
inputBind.NumSamples = 0xFFFFFFFF;
16361638
}
16371639
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// RUN: %dxc -T ps_6_0 -E main %s | %D3DReflect %s | FileCheck %s
2+
3+
Texture2DMS<float4> msTexture;
4+
Texture2DMSArray<float4> msTextureArray : register(t2, space2);
5+
6+
// Not sure what -1 means, but it's legal for fxc, and it's preserved, so we match it here.
7+
Texture2DMS<float4, -1> msTexture1 : register(t1);
8+
Texture2DMSArray<float4, -1> msTextureArray1 : register(t2);
9+
10+
Texture2DMS<float4, 8> msTexture2 : register(t3);
11+
Texture2DMSArray<float4, 4> msTextureArray2 : register(t4);
12+
13+
float4 main(uint4 color : COLOR) : SV_TARGET
14+
{
15+
return float4(0,0,0,0)
16+
+ msTexture.sample[2][color.xy]
17+
+ msTextureArray.sample[3][color.xyz]
18+
+ msTexture1.sample[2][color.xy]
19+
+ msTextureArray1.sample[3][color.xyz]
20+
+ msTexture2.sample[2][color.xy]
21+
+ msTextureArray2.sample[3][color.xyz]
22+
;
23+
}
24+
25+
// CHECK: ID3D12ShaderReflection:
26+
// CHECK: Bound Resources:
27+
// CHECK: D3D12_SHADER_BUFFER_DESC: Name: msTexture
28+
// CHECK-NEXT: Type: D3D_SIT_TEXTURE
29+
// CHECK-NEXT: uID: 0
30+
// CHECK-NEXT: BindCount: 1
31+
// CHECK-NEXT: BindPoint: 0
32+
// CHECK-NEXT: Space: 0
33+
// CHECK-NEXT: ReturnType: D3D_RETURN_TYPE_FLOAT
34+
// CHECK-NEXT: Dimension: D3D_SRV_DIMENSION_TEXTURE2DMS
35+
// CHECK-NEXT: NumSamples (or stride): 0
36+
// CHECK-NEXT: uFlags: (D3D_SIF_TEXTURE_COMPONENT_0 | D3D_SIF_TEXTURE_COMPONENT_1)
37+
// CHECK: D3D12_SHADER_BUFFER_DESC: Name: msTextureArray
38+
// CHECK-NEXT: Type: D3D_SIT_TEXTURE
39+
// CHECK-NEXT: uID: 1
40+
// CHECK-NEXT: BindCount: 1
41+
// CHECK-NEXT: BindPoint: 2
42+
// CHECK-NEXT: Space: 2
43+
// CHECK-NEXT: ReturnType: D3D_RETURN_TYPE_FLOAT
44+
// CHECK-NEXT: Dimension: D3D_SRV_DIMENSION_TEXTURE2DMSARRAY
45+
// CHECK-NEXT: NumSamples (or stride): 0
46+
// CHECK-NEXT: uFlags: (D3D_SIF_TEXTURE_COMPONENT_0 | D3D_SIF_TEXTURE_COMPONENT_1)
47+
// CHECK: D3D12_SHADER_BUFFER_DESC: Name: msTexture1
48+
// CHECK-NEXT: Type: D3D_SIT_TEXTURE
49+
// CHECK-NEXT: uID: 2
50+
// CHECK-NEXT: BindCount: 1
51+
// CHECK-NEXT: BindPoint: 1
52+
// CHECK-NEXT: Space: 0
53+
// CHECK-NEXT: ReturnType: D3D_RETURN_TYPE_FLOAT
54+
// CHECK-NEXT: Dimension: D3D_SRV_DIMENSION_TEXTURE2DMS
55+
// CHECK-NEXT: NumSamples (or stride): 4294967295
56+
// CHECK-NEXT: uFlags: (D3D_SIF_TEXTURE_COMPONENT_0 | D3D_SIF_TEXTURE_COMPONENT_1)
57+
// CHECK: D3D12_SHADER_BUFFER_DESC: Name: msTextureArray1
58+
// CHECK-NEXT: Type: D3D_SIT_TEXTURE
59+
// CHECK-NEXT: uID: 3
60+
// CHECK-NEXT: BindCount: 1
61+
// CHECK-NEXT: BindPoint: 2
62+
// CHECK-NEXT: Space: 0
63+
// CHECK-NEXT: ReturnType: D3D_RETURN_TYPE_FLOAT
64+
// CHECK-NEXT: Dimension: D3D_SRV_DIMENSION_TEXTURE2DMSARRAY
65+
// CHECK-NEXT: NumSamples (or stride): 4294967295
66+
// CHECK-NEXT: uFlags: (D3D_SIF_TEXTURE_COMPONENT_0 | D3D_SIF_TEXTURE_COMPONENT_1)
67+
// CHECK: D3D12_SHADER_BUFFER_DESC: Name: msTexture2
68+
// CHECK-NEXT: Type: D3D_SIT_TEXTURE
69+
// CHECK-NEXT: uID: 4
70+
// CHECK-NEXT: BindCount: 1
71+
// CHECK-NEXT: BindPoint: 3
72+
// CHECK-NEXT: Space: 0
73+
// CHECK-NEXT: ReturnType: D3D_RETURN_TYPE_FLOAT
74+
// CHECK-NEXT: Dimension: D3D_SRV_DIMENSION_TEXTURE2DMS
75+
// CHECK-NEXT: NumSamples (or stride): 8
76+
// CHECK-NEXT: uFlags: (D3D_SIF_TEXTURE_COMPONENT_0 | D3D_SIF_TEXTURE_COMPONENT_1)
77+
// CHECK: D3D12_SHADER_BUFFER_DESC: Name: msTextureArray2
78+
// CHECK-NEXT: Type: D3D_SIT_TEXTURE
79+
// CHECK-NEXT: uID: 5
80+
// CHECK-NEXT: BindCount: 1
81+
// CHECK-NEXT: BindPoint: 4
82+
// CHECK-NEXT: Space: 0
83+
// CHECK-NEXT: ReturnType: D3D_RETURN_TYPE_FLOAT
84+
// CHECK-NEXT: Dimension: D3D_SRV_DIMENSION_TEXTURE2DMSARRAY
85+
// CHECK-NEXT: NumSamples (or stride): 4
86+
// CHECK-NEXT: uFlags: (D3D_SIF_TEXTURE_COMPONENT_0 | D3D_SIF_TEXTURE_COMPONENT_1)

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/annotateHandle.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Make sure sampler and texture get correct annotateHandle.
1010

1111
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 2, i32 1033 })
12-
// CHECK-SAME: resource: Texture2D<F32>
12+
// CHECK-SAME: resource: Texture2D<4xF32>
1313
// CHECK-DAG:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 14, i32 0 })
1414
// CHECK-SAME: resource: SamplerState
1515

tools/clang/test/HLSLFileCheck/hlsl/intrinsics/createHandleFromHeap/createFromHeap3.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 false, i1 false)
1212
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 2, i32 1033 })
13-
//CHECK-SAME: resource: Texture2D<F32>
13+
//CHECK-SAME: resource: Texture2D<4xF32>
1414
//CHECK:call %dx.types.Handle @dx.op.createHandleFromHeap(i32 218, i32 0, i1 true, i1 false)
1515
//CHECK:call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 14, i32 0 })
1616
//CHECK-SAME: resource: SamplerState
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DCC=1 -DSCALAR=1 | FileCheck %s -DELTY=F32 -DPROP1=265
2+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DCC=1 -DSCALAR=1 -DSC=,0 | FileCheck %s -DELTY=F32 -DPROP1=265
3+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DCC=1 -DSCALAR=1 -DSC=,8 | FileCheck %s -DELTY=F32 -DPROP1=265
4+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DCC=1 | FileCheck %s -DELTY=F32 -DPROP1=265
5+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DCC=2 | FileCheck %s -DELTY=2xF32 -DPROP1=521
6+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DCC=3 | FileCheck %s -DELTY=3xF32 -DPROP1=777
7+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float | FileCheck %s -DELTY=4xF32 -DPROP1=1033
8+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DSC=,0 | FileCheck %s -DELTY=4xF32 -DPROP1=1033
9+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float -DSC=,8 | FileCheck %s -DELTY=4xF32 -DPROP1=1033
10+
11+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=int | FileCheck %s -DELTY=4xI32 -DPROP1=1028
12+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=uint | FileCheck %s -DELTY=4xU32 -DPROP1=1029
13+
14+
// half is float for shader type unless -enable-16bit-types is specified
15+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=half | FileCheck %s -DELTY=4xF32 -DPROP1=1033
16+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=half -enable-16bit-types | FileCheck %s -DELTY=4xF16 -DPROP1=1032
17+
18+
// component type is shader type, not storage type,
19+
// so it's 16-bit for min-precision with or without -enable-16bit-types
20+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=min16float | FileCheck %s -DELTY=4xF16 -DPROP1=1032
21+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=min16float -enable-16bit-types | FileCheck %s -DELTY=4xF16 -DPROP1=1032
22+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=min16int | FileCheck %s -DELTY=4xI16 -DPROP1=1026
23+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=min16int -enable-16bit-types | FileCheck %s -DELTY=4xI16 -DPROP1=1026
24+
25+
// Native 16-bit type looks the same in props as min16
26+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=float16_t -enable-16bit-types | FileCheck %s -DELTY=4xF16 -DPROP1=1032
27+
// RUN: %dxc -E main -T ps_6_6 %s -DCT=int16_t -enable-16bit-types | FileCheck %s -DELTY=4xI16 -DPROP1=1026
28+
29+
// Ensure that MS textures from heap have expected properties
30+
31+
// CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 3, i32 [[PROP1]] })
32+
// CHECK-SAME: resource: Texture2DMS<[[ELTY]]>
33+
// CHECK: call %dx.types.Handle @dx.op.annotateHandle(i32 216, %dx.types.Handle %{{.*}}, %dx.types.ResourceProperties { i32 8, i32 [[PROP1]] })
34+
// CHECK-SAME: resource: Texture2DMSArray<[[ELTY]]>
35+
36+
// CT = ComponentType
37+
// CC = ComponentCount
38+
#ifndef CC
39+
#define CC 4
40+
#endif
41+
// SC = SampleCount
42+
#ifndef SC
43+
#define SC
44+
#endif
45+
46+
#ifdef SCALAR
47+
Texture2DMS<CT SC> TexMS_scalar : register(t0);
48+
Texture2DMSArray<CT SC> TexMSA_scalar : register(t1);
49+
#else
50+
Texture2DMS<vector<CT, CC> SC> TexMS_vector : register(t0);
51+
Texture2DMSArray<vector<CT, CC> SC> TexMSA_vector : register(t1);
52+
#endif
53+
54+
vector<CT, CC> main(int4 a : A, float4 coord : TEXCOORD) : SV_TARGET
55+
{
56+
return (vector<CT, CC>)(0)
57+
#ifdef SCALAR
58+
+ TexMS_scalar.Load(a.xy, a.w)
59+
+ TexMSA_scalar.Load(a.xyz, a.w)
60+
#else
61+
+ TexMS_vector.Load(a.xy, a.w)
62+
+ TexMSA_vector.Load(a.xyz, a.w)
63+
#endif
64+
;
65+
}

tools/clang/tools/dxcompiler/dxcdisassembler.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,16 +1393,13 @@ void PrintResourceProperties(DxilResourceProperties &RP,
13931393
case DXIL::ResourceKind::Texture2DArray:
13941394
case DXIL::ResourceKind::TextureCubeArray:
13951395
case DXIL::ResourceKind::TypedBuffer:
1396-
OS << GC << RW << ResourceKindToString(RP.getResourceKind());
1397-
OS << "<" << CompTypeToString(RP.getCompType())
1398-
<< (bUAV && RP.Typed.CompCount > 1 ? "[vec]" : "")
1399-
<< ">";
1400-
break;
1401-
14021396
case DXIL::ResourceKind::Texture2DMS:
14031397
case DXIL::ResourceKind::Texture2DMSArray:
1404-
OS << ResourceKindToString(RP.getResourceKind());
1405-
OS << "<" << CompTypeToString(RP.getCompType())
1398+
OS << GC << RW << ResourceKindToString(RP.getResourceKind());
1399+
OS << "<";
1400+
if (RP.Typed.CompCount > 1)
1401+
OS << std::to_string(RP.Typed.CompCount) << "x";
1402+
OS << CompTypeToString(RP.getCompType())
14061403
<< ">";
14071404
break;
14081405

tools/clang/unittests/HLSL/DxilContainerTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ TEST_F(DxilContainerTest, ReflectionMatchesDXBC_CheckIn) {
17991799
ReflectionTest(hlsl_test::GetPathToHlslDataFile(L"..\\HLSLFileCheck\\d3dreflect\\cb_sizes.hlsl").c_str(), false);
18001800
ReflectionTest(hlsl_test::GetPathToHlslDataFile(L"..\\HLSLFileCheck\\d3dreflect\\tbuffer.hlsl").c_str(), false,
18011801
D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY);
1802+
ReflectionTest(hlsl_test::GetPathToHlslDataFile(L"..\\HLSLFileCheck\\d3dreflect\\texture2dms.hlsl").c_str(), false);
18021803
}
18031804

18041805
TEST_F(DxilContainerTest, ReflectionMatchesDXBC_Full) {

0 commit comments

Comments
 (0)