1 module directx.d3d12shader; 2 ////////////////////////////////////////////////////////////////////////////// 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // File: D3D12Shader.h 7 // Content: D3D12 Shader Types and APIs 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 version(Windows): 12 13 public import directx.d3dcommon; 14 15 alias DWORD D3D12_SHADER_VERSION_TYPE; 16 enum : D3D12_SHADER_VERSION_TYPE 17 { 18 D3D12_SHVER_PIXEL_SHADER = 0, 19 D3D12_SHVER_VERTEX_SHADER = 1, 20 D3D12_SHVER_GEOMETRY_SHADER = 2, 21 22 // D3D11 Shaders 23 D3D12_SHVER_HULL_SHADER = 3, 24 D3D12_SHVER_DOMAIN_SHADER = 4, 25 D3D12_SHVER_COMPUTE_SHADER = 5, 26 27 D3D12_SHVER_RESERVED0 = 0xFFF0, 28 } 29 30 pure nothrow @safe @nogc { 31 DWORD D3D12_SHVER_GET_TYPE(DWORD _Version) { 32 return (_Version >> 16) & 0xffff; 33 } 34 DWORD D3D12_SHVER_GET_MAJOR(DWORD _Version) { 35 return (_Version >> 4) & 0xf; 36 } 37 DWORD D3D12_SHVER_GET_MINOR(DWORD _Version) { 38 return (_Version >> 0) & 0xf; 39 } 40 } 41 42 // Slot ID for library function return 43 enum D3D_RETURN_PARAMETER_INDEX = (-1); 44 45 alias D3D_RESOURCE_RETURN_TYPE D3D12_RESOURCE_RETURN_TYPE; 46 47 alias D3D_CBUFFER_TYPE D3D12_CBUFFER_TYPE; 48 49 struct D3D12_SIGNATURE_PARAMETER_DESC 50 { 51 LPCSTR SemanticName; // Name of the semantic 52 UINT SemanticIndex; // Index of the semantic 53 UINT Register; // Number of member variables 54 D3D_NAME SystemValueType;// A predefined system value, or D3D_NAME_UNDEFINED if not applicable 55 D3D_REGISTER_COMPONENT_TYPE ComponentType; // Scalar type (e.g. uint, float, etc.) 56 BYTE Mask; // Mask to indicate which components of the register 57 // are used (combination of D3D10_COMPONENT_MASK values) 58 BYTE ReadWriteMask; // Mask to indicate whether a given component is 59 // never written (if this is an output signature) or 60 // always read (if this is an input signature). 61 // (combination of D3D_MASK_* values) 62 UINT Stream; // Stream index 63 D3D_MIN_PRECISION MinPrecision; // Minimum desired interpolation precision 64 } 65 66 struct D3D12_SHADER_BUFFER_DESC 67 { 68 LPCSTR Name; // Name of the constant buffer 69 D3D_CBUFFER_TYPE Type; // Indicates type of buffer content 70 UINT Variables; // Number of member variables 71 UINT Size; // Size of CB (in bytes) 72 UINT uFlags; // Buffer description flags 73 } 74 75 struct D3D12_SHADER_VARIABLE_DESC 76 { 77 LPCSTR Name; // Name of the variable 78 UINT StartOffset; // Offset in constant buffer's backing store 79 UINT Size; // Size of variable (in bytes) 80 UINT uFlags; // Variable flags 81 LPVOID DefaultValue; // Raw pointer to default value 82 UINT StartTexture; // First texture index (or -1 if no textures used) 83 UINT TextureSize; // Number of texture slots possibly used. 84 UINT StartSampler; // First sampler index (or -1 if no textures used) 85 UINT SamplerSize; // Number of sampler slots possibly used. 86 } 87 88 struct D3D12_SHADER_TYPE_DESC 89 { 90 D3D_SHADER_VARIABLE_CLASS Class; // Variable class (e.g. object, matrix, etc.) 91 D3D_SHADER_VARIABLE_TYPE Type; // Variable type (e.g. float, sampler, etc.) 92 UINT Rows; // Number of rows (for matrices, 1 for other numeric, 0 if not applicable) 93 UINT Columns; // Number of columns (for vectors & matrices, 1 for other numeric, 0 if not applicable) 94 UINT Elements; // Number of elements (0 if not an array) 95 UINT Members; // Number of members (0 if not a structure) 96 UINT Offset; // Offset from the start of structure (0 if not a structure member) 97 LPCSTR Name; // Name of type, can be NULL 98 } 99 100 alias D3D12_TESSELLATOR_DOMAIN = D3D_TESSELLATOR_DOMAIN; 101 102 alias D3D12_TESSELLATOR_PARTITIONING = D3D_TESSELLATOR_PARTITIONING; 103 104 alias D3D12_TESSELLATOR_OUTPUT_PRIMITIVE = D3D_TESSELLATOR_OUTPUT_PRIMITIVE; 105 106 struct D3D12_SHADER_DESC 107 { 108 UINT Version; // Shader version 109 LPCSTR Creator; // Creator string 110 UINT Flags; // Shader compilation/parse flags 111 112 UINT ConstantBuffers; // Number of constant buffers 113 UINT BoundResources; // Number of bound resources 114 UINT InputParameters; // Number of parameters in the input signature 115 UINT OutputParameters; // Number of parameters in the output signature 116 117 UINT InstructionCount; // Number of emitted instructions 118 UINT TempRegisterCount; // Number of temporary registers used 119 UINT TempArrayCount; // Number of temporary arrays used 120 UINT DefCount; // Number of constant defines 121 UINT DclCount; // Number of declarations (input + output) 122 UINT TextureNormalInstructions; // Number of non-categorized texture instructions 123 UINT TextureLoadInstructions; // Number of texture load instructions 124 UINT TextureCompInstructions; // Number of texture comparison instructions 125 UINT TextureBiasInstructions; // Number of texture bias instructions 126 UINT TextureGradientInstructions; // Number of texture gradient instructions 127 UINT FloatInstructionCount; // Number of floating point arithmetic instructions used 128 UINT IntInstructionCount; // Number of signed integer arithmetic instructions used 129 UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used 130 UINT StaticFlowControlCount; // Number of static flow control instructions used 131 UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used 132 UINT MacroInstructionCount; // Number of macro instructions used 133 UINT ArrayInstructionCount; // Number of array instructions used 134 UINT CutInstructionCount; // Number of cut instructions used 135 UINT EmitInstructionCount; // Number of emit instructions used 136 D3D_PRIMITIVE_TOPOLOGY GSOutputTopology; // Geometry shader output topology 137 UINT GSMaxOutputVertexCount; // Geometry shader maximum output vertex count 138 D3D_PRIMITIVE InputPrimitive; // GS/HS input primitive 139 UINT PatchConstantParameters; // Number of parameters in the patch constant signature 140 UINT cGSInstanceCount; // Number of Geometry shader instances 141 UINT cControlPoints; // Number of control points in the HS->DS stage 142 D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive; // Primitive output by the tessellator 143 D3D_TESSELLATOR_PARTITIONING HSPartitioning; // Partitioning mode of the tessellator 144 D3D_TESSELLATOR_DOMAIN TessellatorDomain; // Domain of the tessellator (quad, tri, isoline) 145 // instruction counts 146 UINT cBarrierInstructions; // Number of barrier instructions in a compute shader 147 UINT cInterlockedInstructions; // Number of interlocked instructions 148 UINT cTextureStoreInstructions; // Number of texture writes 149 } 150 151 struct D3D12_SHADER_INPUT_BIND_DESC 152 { 153 LPCSTR Name; // Name of the resource 154 D3D_SHADER_INPUT_TYPE Type; // Type of resource (e.g. texture, cbuffer, etc.) 155 UINT BindPoint; // Starting bind point 156 UINT BindCount; // Number of contiguous bind points (for arrays) 157 158 UINT uFlags; // Input binding flags 159 D3D_RESOURCE_RETURN_TYPE ReturnType; // Return type (if texture) 160 D3D_SRV_DIMENSION Dimension; // Dimension (if texture) 161 UINT NumSamples; // Number of samples (0 if not MS texture) 162 UINT Space; // Register space 163 UINT uID; // Range ID in the bytecode 164 } 165 166 enum D3D_SHADER_REQUIRES_DOUBLES = 0x00000001; 167 enum D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL = 0x00000002; 168 enum D3D_SHADER_REQUIRES_UAVS_AT_EVERY_STAGE = 0x00000004; 169 enum D3D_SHADER_REQUIRES_64_UAVS = 0x00000008; 170 enum D3D_SHADER_REQUIRES_MINIMUM_PRECISION = 0x00000010; 171 enum D3D_SHADER_REQUIRES_11_1_DOUBLE_EXTENSIONS = 0x00000020; 172 enum D3D_SHADER_REQUIRES_11_1_SHADER_EXTENSIONS = 0x00000040; 173 enum D3D_SHADER_REQUIRES_LEVEL_9_COMPARISON_FILTERING = 0x00000080; 174 enum D3D_SHADER_REQUIRES_TILED_RESOURCES = 0x00000100; 175 enum D3D_SHADER_REQUIRES_STENCIL_REF = 0x00000200; 176 enum D3D_SHADER_REQUIRES_INNER_COVERAGE = 0x00000400; 177 enum D3D_SHADER_REQUIRES_TYPED_UAV_LOAD_ADDITIONAL_FORMATS = 0x00000800; 178 enum D3D_SHADER_REQUIRES_ROVS = 0x00001000; 179 enum D3D_SHADER_REQUIRES_VIEWPORT_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER_FEEDING_RASTERIZER = 0x00002000; 180 181 struct D3D12_LIBRARY_DESC 182 { 183 LPCSTR Creator; // The name of the originator of the library. 184 UINT Flags; // Compilation flags. 185 UINT FunctionCount; // Number of functions exported from the library. 186 } 187 188 struct D3D12_FUNCTION_DESC 189 { 190 UINT Version; // Shader version 191 LPCSTR Creator; // Creator string 192 UINT Flags; // Shader compilation/parse flags 193 194 UINT ConstantBuffers; // Number of constant buffers 195 UINT BoundResources; // Number of bound resources 196 197 UINT InstructionCount; // Number of emitted instructions 198 UINT TempRegisterCount; // Number of temporary registers used 199 UINT TempArrayCount; // Number of temporary arrays used 200 UINT DefCount; // Number of constant defines 201 UINT DclCount; // Number of declarations (input + output) 202 UINT TextureNormalInstructions; // Number of non-categorized texture instructions 203 UINT TextureLoadInstructions; // Number of texture load instructions 204 UINT TextureCompInstructions; // Number of texture comparison instructions 205 UINT TextureBiasInstructions; // Number of texture bias instructions 206 UINT TextureGradientInstructions; // Number of texture gradient instructions 207 UINT FloatInstructionCount; // Number of floating point arithmetic instructions used 208 UINT IntInstructionCount; // Number of signed integer arithmetic instructions used 209 UINT UintInstructionCount; // Number of unsigned integer arithmetic instructions used 210 UINT StaticFlowControlCount; // Number of static flow control instructions used 211 UINT DynamicFlowControlCount; // Number of dynamic flow control instructions used 212 UINT MacroInstructionCount; // Number of macro instructions used 213 UINT ArrayInstructionCount; // Number of array instructions used 214 UINT MovInstructionCount; // Number of mov instructions used 215 UINT MovcInstructionCount; // Number of movc instructions used 216 UINT ConversionInstructionCount; // Number of type conversion instructions used 217 UINT BitwiseInstructionCount; // Number of bitwise arithmetic instructions used 218 D3D_FEATURE_LEVEL MinFeatureLevel; // Min target of the function byte code 219 UINT64 RequiredFeatureFlags; // Required feature flags 220 221 LPCSTR Name; // Function name 222 INT FunctionParameterCount; // Number of logical parameters in the function signature (not including return) 223 BOOL HasReturn; // TRUE, if function returns a value, false - it is a subroutine 224 BOOL Has10Level9VertexShader; // TRUE, if there is a 10L9 VS blob 225 BOOL Has10Level9PixelShader; // TRUE, if there is a 10L9 PS blob 226 } 227 228 struct D3D12_PARAMETER_DESC 229 { 230 LPCSTR Name; // Parameter name. 231 LPCSTR SemanticName; // Parameter semantic name (+index). 232 D3D_SHADER_VARIABLE_TYPE Type; // Element type. 233 D3D_SHADER_VARIABLE_CLASS Class; // Scalar/Vector/Matrix. 234 UINT Rows; // Rows are for matrix parameters. 235 UINT Columns; // Components or Columns in matrix. 236 D3D_INTERPOLATION_MODE InterpolationMode; // Interpolation mode. 237 D3D_PARAMETER_FLAGS Flags; // Parameter modifiers. 238 239 UINT FirstInRegister; // The first input register for this parameter. 240 UINT FirstInComponent; // The first input register component for this parameter. 241 UINT FirstOutRegister; // The first output register for this parameter. 242 UINT FirstOutComponent; // The first output register component for this parameter. 243 } 244 245 ////////////////////////////////////////////////////////////////////////////// 246 // Interfaces //////////////////////////////////////////////////////////////// 247 ////////////////////////////////////////////////////////////////////////////// 248 249 mixin( uuid!(ID3D12ShaderReflectionType, "e913c351-783d-48ca-a1d1-4f306284ad56") ); 250 extern (C++) interface ID3D12ShaderReflectionType : IUnknown 251 { 252 HRESULT GetDesc(D3D12_SHADER_TYPE_DESC* pDesc); 253 254 ID3D12ShaderReflectionType GetMemberTypeByIndex(UINT Index); 255 ID3D12ShaderReflectionType GetMemberTypeByName(LPCSTR Name); 256 LPCSTR GetMemberTypeName(UINT Index); 257 258 HRESULT IsEqual(ID3D12ShaderReflectionType pType); 259 ID3D12ShaderReflectionType GetSubType(); 260 ID3D12ShaderReflectionType GetBaseClass(); 261 UINT GetNumInterfaces(); 262 ID3D12ShaderReflectionType GetInterfaceByIndex(UINT uIndex); 263 HRESULT IsOfType(ID3D12ShaderReflectionType pType); 264 HRESULT ImplementsInterface(ID3D12ShaderReflectionType pBase); 265 } 266 267 mixin( uuid!(ID3D12ShaderReflectionVariable, "8337a8a6-a216-444a-b2f4-314733a73aea") ); 268 extern (C++) interface ID3D12ShaderReflectionVariable : IUnknown 269 { 270 HRESULT GetDesc(D3D12_SHADER_VARIABLE_DESC* pDesc); 271 272 ID3D12ShaderReflectionType GetType(); 273 ID3D12ShaderReflectionConstantBuffer GetBuffer(); 274 275 UINT GetInterfaceSlot(UINT uArrayIndex); 276 } 277 278 mixin( uuid!(ID3D12ShaderReflectionConstantBuffer, "c59598b4-48b3-4869-b9b1-b1618b14a8b7") ); 279 extern (C++) interface ID3D12ShaderReflectionConstantBuffer : IUnknown 280 { 281 HRESULT GetDesc(D3D12_SHADER_BUFFER_DESC* pDesc); 282 283 ID3D12ShaderReflectionVariable GetVariableByIndex(UINT Index); 284 ID3D12ShaderReflectionVariable GetVariableByName(LPCSTR Name); 285 } 286 287 mixin( uuid!(ID3D12ShaderReflection, "5a58797d-a72c-478d-8ba2-efc6b0efe88e") ); 288 extern (C++) interface ID3D12ShaderReflection : IUnknown 289 { 290 HRESULT GetDesc(D3D12_SHADER_DESC* pDesc); 291 292 ID3D12ShaderReflectionConstantBuffer GetConstantBufferByIndex(UINT Index); 293 ID3D12ShaderReflectionConstantBuffer GetConstantBufferByName(LPCSTR Name); 294 295 HRESULT GetResourceBindingDesc(UINT ResourceIndex, 296 D3D12_SHADER_INPUT_BIND_DESC* pDesc); 297 298 HRESULT GetInputParameterDesc(UINT ParameterIndex, 299 D3D12_SIGNATURE_PARAMETER_DESC* pDesc); 300 HRESULT GetOutputParameterDesc(UINT ParameterIndex, 301 D3D12_SIGNATURE_PARAMETER_DESC* pDesc); 302 HRESULT GetPatchConstantParameterDesc(UINT ParameterIndex, 303 D3D12_SIGNATURE_PARAMETER_DESC* pDesc); 304 305 ID3D12ShaderReflectionVariable GetVariableByName(LPCSTR Name); 306 307 HRESULT GetResourceBindingDescByName(LPCSTR Name, 308 D3D12_SHADER_INPUT_BIND_DESC* pDesc); 309 310 UINT GetMovInstructionCount(); 311 UINT GetMovcInstructionCount(); 312 UINT GetConversionInstructionCount(); 313 UINT GetBitwiseInstructionCount(); 314 315 D3D_PRIMITIVE GetGSInputPrimitive(); 316 BOOL IsSampleFrequencyShader(); 317 318 UINT GetNumInterfaceSlots(); 319 HRESULT GetMinFeatureLevel(D3D_FEATURE_LEVEL* pLevel); 320 321 UINT GetThreadGroupSize( 322 UINT* pSizeX, 323 UINT* pSizeY, 324 UINT* pSizeZ); 325 326 UINT64 GetRequiresFlags(); 327 } 328 329 mixin( uuid!(ID3D12LibraryReflection, "8e349d19-54db-4a56-9dc9-119d87bdb804") ); 330 extern (C++) interface ID3D12LibraryReflection : IUnknown 331 { 332 HRESULT GetDesc(D3D12_LIBRARY_DESC* pDesc); 333 334 ID3D12FunctionReflection GetFunctionByIndex(INT FunctionIndex); 335 } 336 337 mixin( uuid!(ID3D12FunctionReflection, "1108795c-2772-4ba9-b2a8-d464dc7e2799") ); 338 extern (C++) interface ID3D12FunctionReflection : IUnknown 339 { 340 HRESULT GetDesc(D3D12_FUNCTION_DESC * pDesc); 341 342 ID3D12ShaderReflectionConstantBuffer GetConstantBufferByIndex(UINT BufferIndex); 343 ID3D12ShaderReflectionConstantBuffer GetConstantBufferByName(LPCSTR Name); 344 345 HRESULT GetResourceBindingDesc(UINT ResourceIndex, 346 D3D12_SHADER_INPUT_BIND_DESC* pDesc); 347 348 ID3D12ShaderReflectionVariable GetVariableByName(LPCSTR Name); 349 350 HRESULT GetResourceBindingDescByName(LPCSTR Name, 351 D3D12_SHADER_INPUT_BIND_DESC* pDesc); 352 353 // Use D3D_RETURN_PARAMETER_INDEX to get description of the return value. 354 ID3D12FunctionParameterReflection GetFunctionParameter(INT ParameterIndex); 355 }; 356 357 mixin( uuid!(ID3D12FunctionParameterReflection, "ec25f42d-7006-4f2b-b33e-02cc3375733f") ); 358 extern (C++) interface ID3D12FunctionParameterReflection : IUnknown 359 { 360 HRESULT GetDesc(D3D12_PARAMETER_DESC* pDesc); 361 }