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