Skip to content

Commit 1856b8a

Browse files
authored
DXC as DownstreamCompiler (shader-slang#1845)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP Fxc as downstream compiler. * First pass FXC downstream compiler working. * GCC compile fix. * Fix FXC parsing issue. * Special case filesystem access. * Use StringUtil getSlice. * Fix isses with not emitting source for FXC. * WIP on DXC. * Small fixes for DXBC handling. * Removed DXC from ParseDiagnosticUtil (can use generic) Try to improve output for notes from DXC.
1 parent d4316c8 commit 1856b8a

13 files changed

+643
-575
lines changed

build/visual-studio/compiler-core/compiler-core.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
<ClInclude Include="..\..\..\source\compiler-core\slang-core-diagnostics.h" />
174174
<ClInclude Include="..\..\..\source\compiler-core\slang-diagnostic-sink.h" />
175175
<ClInclude Include="..\..\..\source\compiler-core\slang-downstream-compiler.h" />
176+
<ClInclude Include="..\..\..\source\compiler-core\slang-dxc-compiler.h" />
176177
<ClInclude Include="..\..\..\source\compiler-core\slang-fxc-compiler.h" />
177178
<ClInclude Include="..\..\..\source\compiler-core\slang-gcc-compiler-util.h" />
178179
<ClInclude Include="..\..\..\source\compiler-core\slang-include-system.h" />
@@ -192,6 +193,7 @@
192193
<ClCompile Include="..\..\..\source\compiler-core\slang-core-diagnostics.cpp" />
193194
<ClCompile Include="..\..\..\source\compiler-core\slang-diagnostic-sink.cpp" />
194195
<ClCompile Include="..\..\..\source\compiler-core\slang-downstream-compiler.cpp" />
196+
<ClCompile Include="..\..\..\source\compiler-core\slang-dxc-compiler.cpp" />
195197
<ClCompile Include="..\..\..\source\compiler-core\slang-fxc-compiler.cpp" />
196198
<ClCompile Include="..\..\..\source\compiler-core\slang-gcc-compiler-util.cpp" />
197199
<ClCompile Include="..\..\..\source\compiler-core\slang-include-system.cpp" />

build/visual-studio/compiler-core/compiler-core.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<ClInclude Include="..\..\..\source\compiler-core\slang-downstream-compiler.h">
1919
<Filter>Header Files</Filter>
2020
</ClInclude>
21+
<ClInclude Include="..\..\..\source\compiler-core\slang-dxc-compiler.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
2124
<ClInclude Include="..\..\..\source\compiler-core\slang-fxc-compiler.h">
2225
<Filter>Header Files</Filter>
2326
</ClInclude>
@@ -71,6 +74,9 @@
7174
<ClCompile Include="..\..\..\source\compiler-core\slang-downstream-compiler.cpp">
7275
<Filter>Source Files</Filter>
7376
</ClCompile>
77+
<ClCompile Include="..\..\..\source\compiler-core\slang-dxc-compiler.cpp">
78+
<Filter>Source Files</Filter>
79+
</ClCompile>
7480
<ClCompile Include="..\..\..\source\compiler-core\slang-fxc-compiler.cpp">
7581
<Filter>Source Files</Filter>
7682
</ClCompile>

build/visual-studio/slang/slang.vcxproj

-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@
333333
<ClCompile Include="..\..\..\source\slang\slang-diagnostics.cpp" />
334334
<ClCompile Include="..\..\..\source\slang\slang-doc-extractor.cpp" />
335335
<ClCompile Include="..\..\..\source\slang\slang-doc-markdown-writer.cpp" />
336-
<ClCompile Include="..\..\..\source\slang\slang-dxc-support.cpp" />
337336
<ClCompile Include="..\..\..\source\slang\slang-emit-c-like.cpp" />
338337
<ClCompile Include="..\..\..\source\slang\slang-emit-cpp.cpp" />
339338
<ClCompile Include="..\..\..\source\slang\slang-emit-cuda.cpp" />

build/visual-studio/slang/slang.vcxproj.filters

-3
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,6 @@
446446
<ClCompile Include="..\..\..\source\slang\slang-doc-markdown-writer.cpp">
447447
<Filter>Source Files</Filter>
448448
</ClCompile>
449-
<ClCompile Include="..\..\..\source\slang\slang-dxc-support.cpp">
450-
<Filter>Source Files</Filter>
451-
</ClCompile>
452449
<ClCompile Include="..\..\..\source\slang\slang-emit-c-like.cpp">
453450
<Filter>Source Files</Filter>
454451
</ClCompile>

source/compiler-core/slang-downstream-compiler.cpp

+22-19
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "slang-gcc-compiler-util.h"
2020
#include "slang-nvrtc-compiler.h"
2121
#include "slang-fxc-compiler.h"
22+
#include "slang-dxc-compiler.h"
2223

2324
namespace Slang
2425
{
@@ -158,6 +159,26 @@ Index DownstreamDiagnostics::getCountBySeverity(Diagnostic::Severity severity) c
158159
return count;
159160
}
160161

162+
void DownstreamDiagnostics::requireErrorDiagnostic()
163+
{
164+
// If we find an error, we don't need to add a generic diagnostic
165+
for (const auto& msg : diagnostics)
166+
{
167+
if (Index(msg.severity) >= Index(DownstreamDiagnostic::Severity::Error))
168+
{
169+
return;
170+
}
171+
}
172+
173+
DownstreamDiagnostic diagnostic;
174+
diagnostic.reset();
175+
diagnostic.severity = DownstreamDiagnostic::Severity::Error;
176+
diagnostic.text = "Generic error during compilation";
177+
178+
// Add the diagnostic
179+
diagnostics.add(diagnostic);
180+
}
181+
161182
Int DownstreamDiagnostics::countByStage(Diagnostic::Stage stage, Index counts[Int(Diagnostic::Severity::CountOf)]) const
162183
{
163184
Int count = 0;
@@ -655,24 +676,6 @@ const DownstreamCompiler::Desc& DownstreamCompilerUtil::getCompiledWithDesc()
655676
}
656677
}
657678

