summaryrefslogtreecommitdiff
path: root/slang.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-02-20 12:24:00 -0800
committerGitHub <noreply@github.com>2024-02-20 12:24:00 -0800
commit4d20fd329956ac89408b1628a8291fea01bc9a6d (patch)
tree8e62d9c1ec05142fd25d0b31073fdb56d44691b0 /slang.h
parent8e9b61e3bac69dbb37a1451b62302e688a017ced (diff)
Refactor compiler option representations. (#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.
Diffstat (limited to 'slang.h')
-rw-r--r--slang.h211
1 files changed, 199 insertions, 12 deletions
diff --git a/slang.h b/slang.h
index b9da7df41..8fad8fbc6 100644
--- a/slang.h
+++ b/slang.h
@@ -824,6 +824,155 @@ extern "C"
SLANG_OPTIMIZATION_LEVEL_MAXIMAL, /**< Include optimizations that may take a very long time, or may involve severe space-vs-speed tradeoffs */
};
+ // All compiler option names supported by Slang.
+ namespace slang
+ {
+ enum class CompilerOptionName
+ {
+ MacroDefine, // stringValue0: macro name; stringValue1: macro value
+ DepFile,
+ EntryPointName,
+ Specialize,
+ Help,
+ HelpStyle,
+ Include, // stringValue: additional include path.
+ Language,
+ MatrixLayoutColumn, // bool
+ MatrixLayoutRow, // bool
+ ModuleName, // stringValue0: module name.
+ Output,
+ Profile, // intValue0: profile
+ Stage, // intValue0: stage
+ Target, // intValue0: CodeGenTarget
+ Version,
+ WarningsAsErrors, // stringValue0: "all" or comma separated list of warning codes or names.
+ DisableWarnings, // stringValue0: comma separated list of warning codes or names.
+ EnableWarning, // stringValue0: warning code or name.
+ DisableWarning, // stringValue0: warning code or name.
+ DumpWarningDiagnostics,
+ InputFilesRemain,
+ EmitIr, // bool
+ ReportDownstreamTime, // bool
+ ReportPerfBenchmark, // bool
+ SkipSPIRVValidation, // bool
+
+ SourceEmbedStyle,
+ SourceEmbedName,
+ SourceEmbedLanguage,
+
+ // Target
+
+ Capability, // intValue0: CapabilityName
+ DefaultImageFormatUnknown, // bool
+ DisableDynamicDispatch, // bool
+ DisableSpecialization, // bool
+ FloatingPointMode, // intValue0: FloatingPointMode
+ DebugInformation, // intValue0: DebugInfoLevel
+ LineDirectiveMode,
+ Optimization, // intValue0: OptimizationLevel
+ Obfuscate, // bool
+
+ VulkanBindShift, // intValue0 (lower 8 bits): kind; intValue0(higher bits): set; intValue1: shift
+ VulkanBindGlobals, // intValue0: index; intValue1: set
+ VulkanInvertY, // bool
+ VulkanUseEntryPointName, // bool
+ VulkanUseGLLayout, // bool
+ VulkanEmitReflection, // bool
+
+ GLSLForceScalarLayout, // bool
+ EnableEffectAnnotations, // bool
+
+ EmitSpirvViaGLSL, // bool
+ EmitSpirvDirectly, // bool
+ SPIRVCoreGrammarJSON, // stringValue0: json path
+
+ // Downstream
+
+ CompilerPath,
+ DefaultDownstreamCompiler,
+ DownstreamArgs, // stringValue0: downstream compiler name. stringValue1: argument list, one per line.
+ PassThrough,
+
+ // Repro
+
+ DumpRepro,
+ DumpReproOnError,
+ ExtractRepro,
+ LoadRepro,
+ LoadReproDirectory,
+ ReproFallbackDirectory,
+
+ // Debugging
+
+ DumpAst,
+ DumpIntermediatePrefix,
+ DumpIntermediates, // bool
+ DumpIr, // bool
+ DumpIrIds,
+ PreprocessorOutput,
+ OutputIncludes,
+ ReproFileSystem,
+ SerialIr, // bool
+ SkipCodeGen, // bool
+ ValidateIr, // bool
+ VerbosePaths,
+ VerifyDebugSerialIr,
+ NoCodeGen, // Not used.
+
+ // Experimental
+
+ FileSystem,
+ Heterogeneous,
+ NoMangle,
+ AllowGLSL,
+
+ // Internal
+
+ ArchiveType,
+ CompileStdLib,
+ Doc,
+ IrCompression,
+ LoadStdLib,
+ ReferenceModule,
+ SaveStdLib,
+ SaveStdLibBinSource,
+ TrackLiveness,
+
+ // Deprecated
+ ParameterBlocksUseRegisterSpaces,
+
+ CountOfParsableOptions,
+
+ // Used in parsed options only.
+ DebugInformationFormat, // intValue0: DebugInfoFormat
+ VulkanBindShiftAll, // intValue0: kind; intValue1: shift
+ GenerateWholeProgram, // bool
+
+ CountOf,
+ };
+
+ enum class CompilerOptionValueKind
+ {
+ Int,
+ String
+ };
+
+ struct CompilerOptionValue
+ {
+ CompilerOptionValueKind kind = CompilerOptionValueKind::Int;
+ int32_t intValue0 = 0;
+ int32_t intValue1 = 0;
+ const char* stringValue0 = nullptr;
+ const char* stringValue1 = nullptr;
+ };
+
+ struct CompilerOptionEntry
+ {
+ CompilerOptionName name;
+ CompilerOptionValue value;
+ };
+ }
+
/** A result code for a Slang API operation.
This type is generally compatible with the Windows API `HRESULT` type. In particular, negative values indicate
@@ -2433,9 +2582,16 @@ extern "C"
SLANG_API SlangReflectionVariableLayout* spReflection_getGlobalParamsVarLayout(
SlangReflection* reflection);
+}
#ifdef __cplusplus
+
+namespace slang
+{
+ struct ISession;
}
+SLANG_API slang::ISession* spReflection_GetSession(SlangReflection* reflection);
+
/* Helper interfaces for C++ users */
namespace slang
{
@@ -3239,6 +3395,11 @@ namespace slang
return spReflection_GetTypeParameterCount((SlangReflection*) this);
}
+ slang::ISession* getSession()
+ {
+ return spReflection_GetSession((SlangReflection*)this);
+ }
+
TypeParameterReflection* getTypeParameterByIndex(unsigned index)
{
return (TypeParameterReflection*)spReflection_GetTypeParameterByIndex((SlangReflection*) this, index);
@@ -3350,7 +3511,6 @@ namespace slang
struct ITypeConformance;
struct IGlobalSession;
struct IModule;
- struct ISession;
struct SessionDesc;
struct SpecializationArg;
@@ -3564,6 +3724,16 @@ namespace slang
*/
virtual SLANG_NO_THROW SlangResult SLANG_MCALL setSPIRVCoreGrammar(
char const* jsonPath) = 0;
+
+ /** Parse slangc command line options into a SessionDesc that can be used to create a session
+ * with all the compiler options specified in the command line.
+ * @param argc The number of command line arguments.
+ * @param argv An input array of command line arguments to parse.
+ * @param outSessionDesc A pointer to a SessionDesc struct to receive parsed session desc.
+ * @param outAuxAllocation Auxillary memory allocated to hold data used in the sesion desc.
+ */
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL parseCommandLineArguments(
+ int argc, const char* const* argv, SessionDesc* outSessionDesc, ISlangUnknown** outAuxAllocation) = 0;
};
#define SLANG_UUID_IGlobalSession IGlobalSession::getTypeGuid()
@@ -4215,22 +4385,21 @@ namespace slang
/** Whether to force `scalar` layout for glsl shader storage buffers.
*/
bool forceGLSLScalarBufferLayout = false;
+
+ /** Pointer to an array of compiler option entries, whose size is compilerOptionEntryCount.
+ */
+ CompilerOptionEntry* compilerOptionEntries = nullptr;
+
+ /** Number of additional compiler option entries.
+ */
+ uint32_t compilerOptionEntryCount = 0;
+
};
typedef uint32_t SessionFlags;
enum
{
- kSessionFlags_None = 0,
-
- /** Use application-specific policy for semantics of the `shared` keyword.
-
- This is a legacy/compatibility flag to help an existing Slang client
- migrate to new language features, and should *not* be used by other
- clients. This feature may be removed in a future release without a
- deprecation warning, and this bit may be re-used for another feature.
- You have been warned.
- */
- kSessionFlag_FalcorCustomSharedKeywordSemantics = 1 << 0,
+ kSessionFlags_None = 0
};
struct PreprocessorMacroDesc
@@ -4270,6 +4439,15 @@ namespace slang
bool enableEffectAnnotations = false;
bool allowGLSLSyntax = false;
+
+ /** Pointer to an array of compiler option entries, whose size is compilerOptionEntryCount.
+ */
+ CompilerOptionEntry* compilerOptionEntries = nullptr;
+
+ /** Number of additional compiler option entries.
+ */
+ uint32_t compilerOptionEntryCount = 0;
+
};
enum class ContainerType
@@ -4657,6 +4835,15 @@ namespace slang
*/
virtual SLANG_NO_THROW SlangResult SLANG_MCALL renameEntryPoint(
const char* newName, IComponentType** outEntryPoint) = 0;
+
+ /** Link and specify additional compiler options when generating code
+ * from the linked program.
+ */
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL linkWithOptions(
+ IComponentType** outLinkedComponentType,
+ uint32_t compilerOptionEntryCount,
+ CompilerOptionEntry* compilerOptionEntries,
+ ISlangBlob** outDiagnostics = nullptr) = 0;
};
#define SLANG_UUID_IComponentType IComponentType::getTypeGuid()