D3D11Shader.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. //
  5. // File: D3D11Shader.h
  6. // Content: D3D11 Shader Types and APIs
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9. #ifndef __D3D11SHADER_H__
  10. #define __D3D11SHADER_H__
  11. #include "d3dcommon.h"
  12. typedef enum D3D11_SHADER_VERSION_TYPE
  13. {
  14. D3D11_SHVER_PIXEL_SHADER = 0,
  15. D3D11_SHVER_VERTEX_SHADER = 1,
  16. D3D11_SHVER_GEOMETRY_SHADER = 2,
  17. // D3D11 Shaders
  18. D3D11_SHVER_HULL_SHADER = 3,
  19. D3D11_SHVER_DOMAIN_SHADER = 4,
  20. D3D11_SHVER_COMPUTE_SHADER = 5,
  21. } D3D11_SHADER_VERSION_TYPE;
  22. #define D3D11_SHVER_GET_TYPE(_Version) \
  23. (((_Version) >> 16) & 0xffff)
  24. #define D3D11_SHVER_GET_MAJOR(_Version) \
  25. (((_Version) >> 4) & 0xf)
  26. #define D3D11_SHVER_GET_MINOR(_Version) \
  27. (((_Version) >> 0) & 0xf)
  28. typedef D3D_RESOURCE_RETURN_TYPE D3D11_RESOURCE_RETURN_TYPE;
  29. typedef D3D_CBUFFER_TYPE D3D11_CBUFFER_TYPE;
  30. typedef struct _D3D11_SIGNATURE_PARAMETER_DESC
  31. {
  32. LPCSTR SemanticName; // Name of the semantic
  33. UINT SemanticIndex; // Index of the semantic
  34. UINT Register; // Number of member variables
  35. D3D_NAME SystemValueType;// A predefined system value, or D3D_NAME_UNDEFINED if not applicable
  36. D3D_REGISTER_COMPONENT_TYPE ComponentType;// Scalar type (e.g. uint, float, etc.)
  37. BYTE Mask; // Mask to indicate which components of the register
  38. // are used (combination of D3D10_COMPONENT_MASK values)
  39. BYTE ReadWriteMask; // Mask to indicate whether a given component is
  40. // never written (if this is an output signature) or
  41. // always read (if this is an input signature).
  42. // (combination of D3D10_COMPONENT_MASK values)
  43. UINT Stream; // Stream index
  44. } D3D11_SIGNATURE_PARAMETER_DESC;
  45. typedef struct _D3D11_SHADER_BUFFER_DESC
  46. {
  47. LPCSTR Name; // Name of the constant buffer
  48. D3D_CBUFFER_TYPE Type; // Indicates type of buffer content
  49. UINT Variables; // Number of member variables
  50. UINT Size; // Size of CB (in bytes)
  51. UINT uFlags; // Buffer description flags
  52. } D3D11_SHADER_BUFFER_DESC;
  53. typedef struct _D3D11_SHADER_VARIABLE_DESC
  54. {
  55. LPCSTR Name; // Name of the variable
  56. UINT StartOffset; // Offset in constant buffer's backing store
  57. UINT Size; // Size of variable (in bytes)
  58. UINT uFlags; // Variable flags
  59. LPVOID DefaultValue; // Raw pointer to default value
  60. UINT StartTexture; // First texture index (or -1 if no textures used)
  61. UINT TextureSize; // Number of texture slots possibly used.
  62. UINT StartSampler; // First sampler index (or -1 if no textures used)
  63. UINT SamplerSize; // Number of sampler slots possibly used.
  64. } D3D11_SHADER_VARIABLE_DESC;
  65. typedef struct _D3D11_SHADER_TYPE_DESC
  66. {
  67. D3D_SHADER_VARIABLE_CLASS Class; // Variable class (e.g. object, matrix, etc.)
  68. D3D_SHADER_VARIABLE_TYPE Type; // Variable type (e.g. float, sampler, etc.)
  69. UINT Rows; // Number of rows (for matrices, 1 for other numeric, 0 if not applicable)
  70. UINT Columns; // Number of columns (for vectors & matrices, 1 for other numeric, 0 if not applicable)
  71. UINT Elements; // Number of elements (0 if not an array)
  72. UINT Members; // Number of members (0 if not a structure)
  73. UINT Offset; // Offset from the start of structure (0 if not a structure member)
  74. LPCSTR Name; // Name of type, can be NULL
  75. } D3D11_SHADER_TYPE_DESC;
  76. typedef D3D_TESSELLATOR_DOMAIN D3D11_TESSELLATOR_DOMAIN;
  77. typedef D3D_TESSELLATOR_PARTITIONING D3D11_TESSELLATOR_PARTITIONING;
  78. typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D11_TESSELLATOR_OUTPUT_PRIMITIVE;
  79. typedef struct _D3D11_SHADER_DESC
  80. {
  81. UINT Version; // Shader version
  82. LPCSTR Creator; // Creator string
  83. UINT Flags; // Shader compilation/parse flags
  84. UINT ConstantBuffers; // Number of constant buffers
  85. UINT BoundResources; // Number of bound resources
  86. UINT InputParameters; // Number of parameters in the input signature
  87. UINT OutputParameters; // Number of parameters in the output signature
  88. UINT InstructionCount; // Number of emitted instructions
  89. UINT TempRegisterCount; // Number of temporary registers used
  90. UINT TempArrayCount; // Number of temporary arrays used
  91. UINT DefCount; // Number of constant defines
  92. UINT DclCount; // Number of declarations (input + output)
  93. UINT TextureNormalInstructions; // Number of non-categorized texture instructions
  94. UINT TextureLoadInstructions; // Number of texture load instructions
  95. UINT TextureCompInstructions; // Number of texture comparison instructions
  96. UINT TextureBiasInstructions; // Number of texture bias instructions
  97. UINT TextureGradientInstructions; // Number of texture gradient instructions
  98. UINT FloatInstructionCount; // Number of floating point arithmetic instructions used
  99. UINT IntInstructionCount; // Number of signed integer arithmetic instructions used
  100. UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used
  101. UINT StaticFlowControlCount; // Number of static flow control instructions used
  102. UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used
  103. UINT MacroInstructionCount; // Number of macro instructions used
  104. UINT ArrayInstructionCount; // Number of array instructions used
  105. UINT CutInstructionCount; // Number of cut instructions used
  106. UINT EmitInstructionCount; // Number of emit instructions used
  107. D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology
  108. UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count
  109. D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive
  110. UINT PatchConstantParameters; // Number of parameters in the patch constant signature
  111. UINT cGSInstanceCount; // Number of Geometry shader instances
  112. UINT cControlPoints; // Number of control points in the HS->DS stage
  113. D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; // Primitive output by the tessellator
  114. D3D_TESSELLATOR_PARTITIONING HSPartitioning; // Partitioning mode of the tessellator
  115. D3D_TESSELLATOR_DOMAIN TessellatorDomain; // Domain of the tessellator (quad, tri, isoline)
  116. // instruction counts
  117. UINT cBarrierInstructions; // Number of barrier instructions in a compute shader
  118. UINT cInterlockedInstructions; // Number of interlocked instructions
  119. UINT cTextureStoreInstructions; // Number of texture writes
  120. } D3D11_SHADER_DESC;
  121. typedef struct _D3D11_SHADER_INPUT_BIND_DESC
  122. {
  123. LPCSTR Name; // Name of the resource
  124. D3D_SHADER_INPUT_TYPE Type; // Type of resource (e.g. texture, cbuffer, etc.)
  125. UINT BindPoint; // Starting bind point
  126. UINT BindCount; // Number of contiguous bind points (for arrays)
  127. UINT uFlags; // Input binding flags
  128. D3D_RESOURCE_RETURN_TYPE ReturnType; // Return type (if texture)
  129. D3D_SRV_DIMENSION Dimension; // Dimension (if texture)
  130. UINT NumSamples; // Number of samples (0 if not MS texture)
  131. } D3D11_SHADER_INPUT_BIND_DESC;
  132. //////////////////////////////////////////////////////////////////////////////
  133. // Interfaces ////////////////////////////////////////////////////////////////
  134. //////////////////////////////////////////////////////////////////////////////
  135. typedef interface ID3D11ShaderReflectionType ID3D11ShaderReflectionType;
  136. typedef interface ID3D11ShaderReflectionType *LPD3D11SHADERREFLECTIONTYPE;
  137. typedef interface ID3D11ShaderReflectionVariable ID3D11ShaderReflectionVariable;
  138. typedef interface ID3D11ShaderReflectionVariable *LPD3D11SHADERREFLECTIONVARIABLE;
  139. typedef interface ID3D11ShaderReflectionConstantBuffer ID3D11ShaderReflectionConstantBuffer;
  140. typedef interface ID3D11ShaderReflectionConstantBuffer *LPD3D11SHADERREFLECTIONCONSTANTBUFFER;
  141. typedef interface ID3D11ShaderReflection ID3D11ShaderReflection;
  142. typedef interface ID3D11ShaderReflection *LPD3D11SHADERREFLECTION;
  143. // {6E6FFA6A-9BAE-4613-A51E-91652D508C21}
  144. DEFINE_GUID(IID_ID3D11ShaderReflectionType,
  145. 0x6e6ffa6a, 0x9bae, 0x4613, 0xa5, 0x1e, 0x91, 0x65, 0x2d, 0x50, 0x8c, 0x21);
  146. #undef INTERFACE
  147. #define INTERFACE ID3D11ShaderReflectionType
  148. DECLARE_INTERFACE(ID3D11ShaderReflectionType)
  149. {
  150. STDMETHOD(GetDesc)(THIS_ __out D3D11_SHADER_TYPE_DESC *pDesc) PURE;
  151. STDMETHOD_(ID3D11ShaderReflectionType*, GetMemberTypeByIndex)(THIS_ __in UINT Index) PURE;
  152. STDMETHOD_(ID3D11ShaderReflectionType*, GetMemberTypeByName)(THIS_ __in LPCSTR Name) PURE;
  153. STDMETHOD_(LPCSTR, GetMemberTypeName)(THIS_ __in UINT Index) PURE;
  154. STDMETHOD(IsEqual)(THIS_ __in ID3D11ShaderReflectionType* pType) PURE;
  155. STDMETHOD_(ID3D11ShaderReflectionType*, GetSubType)(THIS) PURE;
  156. STDMETHOD_(ID3D11ShaderReflectionType*, GetBaseClass)(THIS) PURE;
  157. STDMETHOD_(UINT, GetNumInterfaces)(THIS) PURE;
  158. STDMETHOD_(ID3D11ShaderReflectionType*, GetInterfaceByIndex)(THIS_ __in UINT uIndex) PURE;
  159. STDMETHOD(IsOfType)(THIS_ __in ID3D11ShaderReflectionType* pType) PURE;
  160. STDMETHOD(ImplementsInterface)(THIS_ __in ID3D11ShaderReflectionType* pBase) PURE;
  161. };
  162. // {51F23923-F3E5-4BD1-91CB-606177D8DB4C}
  163. DEFINE_GUID(IID_ID3D11ShaderReflectionVariable,
  164. 0x51f23923, 0xf3e5, 0x4bd1, 0x91, 0xcb, 0x60, 0x61, 0x77, 0xd8, 0xdb, 0x4c);
  165. #undef INTERFACE
  166. #define INTERFACE ID3D11ShaderReflectionVariable
  167. DECLARE_INTERFACE(ID3D11ShaderReflectionVariable)
  168. {
  169. STDMETHOD(GetDesc)(THIS_ __out D3D11_SHADER_VARIABLE_DESC *pDesc) PURE;
  170. STDMETHOD_(ID3D11ShaderReflectionType*, GetType)(THIS) PURE;
  171. STDMETHOD_(ID3D11ShaderReflectionConstantBuffer*, GetBuffer)(THIS) PURE;
  172. STDMETHOD_(UINT, GetInterfaceSlot)(THIS_ __in UINT uArrayIndex) PURE;
  173. };
  174. // {EB62D63D-93DD-4318-8AE8-C6F83AD371B8}
  175. DEFINE_GUID(IID_ID3D11ShaderReflectionConstantBuffer,
  176. 0xeb62d63d, 0x93dd, 0x4318, 0x8a, 0xe8, 0xc6, 0xf8, 0x3a, 0xd3, 0x71, 0xb8);
  177. #undef INTERFACE
  178. #define INTERFACE ID3D11ShaderReflectionConstantBuffer
  179. DECLARE_INTERFACE(ID3D11ShaderReflectionConstantBuffer)
  180. {
  181. STDMETHOD(GetDesc)(THIS_ D3D11_SHADER_BUFFER_DESC *pDesc) PURE;
  182. STDMETHOD_(ID3D11ShaderReflectionVariable*, GetVariableByIndex)(THIS_ __in UINT Index) PURE;
  183. STDMETHOD_(ID3D11ShaderReflectionVariable*, GetVariableByName)(THIS_ __in LPCSTR Name) PURE;
  184. };
  185. // The ID3D11ShaderReflection IID may change from SDK version to SDK version
  186. // if the reflection API changes. This prevents new code with the new API
  187. // from working with an old binary. Recompiling with the new header
  188. // will pick up the new IID.
  189. // 0a233719-3960-4578-9d7c-203b8b1d9cc1
  190. DEFINE_GUID(IID_ID3D11ShaderReflection,
  191. 0x0a233719, 0x3960, 0x4578, 0x9d, 0x7c, 0x20, 0x3b, 0x8b, 0x1d, 0x9c, 0xc1);
  192. #undef INTERFACE
  193. #define INTERFACE ID3D11ShaderReflection
  194. DECLARE_INTERFACE_(ID3D11ShaderReflection, IUnknown)
  195. {
  196. STDMETHOD(QueryInterface)(THIS_ __in REFIID iid,
  197. __out LPVOID *ppv) PURE;
  198. STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  199. STDMETHOD_(ULONG, Release)(THIS) PURE;
  200. STDMETHOD(GetDesc)(THIS_ __out D3D11_SHADER_DESC *pDesc) PURE;
  201. STDMETHOD_(ID3D11ShaderReflectionConstantBuffer*, GetConstantBufferByIndex)(THIS_ __in UINT Index) PURE;
  202. STDMETHOD_(ID3D11ShaderReflectionConstantBuffer*, GetConstantBufferByName)(THIS_ __in LPCSTR Name) PURE;
  203. STDMETHOD(GetResourceBindingDesc)(THIS_ __in UINT ResourceIndex,
  204. __out D3D11_SHADER_INPUT_BIND_DESC *pDesc) PURE;
  205. STDMETHOD(GetInputParameterDesc)(THIS_ __in UINT ParameterIndex,
  206. __out D3D11_SIGNATURE_PARAMETER_DESC *pDesc) PURE;
  207. STDMETHOD(GetOutputParameterDesc)(THIS_ __in UINT ParameterIndex,
  208. __out D3D11_SIGNATURE_PARAMETER_DESC *pDesc) PURE;
  209. STDMETHOD(GetPatchConstantParameterDesc)(THIS_ __in UINT ParameterIndex,
  210. __out D3D11_SIGNATURE_PARAMETER_DESC *pDesc) PURE;
  211. STDMETHOD_(ID3D11ShaderReflectionVariable*, GetVariableByName)(THIS_ __in LPCSTR Name) PURE;
  212. STDMETHOD(GetResourceBindingDescByName)(THIS_ __in LPCSTR Name,
  213. __out D3D11_SHADER_INPUT_BIND_DESC *pDesc) PURE;
  214. STDMETHOD_(UINT, GetMovInstructionCount)(THIS) PURE;
  215. STDMETHOD_(UINT, GetMovcInstructionCount)(THIS) PURE;
  216. STDMETHOD_(UINT, GetConversionInstructionCount)(THIS) PURE;
  217. STDMETHOD_(UINT, GetBitwiseInstructionCount)(THIS) PURE;
  218. STDMETHOD_(D3D_PRIMITIVE, GetGSInputPrimitive)(THIS) PURE;
  219. STDMETHOD_(BOOL, IsSampleFrequencyShader)(THIS) PURE;
  220. STDMETHOD_(UINT, GetNumInterfaceSlots)(THIS) PURE;
  221. STDMETHOD(GetMinFeatureLevel)(THIS_ __out enum D3D_FEATURE_LEVEL* pLevel) PURE;
  222. STDMETHOD_(UINT, GetThreadGroupSize)(THIS_
  223. __out_opt UINT* pSizeX,
  224. __out_opt UINT* pSizeY,
  225. __out_opt UINT* pSizeZ) PURE;
  226. };
  227. //////////////////////////////////////////////////////////////////////////////
  228. // APIs //////////////////////////////////////////////////////////////////////
  229. //////////////////////////////////////////////////////////////////////////////
  230. #ifdef __cplusplus
  231. extern "C" {
  232. #endif //__cplusplus
  233. #ifdef __cplusplus
  234. }
  235. #endif //__cplusplus
  236. #endif //__D3D11SHADER_H__