658-
static SlangResult _locateDXCCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set)
659-
{
660-
// First try dxil, so it's loaded from the same path if it's there
661-
ComPtr<ISlangSharedLibrary> dxil;
662-
DefaultSharedLibraryLoader::load(loader, path, "dxil", dxil.writeRef());
663-
664-
ComPtr<ISlangSharedLibrary> sharedLibrary;
665-
if (SLANG_SUCCEEDED(DefaultSharedLibraryLoader::load(loader, path, "dxcompiler", sharedLibrary.writeRef())))
666-
{
667-
// Can we determine the version?
668-
DownstreamCompiler::Desc desc(SLANG_PASS_THROUGH_DXC);
669-
RefPtr<DownstreamCompiler> compiler(new SharedLibraryDownstreamCompiler(desc, sharedLibrary));
670-
671-
set->addCompiler(compiler);
672-
}
673-
return SLANG_OK;
674-
}
675-
676679
static SlangResult _locateGlslangCompilers(const String& path, ISlangSharedLibraryLoader* loader, DownstreamCompilerSet* set)
677680
{
678681
#if SLANG_UNIX_FAMILY
@@ -697,7 +700,7 @@ static SlangResult _locateGlslangCompilers(const String& path, ISlangSharedLibra
697700
outFuncs[int(SLANG_PASS_THROUGH_CLANG)] = &GCCDownstreamCompilerUtil::locateClangCompilers;
698701
outFuncs[int(SLANG_PASS_THROUGH_GCC)] = &GCCDownstreamCompilerUtil::locateGCCCompilers;
699702
outFuncs[int(SLANG_PASS_THROUGH_NVRTC)] = &NVRTCDownstreamCompilerUtil::locateCompilers;
700-
outFuncs[int(SLANG_PASS_THROUGH_DXC)] = &_locateDXCCompilers;
703+
outFuncs[int(SLANG_PASS_THROUGH_DXC)] = &DXCDownstreamCompilerUtil::locateCompilers;
701704
outFuncs[int(SLANG_PASS_THROUGH_FXC)] = &FXCDownstreamCompilerUtil::locateCompilers;
702705
outFuncs[int(SLANG_PASS_THROUGH_GLSLANG)] = &_locateGlslangCompilers;
703706
}

source/compiler-core/slang-downstream-compiler.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ struct DownstreamDiagnostics
9393
/// Add a note
9494
void addNote(const UnownedStringSlice& in);
9595

96+
/// If there are no error diagnostics, adds a generic error diagnostic
97+
void requireErrorDiagnostic();
98+
9699
static void addNote(const UnownedStringSlice& in, List<DownstreamDiagnostic>& ioDiagnostics);
97100

98101
String rawDiagnostics;
@@ -219,15 +222,6 @@ class DownstreamCompiler: public RefObject
219222
Precise,
220223
};
221224

222-
#if 0
223-
enum TargetType
224-
{
225-
Executable, ///< Produce an executable
226-
SharedLibrary, ///< Produce a shared library object/dll
227-
Object, ///< Produce an object file
228-
};
229-
#endif
230-
231225
enum PipelineType
232226
{
233227
Unknown,
@@ -272,6 +266,7 @@ class DownstreamCompiler: public RefObject
272266
SlangSourceLanguage sourceLanguage = SLANG_SOURCE_LANGUAGE_CPP;
273267
FloatingPointMode floatingPointMode = FloatingPointMode::Default;
274268
PipelineType pipelineType = PipelineType::Unknown;
269+
SlangMatrixLayoutMode matrixLayout = SLANG_MATRIX_LAYOUT_MODE_UNKNOWN;
275270

276271
Flags flags = Flag::EnableExceptionHandling;
277272

0 commit comments

Comments
 (0)