summaryrefslogtreecommitdiffstats
path: root/source/x/vulkan-sdk/DirectXShaderCompiler-dump-reflection.patch
blob: 088c976d6152f02bc8a6b15bc0a46de0ba3138f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
From daf1386161cd6912fbd358f13d74e81466edab8b Mon Sep 17 00:00:00 2001
From: Xiang Li <python3kgae@outlook.com>
Date: Wed, 24 May 2023 13:13:36 -0400
Subject: [PATCH] [dxa] Add option to dump reflection (#5232)

* [dxa] Add option to dump reflection

New option -dumpreflection is added to dump reflection data.
This is to support %D3DReflect test in lit.

* Move Reflection dump to DxilContainer.
---
 lib/DxilContainer/CMakeLists.txt              |  3 +
 .../DxilContainer}/D3DReflectionDumper.cpp    |  0
 .../DxilContainer}/D3DReflectionStrings.cpp   |  0
 .../DxilContainer}/RDATDumper.cpp             |  0
 tools/clang/test/DXC/dxa_tests.test           | 73 +++++++++++++++++++
 tools/clang/tools/dxa/CMakeLists.txt          |  1 -
 tools/clang/tools/dxa/dxa.cpp                 | 72 +++++++++++++++++-
 .../unittests/HLSLTestLib/CMakeLists.txt      |  3 -
 utils/hct/hcttestcmds.cmd                     |  7 ++
 9 files changed, 153 insertions(+), 6 deletions(-)
 rename {tools/clang/unittests/HLSLTestLib => lib/DxilContainer}/D3DReflectionDumper.cpp (100%)
 rename {tools/clang/unittests/HLSLTestLib => lib/DxilContainer}/D3DReflectionStrings.cpp (100%)
 rename {tools/clang/unittests/HLSLTestLib => lib/DxilContainer}/RDATDumper.cpp (100%)

