Prechádzať zdrojové kódy

[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.
Xiang Li 2 rokov pred
rodič
commit
daf1386161

+ 3 - 0
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

+ 0 - 0
tools/clang/unittests/HLSLTestLib/D3DReflectionDumper.cpp → lib/DxilContainer/D3DReflectionDumper.cpp


+ 0 - 0
tools/clang/unittests/HLSLTestLib/D3DReflectionStrings.cpp → lib/DxilContainer/D3DReflectionStrings.cpp


+ 0 - 0
tools/clang/unittests/HLSLTestLib/RDATDumper.cpp → lib/DxilContainer/RDATDumper.cpp


+ 73 - 0
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)

+ 0 - 1
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})

+ 70 - 2
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 @@ public:
   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();
     }

+ 0 - 3
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)

+ 7 - 0
utils/hct/hcttestcmds.cmd

@@ -393,6 +393,13 @@ call :run dxa.exe smoke.ll -o smoke.rebuilt-container2.cso
 call :check_file smoke.rebuilt-container2.cso del
 if %Failed% neq 0 goto :failed
 
+set testname=dxa dump reflection
+call :run dxa.exe -dumpreflection smoke.cso
+if %Failed% neq 0 goto :failed
+rem Check for expected parts for this container
+call :check_file log find "D3D12_SHADER_INPUT_BIND_DESC: Name: $Globals"
+if %Failed% neq 0 goto :failed
+
 set testname=Smoke test for dxopt command line
 call :run-nolog dxc /Odump /T ps_6_0 "%testfiles%\Inputs\smoke.hlsl" > passes.txt
 call :check_file passes.txt find emit