DxilPipelineStateValidation.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilPipelineStateValidation.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. // Defines data used by the D3D runtime for PSO validation. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #ifndef __DXIL_PIPELINE_STATE_VALIDATION__H__
  12. #define __DXIL_PIPELINE_STATE_VALIDATION__H__
  13. // Versioning is additive and based on size
  14. struct PSVRuntimeInfo0
  15. {
  16. union {
  17. struct VSInfo {
  18. char OutputPositionPresent;
  19. } VS;
  20. struct HSInfo {
  21. UINT InputControlPointCount; // max control points == 32
  22. UINT OutputControlPointCount; // max control points == 32
  23. UINT TessellatorDomain; // hlsl::DXIL::TessellatorDomain/D3D11_SB_TESSELLATOR_DOMAIN
  24. UINT TessellatorOutputPrimitive; // hlsl::DXIL::TessellatorOutputPrimitive/D3D11_SB_TESSELLATOR_OUTPUT_PRIMITIVE
  25. } HS;
  26. struct DSInfo {
  27. UINT InputControlPointCount; // max control points == 32
  28. char OutputPositionPresent;
  29. UINT TessellatorDomain; // hlsl::DXIL::TessellatorDomain/D3D11_SB_TESSELLATOR_DOMAIN
  30. } DS;
  31. struct GSInfo {
  32. UINT InputPrimitive; // hlsl::DXIL::InputPrimitive/D3D10_SB_PRIMITIVE
  33. UINT OutputTopology; // hlsl::DXIL::PrimitiveTopology/D3D10_SB_PRIMITIVE_TOPOLOGY
  34. UINT OutputStreamMask; // max streams == 4
  35. char OutputPositionPresent;
  36. } GS;
  37. struct PSInfo {
  38. char DepthOutput;
  39. char SampleFrequency;
  40. } PS;
  41. };
  42. UINT MinimumExpectedWaveLaneCount; // minimum lane count required, 0 if unused
  43. UINT MaximumExpectedWaveLaneCount; // maximum lane count required, 0xffffffff if unused
  44. };
  45. // PSVRuntimeInfo1 would derive and extend
  46. enum class PSVResourceType
  47. {
  48. Invalid = 0,
  49. Sampler,
  50. CBV,
  51. SRVTyped,
  52. SRVRaw,
  53. SRVStructured,
  54. UAVTyped,
  55. UAVRaw,
  56. UAVStructured,
  57. UAVStructuredWithCounter,
  58. NumEntries
  59. };
  60. // Versioning is additive and based on size
  61. struct PSVResourceBindInfo0
  62. {
  63. UINT ResType; // PSVResourceType
  64. UINT Space;
  65. UINT LowerBound;
  66. UINT UpperBound;
  67. };
  68. // PSVResourceBindInfo1 would derive and extend
  69. class DxilPipelineStateValidation
  70. {
  71. UINT m_uPSVRuntimeInfoSize;
  72. PSVRuntimeInfo0* m_pPSVRuntimeInfo0;
  73. UINT m_uResourceCount;
  74. UINT m_uPSVResourceBindInfoSize;
  75. void* m_pPSVResourceBindInfo;
  76. UINT m_uSize;
  77. public:
  78. DxilPipelineStateValidation() :
  79. m_uPSVRuntimeInfoSize(0),
  80. m_pPSVRuntimeInfo0(nullptr),
  81. m_uResourceCount(0),
  82. m_uPSVResourceBindInfoSize(0),
  83. m_pPSVResourceBindInfo(nullptr)
  84. {
  85. }
  86. // Init() from PSV0 blob part that looks like:
  87. // UINT PSVRuntimeInfo_size
  88. // { PSVRuntimeInfoN structure }
  89. // UINT ResourceCount
  90. // --- end of blob if ResourceCount == 0 ---
  91. // UINT PSVResourceBindInfo_size
  92. // { PSVResourceBindInfoN structure } * ResourceCount
  93. // returns true if no errors occurred.
  94. bool InitFromPSV0(const void* pBits, UINT size) {
  95. if(!(pBits != nullptr)) return false;
  96. const BYTE* pCurBits = (BYTE*)pBits;
  97. UINT minsize = sizeof(PSVRuntimeInfo0) + sizeof(UINT) * 2;
  98. if(!(size >= minsize)) return false;
  99. m_uPSVRuntimeInfoSize = *((const UINT*)pCurBits);
  100. if(!(m_uPSVRuntimeInfoSize >= sizeof(PSVRuntimeInfo0))) return false;
  101. pCurBits += sizeof(UINT);
  102. minsize = m_uPSVRuntimeInfoSize + sizeof(UINT) * 2;
  103. if(!(size >= minsize)) return false;
  104. m_pPSVRuntimeInfo0 = const_cast<PSVRuntimeInfo0*>((const PSVRuntimeInfo0*)pCurBits);
  105. pCurBits += m_uPSVRuntimeInfoSize;
  106. m_uResourceCount = *(const UINT*)pCurBits;
  107. pCurBits += sizeof(UINT);
  108. if (m_uResourceCount > 0) {
  109. minsize += sizeof(UINT);
  110. if(!(size >= minsize)) return false;
  111. m_uPSVResourceBindInfoSize = *(const UINT*)pCurBits;
  112. pCurBits += sizeof(UINT);
  113. minsize += m_uPSVResourceBindInfoSize * m_uResourceCount;
  114. if(!(m_uPSVResourceBindInfoSize >= sizeof(PSVResourceBindInfo0))) return false;
  115. if(!(size >= minsize)) return false;
  116. m_pPSVResourceBindInfo = static_cast<void*>(const_cast<BYTE*>(pCurBits));
  117. }
  118. return true;
  119. }
  120. // Initialize a new buffer
  121. // call with null pBuffer to get required size
  122. bool InitNew(UINT ResourceCount, void *pBuffer, UINT *pSize) {
  123. if(!(pSize)) return false;
  124. UINT size = sizeof(PSVRuntimeInfo0) + sizeof(UINT) * 2;
  125. if (ResourceCount) {
  126. size += sizeof(UINT) + (sizeof(PSVResourceBindInfo0) * ResourceCount);
  127. }
  128. if (pBuffer) {
  129. if(!(*pSize >= size)) return false;
  130. } else {
  131. *pSize = size;
  132. return true;
  133. }
  134. ::ZeroMemory(pBuffer, size);
  135. m_uPSVRuntimeInfoSize = sizeof(PSVRuntimeInfo0);
  136. BYTE* pCurBits = (BYTE*)pBuffer;
  137. *(UINT*)pCurBits = sizeof(PSVRuntimeInfo0);
  138. pCurBits += sizeof(UINT);
  139. m_pPSVRuntimeInfo0 = (PSVRuntimeInfo0*)pCurBits;
  140. pCurBits += sizeof(PSVRuntimeInfo0);
  141. // Set resource info:
  142. m_uResourceCount = ResourceCount;
  143. *(UINT*)pCurBits = ResourceCount;
  144. pCurBits += sizeof(UINT);
  145. if (ResourceCount > 0) {
  146. m_uPSVResourceBindInfoSize = sizeof(PSVResourceBindInfo0);
  147. *(UINT*)pCurBits = m_uPSVResourceBindInfoSize;
  148. pCurBits += sizeof(UINT);
  149. m_pPSVResourceBindInfo = pCurBits;
  150. }
  151. return true;
  152. }
  153. PSVRuntimeInfo0* GetPSVRuntimeInfo0() {
  154. return m_pPSVRuntimeInfo0;
  155. }
  156. UINT GetBindCount() const {
  157. return m_uResourceCount;
  158. }
  159. PSVResourceBindInfo0* GetPSVResourceBindInfo0(UINT index) {
  160. if (index < m_uResourceCount && m_pPSVResourceBindInfo &&
  161. sizeof(PSVResourceBindInfo0) <= m_uPSVResourceBindInfoSize) {
  162. return (PSVResourceBindInfo0*)((BYTE*)m_pPSVResourceBindInfo +
  163. (index * m_uPSVResourceBindInfoSize));
  164. }
  165. return nullptr;
  166. }
  167. };
  168. #endif // __DXIL_PIPELINE_STATE_VALIDATION__H__