Skip to content

Commit 4d20fd3

Browse files
authored
Refactor compiler option representations. (shader-slang#3598)
* Refactor compiler option representation. * Fix binary compatibility. * Add a test for specifying compiler options at link time. * Fix binary compatibility. * Fix binary compatibility. * Fix backward compatibility on matrix layout. * Fix. * Fix. * Fix. * Fix gfx. * Fix gfx. * Fix dynamic dispatch. * Polish.
1 parent 8e9b61e commit 4d20fd3

File tree

125 files changed

+2307
-1399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+2307
-1399
lines changed

build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@
304304
<ClCompile Include="..\..\..\tools\gfx-unit-test\gfx-test-util.cpp" />
305305
<ClCompile Include="..\..\..\tools\gfx-unit-test\instanced-draw-tests.cpp" />
306306
<ClCompile Include="..\..\..\tools\gfx-unit-test\link-time-constant.cpp" />
307+
<ClCompile Include="..\..\..\tools\gfx-unit-test\link-time-options.cpp" />
307308
<ClCompile Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.cpp" />
308309
<ClCompile Include="..\..\..\tools\gfx-unit-test\nested-parameter-block.cpp" />
309310
<ClCompile Include="..\..\..\tools\gfx-unit-test\precompiled-module-2.cpp" />
@@ -327,6 +328,7 @@
327328
<None Include="..\..\..\tools\gfx-unit-test\format-test-shaders.slang" />
328329
<None Include="..\..\..\tools\gfx-unit-test\graphics-smoke.slang" />
329330
<None Include="..\..\..\tools\gfx-unit-test\link-time-constant.slang" />
331+
<None Include="..\..\..\tools\gfx-unit-test\link-time-options.slang" />
330332
<None Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.slang" />
331333
<None Include="..\..\..\tools\gfx-unit-test\nested-parameter-block.slang" />
332334
<None Include="..\..\..\tools\gfx-unit-test\precompiled-module-imported.slang" />

build/visual-studio/gfx-unit-test-tool/gfx-unit-test-tool.vcxproj.filters

+6
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
<ClCompile Include="..\..\..\tools\gfx-unit-test\link-time-constant.cpp">
6969
<Filter>Source Files</Filter>
7070
</ClCompile>
71+
<ClCompile Include="..\..\..\tools\gfx-unit-test\link-time-options.cpp">
72+
<Filter>Source Files</Filter>
73+
</ClCompile>
7174
<ClCompile Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.cpp">
7275
<Filter>Source Files</Filter>
7376
</ClCompile>
@@ -133,6 +136,9 @@
133136
<None Include="..\..\..\tools\gfx-unit-test\link-time-constant.slang">
134137
<Filter>Source Files</Filter>
135138
</None>
139+
<None Include="..\..\..\tools\gfx-unit-test\link-time-options.slang">
140+
<Filter>Source Files</Filter>
141+
</None>
136142
<None Include="..\..\..\tools\gfx-unit-test\mutable-shader-object.slang">
137143
<Filter>Source Files</Filter>
138144
</None>

build/visual-studio/slang/slang.vcxproj

+2
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla
328328
<ClInclude Include="..\..\..\source\slang\slang-capability.h" />
329329
<ClInclude Include="..\..\..\source\slang\slang-check-impl.h" />
330330
<ClInclude Include="..\..\..\source\slang\slang-check.h" />
331+
<ClInclude Include="..\..\..\source\slang\slang-compiler-options.h" />
331332
<ClInclude Include="..\..\..\source\slang\slang-compiler.h" />
332333
<ClInclude Include="..\..\..\source\slang\slang-container-pool.h" />
333334
<ClInclude Include="..\..\..\source\slang\slang-content-assist-info.h" />
@@ -553,6 +554,7 @@ IF EXIST ..\..\..\external\slang-glslang\bin\windows-aarch64\release\slang-glsla
553554
<ClCompile Include="..\..\..\source\slang\slang-check-stmt.cpp" />
554555
<ClCompile Include="..\..\..\source\slang\slang-check-type.cpp" />
555556
<ClCompile Include="..\..\..\source\slang\slang-check.cpp" />
557+
<ClCompile Include="..\..\..\source\slang\slang-compiler-options.cpp" />
556558
<ClCompile Include="..\..\..\source\slang\slang-compiler.cpp" />
557559
<ClCompile Include="..\..\..\source\slang\slang-container-pool.cpp" />
558560
<ClCompile Include="..\..\..\source\slang\slang-diagnostics.cpp" />

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

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
<ClInclude Include="..\..\..\source\slang\slang-check.h">
7373
<Filter>Header Files</Filter>
7474
</ClInclude>
75+
<ClInclude Include="..\..\..\source\slang\slang-compiler-options.h">
76+
<Filter>Header Files</Filter>
77+
</ClInclude>
7578
<ClInclude Include="..\..\..\source\slang\slang-compiler.h">
7679
<Filter>Header Files</Filter>
7780
</ClInclude>
@@ -743,6 +746,9 @@
743746
<ClCompile Include="..\..\..\source\slang\slang-check.cpp">
744747
<Filter>Source Files</Filter>
745748
</ClCompile>
749+
<ClCompile Include="..\..\..\source\slang\slang-compiler-options.cpp">
750+
<Filter>Source Files</Filter>
751+
</ClCompile>
746752
<ClCompile Include="..\..\..\source\slang\slang-compiler.cpp">
747753
<Filter>Source Files</Filter>
748754
</ClCompile>

slang-gfx.h

+12
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,18 @@ class IDevice : public ISlangUnknown
25802580
const ITextureResource::Desc& desc, Size* outSize, Size* outAlignment) = 0;
25812581

