Skip to content

Commit b623864

Browse files
committed
2 parents b475415 + ec41631 commit b623864

10 files changed

+773
-4
lines changed

external/dxc/dxcapi.h

+368
Large diffs are not rendered by default.

slang.h

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ extern "C"
8989
SLANG_SPIRV_ASM,
9090
SLANG_DXBC,
9191
SLANG_DXBC_ASM,
92+
SLANG_DXIL,
93+
SLANG_DXIL_ASM,
9294
};
9395

9496
/* A "container format" describes the way that the outputs
@@ -1079,6 +1081,7 @@ namespace slang
10791081
#include "source/core/text-io.cpp"
10801082
#include "source/slang/bytecode.cpp"
10811083
#include "source/slang/diagnostics.cpp"
1084+
#include "source/slang/dxc-support.cpp"
10821085
#include "source/slang/emit.cpp"
10831086
#include "source/slang/ir.cpp"
10841087
#include "source/slang/lexer.cpp"

source/slang/compiler.cpp

+81-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "reflection.h"
1616
#include "emit.h"
1717

18-
// Enable calling through to `fxc` to
18+
// Enable calling through to `fxc` or `dxc` to
1919
// generate code on Windows.
2020
#ifdef _WIN32
2121
#define WIN32_LEAN_AND_MEAN
@@ -27,12 +27,18 @@
2727
#ifndef SLANG_ENABLE_DXBC_SUPPORT
2828
#define SLANG_ENABLE_DXBC_SUPPORT 1
2929
#endif
30+
#ifndef SLANG_ENABLE_DXIL_SUPPORT
31+
#define SLANG_ENABLE_DXIL_SUPPORT 1
32+
#endif
3033
#endif
3134
//
32-
// Otherwise, don't enable DXBC by default:
35+
// Otherwise, don't enable DXBC/DXIL by default:
3336
#ifndef SLANG_ENABLE_DXBC_SUPPORT
3437
#define SLANG_ENABLE_DXBC_SUPPORT 0
3538
#endif
39+
#ifndef SLANG_ENABLE_DXIL_SUPPORT
40+
#define SLANG_ENABLE_DXIL_SUPPORT 0
41+
#endif
3642

3743
// Enable calling through to `glslang` on
3844
// all platforms.
@@ -356,6 +362,22 @@ namespace Slang
356362
}
357363
#endif
358364

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+
359381
#if SLANG_ENABLE_GLSLANG_SUPPORT
360382

361383
SharedLibrary loadGLSLCompilerDLL(CompileRequest* request)
@@ -540,6 +562,38 @@ namespace Slang
540562
break;
541563
#endif
542564

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+
543597
case CodeGenTarget::SPIRV:
544598
{
545599
List<uint8_t> code = emitSPIRVForEntryPoint(entryPoint, targetReq);
@@ -703,6 +757,17 @@ namespace Slang
703757
break;
704758
#endif
705759

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+
706771
case CodeGenTarget::SPIRV:
707772
{
708773
String assembly = dissassembleSPIRV(compileRequest,
@@ -943,6 +1008,20 @@ namespace Slang
9431008
}
9441009
break;
9451010
#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
9461025
}
9471026
}
9481027

source/slang/compiler.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ namespace Slang
4747
SPIRVAssembly = SLANG_SPIRV_ASM,
4848
DXBytecode = SLANG_DXBC,
4949
DXBytecodeAssembly = SLANG_DXBC_ASM,
50+
DXIL = SLANG_DXIL,
51+
DXILAssembly = SLANG_DXIL_ASM,
5052
};
5153

5254
enum class ContainerFormat
@@ -126,8 +128,9 @@ namespace Slang
126128
enum class PassThroughMode : SlangPassThrough
127129
{
128130
None = SLANG_PASS_THROUGH_NONE, // don't pass through: use Slang compiler
129-
HLSL = SLANG_PASS_THROUGH_FXC, // pass through HLSL to `D3DCompile` API
130-
// GLSL, // pass through GLSL to `glslang` library
131+
fxc = SLANG_PASS_THROUGH_FXC, // pass through HLSL to `D3DCompile` API
132+
dxc = SLANG_PASS_THROUGH_DXC, // pass through HLSL to `IDxcCompiler` API
133+
glslang = SLANG_PASS_THROUGH_GLSLANG, // pass through GLSL to `glslang` library
131134
};
132135

133136
class SourceFile;

0 commit comments

Comments
 (0)