Skip to content

Commit 515d8eb

Browse files
authored
Merge branch 'master' into feature/prelude-fix
2 parents e2d2102 + aa6aca4 commit 515d8eb

39 files changed

+640
-342
lines changed

examples/cpu-hello-world/main.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ static SlangResult _innerMain(int argc, char** argv)
6161
// directory called 'slang-cpp-prelude.h'.
6262
//
6363
// We need to tell slang either the contents of the prelude, or suitable include/s
64-
// that will work. The actual API call to set the prelude is `setDownstreamCompilerPrelude`
65-
// and this just sets for a specific backend a bit of text placed before generated code.
64+
// that will work. The actual API call to set the prelude is `setPrelude`
65+
// and this just sets for a specific language a bit of text placed before generated code.
6666
//
6767
// Most downstream C++ compilers work on files. In that case slang may generate temporary
6868
// files that contain the generated code. Typically the generated files will not be in the
@@ -184,7 +184,7 @@ static SlangResult _innerMain(int argc, char** argv)
184184
// We don't have any entry point parameters so that's passed as NULL
185185
// We need to cast our definition of the uniform state to the undefined CPPPrelude::UniformState as
186186
// that type is just a name to indicate what kind of thing needs to be passed in.
187-
func(&varyingInput, NULL, (CPPPrelude::UniformState*)&uniformState);
187+
func(&varyingInput, NULL, &uniformState);
188188

189189
// bufferContents holds the output
190190

prelude/slang-cpp-prelude.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,4 @@
4949
# define SLANG_UNROLL
5050
#endif
5151

52-
#endif
53-
54-
struct Context;
52+
#endif

prelude/slang-cpp-types.h

+4-7
Original file line numberDiff line numberDiff line change
@@ -822,14 +822,11 @@ struct ComputeVaryingInput
822822
uint3 endGroupID; ///< Non inclusive end groupID
823823
};
824824

825-
/* Type that defines the uniform entry point params. The actual content of this type is dependent on the entry point parameters, and can be
826-
found via reflection or defined such that it matches the shader appropriately.
827-
*/
828-
struct UniformEntryPointParams;
829-
struct UniformState;
825+
// The uniformEntryPointParams and uniformState must be set to structures that match layout that the kernel expects.
826+
// This can be determined via reflection for example.
830827

831-
typedef void(*ComputeThreadFunc)(ComputeThreadVaryingInput* varyingInput, UniformEntryPointParams* uniformEntryPointParams, UniformState* uniformState);
832-
typedef void(*ComputeFunc)(ComputeVaryingInput* varyingInput, UniformEntryPointParams* uniformEntryPointParams, UniformState* uniformState);
828+
typedef void(*ComputeThreadFunc)(ComputeThreadVaryingInput* varyingInput, void* uniformEntryPointParams, void* uniformState);
829+
typedef void(*ComputeFunc)(ComputeVaryingInput* varyingInput, void* uniformEntryPointParams, void* uniformState);
833830

834831
#ifdef SLANG_PRELUDE_NAMESPACE
835832
}

slang.h

+25-2
Original file line numberDiff line numberDiff line change
@@ -2862,7 +2862,9 @@ namespace slang
28622862
SlangPassThrough passThrough,
28632863
char const* path) = 0;
28642864

2865-
/** Set the 'prelude' for generated code for a 'downstream compiler'.
2865+
/** DEPRECIATED: Use setLanguagePrelude
2866+
2867+
Set the 'prelude' for generated code for a 'downstream compiler'.
28662868
@param passThrough The downstream compiler for generated code that will have the prelude applied to it.
28672869
@param preludeText The text added pre-pended verbatim before the generated source
28682870
@@ -2872,7 +2874,9 @@ namespace slang
28722874
SlangPassThrough passThrough,
28732875
const char* preludeText) = 0;
28742876

2875-
/** Get the 'prelude' for generated code for a 'downstream compiler'.
2877+
/** DEPRECIATED: Use getLanguagePrelude
2878+
2879+
Get the 'prelude' for generated code for a 'downstream compiler'.
28762880
@param passThrough The downstream compiler for generated code that will have the prelude applied to it.
28772881
@param outPrelude On exit holds a blob that holds the string of the prelude.
28782882
*/
@@ -2909,6 +2913,25 @@ namespace slang
29092913
@return The downstream compiler for that source language */
29102914
virtual SlangPassThrough SLANG_MCALL getDefaultDownstreamCompiler(
29112915
SlangSourceLanguage sourceLanguage) = 0;
2916+
2917+
/* Set the 'prelude' placed before generated code for a specific language type.
2918+
2919+
@param sourceLanguage The language the prelude should be inserted on.
2920+
@param preludeText The text added pre-pended verbatim before the generated source
2921+
2922+
Note! That for pass-through usage, prelude is not pre-pended, preludes are for code generation only.
2923+
*/
2924+
virtual SLANG_NO_THROW void SLANG_MCALL setLanguagePrelude(
2925+
SlangSourceLanguage sourceLanguage,
2926+
const char* preludeText) = 0;
2927+
2928+
/** Get the 'prelude' associated with a specific source language.
2929+
@param sourceLanguage The language the prelude should be inserted on.
2930+
@param outPrelude On exit holds a blob that holds the string of the prelude.
2931+
*/
2932+
virtual SLANG_NO_THROW void SLANG_MCALL getLanguagePrelude(
2933+
SlangSourceLanguage sourceLanguage,
2934+
ISlangBlob** outPrelude) = 0;
29122935
};
29132936

