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