D3DReflectionDumper.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // D3DReflectionDumper.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Use this to dump D3D Reflection data for testing. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "dxc/Support/Global.h"
  13. #include <algorithm>
  14. #include <string>
  15. #include <ostream>
  16. #include <iomanip>
  17. #include "dxc/Support/WinIncludes.h"
  18. #include "dxc/dxcapi.h"
  19. #include <d3d12shader.h>
  20. #include "dxc/DxilContainer/DxilContainer.h"
  21. LPCSTR ToString(D3D_CBUFFER_TYPE CBType);
  22. LPCSTR ToString(D3D_SHADER_INPUT_TYPE Type);
  23. LPCSTR ToString(D3D_RESOURCE_RETURN_TYPE ReturnType);
  24. LPCSTR ToString(D3D_SRV_DIMENSION Dimension);
  25. LPCSTR ToString(D3D_PRIMITIVE_TOPOLOGY GSOutputTopology);
  26. LPCSTR ToString(D3D_PRIMITIVE InputPrimitive);
  27. LPCSTR ToString(D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive);
  28. LPCSTR ToString(D3D_TESSELLATOR_PARTITIONING HSPartitioning);
  29. LPCSTR ToString(D3D_TESSELLATOR_DOMAIN TessellatorDomain);
  30. LPCSTR ToString(D3D_SHADER_VARIABLE_CLASS Class);
  31. LPCSTR ToString(D3D_SHADER_VARIABLE_TYPE Type);
  32. class DumperBase {
  33. private:
  34. std::ostream &m_out;
  35. unsigned m_indent = 0;
  36. bool m_bCheckByName = false;
  37. std::ostream &DoIndent() {
  38. return m_out << std::setfill(' ')
  39. << std::setw(std::min(m_indent * 2, (unsigned)32))
  40. << "";
  41. }
  42. public:
  43. DumperBase(std::ostream &outStream) : m_out(outStream) {}
  44. void Indent() { if (m_indent < (1 << 30)) m_indent++; }
  45. void Dedent() { if (m_indent > 0) m_indent--; }
  46. template<typename _T>
  47. std::ostream &Write(std::ostream &out, _T t) {
  48. return out << t;
  49. }
  50. template<typename _T, typename... Args>
  51. std::ostream &Write(std::ostream &out, _T t, Args... args) {
  52. return Write(out << t, args...);
  53. }
  54. template<typename _T>
  55. std::ostream &WriteLn(_T t) {
  56. return Write(DoIndent(), t) << std::endl
  57. << std::resetiosflags(std::ios_base::basefield | std::ios_base::showbase);
  58. }
  59. template<typename _T, typename... Args>
  60. std::ostream &WriteLn(_T t, Args... args) {
  61. return Write(Write(DoIndent(), t), args...) << std::endl
  62. << std::resetiosflags(std::ios_base::basefield | std::ios_base::showbase);
  63. }
  64. template<typename _T>
  65. void DumpEnum(const char *Name, _T eValue) {
  66. LPCSTR szValue = ToString(eValue);
  67. if (szValue)
  68. WriteLn(Name, ": ", szValue);
  69. else
  70. WriteLn(Name, ": <unknown: ", std::hex, std::showbase, (UINT)eValue, ">");
  71. }
  72. template<typename... Args>
  73. void Failure(Args... args) {
  74. WriteLn("Failed: ", args...);
  75. }
  76. };
  77. class D3DReflectionDumper : public DumperBase {
  78. private:
  79. bool m_bCheckByName = false;
  80. const char *m_LastName = nullptr;
  81. void SetLastName(const char *Name = nullptr) { m_LastName = Name ? Name : "<nullptr>"; }
  82. public:
  83. D3DReflectionDumper(std::ostream &outStream) : DumperBase(outStream) {}
  84. void SetCheckByName(bool bCheckByName) { m_bCheckByName = bCheckByName; }
  85. void DumpShaderVersion(UINT Version);
  86. void DumpDefaultValue(LPCVOID pDefaultValue, UINT Size);
  87. void Dump(D3D12_SHADER_TYPE_DESC &tyDesc);
  88. void Dump(D3D12_SHADER_VARIABLE_DESC &varDesc);
  89. void Dump(D3D12_SHADER_BUFFER_DESC &Desc);
  90. void Dump(D3D12_SHADER_INPUT_BIND_DESC &resDesc);
  91. void Dump(D3D12_SHADER_DESC &Desc);
  92. void Dump(D3D12_FUNCTION_DESC &Desc);
  93. void Dump(D3D12_LIBRARY_DESC &Desc);
  94. void Dump(ID3D12ShaderReflectionType *pType);
  95. void Dump(ID3D12ShaderReflectionVariable *pVar);
  96. void Dump(ID3D12ShaderReflectionConstantBuffer *pCBReflection);
  97. void Dump(ID3D12ShaderReflection *pShaderReflection);
  98. void Dump(ID3D12FunctionReflection *pFunctionReflection);
  99. void Dump(ID3D12LibraryReflection *pLibraryReflection);
  100. };