29142937
#define SLANG_UUID_IGlobalSession { 0xc140b5fd, 0xc78, 0x452e, { 0xba, 0x7c, 0x1a, 0x1e, 0x70, 0xc7, 0xf7, 0x1c } };

source/core/slang-test-tool-util.cpp

+2-19
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,19 @@ static SlangResult _addCPPPrelude(const String& parentPath, slang::IGlobalSessio
5959
{
6060
String includePath;
6161
SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cpp-prelude.h", includePath));
62-
6362
StringBuilder prelude;
6463
prelude << "#include \"" << includePath << "\"\n\n";
65-
const SlangPassThrough downstreamCompilers[] = {
66-
SLANG_PASS_THROUGH_CLANG, ///< Clang C/C++ compiler
67-
SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio C/C++ compiler
68-
SLANG_PASS_THROUGH_GCC, ///< GCC C/C++ compiler
69-
SLANG_PASS_THROUGH_GENERIC_C_CPP,
70-
};
71-
for (auto downstreamCompiler : downstreamCompilers)
72-
{
73-
session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
74-
}
64+
session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CPP, prelude.getBuffer());
7565
return SLANG_OK;
7666
}
7767

7868
static SlangResult _addCUDAPrelude(const String& parentPath, slang::IGlobalSession* session)
7969
{
8070
String includePath;
8171
SLANG_RETURN_ON_FAIL(_calcIncludePath(parentPath, "../../../prelude/slang-cuda-prelude.h", includePath));
82-
8372
StringBuilder prelude;
8473
prelude << "#include \"" << includePath << "\"\n\n";
85-
const SlangPassThrough downstreamCompilers[] = {
86-
SLANG_PASS_THROUGH_NVRTC, ///< nvrtc CUDA compiler
87-
};
88-
for (auto downstreamCompiler : downstreamCompilers)
89-
{
90-
session->setDownstreamCompilerPrelude(downstreamCompiler, prelude.getBuffer());
91-
}
74+
session->setLanguagePrelude(SLANG_SOURCE_LANGUAGE_CUDA, prelude.getBuffer());
9275
return SLANG_OK;
9376
}
9477

