|
15 | 15 | #include "reflection.h"
|
16 | 16 | #include "emit.h"
|
17 | 17 |
|
18 |
| -// Enable calling through to `fxc` to |
| 18 | +// Enable calling through to `fxc` or `dxc` to |
19 | 19 | // generate code on Windows.
|
20 | 20 | #ifdef _WIN32
|
21 | 21 | #define WIN32_LEAN_AND_MEAN
|
|
27 | 27 | #ifndef SLANG_ENABLE_DXBC_SUPPORT
|
28 | 28 | #define SLANG_ENABLE_DXBC_SUPPORT 1
|
29 | 29 | #endif
|
| 30 | + #ifndef SLANG_ENABLE_DXIL_SUPPORT |
| 31 | + #define SLANG_ENABLE_DXIL_SUPPORT 1 |
| 32 | + #endif |
30 | 33 | #endif
|
31 | 34 | //
|
32 |
| -// Otherwise, don't enable DXBC by default: |
| 35 | +// Otherwise, don't enable DXBC/DXIL by default: |
33 | 36 | #ifndef SLANG_ENABLE_DXBC_SUPPORT
|
34 | 37 | #define SLANG_ENABLE_DXBC_SUPPORT 0
|
35 | 38 | #endif
|
| 39 | +#ifndef SLANG_ENABLE_DXIL_SUPPORT |
| 40 | + #define SLANG_ENABLE_DXIL_SUPPORT 0 |
| 41 | +#endif |
36 | 42 |
|
37 | 43 | // Enable calling through to `glslang` on
|
38 | 44 | // all platforms.
|
@@ -356,6 +362,22 @@ namespace Slang
|
356 | 362 | }
|
357 | 363 | #endif
|
358 | 364 |
|
| 365 | +#if SLANG_ENABLE_DXIL_SUPPORT |
| 366 | + |
| 367 | +// Implementations in `dxc-support.cpp` |
| 368 | + |
| 369 | +int emitDXILForEntryPointUsingDXC( |
| 370 | + EntryPointRequest* entryPoint, |
| 371 | + TargetRequest* targetReq, |
| 372 | + List<uint8_t>& outCode); |
| 373 | + |
| 374 | +String dissassembleDXILUsingDXC( |
| 375 | + CompileRequest* compileRequest, |
| 376 | + void const* data, |
| 377 | + size_t size); |
| 378 | + |
| 379 | +#endif |
| 380 | + |
359 | 381 | #if SLANG_ENABLE_GLSLANG_SUPPORT
|
360 | 382 |
|
361 | 383 | SharedLibrary loadGLSLCompilerDLL(CompileRequest* request)
|
@@ -540,6 +562,38 @@ namespace Slang
|
540 | 562 | break;
|
541 | 563 | #endif
|
542 | 564 |
|
| 565 | +#if SLANG_ENABLE_DXIL_SUPPORT |
| 566 | + case CodeGenTarget::DXIL: |
| 567 | + { |
| 568 | + List<uint8_t> code; |
| 569 | + int err = emitDXILForEntryPointUsingDXC(entryPoint, targetReq, code); |
| 570 | + if (!err) |
| 571 | + { |
| 572 | + maybeDumpIntermediate(compileRequest, code.Buffer(), code.Count(), target); |
| 573 | + result = CompileResult(code); |
| 574 | + } |
| 575 | + } |
| 576 | + break; |
| 577 | + |
| 578 | + case CodeGenTarget::DXILAssembly: |
| 579 | + { |
| 580 | + List<uint8_t> code; |
| 581 | + int err = emitDXILForEntryPointUsingDXC(entryPoint, targetReq, code); |
| 582 | + if (!err) |
| 583 | + { |
| 584 | + String assembly = dissassembleDXILUsingDXC( |
| 585 | + compileRequest, |
| 586 | + code.Buffer(), |
| 587 | + code.Count()); |
| 588 | + |
| 589 | + maybeDumpIntermediate(compileRequest, assembly.Buffer(), target); |
| 590 | + |
| 591 | + result = CompileResult(assembly); |
| 592 | + } |
| 593 | + } |
| 594 | + break; |
| 595 | +#endif |
| 596 | + |
543 | 597 | case CodeGenTarget::SPIRV:
|
544 | 598 | {
|
545 | 599 | List<uint8_t> code = emitSPIRVForEntryPoint(entryPoint, targetReq);
|
@@ -703,6 +757,17 @@ namespace Slang
|
703 | 757 | break;
|
704 | 758 | #endif
|
705 | 759 |
|
| 760 | + #if SLANG_ENABLE_DXIL_SUPPORT |
| 761 | + case CodeGenTarget::DXIL: |
| 762 | + { |
| 763 | + String assembly = dissassembleDXILUsingDXC(compileRequest, |
| 764 | + data.begin(), |
| 765 | + data.end() - data.begin()); |
| 766 | + writeOutputToConsole(compileRequest, assembly); |
| 767 | + } |
| 768 | + break; |
| 769 | + #endif |
| 770 | + |
706 | 771 | case CodeGenTarget::SPIRV:
|
707 | 772 | {
|
708 | 773 | String assembly = dissassembleSPIRV(compileRequest,
|
@@ -943,6 +1008,20 @@ namespace Slang
|
943 | 1008 | }
|
944 | 1009 | break;
|
945 | 1010 | #endif
|
| 1011 | + |
| 1012 | + #if SLANG_ENABLE_DXIL_SUPPORT |
| 1013 | + case CodeGenTarget::DXILAssembly: |
| 1014 | + dumpIntermediateText(compileRequest, data, size, ".dxil.asm"); |
| 1015 | + break; |
| 1016 | + |
| 1017 | + case CodeGenTarget::DXIL: |
| 1018 | + dumpIntermediateBinary(compileRequest, data, size, ".dxil"); |
| 1019 | + { |
| 1020 | + String dxilAssembly = dissassembleDXILUsingDXC(compileRequest, data, size); |
| 1021 | + dumpIntermediateText(compileRequest, dxilAssembly.begin(), dxilAssembly.Length(), ".dxil.asm"); |
| 1022 | + } |
| 1023 | + break; |
| 1024 | + #endif |
946 | 1025 | }
|
947 | 1026 | }
|
948 | 1027 |
|
|
0 commit comments