diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-08-24 13:09:07 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-24 10:09:07 -0700 |
| commit | 0b808453407f8feef8574cae99afd90771712185 (patch) | |
| tree | 01698f8a4354d836205731762619e5b4205d31e7 /source | |
| parent | f5755019246504ad4da4614d1e34a00d74970ea7 (diff) | |
Use enums with backing types in Slang API (#2375)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Use enum types and specify backing rather than use typedefs so as to get enum type safety.
* Add version of TextureFlavor that uses internal types.
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-compiler.cpp | 2 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 20 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 8 | ||||
| -rw-r--r-- | source/slang/slang-profile.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 38 | ||||
| -rw-r--r-- | source/slang/slang-repro.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-type-system-shared.h | 8 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 2 |
8 files changed, 43 insertions, 39 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index d50350b29..c1f25a012 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -1221,7 +1221,7 @@ namespace Slang } // Set the matrix layout - options.matrixLayout = getTargetReq()->getDefaultMatrixLayoutMode(); + options.matrixLayout = SlangMatrixLayoutMode(getTargetReq()->getDefaultMatrixLayoutMode()); } // Set the profile diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 0dbaa9099..3c17d1c09 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -49,7 +49,7 @@ namespace Slang GenerateChoice }; - enum class StageTarget + enum class StageTarget { Unknown, VertexShader, @@ -60,7 +60,7 @@ namespace Slang ComputeShader, }; - enum class CodeGenTarget + enum class CodeGenTarget : SlangCompileTargetIntegral { Unknown = SLANG_TARGET_UNKNOWN, None = SLANG_TARGET_NONE, @@ -91,13 +91,13 @@ namespace Slang void printDiagnosticArg(StringBuilder& sb, CodeGenTarget val); - enum class ContainerFormat : SlangContainerFormat + enum class ContainerFormat : SlangContainerFormatIntegral { None = SLANG_CONTAINER_FORMAT_NONE, SlangModule = SLANG_CONTAINER_FORMAT_SLANG_MODULE, }; - enum class LineDirectiveMode : SlangLineDirectiveMode + enum class LineDirectiveMode : SlangLineDirectiveModeIntegral { Default = SLANG_LINE_DIRECTIVE_MODE_DEFAULT, None = SLANG_LINE_DIRECTIVE_MODE_NONE, @@ -117,13 +117,13 @@ namespace Slang // laid out with row-major or column-major // storage. // - enum MatrixLayoutMode + enum MatrixLayoutMode : SlangMatrixLayoutModeIntegral { kMatrixLayoutMode_RowMajor = SLANG_MATRIX_LAYOUT_ROW_MAJOR, kMatrixLayoutMode_ColumnMajor = SLANG_MATRIX_LAYOUT_COLUMN_MAJOR, }; - enum class DebugInfoLevel : SlangDebugInfoLevel + enum class DebugInfoLevel : SlangDebugInfoLevelIntegral { None = SLANG_DEBUG_INFO_LEVEL_NONE, Minimal = SLANG_DEBUG_INFO_LEVEL_MINIMAL, @@ -131,7 +131,7 @@ namespace Slang Maximal = SLANG_DEBUG_INFO_LEVEL_MAXIMAL, }; - enum class OptimizationLevel : SlangOptimizationLevel + enum class OptimizationLevel : SlangOptimizationLevelIntegral { None = SLANG_OPTIMIZATION_LEVEL_NONE, Default = SLANG_OPTIMIZATION_LEVEL_DEFAULT, @@ -1416,14 +1416,14 @@ namespace Slang SourceManager* getSourceManager(); }; - enum class FloatingPointMode : SlangFloatingPointMode + enum class FloatingPointMode : SlangFloatingPointModeIntegral { Default = SLANG_FLOATING_POINT_MODE_DEFAULT, Fast = SLANG_FLOATING_POINT_MODE_FAST, Precise = SLANG_FLOATING_POINT_MODE_PRECISE, }; - enum class WriterChannel : SlangWriterChannel + enum class WriterChannel : SlangWriterChannelIntegral { Diagnostic = SLANG_WRITER_CHANNEL_DIAGNOSTIC, StdOutput = SLANG_WRITER_CHANNEL_STD_OUTPUT, @@ -1431,7 +1431,7 @@ namespace Slang CountOf = SLANG_WRITER_CHANNEL_COUNT_OF, }; - enum class WriterMode : SlangWriterMode + enum class WriterMode : SlangWriterModeIntegral { Text = SLANG_WRITER_MODE_TEXT, Binary = SLANG_WRITER_MODE_BINARY, diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index a28217fd8..f88f02221 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -1126,7 +1126,7 @@ struct OptionsParser // UnownedStringSlice profileName = sliceCount >= 1 ? slices[0] : UnownedTerminatedStringSlice(""); - SlangProfileID profileID = Slang::Profile::lookUp(profileName).raw; + SlangProfileID profileID = SlangProfileID(Slang::Profile::lookUp(profileName).raw); if( profileID == SLANG_PROFILE_UNKNOWN ) { sink->diagnose(operand.loc, Diagnostics::unknownProfile, profileName); @@ -1332,11 +1332,11 @@ struct OptionsParser } else if(argValue == "-matrix-layout-row-major") { - defaultMatrixLayoutMode = kMatrixLayoutMode_RowMajor; + defaultMatrixLayoutMode = SlangMatrixLayoutMode(kMatrixLayoutMode_RowMajor); } else if(argValue == "-matrix-layout-column-major") { - defaultMatrixLayoutMode = kMatrixLayoutMode_ColumnMajor; + defaultMatrixLayoutMode = SlangMatrixLayoutMode(kMatrixLayoutMode_ColumnMajor); } else if(argValue == "-line-directive-mode") { @@ -1993,7 +1993,7 @@ struct OptionsParser if( rawTarget.profileVersion != ProfileVersion::Unknown ) { - compileRequest->setTargetProfile(targetID, Profile(rawTarget.profileVersion).raw); + compileRequest->setTargetProfile(targetID, SlangProfileID(Profile(rawTarget.profileVersion).raw)); } for( auto atom : rawTarget.capabilityAtoms ) { diff --git a/source/slang/slang-profile.h b/source/slang/slang-profile.h index 5150da27a..661274ad4 100644 --- a/source/slang/slang-profile.h +++ b/source/slang/slang-profile.h @@ -44,7 +44,7 @@ namespace Slang void printDiagnosticArg(StringBuilder& sb, ProfileVersion val); - enum class Stage : SlangStage + enum class Stage : SlangStageIntegral { Unknown = SLANG_STAGE_NONE, #define PROFILE_STAGE(TAG, NAME, VAL) TAG = VAL, diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index 96b1f9004..ae43f9113 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -542,7 +542,7 @@ SLANG_API unsigned int spReflectionType_GetColumnCount(SlangReflectionType* inTy SLANG_API SlangScalarType spReflectionType_GetScalarType(SlangReflectionType* inType) { auto type = convert(inType); - if(!type) return 0; + if(!type) return SLANG_SCALAR_TYPE_NONE; if(auto matrixType = as<MatrixExpressionType>(type)) { @@ -623,7 +623,7 @@ SLANG_API SlangReflectionUserAttribute* spReflectionType_FindUserAttributeByName SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionType* inType) { auto type = convert(inType); - if(!type) return 0; + if(!type) return SLANG_RESOURCE_NONE; while(auto arrayType = as<ArrayExpressionType>(type)) { @@ -659,7 +659,7 @@ SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionTy SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflectionType* inType) { auto type = convert(inType); - if(!type) return 0; + if(!type) return SLANG_RESOURCE_ACCESS_NONE; while(auto arrayType = as<ArrayExpressionType>(type)) { @@ -1038,7 +1038,7 @@ SLANG_API SlangParameterCategory spReflectionTypeLayout_GetCategoryByIndex(Slang auto typeLayout = convert(inTypeLayout); if(!typeLayout) return SLANG_PARAMETER_CATEGORY_NONE; - return typeLayout->resourceInfos[index].kind; + return SlangParameterCategory(typeLayout->resourceInfos[index].kind); } SLANG_API SlangMatrixLayoutMode spReflectionTypeLayout_GetMatrixLayoutMode(SlangReflectionTypeLayout* inTypeLayout) @@ -1048,7 +1048,7 @@ SLANG_API SlangMatrixLayoutMode spReflectionTypeLayout_GetMatrixLayoutMode(Slang if( auto matrixLayout = as<MatrixTypeLayout>(typeLayout) ) { - return matrixLayout->mode; + return SlangMatrixLayoutMode(matrixLayout->mode); } else { @@ -1248,10 +1248,10 @@ namespace Slang switch( shape ) { default: - return SLANG_BINDING_TYPE_TEXTURE | mutableFlag; + return SlangBindingType(SLANG_BINDING_TYPE_TEXTURE | mutableFlag); case SLANG_TEXTURE_BUFFER: - return SLANG_BINDING_TYPE_TYPED_BUFFER | mutableFlag; + return SlangBindingType(SLANG_BINDING_TYPE_TYPED_BUFFER | mutableFlag); } } else if( auto structuredBufferType = as<HLSLStructuredBufferTypeBase>(type) ) @@ -1968,8 +1968,8 @@ SLANG_API SlangBindingType spReflectionTypeLayout_getBindingRangeType(SlangRefle if(!typeLayout) return SLANG_BINDING_TYPE_UNKNOWN; auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout); - if(index < 0) return 0; - if(index >= extTypeLayout->m_bindingRanges.getCount()) return 0; + if(index < 0) return SLANG_BINDING_TYPE_UNKNOWN; + if(index >= extTypeLayout->m_bindingRanges.getCount()) return SLANG_BINDING_TYPE_UNKNOWN; auto& bindingRange = extTypeLayout->m_bindingRanges[index]; return bindingRange.bindingType; @@ -2155,16 +2155,16 @@ SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetDescriptorRangeDescrip SLANG_API SlangBindingType spReflectionTypeLayout_getDescriptorSetDescriptorRangeType(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex, SlangInt rangeIndex) { auto typeLayout = convert(inTypeLayout); - if(!typeLayout) return 0; + if(!typeLayout) return SLANG_BINDING_TYPE_UNKNOWN; auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout); - if(setIndex < 0) return 0; - if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return 0; + if(setIndex < 0) return SLANG_BINDING_TYPE_UNKNOWN; + if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return SLANG_BINDING_TYPE_UNKNOWN; auto descriptorSet = extTypeLayout->m_descriptorSets[setIndex]; - if(rangeIndex < 0) return 0; - if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return 0; + if(rangeIndex < 0) return SLANG_BINDING_TYPE_UNKNOWN; + if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return SLANG_BINDING_TYPE_UNKNOWN; auto& range = descriptorSet->descriptorRanges[rangeIndex]; return range.bindingType; @@ -2173,16 +2173,16 @@ SLANG_API SlangBindingType spReflectionTypeLayout_getDescriptorSetDescriptorRang SLANG_API SlangParameterCategory spReflectionTypeLayout_getDescriptorSetDescriptorRangeCategory(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex, SlangInt rangeIndex) { auto typeLayout = convert(inTypeLayout); - if(!typeLayout) return 0; + if(!typeLayout) return SLANG_PARAMETER_CATEGORY_NONE; auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout); - if(setIndex < 0) return 0; - if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return 0; + if(setIndex < 0) return SLANG_PARAMETER_CATEGORY_NONE; + if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return SLANG_PARAMETER_CATEGORY_NONE; auto descriptorSet = extTypeLayout->m_descriptorSets[setIndex]; - if(rangeIndex < 0) return 0; - if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return 0; + if(rangeIndex < 0) return SLANG_PARAMETER_CATEGORY_NONE; + if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return SLANG_PARAMETER_CATEGORY_NONE; auto& range = descriptorSet->descriptorRanges[rangeIndex]; return SlangParameterCategory(range.kind); diff --git a/source/slang/slang-repro.cpp b/source/slang/slang-repro.cpp index ad1bc25fc..aa4dc92fc 100644 --- a/source/slang/slang-repro.cpp +++ b/source/slang/slang-repro.cpp @@ -373,7 +373,7 @@ static String _scrubName(const String& in) dst->useUnknownImageFormatAsDefault = request->useUnknownImageFormatAsDefault; dst->obfuscateCode = linkage->m_obfuscateCode; - dst->defaultMatrixLayoutMode = linkage->defaultMatrixLayoutMode; + dst->defaultMatrixLayoutMode = SlangMatrixLayoutMode(linkage->defaultMatrixLayoutMode); } // Entry points diff --git a/source/slang/slang-type-system-shared.h b/source/slang/slang-type-system-shared.h index d0972881a..a0b8f45a8 100644 --- a/source/slang/slang-type-system-shared.h +++ b/source/slang/slang-type-system-shared.h @@ -87,14 +87,18 @@ FOREACH_BASE_TYPE(DEFINE_BASE_TYPE) SLANG_FORCE_INLINE bool operator==(const ThisType& rhs) const { return flavor == rhs.flavor; } SLANG_FORCE_INLINE bool operator!=(const ThisType& rhs) const { return !(*this == rhs); } - SlangResourceShape getShape() const { return flavor & 0xFF; } - SlangResourceAccess getAccess() const { return (flavor >> 8) & 0xFF; } + SlangResourceShape getShape() const { return SlangResourceShape(flavor & 0xFF); } + SlangResourceAccess getAccess() const { return SlangResourceAccess((flavor >> 8) & 0xFF); } TextureFlavor() = default; TextureFlavor(uint32_t tag) { flavor = (uint16_t)tag; } static TextureFlavor create(SlangResourceShape shape, SlangResourceAccess access); static TextureFlavor create(SlangResourceShape shape, SlangResourceAccess access, int flags); + + static TextureFlavor create(TextureFlavor::Shape shape, SlangResourceAccess access) { return create(SlangResourceShape(shape), access); } + static TextureFlavor create(TextureFlavor::Shape shape, SlangResourceAccess access, int flags) { return create(SlangResourceShape(shape), access, flags); } + }; enum class SamplerStateFlavor : uint8_t diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 2224c10bf..461d15df5 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -612,7 +612,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::createCompileRequest(slang::ICom SLANG_NO_THROW SlangProfileID SLANG_MCALL Session::findProfile( char const* name) { - return Slang::Profile::lookUp(name).raw; + return SlangProfileID(Slang::Profile::lookUp(name).raw); } SLANG_NO_THROW SlangCapabilityID SLANG_MCALL Session::findCapability( |