25822582
virtual SLANG_NO_THROW Result SLANG_MCALL getTextureRowAlignment(Size* outAlignment) = 0;
2583+
2584+
virtual SLANG_NO_THROW Result SLANG_MCALL createShaderObject2(
2585+
slang::ISession* slangSession,
2586+
slang::TypeReflection* type,
2587+
ShaderObjectContainerType container,
2588+
IShaderObject** outObject) = 0;
2589+
2590+
virtual SLANG_NO_THROW Result SLANG_MCALL createMutableShaderObject2(
2591+
slang::ISession* slangSession,
2592+
slang::TypeReflection* type,
2593+
ShaderObjectContainerType container,
2594+
IShaderObject** outObject) = 0;
25832595
};
25842596

25852597
#define SLANG_UUID_IDevice \

slang.h

+199-12
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,155 @@ extern "C"
824824
SLANG_OPTIMIZATION_LEVEL_MAXIMAL, /**< Include optimizations that may take a very long time, or may involve severe space-vs-speed tradeoffs */
825825
};
826826

827+
// All compiler option names supported by Slang.
828+
namespace slang
829+
{
830+
enum class CompilerOptionName
831+
{
832+
MacroDefine, // stringValue0: macro name; stringValue1: macro value
833+
DepFile,
834+
EntryPointName,
835+
Specialize,
836+
Help,
837+
HelpStyle,
838+
Include, // stringValue: additional include path.
839+
Language,
840+
MatrixLayoutColumn, // bool
841+
MatrixLayoutRow, // bool
842+
ModuleName, // stringValue0: module name.
843+
Output,
844+
Profile, // intValue0: profile
845+
Stage, // intValue0: stage
846+
Target, // intValue0: CodeGenTarget
847+
Version,
848+
WarningsAsErrors, // stringValue0: "all" or comma separated list of warning codes or names.
849+
DisableWarnings, // stringValue0: comma separated list of warning codes or names.
850+
EnableWarning, // stringValue0: warning code or name.
851+
DisableWarning, // stringValue0: warning code or name.
852+
DumpWarningDiagnostics,
853+
InputFilesRemain,
854+
EmitIr, // bool
855+
ReportDownstreamTime, // bool
856+
ReportPerfBenchmark, // bool
857+
SkipSPIRVValidation, // bool
858+
859+
SourceEmbedStyle,
860+
SourceEmbedName,
861+
SourceEmbedLanguage,
862+
863+
// Target
864+
865+
Capability, // intValue0: CapabilityName
866+
DefaultImageFormatUnknown, // bool
867+
DisableDynamicDispatch, // bool
868+
DisableSpecialization, // bool
869+
FloatingPointMode, // intValue0: FloatingPointMode
870+
DebugInformation, // intValue0: DebugInfoLevel
871+
LineDirectiveMode,
872+
Optimization, // intValue0: OptimizationLevel
873+
Obfuscate, // bool
874+
875+
VulkanBindShift, // intValue0 (lower 8 bits): kind; intValue0(higher bits): set; intValue1: shift
876+
VulkanBindGlobals, // intValue0: index; intValue1: set
877+
VulkanInvertY, // bool
878+
VulkanUseEntryPointName, // bool
879+
VulkanUseGLLayout, // bool
880+
VulkanEmitReflection, // bool
881+
882+
GLSLForceScalarLayout, // bool
883+
EnableEffectAnnotations, // bool
884+
885+
EmitSpirvViaGLSL, // bool
886+
EmitSpirvDirectly, // bool
887+
SPIRVCoreGrammarJSON, // stringValue0: json path
888+
889+
// Downstream
890+
891+
CompilerPath,
892+
DefaultDownstreamCompiler,
893+
DownstreamArgs, // stringValue0: downstream compiler name. stringValue1: argument list, one per line.
894+
PassThrough,
895+
896+
// Repro
897+
898+
DumpRepro,
899+
DumpReproOnError,
900+
ExtractRepro,
901+
LoadRepro,
902+
LoadReproDirectory,
903+
ReproFallbackDirectory,
904+
905+
// Debugging
906+
907+
DumpAst,
908+
DumpIntermediatePrefix,
909+
DumpIntermediates, // bool
910+
DumpIr, // bool
911+
DumpIrIds,
912+
PreprocessorOutput,
913+
OutputIncludes,
914+
ReproFileSystem,
915+
SerialIr, // bool
916+
SkipCodeGen, // bool
917+
ValidateIr, // bool
918+
VerbosePaths,
919+
VerifyDebugSerialIr,
920+
NoCodeGen, // Not used.
921+
922+
// Experimental
923+
924+
FileSystem,
925+
Heterogeneous,
926+
NoMangle,
927+
AllowGLSL,
928+
929+
// Internal
930+
931+
ArchiveType,
932+
CompileStdLib,
933+
Doc,
934+
IrCompression,
935+
LoadStdLib,
936+
ReferenceModule,
937+
SaveStdLib,
938+
SaveStdLibBinSource,
939+
TrackLiveness,
940+
941+
// Deprecated
942+
ParameterBlocksUseRegisterSpaces,
943+
944+
CountOfParsableOptions,
945+
946+
// Used in parsed options only.
947+
DebugInformationFormat, // intValue0: DebugInfoFormat
948+
VulkanBindShiftAll, // intValue0: kind; intValue1: shift
949+
GenerateWholeProgram, // bool
950+
951+
CountOf,
952+
};
953+
954+
enum class CompilerOptionValueKind
955+
{
956+
Int,
957+
String
958+
};
959+
960+
struct CompilerOptionValue
961+
{
962+
CompilerOptionValueKind kind = CompilerOptionValueKind::Int;
963+
int32_t intValue0 = 0;
964+
int32_t intValue1 = 0;
965+
const char* stringValue0 = nullptr;
966+
const char* stringValue1 = nullptr;
967+
};
968+
969+
struct CompilerOptionEntry
970+
{
971+
CompilerOptionName name;
972+
CompilerOptionValue value;
973+
};
974+
}
975+
827976
/** A result code for a Slang API operation.
828977
829978
This type is generally compatible with the Windows API `HRESULT` type. In particular, negative values indicate
@@ -2433,9 +2582,16 @@ extern "C"
24332582
SLANG_API SlangReflectionVariableLayout* spReflection_getGlobalParamsVarLayout(
24342583
SlangReflection* reflection);
24352584

2585+
}
24362586
#ifdef __cplusplus
2587+
2588+
namespace slang
2589+
{
2590+
struct ISession;
24372591
}
24382592

2593+
SLANG_API slang::ISession* spReflection_GetSession(SlangReflection* reflection);
2594+
24392595
/* Helper interfaces for C++ users */
24402596
namespace slang
24412597
{
@@ -3239,6 +3395,11 @@ namespace slang
32393395
return spReflection_GetTypeParameterCount((SlangReflection*) this);
32403396
}
32413397

