1 module directx.d3dcompiler; 2 ////////////////////////////////////////////////////////////////////////////// 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // File: D3DCompiler.h 7 // Content: D3D Compilation Types and APIs 8 // 9 ////////////////////////////////////////////////////////////////////////////// 10 11 version(Windows): 12 13 public import directx.d3d11shader; 14 public import directx.d3d12shader; 15 16 17 // useful enums for shader versions 18 alias LPCSTR_D3D_SHADER_TARGET_ext = LPCSTR; 19 enum : LPCSTR_D3D_SHADER_TARGET_ext 20 { 21 // Direct3D 11.0 and 11.1 22 23 cs_5_0 = "cs_5_0", 24 ds_5_0 = "ds_5_0", 25 gs_5_0 = "gs_5_0", 26 hs_5_0 = "hs_5_0", 27 ps_5_0 = "ps_5_0", 28 vs_5_0 = "vs_5_0", 29 30 // Direct3D 10.1 31 32 cs_4_1 = "cs_4_1", 33 gs_4_1 = "gs_4_1", 34 ps_4_1 = "ps_4_1", 35 vs_4_1 = "vs_4_1", 36 37 // Direct3D 10.0 38 39 cs_4_0 = "cs_4_0", 40 gs_4_0 = "gs_4_0", 41 ps_4_0 = "ps_4_0", 42 vs_4_0 = "vs_4_0", 43 44 // Direct3D 9.1, 9.2, 9.3 45 46 ps_4_0_level_9_1 = "ps_4_0_level_9_1", 47 ps_4_0_level_9_3 = "ps_4_0_level_9_3", 48 vs_4_0_level_9_1 = "vs_4_0_level_9_1", 49 vs_4_0_level_9_3 = "vs_4_0_level_9_3", 50 51 // Legacy Direct3D 9 SM 3.0 52 53 ps_3_0 = "ps_3_0", 54 ps_3_sw = "ps_3_sw", 55 vs_3_0 = "vs_3_0", 56 vs_3_sw = "vs_3_sw", 57 58 // Legacy Direct3D 9 SM 2.0 59 60 ps_2_0 = "ps_2_0", 61 ps_2_a = "ps_2_a", 62 ps_2_b = "ps_2_b", 63 ps_2_sw = "ps_2_sw", 64 vs_2_0 = "vs_2_0", 65 vs_2_a = "vs_2_a", 66 vs_2_sw = "vs_2_sw", 67 68 // Legacy effects 69 70 fx_2_0 = "fx_2_0", 71 fx_4_0 = "fx_4_0", 72 fx_4_1 = "fx_4_1", 73 fx_5_0 = "fx_5_0", 74 75 } // enum LPCSTR_D3D_SHADER_TARGET_ext 76 77 78 ////////////////////////////////////////////////////////////////////////////// 79 // APIs ////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////// 81 82 83 /// predefined for D3DDisassemble10Effect 84 interface ID3D10Effect : IUnknown {} 85 86 extern(C) 87 { 88 89 //---------------------------------------------------------------------------- 90 // D3DCOMPILE flags: 91 // ----------------- 92 // D3DCOMPILE_DEBUG 93 // Insert debug file/line/type/symbol information. 94 // 95 // D3DCOMPILE_SKIP_VALIDATION 96 // Do not validate the generated code against known capabilities and 97 // constraints. This option is only recommended when compiling shaders 98 // you KNOW will work. (ie. have compiled before without this option.) 99 // Shaders are always validated by D3D before they are set to the device. 100 // 101 // D3DCOMPILE_SKIP_OPTIMIZATION 102 // Instructs the compiler to skip optimization steps during code generation. 103 // Unless you are trying to isolate a problem in your code using this option 104 // is not recommended. 105 // 106 // D3DCOMPILE_PACK_MATRIX_ROW_MAJOR 107 // Unless explicitly specified, matrices will be packed in row-major order 108 // on input and output from the shader. 109 // 110 // D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR 111 // Unless explicitly specified, matrices will be packed in column-major 112 // order on input and output from the shader. This is generally more 113 // efficient, since it allows vector-matrix multiplication to be performed 114 // using a series of dot-products. 115 // 116 // D3DCOMPILE_PARTIAL_PRECISION 117 // Force all computations in resulting shader to occur at partial precision. 118 // This may result in faster evaluation of shaders on some hardware. 119 // 120 // D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT 121 // Force compiler to compile against the next highest available software 122 // target for vertex shaders. This flag also turns optimizations off, 123 // and debugging on. 124 // 125 // D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT 126 // Force compiler to compile against the next highest available software 127 // target for pixel shaders. This flag also turns optimizations off, 128 // and debugging on. 129 // 130 // D3DCOMPILE_NO_PRESHADER 131 // Disables Preshaders. Using this flag will cause the compiler to not 132 // pull out static expression for evaluation on the host cpu 133 // 134 // D3DCOMPILE_AVOID_FLOW_CONTROL 135 // Hint compiler to avoid flow-control constructs where possible. 136 // 137 // D3DCOMPILE_PREFER_FLOW_CONTROL 138 // Hint compiler to prefer flow-control constructs where possible. 139 // 140 // D3DCOMPILE_ENABLE_STRICTNESS 141 // By default, the HLSL/Effect compilers are not strict on deprecated syntax. 142 // Specifying this flag enables the strict mode. Deprecated syntax may be 143 // removed in a future release, and enabling syntax is a good way to make 144 // sure your shaders comply to the latest spec. 145 // 146 // D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY 147 // This enables older shaders to compile to 4_0 targets. 148 // 149 //---------------------------------------------------------------------------- 150 151 enum D3DCOMPILE_DEBUG = (1 << 0); 152 enum D3DCOMPILE_SKIP_VALIDATION = (1 << 1); 153 enum D3DCOMPILE_SKIP_OPTIMIZATION = (1 << 2); 154 enum D3DCOMPILE_PACK_MATRIX_ROW_MAJOR = (1 << 3); 155 enum D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR = (1 << 4); 156 enum D3DCOMPILE_PARTIAL_PRECISION = (1 << 5); 157 enum D3DCOMPILE_FORCE_VS_SOFTWARE_NO_OPT = (1 << 6); 158 enum D3DCOMPILE_FORCE_PS_SOFTWARE_NO_OPT = (1 << 7); 159 enum D3DCOMPILE_NO_PRESHADER = (1 << 8); 160 enum D3DCOMPILE_AVOID_FLOW_CONTROL = (1 << 9); 161 enum D3DCOMPILE_PREFER_FLOW_CONTROL = (1 << 10); 162 enum D3DCOMPILE_ENABLE_STRICTNESS = (1 << 11); 163 enum D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY = (1 << 12); 164 enum D3DCOMPILE_IEEE_STRICTNESS = (1 << 13); 165 enum D3DCOMPILE_OPTIMIZATION_LEVEL0 = (1 << 14); 166 enum D3DCOMPILE_OPTIMIZATION_LEVEL1 = 0; 167 enum D3DCOMPILE_OPTIMIZATION_LEVEL2 = ((1 << 14) | (1 << 15)); 168 enum D3DCOMPILE_OPTIMIZATION_LEVEL3 = (1 << 15); 169 enum D3DCOMPILE_RESERVED16 = (1 << 16); 170 enum D3DCOMPILE_RESERVED17 = (1 << 17); 171 enum D3DCOMPILE_WARNINGS_ARE_ERRORS = (1 << 18); 172 173 //---------------------------------------------------------------------------- 174 // D3DCOMPILE_EFFECT flags: 175 // ------------------------------------- 176 // These flags are passed in when creating an effect, and affect 177 // either compilation behavior or runtime effect behavior 178 // 179 // D3DCOMPILE_EFFECT_CHILD_EFFECT 180 // Compile this .fx file to a child effect. Child effects have no 181 // initializers for any shared values as these are initialied in the 182 // master effect (pool). 183 // 184 // D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS 185 // By default, performance mode is enabled. Performance mode 186 // disallows mutable state objects by preventing non-literal 187 // expressions from appearing in state object definitions. 188 // Specifying this flag will disable the mode and allow for mutable 189 // state objects. 190 // 191 //---------------------------------------------------------------------------- 192 193 enum D3DCOMPILE_EFFECT_CHILD_EFFECT = (1 << 0); 194 enum D3DCOMPILE_EFFECT_ALLOW_SLOW_OPS = (1 << 1); 195 196 //---------------------------------------------------------------------------- 197 // D3DCompile: 198 // ---------- 199 // Compile source text into bytecode appropriate for the given target. 200 //---------------------------------------------------------------------------- 201 extern(Windows) nothrow 202 HRESULT D3DCompile( 203 LPCVOID pSrcData, 204 SIZE_T SrcDataSize, 205 LPCSTR pSourceName, 206 const(D3D_SHADER_MACRO)* pDefines, 207 ID3DInclude pInclude, 208 LPCSTR pEntrypoint, 209 LPCSTR pTarget, 210 UINT Flags1, 211 UINT Flags2, 212 ID3DBlob* ppCode, 213 ID3DBlob* ppErrorMsgs); 214 215 alias pD3DCompile = extern(Windows) nothrow HRESULT function( 216 LPCVOID pSrcData, 217 SIZE_T SrcDataSize, 218 LPCSTR pFileName, 219 const(D3D_SHADER_MACRO)* pDefines, 220 ID3DInclude pInclude, 221 LPCSTR pEntrypoint, 222 LPCSTR_D3D_SHADER_TARGET_ext pTarget, 223 UINT Flags1, 224 UINT Flags2, 225 ID3DBlob* ppCode, 226 ID3DBlob* ppErrorMsgs); 227 228 229 // NOTE: Since D3DCompiler_44 D3DCompileFromFile is now part of the DirectX rather than Windows 230 extern(Windows) nothrow 231 HRESULT D3DCompileFromFile( 232 LPCWSTR pFileName, 233 const(D3D_SHADER_MACRO)* pDefines, 234 ID3DInclude pInclude, 235 LPCSTR pEntrypoint, 236 LPCSTR pTarget, 237 UINT Flags1, 238 UINT Flags2, 239 ID3DBlob* ppCode, 240 ID3DBlob* ppErrorMsgs); 241 242 //---------------------------------------------------------------------------- 243 // D3DPreprocess: 244 // ---------- 245 // Process source text with the compiler's preprocessor and return 246 // the resulting text. 247 //---------------------------------------------------------------------------- 248 249 extern(Windows) nothrow 250 HRESULT D3DPreprocess( 251 LPCVOID pSrcData, 252 SIZE_T SrcDataSize, 253 LPCSTR pSourceName, 254 const(D3D_SHADER_MACRO)* pDefines, 255 ID3DInclude pInclude, 256 ID3DBlob* ppCodeText, 257 ID3DBlob* ppErrorMsgs); 258 259 alias pD3DPreprocess = extern(Windows) nothrow HRESULT function( 260 LPCVOID pSrcData, 261 SIZE_T SrcDataSize, 262 LPCSTR pFileName, 263 const(D3D_SHADER_MACRO)* pDefines, 264 ID3DInclude pInclude, 265 ID3DBlob* ppCodeText, 266 ID3DBlob* ppErrorMsgs); 267 268 //---------------------------------------------------------------------------- 269 // D3DGetDebugInfo: 270 // ----------------------- 271 // Gets shader debug info. Debug info is generated by D3DCompile and is 272 // embedded in the body of the shader. 273 //---------------------------------------------------------------------------- 274 275 extern(Windows) nothrow 276 HRESULT D3DGetDebugInfo( 277 LPCVOID pSrcData, 278 SIZE_T SrcDataSize, 279 ID3DBlob* ppDebugInfo); 280 281 //---------------------------------------------------------------------------- 282 // D3DReflect: 283 // ---------- 284 // Shader code contains metadata that can be inspected via the 285 // reflection APIs. 286 //---------------------------------------------------------------------------- 287 288 extern(Windows) nothrow 289 HRESULT D3DReflect( 290 LPCVOID pSrcData, 291 SIZE_T SrcDataSize, 292 REFIID pInterface, 293 void** ppReflector); 294 295 //---------------------------------------------------------------------------- 296 // D3DDisassemble: 297 // ---------------------- 298 // Takes a binary shader and returns a buffer containing text assembly. 299 //---------------------------------------------------------------------------- 300 301 enum D3D_DISASM_ENABLE_COLOR_CODE = 0x00000001; 302 enum D3D_DISASM_ENABLE_DEFAULT_VALUE_PRINTS = 0x00000002; 303 enum D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING = 0x00000004; 304 enum D3D_DISASM_ENABLE_INSTRUCTION_CYCLE = 0x00000008; 305 enum D3D_DISASM_DISABLE_DEBUG_INFO = 0x00000010; 306 307 extern(Windows) nothrow 308 HRESULT D3DDisassemble( 309 LPCVOID pSrcData, 310 SIZE_T SrcDataSize, 311 UINT Flags, 312 LPCSTR szComments, 313 ID3DBlob* ppDisassembly); 314 315 alias pD3DDisassemble = extern(Windows) nothrow HRESULT function( 316 LPCVOID pSrcData, 317 SIZE_T SrcDataSize, 318 UINT Flags, 319 LPCSTR szComments, 320 ID3DBlob* ppDisassembly); 321 322 //---------------------------------------------------------------------------- 323 // D3DDisassemble10Effect: 324 // ----------------------- 325 // Takes a D3D10 effect interface and returns a 326 // buffer containing text assembly. 327 //---------------------------------------------------------------------------- 328 329 extern(Windows) nothrow 330 HRESULT D3DDisassemble10Effect( 331 ID3D10Effect pEffect, 332 UINT Flags, 333 ID3DBlob* ppDisassembly); 334 335 //---------------------------------------------------------------------------- 336 // D3DGetInputSignatureBlob: 337 // ----------------------- 338 // Retrieve the input signature from a compilation result. 339 //---------------------------------------------------------------------------- 340 341 extern(Windows) nothrow 342 HRESULT D3DGetInputSignatureBlob( 343 LPCVOID pSrcData, 344 SIZE_T SrcDataSize, 345 ID3DBlob* ppSignatureBlob); 346 347 //---------------------------------------------------------------------------- 348 // D3DGetOutputSignatureBlob: 349 // ----------------------- 350 // Retrieve the output signature from a compilation result. 351 //---------------------------------------------------------------------------- 352 353 extern(Windows) nothrow 354 HRESULT D3DGetOutputSignatureBlob( 355 LPCVOID pSrcData, 356 SIZE_T SrcDataSize, 357 ID3DBlob* ppSignatureBlob); 358 359 //---------------------------------------------------------------------------- 360 // D3DGetInputAndOutputSignatureBlob: 361 // ----------------------- 362 // Retrieve the input and output signatures from a compilation result. 363 //---------------------------------------------------------------------------- 364 365 extern(Windows) nothrow 366 HRESULT D3DGetInputAndOutputSignatureBlob( 367 LPCVOID pSrcData, 368 SIZE_T SrcDataSize, 369 ID3DBlob* ppSignatureBlob); 370 371 //---------------------------------------------------------------------------- 372 // D3DStripShader: 373 // ----------------------- 374 // Removes unwanted blobs from a compilation result 375 //---------------------------------------------------------------------------- 376 377 enum D3DCOMPILER_STRIP_FLAGS 378 { 379 D3DCOMPILER_STRIP_REFLECTION_DATA = 1, 380 D3DCOMPILER_STRIP_DEBUG_INFO = 2, 381 D3DCOMPILER_STRIP_TEST_BLOBS = 4, 382 D3DCOMPILER_STRIP_FORCE_DWORD = 0x7fffffff, 383 } 384 385 extern(Windows) nothrow 386 HRESULT D3DStripShader( 387 LPCVOID pShaderBytecode, 388 SIZE_T BytecodeLength, 389 UINT uStripFlags, 390 ID3DBlob* ppStrippedBlob); 391 392 //---------------------------------------------------------------------------- 393 // D3DGetBlobPart: 394 // ----------------------- 395 // Extracts information from a compilation result. 396 //---------------------------------------------------------------------------- 397 alias D3D_BLOB_PART = int; 398 enum : D3D_BLOB_PART 399 { 400 D3D_BLOB_INPUT_SIGNATURE_BLOB, 401 D3D_BLOB_OUTPUT_SIGNATURE_BLOB, 402 D3D_BLOB_INPUT_AND_OUTPUT_SIGNATURE_BLOB, 403 D3D_BLOB_PATCH_CONSTANT_SIGNATURE_BLOB, 404 D3D_BLOB_ALL_SIGNATURE_BLOB, 405 D3D_BLOB_DEBUG_INFO, 406 D3D_BLOB_LEGACY_SHADER, 407 D3D_BLOB_XNA_PREPASS_SHADER, 408 D3D_BLOB_XNA_SHADER, 409 410 // Test parts are only produced by special compiler versions and so 411 // are usually not present in shaders. 412 D3D_BLOB_TEST_ALTERNATE_SHADER = 0x8000, 413 D3D_BLOB_TEST_COMPILE_DETAILS, 414 D3D_BLOB_TEST_COMPILE_PERF, 415 } 416 417 extern(Windows) nothrow 418 HRESULT D3DGetBlobPart( 419 LPCVOID pSrcData, 420 SIZE_T SrcDataSize, 421 D3D_BLOB_PART Part, 422 UINT Flags, 423 ID3DBlob* ppPart); 424 425 //---------------------------------------------------------------------------- 426 // D3DCompressShaders: 427 // ----------------------- 428 // Compresses a set of shaders into a more compact form. 429 //---------------------------------------------------------------------------- 430 431 struct _D3D_SHADER_DATA 432 { 433 LPCVOID pBytecode; 434 SIZE_T BytecodeLength; 435 } 436 alias _D3D_SHADER_DATA D3D_SHADER_DATA; 437 438 enum D3D_COMPRESS_SHADER_KEEP_ALL_PARTS = 0x00000001; 439 440 extern(Windows) nothrow 441 HRESULT D3DCompressShaders( 442 UINT uNumShaders, 443 D3D_SHADER_DATA* pShaderData, 444 UINT uFlags, 445 ID3DBlob* ppCompressedData); 446 447 //---------------------------------------------------------------------------- 448 // D3DDecompressShaders: 449 // ----------------------- 450 // Decompresses one or more shaders from a compressed set. 451 //---------------------------------------------------------------------------- 452 453 extern(Windows) nothrow 454 HRESULT D3DDecompressShaders( 455 LPCVOID pSrcData, 456 SIZE_T SrcDataSize, 457 UINT uNumShaders, 458 UINT uStartIndex, 459 UINT* pIndices, 460 UINT uFlags, 461 ID3DBlob* ppShaders, 462 UINT* pTotalShaders); 463 464 //---------------------------------------------------------------------------- 465 // D3DCreateBlob: 466 // ----------------------- 467 // Create an ID3DBlob instance. 468 //---------------------------------------------------------------------------- 469 470 extern(Windows) nothrow 471 HRESULT D3DCreateBlob( 472 SIZE_T Size, 473 ID3DBlob* ppBlob); 474 475 476 }