source/slang/slang-check-shader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ namespace Slang
544544
auto entryPointProfile = entryPointReq->getProfile();
545545
if( auto entryPointAttribute = entryPointFuncDecl->findModifier<EntryPointAttribute>() )
546546
{
547-
auto entryPointStage = entryPointProfile.GetStage();
547+
auto entryPointStage = entryPointProfile.getStage();
548548
if( entryPointStage == Stage::Unknown )
549549
{
550550
entryPointProfile.setStage(entryPointAttribute->stage);

source/slang/slang-compiler.cpp

+46-49
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ namespace Slang
320320

321321
//
322322

323-
Profile Profile::LookUp(char const* name)
323+
Profile Profile::lookUp(char const* name)
324324
{
325325
#define PROFILE(TAG, NAME, STAGE, VERSION) if(strcmp(name, #NAME) == 0) return Profile::TAG;
326326
#define PROFILE_ALIAS(TAG, DEF, NAME) if(strcmp(name, #NAME) == 0) return Profile::TAG;
@@ -408,36 +408,58 @@ namespace Slang
408408
return session->getOrLoadDownstreamCompiler(passThrough, nullptr) ? SLANG_OK: SLANG_E_NOT_FOUND;
409409
}
410410

411-
PassThroughMode getPreludeDownstreamCompilerForTarget(Session* session, CodeGenTarget target)
411+
SourceLanguage getDefaultSourceLanguageForDownstreamCompiler(PassThroughMode compiler)
412412
{
413-
switch (target)
413+
switch (compiler)
414414
{
415-
case CodeGenTarget::None:
415+
case PassThroughMode::None:
416416
{
417-
return PassThroughMode::None;
417+
return SourceLanguage::Unknown;
418418
}
419-
case CodeGenTarget::GLSL:
419+
case PassThroughMode::Fxc:
420+
case PassThroughMode::Dxc:
420421
{
421-
// For the prelude we'll use Glslang
422-
return PassThroughMode::Glslang;
422+
return SourceLanguage::HLSL;
423423
}
424-
case CodeGenTarget::HLSL:
424+
case PassThroughMode::Glslang:
425425
{
426-
// Use the default compiler for the source language if set,
427-
DownstreamCompiler* downstreamCompiler = session->getDefaultDownstreamCompiler(SourceLanguage::HLSL);
428-
if (downstreamCompiler)
429-
{
430-
return PassThroughMode(downstreamCompiler->getDesc().type);
431-
}
432-
else
433-
{
434-
// This is ambiguous, because we could use dxc or fxc. For now we'll go with Dxc.
435-
return PassThroughMode::Dxc;
436-
}
426+
return SourceLanguage::GLSL;
427+
}
428+
case PassThroughMode::Clang:
429+
case PassThroughMode::VisualStudio:
430+
case PassThroughMode::Gcc:
431+
case PassThroughMode::GenericCCpp:
432+
{
433+
// These could ingest C, but we only have this function to work out a
434+
// 'default' language to ingest.
435+
return SourceLanguage::CPP;
437436
}
437+
case PassThroughMode::NVRTC:
438+
{
439+
return SourceLanguage::CUDA;
440+
}
441+
default: break;
442+
}
443+
SLANG_ASSERT(!"Unknown compiler");
444+
return SourceLanguage::Unknown;
445+
}
446+
447+
PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target)
448+
{
449+
switch (target)
450+
{
451+
// Don't *require* a downstream compiler for source output
452+
case CodeGenTarget::GLSL:
453+
case CodeGenTarget::HLSL:
438454
case CodeGenTarget::CUDASource:
455+
case CodeGenTarget::CPPSource:
456+
case CodeGenTarget::CSource:
439457
{
440-
return PassThroughMode::NVRTC;
458+
return PassThroughMode::None;
459+
}
460+
case CodeGenTarget::None:
461+
{
462+
return PassThroughMode::None;
441463
}
442464
case CodeGenTarget::SPIRVAssembly:
443465
case CodeGenTarget::SPIRV:
@@ -459,12 +481,6 @@ namespace Slang
459481
{
460482
return PassThroughMode::Glslang;
461483
}
462-
case CodeGenTarget::CPPSource:
463-
case CodeGenTarget::CSource:
464-
{
465-
// We'll just use the generic C/C++ compiler
466-
return PassThroughMode::GenericCCpp;
467-
}
468484
case CodeGenTarget::HostCallable:
469485
case CodeGenTarget::SharedLibrary:
470486
case CodeGenTarget::Executable:
@@ -484,28 +500,9 @@ namespace Slang
484500
return PassThroughMode::None;
485501
}
486502

487-
PassThroughMode getDownstreamCompilerRequiredForTarget(Session* session, CodeGenTarget target)
488-
{
489-
switch (target)
490-
{
491-
// Don't *require* a downstream compiler for source output
492-
case CodeGenTarget::GLSL:
493-
case CodeGenTarget::HLSL:
494-
case CodeGenTarget::CUDASource:
495-
case CodeGenTarget::CPPSource:
496-
case CodeGenTarget::CSource:
497-
{
498-
return PassThroughMode::None;
499-
}
500-
default: break;
501-
}
502-
503-
return getPreludeDownstreamCompilerForTarget(session, target);
504-
}
505-
506503
SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target)
507504
{
508-
const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(session, target);
505+
const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target);
509506
return (mode != PassThroughMode::None) ?
510507
checkExternalCompilerSupport(session, mode) :
511508
SLANG_OK;
@@ -634,7 +631,7 @@ namespace Slang
634631
}
635632

636633
char const* stagePrefix = nullptr;
637-
switch( profile.GetStage() )
634+
switch( profile.getStage() )
638635
{
639636
// Note: All of the raytracing-related stages require
640637
// compiling for a `lib_*` profile, even when only a
@@ -669,7 +666,7 @@ namespace Slang
669666
}
670667