3398+
slang::ISession* getSession()
3399+
{
3400+
return spReflection_GetSession((SlangReflection*)this);
3401+
}
3402+
32423403
TypeParameterReflection* getTypeParameterByIndex(unsigned index)
32433404
{
32443405
return (TypeParameterReflection*)spReflection_GetTypeParameterByIndex((SlangReflection*) this, index);
@@ -3350,7 +3511,6 @@ namespace slang
33503511
struct ITypeConformance;
33513512
struct IGlobalSession;
33523513
struct IModule;
3353-
struct ISession;
33543514

33553515
struct SessionDesc;
33563516
struct SpecializationArg;
@@ -3564,6 +3724,16 @@ namespace slang
35643724
*/
35653725
virtual SLANG_NO_THROW SlangResult SLANG_MCALL setSPIRVCoreGrammar(
35663726
char const* jsonPath) = 0;
3727+
3728+
/** Parse slangc command line options into a SessionDesc that can be used to create a session
3729+
* with all the compiler options specified in the command line.
3730+
* @param argc The number of command line arguments.
3731+
* @param argv An input array of command line arguments to parse.
3732+
* @param outSessionDesc A pointer to a SessionDesc struct to receive parsed session desc.
3733+
* @param outAuxAllocation Auxillary memory allocated to hold data used in the sesion desc.
3734+
*/
3735+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL parseCommandLineArguments(
3736+
int argc, const char* const* argv, SessionDesc* outSessionDesc, ISlangUnknown** outAuxAllocation) = 0;
35673737
};
35683738

