D3DReflectionDumper.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // D3DReflectionDumper.cpp //
  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. #include "dxc/Support/Global.h"
  12. #include "dxc/test/D3DReflectionDumper.h"
  13. #include "dxc/DxilContainer/DxilContainer.h"
  14. #include <sstream>
  15. // Remove this workaround once newer version of d3dcommon.h can be compiled against
  16. #define ADD_16_64_BIT_TYPES
  17. // Copied from llvm/ADT/StringExtras.h
  18. static inline char hexdigit(unsigned X, bool LowerCase = false) {
  19. const char HexChar = LowerCase ? 'a' : 'A';
  20. return X < 10 ? '0' + X : HexChar + X - 10;
  21. }
  22. // Copied from lib/IR/AsmWriter.cpp
  23. // PrintEscapedString - Print each character of the specified string, escaping
  24. // it if it is not printable or if it is an escape char.
  25. static std::string EscapedString(const char *text) {
  26. std::ostringstream ss;
  27. size_t size = strlen(text);
  28. for (unsigned i = 0, e = size; i != e; ++i) {
  29. unsigned char C = text[i];
  30. if (isprint(C) && C != '\\' && C != '"')
  31. ss << C;
  32. else
  33. ss << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
  34. }
  35. return ss.str();
  36. }
  37. namespace refl_dump {
  38. LPCSTR ToString(D3D_CBUFFER_TYPE CBType) {
  39. switch (CBType) {
  40. case D3D_CT_CBUFFER: return "D3D_CT_CBUFFER";
  41. case D3D_CT_TBUFFER: return "D3D_CT_TBUFFER";
  42. case D3D_CT_INTERFACE_POINTERS: return "D3D_CT_INTERFACE_POINTERS";
  43. case D3D_CT_RESOURCE_BIND_INFO: return "D3D_CT_RESOURCE_BIND_INFO";
  44. default: return nullptr;
  45. }
  46. }
  47. LPCSTR ToString(D3D_SHADER_INPUT_TYPE Type) {
  48. switch ((UINT32)Type) {
  49. case D3D_SIT_CBUFFER: return "D3D_SIT_CBUFFER";
  50. case D3D_SIT_TBUFFER: return "D3D_SIT_TBUFFER";
  51. case D3D_SIT_TEXTURE: return "D3D_SIT_TEXTURE";
  52. case D3D_SIT_SAMPLER: return "D3D_SIT_SAMPLER";
  53. case D3D_SIT_UAV_RWTYPED: return "D3D_SIT_UAV_RWTYPED";
  54. case D3D_SIT_STRUCTURED: return "D3D_SIT_STRUCTURED";
  55. case D3D_SIT_UAV_RWSTRUCTURED: return "D3D_SIT_UAV_RWSTRUCTURED";
  56. case D3D_SIT_BYTEADDRESS: return "D3D_SIT_BYTEADDRESS";
  57. case D3D_SIT_UAV_RWBYTEADDRESS: return "D3D_SIT_UAV_RWBYTEADDRESS";
  58. case D3D_SIT_UAV_APPEND_STRUCTURED: return "D3D_SIT_UAV_APPEND_STRUCTURED";
  59. case D3D_SIT_UAV_CONSUME_STRUCTURED: return "D3D_SIT_UAV_CONSUME_STRUCTURED";
  60. case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER: return "D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER";
  61. case (D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER + 1): return "D3D_SIT_RTACCELERATIONSTRUCTURE";
  62. case (D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER + 2): return "D3D_SIT_UAV_FEEDBACKTEXTURE";
  63. default: return nullptr;
  64. }
  65. }
  66. LPCSTR ToString(D3D_RESOURCE_RETURN_TYPE ReturnType) {
  67. switch (ReturnType) {
  68. case D3D_RETURN_TYPE_UNORM: return "D3D_RETURN_TYPE_UNORM";
  69. case D3D_RETURN_TYPE_SNORM: return "D3D_RETURN_TYPE_SNORM";
  70. case D3D_RETURN_TYPE_SINT: return "D3D_RETURN_TYPE_SINT";
  71. case D3D_RETURN_TYPE_UINT: return "D3D_RETURN_TYPE_UINT";
  72. case D3D_RETURN_TYPE_FLOAT: return "D3D_RETURN_TYPE_FLOAT";
  73. case D3D_RETURN_TYPE_MIXED: return "D3D_RETURN_TYPE_MIXED";
  74. case D3D_RETURN_TYPE_DOUBLE: return "D3D_RETURN_TYPE_DOUBLE";
  75. case D3D_RETURN_TYPE_CONTINUED: return "D3D_RETURN_TYPE_CONTINUED";
  76. default: return nullptr;
  77. }
  78. }
  79. LPCSTR ToString(D3D_SRV_DIMENSION Dimension) {
  80. switch (Dimension) {
  81. case D3D_SRV_DIMENSION_UNKNOWN: return "D3D_SRV_DIMENSION_UNKNOWN";
  82. case D3D_SRV_DIMENSION_BUFFER: return "D3D_SRV_DIMENSION_BUFFER";
  83. case D3D_SRV_DIMENSION_TEXTURE1D: return "D3D_SRV_DIMENSION_TEXTURE1D";
  84. case D3D_SRV_DIMENSION_TEXTURE1DARRAY: return "D3D_SRV_DIMENSION_TEXTURE1DARRAY";
  85. case D3D_SRV_DIMENSION_TEXTURE2D: return "D3D_SRV_DIMENSION_TEXTURE2D";
  86. case D3D_SRV_DIMENSION_TEXTURE2DARRAY: return "D3D_SRV_DIMENSION_TEXTURE2DARRAY";
  87. case D3D_SRV_DIMENSION_TEXTURE2DMS: return "D3D_SRV_DIMENSION_TEXTURE2DMS";
  88. case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY: return "D3D_SRV_DIMENSION_TEXTURE2DMSARRAY";
  89. case D3D_SRV_DIMENSION_TEXTURE3D: return "D3D_SRV_DIMENSION_TEXTURE3D";
  90. case D3D_SRV_DIMENSION_TEXTURECUBE: return "D3D_SRV_DIMENSION_TEXTURECUBE";
  91. case D3D_SRV_DIMENSION_TEXTURECUBEARRAY: return "D3D_SRV_DIMENSION_TEXTURECUBEARRAY";
  92. case D3D_SRV_DIMENSION_BUFFEREX: return "D3D_SRV_DIMENSION_BUFFEREX";
  93. default: return nullptr;
  94. }
  95. }
  96. LPCSTR ToString(D3D_PRIMITIVE_TOPOLOGY GSOutputTopology) {
  97. switch (GSOutputTopology) {
  98. case D3D_PRIMITIVE_TOPOLOGY_UNDEFINED: return "D3D_PRIMITIVE_TOPOLOGY_UNDEFINED";
  99. case D3D_PRIMITIVE_TOPOLOGY_POINTLIST: return "D3D_PRIMITIVE_TOPOLOGY_POINTLIST";
  100. case D3D_PRIMITIVE_TOPOLOGY_LINELIST: return "D3D_PRIMITIVE_TOPOLOGY_LINELIST";
  101. case D3D_PRIMITIVE_TOPOLOGY_LINESTRIP: return "D3D_PRIMITIVE_TOPOLOGY_LINESTRIP";
  102. case D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST: return "D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST";
  103. case D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP: return "D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP";
  104. case D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ: return "D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ";
  105. case D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ: return "D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ";
  106. case D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ: return "D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ";
  107. case D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ: return "D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ";
  108. case D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST";
  109. case D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST";
  110. case D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST";
  111. case D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST";
  112. case D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST";
  113. case D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST";
  114. case D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST";
  115. case D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST";
  116. case D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST";
  117. case D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST";
  118. case D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST";
  119. case D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST";
  120. case D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST";
  121. case D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST";
  122. case D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST";
  123. case D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST";
  124. case D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST";
  125. case D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST";
  126. case D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST";
  127. case D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST";
  128. case D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST";
  129. case D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST";
  130. case D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST";
  131. case D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST";
  132. case D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST";
  133. case D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST";
  134. case D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST";
  135. case D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST";
  136. case D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST";
  137. case D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST";
  138. case D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST";
  139. case D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST: return "D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST";
  140. default: return nullptr;
  141. }
  142. }
  143. LPCSTR ToString(D3D_PRIMITIVE InputPrimitive) {
  144. switch (InputPrimitive) {
  145. case D3D_PRIMITIVE_UNDEFINED: return "D3D_PRIMITIVE_UNDEFINED";
  146. case D3D_PRIMITIVE_POINT: return "D3D_PRIMITIVE_POINT";
  147. case D3D_PRIMITIVE_LINE: return "D3D_PRIMITIVE_LINE";
  148. case D3D_PRIMITIVE_TRIANGLE: return "D3D_PRIMITIVE_TRIANGLE";
  149. case D3D_PRIMITIVE_LINE_ADJ: return "D3D_PRIMITIVE_LINE_ADJ";
  150. case D3D_PRIMITIVE_TRIANGLE_ADJ: return "D3D_PRIMITIVE_TRIANGLE_ADJ";
  151. case D3D_PRIMITIVE_1_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_1_CONTROL_POINT_PATCH";
  152. case D3D_PRIMITIVE_2_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_2_CONTROL_POINT_PATCH";
  153. case D3D_PRIMITIVE_3_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_3_CONTROL_POINT_PATCH";
  154. case D3D_PRIMITIVE_4_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_4_CONTROL_POINT_PATCH";
  155. case D3D_PRIMITIVE_5_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_5_CONTROL_POINT_PATCH";
  156. case D3D_PRIMITIVE_6_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_6_CONTROL_POINT_PATCH";
  157. case D3D_PRIMITIVE_7_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_7_CONTROL_POINT_PATCH";
  158. case D3D_PRIMITIVE_8_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_8_CONTROL_POINT_PATCH";
  159. case D3D_PRIMITIVE_9_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_9_CONTROL_POINT_PATCH";
  160. case D3D_PRIMITIVE_10_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_10_CONTROL_POINT_PATCH";
  161. case D3D_PRIMITIVE_11_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_11_CONTROL_POINT_PATCH";
  162. case D3D_PRIMITIVE_12_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_12_CONTROL_POINT_PATCH";
  163. case D3D_PRIMITIVE_13_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_13_CONTROL_POINT_PATCH";
  164. case D3D_PRIMITIVE_14_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_14_CONTROL_POINT_PATCH";
  165. case D3D_PRIMITIVE_15_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_15_CONTROL_POINT_PATCH";
  166. case D3D_PRIMITIVE_16_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_16_CONTROL_POINT_PATCH";
  167. case D3D_PRIMITIVE_17_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_17_CONTROL_POINT_PATCH";
  168. case D3D_PRIMITIVE_18_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_18_CONTROL_POINT_PATCH";
  169. case D3D_PRIMITIVE_19_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_19_CONTROL_POINT_PATCH";
  170. case D3D_PRIMITIVE_20_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_20_CONTROL_POINT_PATCH";
  171. case D3D_PRIMITIVE_21_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_21_CONTROL_POINT_PATCH";
  172. case D3D_PRIMITIVE_22_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_22_CONTROL_POINT_PATCH";
  173. case D3D_PRIMITIVE_23_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_23_CONTROL_POINT_PATCH";
  174. case D3D_PRIMITIVE_24_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_24_CONTROL_POINT_PATCH";
  175. case D3D_PRIMITIVE_25_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_25_CONTROL_POINT_PATCH";
  176. case D3D_PRIMITIVE_26_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_26_CONTROL_POINT_PATCH";
  177. case D3D_PRIMITIVE_27_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_27_CONTROL_POINT_PATCH";
  178. case D3D_PRIMITIVE_28_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_28_CONTROL_POINT_PATCH";
  179. case D3D_PRIMITIVE_29_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_29_CONTROL_POINT_PATCH";
  180. case D3D_PRIMITIVE_30_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_30_CONTROL_POINT_PATCH";
  181. case D3D_PRIMITIVE_31_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_31_CONTROL_POINT_PATCH";
  182. case D3D_PRIMITIVE_32_CONTROL_POINT_PATCH: return "D3D_PRIMITIVE_32_CONTROL_POINT_PATCH";
  183. default: return nullptr;
  184. }
  185. }
  186. LPCSTR ToString(D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive) {
  187. switch (HSOutputPrimitive) {
  188. case D3D_TESSELLATOR_OUTPUT_UNDEFINED: return "D3D_TESSELLATOR_OUTPUT_UNDEFINED";
  189. case D3D_TESSELLATOR_OUTPUT_POINT: return "D3D_TESSELLATOR_OUTPUT_POINT";
  190. case D3D_TESSELLATOR_OUTPUT_LINE: return "D3D_TESSELLATOR_OUTPUT_LINE";
  191. case D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW: return "D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW";
  192. case D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW: return "D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW";
  193. default: return nullptr;
  194. }
  195. }
  196. LPCSTR ToString(D3D_TESSELLATOR_PARTITIONING HSPartitioning) {
  197. switch (HSPartitioning) {
  198. case D3D_TESSELLATOR_PARTITIONING_UNDEFINED: return "D3D_TESSELLATOR_PARTITIONING_UNDEFINED";
  199. case D3D_TESSELLATOR_PARTITIONING_INTEGER: return "D3D_TESSELLATOR_PARTITIONING_INTEGER";
  200. case D3D_TESSELLATOR_PARTITIONING_POW2: return "D3D_TESSELLATOR_PARTITIONING_POW2";
  201. case D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD: return "D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD";
  202. case D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN: return "D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN";
  203. default: return nullptr;
  204. }
  205. }
  206. LPCSTR ToString(D3D_TESSELLATOR_DOMAIN TessellatorDomain) {
  207. switch (TessellatorDomain) {
  208. case D3D_TESSELLATOR_DOMAIN_UNDEFINED: return "D3D_TESSELLATOR_DOMAIN_UNDEFINED";
  209. case D3D_TESSELLATOR_DOMAIN_ISOLINE: return "D3D_TESSELLATOR_DOMAIN_ISOLINE";
  210. case D3D_TESSELLATOR_DOMAIN_TRI: return "D3D_TESSELLATOR_DOMAIN_TRI";
  211. case D3D_TESSELLATOR_DOMAIN_QUAD: return "D3D_TESSELLATOR_DOMAIN_QUAD";
  212. default: return nullptr;
  213. }
  214. }
  215. LPCSTR ToString(D3D_SHADER_VARIABLE_CLASS Class) {
  216. switch (Class) {
  217. case D3D_SVC_SCALAR: return "D3D_SVC_SCALAR";
  218. case D3D_SVC_VECTOR: return "D3D_SVC_VECTOR";
  219. case D3D_SVC_MATRIX_ROWS: return "D3D_SVC_MATRIX_ROWS";
  220. case D3D_SVC_MATRIX_COLUMNS: return "D3D_SVC_MATRIX_COLUMNS";
  221. case D3D_SVC_OBJECT: return "D3D_SVC_OBJECT";
  222. case D3D_SVC_STRUCT: return "D3D_SVC_STRUCT";
  223. case D3D_SVC_INTERFACE_CLASS: return "D3D_SVC_INTERFACE_CLASS";
  224. case D3D_SVC_INTERFACE_POINTER: return "D3D_SVC_INTERFACE_POINTER";
  225. default: return nullptr;
  226. }
  227. }
  228. #ifdef ADD_16_64_BIT_TYPES
  229. #define D3D_SVT_INT16 ((D3D_SHADER_VARIABLE_TYPE)58)
  230. #define D3D_SVT_UINT16 ((D3D_SHADER_VARIABLE_TYPE)59)
  231. #define D3D_SVT_FLOAT16 ((D3D_SHADER_VARIABLE_TYPE)60)
  232. #define D3D_SVT_INT64 ((D3D_SHADER_VARIABLE_TYPE)61)
  233. #define D3D_SVT_UINT64 ((D3D_SHADER_VARIABLE_TYPE)62)
  234. #endif // ADD_16_64_BIT_TYPES
  235. LPCSTR ToString(D3D_SHADER_VARIABLE_TYPE Type) {
  236. switch (Type) {
  237. case D3D_SVT_VOID: return "D3D_SVT_VOID";
  238. case D3D_SVT_BOOL: return "D3D_SVT_BOOL";
  239. case D3D_SVT_INT: return "D3D_SVT_INT";
  240. case D3D_SVT_FLOAT: return "D3D_SVT_FLOAT";
  241. case D3D_SVT_STRING: return "D3D_SVT_STRING";
  242. case D3D_SVT_TEXTURE: return "D3D_SVT_TEXTURE";
  243. case D3D_SVT_TEXTURE1D: return "D3D_SVT_TEXTURE1D";
  244. case D3D_SVT_TEXTURE2D: return "D3D_SVT_TEXTURE2D";
  245. case D3D_SVT_TEXTURE3D: return "D3D_SVT_TEXTURE3D";
  246. case D3D_SVT_TEXTURECUBE: return "D3D_SVT_TEXTURECUBE";
  247. case D3D_SVT_SAMPLER: return "D3D_SVT_SAMPLER";
  248. case D3D_SVT_SAMPLER1D: return "D3D_SVT_SAMPLER1D";
  249. case D3D_SVT_SAMPLER2D: return "D3D_SVT_SAMPLER2D";
  250. case D3D_SVT_SAMPLER3D: return "D3D_SVT_SAMPLER3D";
  251. case D3D_SVT_SAMPLERCUBE: return "D3D_SVT_SAMPLERCUBE";
  252. case D3D_SVT_PIXELSHADER: return "D3D_SVT_PIXELSHADER";
  253. case D3D_SVT_VERTEXSHADER: return "D3D_SVT_VERTEXSHADER";
  254. case D3D_SVT_PIXELFRAGMENT: return "D3D_SVT_PIXELFRAGMENT";
  255. case D3D_SVT_VERTEXFRAGMENT: return "D3D_SVT_VERTEXFRAGMENT";
  256. case D3D_SVT_UINT: return "D3D_SVT_UINT";
  257. case D3D_SVT_UINT8: return "D3D_SVT_UINT8";
  258. case D3D_SVT_GEOMETRYSHADER: return "D3D_SVT_GEOMETRYSHADER";
  259. case D3D_SVT_RASTERIZER: return "D3D_SVT_RASTERIZER";
  260. case D3D_SVT_DEPTHSTENCIL: return "D3D_SVT_DEPTHSTENCIL";
  261. case D3D_SVT_BLEND: return "D3D_SVT_BLEND";
  262. case D3D_SVT_BUFFER: return "D3D_SVT_BUFFER";
  263. case D3D_SVT_CBUFFER: return "D3D_SVT_CBUFFER";
  264. case D3D_SVT_TBUFFER: return "D3D_SVT_TBUFFER";
  265. case D3D_SVT_TEXTURE1DARRAY: return "D3D_SVT_TEXTURE1DARRAY";
  266. case D3D_SVT_TEXTURE2DARRAY: return "D3D_SVT_TEXTURE2DARRAY";
  267. case D3D_SVT_RENDERTARGETVIEW: return "D3D_SVT_RENDERTARGETVIEW";
  268. case D3D_SVT_DEPTHSTENCILVIEW: return "D3D_SVT_DEPTHSTENCILVIEW";
  269. case D3D_SVT_TEXTURE2DMS: return "D3D_SVT_TEXTURE2DMS";
  270. case D3D_SVT_TEXTURE2DMSARRAY: return "D3D_SVT_TEXTURE2DMSARRAY";
  271. case D3D_SVT_TEXTURECUBEARRAY: return "D3D_SVT_TEXTURECUBEARRAY";
  272. case D3D_SVT_HULLSHADER: return "D3D_SVT_HULLSHADER";
  273. case D3D_SVT_DOMAINSHADER: return "D3D_SVT_DOMAINSHADER";
  274. case D3D_SVT_INTERFACE_POINTER: return "D3D_SVT_INTERFACE_POINTER";
  275. case D3D_SVT_COMPUTESHADER: return "D3D_SVT_COMPUTESHADER";
  276. case D3D_SVT_DOUBLE: return "D3D_SVT_DOUBLE";
  277. case D3D_SVT_RWTEXTURE1D: return "D3D_SVT_RWTEXTURE1D";
  278. case D3D_SVT_RWTEXTURE1DARRAY: return "D3D_SVT_RWTEXTURE1DARRAY";
  279. case D3D_SVT_RWTEXTURE2D: return "D3D_SVT_RWTEXTURE2D";
  280. case D3D_SVT_RWTEXTURE2DARRAY: return "D3D_SVT_RWTEXTURE2DARRAY";
  281. case D3D_SVT_RWTEXTURE3D: return "D3D_SVT_RWTEXTURE3D";
  282. case D3D_SVT_RWBUFFER: return "D3D_SVT_RWBUFFER";
  283. case D3D_SVT_BYTEADDRESS_BUFFER: return "D3D_SVT_BYTEADDRESS_BUFFER";
  284. case D3D_SVT_RWBYTEADDRESS_BUFFER: return "D3D_SVT_RWBYTEADDRESS_BUFFER";
  285. case D3D_SVT_STRUCTURED_BUFFER: return "D3D_SVT_STRUCTURED_BUFFER";
  286. case D3D_SVT_RWSTRUCTURED_BUFFER: return "D3D_SVT_RWSTRUCTURED_BUFFER";
  287. case D3D_SVT_APPEND_STRUCTURED_BUFFER: return "D3D_SVT_APPEND_STRUCTURED_BUFFER";
  288. case D3D_SVT_CONSUME_STRUCTURED_BUFFER: return "D3D_SVT_CONSUME_STRUCTURED_BUFFER";
  289. case D3D_SVT_MIN8FLOAT: return "D3D_SVT_MIN8FLOAT";
  290. case D3D_SVT_MIN10FLOAT: return "D3D_SVT_MIN10FLOAT";
  291. case D3D_SVT_MIN16FLOAT: return "D3D_SVT_MIN16FLOAT";
  292. case D3D_SVT_MIN12INT: return "D3D_SVT_MIN12INT";
  293. case D3D_SVT_MIN16INT: return "D3D_SVT_MIN16INT";
  294. case D3D_SVT_MIN16UINT: return "D3D_SVT_MIN16UINT";
  295. case D3D_SVT_INT16: return "D3D_SVT_INT16";
  296. case D3D_SVT_UINT16: return "D3D_SVT_UINT16";
  297. case D3D_SVT_FLOAT16: return "D3D_SVT_FLOAT16";
  298. case D3D_SVT_INT64: return "D3D_SVT_INT64";
  299. case D3D_SVT_UINT64: return "D3D_SVT_UINT64";
  300. default: return nullptr;
  301. }
  302. }
  303. LPCSTR ToString(D3D_SHADER_VARIABLE_FLAGS Flag) {
  304. switch (Flag) {
  305. case D3D_SVF_USERPACKED: return "D3D_SVF_USERPACKED";
  306. case D3D_SVF_USED: return "D3D_SVF_USED";
  307. case D3D_SVF_INTERFACE_POINTER: return "D3D_SVF_INTERFACE_POINTER";
  308. case D3D_SVF_INTERFACE_PARAMETER: return "D3D_SVF_INTERFACE_PARAMETER";
  309. }
  310. return nullptr;
  311. }
  312. LPCSTR ToString(D3D_SHADER_INPUT_FLAGS Flag) {
  313. switch (Flag) {
  314. case D3D_SIF_USERPACKED: return "D3D_SIF_USERPACKED";
  315. case D3D_SIF_COMPARISON_SAMPLER: return "D3D_SIF_COMPARISON_SAMPLER";
  316. case D3D_SIF_TEXTURE_COMPONENT_0: return "D3D_SIF_TEXTURE_COMPONENT_0";
  317. case D3D_SIF_TEXTURE_COMPONENT_1: return "D3D_SIF_TEXTURE_COMPONENT_1";
  318. case D3D_SIF_TEXTURE_COMPONENTS: return "D3D_SIF_TEXTURE_COMPONENTS";
  319. case D3D_SIF_UNUSED: return "D3D_SIF_UNUSED";
  320. }
  321. return nullptr;
  322. }
  323. LPCSTR ToString(D3D_SHADER_CBUFFER_FLAGS Flag) {
  324. switch (Flag) {
  325. case D3D_CBF_USERPACKED: return "D3D_CBF_USERPACKED";
  326. }
  327. return nullptr;
  328. }
  329. LPCSTR ToString(D3D_PARAMETER_FLAGS Flag) {
  330. switch (Flag) {
  331. case D3D_PF_IN: return "D3D_PF_IN";
  332. case D3D_PF_OUT: return "D3D_PF_OUT";
  333. }
  334. return nullptr;
  335. }
  336. void D3DReflectionDumper::DumpDefaultValue(LPCVOID pDefaultValue, UINT Size) {
  337. WriteLn("DefaultValue: ", pDefaultValue ? "<present>" : "<nullptr>"); // TODO: Dump DefaultValue
  338. }
  339. void D3DReflectionDumper::DumpShaderVersion(UINT Version) {
  340. const char *szType = "<unknown>";
  341. UINT Type = D3D12_SHVER_GET_TYPE(Version);
  342. switch (Type) {
  343. case (UINT)hlsl::DXIL::ShaderKind::Pixel: szType = "Pixel"; break;
  344. case (UINT)hlsl::DXIL::ShaderKind::Vertex: szType = "Vertex"; break;
  345. case (UINT)hlsl::DXIL::ShaderKind::Geometry: szType = "Geometry"; break;
  346. case (UINT)hlsl::DXIL::ShaderKind::Hull: szType = "Hull"; break;
  347. case (UINT)hlsl::DXIL::ShaderKind::Domain: szType = "Domain"; break;
  348. case (UINT)hlsl::DXIL::ShaderKind::Compute: szType = "Compute"; break;
  349. case (UINT)hlsl::DXIL::ShaderKind::Library: szType = "Library"; break;
  350. case (UINT)hlsl::DXIL::ShaderKind::RayGeneration: szType = "RayGeneration"; break;
  351. case (UINT)hlsl::DXIL::ShaderKind::Intersection: szType = "Intersection"; break;
  352. case (UINT)hlsl::DXIL::ShaderKind::AnyHit: szType = "AnyHit"; break;
  353. case (UINT)hlsl::DXIL::ShaderKind::ClosestHit: szType = "ClosestHit"; break;
  354. case (UINT)hlsl::DXIL::ShaderKind::Miss: szType = "Miss"; break;
  355. case (UINT)hlsl::DXIL::ShaderKind::Callable: szType = "Callable"; break;
  356. case (UINT)hlsl::DXIL::ShaderKind::Mesh: szType = "Mesh"; break;
  357. case (UINT)hlsl::DXIL::ShaderKind::Amplification: szType = "Amplification"; break;
  358. case (UINT)hlsl::DXIL::ShaderKind::Invalid: szType = "Invalid"; break;
  359. }
  360. UINT Major = D3D12_SHVER_GET_MAJOR(Version);
  361. UINT Minor = D3D12_SHVER_GET_MINOR(Version);
  362. WriteLn("Shader Version: ", szType, " ", Major, ".", Minor);
  363. }
  364. void D3DReflectionDumper::Dump(D3D12_SHADER_TYPE_DESC &tyDesc) {
  365. SetLastName(tyDesc.Name);
  366. WriteLn("D3D12_SHADER_TYPE_DESC: Name: ", m_LastName);
  367. Indent();
  368. DumpEnum("Class", tyDesc.Class);
  369. DumpEnum("Type", tyDesc.Type);
  370. WriteLn("Elements: ", tyDesc.Elements);
  371. WriteLn("Rows: ", tyDesc.Rows);
  372. WriteLn("Columns: ", tyDesc.Columns);
  373. WriteLn("Members: ", tyDesc.Members);
  374. WriteLn("Offset: ", tyDesc.Offset);
  375. Dedent();
  376. }
  377. void D3DReflectionDumper::Dump(D3D12_SHADER_VARIABLE_DESC &varDesc) {
  378. SetLastName(varDesc.Name);
  379. WriteLn("D3D12_SHADER_VARIABLE_DESC: Name: ", m_LastName);
  380. Indent();
  381. WriteLn("Size: ", varDesc.Size);
  382. WriteLn("StartOffset: ", varDesc.StartOffset);
  383. WriteLn("uFlags: ", FlagsValue<D3D_SHADER_VARIABLE_FLAGS>(varDesc.uFlags));
  384. DumpDefaultValue(varDesc.DefaultValue, varDesc.Size);
  385. Dedent();
  386. }
  387. void D3DReflectionDumper::Dump(D3D12_SHADER_BUFFER_DESC &Desc) {
  388. SetLastName(Desc.Name);
  389. WriteLn("D3D12_SHADER_BUFFER_DESC: Name: ", m_LastName);
  390. Indent();
  391. DumpEnum("Type", Desc.Type);
  392. WriteLn("Size: ", Desc.Size);
  393. WriteLn("uFlags: ", FlagsValue<D3D_SHADER_CBUFFER_FLAGS>(Desc.uFlags));
  394. WriteLn("Num Variables: ", Desc.Variables);
  395. Dedent();
  396. }
  397. void D3DReflectionDumper::Dump(D3D12_SHADER_INPUT_BIND_DESC &resDesc) {
  398. SetLastName(resDesc.Name);
  399. WriteLn("D3D12_SHADER_BUFFER_DESC: Name: ", m_LastName);
  400. Indent();
  401. DumpEnum("Type", resDesc.Type);
  402. WriteLn("uID: ", resDesc.uID);
  403. WriteLn("BindCount: ", resDesc.BindCount);
  404. WriteLn("BindPoint: ", resDesc.BindPoint);
  405. WriteLn("Space: ", resDesc.Space);
  406. DumpEnum("ReturnType", resDesc.ReturnType);
  407. DumpEnum("Dimension", resDesc.Dimension);
  408. WriteLn("NumSamples (or stride): ", resDesc.NumSamples);
  409. WriteLn("uFlags: ", FlagsValue<D3D_SHADER_INPUT_FLAGS>(resDesc.uFlags));
  410. Dedent();
  411. }
  412. void D3DReflectionDumper::Dump(D3D12_SHADER_DESC &Desc) {
  413. WriteLn("D3D12_SHADER_BUFFER_DESC:");
  414. Indent();
  415. DumpShaderVersion(Desc.Version);
  416. WriteLn("Creator: ", Desc.Creator ? Desc.Creator : "<nullptr>");
  417. WriteLn("Flags: ", std::hex, std::showbase, Desc.Flags); // TODO: fxc compiler flags
  418. WriteLn("ConstantBuffers: ", Desc.ConstantBuffers);
  419. WriteLn("BoundResources: ", Desc.BoundResources);
  420. WriteLn("InputParameters: ", Desc.InputParameters);
  421. WriteLn("OutputParameters: ", Desc.OutputParameters);
  422. hlsl::DXIL::ShaderKind ShaderKind = (hlsl::DXIL::ShaderKind)D3D12_SHVER_GET_TYPE(Desc.Version);
  423. if (ShaderKind == hlsl::DXIL::ShaderKind::Geometry) {
  424. WriteLn("cGSInstanceCount: ", Desc.cGSInstanceCount);
  425. WriteLn("GSMaxOutputVertexCount: ", Desc.GSMaxOutputVertexCount);
  426. DumpEnum("GSOutputTopology", Desc.GSOutputTopology);
  427. DumpEnum("InputPrimitive", Desc.InputPrimitive);
  428. }
  429. if (ShaderKind == hlsl::DXIL::ShaderKind::Hull) {
  430. WriteLn("PatchConstantParameters: ", Desc.PatchConstantParameters);
  431. WriteLn("cControlPoints: ", Desc.cControlPoints);
  432. DumpEnum("InputPrimitive", Desc.InputPrimitive);
  433. DumpEnum("HSOutputPrimitive", Desc.HSOutputPrimitive);
  434. DumpEnum("HSPartitioning", Desc.HSPartitioning);
  435. DumpEnum("TessellatorDomain", Desc.TessellatorDomain);
  436. }
  437. if (ShaderKind == hlsl::DXIL::ShaderKind::Domain) {
  438. WriteLn("PatchConstantParameters: ", Desc.PatchConstantParameters);
  439. WriteLn("cControlPoints: ", Desc.cControlPoints);
  440. DumpEnum("TessellatorDomain", Desc.TessellatorDomain);
  441. }
  442. // TODO
  443. Dedent();
  444. }
  445. void D3DReflectionDumper::Dump(D3D12_FUNCTION_DESC &Desc) {
  446. SetLastName(Desc.Name);
  447. WriteLn("D3D12_FUNCTION_DESC: Name: ", EscapedString(m_LastName));
  448. Indent();
  449. DumpShaderVersion(Desc.Version);
  450. WriteLn("Creator: ", Desc.Creator ? Desc.Creator : "<nullptr>");
  451. WriteLn("Flags: ", std::hex, std::showbase, Desc.Flags);
  452. WriteLn("ConstantBuffers: ", Desc.ConstantBuffers);
  453. WriteLn("BoundResources: ", Desc.BoundResources);
  454. WriteLn("FunctionParameterCount: ", Desc.FunctionParameterCount);
  455. WriteLn("HasReturn: ", Desc.HasReturn ? "TRUE" : "FALSE");
  456. Dedent();
  457. }
  458. void D3DReflectionDumper::Dump(D3D12_LIBRARY_DESC &Desc) {
  459. WriteLn("D3D12_LIBRARY_DESC:");
  460. Indent();
  461. WriteLn("Creator: ", Desc.Creator ? Desc.Creator : "<nullptr>");
  462. WriteLn("Flags: ", std::hex, std::showbase, Desc.Flags);
  463. WriteLn("FunctionCount: ", Desc.FunctionCount);
  464. Dedent();
  465. }
  466. void D3DReflectionDumper::Dump(ID3D12ShaderReflectionType *pType) {
  467. WriteLn("ID3D12ShaderReflectionType:");
  468. Indent();
  469. D3D12_SHADER_TYPE_DESC tyDesc;
  470. if (!pType || FAILED(pType->GetDesc(&tyDesc))) {
  471. Failure("GetDesc");
  472. Dedent();
  473. return;
  474. }
  475. Dump(tyDesc);
  476. if (tyDesc.Members) {
  477. WriteLn("{");
  478. Indent();
  479. for (UINT uMember = 0; uMember < tyDesc.Members; uMember++) {
  480. Dump(pType->GetMemberTypeByIndex(uMember));
  481. }
  482. Dedent();
  483. WriteLn("}");
  484. }
  485. Dedent();
  486. }
  487. void D3DReflectionDumper::Dump(ID3D12ShaderReflectionVariable *pVar) {
  488. WriteLn("ID3D12ShaderReflectionVariable:");
  489. Indent();
  490. D3D12_SHADER_VARIABLE_DESC varDesc;
  491. if (!pVar || FAILED(pVar->GetDesc(&varDesc))) {
  492. Failure("GetDesc");
  493. Dedent();
  494. return;
  495. }
  496. Dump(varDesc);
  497. Dump(pVar->GetType());
  498. ID3D12ShaderReflectionConstantBuffer* pCB = pVar->GetBuffer();
  499. D3D12_SHADER_BUFFER_DESC CBDesc;
  500. if (pCB && SUCCEEDED(pCB->GetDesc(&CBDesc))) {
  501. WriteLn("CBuffer: ", CBDesc.Name);
  502. }
  503. Dedent();
  504. }
  505. void D3DReflectionDumper::Dump(ID3D12ShaderReflectionConstantBuffer *pCBReflection) {
  506. WriteLn("ID3D12ShaderReflectionConstantBuffer:");
  507. Indent();
  508. D3D12_SHADER_BUFFER_DESC Desc;
  509. if (!pCBReflection || FAILED(pCBReflection->GetDesc(&Desc))) {
  510. Failure("GetDesc");
  511. Dedent();
  512. return;
  513. }
  514. Dump(Desc);
  515. if (Desc.Variables) {
  516. WriteLn("{");
  517. Indent();
  518. bool bCheckByNameFailed = false;
  519. for (UINT uVar = 0; uVar < Desc.Variables; uVar++) {
  520. if (m_bCheckByName)
  521. SetLastName();
  522. ID3D12ShaderReflectionVariable *pVar = pCBReflection->GetVariableByIndex(uVar);
  523. Dump(pVar);
  524. if (m_bCheckByName) {
  525. if (pCBReflection->GetVariableByName(m_LastName) != pVar) {
  526. bCheckByNameFailed = true;
  527. Failure("GetVariableByName ", m_LastName);
  528. }
  529. }
  530. }
  531. if (m_bCheckByName && !bCheckByNameFailed) {
  532. WriteLn("GetVariableByName checks succeeded.");
  533. }
  534. Dedent();
  535. WriteLn("}");
  536. }
  537. Dedent();
  538. }
  539. void D3DReflectionDumper::Dump(ID3D12ShaderReflection *pShaderReflection) {
  540. WriteLn("ID3D12ShaderReflection:");
  541. Indent();
  542. D3D12_SHADER_DESC Desc;
  543. if (!pShaderReflection || FAILED(pShaderReflection->GetDesc(&Desc))) {
  544. Failure("GetDesc");
  545. Dedent();
  546. return;
  547. }
  548. Dump(Desc);
  549. if (Desc.ConstantBuffers) {
  550. WriteLn("Constant Buffers:");
  551. Indent();
  552. bool bCheckByNameFailed = false;
  553. for (UINT uCB = 0; uCB < Desc.ConstantBuffers; uCB++) {
  554. ID3D12ShaderReflectionConstantBuffer *pCB = pShaderReflection->GetConstantBufferByIndex(uCB);
  555. Dump(pCB);
  556. if (m_bCheckByName && m_LastName) {
  557. if (pShaderReflection->GetConstantBufferByName(m_LastName) != pCB) {
  558. bCheckByNameFailed = true;
  559. Failure("GetConstantBufferByName ", m_LastName);
  560. }
  561. }
  562. }
  563. if (m_bCheckByName && !bCheckByNameFailed) {
  564. WriteLn("GetConstantBufferByName checks succeeded.");
  565. }
  566. Dedent();
  567. }
  568. if (Desc.BoundResources) {
  569. WriteLn("Bound Resources:");
  570. Indent();
  571. bool bCheckByNameFailed = false;
  572. for (UINT uRes = 0; uRes < Desc.BoundResources; uRes++) {
  573. D3D12_SHADER_INPUT_BIND_DESC bindDesc;
  574. if (FAILED(pShaderReflection->GetResourceBindingDesc(uRes, &bindDesc))) {
  575. }
  576. Dump(bindDesc);
  577. if (m_bCheckByName && bindDesc.Name) {
  578. D3D12_SHADER_INPUT_BIND_DESC bindDesc2;
  579. if (FAILED(pShaderReflection->GetResourceBindingDescByName(bindDesc.Name, &bindDesc2)) || bindDesc2.Name != bindDesc.Name) {
  580. bCheckByNameFailed = true;
  581. Failure("GetResourceBindingDescByName ", bindDesc.Name);
  582. }
  583. }
  584. }
  585. if (m_bCheckByName && !bCheckByNameFailed) {
  586. WriteLn("GetResourceBindingDescByName checks succeeded.");
  587. }
  588. Dedent();
  589. }
  590. // TODO
  591. Dedent();
  592. }
  593. void D3DReflectionDumper::Dump(ID3D12FunctionReflection *pFunctionReflection) {
  594. WriteLn("ID3D12FunctionReflection:");
  595. Indent();
  596. D3D12_FUNCTION_DESC Desc;
  597. if (!pFunctionReflection || FAILED(pFunctionReflection->GetDesc(&Desc))) {
  598. Failure("GetDesc");
  599. Dedent();
  600. return;
  601. }
  602. Dump(Desc);
  603. if (Desc.ConstantBuffers) {
  604. WriteLn("Constant Buffers:");
  605. Indent();
  606. bool bCheckByNameFailed = false;
  607. for (UINT uCB = 0; uCB < Desc.ConstantBuffers; uCB++) {
  608. ID3D12ShaderReflectionConstantBuffer *pCB = pFunctionReflection->GetConstantBufferByIndex(uCB);
  609. Dump(pCB);
  610. if (m_bCheckByName && m_LastName) {
  611. if (pFunctionReflection->GetConstantBufferByName(m_LastName) != pCB) {
  612. bCheckByNameFailed = true;
  613. Failure("GetConstantBufferByName ", m_LastName);
  614. }
  615. }
  616. }
  617. if (m_bCheckByName && !bCheckByNameFailed) {
  618. WriteLn("GetConstantBufferByName checks succeeded.");
  619. }
  620. Dedent();
  621. }
  622. if (Desc.BoundResources) {
  623. WriteLn("Bound Resources:");
  624. Indent();
  625. bool bCheckByNameFailed = false;
  626. for (UINT uRes = 0; uRes < Desc.BoundResources; uRes++) {
  627. D3D12_SHADER_INPUT_BIND_DESC bindDesc;
  628. if (FAILED(pFunctionReflection->GetResourceBindingDesc(uRes, &bindDesc))) {
  629. }
  630. Dump(bindDesc);
  631. if (m_bCheckByName && bindDesc.Name) {
  632. D3D12_SHADER_INPUT_BIND_DESC bindDesc2;
  633. if (FAILED(pFunctionReflection->GetResourceBindingDescByName(bindDesc.Name, &bindDesc2)) || bindDesc2.Name != bindDesc.Name) {
  634. bCheckByNameFailed = true;
  635. Failure("GetResourceBindingDescByName ", bindDesc.Name);
  636. }
  637. }
  638. }
  639. if (m_bCheckByName && !bCheckByNameFailed) {
  640. WriteLn("GetResourceBindingDescByName checks succeeded.");
  641. }
  642. Dedent();
  643. }
  644. // TODO
  645. Dedent();
  646. }
  647. void D3DReflectionDumper::Dump(ID3D12LibraryReflection *pLibraryReflection) {
  648. WriteLn("ID3D12LibraryReflection:");
  649. Indent();
  650. D3D12_LIBRARY_DESC Desc;
  651. if (!pLibraryReflection || FAILED(pLibraryReflection->GetDesc(&Desc))) {
  652. Failure("GetDesc");
  653. Dedent();
  654. return;
  655. }
  656. Dump(Desc);
  657. if (Desc.FunctionCount) {
  658. for (UINT uFunc = 0; uFunc < Desc.FunctionCount; uFunc++)
  659. Dump(pLibraryReflection->GetFunctionByIndex((INT)uFunc));
  660. }
  661. Dedent();
  662. }
  663. } // namespace refl_dump