diff --git a/lib/DxilContainer/CMakeLists.txt b/lib/DxilContainer/CMakeLists.txt
index f0ab344d23..a6369a36e6 100644
--- a/lib/DxilContainer/CMakeLists.txt
+++ b/lib/DxilContainer/CMakeLists.txt
@@ -1,12 +1,15 @@
 # Copyright (C) Microsoft Corporation. All rights reserved.
 # This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
 add_llvm_library(LLVMDxilContainer
+  D3DReflectionDumper.cpp
+  D3DReflectionStrings.cpp
   DxilContainer.cpp
   DxilContainerAssembler.cpp
   DxilContainerReader.cpp
   DxcContainerBuilder.cpp
   DxilRDATBuilder.cpp
   DxilRuntimeReflection.cpp
+  RDATDumper.cpp
   RDATDxilSubobjects.cpp
 
   ADDITIONAL_HEADER_DIRS
diff --git a/tools/clang/unittests/HLSLTestLib/D3DReflectionDumper.cpp b/lib/DxilContainer/D3DReflectionDumper.cpp
similarity index 100%
rename from tools/clang/unittests/HLSLTestLib/D3DReflectionDumper.cpp
rename to lib/DxilContainer/D3DReflectionDumper.cpp
diff --git a/tools/clang/unittests/HLSLTestLib/D3DReflectionStrings.cpp b/lib/DxilContainer/D3DReflectionStrings.cpp
similarity index 100%
rename from tools/clang/unittests/HLSLTestLib/D3DReflectionStrings.cpp
rename to lib/DxilContainer/D3DReflectionStrings.cpp
diff --git a/tools/clang/unittests/HLSLTestLib/RDATDumper.cpp b/lib/DxilContainer/RDATDumper.cpp
similarity index 100%
rename from tools/clang/unittests/HLSLTestLib/RDATDumper.cpp
rename to lib/DxilContainer/RDATDumper.cpp
diff --git a/tools/clang/test/DXC/dxa_tests.test b/tools/clang/test/DXC/dxa_tests.test
index a7d8ee5bad..655155941b 100644
--- a/tools/clang/test/DXC/dxa_tests.test
+++ b/tools/clang/test/DXC/dxa_tests.test
@@ -34,3 +34,76 @@
 // RUN: %dxc -dumpbin %t.rebuilt-container2.cso | FileCheck %s --check-prefix=REBUILD
 
 // REBUILD:define void @main()
+
+// RUN: %dxa %t.dxa.cso -dumpreflection | FileCheck %s --check-prefix=REFLECTION
+// REFLECTION: ID3D12ShaderReflection:
+// REFLECTION-NEXT: D3D12_SHADER_DESC:
+// REFLECTION-NEXT:     Shader Version: Vertex 6.0
+// REFLECTION-NEXT:     Creator: dxc
+// REFLECTION-NEXT:     Flags: 0
+// REFLECTION-NEXT:     ConstantBuffers: 1
+// REFLECTION-NEXT:     BoundResources: 1
+// REFLECTION-NEXT:     InputParameters: 0
+// REFLECTION-NEXT:     OutputParameters: 1
+// REFLECTION-NEXT:     InstructionCount: 10
+// REFLECTION-NEXT:     TempArrayCount: 0
+// REFLECTION-NEXT:     DynamicFlowControlCount: 0
+// REFLECTION-NEXT:     ArrayInstructionCount: 0
+// REFLECTION-NEXT:     TextureNormalInstructions: 0
+// REFLECTION-NEXT:     TextureLoadInstructions: 0
+// REFLECTION-NEXT:     TextureCompInstructions: 0
+// REFLECTION-NEXT:     TextureBiasInstructions: 0
+// REFLECTION-NEXT:     TextureGradientInstructions: 0
+// REFLECTION-NEXT:     FloatInstructionCount: 1
+// REFLECTION-NEXT:     IntInstructionCount: 1
+// REFLECTION-NEXT:     UintInstructionCount: 0
+// REFLECTION-NEXT:     CutInstructionCount: 0
+// REFLECTION-NEXT:     EmitInstructionCount: 0
+// REFLECTION-NEXT:     cBarrierInstructions: 0
+// REFLECTION-NEXT:     cInterlockedInstructions: 0
+// REFLECTION-NEXT:     cTextureStoreInstructions: 0
+// REFLECTION-NEXT:   OutputParameter Elements: 1
+// REFLECTION-NEXT:     D3D12_SIGNATURE_PARAMETER_DESC: SemanticName: SV_POSITION SemanticIndex: 0
+// REFLECTION-NEXT:       Register: 0
+// REFLECTION-NEXT:       SystemValueType: D3D_NAME_POSITION
+// REFLECTION-NEXT:       ComponentType: D3D_REGISTER_COMPONENT_FLOAT32
+// REFLECTION-NEXT:       Mask: xyzw (15)
+// REFLECTION-NEXT:       ReadWriteMask: ---- (0) (AlwaysReads/NeverWrites)
+// REFLECTION-NEXT:       Stream: 0
+// REFLECTION-NEXT:       MinPrecision: D3D_MIN_PRECISION_DEFAULT
+// REFLECTION-NEXT:   Constant Buffers:
+// REFLECTION-NEXT:     ID3D12ShaderReflectionConstantBuffer:
+// REFLECTION-NEXT:       D3D12_SHADER_BUFFER_DESC: Name: $Globals
+// REFLECTION-NEXT:         Type: D3D_CT_CBUFFER
+// REFLECTION-NEXT:         Size: 16
+// REFLECTION-NEXT:         uFlags: 0
+// REFLECTION-NEXT:         Num Variables: 1
+// REFLECTION-NEXT:       {
+// REFLECTION-NEXT:         ID3D12ShaderReflectionVariable:
+// REFLECTION-NEXT:           D3D12_SHADER_VARIABLE_DESC: Name: g
+// REFLECTION-NEXT:             Size: 4
+// REFLECTION-NEXT:             StartOffset: 0
+// REFLECTION-NEXT:             uFlags: (D3D_SVF_USED)
+// REFLECTION-NEXT:             DefaultValue: <nullptr>
+// REFLECTION-NEXT:           ID3D12ShaderReflectionType:
+// REFLECTION-NEXT:             D3D12_SHADER_TYPE_DESC: Name: int
+// REFLECTION-NEXT:               Class: D3D_SVC_SCALAR
+// REFLECTION-NEXT:               Type: D3D_SVT_INT
+// REFLECTION-NEXT:               Elements: 0
+// REFLECTION-NEXT:               Rows: 1
+// REFLECTION-NEXT:               Columns: 1
+// REFLECTION-NEXT:               Members: 0
+// REFLECTION-NEXT:               Offset: 0
+// REFLECTION-NEXT:           CBuffer: $Globals
+// REFLECTION-NEXT:       }
+// REFLECTION-NEXT:   Bound Resources:
+// REFLECTION-NEXT:     D3D12_SHADER_INPUT_BIND_DESC: Name: $Globals
+// REFLECTION-NEXT:       Type: D3D_SIT_CBUFFER
+// REFLECTION-NEXT:       uID: 0
+// REFLECTION-NEXT:       BindCount: 1
+// REFLECTION-NEXT:       BindPoint: 0
+// REFLECTION-NEXT:       Space: 0
+// REFLECTION-NEXT:       ReturnType: <unknown: 0>
+// REFLECTION-NEXT:       Dimension: D3D_SRV_DIMENSION_UNKNOWN
+// REFLECTION-NEXT:       NumSamples (or stride): 0
+// REFLECTION-NEXT:       uFlags: (D3D_SIF_USERPACKED)
diff --git a/tools/clang/tools/dxa/CMakeLists.txt b/tools/clang/tools/dxa/CMakeLists.txt
index 391ac8b062..33e61ca121 100644
--- a/tools/clang/tools/dxa/CMakeLists.txt
+++ b/tools/clang/tools/dxa/CMakeLists.txt
@@ -23,7 +23,6 @@ add_clang_executable(dxa
 
 target_link_libraries(dxa
   dxcompiler
-  HLSLTestLib
   )
 
 set_target_properties(dxa PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})
diff --git a/tools/clang/tools/dxa/dxa.cpp b/tools/clang/tools/dxa/dxa.cpp
index dd3a0e64c4..cf9339afdc 100644
--- a/tools/clang/tools/dxa/dxa.cpp
+++ b/tools/clang/tools/dxa/dxa.cpp
@@ -19,6 +19,7 @@
 #include "dxc/DxilContainer/DxilContainer.h"
 #include "dxc/DxilRootSignature/DxilRootSignature.h"
 #include "dxc/Test/RDATDumper.h"
+#include "dxc/Test/D3DReflectionDumper.h"
 
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support//MSFileSystem.h"
@@ -63,6 +64,10 @@ static cl::opt<bool> DumpRDAT("dumprdat",
                               cl::desc("Dump RDAT"),
                               cl::init(false));
 
+static cl::opt<bool> DumpReflection("dumpreflection",
+                              cl::desc("Dump reflection"),
+                              cl::init(false));
+
 class DxaContext {
 
 private:
@@ -80,6 +85,7 @@ class DxaContext {
   void ListParts();
   void DumpRS();
   void DumpRDAT();
+  void DumpReflection();
 };
 
 void DxaContext::Assemble() {
@@ -378,6 +384,66 @@ void DxaContext::DumpRDAT() {
   printf("%s", ss.str().c_str());
 }
 
+void DxaContext::DumpReflection() {
+  CComPtr<IDxcBlobEncoding> pSource;
+  ReadFileIntoBlob(m_dxcSupport, StringRefWide(InputFilename), &pSource);
+
+  CComPtr<IDxcContainerReflection> pReflection;
+  IFT(m_dxcSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection));
+  IFT(pReflection->Load(pSource));
+
+  UINT32 partCount;
+  IFT(pReflection->GetPartCount(&partCount));
+
+  bool blobFound = false;
+  std::ostringstream ss;
+  hlsl::dump::D3DReflectionDumper dumper(ss);
+
+  CComPtr<ID3D12ShaderReflection> pShaderReflection;
+  CComPtr<ID3D12LibraryReflection> pLibraryReflection;
+  for (uint32_t i = 0; i < partCount; ++i) {
+    uint32_t kind;
+    IFT(pReflection->GetPartKind(i, &kind));
+    if (kind == (uint32_t)hlsl::DxilFourCC::DFCC_DXIL) {
+      blobFound = true;
+      CComPtr<IDxcBlob> pPart;
+      IFT(pReflection->GetPartContent(i, &pPart));
+      const hlsl::DxilProgramHeader *pProgramHeader =
+        reinterpret_cast<const hlsl::DxilProgramHeader*>(pPart->GetBufferPointer());
+      IFT(IsValidDxilProgramHeader(pProgramHeader, (uint32_t)pPart->GetBufferSize()));
+      hlsl::DXIL::ShaderKind SK = hlsl::GetVersionShaderType(pProgramHeader->ProgramVersion);
+      if (SK == hlsl::DXIL::ShaderKind::Library) {
+        IFT(pReflection->GetPartReflection(i,
+                                           IID_PPV_ARGS(&pLibraryReflection)));
+
+      } else {
+        IFT(pReflection->GetPartReflection(i,
+                                           IID_PPV_ARGS(&pShaderReflection)));
+      }
+      break;
+    } else if (kind == (uint32_t)hlsl::DxilFourCC::DFCC_RuntimeData) {
+      CComPtr<IDxcBlob> pPart;
+      IFT(pReflection->GetPartContent(i, &pPart));
+      hlsl::RDAT::DxilRuntimeData rdat(pPart->GetBufferPointer(),
+                                       pPart->GetBufferSize());
+      hlsl::dump::DumpContext d(ss);
+      DumpRuntimeData(rdat, d);
+    }
+  }
+
+  if (!blobFound) {
+    printf("Unable to find DXIL part");
+    return;
+  } else if (pShaderReflection) {
+    dumper.Dump(pShaderReflection);
+  } else if (pLibraryReflection) {
+    dumper.Dump(pLibraryReflection);
+  }
+
+  ss.flush();
+  printf("%s", ss.str().c_str());
+}
+
 using namespace hlsl::options;
 
 #ifdef _WIN32
@@ -439,8 +505,10 @@ int main(int argc, const char **argv) {
     } else if (DumpRDAT) {
       pStage = "Dump RDAT";
       context.DumpRDAT();
-    }
-    else {
+    } else if (DumpReflection) {
+      pStage = "Dump Reflection";
+      context.DumpReflection();
+    } else {
       pStage = "Assembling";
       context.Assemble();
     }
diff --git a/tools/clang/unittests/HLSLTestLib/CMakeLists.txt b/tools/clang/unittests/HLSLTestLib/CMakeLists.txt
index 0dc937617c..2ade2b3138 100644
--- a/tools/clang/unittests/HLSLTestLib/CMakeLists.txt
+++ b/tools/clang/unittests/HLSLTestLib/CMakeLists.txt
@@ -8,12 +8,9 @@ include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include)
 endif(WIN32)
 
 add_clang_library(HLSLTestLib
-  D3DReflectionDumper.cpp
-  D3DReflectionStrings.cpp
   DxcTestUtils.cpp
   FileCheckerTest.cpp
   FileCheckForTest.cpp
-  RDATDumper.cpp
 )
 
 add_dependencies(HLSLTestLib TablegenHLSLOptions)