35693739
#define SLANG_UUID_IGlobalSession IGlobalSession::getTypeGuid()
@@ -4215,22 +4385,21 @@ namespace slang
42154385
/** Whether to force `scalar` layout for glsl shader storage buffers.
42164386
*/
42174387
bool forceGLSLScalarBufferLayout = false;
4388+
4389+
/** Pointer to an array of compiler option entries, whose size is compilerOptionEntryCount.
4390+
*/
4391+
CompilerOptionEntry* compilerOptionEntries = nullptr;
4392+
4393+
/** Number of additional compiler option entries.
4394+
*/
4395+
uint32_t compilerOptionEntryCount = 0;
4396+
42184397
};
42194398

42204399
typedef uint32_t SessionFlags;
42214400
enum
42224401
{
4223-
kSessionFlags_None = 0,
4224-
4225-
/** Use application-specific policy for semantics of the `shared` keyword.
4226-
4227-
This is a legacy/compatibility flag to help an existing Slang client
4228-
migrate to new language features, and should *not* be used by other
4229-
clients. This feature may be removed in a future release without a
4230-
deprecation warning, and this bit may be re-used for another feature.
4231-
You have been warned.
4232-
*/
4233-
kSessionFlag_FalcorCustomSharedKeywordSemantics = 1 << 0,
4402+
kSessionFlags_None = 0
42344403
};
42354404

42364405
struct PreprocessorMacroDesc
@@ -4270,6 +4439,15 @@ namespace slang
42704439

42714440
bool enableEffectAnnotations = false;
42724441
bool allowGLSLSyntax = false;
4442+
4443+
/** Pointer to an array of compiler option entries, whose size is compilerOptionEntryCount.
4444+
*/
4445+
CompilerOptionEntry* compilerOptionEntries = nullptr;
4446+
4447+
/** Number of additional compiler option entries.
4448+
*/
4449+
uint32_t compilerOptionEntryCount = 0;
4450+
42734451
};
42744452

42754453
enum class ContainerType
@@ -4657,6 +4835,15 @@ namespace slang
46574835
*/
46584836
virtual SLANG_NO_THROW SlangResult SLANG_MCALL renameEntryPoint(
46594837
const char* newName, IComponentType** outEntryPoint) = 0;
4838+
4839+
/** Link and specify additional compiler options when generating code
4840+
* from the linked program.
4841+
*/
4842+
virtual SLANG_NO_THROW SlangResult SLANG_MCALL linkWithOptions(
4843+
IComponentType** outLinkedComponentType,
4844+
uint32_t compilerOptionEntryCount,
4845+
CompilerOptionEntry* compilerOptionEntries,
4846+
ISlangBlob** outDiagnostics = nullptr) = 0;
46604847
};
46614848
#define SLANG_UUID_IComponentType IComponentType::getTypeGuid()
46624849

0 commit comments

Comments
 (0)