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