671668
char const* versionSuffix = nullptr;
672-
switch(profile.GetVersion())
669+
switch(profile.getVersion())
673670
{
674671
#define CASE(TAG, SUFFIX) case ProfileVersion::TAG: versionSuffix = #SUFFIX; break
675672
CASE(DX_4_0, _4_0);

source/slang/slang-compiler.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ namespace Slang
180180
Name* getName() { return m_name; }
181181

182182
/// Get the stage that the entry point is to be compiled for
183-
Stage getStage() { return m_profile.GetStage(); }
183+
Stage getStage() { return m_profile.getStage(); }
184184

185185
/// Get the profile that the entry point is to be compiled for
186186
Profile getProfile() { return m_profile; }
@@ -725,7 +725,7 @@ namespace Slang
725725
Profile getProfile() { return m_profile; }
726726

727727
/// Get the stage that the entry point is for.
728-
Stage getStage() { return m_profile.GetStage(); }
728+
Stage getStage() { return m_profile.getStage(); }
729729

730730
/// Get the module that contains the entry point.
731731
Module* getModule();
@@ -1191,9 +1191,9 @@ namespace Slang
11911191
};
11921192

11931193
/// Given a target returns the required downstream compiler
1194-
PassThroughMode getDownstreamCompilerRequiredForTarget(Session* session, CodeGenTarget target);
1194+
PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target);
11951195
/// Given a target returns a downstream compiler the prelude should be taken from.
1196-
PassThroughMode getPreludeDownstreamCompilerForTarget(Session* session, CodeGenTarget target);
1196+
SourceLanguage getDefaultSourceLanguageForDownstreamCompiler(PassThroughMode compiler);
11971197

11981198
struct TypeCheckingCache;
11991199

@@ -2033,7 +2033,10 @@ namespace Slang
20332033

20342034
SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage) override;
20352035

2036-
/// Get the default cpp compiler for a language
2036+
SLANG_NO_THROW void SLANG_MCALL setLanguagePrelude(SlangSourceLanguage inSourceLanguage, char const* prelude) override;
2037+
SLANG_NO_THROW void SLANG_MCALL getLanguagePrelude(SlangSourceLanguage inSourceLanguage, ISlangBlob** outPrelude) override;
2038+
2039+
/// Get the default compiler for a language
20372040
DownstreamCompiler* getDefaultDownstreamCompiler(SourceLanguage sourceLanguage);
20382041

20392042
enum class SharedLibraryFuncType
@@ -2103,8 +2106,8 @@ namespace Slang
21032106

21042107
SlangFuncPtr getSharedLibraryFunc(SharedLibraryFuncType type, DiagnosticSink* sink);
21052108

2106-
/// Get the downstream compiler prelude
2107-
const String& getDownstreamCompilerPrelude(PassThroughMode mode) { return m_downstreamCompilerPreludes[int(mode)]; }
2109+
/// Get the prelude associated with the language
2110+
const String& getPreludeForLanguage(SourceLanguage language) { return m_languagePreludes[int(language)]; }
21082111

21092112
void init();
21102113

@@ -2128,12 +2131,11 @@ namespace Slang
21282131

21292132
SlangResult _loadRequest(EndToEndCompileRequest* request, const void* data, size_t size);
21302133

2131-
21322134
/// Linkage used for all built-in (stdlib) code.
21332135
RefPtr<Linkage> m_builtinLinkage;
21342136

2135-
String m_downstreamCompilerPaths[int(PassThroughMode::CountOf)]; ///< Paths for each pass through
2136-
String m_downstreamCompilerPreludes[int(PassThroughMode::CountOf)]; ///< Prelude for each type of target
2137+
String m_downstreamCompilerPaths[int(PassThroughMode::CountOf)]; ///< Paths for each pass through
2138+
String m_languagePreludes[int(SourceLanguage::CountOf)]; ///< Prelude for each source language
21372139
PassThroughMode m_defaultDownstreamCompilers[int(SourceLanguage::CountOf)];
21382140
};
21392141

source/slang/slang-dxc-support.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ namespace Slang
185185
// TODO: Ideally the dxc back-end should be passed some information
186186
// on the "capabilities" that were used and/or requested in the code.
187187
//
188-
if( profile.GetVersion() >= ProfileVersion::DX_6_2 )
188+
if( profile.getVersion() >= ProfileVersion::DX_6_2 )
189189
{
190190
args[argCount++] = L"-enable-16bit-types";
191191
}
@@ -195,7 +195,7 @@ namespace Slang
195195
ComPtr<IDxcOperationResult> dxcResult;
196196
SLANG_RETURN_ON_FAIL(dxcCompiler->Compile(dxcSourceBlob,
197197
sourcePath.toWString().begin(),
198-
profile.GetStage() == Stage::Unknown ? L"" : wideEntryPointName.begin(),
198+
profile.getStage() == Stage::Unknown ? L"" : wideEntryPointName.begin(),
199199
wideProfileName.begin(),
200200
args,
201201
argCount,

0 commit comments

Comments
 (0)