summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-reflection-api.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-reflection-api.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-reflection-api.cpp')
-rw-r--r--source/slang/slang-reflection-api.cpp3124
1 files changed, 1741 insertions, 1383 deletions
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp
index ae351aee9..bb4dfbbc2 100644
--- a/source/slang/slang-reflection-api.cpp
+++ b/source/slang/slang-reflection-api.cpp
@@ -1,21 +1,22 @@
// slang-reflection-api.cpp
#include "../core/slang-basic.h"
+#include "slang-check.h"
+#include "slang-compiler.h"
#include "slang-syntax.h"
-
+#include "slang-type-layout.h"
#include "slang.h"
-#include "slang-compiler.h"
-#include "slang-type-layout.h"
-#include "slang-syntax.h"
-#include "slang-check.h"
#include <assert.h>
// Don't signal errors for stuff we don't implement here,
// and instead just try to return things defensively
//
// Slang developers can switch this when debugging.
-#define SLANG_REFLECTION_UNEXPECTED() do {} while(0)
+#define SLANG_REFLECTION_UNEXPECTED() \
+ do \
+ { \
+ } while (0)
namespace Slang
{
@@ -33,37 +34,37 @@ static inline SlangReflectionUserAttribute* convert(UserDefinedAttribute* attrib
static inline Type* convert(SlangReflectionType* type)
{
- return (Type*) type;
+ return (Type*)type;
}
static inline SlangReflectionType* convert(Type* type)
{
- return (SlangReflectionType*) type;
+ return (SlangReflectionType*)type;
}
static inline TypeLayout* convert(SlangReflectionTypeLayout* type)
{
- return (TypeLayout*) type;
+ return (TypeLayout*)type;
}
static inline SlangReflectionTypeLayout* convert(TypeLayout* type)
{
- return (SlangReflectionTypeLayout*) type;
+ return (SlangReflectionTypeLayout*)type;
}
-static inline SpecializationParamLayout* convert(SlangReflectionTypeParameter * typeParam)
+static inline SpecializationParamLayout* convert(SlangReflectionTypeParameter* typeParam)
{
- return (SpecializationParamLayout*) typeParam;
+ return (SpecializationParamLayout*)typeParam;
}
static inline DeclRef<Decl> convert(SlangReflectionVariable* var)
{
- return DeclRef<Decl>((DeclRefBase*) var);
+ return DeclRef<Decl>((DeclRefBase*)var);
}
static inline SlangReflectionVariable* convert(DeclRef<Decl> var)
{
- return (SlangReflectionVariable*) var.declRefBase;
+ return (SlangReflectionVariable*)var.declRefBase;
}
static inline DeclRef<FunctionDeclBase> convertToFunc(SlangReflectionFunction* func)
@@ -106,33 +107,32 @@ static inline SlangReflectionGeneric* convertDeclToGeneric(DeclRef<Decl> func)
static inline VarLayout* convert(SlangReflectionVariableLayout* var)
{
- return (VarLayout*) var;
+ return (VarLayout*)var;
}
static inline SlangReflectionVariableLayout* convert(VarLayout* var)
{
- return (SlangReflectionVariableLayout*) var;
+ return (SlangReflectionVariableLayout*)var;
}
static inline EntryPointLayout* convert(SlangReflectionEntryPoint* entryPoint)
{
- return (EntryPointLayout*) entryPoint;
+ return (EntryPointLayout*)entryPoint;
}
static inline SlangReflectionEntryPoint* convert(EntryPointLayout* entryPoint)
{
- return (SlangReflectionEntryPoint*) entryPoint;
+ return (SlangReflectionEntryPoint*)entryPoint;
}
static inline ProgramLayout* convert(SlangReflection* program)
{
- return (ProgramLayout*) program;
+ return (ProgramLayout*)program;
}
-[[maybe_unused]]
-static inline SlangReflection* convert(ProgramLayout* program)
+[[maybe_unused]] static inline SlangReflection* convert(ProgramLayout* program)
{
- return (SlangReflection*) program;
+ return (SlangReflection*)program;
}
// user attribute
@@ -148,7 +148,10 @@ static unsigned int getUserAttributeCount(Decl* decl)
return count;
}
-static SlangReflectionUserAttribute* findUserAttributeByName(Session* session, Decl* decl, const char* name)
+static SlangReflectionUserAttribute* findUserAttributeByName(
+ Session* session,
+ Decl* decl,
+ const char* name)
{
auto nameObj = session->tryGetNameObj(name);
for (auto x : decl->getModifiersOfType<UserDefinedAttribute>())
@@ -175,8 +178,8 @@ static SlangReflectionUserAttribute* getUserAttributeByIndex(Decl* decl, unsigne
// Attempt "do what I mean" remapping from the parameter category the user asked about,
// over to a parameter category that they might have meant.
static SlangParameterCategory maybeRemapParameterCategory(
- TypeLayout* typeLayout,
- SlangParameterCategory category)
+ TypeLayout* typeLayout,
+ SlangParameterCategory category)
{
// Do we have an entry for the category they asked about? Then use that.
if (typeLayout->FindResourceInfo(LayoutResourceKind(category)))
@@ -192,30 +195,29 @@ static SlangParameterCategory maybeRemapParameterCategory(
type = arrayType->getElementType();
switch (spReflectionType_GetKind(convert(type)))
{
- case SLANG_TYPE_KIND_CONSTANT_BUFFER:
- if (category == SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER)
- return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
- break;
+ case SLANG_TYPE_KIND_CONSTANT_BUFFER:
+ if (category == SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER)
+ return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
+ break;
- case SLANG_TYPE_KIND_RESOURCE:
- if (category == SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE)
- return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
- break;
+ case SLANG_TYPE_KIND_RESOURCE:
+ if (category == SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE)
+ return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
+ break;
- case SLANG_TYPE_KIND_SAMPLER_STATE:
- if (category == SLANG_PARAMETER_CATEGORY_SAMPLER_STATE)
- return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
- break;
+ case SLANG_TYPE_KIND_SAMPLER_STATE:
+ if (category == SLANG_PARAMETER_CATEGORY_SAMPLER_STATE)
+ return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
+ break;
- case SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER:
- if (category == SLANG_PARAMETER_CATEGORY_UNIFORM)
- return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
- break;
+ case SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER:
+ if (category == SLANG_PARAMETER_CATEGORY_UNIFORM)
+ return SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT;
+ break;
- // TODO: implement more helpers here
+ // TODO: implement more helpers here
- default:
- break;
+ default: break;
}
}
@@ -254,14 +256,12 @@ static VarLayout* getParameterByIndex(RefPtr<TypeLayout> typeLayout, unsigned in
return 0;
}
-static SlangParameterCategory getParameterCategory(
- LayoutResourceKind kind)
+static SlangParameterCategory getParameterCategory(LayoutResourceKind kind)
{
return SlangParameterCategory(kind);
}
-static SlangParameterCategory getParameterCategory(
- TypeLayout* typeLayout)
+static SlangParameterCategory getParameterCategory(TypeLayout* typeLayout)
{
auto resourceInfoCount = typeLayout->resourceInfos.getCount();
if (resourceInfoCount == 1)
@@ -292,26 +292,37 @@ using namespace Slang;
SLANG_API char const* spReflectionUserAttribute_GetName(SlangReflectionUserAttribute* attrib)
{
auto userAttr = convert(attrib);
- if (!userAttr) return nullptr;
+ if (!userAttr)
+ return nullptr;
return userAttr->getKeywordName()->text.getBuffer();
}
-SLANG_API unsigned int spReflectionUserAttribute_GetArgumentCount(SlangReflectionUserAttribute* attrib)
+SLANG_API unsigned int spReflectionUserAttribute_GetArgumentCount(
+ SlangReflectionUserAttribute* attrib)
{
auto userAttr = convert(attrib);
- if (!userAttr) return 0;
+ if (!userAttr)
+ return 0;
return (unsigned int)userAttr->args.getCount();
}
-SlangReflectionType* spReflectionUserAttribute_GetArgumentType(SlangReflectionUserAttribute* attrib, unsigned int index)
+SlangReflectionType* spReflectionUserAttribute_GetArgumentType(
+ SlangReflectionUserAttribute* attrib,
+ unsigned int index)
{
auto userAttr = convert(attrib);
- if (!userAttr) return nullptr;
+ if (!userAttr)
+ return nullptr;
return convert(userAttr->args[index]->type.type);
}
-SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueInt(SlangReflectionUserAttribute* attrib, unsigned int index, int * rs)
+SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueInt(
+ SlangReflectionUserAttribute* attrib,
+ unsigned int index,
+ int* rs)
{
auto userAttr = convert(attrib);
- if (!userAttr) return SLANG_E_INVALID_ARG;
- if (index >= (unsigned int)userAttr->args.getCount()) return SLANG_E_INVALID_ARG;
+ if (!userAttr)
+ return SLANG_E_INVALID_ARG;
+ if (index >= (unsigned int)userAttr->args.getCount())
+ return SLANG_E_INVALID_ARG;
if (userAttr->intArgVals.getCount() > (Index)index)
{
@@ -324,11 +335,16 @@ SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueInt(SlangReflect
}
return SLANG_E_INVALID_ARG;
}
-SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueFloat(SlangReflectionUserAttribute* attrib, unsigned int index, float * rs)
+SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueFloat(
+ SlangReflectionUserAttribute* attrib,
+ unsigned int index,
+ float* rs)
{
auto userAttr = convert(attrib);
- if (!userAttr) return SLANG_E_INVALID_ARG;
- if (index >= (unsigned int)userAttr->args.getCount()) return SLANG_E_INVALID_ARG;
+ if (!userAttr)
+ return SLANG_E_INVALID_ARG;
+ if (index >= (unsigned int)userAttr->args.getCount())
+ return SLANG_E_INVALID_ARG;
if (auto cexpr = as<FloatingPointLiteralExpr>(userAttr->args[index]))
{
*rs = (float)cexpr->value;
@@ -336,11 +352,16 @@ SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueFloat(SlangRefle
}
return SLANG_E_INVALID_ARG;
}
-SLANG_API const char* spReflectionUserAttribute_GetArgumentValueString(SlangReflectionUserAttribute* attrib, unsigned int index, size_t* bufLen)
+SLANG_API const char* spReflectionUserAttribute_GetArgumentValueString(
+ SlangReflectionUserAttribute* attrib,
+ unsigned int index,
+ size_t* bufLen)
{
auto userAttr = convert(attrib);
- if (!userAttr) return nullptr;
- if (index >= (unsigned int)userAttr->args.getCount()) return nullptr;
+ if (!userAttr)
+ return nullptr;
+ if (index >= (unsigned int)userAttr->args.getCount())
+ return nullptr;
if (auto cexpr = as<StringLiteralExpr>(userAttr->args[index]))
{
if (bufLen)
@@ -355,7 +376,8 @@ SLANG_API const char* spReflectionUserAttribute_GetArgumentValueString(SlangRefl
SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return SLANG_TYPE_KIND_NONE;
+ if (!type)
+ return SLANG_TYPE_KIND_NONE;
// TODO(tfoley): Don't emit the same type more than once...
@@ -379,11 +401,11 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType)
{
return SLANG_TYPE_KIND_CONSTANT_BUFFER;
}
- else if( const auto streamOutputType = as<HLSLStreamOutputType>(type) )
+ else if (const auto streamOutputType = as<HLSLStreamOutputType>(type))
{
return SLANG_TYPE_KIND_OUTPUT_STREAM;
}
- else if( as<MeshOutputType>(type) )
+ else if (as<MeshOutputType>(type))
{
return SLANG_TYPE_KIND_MESH_OUTPUT;
}
@@ -416,10 +438,12 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType)
return SLANG_TYPE_KIND_DYNAMIC_RESOURCE;
}
// TODO: need a better way to handle this stuff...
-#define CASE(TYPE) \
- else if(as<TYPE>(type)) do { \
- return SLANG_TYPE_KIND_RESOURCE; \
- } while(0)
+#define CASE(TYPE) \
+ else if (as<TYPE>(type)) do \
+ { \
+ return SLANG_TYPE_KIND_RESOURCE; \
+ } \
+ while (0)
CASE(HLSLStructuredBufferType);
CASE(HLSLRWStructuredBufferType);
@@ -437,10 +461,10 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType)
{
return SLANG_TYPE_KIND_ARRAY;
}
- else if( auto declRefType = as<DeclRefType>(type) )
+ else if (auto declRefType = as<DeclRefType>(type))
{
const auto& declRef = declRefType->getDeclRef();
- if(declRef.is<StructDecl>() )
+ if (declRef.is<StructDecl>())
{
return SLANG_TYPE_KIND_STRUCT;
}
@@ -458,7 +482,7 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType)
return SLANG_TYPE_KIND_STRUCT;
}
}
- else if( const auto specializedType = as<ExistentialSpecializedType>(type) )
+ else if (const auto specializedType = as<ExistentialSpecializedType>(type))
{
return SLANG_TYPE_KIND_SPECIALIZED;
}
@@ -475,14 +499,15 @@ SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* inType)
SLANG_API unsigned int spReflectionType_GetFieldCount(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return 0;
+ if (!type)
+ return 0;
// TODO: maybe filter based on kind
- if(auto declRefType = as<DeclRefType>(type))
+ if (auto declRefType = as<DeclRefType>(type))
{
auto declRef = declRefType->getDeclRef();
- if( auto structDeclRef = declRef.as<StructDecl>())
+ if (auto structDeclRef = declRef.as<StructDecl>())
{
return (unsigned int)getFields(
getModule(declRef.getDecl())->getLinkage()->getASTBuilder(),
@@ -495,20 +520,25 @@ SLANG_API unsigned int spReflectionType_GetFieldCount(SlangReflectionType* inTyp
return 0;
}
-SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(SlangReflectionType* inType, unsigned index)
+SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(
+ SlangReflectionType* inType,
+ unsigned index)
{
auto type = convert(inType);
- if(!type) return nullptr;
+ if (!type)
+ return nullptr;
// TODO: maybe filter based on kind
- if(auto declRefType = as<DeclRefType>(type))
+ if (auto declRefType = as<DeclRefType>(type))
{
auto declRef = declRefType->getDeclRef();
- if( auto structDeclRef = declRef.as<StructDecl>())
+ if (auto structDeclRef = declRef.as<StructDecl>())
{
auto fields = getFields(
- getModule(declRef.getDecl())->getLinkage()->getASTBuilder(), structDeclRef, MemberFilterStyle::Instance);
+ getModule(declRef.getDecl())->getLinkage()->getASTBuilder(),
+ structDeclRef,
+ MemberFilterStyle::Instance);
auto fieldDeclRef = fields[index];
return convert(fieldDeclRef);
}
@@ -520,15 +550,16 @@ SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(SlangReflect
SLANG_API size_t spReflectionType_GetElementCount(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return 0;
+ if (!type)
+ return 0;
- if(auto arrayType = as<ArrayExpressionType>(type))
+ if (auto arrayType = as<ArrayExpressionType>(type))
{
return !arrayType->isUnsized() ? (size_t)getIntVal(arrayType->getElementCount()) : 0;
}
- else if( auto vectorType = as<VectorExpressionType>(type))
+ else if (auto vectorType = as<VectorExpressionType>(type))
{
- return (size_t) getIntVal(vectorType->getElementCount());
+ return (size_t)getIntVal(vectorType->getElementCount());
}
return 0;
@@ -537,13 +568,14 @@ SLANG_API size_t spReflectionType_GetElementCount(SlangReflectionType* inType)
SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return nullptr;
+ if (!type)
+ return nullptr;
- if(auto arrayType = as<ArrayExpressionType>(type))
+ if (auto arrayType = as<ArrayExpressionType>(type))
{
- return (SlangReflectionType*) arrayType->getElementType();
+ return (SlangReflectionType*)arrayType->getElementType();
}
- else if( auto parameterGroupType = as<ParameterGroupType>(type))
+ else if (auto parameterGroupType = as<ParameterGroupType>(type))
{
return convert(parameterGroupType->getElementType());
}
@@ -551,11 +583,11 @@ SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionTy
{
return convert(structuredBufferType->getElementType());
}
- else if( auto vectorType = as<VectorExpressionType>(type))
+ else if (auto vectorType = as<VectorExpressionType>(type))
{
return convert(vectorType->getElementType());
}
- else if( auto matrixType = as<MatrixExpressionType>(type))
+ else if (auto matrixType = as<MatrixExpressionType>(type))
{
return convert(matrixType->getElementType());
}
@@ -566,17 +598,18 @@ SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionTy
SLANG_API unsigned int spReflectionType_GetRowCount(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return 0;
+ if (!type)
+ return 0;
- if(auto matrixType = as<MatrixExpressionType>(type))
+ if (auto matrixType = as<MatrixExpressionType>(type))
{
- return (unsigned int) getIntVal(matrixType->getRowCount());
+ return (unsigned int)getIntVal(matrixType->getRowCount());
}
- else if(const auto vectorType = as<VectorExpressionType>(type))
+ else if (const auto vectorType = as<VectorExpressionType>(type))
{
return 1;
}
- else if( const auto basicType = as<BasicExpressionType>(type) )
+ else if (const auto basicType = as<BasicExpressionType>(type))
{
return 1;
}
@@ -587,17 +620,18 @@ SLANG_API unsigned int spReflectionType_GetRowCount(SlangReflectionType* inType)
SLANG_API unsigned int spReflectionType_GetColumnCount(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return 0;
+ if (!type)
+ return 0;
- if(auto matrixType = as<MatrixExpressionType>(type))
+ if (auto matrixType = as<MatrixExpressionType>(type))
{
- return (unsigned int) getIntVal(matrixType->getColumnCount());
+ return (unsigned int)getIntVal(matrixType->getColumnCount());
}
- else if(auto vectorType = as<VectorExpressionType>(type))
+ else if (auto vectorType = as<VectorExpressionType>(type))
{
- return (unsigned int) getIntVal(vectorType->getElementCount());
+ return (unsigned int)getIntVal(vectorType->getElementCount());
}
- else if( const auto basicType = as<BasicExpressionType>(type) )
+ else if (const auto basicType = as<BasicExpressionType>(type))
{
return 1;
}
@@ -608,37 +642,38 @@ SLANG_API unsigned int spReflectionType_GetColumnCount(SlangReflectionType* inTy
SLANG_API SlangScalarType spReflectionType_GetScalarType(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return SLANG_SCALAR_TYPE_NONE;
+ if (!type)
+ return SLANG_SCALAR_TYPE_NONE;
- if(auto matrixType = as<MatrixExpressionType>(type))
+ if (auto matrixType = as<MatrixExpressionType>(type))
{
type = matrixType->getElementType();
}
- else if(auto vectorType = as<VectorExpressionType>(type))
+ else if (auto vectorType = as<VectorExpressionType>(type))
{
type = vectorType->getElementType();
}
- if(auto basicType = as<BasicExpressionType>(type))
+ if (auto basicType = as<BasicExpressionType>(type))
{
switch (basicType->getBaseType())
{
#define CASE(BASE, TAG) \
- case BaseType::BASE: return SLANG_SCALAR_TYPE_##TAG
-
- CASE(Void, VOID);
- CASE(Bool, BOOL);
- CASE(Int8, INT8);
- CASE(Int16, INT16);
- CASE(Int, INT32);
- CASE(Int64, INT64);
- CASE(UInt8, UINT8);
- CASE(UInt16, UINT16);
- CASE(UInt, UINT32);
- CASE(UInt64, UINT64);
- CASE(Half, FLOAT16);
- CASE(Float, FLOAT32);
- CASE(Double, FLOAT64);
+ case BaseType::BASE: return SLANG_SCALAR_TYPE_##TAG
+
+ CASE(Void, VOID);
+ CASE(Bool, BOOL);
+ CASE(Int8, INT8);
+ CASE(Int16, INT16);
+ CASE(Int, INT32);
+ CASE(Int64, INT64);
+ CASE(UInt8, UINT8);
+ CASE(UInt16, UINT16);
+ CASE(UInt, UINT32);
+ CASE(UInt64, UINT64);
+ CASE(Half, FLOAT16);
+ CASE(Float, FLOAT32);
+ CASE(Double, FLOAT64);
#undef CASE
@@ -655,27 +690,34 @@ SLANG_API SlangScalarType spReflectionType_GetScalarType(SlangReflectionType* in
SLANG_API unsigned int spReflectionType_GetUserAttributeCount(SlangReflectionType* inType)
{
auto type = convert(inType);
- if (!type) return 0;
+ if (!type)
+ return 0;
if (auto declRefType = as<DeclRefType>(type))
{
return getUserAttributeCount(declRefType->getDeclRef().getDecl());
}
return 0;
}
-SLANG_API SlangReflectionUserAttribute* spReflectionType_GetUserAttribute(SlangReflectionType* inType, unsigned int index)
+SLANG_API SlangReflectionUserAttribute* spReflectionType_GetUserAttribute(
+ SlangReflectionType* inType,
+ unsigned int index)
{
auto type = convert(inType);
- if (!type) return 0;
+ if (!type)
+ return 0;
if (auto declRefType = as<DeclRefType>(type))
{
return getUserAttributeByIndex(declRefType->getDeclRef().getDecl(), index);
}
return 0;
}
-SLANG_API SlangReflectionUserAttribute* spReflectionType_FindUserAttributeByName(SlangReflectionType* inType, char const* name)
+SLANG_API SlangReflectionUserAttribute* spReflectionType_FindUserAttributeByName(
+ SlangReflectionType* inType,
+ char const* name)
{
auto type = convert(inType);
- if (!type) return 0;
+ if (!type)
+ return 0;
if (auto declRefType = as<DeclRefType>(type))
{
ASTBuilder* astBuilder = declRefType->getASTBuilderForReflection();
@@ -686,49 +728,64 @@ SLANG_API SlangReflectionUserAttribute* spReflectionType_FindUserAttributeByName
return 0;
}
-SLANG_API SlangReflectionType* spReflectionType_applySpecializations(SlangReflectionType* inType, SlangReflectionGeneric* generic)
+SLANG_API SlangReflectionType* spReflectionType_applySpecializations(
+ SlangReflectionType* inType,
+ SlangReflectionGeneric* generic)
{
auto type = convert(inType);
auto genericDeclRef = convertGenericToDeclRef(generic);
-
+
if (!type || !genericDeclRef)
return nullptr;
-
- return convert(substituteType(SubstitutionSet(genericDeclRef), type->getASTBuilderForReflection(), type));
+
+ return convert(
+ substituteType(SubstitutionSet(genericDeclRef), type->getASTBuilderForReflection(), type));
}
SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return SLANG_RESOURCE_NONE;
+ if (!type)
+ return SLANG_RESOURCE_NONE;
- while(auto arrayType = as<ArrayExpressionType>(type))
+ while (auto arrayType = as<ArrayExpressionType>(type))
{
type = arrayType->getElementType();
}
- if(auto textureType = as<TextureTypeBase>(type))
+ if (auto textureType = as<TextureTypeBase>(type))
{
return textureType->getShape();
}
// TODO: need a better way to handle this stuff...
-#define CASE(TYPE, SHAPE, ACCESS) \
- else if(as<TYPE>(type)) do { \
- return SHAPE; \
- } while(0)
-
- CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLRasterizerOrderedStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
- CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
- CASE(HLSLConsumeStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_CONSUME);
- CASE(HLSLByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLRasterizerOrderedByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
- CASE(RaytracingAccelerationStructureType, SLANG_ACCELERATION_STRUCTURE, SLANG_RESOURCE_ACCESS_READ);
- CASE(UntypedBufferResourceType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(GLSLShaderStorageBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
+#define CASE(TYPE, SHAPE, ACCESS) \
+ else if (as<TYPE>(type)) do \
+ { \
+ return SHAPE; \
+ } \
+ while (0)
+
+ CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
+ CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
+ CASE(
+ HLSLRasterizerOrderedStructuredBufferType,
+ SLANG_STRUCTURED_BUFFER,
+ SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
+ CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
+ CASE(HLSLConsumeStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_CONSUME);
+ CASE(HLSLByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
+ CASE(HLSLRWByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
+ CASE(
+ HLSLRasterizerOrderedByteAddressBufferType,
+ SLANG_BYTE_ADDRESS_BUFFER,
+ SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
+ CASE(
+ RaytracingAccelerationStructureType,
+ SLANG_ACCELERATION_STRUCTURE,
+ SLANG_RESOURCE_ACCESS_READ);
+ CASE(UntypedBufferResourceType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
+ CASE(GLSLShaderStorageBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
#undef CASE
return SLANG_RESOURCE_NONE;
@@ -737,34 +794,43 @@ SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionTy
SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return SLANG_RESOURCE_ACCESS_NONE;
+ if (!type)
+ return SLANG_RESOURCE_ACCESS_NONE;
- while(auto arrayType = as<ArrayExpressionType>(type))
+ while (auto arrayType = as<ArrayExpressionType>(type))
{
type = arrayType->getElementType();
}
- if(auto textureType = as<TextureTypeBase>(type))
+ if (auto textureType = as<TextureTypeBase>(type))
{
return textureType->getAccess();
}
// TODO: need a better way to handle this stuff...
-#define CASE(TYPE, SHAPE, ACCESS) \
- else if(as<TYPE>(type)) do { \
- return ACCESS; \
- } while(0)
-
- CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLRasterizerOrderedStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
- CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
- CASE(HLSLConsumeStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_CONSUME);
- CASE(HLSLByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLRasterizerOrderedByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
- CASE(UntypedBufferResourceType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(GLSLShaderStorageBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
+#define CASE(TYPE, SHAPE, ACCESS) \
+ else if (as<TYPE>(type)) do \
+ { \
+ return ACCESS; \
+ } \
+ while (0)
+
+ CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
+ CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
+ CASE(
+ HLSLRasterizerOrderedStructuredBufferType,
+ SLANG_STRUCTURED_BUFFER,
+ SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
+ CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
+ CASE(HLSLConsumeStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_CONSUME);
+ CASE(HLSLByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
+ CASE(HLSLRWByteAddressBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
+ CASE(
+ HLSLRasterizerOrderedByteAddressBufferType,
+ SLANG_BYTE_ADDRESS_BUFFER,
+ SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
+ CASE(UntypedBufferResourceType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ);
+ CASE(GLSLShaderStorageBufferType, SLANG_BYTE_ADDRESS_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
#undef CASE
return SLANG_RESOURCE_ACCESS_NONE;
@@ -774,14 +840,14 @@ SLANG_API char const* spReflectionType_GetName(SlangReflectionType* inType)
{
auto type = convert(inType);
- if( auto declRefType = as<DeclRefType>(type) )
+ if (auto declRefType = as<DeclRefType>(type))
{
auto declRef = declRefType->getDeclRef();
// Don't return a name for auto-generated anonymous types
// that represent `cbuffer` members, etc.
auto decl = declRef.getDecl();
- if(decl->hasModifier<ImplicitParameterGroupElementTypeModifier>())
+ if (decl->hasModifier<ImplicitParameterGroupElementTypeModifier>())
return nullptr;
return getText(declRef.getName()).begin();
}
@@ -789,11 +855,13 @@ SLANG_API char const* spReflectionType_GetName(SlangReflectionType* inType)
return nullptr;
}
-SLANG_API SlangResult spReflectionType_GetFullName(SlangReflectionType* inType, ISlangBlob** outNameBlob)
+SLANG_API SlangResult
+spReflectionType_GetFullName(SlangReflectionType* inType, ISlangBlob** outNameBlob)
{
auto type = convert(inType);
- if (!type) return SLANG_FAIL;
+ if (!type)
+ return SLANG_FAIL;
StringBuilder sb;
type->toText(sb);
@@ -808,9 +876,11 @@ SlangReflectionFunction* tryConvertExprToFunctionReflection(ASTBuilder* astBuild
auto declRef = declRefExpr->declRef;
if (auto genericDeclRef = declRef.as<GenericDecl>())
{
- auto innerDeclRef = createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, genericDeclRef.getDecl()->inner);
- declRef = substituteDeclRef(
- SubstitutionSet(genericDeclRef), astBuilder, innerDeclRef);
+ auto innerDeclRef = createDefaultSubstitutionsIfNeeded(
+ astBuilder,
+ nullptr,
+ genericDeclRef.getDecl()->inner);
+ declRef = substituteDeclRef(SubstitutionSet(genericDeclRef), astBuilder, innerDeclRef);
}
if (auto funcDeclRef = declRef.as<FunctionDeclBase>())
@@ -818,11 +888,13 @@ SlangReflectionFunction* tryConvertExprToFunctionReflection(ASTBuilder* astBuild
}
else if (auto overloadedExpr = as<OverloadedExpr>(expr))
return convert(overloadedExpr);
-
+
return nullptr;
}
-SLANG_API SlangReflectionFunction* spReflection_FindFunctionByName(SlangReflection* reflection, char const* name)
+SLANG_API SlangReflectionFunction* spReflection_FindFunctionByName(
+ SlangReflection* reflection,
+ char const* name)
{
auto programLayout = convert(reflection);
auto program = programLayout->getProgram();
@@ -847,7 +919,10 @@ SLANG_API SlangReflectionFunction* spReflection_FindFunctionByName(SlangReflecti
return nullptr;
}
-SLANG_API SlangReflectionFunction* spReflection_FindFunctionByNameInType(SlangReflection* reflection, SlangReflectionType* reflType, char const* name)
+SLANG_API SlangReflectionFunction* spReflection_FindFunctionByNameInType(
+ SlangReflection* reflection,
+ SlangReflectionType* reflType,
+ char const* name)
{
auto programLayout = convert(reflection);
auto program = programLayout->getProgram();
@@ -871,7 +946,10 @@ SLANG_API SlangReflectionFunction* spReflection_FindFunctionByNameInType(SlangRe
return nullptr;
}
-SLANG_API SlangReflectionVariable* spReflection_FindVarByNameInType(SlangReflection* reflection, SlangReflectionType* reflType, char const* name)
+SLANG_API SlangReflectionVariable* spReflection_FindVarByNameInType(
+ SlangReflection* reflection,
+ SlangReflectionType* reflType,
+ char const* name)
{
auto programLayout = convert(reflection);
auto program = programLayout->getProgram();
@@ -881,7 +959,7 @@ SLANG_API SlangReflectionVariable* spReflection_FindVarByNameInType(SlangReflect
Slang::DiagnosticSink sink(
programLayout->getTargetReq()->getLinkage()->getSourceManager(),
Lexer::sourceLocationLexer);
-
+
try
{
auto result = program->findDeclFromStringInType(type, name, LookupMask::Value, &sink);
@@ -897,7 +975,9 @@ SLANG_API SlangReflectionVariable* spReflection_FindVarByNameInType(SlangReflect
return nullptr;
}
-SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * reflection, char const * name)
+SLANG_API SlangReflectionType* spReflection_FindTypeByName(
+ SlangReflection* reflection,
+ char const* name)
{
auto programLayout = convert(reflection);
auto program = programLayout->getProgram();
@@ -919,19 +999,19 @@ SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * re
{
auto genericDeclRef = genericType->getDeclRef();
auto innerDeclRef = substituteDeclRef(
- SubstitutionSet(genericDeclRef), astBuilder, genericDeclRef.getDecl()->inner);
- return convert(
- DeclRefType::create(
- astBuilder,
- createDefaultSubstitutionsIfNeeded(
- astBuilder, nullptr, innerDeclRef)));
+ SubstitutionSet(genericDeclRef),
+ astBuilder,
+ genericDeclRef.getDecl()->inner);
+ return convert(DeclRefType::create(
+ astBuilder,
+ createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, innerDeclRef)));
}
if (as<ErrorType>(result))
return nullptr;
return (SlangReflectionType*)result;
}
- catch( ... )
+ catch (...)
{
return nullptr;
}
@@ -939,7 +1019,7 @@ SLANG_API SlangReflectionType * spReflection_FindTypeByName(SlangReflection * re
SLANG_API bool spReflection_isSubType(
- SlangReflection * reflection,
+ SlangReflection* reflection,
SlangReflectionType* subType,
SlangReflectionType* superType)
{
@@ -960,7 +1040,7 @@ SLANG_API bool spReflection_isSubType(
return program->isSubType(sub, super);
}
- catch( ... )
+ catch (...)
{
return false;
}
@@ -971,13 +1051,13 @@ DeclRef<Decl> getInnermostGenericParent(DeclRef<Decl> declRef)
auto decl = declRef.getDecl();
auto astBuilder = getModule(decl)->getLinkage()->getASTBuilder();
auto parentDecl = decl;
- while(parentDecl)
+ while (parentDecl)
{
- if(parentDecl->parentDecl && as<GenericDecl>(parentDecl->parentDecl))
+ if (parentDecl->parentDecl && as<GenericDecl>(parentDecl->parentDecl))
return substituteDeclRef(
- SubstitutionSet(declRef),
- astBuilder,
- createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, DeclRef(parentDecl)));
+ SubstitutionSet(declRef),
+ astBuilder,
+ createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, DeclRef(parentDecl)));
parentDecl = parentDecl->parentDecl;
}
@@ -989,13 +1069,11 @@ SLANG_API SlangReflectionGeneric* spReflectionType_GetGenericContainer(SlangRefl
auto slangType = convert(type);
if (auto declRefType = as<DeclRefType>(slangType))
{
- return convertDeclToGeneric(
- getInnermostGenericParent(declRefType->getDeclRef()));
+ return convertDeclToGeneric(getInnermostGenericParent(declRefType->getDeclRef()));
}
else if (auto genericDeclRefType = as<GenericDeclRefType>(slangType))
{
- return convertDeclToGeneric(
- getInnermostGenericParent(genericDeclRefType->getDeclRef()));
+ return convertDeclToGeneric(getInnermostGenericParent(genericDeclRefType->getDeclRef()));
}
return nullptr;
@@ -1017,9 +1095,10 @@ SLANG_API SlangReflectionTypeLayout* spReflection_GetTypeLayout(
SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return nullptr;
+ if (!type)
+ return nullptr;
- while(auto arrayType = as<ArrayExpressionType>(type))
+ while (auto arrayType = as<ArrayExpressionType>(type))
{
type = arrayType->getElementType();
}
@@ -1030,18 +1109,23 @@ SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangRefle
}
// TODO: need a better way to handle this stuff...
-#define CASE(TYPE, SHAPE, ACCESS) \
- else if(as<TYPE>(type)) do { \
- return convert(as<TYPE>(type)->getElementType()); \
- } while(0)
+#define CASE(TYPE, SHAPE, ACCESS) \
+ else if (as<TYPE>(type)) do \
+ { \
+ return convert(as<TYPE>(type)->getElementType()); \
+ } \
+ while (0)
// TODO: structured buffer needs to expose type layout!
- CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
- CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
- CASE(HLSLRasterizerOrderedStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
- CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
- CASE(HLSLConsumeStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_CONSUME);
+ CASE(HLSLStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ);
+ CASE(HLSLRWStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_READ_WRITE);
+ CASE(
+ HLSLRasterizerOrderedStructuredBufferType,
+ SLANG_STRUCTURED_BUFFER,
+ SLANG_RESOURCE_ACCESS_RASTER_ORDERED);
+ CASE(HLSLAppendStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_APPEND);
+ CASE(HLSLConsumeStructuredBufferType, SLANG_STRUCTURED_BUFFER, SLANG_RESOURCE_ACCESS_CONSUME);
#undef CASE
return nullptr;
@@ -1049,29 +1133,32 @@ SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangRefle
// type Layout Reflection
-SLANG_API SlangReflectionType* spReflectionTypeLayout_GetType(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangReflectionType* spReflectionTypeLayout_GetType(
+ SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return nullptr;
+ if (!typeLayout)
+ return nullptr;
- return (SlangReflectionType*) typeLayout->type;
+ return (SlangReflectionType*)typeLayout->type;
}
SLANG_API SlangTypeKind spReflectionTypeLayout_getKind(SlangReflectionTypeLayout* inTypeLayout)
{
- if(!inTypeLayout) return SLANG_TYPE_KIND_NONE;
+ if (!inTypeLayout)
+ return SLANG_TYPE_KIND_NONE;
- if( auto type = spReflectionTypeLayout_GetType(inTypeLayout) )
+ if (auto type = spReflectionTypeLayout_GetType(inTypeLayout))
{
return spReflectionType_GetKind(type);
}
auto typeLayout = convert(inTypeLayout);
- if( as<StructTypeLayout>(typeLayout) )
+ if (as<StructTypeLayout>(typeLayout))
{
return SLANG_TYPE_KIND_STRUCT;
}
- else if( as<ParameterGroupTypeLayout>(typeLayout) )
+ else if (as<ParameterGroupTypeLayout>(typeLayout))
{
return SLANG_TYPE_KIND_CONSTANT_BUFFER;
}
@@ -1081,98 +1168,117 @@ SLANG_API SlangTypeKind spReflectionTypeLayout_getKind(SlangReflectionTypeLayout
namespace
{
- static size_t getReflectionSize(LayoutSize size)
- {
- if(size.isFinite())
- return size.getFiniteValue();
+static size_t getReflectionSize(LayoutSize size)
+{
+ if (size.isFinite())
+ return size.getFiniteValue();
- return SLANG_UNBOUNDED_SIZE;
- }
+ return SLANG_UNBOUNDED_SIZE;
+}
- static int32_t getAlignment(TypeLayout* typeLayout, SlangParameterCategory category)
+static int32_t getAlignment(TypeLayout* typeLayout, SlangParameterCategory category)
+{
+ if (category == SLANG_PARAMETER_CATEGORY_UNIFORM)
{
- if( category == SLANG_PARAMETER_CATEGORY_UNIFORM )
- {
- return int32_t(typeLayout->uniformAlignment);
- }
- else
- {
- return 1;
- }
+ return int32_t(typeLayout->uniformAlignment);
}
-
- static size_t getStride(TypeLayout* typeLayout, SlangParameterCategory category)
+ else
{
- auto info = typeLayout->FindResourceInfo(LayoutResourceKind(category));
- if(!info) return 0;
+ return 1;
+ }
+}
- auto size = info->count;
- if(size.isInfinite())
- return SLANG_UNBOUNDED_SIZE;
+static size_t getStride(TypeLayout* typeLayout, SlangParameterCategory category)
+{
+ auto info = typeLayout->FindResourceInfo(LayoutResourceKind(category));
+ if (!info)
+ return 0;
- size_t finiteSize = size.getFiniteValue();
- size_t alignment = getAlignment(typeLayout, category);
- SLANG_ASSERT(alignment >= 1);
+ auto size = info->count;
+ if (size.isInfinite())
+ return SLANG_UNBOUNDED_SIZE;
- auto stride = (finiteSize + (alignment-1)) & ~(alignment-1);
- return stride;
- }
+ size_t finiteSize = size.getFiniteValue();
+ size_t alignment = getAlignment(typeLayout, category);
+ SLANG_ASSERT(alignment >= 1);
+
+ auto stride = (finiteSize + (alignment - 1)) & ~(alignment - 1);
+ return stride;
}
+} // namespace
-SLANG_API size_t spReflectionTypeLayout_GetSize(SlangReflectionTypeLayout* inTypeLayout, SlangParameterCategory category)
+SLANG_API size_t spReflectionTypeLayout_GetSize(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangParameterCategory category)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto info = typeLayout->FindResourceInfo(LayoutResourceKind(category));
- if(!info) return 0;
+ if (!info)
+ return 0;
return getReflectionSize(info->count);
}
-SLANG_API size_t spReflectionTypeLayout_GetStride(SlangReflectionTypeLayout* inTypeLayout, SlangParameterCategory category)
+SLANG_API size_t spReflectionTypeLayout_GetStride(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangParameterCategory category)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
return getStride(typeLayout, category);
}
-SLANG_API int32_t spReflectionTypeLayout_getAlignment(SlangReflectionTypeLayout* inTypeLayout, SlangParameterCategory category)
+SLANG_API int32_t spReflectionTypeLayout_getAlignment(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangParameterCategory category)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
return getAlignment(typeLayout, category);
}
-SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetFieldByIndex(SlangReflectionTypeLayout* inTypeLayout, unsigned index)
+SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetFieldByIndex(
+ SlangReflectionTypeLayout* inTypeLayout,
+ unsigned index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return nullptr;
+ if (!typeLayout)
+ return nullptr;
- if(auto structTypeLayout = as<StructTypeLayout>(typeLayout))
+ if (auto structTypeLayout = as<StructTypeLayout>(typeLayout))
{
- return (SlangReflectionVariableLayout*) structTypeLayout->fields[index].Ptr();
+ return (SlangReflectionVariableLayout*)structTypeLayout->fields[index].Ptr();
}
return nullptr;
}
-SLANG_API SlangInt spReflectionTypeLayout_findFieldIndexByName(SlangReflectionTypeLayout* inTypeLayout, const char* nameBegin, const char* nameEnd)
+SLANG_API SlangInt spReflectionTypeLayout_findFieldIndexByName(
+ SlangReflectionTypeLayout* inTypeLayout,
+ const char* nameBegin,
+ const char* nameEnd)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return -1;
+ if (!typeLayout)
+ return -1;
- UnownedStringSlice name = nameEnd != nullptr ? UnownedStringSlice(nameBegin, nameEnd) : UnownedTerminatedStringSlice(nameBegin);
+ UnownedStringSlice name = nameEnd != nullptr ? UnownedStringSlice(nameBegin, nameEnd)
+ : UnownedTerminatedStringSlice(nameBegin);
- if(auto structTypeLayout = as<StructTypeLayout>(typeLayout))
+ if (auto structTypeLayout = as<StructTypeLayout>(typeLayout))
{
Index fieldCount = structTypeLayout->fields.getCount();
- for(Index f = 0; f < fieldCount; ++f)
+ for (Index f = 0; f < fieldCount; ++f)
{
auto field = structTypeLayout->fields[f];
- if(getReflectionName(field->getVariable())->text.getUnownedSlice() == name)
+ if (getReflectionName(field->getVariable())->text.getUnownedSlice() == name)
return f;
}
}
@@ -1180,26 +1286,29 @@ SLANG_API SlangInt spReflectionTypeLayout_findFieldIndexByName(SlangReflectionTy
return -1;
}
-SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetExplicitCounter(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetExplicitCounter(
+ SlangReflectionTypeLayout* inTypeLayout)
{
const auto typeLayout = convert(inTypeLayout);
- if(const auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
- return (SlangReflectionVariableLayout*) structuredBufferTypeLayout->counterVarLayout.Ptr();
+ if (const auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
+ return (SlangReflectionVariableLayout*)structuredBufferTypeLayout->counterVarLayout.Ptr();
return nullptr;
}
-SLANG_API size_t spReflectionTypeLayout_GetElementStride(SlangReflectionTypeLayout* inTypeLayout, SlangParameterCategory category)
+SLANG_API size_t spReflectionTypeLayout_GetElementStride(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangParameterCategory category)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
- if( auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout))
+ if (auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout))
{
switch (category)
{
// We store the stride explicitly for the uniform case
- case SLANG_PARAMETER_CATEGORY_UNIFORM:
- return arrayTypeLayout->uniformStride;
+ case SLANG_PARAMETER_CATEGORY_UNIFORM: return arrayTypeLayout->uniformStride;
// For most other cases (resource registers), the "stride"
// of an array is simply the number of resources (if any)
@@ -1208,45 +1317,49 @@ SLANG_API size_t spReflectionTypeLayout_GetElementStride(SlangReflectionTypeLayo
{
auto elementTypeLayout = arrayTypeLayout->elementTypeLayout;
auto info = elementTypeLayout->FindResourceInfo(LayoutResourceKind(category));
- if(!info) return 0;
+ if (!info)
+ return 0;
return getReflectionSize(info->count);
}
// An important special case, though, is Vulkan descriptor-table slots,
// where an entire array will use a single `binding`, so that the
// effective stride is zero:
- case SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT:
- return 0;
+ case SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT: return 0;
}
}
else if (auto vectorTypeLayout = as<VectorTypeLayout>(typeLayout))
{
- auto resInfo = vectorTypeLayout->elementTypeLayout->FindResourceInfo(LayoutResourceKind::Uniform);
- if (!resInfo) return 0;
+ auto resInfo =
+ vectorTypeLayout->elementTypeLayout->FindResourceInfo(LayoutResourceKind::Uniform);
+ if (!resInfo)
+ return 0;
return resInfo->count.getFiniteValue();
}
return 0;
}
-SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_GetElementTypeLayout(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_GetElementTypeLayout(
+ SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return nullptr;
+ if (!typeLayout)
+ return nullptr;
- if( auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout))
+ if (auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout))
{
- return (SlangReflectionTypeLayout*) arrayTypeLayout->elementTypeLayout.Ptr();
+ return (SlangReflectionTypeLayout*)arrayTypeLayout->elementTypeLayout.Ptr();
}
- else if( auto constantBufferTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
+ else if (auto constantBufferTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
{
return convert(constantBufferTypeLayout->offsetElementTypeLayout.Ptr());
}
- else if( auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
+ else if (auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
{
return convert(structuredBufferTypeLayout->elementTypeLayout.Ptr());
}
- else if( auto specializedTypeLayout = as<ExistentialSpecializedTypeLayout>(typeLayout) )
+ else if (auto specializedTypeLayout = as<ExistentialSpecializedTypeLayout>(typeLayout))
{
return convert(specializedTypeLayout->baseTypeLayout.Ptr());
}
@@ -1265,12 +1378,14 @@ SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_GetElementTypeLayout
return nullptr;
}
-SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetElementVarLayout(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetElementVarLayout(
+ SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return nullptr;
+ if (!typeLayout)
+ return nullptr;
- if( auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
+ if (auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
{
return convert(parameterGroupTypeLayout->elementVarLayout.Ptr());
}
@@ -1278,12 +1393,14 @@ SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetElementVarLay
return nullptr;
}
-SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getContainerVarLayout(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getContainerVarLayout(
+ SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return nullptr;
+ if (!typeLayout)
+ return nullptr;
- if( auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
+ if (auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
{
return convert(parameterGroupTypeLayout->containerVarLayout.Ptr());
}
@@ -1291,10 +1408,12 @@ SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getContainerVarL
return nullptr;
}
-SLANG_API SlangParameterCategory spReflectionTypeLayout_GetParameterCategory(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangParameterCategory
+spReflectionTypeLayout_GetParameterCategory(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return SLANG_PARAMETER_CATEGORY_NONE;
+ if (!typeLayout)
+ return SLANG_PARAMETER_CATEGORY_NONE;
return getParameterCategory(typeLayout);
}
@@ -1302,7 +1421,8 @@ SLANG_API SlangParameterCategory spReflectionTypeLayout_GetParameterCategory(Sla
SLANG_API uint32_t spReflectionTypeLayout_GetFieldCount(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if (!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
if (auto structTypeLayout = as<StructTypeLayout>(typeLayout))
{
@@ -1314,25 +1434,30 @@ SLANG_API uint32_t spReflectionTypeLayout_GetFieldCount(SlangReflectionTypeLayou
SLANG_API unsigned spReflectionTypeLayout_GetCategoryCount(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
- return (unsigned) typeLayout->resourceInfos.getCount();
+ return (unsigned)typeLayout->resourceInfos.getCount();
}
-SLANG_API SlangParameterCategory spReflectionTypeLayout_GetCategoryByIndex(SlangReflectionTypeLayout* inTypeLayout, unsigned index)
+SLANG_API SlangParameterCategory
+spReflectionTypeLayout_GetCategoryByIndex(SlangReflectionTypeLayout* inTypeLayout, unsigned index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return SLANG_PARAMETER_CATEGORY_NONE;
+ if (!typeLayout)
+ return SLANG_PARAMETER_CATEGORY_NONE;
return SlangParameterCategory(typeLayout->resourceInfos[index].kind);
}
-SLANG_API SlangMatrixLayoutMode spReflectionTypeLayout_GetMatrixLayoutMode(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangMatrixLayoutMode
+spReflectionTypeLayout_GetMatrixLayoutMode(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return SLANG_MATRIX_LAYOUT_MODE_UNKNOWN;
+ if (!typeLayout)
+ return SLANG_MATRIX_LAYOUT_MODE_UNKNOWN;
- if( auto matrixLayout = as<MatrixTypeLayout>(typeLayout) )
+ if (auto matrixLayout = as<MatrixTypeLayout>(typeLayout))
{
return SlangMatrixLayoutMode(matrixLayout->mode);
}
@@ -1340,17 +1465,17 @@ SLANG_API SlangMatrixLayoutMode spReflectionTypeLayout_GetMatrixLayoutMode(Slang
{
return SLANG_MATRIX_LAYOUT_MODE_UNKNOWN;
}
-
}
SLANG_API int spReflectionTypeLayout_getGenericParamIndex(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return -1;
+ if (!typeLayout)
+ return -1;
- if(auto genericParamTypeLayout = as<GenericParamTypeLayout>(typeLayout))
+ if (auto genericParamTypeLayout = as<GenericParamTypeLayout>(typeLayout))
{
- return (int) genericParamTypeLayout->paramIndex;
+ return (int)genericParamTypeLayout->paramIndex;
}
else
{
@@ -1358,30 +1483,36 @@ SLANG_API int spReflectionTypeLayout_getGenericParamIndex(SlangReflectionTypeLay
}
}
-SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_getPendingDataTypeLayout(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_getPendingDataTypeLayout(
+ SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return nullptr;
+ if (!typeLayout)
+ return nullptr;
auto pendingDataTypeLayout = typeLayout->pendingDataTypeLayout.Ptr();
return convert(pendingDataTypeLayout);
}
-SLANG_API SlangReflectionVariableLayout* spReflectionVariableLayout_getPendingDataLayout(SlangReflectionVariableLayout* inVarLayout)
+SLANG_API SlangReflectionVariableLayout* spReflectionVariableLayout_getPendingDataLayout(
+ SlangReflectionVariableLayout* inVarLayout)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return nullptr;
+ if (!varLayout)
+ return nullptr;
auto pendingDataLayout = varLayout->pendingVarLayout.Ptr();
return convert(pendingDataLayout);
}
-SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getSpecializedTypePendingDataVarLayout(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getSpecializedTypePendingDataVarLayout(
+ SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return nullptr;
+ if (!typeLayout)
+ return nullptr;
- if( auto specializedTypeLayout = as<ExistentialSpecializedTypeLayout>(typeLayout) )
+ if (auto specializedTypeLayout = as<ExistentialSpecializedTypeLayout>(typeLayout))
{
auto pendingDataVarLayout = specializedTypeLayout->pendingDataVarLayout.Ptr();
return convert(pendingDataVarLayout);
@@ -1395,24 +1526,32 @@ SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getSpecializedTy
SLANG_API SlangInt spReflectionType_getSpecializedTypeArgCount(SlangReflectionType* inType)
{
auto type = convert(inType);
- if(!type) return 0;
+ if (!type)
+ return 0;
auto specializedType = as<ExistentialSpecializedType>(type);
- if(!specializedType) return 0;
+ if (!specializedType)
+ return 0;
return specializedType->getArgCount();
}
-SLANG_API SlangReflectionType* spReflectionType_getSpecializedTypeArgType(SlangReflectionType* inType, SlangInt index)
+SLANG_API SlangReflectionType* spReflectionType_getSpecializedTypeArgType(
+ SlangReflectionType* inType,
+ SlangInt index)
{
auto type = convert(inType);
- if(!type) return nullptr;
+ if (!type)
+ return nullptr;
auto specializedType = as<ExistentialSpecializedType>(type);
- if(!specializedType) return nullptr;
+ if (!specializedType)
+ return nullptr;
- if(index < 0) return nullptr;
- if(index >= specializedType->getArgCount()) return nullptr;
+ if (index < 0)
+ return nullptr;
+ if (index >= specializedType->getArgCount())
+ return nullptr;
auto argType = as<Type>(specializedType->getArg(index).val);
return convert(argType);
@@ -1420,933 +1559,940 @@ SLANG_API SlangReflectionType* spReflectionType_getSpecializedTypeArgType(SlangR
namespace Slang
{
- /// A link in a chain of `VarLayout`s that can be used to compute offset information for a nested field
- struct BindingRangePathLink
- {
- BindingRangePathLink()
- {}
+/// A link in a chain of `VarLayout`s that can be used to compute offset information for a nested
+/// field
+struct BindingRangePathLink
+{
+ BindingRangePathLink() {}
- BindingRangePathLink(
- BindingRangePathLink* parent,
- VarLayout* var)
- : var(var)
- , parent(parent)
- {}
+ BindingRangePathLink(BindingRangePathLink* parent, VarLayout* var)
+ : var(var), parent(parent)
+ {
+ }
- /// The inner-most variable that contributes to the offset along this path
- VarLayout* var = nullptr;
+ /// The inner-most variable that contributes to the offset along this path
+ VarLayout* var = nullptr;
- /// The next outer link along the path
- BindingRangePathLink* parent = nullptr;
- };
+ /// The next outer link along the path
+ BindingRangePathLink* parent = nullptr;
+};
- /// A path leading to some nested field, with both parimary and "pending" data offsets
- struct BindingRangePath
- {
+/// A path leading to some nested field, with both parimary and "pending" data offsets
+struct BindingRangePath
+{
- /// The chain of variables that defines the "primary" offset of a nested field
- BindingRangePathLink* primary = nullptr;
+ /// The chain of variables that defines the "primary" offset of a nested field
+ BindingRangePathLink* primary = nullptr;
- /// The chain of variables that defines the offset for "pending" data of a nested field
- BindingRangePathLink* pending = nullptr;
- };
+ /// The chain of variables that defines the offset for "pending" data of a nested field
+ BindingRangePathLink* pending = nullptr;
+};
- /// A helper type to construct a `BindingRangePath` that extends an existing path
- struct ExtendedBindingRangePath : BindingRangePath
+/// A helper type to construct a `BindingRangePath` that extends an existing path
+struct ExtendedBindingRangePath : BindingRangePath
+{
+ /// Construct a path that extends `parent` with offset information from `varLayout`
+ ExtendedBindingRangePath(BindingRangePath const& parent, VarLayout* varLayout)
{
- /// Construct a path that extends `parent` with offset information from `varLayout`
- ExtendedBindingRangePath(
- BindingRangePath const& parent,
- VarLayout* varLayout)
- {
- SLANG_ASSERT(varLayout);
+ SLANG_ASSERT(varLayout);
- // We always add another link to the primary chain.
- //
- primaryLink = BindingRangePathLink(parent.primary, varLayout);
- primary = &primaryLink;
+ // We always add another link to the primary chain.
+ //
+ primaryLink = BindingRangePathLink(parent.primary, varLayout);
+ primary = &primaryLink;
- // If the `varLayout` provided has any offset information
- // for pending data, then we also add a link to the pending
- // chain, but otherwise we re-use the pending chain from
- // the parent path.
- //
- if(auto pendingLayout = varLayout->pendingVarLayout)
- {
- pendingLink = BindingRangePathLink(parent.pending, pendingLayout);
- pending = &pendingLink;
- }
- else
- {
- pending = parent.pending;
- }
+ // If the `varLayout` provided has any offset information
+ // for pending data, then we also add a link to the pending
+ // chain, but otherwise we re-use the pending chain from
+ // the parent path.
+ //
+ if (auto pendingLayout = varLayout->pendingVarLayout)
+ {
+ pendingLink = BindingRangePathLink(parent.pending, pendingLayout);
+ pending = &pendingLink;
}
+ else
+ {
+ pending = parent.pending;
+ }
+ }
- /// Storage for a link in the primary chain, if needed
- BindingRangePathLink primaryLink;
+ /// Storage for a link in the primary chain, if needed
+ BindingRangePathLink primaryLink;
- /// Storage for a link in the pending chain, if needed
- BindingRangePathLink pendingLink;
- };
+ /// Storage for a link in the pending chain, if needed
+ BindingRangePathLink pendingLink;
+};
- /// Calculate the offset for resources of the given `kind` in the `path`.
- Int _calcIndexOffset(BindingRangePathLink* path, LayoutResourceKind kind)
+/// Calculate the offset for resources of the given `kind` in the `path`.
+Int _calcIndexOffset(BindingRangePathLink* path, LayoutResourceKind kind)
+{
+ Int result = 0;
+ for (auto link = path; link; link = link->parent)
{
- Int result = 0;
- for( auto link = path; link; link = link->parent )
+ if (auto resInfo = link->var->FindResourceInfo(kind))
{
- if( auto resInfo = link->var->FindResourceInfo(kind) )
- {
- result += resInfo->index;
- }
+ result += resInfo->index;
}
- return result;
}
+ return result;
+}
- /// Calculate the regsiter space / set for resources of the given `kind` in the `path`.
- Int _calcSpaceOffset(BindingRangePathLink* path, LayoutResourceKind kind)
+/// Calculate the regsiter space / set for resources of the given `kind` in the `path`.
+Int _calcSpaceOffset(BindingRangePathLink* path, LayoutResourceKind kind)
+{
+ Int result = 0;
+ for (auto link = path; link; link = link->parent)
{
- Int result = 0;
- for( auto link = path; link; link = link->parent )
+ if (auto resInfo = link->var->FindResourceInfo(kind))
{
- if( auto resInfo = link->var->FindResourceInfo(kind) )
- {
- result += resInfo->space;
- }
+ result += resInfo->space;
}
- return result;
}
+ return result;
+}
- SlangBindingType _calcResourceBindingType(
- Type* type)
+SlangBindingType _calcResourceBindingType(Type* type)
+{
+ if (auto resourceType = as<ResourceType>(type))
{
- if( auto resourceType = as<ResourceType>(type) )
- {
- if (resourceType->isCombined())
- return SlangBindingType(SLANG_BINDING_TYPE_COMBINED_TEXTURE_SAMPLER);
-
- auto shape = resourceType->getBaseShape();
+ if (resourceType->isCombined())
+ return SlangBindingType(SLANG_BINDING_TYPE_COMBINED_TEXTURE_SAMPLER);
- auto access = resourceType->getAccess();
- auto mutableFlag = access != SLANG_RESOURCE_ACCESS_READ
- ? SLANG_BINDING_TYPE_MUTABLE_FLAG
- : SLANG_BINDING_TYPE_UNKNOWN;
+ auto shape = resourceType->getBaseShape();
- switch(SlangResourceShape(shape ))
- {
- default:
- return SlangBindingType(SLANG_BINDING_TYPE_TEXTURE | mutableFlag);
+ auto access = resourceType->getAccess();
+ auto mutableFlag = access != SLANG_RESOURCE_ACCESS_READ ? SLANG_BINDING_TYPE_MUTABLE_FLAG
+ : SLANG_BINDING_TYPE_UNKNOWN;
- case SLANG_TEXTURE_BUFFER:
- return SlangBindingType(SLANG_BINDING_TYPE_TYPED_BUFFER | mutableFlag);
- }
- }
- else if( const auto structuredBufferType = as<HLSLStructuredBufferTypeBase>(type) )
- {
- if( as<HLSLStructuredBufferType>(type) )
- {
- return SLANG_BINDING_TYPE_RAW_BUFFER;
- }
- else
- {
- return SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
- }
- }
- else if( as<RaytracingAccelerationStructureType>(type) )
- {
- return SLANG_BINDING_TYPE_RAY_TRACING_ACCELERATION_STRUCTURE;
- }
- else if( const auto untypedBufferType = as<UntypedBufferResourceType>(type) )
+ switch (SlangResourceShape(shape))
{
- if( as<HLSLByteAddressBufferType>(type) )
- {
- return SLANG_BINDING_TYPE_RAW_BUFFER;
- }
- else
- {
- return SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
- }
+ default: return SlangBindingType(SLANG_BINDING_TYPE_TEXTURE | mutableFlag);
+
+ case SLANG_TEXTURE_BUFFER:
+ return SlangBindingType(SLANG_BINDING_TYPE_TYPED_BUFFER | mutableFlag);
}
- else if (as<GLSLAtomicUintType>(type))
+ }
+ else if (const auto structuredBufferType = as<HLSLStructuredBufferTypeBase>(type))
+ {
+ if (as<HLSLStructuredBufferType>(type))
{
- return SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
+ return SLANG_BINDING_TYPE_RAW_BUFFER;
}
- else if( as<GLSLShaderStorageBufferType>(type) )
+ else
{
- // TODO Immutable buffers
return SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
}
- else if( as<ConstantBufferType>(type) )
- {
- return SLANG_BINDING_TYPE_CONSTANT_BUFFER;
- }
- else if( as<SamplerStateType>(type) )
- {
- return SLANG_BINDING_TYPE_SAMPLER;
- }
- else if (as<ParameterBlockType>(type))
+ }
+ else if (as<RaytracingAccelerationStructureType>(type))
+ {
+ return SLANG_BINDING_TYPE_RAY_TRACING_ACCELERATION_STRUCTURE;
+ }
+ else if (const auto untypedBufferType = as<UntypedBufferResourceType>(type))
+ {
+ if (as<HLSLByteAddressBufferType>(type))
{
- return SLANG_BINDING_TYPE_PARAMETER_BLOCK;
+ return SLANG_BINDING_TYPE_RAW_BUFFER;
}
else
{
- return SLANG_BINDING_TYPE_UNKNOWN;
+ return SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
}
}
+ else if (as<GLSLAtomicUintType>(type))
+ {
+ return SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
+ }
+ else if (as<GLSLShaderStorageBufferType>(type))
+ {
+ // TODO Immutable buffers
+ return SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
+ }
+ else if (as<ConstantBufferType>(type))
+ {
+ return SLANG_BINDING_TYPE_CONSTANT_BUFFER;
+ }
+ else if (as<SamplerStateType>(type))
+ {
+ return SLANG_BINDING_TYPE_SAMPLER;
+ }
+ else if (as<ParameterBlockType>(type))
+ {
+ return SLANG_BINDING_TYPE_PARAMETER_BLOCK;
+ }
+ else
+ {
+ return SLANG_BINDING_TYPE_UNKNOWN;
+ }
+}
- SlangBindingType _calcResourceBindingType(
- TypeLayout* typeLayout)
+SlangBindingType _calcResourceBindingType(TypeLayout* typeLayout)
+{
+ if (auto type = typeLayout->getType())
{
- if(auto type = typeLayout->getType())
- {
- return _calcResourceBindingType(type);
- }
+ return _calcResourceBindingType(type);
+ }
- if(as<ParameterGroupTypeLayout>(typeLayout))
- {
- return SLANG_BINDING_TYPE_CONSTANT_BUFFER;
- }
- else
- {
- return SLANG_BINDING_TYPE_UNKNOWN;
- }
+ if (as<ParameterGroupTypeLayout>(typeLayout))
+ {
+ return SLANG_BINDING_TYPE_CONSTANT_BUFFER;
}
+ else
+ {
+ return SLANG_BINDING_TYPE_UNKNOWN;
+ }
+}
- SlangBindingType _calcBindingType(
- LayoutResourceKind kind)
+SlangBindingType _calcBindingType(LayoutResourceKind kind)
+{
+ switch (kind)
{
- switch( kind )
- {
- default:
- return SLANG_BINDING_TYPE_UNKNOWN;
+ default:
+ return SLANG_BINDING_TYPE_UNKNOWN;
// Some cases of `LayoutResourceKind` can be mapped
// directly to a `BindingType` because there is only
// one case of types that have that resource kind.
- #define CASE(FROM, TO) \
- case LayoutResourceKind::FROM: return SLANG_BINDING_TYPE_##TO
+#define CASE(FROM, TO) \
+ case LayoutResourceKind::FROM: return SLANG_BINDING_TYPE_##TO
- CASE(ConstantBuffer, CONSTANT_BUFFER);
- CASE(SamplerState, SAMPLER);
- CASE(VaryingInput, VARYING_INPUT);
- CASE(VaryingOutput, VARYING_OUTPUT);
- CASE(ExistentialObjectParam, EXISTENTIAL_VALUE);
- CASE(PushConstantBuffer, PUSH_CONSTANT);
- CASE(Uniform, INLINE_UNIFORM_DATA);
+ CASE(ConstantBuffer, CONSTANT_BUFFER);
+ CASE(SamplerState, SAMPLER);
+ CASE(VaryingInput, VARYING_INPUT);
+ CASE(VaryingOutput, VARYING_OUTPUT);
+ CASE(ExistentialObjectParam, EXISTENTIAL_VALUE);
+ CASE(PushConstantBuffer, PUSH_CONSTANT);
+ CASE(Uniform, INLINE_UNIFORM_DATA);
// TODO: register space
- #undef CASE
- }
+#undef CASE
}
+}
- SlangBindingType _calcBindingType(
- Slang::TypeLayout* typeLayout,
- LayoutResourceKind kind)
+SlangBindingType _calcBindingType(Slang::TypeLayout* typeLayout, LayoutResourceKind kind)
+{
+ // At the type level, a push-constant buffer and a regular constant
+ // buffer are currently not distinct, so we need to detect push
+ // constant buffers/ranges before we inspect the `typeLayout` to
+ // avoid reflecting them all as ordinary constant buffers.
+ //
+ switch (kind)
{
- // At the type level, a push-constant buffer and a regular constant
- // buffer are currently not distinct, so we need to detect push
- // constant buffers/ranges before we inspect the `typeLayout` to
- // avoid reflecting them all as ordinary constant buffers.
- //
- switch(kind)
- {
- default:
- break;
+ default: break;
- case LayoutResourceKind::PushConstantBuffer:
- return SLANG_BINDING_TYPE_PUSH_CONSTANT;
- }
-
- // If the type or type layout implies a specific binding type
- // (e.g., a `Texture2D` implies a texture binding), then we
- // will always favor the binding type implied.
- //
- if( auto bindingType = _calcResourceBindingType(typeLayout) )
- {
- if(bindingType != SLANG_BINDING_TYPE_UNKNOWN)
- return bindingType;
- }
+ case LayoutResourceKind::PushConstantBuffer: return SLANG_BINDING_TYPE_PUSH_CONSTANT;
+ }
- // As a fallback, we may look at the kind of resources consumed
- // by a type layout, and use that to infer the type of binding
- // used. Note that, for example, a `float4` might represent
- // multiple different kinds of binding, depending on where/how
- // it is used (e.g., as a varying parameter, a root constant, etc.).
- //
- return _calcBindingType(kind);
+ // If the type or type layout implies a specific binding type
+ // (e.g., a `Texture2D` implies a texture binding), then we
+ // will always favor the binding type implied.
+ //
+ if (auto bindingType = _calcResourceBindingType(typeLayout))
+ {
+ if (bindingType != SLANG_BINDING_TYPE_UNKNOWN)
+ return bindingType;
}
- static DeclRefType* asInterfaceType(Type* type)
+ // As a fallback, we may look at the kind of resources consumed
+ // by a type layout, and use that to infer the type of binding
+ // used. Note that, for example, a `float4` might represent
+ // multiple different kinds of binding, depending on where/how
+ // it is used (e.g., as a varying parameter, a root constant, etc.).
+ //
+ return _calcBindingType(kind);
+}
+
+static DeclRefType* asInterfaceType(Type* type)
+{
+ if (auto declRefType = as<DeclRefType>(type))
{
- if(auto declRefType = as<DeclRefType>(type))
+ if (declRefType->getDeclRef().as<InterfaceDecl>())
{
- if(declRefType->getDeclRef().as<InterfaceDecl>())
- {
- return declRefType;
- }
+ return declRefType;
}
- return nullptr;
}
+ return nullptr;
+}
- struct ExtendedTypeLayoutContext
- {
- TypeLayout* m_typeLayout;
- TypeLayout::ExtendedInfo* m_extendedInfo;
+struct ExtendedTypeLayoutContext
+{
+ TypeLayout* m_typeLayout;
+ TypeLayout::ExtendedInfo* m_extendedInfo;
- Dictionary<Int, Int> m_mapSpaceToDescriptorSetIndex;
+ Dictionary<Int, Int> m_mapSpaceToDescriptorSetIndex;
- Int _findOrAddDescriptorSet(Int space)
- {
- Int index = 0;
- if(m_mapSpaceToDescriptorSetIndex.tryGetValue(space, index))
- return index;
-
- index = m_extendedInfo->m_descriptorSets.getCount();
- m_mapSpaceToDescriptorSetIndex.add(space, index);
+ Int _findOrAddDescriptorSet(Int space)
+ {
+ Int index = 0;
+ if (m_mapSpaceToDescriptorSetIndex.tryGetValue(space, index))
+ return index;
- RefPtr<TypeLayout::ExtendedInfo::DescriptorSetInfo> descriptorSet = new TypeLayout::ExtendedInfo::DescriptorSetInfo();
- m_extendedInfo->m_descriptorSets.add(descriptorSet);
+ index = m_extendedInfo->m_descriptorSets.getCount();
+ m_mapSpaceToDescriptorSetIndex.add(space, index);
- return index;
- }
+ RefPtr<TypeLayout::ExtendedInfo::DescriptorSetInfo> descriptorSet =
+ new TypeLayout::ExtendedInfo::DescriptorSetInfo();
+ m_extendedInfo->m_descriptorSets.add(descriptorSet);
- /// Create a single `VarLayout` for `typeLayout` that summarizes all of the offset information in `path`.
- ///
- /// Note: This function does not handle "pending" layout information.
- RefPtr<VarLayout> _createSimpleOffsetVarLayout(TypeLayout* typeLayout, BindingRangePathLink* path)
- {
- SLANG_ASSERT(typeLayout);
+ return index;
+ }
- RefPtr<VarLayout> varLayout = new VarLayout();
- varLayout->typeLayout = typeLayout;
- varLayout->typeLayout.demoteToWeakReference();
+ /// Create a single `VarLayout` for `typeLayout` that summarizes all of the offset information
+ /// in `path`.
+ ///
+ /// Note: This function does not handle "pending" layout information.
+ RefPtr<VarLayout> _createSimpleOffsetVarLayout(
+ TypeLayout* typeLayout,
+ BindingRangePathLink* path)
+ {
+ SLANG_ASSERT(typeLayout);
- for(auto typeResInfo : typeLayout->resourceInfos)
- {
- auto kind = typeResInfo.kind;
- auto varResInfo = varLayout->findOrAddResourceInfo(kind);
- varResInfo->index = _calcIndexOffset(path, kind);
- varResInfo->space = _calcSpaceOffset(path, kind);
- }
+ RefPtr<VarLayout> varLayout = new VarLayout();
+ varLayout->typeLayout = typeLayout;
+ varLayout->typeLayout.demoteToWeakReference();
- return varLayout;
+ for (auto typeResInfo : typeLayout->resourceInfos)
+ {
+ auto kind = typeResInfo.kind;
+ auto varResInfo = varLayout->findOrAddResourceInfo(kind);
+ varResInfo->index = _calcIndexOffset(path, kind);
+ varResInfo->space = _calcSpaceOffset(path, kind);
}
- /// Create a single `VarLayout` for `typeLayout` that summarizes all of the offset information in `path`.
- RefPtr<VarLayout> createOffsetVarLayout(TypeLayout* typeLayout, BindingRangePath const& path)
- {
- auto primaryVarLayout = _createSimpleOffsetVarLayout(typeLayout, path.primary);
- SLANG_ASSERT(primaryVarLayout);
+ return varLayout;
+ }
- if(auto pendingDataTypeLayout = typeLayout->pendingDataTypeLayout)
- {
- primaryVarLayout->pendingVarLayout = _createSimpleOffsetVarLayout(pendingDataTypeLayout, path.pending);
- }
+ /// Create a single `VarLayout` for `typeLayout` that summarizes all of the offset information
+ /// in `path`.
+ RefPtr<VarLayout> createOffsetVarLayout(TypeLayout* typeLayout, BindingRangePath const& path)
+ {
+ auto primaryVarLayout = _createSimpleOffsetVarLayout(typeLayout, path.primary);
+ SLANG_ASSERT(primaryVarLayout);
- return primaryVarLayout;
+ if (auto pendingDataTypeLayout = typeLayout->pendingDataTypeLayout)
+ {
+ primaryVarLayout->pendingVarLayout =
+ _createSimpleOffsetVarLayout(pendingDataTypeLayout, path.pending);
}
- void addRangesRec(TypeLayout* typeLayout, BindingRangePath const& path, LayoutSize multiplier)
+ return primaryVarLayout;
+ }
+
+ void addRangesRec(TypeLayout* typeLayout, BindingRangePath const& path, LayoutSize multiplier)
+ {
+ if (auto structTypeLayout = as<StructTypeLayout>(typeLayout))
{
- if( auto structTypeLayout = as<StructTypeLayout>(typeLayout) )
+ // For a structure type, we need to recursively
+ // add the ranges for each field.
+ //
+ // Along the way we will make sure to properly update
+ // the offset information on the fields so that
+ // they properly show their binding-range offset
+ // within the parent type.
+ //
+ Index structBindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
+ for (auto fieldVarLayout : structTypeLayout->fields)
{
- // For a structure type, we need to recursively
- // add the ranges for each field.
- //
- // Along the way we will make sure to properly update
- // the offset information on the fields so that
- // they properly show their binding-range offset
- // within the parent type.
- //
- Index structBindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
- for( auto fieldVarLayout : structTypeLayout->fields )
- {
- Index fieldBindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
- fieldVarLayout->bindingRangeOffset = fieldBindingRangeIndex - structBindingRangeIndex;
+ Index fieldBindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
+ fieldVarLayout->bindingRangeOffset =
+ fieldBindingRangeIndex - structBindingRangeIndex;
- auto fieldTypeLayout = fieldVarLayout->getTypeLayout();
+ auto fieldTypeLayout = fieldVarLayout->getTypeLayout();
- ExtendedBindingRangePath fieldPath(path, fieldVarLayout);
- addRangesRec(fieldTypeLayout, fieldPath, multiplier);
- }
- return;
+ ExtendedBindingRangePath fieldPath(path, fieldVarLayout);
+ addRangesRec(fieldTypeLayout, fieldPath, multiplier);
}
- else if( auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout) )
+ return;
+ }
+ else if (auto arrayTypeLayout = as<ArrayTypeLayout>(typeLayout))
+ {
+ // For an array, we need to recursively add the
+ // element type of the array, but with an adjusted
+ // `multiplier` to account for the element count.
+ //
+ auto elementTypeLayout = arrayTypeLayout->elementTypeLayout;
+ LayoutSize elementCount = LayoutSize::infinite();
+ if (auto arrayType = as<ArrayExpressionType>(arrayTypeLayout->type))
{
- // For an array, we need to recursively add the
- // element type of the array, but with an adjusted
- // `multiplier` to account for the element count.
- //
- auto elementTypeLayout = arrayTypeLayout->elementTypeLayout;
- LayoutSize elementCount = LayoutSize::infinite();
- if( auto arrayType = as<ArrayExpressionType>(arrayTypeLayout->type) )
+ if (!arrayType->isUnsized())
{
- if( !arrayType->isUnsized())
- {
- elementCount = LayoutSize::RawValue(getIntVal(arrayType->getElementCount()));
- }
+ elementCount = LayoutSize::RawValue(getIntVal(arrayType->getElementCount()));
}
- addRangesRec(elementTypeLayout, path, multiplier * elementCount);
- return;
}
- else if( auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
+ addRangesRec(elementTypeLayout, path, multiplier * elementCount);
+ return;
+ }
+ else if (auto parameterGroupTypeLayout = as<ParameterGroupTypeLayout>(typeLayout))
+ {
+ // A parameter group (whether a `ConstantBuffer<>` or `ParameterBlock<>`
+ // introduces a separately-allocated "sub-object" in the application's
+ // layout for shader objects.
+ //
+ // We will represent the parameter group with a single sub-object
+ // binding range (and an associated sub-object range).
+ //
+ // We start out by looking at the resources consumed by the parameter group
+ // itself, to determine what kind of binding range to report it as.
+ //
+ Index bindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
+ SlangBindingType bindingType = SLANG_BINDING_TYPE_CONSTANT_BUFFER;
+ bool shouldAllocDescriptorSet = true;
+ LayoutResourceKind kind = LayoutResourceKind::None;
+
+ // If the parameter group container starts a new space,
+ // we do not want to allocate a descriptor set from the current parent.
+ if (parameterGroupTypeLayout->containerVarLayout->FindResourceInfo(
+ LayoutResourceKind::RegisterSpace))
{
- // A parameter group (whether a `ConstantBuffer<>` or `ParameterBlock<>`
- // introduces a separately-allocated "sub-object" in the application's
- // layout for shader objects.
- //
- // We will represent the parameter group with a single sub-object
- // binding range (and an associated sub-object range).
- //
- // We start out by looking at the resources consumed by the parameter group
- // itself, to determine what kind of binding range to report it as.
- //
- Index bindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
- SlangBindingType bindingType = SLANG_BINDING_TYPE_CONSTANT_BUFFER;
- bool shouldAllocDescriptorSet = true;
- LayoutResourceKind kind = LayoutResourceKind::None;
-
- // If the parameter group container starts a new space,
- // we do not want to allocate a descriptor set from the current parent.
- if (parameterGroupTypeLayout->containerVarLayout->FindResourceInfo(LayoutResourceKind::RegisterSpace))
- {
- kind = LayoutResourceKind::RegisterSpace;
- bindingType = SLANG_BINDING_TYPE_PARAMETER_BLOCK;
- shouldAllocDescriptorSet = false;
- }
+ kind = LayoutResourceKind::RegisterSpace;
+ bindingType = SLANG_BINDING_TYPE_PARAMETER_BLOCK;
+ shouldAllocDescriptorSet = false;
+ }
- if (shouldAllocDescriptorSet)
+ if (shouldAllocDescriptorSet)
+ {
+ // If this is not a parameter block, derive the binding type
+ // from resource infos.
+ for (auto& resInfo : parameterGroupTypeLayout->resourceInfos)
{
- // If this is not a parameter block, derive the binding type
- // from resource infos.
- for(auto& resInfo : parameterGroupTypeLayout->resourceInfos)
+ kind = resInfo.kind;
+ switch (kind)
{
- kind = resInfo.kind;
- switch(kind)
- {
- default:
- continue;
-
- case LayoutResourceKind::ConstantBuffer:
- case LayoutResourceKind::PushConstantBuffer:
- case LayoutResourceKind::DescriptorTableSlot:
- break;
-
- // Certain cases indicate a parameter block that
- // actually involves indirection.
- //
- // Note: the only case where a parameter group should
- // reflect as consuming `Uniform` storage is on CPU/CUDA,
- // where that will be the only resource it contains.
- case LayoutResourceKind::Uniform:
- break;
- }
+ default: continue;
- bindingType = _calcBindingType(typeLayout, kind);
+ case LayoutResourceKind::ConstantBuffer:
+ case LayoutResourceKind::PushConstantBuffer:
+ case LayoutResourceKind::DescriptorTableSlot:
break;
+
+ // Certain cases indicate a parameter block that
+ // actually involves indirection.
+ //
+ // Note: the only case where a parameter group should
+ // reflect as consuming `Uniform` storage is on CPU/CUDA,
+ // where that will be the only resource it contains.
+ case LayoutResourceKind::Uniform: break;
}
+
+ bindingType = _calcBindingType(typeLayout, kind);
+ break;
}
-
- TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
- bindingRange.leafTypeLayout = typeLayout;
- bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
- bindingRange.bindingType = bindingType;
- bindingRange.count = multiplier;
- bindingRange.descriptorSetIndex = -1;
- bindingRange.firstDescriptorRangeIndex = 0;
- bindingRange.descriptorRangeCount = 0;
-
- // Every parameter group will introduce a sub-object range,
- // which will include bindings based on the type of data
- // inside the sub-object.
- //
- TypeLayout::ExtendedInfo::SubObjectRangeInfo subObjectRange;
- subObjectRange.bindingRangeIndex = bindingRangeIndex;
- subObjectRange.offsetVarLayout = createOffsetVarLayout(typeLayout, path);
- subObjectRange.spaceOffset = 0;
- if (kind == LayoutResourceKind::SubElementRegisterSpace && path.primary)
+ }
+
+ TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
+ bindingRange.leafTypeLayout = typeLayout;
+ bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
+ bindingRange.bindingType = bindingType;
+ bindingRange.count = multiplier;
+ bindingRange.descriptorSetIndex = -1;
+ bindingRange.firstDescriptorRangeIndex = 0;
+ bindingRange.descriptorRangeCount = 0;
+
+ // Every parameter group will introduce a sub-object range,
+ // which will include bindings based on the type of data
+ // inside the sub-object.
+ //
+ TypeLayout::ExtendedInfo::SubObjectRangeInfo subObjectRange;
+ subObjectRange.bindingRangeIndex = bindingRangeIndex;
+ subObjectRange.offsetVarLayout = createOffsetVarLayout(typeLayout, path);
+ subObjectRange.spaceOffset = 0;
+ if (kind == LayoutResourceKind::SubElementRegisterSpace && path.primary)
+ {
+ if (auto resInfo = path.primary->var->FindResourceInfo(
+ LayoutResourceKind::SubElementRegisterSpace))
{
- if (auto resInfo = path.primary->var->FindResourceInfo(LayoutResourceKind::SubElementRegisterSpace))
- {
- subObjectRange.spaceOffset = resInfo->index;
- }
+ subObjectRange.spaceOffset = resInfo->index;
}
- // It is possible that the sub-object has descriptor ranges
- // that will need to be exposed upward, into the parent.
- //
- // Note: it is a subtle point, but we are only going to expose
- // *descriptor ranges* upward and not *binding ranges*. The
- // distinction here comes down to:
- //
- // * Descriptor ranges are used to describe the entries that
- // must be allocated in one or more API descriptor sets to
- // physically hold a value of a given type (layout).
- //
- // * Binding ranges are used to describe the entries that must
- // be allocated in an application shader object to logically
- // hold a value of a given type (layout).
- //
- // In practice, a binding range might logically belong to a
- // sub-object, but physically belong to a parent. Consider:
- //
- // cbuffer C { Texture2D a; float b; }
- //
- // Independent of the API we compile for, we expect the global
- // scope to have a sub-object for `C`, and for that sub-object
- // to have a binding range for `a` (that is, we bind the texture
- // into the sub-object).
+ }
+ // It is possible that the sub-object has descriptor ranges
+ // that will need to be exposed upward, into the parent.
+ //
+ // Note: it is a subtle point, but we are only going to expose
+ // *descriptor ranges* upward and not *binding ranges*. The
+ // distinction here comes down to:
+ //
+ // * Descriptor ranges are used to describe the entries that
+ // must be allocated in one or more API descriptor sets to
+ // physically hold a value of a given type (layout).
+ //
+ // * Binding ranges are used to describe the entries that must
+ // be allocated in an application shader object to logically
+ // hold a value of a given type (layout).
+ //
+ // In practice, a binding range might logically belong to a
+ // sub-object, but physically belong to a parent. Consider:
+ //
+ // cbuffer C { Texture2D a; float b; }
+ //
+ // Independent of the API we compile for, we expect the global
+ // scope to have a sub-object for `C`, and for that sub-object
+ // to have a binding range for `a` (that is, we bind the texture
+ // into the sub-object).
+ //
+ // When compiling for D3D12 or Vulkan, we expect that the global
+ // scope must have two descriptor ranges for `C`: one for the
+ // constant buffer itself, and another for the texture `a`.
+ // The reason for this is that `a` needs to be bound as part
+ // of a descriptor set, and `C` doesn't create/allocate its own
+ // descriptor set(s).
+ //
+ // When compiling for CPU or CUDA, we expect that the global scope
+ // will have a descriptor range for `C` but *not* one for `C.a`,
+ // because the physical storage for `C.a` is provided by the
+ // memory allocation for `C` itself.
+
+ if (shouldAllocDescriptorSet)
+ {
+ // The logic here assumes that when a parameter group consumes
+ // resources that must "leak" into the outer scope (including
+ // reosurces consumed by the group "container"), those resources
+ // will amount to descriptor ranges that are part of the same
+ // descriptor set.
//
- // When compiling for D3D12 or Vulkan, we expect that the global
- // scope must have two descriptor ranges for `C`: one for the
- // constant buffer itself, and another for the texture `a`.
- // The reason for this is that `a` needs to be bound as part
- // of a descriptor set, and `C` doesn't create/allocate its own
- // descriptor set(s).
+ // (If the contents of a group consume whole spaces/sets, then
+ // those resources will be accounted for separately).
//
- // When compiling for CPU or CUDA, we expect that the global scope
- // will have a descriptor range for `C` but *not* one for `C.a`,
- // because the physical storage for `C.a` is provided by the
- // memory allocation for `C` itself.
+ Int descriptorSetIndex = _findOrAddDescriptorSet(0);
+ auto descriptorSet = m_extendedInfo->m_descriptorSets[descriptorSetIndex];
+ auto firstDescriptorRangeIndex = descriptorSet->descriptorRanges.getCount();
- if (shouldAllocDescriptorSet)
+ // First, we need to deal with any descriptor ranges that are
+ // introduced by the "container" type itself.
+ //
+ switch (kind)
{
- // The logic here assumes that when a parameter group consumes
- // resources that must "leak" into the outer scope (including
- // reosurces consumed by the group "container"), those resources
- // will amount to descriptor ranges that are part of the same
- // descriptor set.
- //
- // (If the contents of a group consume whole spaces/sets, then
- // those resources will be accounted for separately).
+ // If the parameter group was allocated to consume one or
+ // more whole register spaces/sets, then nothing should
+ // leak through that is measured in descriptor sets.
//
- Int descriptorSetIndex = _findOrAddDescriptorSet(0);
- auto descriptorSet = m_extendedInfo->m_descriptorSets[descriptorSetIndex];
- auto firstDescriptorRangeIndex = descriptorSet->descriptorRanges.getCount();
+ case LayoutResourceKind::SubElementRegisterSpace:
+ case LayoutResourceKind::None: break;
- // First, we need to deal with any descriptor ranges that are
- // introduced by the "container" type itself.
- //
- switch(kind)
+ default:
{
- // If the parameter group was allocated to consume one or
- // more whole register spaces/sets, then nothing should
- // leak through that is measured in descriptor sets.
+ // In a constant-buffer-like case, then all the (non-space/set) resource
+ // usage of the "container" should be reflected as descriptor
+ // ranges in the parent scope.
//
- case LayoutResourceKind::SubElementRegisterSpace:
- case LayoutResourceKind::None:
- break;
-
- default:
+ for (auto resInfo : parameterGroupTypeLayout->containerVarLayout->typeLayout
+ ->resourceInfos)
{
- // In a constant-buffer-like case, then all the (non-space/set) resource
- // usage of the "container" should be reflected as descriptor
- // ranges in the parent scope.
- //
- for(auto resInfo : parameterGroupTypeLayout->containerVarLayout->typeLayout->resourceInfos)
+ switch (resInfo.kind)
{
- switch( resInfo.kind )
- {
- case LayoutResourceKind::SubElementRegisterSpace:
- continue;
-
- default:
- break;
- }
-
- TypeLayout::ExtendedInfo::DescriptorRangeInfo descriptorRange;
- descriptorRange.kind = resInfo.kind;
- descriptorRange.bindingType = _calcBindingType(typeLayout, resInfo.kind);
- descriptorRange.count = multiplier;
- descriptorRange.indexOffset = _calcIndexOffset(path.primary, resInfo.kind);
- descriptorSet->descriptorRanges.add(descriptorRange);
+ case LayoutResourceKind::SubElementRegisterSpace: continue;
+
+ default: break;
}
- }
+ TypeLayout::ExtendedInfo::DescriptorRangeInfo descriptorRange;
+ descriptorRange.kind = resInfo.kind;
+ descriptorRange.bindingType =
+ _calcBindingType(typeLayout, resInfo.kind);
+ descriptorRange.count = multiplier;
+ descriptorRange.indexOffset =
+ _calcIndexOffset(path.primary, resInfo.kind);
+ descriptorSet->descriptorRanges.add(descriptorRange);
+ }
}
+ }
- // Second, we need to consider resource usage from the "element"
- // type that might leak through to the parent.
+ // Second, we need to consider resource usage from the "element"
+ // type that might leak through to the parent.
+ //
+ switch (kind)
+ {
+ // If the parameter group was allocated as a full register space/set,
+ // *or* if it was allocated as ordinary uniform storage (likely
+ // because it was compiled for CPU/CUDA), then there should
+ // be no "leakage" of descriptor ranges from the element type
+ // to the parent.
//
- switch(kind)
+ case LayoutResourceKind::SubElementRegisterSpace:
+ case LayoutResourceKind::Uniform:
+ case LayoutResourceKind::None: break;
+
+ default:
{
- // If the parameter group was allocated as a full register space/set,
- // *or* if it was allocated as ordinary uniform storage (likely
- // because it was compiled for CPU/CUDA), then there should
- // be no "leakage" of descriptor ranges from the element type
- // to the parent.
+ // If we are in the constant-buffer-like case, on an API
+ // where constant bufers "leak" resource usage to the
+ // outer context, then we need to add the descriptor ranges
+ // implied by the element type.
//
- case LayoutResourceKind::SubElementRegisterSpace:
- case LayoutResourceKind::Uniform:
- case LayoutResourceKind::None:
- break;
+ // HACK: We enumerate these nested ranges by recurisvely
+ // calling `addRangesRec`, which adds all of descriptor ranges,
+ // binding ranges, and sub-object ranges, and then we trim
+ // the lists we don't actually care about as a post-process.
+ //
+ // TODO: We could try to consider a model where we first
+ // query the extended layout information of the element
+ // type (which might already be cached) and then enumerate
+ // the descriptor ranges and copy them over.
+ //
+ // TODO: It is possible that there could be cases where
+ // some, but not all, of the nested descriptor ranges ought
+ // to be enumerated here. In that case we might have to introduce
+ // a kind of "mask" parameter that is passed down into
+ // the recursive call so that only the appropriate ranges
+ // get added.
+
+ // We need to add a link to the "path" that is used when looking
+ // up binding information, to ensure that the descriptor ranges
+ // that get enumerated here have correct register/binding offsets.
+ //
+ ExtendedBindingRangePath elementPath(
+ path,
+ parameterGroupTypeLayout->elementVarLayout);
- default:
- {
- // If we are in the constant-buffer-like case, on an API
- // where constant bufers "leak" resource usage to the
- // outer context, then we need to add the descriptor ranges
- // implied by the element type.
- //
- // HACK: We enumerate these nested ranges by recurisvely
- // calling `addRangesRec`, which adds all of descriptor ranges,
- // binding ranges, and sub-object ranges, and then we trim
- // the lists we don't actually care about as a post-process.
- //
- // TODO: We could try to consider a model where we first
- // query the extended layout information of the element
- // type (which might already be cached) and then enumerate
- // the descriptor ranges and copy them over.
- //
- // TODO: It is possible that there could be cases where
- // some, but not all, of the nested descriptor ranges ought
- // to be enumerated here. In that case we might have to introduce
- // a kind of "mask" parameter that is passed down into
- // the recursive call so that only the appropriate ranges
- // get added.
-
- // We need to add a link to the "path" that is used when looking
- // up binding information, to ensure that the descriptor ranges
- // that get enumerated here have correct register/binding offsets.
- //
- ExtendedBindingRangePath elementPath(path, parameterGroupTypeLayout->elementVarLayout);
-
- Index bindingRangeCountBefore = m_extendedInfo->m_bindingRanges.getCount();
- Index subObjectRangeCountBefore = m_extendedInfo->m_subObjectRanges.getCount();
-
- addRangesRec(parameterGroupTypeLayout->elementVarLayout->typeLayout, elementPath, multiplier);
-
- m_extendedInfo->m_bindingRanges.setCount(bindingRangeCountBefore);
- m_extendedInfo->m_subObjectRanges.setCount(subObjectRangeCountBefore);
- }
- break;
- }
+ Index bindingRangeCountBefore = m_extendedInfo->m_bindingRanges.getCount();
+ Index subObjectRangeCountBefore =
+ m_extendedInfo->m_subObjectRanges.getCount();
- auto descriptorRangeCount = descriptorSet->descriptorRanges.getCount() - firstDescriptorRangeIndex;
- bindingRange.descriptorSetIndex = descriptorSetIndex;
- bindingRange.firstDescriptorRangeIndex = firstDescriptorRangeIndex;
- bindingRange.descriptorRangeCount = descriptorRangeCount;
- }
+ addRangesRec(
+ parameterGroupTypeLayout->elementVarLayout->typeLayout,
+ elementPath,
+ multiplier);
- m_extendedInfo->m_bindingRanges.add(bindingRange);
- m_extendedInfo->m_subObjectRanges.add(subObjectRange);
- return;
- }
- else if(asInterfaceType(typeLayout->type))
- {
- // An `interface` type should introduce a binding range and a matching
- // sub-object range.
- //
- TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
- bindingRange.leafTypeLayout = typeLayout;
- bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
- bindingRange.bindingType = SLANG_BINDING_TYPE_EXISTENTIAL_VALUE;
- bindingRange.count = multiplier;
- bindingRange.descriptorSetIndex = 0;
- bindingRange.descriptorRangeCount = 0;
- bindingRange.firstDescriptorRangeIndex = 0;
-
- TypeLayout::ExtendedInfo::SubObjectRangeInfo subObjectRange;
- subObjectRange.bindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
- subObjectRange.offsetVarLayout = createOffsetVarLayout(typeLayout, path);
-
- m_extendedInfo->m_bindingRanges.add(bindingRange);
- m_extendedInfo->m_subObjectRanges.add(subObjectRange);
- }
- else if(const auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
- {
- // For structured buffers we expect them to consume a single
- // resource descriptor slot (not counting the possible counter
- // buffer)
- SLANG_ASSERT(typeLayout->resourceInfos.getCount() >= 1);
- TypeLayout::ResourceInfo resInfo;
- for (auto& info : typeLayout->resourceInfos)
- {
- switch (info.kind)
- {
- case LayoutResourceKind::UnorderedAccess:
- case LayoutResourceKind::ShaderResource:
- case LayoutResourceKind::DescriptorTableSlot:
- case LayoutResourceKind::Uniform:
- case LayoutResourceKind::ConstantBuffer: // for metal
- case LayoutResourceKind::MetalArgumentBufferElement:
- resInfo = info;
- break;
+ m_extendedInfo->m_bindingRanges.setCount(bindingRangeCountBefore);
+ m_extendedInfo->m_subObjectRanges.setCount(subObjectRangeCountBefore);
}
+ break;
}
- SLANG_ASSERT(resInfo.kind != LayoutResourceKind::None);
- const auto bindingType = as<HLSLStructuredBufferType>(typeLayout->getType())
- ? SLANG_BINDING_TYPE_RAW_BUFFER
- : SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
-
- // We now allocate a descriptor range for this buffer
- TypeLayout::ExtendedInfo::DescriptorRangeInfo descriptorRange;
- descriptorRange.kind = resInfo.kind;
- descriptorRange.bindingType = bindingType;
- // Note that we don't use resInfo.count here, as each
- // structuredBufferType is essentially a struct of 2 fields
- // (elements, counter) and not an array of length 2.
- SLANG_ASSERT(resInfo.count != 2 || structuredBufferTypeLayout->counterVarLayout);
- SLANG_ASSERT(resInfo.count != 1 || !structuredBufferTypeLayout->counterVarLayout);
- descriptorRange.count = multiplier;
- descriptorRange.indexOffset = _calcIndexOffset(path.primary, resInfo.kind);
-
- Int descriptorSetIndex = _findOrAddDescriptorSet(_calcSpaceOffset(path.primary, resInfo.kind));
- const RefPtr<TypeLayout::ExtendedInfo::DescriptorSetInfo> descriptorSet
- = m_extendedInfo->m_descriptorSets[descriptorSetIndex];
- auto descriptorRangeIndex = descriptorSet->descriptorRanges.getCount();
- descriptorSet->descriptorRanges.add(descriptorRange);
-
- // We will map the elements buffer to a single binding range
- TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
- bindingRange.leafTypeLayout = typeLayout;
- bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
- bindingRange.bindingType = bindingType;
- bindingRange.count = multiplier;
+ auto descriptorRangeCount =
+ descriptorSet->descriptorRanges.getCount() - firstDescriptorRangeIndex;
bindingRange.descriptorSetIndex = descriptorSetIndex;
- bindingRange.firstDescriptorRangeIndex = descriptorRangeIndex;
- bindingRange.descriptorRangeCount = 1;
-
- auto bindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
- m_extendedInfo->m_bindingRanges.add(bindingRange);
-
- // We also make sure to report it as a sub-object range.
- TypeLayout::ExtendedInfo::SubObjectRangeInfo subObjectRange;
- subObjectRange.bindingRangeIndex = bindingRangeIndex;
- subObjectRange.offsetVarLayout = createOffsetVarLayout(typeLayout, path);
- subObjectRange.spaceOffset = 0;
- m_extendedInfo->m_subObjectRanges.add(subObjectRange);
-
- // If we have an associated counter for this structured buffer,
- // add its ranges
- if(structuredBufferTypeLayout->counterVarLayout)
+ bindingRange.firstDescriptorRangeIndex = firstDescriptorRangeIndex;
+ bindingRange.descriptorRangeCount = descriptorRangeCount;
+ }
+
+ m_extendedInfo->m_bindingRanges.add(bindingRange);
+ m_extendedInfo->m_subObjectRanges.add(subObjectRange);
+ return;
+ }
+ else if (asInterfaceType(typeLayout->type))
+ {
+ // An `interface` type should introduce a binding range and a matching
+ // sub-object range.
+ //
+ TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
+ bindingRange.leafTypeLayout = typeLayout;
+ bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
+ bindingRange.bindingType = SLANG_BINDING_TYPE_EXISTENTIAL_VALUE;
+ bindingRange.count = multiplier;
+ bindingRange.descriptorSetIndex = 0;
+ bindingRange.descriptorRangeCount = 0;
+ bindingRange.firstDescriptorRangeIndex = 0;
+
+ TypeLayout::ExtendedInfo::SubObjectRangeInfo subObjectRange;
+ subObjectRange.bindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
+ subObjectRange.offsetVarLayout = createOffsetVarLayout(typeLayout, path);
+
+ m_extendedInfo->m_bindingRanges.add(bindingRange);
+ m_extendedInfo->m_subObjectRanges.add(subObjectRange);
+ }
+ else if (const auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
+ {
+ // For structured buffers we expect them to consume a single
+ // resource descriptor slot (not counting the possible counter
+ // buffer)
+ SLANG_ASSERT(typeLayout->resourceInfos.getCount() >= 1);
+ TypeLayout::ResourceInfo resInfo;
+ for (auto& info : typeLayout->resourceInfos)
+ {
+ switch (info.kind)
{
- ExtendedBindingRangePath counterPath(
- path,
- structuredBufferTypeLayout->counterVarLayout
- );
- // This should always be 1, because it comes after the
- // single binding range we just added
- structuredBufferTypeLayout->counterVarLayout->bindingRangeOffset =
- m_extendedInfo->m_bindingRanges.getCount() - bindingRangeIndex;
- addRangesRec(
- structuredBufferTypeLayout->counterVarLayout->typeLayout,
- counterPath,
- multiplier
- );
+ case LayoutResourceKind::UnorderedAccess:
+ case LayoutResourceKind::ShaderResource:
+ case LayoutResourceKind::DescriptorTableSlot:
+ case LayoutResourceKind::Uniform:
+ case LayoutResourceKind::ConstantBuffer: // for metal
+ case LayoutResourceKind::MetalArgumentBufferElement: resInfo = info; break;
}
}
- else
+ SLANG_ASSERT(resInfo.kind != LayoutResourceKind::None);
+
+ const auto bindingType = as<HLSLStructuredBufferType>(typeLayout->getType())
+ ? SLANG_BINDING_TYPE_RAW_BUFFER
+ : SLANG_BINDING_TYPE_MUTABLE_RAW_BUFFER;
+
+ // We now allocate a descriptor range for this buffer
+ TypeLayout::ExtendedInfo::DescriptorRangeInfo descriptorRange;
+ descriptorRange.kind = resInfo.kind;
+ descriptorRange.bindingType = bindingType;
+ // Note that we don't use resInfo.count here, as each
+ // structuredBufferType is essentially a struct of 2 fields
+ // (elements, counter) and not an array of length 2.
+ SLANG_ASSERT(resInfo.count != 2 || structuredBufferTypeLayout->counterVarLayout);
+ SLANG_ASSERT(resInfo.count != 1 || !structuredBufferTypeLayout->counterVarLayout);
+ descriptorRange.count = multiplier;
+ descriptorRange.indexOffset = _calcIndexOffset(path.primary, resInfo.kind);
+
+ Int descriptorSetIndex =
+ _findOrAddDescriptorSet(_calcSpaceOffset(path.primary, resInfo.kind));
+ const RefPtr<TypeLayout::ExtendedInfo::DescriptorSetInfo> descriptorSet =
+ m_extendedInfo->m_descriptorSets[descriptorSetIndex];
+ auto descriptorRangeIndex = descriptorSet->descriptorRanges.getCount();
+ descriptorSet->descriptorRanges.add(descriptorRange);
+
+ // We will map the elements buffer to a single binding range
+ TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
+ bindingRange.leafTypeLayout = typeLayout;
+ bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
+ bindingRange.bindingType = bindingType;
+ bindingRange.count = multiplier;
+ bindingRange.descriptorSetIndex = descriptorSetIndex;
+ bindingRange.firstDescriptorRangeIndex = descriptorRangeIndex;
+ bindingRange.descriptorRangeCount = 1;
+
+ auto bindingRangeIndex = m_extendedInfo->m_bindingRanges.getCount();
+ m_extendedInfo->m_bindingRanges.add(bindingRange);
+
+ // We also make sure to report it as a sub-object range.
+ TypeLayout::ExtendedInfo::SubObjectRangeInfo subObjectRange;
+ subObjectRange.bindingRangeIndex = bindingRangeIndex;
+ subObjectRange.offsetVarLayout = createOffsetVarLayout(typeLayout, path);
+ subObjectRange.spaceOffset = 0;
+ m_extendedInfo->m_subObjectRanges.add(subObjectRange);
+
+ // If we have an associated counter for this structured buffer,
+ // add its ranges
+ if (structuredBufferTypeLayout->counterVarLayout)
{
- // Here we have the catch-all case that handles "leaf" fields
- // that might need to introduce a binding range and descriptor
- // ranges.
- //
- // First, we want to determine what type of binding this
- // leaf field should map to, if any. We being by querying
- // the type itself, since there are many distinct descriptor
- // types for textures/buffers that can only be determined
- // by type, rather than by a `LayoutResourceKind`.
- //
- auto bindingType = _calcResourceBindingType(typeLayout);
+ ExtendedBindingRangePath counterPath(
+ path,
+ structuredBufferTypeLayout->counterVarLayout);
+ // This should always be 1, because it comes after the
+ // single binding range we just added
+ structuredBufferTypeLayout->counterVarLayout->bindingRangeOffset =
+ m_extendedInfo->m_bindingRanges.getCount() - bindingRangeIndex;
+ addRangesRec(
+ structuredBufferTypeLayout->counterVarLayout->typeLayout,
+ counterPath,
+ multiplier);
+ }
+ }
+ else
+ {
+ // Here we have the catch-all case that handles "leaf" fields
+ // that might need to introduce a binding range and descriptor
+ // ranges.
+ //
+ // First, we want to determine what type of binding this
+ // leaf field should map to, if any. We being by querying
+ // the type itself, since there are many distinct descriptor
+ // types for textures/buffers that can only be determined
+ // by type, rather than by a `LayoutResourceKind`.
+ //
+ auto bindingType = _calcResourceBindingType(typeLayout);
- // It is possible that the type alone isn't enough to tell
- // us a specific binding type, at which point we need to
- // start looking at the actual resources the type layout
- // consumes.
+ // It is possible that the type alone isn't enough to tell
+ // us a specific binding type, at which point we need to
+ // start looking at the actual resources the type layout
+ // consumes.
+ //
+ if (bindingType == SLANG_BINDING_TYPE_UNKNOWN)
+ {
+ // We will search through all the resource kinds that
+ // the type layout consumes, to see if we can find
+ // one that indicates a binding type we actually
+ // want to reflect.
//
- if(bindingType == SLANG_BINDING_TYPE_UNKNOWN)
+ for (auto resInfo : typeLayout->resourceInfos)
{
- // We will search through all the resource kinds that
- // the type layout consumes, to see if we can find
- // one that indicates a binding type we actually
- // want to reflect.
+ auto kind = resInfo.kind;
+ if (kind == LayoutResourceKind::Uniform)
+ continue;
+
+ auto kindBindingType = _calcBindingType(kind);
+ if (kindBindingType == SLANG_BINDING_TYPE_UNKNOWN)
+ continue;
+
+ // If we find a relevant binding type based on
+ // one of the resource kinds that are consumed,
+ // then we immediately stop the search and use
+ // the first one found (whether or not later
+ // entries might also provide something relevant).
//
- for( auto resInfo : typeLayout->resourceInfos )
- {
- auto kind = resInfo.kind;
- if(kind == LayoutResourceKind::Uniform)
- continue;
-
- auto kindBindingType = _calcBindingType(kind);
- if(kindBindingType == SLANG_BINDING_TYPE_UNKNOWN)
- continue;
-
- // If we find a relevant binding type based on
- // one of the resource kinds that are consumed,
- // then we immediately stop the search and use
- // the first one found (whether or not later
- // entries might also provide something relevant).
- //
- bindingType = kindBindingType;
- break;
- }
+ bindingType = kindBindingType;
+ break;
}
+ }
- // After we've tried to determine a binding type, if
- // we have nothing to go on then we don't want to add
- // a binding range.
- //
- if(bindingType == SLANG_BINDING_TYPE_UNKNOWN)
- return;
+ // After we've tried to determine a binding type, if
+ // we have nothing to go on then we don't want to add
+ // a binding range.
+ //
+ if (bindingType == SLANG_BINDING_TYPE_UNKNOWN)
+ return;
- // We now know that the leaf field will map to a single binding range,
- // and zero or more descriptor ranges.
- //
- TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
- bindingRange.leafTypeLayout = typeLayout;
- bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
- bindingRange.bindingType = bindingType;
- bindingRange.count = multiplier;
- bindingRange.descriptorSetIndex = 0;
- bindingRange.firstDescriptorRangeIndex = 0;
- bindingRange.descriptorRangeCount = 0;
-
- // We will associate the binding range with a specific descriptor
- // set on demand *if* we discover that it shold contain any
- // descriptor ranges.
- //
- RefPtr<TypeLayout::ExtendedInfo::DescriptorSetInfo> descriptorSet;
+ // We now know that the leaf field will map to a single binding range,
+ // and zero or more descriptor ranges.
+ //
+ TypeLayout::ExtendedInfo::BindingRangeInfo bindingRange;
+ bindingRange.leafTypeLayout = typeLayout;
+ bindingRange.leafVariable = path.primary ? path.primary->var->getVariable() : nullptr;
+ bindingRange.bindingType = bindingType;
+ bindingRange.count = multiplier;
+ bindingRange.descriptorSetIndex = 0;
+ bindingRange.firstDescriptorRangeIndex = 0;
+ bindingRange.descriptorRangeCount = 0;
+
+ // We will associate the binding range with a specific descriptor
+ // set on demand *if* we discover that it shold contain any
+ // descriptor ranges.
+ //
+ RefPtr<TypeLayout::ExtendedInfo::DescriptorSetInfo> descriptorSet;
- // We will add a descriptor range for each relevant resource kind
- // that the type layout consumes.
- //
- for(auto resInfo : typeLayout->resourceInfos)
+ // We will add a descriptor range for each relevant resource kind
+ // that the type layout consumes.
+ //
+ for (auto resInfo : typeLayout->resourceInfos)
+ {
+ auto kind = resInfo.kind;
+ switch (kind)
{
- auto kind = resInfo.kind;
- switch( kind )
- {
- default:
- break;
+ default:
+ break;
- // There are many resource kinds that we do not want
- // to expose as descriptor ranges simply because they
- // do not actually allocate descriptors on our target
- // APIs.
- //
- // Notably included here are uniform/ordinary data and
- // varying input/output (including the ray-tracing cases).
- //
- // It is worth noting that we *do* allow root/push-constant
- // ranges to be reflected as "descriptor" ranges here,
- // despite the fact that they are not descriptor-bound
- // under D3D12/Vulkan.
- //
- // In practice, even with us filtering out some cases here,
- // an application/renderer layer will need to filter/translate
- // or descriptor ranges into API-specific ones, and a one-to-one
- // mapping should not be assumed.
- //
- // TODO: Make some clear decisions about what should and should
- // not appear here.
- //
- case LayoutResourceKind::SubElementRegisterSpace:
- case LayoutResourceKind::VaryingInput:
- case LayoutResourceKind::VaryingOutput:
- case LayoutResourceKind::HitAttributes:
- case LayoutResourceKind::RayPayload:
- case LayoutResourceKind::ExistentialTypeParam:
- case LayoutResourceKind::ExistentialObjectParam:
- continue;
- }
-
- // We will prefer to use a binding type derived from the specific
- // resource kind, but will fall back to information from the
- // type layout when that is not available.
+ // There are many resource kinds that we do not want
+ // to expose as descriptor ranges simply because they
+ // do not actually allocate descriptors on our target
+ // APIs.
//
- // TODO: This logic probably needs a bit more work to handle
- // the case of a combined texture-sampler field that is being
- // compiled for an API with separate textures and samplers.
+ // Notably included here are uniform/ordinary data and
+ // varying input/output (including the ray-tracing cases).
//
- auto kindBindingType = _calcBindingType(kind);
- if( kindBindingType == SLANG_BINDING_TYPE_UNKNOWN )
- {
- kindBindingType = bindingType;
- }
-
- // We now expect to allocate a descriptor range for this
- // `resInfo` representing resouce usage.
+ // It is worth noting that we *do* allow root/push-constant
+ // ranges to be reflected as "descriptor" ranges here,
+ // despite the fact that they are not descriptor-bound
+ // under D3D12/Vulkan.
+ //
+ // In practice, even with us filtering out some cases here,
+ // an application/renderer layer will need to filter/translate
+ // or descriptor ranges into API-specific ones, and a one-to-one
+ // mapping should not be assumed.
+ //
+ // TODO: Make some clear decisions about what should and should
+ // not appear here.
//
- auto count = resInfo.count * multiplier;
- auto indexOffset = _calcIndexOffset(path.primary, kind);
- auto spaceOffset = _calcSpaceOffset(path.primary, kind);
+ case LayoutResourceKind::SubElementRegisterSpace:
+ case LayoutResourceKind::VaryingInput:
+ case LayoutResourceKind::VaryingOutput:
+ case LayoutResourceKind::HitAttributes:
+ case LayoutResourceKind::RayPayload:
+ case LayoutResourceKind::ExistentialTypeParam:
+ case LayoutResourceKind::ExistentialObjectParam: continue;
+ }
- TypeLayout::ExtendedInfo::DescriptorRangeInfo descriptorRange;
- descriptorRange.kind = kind;
- descriptorRange.bindingType = kindBindingType;
- descriptorRange.count = count;
- descriptorRange.indexOffset = indexOffset;
+ // We will prefer to use a binding type derived from the specific
+ // resource kind, but will fall back to information from the
+ // type layout when that is not available.
+ //
+ // TODO: This logic probably needs a bit more work to handle
+ // the case of a combined texture-sampler field that is being
+ // compiled for an API with separate textures and samplers.
+ //
+ auto kindBindingType = _calcBindingType(kind);
+ if (kindBindingType == SLANG_BINDING_TYPE_UNKNOWN)
+ {
+ kindBindingType = bindingType;
+ }
- if(!descriptorSet)
- {
- Int descriptorSetIndex = _findOrAddDescriptorSet(spaceOffset);
- descriptorSet = m_extendedInfo->m_descriptorSets[descriptorSetIndex];
+ // We now expect to allocate a descriptor range for this
+ // `resInfo` representing resouce usage.
+ //
+ auto count = resInfo.count * multiplier;
+ auto indexOffset = _calcIndexOffset(path.primary, kind);
+ auto spaceOffset = _calcSpaceOffset(path.primary, kind);
- bindingRange.descriptorSetIndex = descriptorSetIndex;
- bindingRange.firstDescriptorRangeIndex = descriptorSet->descriptorRanges.getCount();
- }
+ TypeLayout::ExtendedInfo::DescriptorRangeInfo descriptorRange;
+ descriptorRange.kind = kind;
+ descriptorRange.bindingType = kindBindingType;
+ descriptorRange.count = count;
+ descriptorRange.indexOffset = indexOffset;
+
+ if (!descriptorSet)
+ {
+ Int descriptorSetIndex = _findOrAddDescriptorSet(spaceOffset);
+ descriptorSet = m_extendedInfo->m_descriptorSets[descriptorSetIndex];
- descriptorSet->descriptorRanges.add(descriptorRange);
- bindingRange.descriptorRangeCount++;
+ bindingRange.descriptorSetIndex = descriptorSetIndex;
+ bindingRange.firstDescriptorRangeIndex =
+ descriptorSet->descriptorRanges.getCount();
}
- m_extendedInfo->m_bindingRanges.add(bindingRange);
+ descriptorSet->descriptorRanges.add(descriptorRange);
+ bindingRange.descriptorRangeCount++;
}
+
+ m_extendedInfo->m_bindingRanges.add(bindingRange);
}
- };
+ }
+};
- TypeLayout::ExtendedInfo* getExtendedTypeLayout(TypeLayout* typeLayout)
+TypeLayout::ExtendedInfo* getExtendedTypeLayout(TypeLayout* typeLayout)
+{
+ if (!typeLayout->m_extendedInfo)
{
- if( !typeLayout->m_extendedInfo )
- {
- RefPtr<TypeLayout::ExtendedInfo> extendedInfo = new TypeLayout::ExtendedInfo;
+ RefPtr<TypeLayout::ExtendedInfo> extendedInfo = new TypeLayout::ExtendedInfo;
- ExtendedTypeLayoutContext context;
- context.m_typeLayout = typeLayout;
- context.m_extendedInfo = extendedInfo;
+ ExtendedTypeLayoutContext context;
+ context.m_typeLayout = typeLayout;
+ context.m_extendedInfo = extendedInfo;
- BindingRangePath rootPath;
- context.addRangesRec(typeLayout, rootPath, 1);
+ BindingRangePath rootPath;
+ context.addRangesRec(typeLayout, rootPath, 1);
- typeLayout->m_extendedInfo = extendedInfo;
- }
- return typeLayout->m_extendedInfo;
+ typeLayout->m_extendedInfo = extendedInfo;
}
+ return typeLayout->m_extendedInfo;
}
+} // namespace Slang
-SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeCount(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangInt
+spReflectionTypeLayout_getBindingRangeCount(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
return extTypeLayout->m_bindingRanges.getCount();
}
-SLANG_API SlangBindingType spReflectionTypeLayout_getBindingRangeType(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+SLANG_API SlangBindingType
+spReflectionTypeLayout_getBindingRangeType(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return SLANG_BINDING_TYPE_UNKNOWN;
+ if (!typeLayout)
+ return SLANG_BINDING_TYPE_UNKNOWN;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(index < 0) return SLANG_BINDING_TYPE_UNKNOWN;
- if(index >= extTypeLayout->m_bindingRanges.getCount()) return SLANG_BINDING_TYPE_UNKNOWN;
+ 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;
}
-SLANG_API SlangInt spReflectionTypeLayout_isBindingRangeSpecializable(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+SLANG_API SlangInt spReflectionTypeLayout_isBindingRangeSpecializable(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
- if (!typeLayout) return SLANG_BINDING_TYPE_UNKNOWN;
+ if (!typeLayout)
+ return SLANG_BINDING_TYPE_UNKNOWN;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if (index < 0) return SLANG_BINDING_TYPE_UNKNOWN;
- if (index >= extTypeLayout->m_bindingRanges.getCount()) return SLANG_BINDING_TYPE_UNKNOWN;
+ 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];
auto type = bindingRange.leafTypeLayout->getType();
if (asInterfaceType(type))
@@ -2359,14 +2505,19 @@ SLANG_API SlangInt spReflectionTypeLayout_isBindingRangeSpecializable(SlangRefle
return 0;
}
-SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeBindingCount(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeBindingCount(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(index < 0) return 0;
- if(index >= extTypeLayout->m_bindingRanges.getCount()) return 0;
+ if (index < 0)
+ return 0;
+ if (index >= extTypeLayout->m_bindingRanges.getCount())
+ return 0;
auto& bindingRange = extTypeLayout->m_bindingRanges[index];
auto count = bindingRange.count;
@@ -2391,21 +2542,27 @@ SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeSpaceOffset(SlangReflec
}
#endif
-SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_getBindingRangeLeafTypeLayout(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_getBindingRangeLeafTypeLayout(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(index < 0) return 0;
- if(index >= extTypeLayout->m_bindingRanges.getCount()) return 0;
+ if (index < 0)
+ return 0;
+ if (index >= extTypeLayout->m_bindingRanges.getCount())
+ return 0;
auto& bindingRange = extTypeLayout->m_bindingRanges[index];
return convert(bindingRange.leafTypeLayout);
}
SLANG_API SlangReflectionVariable* spReflectionTypeLayout_getBindingRangeLeafVariable(
- SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
if (!typeLayout)
@@ -2421,14 +2578,19 @@ SLANG_API SlangReflectionVariable* spReflectionTypeLayout_getBindingRangeLeafVar
return convert(DeclRef<Decl>(bindingRange.leafVariable));
}
-SLANG_API SlangImageFormat spReflectionTypeLayout_getBindingRangeImageFormat(SlangReflectionTypeLayout* typeLayout, SlangInt index)
+SLANG_API SlangImageFormat spReflectionTypeLayout_getBindingRangeImageFormat(
+ SlangReflectionTypeLayout* typeLayout,
+ SlangInt index)
{
auto typeLayout_ = convert(typeLayout);
- if (!typeLayout_) return SLANG_IMAGE_FORMAT_unknown;
+ if (!typeLayout_)
+ return SLANG_IMAGE_FORMAT_unknown;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout_);
- if (index < 0) return SLANG_IMAGE_FORMAT_unknown;
- if (index >= extTypeLayout->m_bindingRanges.getCount()) return SLANG_IMAGE_FORMAT_unknown;
+ if (index < 0)
+ return SLANG_IMAGE_FORMAT_unknown;
+ if (index >= extTypeLayout->m_bindingRanges.getCount())
+ return SLANG_IMAGE_FORMAT_unknown;
auto& bindingRange = extTypeLayout->m_bindingRanges[index];
auto leafVar = bindingRange.leafVariable;
@@ -2440,175 +2602,241 @@ SLANG_API SlangImageFormat spReflectionTypeLayout_getBindingRangeImageFormat(Sla
}
-SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeDescriptorSetIndex(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeDescriptorSetIndex(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(index < 0) return 0;
- if(index >= extTypeLayout->m_bindingRanges.getCount()) return 0;
+ if (index < 0)
+ return 0;
+ if (index >= extTypeLayout->m_bindingRanges.getCount())
+ return 0;
auto& bindingRange = extTypeLayout->m_bindingRanges[index];
return bindingRange.descriptorSetIndex;
}
-SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeFirstDescriptorRangeIndex(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeFirstDescriptorRangeIndex(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(index < 0) return 0;
- if(index >= extTypeLayout->m_bindingRanges.getCount()) return 0;
+ if (index < 0)
+ return 0;
+ if (index >= extTypeLayout->m_bindingRanges.getCount())
+ return 0;
auto& bindingRange = extTypeLayout->m_bindingRanges[index];
return bindingRange.firstDescriptorRangeIndex;
}
-SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeDescriptorRangeCount(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
+SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeDescriptorRangeCount(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt index)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(index < 0) return 0;
- if(index >= extTypeLayout->m_bindingRanges.getCount()) return 0;
+ if (index < 0)
+ return 0;
+ if (index >= extTypeLayout->m_bindingRanges.getCount())
+ return 0;
auto& bindingRange = extTypeLayout->m_bindingRanges[index];
return bindingRange.descriptorRangeCount;
}
-SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetCount(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangInt
+spReflectionTypeLayout_getDescriptorSetCount(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
return extTypeLayout->m_descriptorSets.getCount();
}
-SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetSpaceOffset(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex)
+SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetSpaceOffset(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt setIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(setIndex < 0) return 0;
- if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return 0;
+ if (setIndex < 0)
+ return 0;
+ if (setIndex >= extTypeLayout->m_descriptorSets.getCount())
+ return 0;
auto descriptorSet = extTypeLayout->m_descriptorSets[setIndex];
return descriptorSet->spaceOffset;
}
-SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetDescriptorRangeCount(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex)
+SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetDescriptorRangeCount(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt setIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(setIndex < 0) return 0;
- if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return 0;
+ if (setIndex < 0)
+ return 0;
+ if (setIndex >= extTypeLayout->m_descriptorSets.getCount())
+ return 0;
auto descriptorSet = extTypeLayout->m_descriptorSets[setIndex];
return descriptorSet->descriptorRanges.getCount();
}
-SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetDescriptorRangeIndexOffset(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex, SlangInt rangeIndex)
+SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetDescriptorRangeIndexOffset(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt setIndex,
+ SlangInt rangeIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(setIndex < 0) return 0;
- if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return 0;
+ if (setIndex < 0)
+ return 0;
+ if (setIndex >= extTypeLayout->m_descriptorSets.getCount())
+ return 0;
auto descriptorSet = extTypeLayout->m_descriptorSets[setIndex];
- if(rangeIndex < 0) return 0;
- if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return 0;
+ if (rangeIndex < 0)
+ return 0;
+ if (rangeIndex >= descriptorSet->descriptorRanges.getCount())
+ return 0;
auto& range = descriptorSet->descriptorRanges[rangeIndex];
return range.indexOffset;
}
-SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetDescriptorRangeDescriptorCount(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex, SlangInt rangeIndex)
+SLANG_API SlangInt spReflectionTypeLayout_getDescriptorSetDescriptorRangeDescriptorCount(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt setIndex,
+ SlangInt rangeIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(setIndex < 0) return 0;
- if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return 0;
+ if (setIndex < 0)
+ return 0;
+ if (setIndex >= extTypeLayout->m_descriptorSets.getCount())
+ return 0;
auto descriptorSet = extTypeLayout->m_descriptorSets[setIndex];
- if(rangeIndex < 0) return 0;
- if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return 0;
+ if (rangeIndex < 0)
+ return 0;
+ if (rangeIndex >= descriptorSet->descriptorRanges.getCount())
+ return 0;
auto& range = descriptorSet->descriptorRanges[rangeIndex];
auto count = range.count;
return count.isFinite() ? count.getFiniteValue() : -1;
}
-SLANG_API SlangBindingType spReflectionTypeLayout_getDescriptorSetDescriptorRangeType(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex, SlangInt rangeIndex)
+SLANG_API SlangBindingType spReflectionTypeLayout_getDescriptorSetDescriptorRangeType(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt setIndex,
+ SlangInt rangeIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return SLANG_BINDING_TYPE_UNKNOWN;
+ if (!typeLayout)
+ return SLANG_BINDING_TYPE_UNKNOWN;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(setIndex < 0) return SLANG_BINDING_TYPE_UNKNOWN;
- if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return SLANG_BINDING_TYPE_UNKNOWN;
+ 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 SLANG_BINDING_TYPE_UNKNOWN;
- if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return SLANG_BINDING_TYPE_UNKNOWN;
+ 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;
}
-SLANG_API SlangParameterCategory spReflectionTypeLayout_getDescriptorSetDescriptorRangeCategory(SlangReflectionTypeLayout* inTypeLayout, SlangInt setIndex, SlangInt rangeIndex)
+SLANG_API SlangParameterCategory spReflectionTypeLayout_getDescriptorSetDescriptorRangeCategory(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt setIndex,
+ SlangInt rangeIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return SLANG_PARAMETER_CATEGORY_NONE;
+ if (!typeLayout)
+ return SLANG_PARAMETER_CATEGORY_NONE;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(setIndex < 0) return SLANG_PARAMETER_CATEGORY_NONE;
- if(setIndex >= extTypeLayout->m_descriptorSets.getCount()) return SLANG_PARAMETER_CATEGORY_NONE;
+ 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 SLANG_PARAMETER_CATEGORY_NONE;
- if(rangeIndex >= descriptorSet->descriptorRanges.getCount()) return SLANG_PARAMETER_CATEGORY_NONE;
+ 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);
}
-SLANG_API SlangInt spReflectionTypeLayout_getSubObjectRangeCount(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangInt
+spReflectionTypeLayout_getSubObjectRangeCount(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
return extTypeLayout->m_subObjectRanges.getCount();
}
-SLANG_API SlangInt spReflectionTypeLayout_getSubObjectRangeBindingRangeIndex(SlangReflectionTypeLayout* inTypeLayout, SlangInt subObjectRangeIndex)
+SLANG_API SlangInt spReflectionTypeLayout_getSubObjectRangeBindingRangeIndex(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt subObjectRangeIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
auto extTypeLayout = Slang::getExtendedTypeLayout(typeLayout);
- if(subObjectRangeIndex < 0) return 0;
- if(subObjectRangeIndex >= extTypeLayout->m_subObjectRanges.getCount()) return 0;
+ if (subObjectRangeIndex < 0)
+ return 0;
+ if (subObjectRangeIndex >= extTypeLayout->m_subObjectRanges.getCount())
+ return 0;
return extTypeLayout->m_subObjectRanges[subObjectRangeIndex].bindingRangeIndex;
}
@@ -2650,7 +2878,6 @@ SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_getSubObjectRang
}
-
#if 0
SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeSubObjectRangeIndex(SlangReflectionTypeLayout* inTypeLayout, SlangInt index)
{
@@ -2662,12 +2889,15 @@ SLANG_API SlangInt spReflectionTypeLayout_getBindingRangeSubObjectRangeIndex(Sla
#endif
-SLANG_API SlangInt spReflectionTypeLayout_getFieldBindingRangeOffset(SlangReflectionTypeLayout* inTypeLayout, SlangInt fieldIndex)
+SLANG_API SlangInt spReflectionTypeLayout_getFieldBindingRangeOffset(
+ SlangReflectionTypeLayout* inTypeLayout,
+ SlangInt fieldIndex)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
- if( auto structTypeLayout = as<StructTypeLayout>(typeLayout) )
+ if (auto structTypeLayout = as<StructTypeLayout>(typeLayout))
{
getExtendedTypeLayout(structTypeLayout);
@@ -2677,17 +2907,19 @@ SLANG_API SlangInt spReflectionTypeLayout_getFieldBindingRangeOffset(SlangReflec
return 0;
}
-SLANG_API SlangInt spReflectionTypeLayout_getExplicitCounterBindingRangeOffset(SlangReflectionTypeLayout* inTypeLayout)
+SLANG_API SlangInt
+spReflectionTypeLayout_getExplicitCounterBindingRangeOffset(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
- if(!typeLayout) return 0;
+ if (!typeLayout)
+ return 0;
- if(const auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
+ if (const auto structuredBufferTypeLayout = as<StructuredBufferTypeLayout>(typeLayout))
{
getExtendedTypeLayout(structuredBufferTypeLayout);
return structuredBufferTypeLayout->counterVarLayout
- ? structuredBufferTypeLayout->counterVarLayout->bindingRangeOffset
- : 0;
+ ? structuredBufferTypeLayout->counterVarLayout->bindingRangeOffset
+ : 0;
}
return 0;
@@ -2783,11 +3015,12 @@ SLANG_API char const* spReflectionVariable_GetName(SlangReflectionVariable* inVa
if (as<InheritanceDecl>(var))
return "$base";
- if(!var) return nullptr;
+ if (!var)
+ return nullptr;
// If the variable is one that has an "external" name that is supposed
// to be exposed for reflection, then report it here
- if(auto reflectionNameMod = var->findModifier<ParameterGroupReflectionName>())
+ if (auto reflectionNameMod = var->findModifier<ParameterGroupReflectionName>())
return getText(reflectionNameMod->nameAndLoc.name).getBuffer();
return getText(var->getName()).getBuffer();
@@ -2797,7 +3030,8 @@ SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVaria
{
auto var = convert(inVar);
- if(!var) return nullptr;
+ if (!var)
+ return nullptr;
auto astBuilder = getModule(var.getDecl())->getLinkage()->getASTBuilder();
@@ -2805,80 +3039,66 @@ SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVaria
return convert(inheritanceDecl->base.type);
if (auto varDecl = as<VarDeclBase>(var.getDecl()))
- return convert(
- substituteType(
- SubstitutionSet(var),
- astBuilder,
- varDecl->getType()));
-
+ return convert(substituteType(SubstitutionSet(var), astBuilder, varDecl->getType()));
+
return nullptr;
}
-SLANG_API SlangReflectionModifier* spReflectionVariable_FindModifier(SlangReflectionVariable* inVar, SlangModifierID modifierID)
+SLANG_API SlangReflectionModifier* spReflectionVariable_FindModifier(
+ SlangReflectionVariable* inVar,
+ SlangModifierID modifierID)
{
auto var = convert(inVar).getDecl();
- if(!var) return nullptr;
+ if (!var)
+ return nullptr;
Modifier* modifier = nullptr;
- switch( modifierID )
- {
- case SLANG_MODIFIER_SHARED:
- modifier = var->findModifier<HLSLEffectSharedModifier>();
- break;
- case SLANG_MODIFIER_CONST:
- modifier = var->findModifier<ConstModifier>();
- break;
- case SLANG_MODIFIER_NO_DIFF:
- modifier = var->findModifier<NoDiffModifier>();
- break;
- case SLANG_MODIFIER_STATIC:
- modifier = var->findModifier<HLSLStaticModifier>();
- break;
- case SLANG_MODIFIER_EXPORT:
- modifier = var->findModifier<HLSLExportModifier>();
- break;
- case SLANG_MODIFIER_EXTERN:
- modifier = var->findModifier<ExternModifier>();
- break;
+ switch (modifierID)
+ {
+ case SLANG_MODIFIER_SHARED: modifier = var->findModifier<HLSLEffectSharedModifier>(); break;
+ case SLANG_MODIFIER_CONST: modifier = var->findModifier<ConstModifier>(); break;
+ case SLANG_MODIFIER_NO_DIFF: modifier = var->findModifier<NoDiffModifier>(); break;
+ case SLANG_MODIFIER_STATIC: modifier = var->findModifier<HLSLStaticModifier>(); break;
+ case SLANG_MODIFIER_EXPORT: modifier = var->findModifier<HLSLExportModifier>(); break;
+ case SLANG_MODIFIER_EXTERN: modifier = var->findModifier<ExternModifier>(); break;
case SLANG_MODIFIER_DIFFERENTIABLE:
modifier = var->findModifier<DifferentiableAttribute>();
break;
- case SLANG_MODIFIER_MUTATING:
- modifier = var->findModifier<MutatingAttribute>();
- break;
- case SLANG_MODIFIER_IN:
- modifier = var->findModifier<InModifier>();
- break;
- case SLANG_MODIFIER_OUT:
- modifier = var->findModifier<OutModifier>();
- break;
- case SLANG_MODIFIER_INOUT:
- modifier = var->findModifier<InOutModifier>();
- break;
- default:
- return nullptr;
+ case SLANG_MODIFIER_MUTATING: modifier = var->findModifier<MutatingAttribute>(); break;
+ case SLANG_MODIFIER_IN: modifier = var->findModifier<InModifier>(); break;
+ case SLANG_MODIFIER_OUT: modifier = var->findModifier<OutModifier>(); break;
+ case SLANG_MODIFIER_INOUT: modifier = var->findModifier<InOutModifier>(); break;
+ default: return nullptr;
}
- return (SlangReflectionModifier*) modifier;
+ return (SlangReflectionModifier*)modifier;
}
SLANG_API unsigned int spReflectionVariable_GetUserAttributeCount(SlangReflectionVariable* inVar)
{
auto varDecl = convert(inVar).getDecl();
- if (!varDecl) return 0;
+ if (!varDecl)
+ return 0;
return getUserAttributeCount(varDecl);
}
-SLANG_API SlangReflectionUserAttribute* spReflectionVariable_GetUserAttribute(SlangReflectionVariable* inVar, unsigned int index)
+SLANG_API SlangReflectionUserAttribute* spReflectionVariable_GetUserAttribute(
+ SlangReflectionVariable* inVar,
+ unsigned int index)
{
auto varDecl = convert(inVar).getDecl();
- if (!varDecl) return 0;
+ if (!varDecl)
+ return 0;
return getUserAttributeByIndex(varDecl, index);
}
-SLANG_API SlangReflectionUserAttribute* spReflectionVariable_FindUserAttributeByName(SlangReflectionVariable* inVar, SlangSession* session, char const* name)
+SLANG_API SlangReflectionUserAttribute* spReflectionVariable_FindUserAttributeByName(
+ SlangReflectionVariable* inVar,
+ SlangSession* session,
+ char const* name)
{
auto varDecl = convert(inVar).getDecl();
- if (!varDecl) return 0;
+ if (!varDecl)
+ return 0;
return findUserAttributeByName(asInternal(session), varDecl, name);
}
@@ -2889,23 +3109,26 @@ SLANG_API bool spReflectionVariable_HasDefaultValue(SlangReflectionVariable* inV
{
return varDecl->initExpr != nullptr;
}
-
+
return false;
}
-SLANG_API SlangReflectionGeneric* spReflectionVariable_GetGenericContainer(SlangReflectionVariable* var)
+SLANG_API SlangReflectionGeneric* spReflectionVariable_GetGenericContainer(
+ SlangReflectionVariable* var)
{
auto declRef = convert(var);
return convertDeclToGeneric(getInnermostGenericParent(declRef));
}
-SLANG_API SlangReflectionVariable* spReflectionVariable_applySpecializations(SlangReflectionVariable* var, SlangReflectionGeneric* generic)
+SLANG_API SlangReflectionVariable* spReflectionVariable_applySpecializations(
+ SlangReflectionVariable* var,
+ SlangReflectionGeneric* generic)
{
auto declRef = convert(var);
auto genericDeclRef = convertGenericToDeclRef(generic);
if (!declRef || !genericDeclRef)
return nullptr;
-
+
auto astBuilder = getModule(declRef.getDecl())->getLinkage()->getASTBuilder();
auto substDeclRef = substituteDeclRef(SubstitutionSet(genericDeclRef), astBuilder, declRef);
@@ -2914,26 +3137,33 @@ SLANG_API SlangReflectionVariable* spReflectionVariable_applySpecializations(Sla
// Variable Layout Reflection
-SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(SlangReflectionVariableLayout* inVarLayout)
+SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(
+ SlangReflectionVariableLayout* inVarLayout)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return nullptr;
+ if (!varLayout)
+ return nullptr;
return convert(varLayout->varDecl);
}
-SLANG_API SlangReflectionTypeLayout* spReflectionVariableLayout_GetTypeLayout(SlangReflectionVariableLayout* inVarLayout)
+SLANG_API SlangReflectionTypeLayout* spReflectionVariableLayout_GetTypeLayout(
+ SlangReflectionVariableLayout* inVarLayout)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return nullptr;
+ if (!varLayout)
+ return nullptr;
return convert(varLayout->getTypeLayout());
}
-SLANG_API size_t spReflectionVariableLayout_GetOffset(SlangReflectionVariableLayout* inVarLayout, SlangParameterCategory category)
+SLANG_API size_t spReflectionVariableLayout_GetOffset(
+ SlangReflectionVariableLayout* inVarLayout,
+ SlangParameterCategory category)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return 0;
+ if (!varLayout)
+ return 0;
auto info = varLayout->FindResourceInfo(LayoutResourceKind(category));
@@ -2944,15 +3174,19 @@ SLANG_API size_t spReflectionVariableLayout_GetOffset(SlangReflectionVariableLay
info = varLayout->FindResourceInfo(LayoutResourceKind(category));
}
- if(!info) return 0;
+ if (!info)
+ return 0;
return info->index;
}
-SLANG_API size_t spReflectionVariableLayout_GetSpace(SlangReflectionVariableLayout* inVarLayout, SlangParameterCategory category)
+SLANG_API size_t spReflectionVariableLayout_GetSpace(
+ SlangReflectionVariableLayout* inVarLayout,
+ SlangParameterCategory category)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return 0;
+ if (!varLayout)
+ return 0;
auto info = varLayout->FindResourceInfo(LayoutResourceKind(category));
@@ -3004,10 +3238,12 @@ SLANG_API size_t spReflectionVariableLayout_GetSpace(SlangReflectionVariableLayo
return space;
}
-SLANG_API char const* spReflectionVariableLayout_GetSemanticName(SlangReflectionVariableLayout* inVarLayout)
+SLANG_API char const* spReflectionVariableLayout_GetSemanticName(
+ SlangReflectionVariableLayout* inVarLayout)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return 0;
+ if (!varLayout)
+ return 0;
if (!(varLayout->flags & Slang::VarLayoutFlag::HasSemantic))
return 0;
@@ -3015,10 +3251,12 @@ SLANG_API char const* spReflectionVariableLayout_GetSemanticName(SlangReflection
return varLayout->semanticName.getBuffer();
}
-SLANG_API size_t spReflectionVariableLayout_GetSemanticIndex(SlangReflectionVariableLayout* inVarLayout)
+SLANG_API size_t
+spReflectionVariableLayout_GetSemanticIndex(SlangReflectionVariableLayout* inVarLayout)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return 0;
+ if (!varLayout)
+ return 0;
if (!(varLayout->flags & Slang::VarLayoutFlag::HasSemantic))
return 0;
@@ -3026,11 +3264,11 @@ SLANG_API size_t spReflectionVariableLayout_GetSemanticIndex(SlangReflectionVari
return varLayout->semanticIndex;
}
-SLANG_API SlangStage spReflectionVariableLayout_getStage(
- SlangReflectionVariableLayout* inVarLayout)
+SLANG_API SlangStage spReflectionVariableLayout_getStage(SlangReflectionVariableLayout* inVarLayout)
{
auto varLayout = convert(inVarLayout);
- if(!varLayout) return SLANG_STAGE_NONE;
+ if (!varLayout)
+ return SLANG_STAGE_NONE;
// A parameter that is not a varying input or output is
// not considered to belong to a single stage.
@@ -3038,8 +3276,8 @@ SLANG_API SlangStage spReflectionVariableLayout_getStage(
// TODO: We might need to reconsider this for, e.g., entry
// point parameters, where they might be stage-specific even
// if they are uniform.
- if (!varLayout->FindResourceInfo(Slang::LayoutResourceKind::VaryingInput)
- && !varLayout->FindResourceInfo(Slang::LayoutResourceKind::VaryingOutput))
+ if (!varLayout->FindResourceInfo(Slang::LayoutResourceKind::VaryingInput) &&
+ !varLayout->FindResourceInfo(Slang::LayoutResourceKind::VaryingOutput))
{
return SLANG_STAGE_NONE;
}
@@ -3053,7 +3291,7 @@ SLANG_API SlangStage spReflectionVariableLayout_getStage(
// information, so doing that walk would be tricky right now, so
// it is easier to just bloat the representation and store yet another
// field on every variable layout.
- return (SlangStage) varLayout->stage;
+ return (SlangStage)varLayout->stage;
}
// Function Reflection
@@ -3061,7 +3299,8 @@ SLANG_API SlangStage spReflectionVariableLayout_getStage(
SLANG_API SlangReflectionDecl* spReflectionFunction_asDecl(SlangReflectionFunction* inFunc)
{
auto func = convertToFunc(inFunc);
- if (!func) return nullptr;
+ if (!func)
+ return nullptr;
return (SlangReflectionDecl*)func.getDecl();
}
@@ -3069,7 +3308,8 @@ SLANG_API SlangReflectionDecl* spReflectionFunction_asDecl(SlangReflectionFuncti
SLANG_API char const* spReflectionFunction_GetName(SlangReflectionFunction* inFunc)
{
auto func = convertToFunc(inFunc);
- if (!func) return nullptr;
+ if (!func)
+ return nullptr;
return getText(func.getDecl()->getName()).getBuffer();
}
@@ -3077,7 +3317,8 @@ SLANG_API char const* spReflectionFunction_GetName(SlangReflectionFunction* inFu
SLANG_API SlangReflectionType* spReflectionFunction_GetResultType(SlangReflectionFunction* inFunc)
{
auto func = convertToFunc(inFunc);
- if (!func) return nullptr;
+ if (!func)
+ return nullptr;
auto rawType = func.getDecl()->returnType.type;
auto astBuilder = rawType->getASTBuilderForReflection();
@@ -3085,13 +3326,17 @@ SLANG_API SlangReflectionType* spReflectionFunction_GetResultType(SlangReflectio
return convert((Type*)rawType->substitute(astBuilder, SubstitutionSet(func.declRefBase)));
}
-SLANG_API SlangReflectionModifier* spReflectionFunction_FindModifier(SlangReflectionFunction* inFunc, SlangModifierID modifierID)
+SLANG_API SlangReflectionModifier* spReflectionFunction_FindModifier(
+ SlangReflectionFunction* inFunc,
+ SlangModifierID modifierID)
{
auto funcDeclRef = convertToFunc(inFunc);
- if (!funcDeclRef) return nullptr;
+ if (!funcDeclRef)
+ return nullptr;
auto varRefl = convert(funcDeclRef.as<Decl>());
- if (!varRefl) return nullptr;
+ if (!varRefl)
+ return nullptr;
return spReflectionVariable_FindModifier(varRefl, modifierID);
}
@@ -3099,22 +3344,30 @@ SLANG_API SlangReflectionModifier* spReflectionFunction_FindModifier(SlangReflec
SLANG_API unsigned int spReflectionFunction_GetUserAttributeCount(SlangReflectionFunction* inFunc)
{
auto func = convertToFunc(inFunc);
- if (!func) return 0;
+ if (!func)
+ return 0;
return getUserAttributeCount(func.getDecl());
}
-SLANG_API SlangReflectionUserAttribute* spReflectionFunction_GetUserAttribute(SlangReflectionFunction* inFunc, unsigned int index)
+SLANG_API SlangReflectionUserAttribute* spReflectionFunction_GetUserAttribute(
+ SlangReflectionFunction* inFunc,
+ unsigned int index)
{
auto func = convertToFunc(inFunc);
- if (!func) return nullptr;
+ if (!func)
+ return nullptr;
return getUserAttributeByIndex(func.getDecl(), index);
}
-SLANG_API SlangReflectionUserAttribute* spReflectionFunction_FindUserAttributeByName(SlangReflectionFunction* inFunc, SlangSession* session, char const* name)
+SLANG_API SlangReflectionUserAttribute* spReflectionFunction_FindUserAttributeByName(
+ SlangReflectionFunction* inFunc,
+ SlangSession* session,
+ char const* name)
{
auto func = convertToFunc(inFunc);
- if (!func) return nullptr;
+ if (!func)
+ return nullptr;
return findUserAttributeByName(asInternal(session), func.getDecl(), name);
}
@@ -3122,22 +3375,27 @@ SLANG_API SlangReflectionUserAttribute* spReflectionFunction_FindUserAttributeBy
SLANG_API unsigned int spReflectionFunction_GetParameterCount(SlangReflectionFunction* inFunc)
{
auto func = convertToFunc(inFunc);
- if (!func) return 0;
+ if (!func)
+ return 0;
return (unsigned int)func.getDecl()->getParameters().getCount();
}
-SLANG_API SlangReflectionVariable* spReflectionFunction_GetParameter(SlangReflectionFunction* inFunc, unsigned int index)
+SLANG_API SlangReflectionVariable* spReflectionFunction_GetParameter(
+ SlangReflectionFunction* inFunc,
+ unsigned int index)
{
auto func = convertToFunc(inFunc);
- if (!func) return nullptr;
+ if (!func)
+ return nullptr;
auto astBuilder = getModule(func.getDecl())->getLinkage()->getASTBuilder();
return convert(getParameters(astBuilder, func)[index]);
}
-SLANG_API SlangReflectionGeneric* spReflectionFunction_GetGenericContainer(SlangReflectionFunction* func)
+SLANG_API SlangReflectionGeneric* spReflectionFunction_GetGenericContainer(
+ SlangReflectionFunction* func)
{
auto declRef = convertToFunc(func);
if (!declRef)
@@ -3146,7 +3404,9 @@ SLANG_API SlangReflectionGeneric* spReflectionFunction_GetGenericContainer(Slang
return convertDeclToGeneric(getInnermostGenericParent(declRef));
}
-SLANG_API SlangReflectionFunction* spReflectionFunction_applySpecializations(SlangReflectionFunction* func, SlangReflectionGeneric* generic)
+SLANG_API SlangReflectionFunction* spReflectionFunction_applySpecializations(
+ SlangReflectionFunction* func,
+ SlangReflectionGeneric* generic)
{
auto declRef = convertToFunc(func);
auto genericDeclRef = convertGenericToDeclRef(generic);
@@ -3183,7 +3443,7 @@ SLANG_API SlangReflectionFunction* spReflectionFunction_specializeWithArgTypes(
{
return nullptr;
}
-
+
List<Type*> argTypeList;
for (SlangInt ii = 0; ii < argTypeCount; ++ii)
{
@@ -3191,10 +3451,11 @@ SLANG_API SlangReflectionFunction* spReflectionFunction_specializeWithArgTypes(
argTypeList.add(argType);
}
- try
+ try
{
DiagnosticSink sink(linkage->getSourceManager(), Lexer::sourceLocationLexer);
- auto resultFunc = linkage->specializeWithArgTypes(funcExpr, argTypeList, &sink).as<FunctionDeclBase>();
+ auto resultFunc =
+ linkage->specializeWithArgTypes(funcExpr, argTypeList, &sink).as<FunctionDeclBase>();
if (sink.getErrorCount() != 0)
return nullptr; // Failed coercion.
@@ -3207,19 +3468,18 @@ SLANG_API SlangReflectionFunction* spReflectionFunction_specializeWithArgTypes(
}
}
-SLANG_API bool spReflectionFunction_isOverloaded(
- SlangReflectionFunction* func)
+SLANG_API bool spReflectionFunction_isOverloaded(SlangReflectionFunction* func)
{
return (convertToOverloadedFunc(func) != nullptr);
}
-SLANG_API unsigned int spReflectionFunction_getOverloadCount(
- SlangReflectionFunction* func)
+SLANG_API unsigned int spReflectionFunction_getOverloadCount(SlangReflectionFunction* func)
{
auto overloadedFunc = convertToOverloadedFunc(func);
- if (!overloadedFunc) return 1;
+ if (!overloadedFunc)
+ return 1;
- return (unsigned int) overloadedFunc->lookupResult2.items.getCount();
+ return (unsigned int)overloadedFunc->lookupResult2.items.getCount();
}
SLANG_API SlangReflectionFunction* spReflectionFunction_getOverload(
@@ -3227,7 +3487,8 @@ SLANG_API SlangReflectionFunction* spReflectionFunction_getOverload(
unsigned int index)
{
auto overloadedFunc = convertToOverloadedFunc(func);
- if (!overloadedFunc) return nullptr;
+ if (!overloadedFunc)
+ return nullptr;
auto declRef = overloadedFunc->lookupResult2.items[index].declRef;
if (auto funcDeclRef = declRef.as<FunctionDeclBase>())
@@ -3238,13 +3499,15 @@ SLANG_API SlangReflectionFunction* spReflectionFunction_getOverload(
{
auto astBuilder = getModule(genericDeclRef.getDecl())->getLinkage()->getASTBuilder();
auto innerDeclRef = substituteDeclRef(
- SubstitutionSet(genericDeclRef), astBuilder, genericDeclRef.getDecl()->inner);
- return convert(
- createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, innerDeclRef).as<FunctionDeclBase>());
+ SubstitutionSet(genericDeclRef),
+ astBuilder,
+ genericDeclRef.getDecl()->inner);
+ return convert(createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, innerDeclRef)
+ .as<FunctionDeclBase>());
}
return nullptr;
-}
+}
// Abstract decl reflection
@@ -3255,11 +3518,13 @@ SLANG_API unsigned int spReflectionDecl_getChildrenCount(SlangReflectionDecl* pa
{
return (unsigned int)as<ContainerDecl>(decl)->members.getCount();
}
-
+
return 0;
}
-SLANG_API SlangReflectionDecl* spReflectionDecl_getChild(SlangReflectionDecl* parentDecl, unsigned int index)
+SLANG_API SlangReflectionDecl* spReflectionDecl_getChild(
+ SlangReflectionDecl* parentDecl,
+ unsigned int index)
{
Decl* decl = (Decl*)parentDecl;
if (auto containerDecl = as<ContainerDecl>(decl))
@@ -3274,7 +3539,7 @@ SLANG_API SlangReflectionDecl* spReflectionDecl_getChild(SlangReflectionDecl* pa
SLANG_API char const* spReflectionDecl_getName(SlangReflectionDecl* decl)
{
Decl* slangDecl = (Decl*)decl;
-
+
if (auto name = slangDecl->getName())
return getText(name).getBuffer();
@@ -3314,7 +3579,7 @@ SLANG_API SlangDeclKind spReflectionDecl_getKind(SlangReflectionDecl* decl)
SLANG_API SlangReflectionFunction* spReflectionDecl_castToFunction(SlangReflectionDecl* decl)
{
- Decl* slangDecl = (Decl*) decl;
+ Decl* slangDecl = (Decl*)decl;
if (auto funcDecl = as<FunctionDeclBase>(slangDecl))
{
return convert(DeclRef<FunctionDeclBase>(funcDecl->getDefaultDeclRef()));
@@ -3326,7 +3591,7 @@ SLANG_API SlangReflectionFunction* spReflectionDecl_castToFunction(SlangReflecti
SLANG_API SlangReflectionVariable* spReflectionDecl_castToVariable(SlangReflectionDecl* decl)
{
- Decl* slangDecl = (Decl*) decl;
+ Decl* slangDecl = (Decl*)decl;
if (auto varDecl = as<VarDeclBase>(slangDecl))
{
return convert(DeclRef(varDecl));
@@ -3338,7 +3603,7 @@ SLANG_API SlangReflectionVariable* spReflectionDecl_castToVariable(SlangReflecti
SLANG_API SlangReflectionGeneric* spReflectionDecl_castToGeneric(SlangReflectionDecl* decl)
{
- Decl* slangDecl = (Decl*) decl;
+ Decl* slangDecl = (Decl*)decl;
if (auto genericInnerDecl = as<GenericDecl>(slangDecl)->inner)
{
return convertDeclToGeneric(genericInnerDecl);
@@ -3378,32 +3643,42 @@ SLANG_API SlangReflectionDecl* spReflectionDecl_getParent(SlangReflectionDecl* d
SLANG_API SlangReflectionDecl* spReflectionGeneric_asDecl(SlangReflectionGeneric* generic)
{
- return (SlangReflectionDecl*) convertGenericToDeclRef(generic).getDecl()->parentDecl;
+ return (SlangReflectionDecl*)convertGenericToDeclRef(generic).getDecl()->parentDecl;
}
SLANG_API char const* spReflectionGeneric_GetName(SlangReflectionGeneric* generic)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return nullptr;
+ if (!slangGeneric)
+ return nullptr;
return getText(slangGeneric.getDecl()->getName()).getBuffer();
}
SLANG_API unsigned int spReflectionGeneric_GetTypeParameterCount(SlangReflectionGeneric* generic)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return 0;
+ if (!slangGeneric)
+ return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
- return (unsigned int) getMembersOfType<GenericTypeParamDecl>(astBuilder, slangGeneric.getDecl()->parentDecl).getCount();
+ return (unsigned int)getMembersOfType<GenericTypeParamDecl>(
+ astBuilder,
+ slangGeneric.getDecl()->parentDecl)
+ .getCount();
}
-SLANG_API SlangReflectionVariable* spReflectionGeneric_GetTypeParameter(SlangReflectionGeneric* generic, unsigned index)
+SLANG_API SlangReflectionVariable* spReflectionGeneric_GetTypeParameter(
+ SlangReflectionGeneric* generic,
+ unsigned index)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return nullptr;
+ if (!slangGeneric)
+ return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
- auto paramDeclRef = getMembersOfType<GenericTypeParamDecl>(astBuilder, slangGeneric.getDecl()->parentDecl)[index];
+ auto paramDeclRef = getMembersOfType<GenericTypeParamDecl>(
+ astBuilder,
+ slangGeneric.getDecl()->parentDecl)[index];
return convert(substituteDeclRef(SubstitutionSet(slangGeneric), astBuilder, paramDeclRef));
}
@@ -3411,33 +3686,45 @@ SLANG_API SlangReflectionVariable* spReflectionGeneric_GetTypeParameter(SlangRef
SLANG_API unsigned int spReflectionGeneric_GetValueParameterCount(SlangReflectionGeneric* generic)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return 0;
+ if (!slangGeneric)
+ return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
- return (unsigned int) getMembersOfType<GenericValueParamDecl>(astBuilder, slangGeneric.getDecl()->parentDecl).getCount();
+ return (unsigned int)getMembersOfType<GenericValueParamDecl>(
+ astBuilder,
+ slangGeneric.getDecl()->parentDecl)
+ .getCount();
}
-SLANG_API SlangReflectionVariable* spReflectionGeneric_GetValueParameter(SlangReflectionGeneric* generic, unsigned index)
+SLANG_API SlangReflectionVariable* spReflectionGeneric_GetValueParameter(
+ SlangReflectionGeneric* generic,
+ unsigned index)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return nullptr;
+ if (!slangGeneric)
+ return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
- auto paramDeclRef = getMembersOfType<GenericValueParamDecl>(astBuilder, slangGeneric.getDecl()->parentDecl)[index];
+ auto paramDeclRef = getMembersOfType<GenericValueParamDecl>(
+ astBuilder,
+ slangGeneric.getDecl()->parentDecl)[index];
return convert(substituteDeclRef(SubstitutionSet(slangGeneric), astBuilder, paramDeclRef));
}
-SLANG_API unsigned int spReflectionGeneric_GetTypeParameterConstraintCount(SlangReflectionGeneric* generic, SlangReflectionVariable* typeParam)
+SLANG_API unsigned int spReflectionGeneric_GetTypeParameterConstraintCount(
+ SlangReflectionGeneric* generic,
+ SlangReflectionVariable* typeParam)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return 0;
+ if (!slangGeneric)
+ return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
if (auto typeParamDecl = as<GenericTypeParamDecl>(convert(typeParam).getDecl()))
{
auto constraints = getCanonicalGenericConstraints(
- astBuilder,
+ astBuilder,
DeclRef<GenericDecl>(slangGeneric.getDecl()->parentDecl));
return (unsigned int)(constraints[typeParamDecl]).getValue().getCount();
}
@@ -3445,10 +3732,14 @@ SLANG_API unsigned int spReflectionGeneric_GetTypeParameterConstraintCount(Slang
return 0;
}
-SLANG_API SlangReflectionType* spReflectionGeneric_GetTypeParameterConstraintType(SlangReflectionGeneric* generic, SlangReflectionVariable* typeParam, unsigned index)
+SLANG_API SlangReflectionType* spReflectionGeneric_GetTypeParameterConstraintType(
+ SlangReflectionGeneric* generic,
+ SlangReflectionVariable* typeParam,
+ unsigned index)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return nullptr;
+ if (!slangGeneric)
+ return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
if (auto typeParamDecl = as<GenericTypeParamDecl>(convert(typeParam).getDecl()))
@@ -3468,7 +3759,8 @@ SLANG_API SlangReflectionType* spReflectionGeneric_GetTypeParameterConstraintTyp
SLANG_API SlangDeclKind spReflectionGeneric_GetInnerKind(SlangReflectionGeneric* generic)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return SLANG_DECL_KIND_UNSUPPORTED_FOR_REFLECTION;
+ if (!slangGeneric)
+ return SLANG_DECL_KIND_UNSUPPORTED_FOR_REFLECTION;
return spReflectionDecl_getKind((SlangReflectionDecl*)slangGeneric.getDecl());
}
@@ -3476,31 +3768,37 @@ SLANG_API SlangDeclKind spReflectionGeneric_GetInnerKind(SlangReflectionGeneric*
SLANG_API SlangReflectionDecl* spReflectionGeneric_GetInnerDecl(SlangReflectionGeneric* generic)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return nullptr;
+ if (!slangGeneric)
+ return nullptr;
return (SlangReflectionDecl*)slangGeneric.getDecl();
}
-SLANG_API SlangReflectionGeneric* spReflectionGeneric_GetOuterGenericContainer(SlangReflectionGeneric* generic)
+SLANG_API SlangReflectionGeneric* spReflectionGeneric_GetOuterGenericContainer(
+ SlangReflectionGeneric* generic)
{
auto declRef = convertGenericToDeclRef(generic);
-
+
auto astBuilder = getModule(declRef.getDecl())->getLinkage()->getASTBuilder();
- return convertDeclToGeneric(
- getInnermostGenericParent(
- substituteDeclRef(
- SubstitutionSet(declRef),
- astBuilder,
- createDefaultSubstitutionsIfNeeded(astBuilder, nullptr, DeclRef(declRef.getDecl()->parentDecl)))));
+ return convertDeclToGeneric(getInnermostGenericParent(substituteDeclRef(
+ SubstitutionSet(declRef),
+ astBuilder,
+ createDefaultSubstitutionsIfNeeded(
+ astBuilder,
+ nullptr,
+ DeclRef(declRef.getDecl()->parentDecl)))));
}
-SLANG_API SlangReflectionType* spReflectionGeneric_GetConcreteType(SlangReflectionGeneric* generic, SlangReflectionVariable* typeParam)
+SLANG_API SlangReflectionType* spReflectionGeneric_GetConcreteType(
+ SlangReflectionGeneric* generic,
+ SlangReflectionVariable* typeParam)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return nullptr;
+ if (!slangGeneric)
+ return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
-
+
auto genericType = DeclRefType::create(astBuilder, convert(typeParam));
auto substType = substituteType(SubstitutionSet(slangGeneric), astBuilder, genericType);
@@ -3513,17 +3811,22 @@ SLANG_API SlangReflectionType* spReflectionGeneric_GetConcreteType(SlangReflecti
return nullptr;
}
-SLANG_API int64_t spReflectionGeneric_GetConcreteIntVal(SlangReflectionGeneric* generic, SlangReflectionVariable* valueParam)
+SLANG_API int64_t spReflectionGeneric_GetConcreteIntVal(
+ SlangReflectionGeneric* generic,
+ SlangReflectionVariable* valueParam)
{
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return 0;
+ if (!slangGeneric)
+ return 0;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
auto valueParamDeclRef = convert(valueParam);
Val* valResult = astBuilder->getOrCreate<GenericParamIntVal>(
- valueParamDeclRef.substitute(astBuilder, as<GenericValueParamDecl>(valueParamDeclRef.getDecl())->getType()),
- valueParamDeclRef);
+ valueParamDeclRef.substitute(
+ astBuilder,
+ as<GenericValueParamDecl>(valueParamDeclRef.getDecl())->getType()),
+ valueParamDeclRef);
valResult = valResult->substitute(astBuilder, SubstitutionSet(slangGeneric));
auto intVal = as<ConstantIntVal>(valResult);
@@ -3535,7 +3838,9 @@ SLANG_API int64_t spReflectionGeneric_GetConcreteIntVal(SlangReflectionGeneric*
return 0;
}
-SLANG_API SlangReflectionGeneric* spReflectionGeneric_applySpecializations(SlangReflectionGeneric* currGeneric, SlangReflectionGeneric* generic)
+SLANG_API SlangReflectionGeneric* spReflectionGeneric_applySpecializations(
+ SlangReflectionGeneric* currGeneric,
+ SlangReflectionGeneric* generic)
{
auto declRef = convertGenericToDeclRef(currGeneric);
auto genericDeclRef = convertGenericToDeclRef(generic);
@@ -3554,7 +3859,7 @@ SLANG_API SlangReflectionGeneric* spReflectionGeneric_applySpecializations(Slang
SLANG_API unsigned spReflectionParameter_GetBindingIndex(SlangReflectionParameter* inVarLayout)
{
SlangReflectionVariableLayout* varLayout = (SlangReflectionVariableLayout*)inVarLayout;
- return (unsigned) spReflectionVariableLayout_GetOffset(
+ return (unsigned)spReflectionVariableLayout_GetOffset(
varLayout,
spReflectionTypeLayout_GetParameterCategory(
spReflectionVariableLayout_GetTypeLayout(varLayout)));
@@ -3563,7 +3868,7 @@ SLANG_API unsigned spReflectionParameter_GetBindingIndex(SlangReflectionParamete
SLANG_API unsigned spReflectionParameter_GetBindingSpace(SlangReflectionParameter* inVarLayout)
{
SlangReflectionVariableLayout* varLayout = (SlangReflectionVariableLayout*)inVarLayout;
- return (unsigned) spReflectionVariableLayout_GetSpace(
+ return (unsigned)spReflectionVariableLayout_GetSpace(
varLayout,
spReflectionTypeLayout_GetParameterCategory(
spReflectionVariableLayout_GetTypeLayout(varLayout)));
@@ -3577,24 +3882,30 @@ SLANG_API SlangResult spIsParameterLocationUsed(
SlangUInt spaceIndex,
SlangUInt registerIndex,
bool& outUsed)
-{
+{
if (!request)
return SLANG_E_INVALID_ARG;
-
- return request->isParameterLocationUsed(entryPointIndex, targetIndex, category, spaceIndex, registerIndex, outUsed);
+
+ return request->isParameterLocationUsed(
+ entryPointIndex,
+ targetIndex,
+ category,
+ spaceIndex,
+ registerIndex,
+ outUsed);
}
// Entry Point Reflection
-SLANG_API char const* spReflectionEntryPoint_getName(
- SlangReflectionEntryPoint* inEntryPoint)
+SLANG_API char const* spReflectionEntryPoint_getName(SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
return entryPointLayout ? getCstr(entryPointLayout->name) : nullptr;
}
-SLANG_API char const* spReflectionEntryPoint_getNameOverride(SlangReflectionEntryPoint* inEntryPoint)
+SLANG_API char const* spReflectionEntryPoint_getNameOverride(
+ SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
if (entryPointLayout)
@@ -3607,7 +3918,8 @@ SLANG_API char const* spReflectionEntryPoint_getNameOverride(SlangReflectionEntr
return nullptr;
}
-SLANG_API SlangReflectionFunction* spReflectionEntryPoint_getFunction(SlangReflectionEntryPoint* inEntryPoint)
+SLANG_API SlangReflectionFunction* spReflectionEntryPoint_getFunction(
+ SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
if (entryPointLayout)
@@ -3617,21 +3929,22 @@ SLANG_API SlangReflectionFunction* spReflectionEntryPoint_getFunction(SlangRefle
return nullptr;
}
-SLANG_API unsigned spReflectionEntryPoint_getParameterCount(
- SlangReflectionEntryPoint* inEntryPoint)
+SLANG_API unsigned spReflectionEntryPoint_getParameterCount(SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout) return 0;
+ if (!entryPointLayout)
+ return 0;
return getParameterCount(entryPointLayout->parametersLayout->typeLayout);
}
SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getParameterByIndex(
- SlangReflectionEntryPoint* inEntryPoint,
- unsigned index)
+ SlangReflectionEntryPoint* inEntryPoint,
+ unsigned index)
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout) return 0;
+ if (!entryPointLayout)
+ return 0;
return convert(getParameterByIndex(entryPointLayout->parametersLayout->typeLayout, index));
}
@@ -3640,26 +3953,31 @@ SLANG_API SlangStage spReflectionEntryPoint_getStage(SlangReflectionEntryPoint*
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout) return SLANG_STAGE_NONE;
+ if (!entryPointLayout)
+ return SLANG_STAGE_NONE;
return SlangStage(entryPointLayout->profile.getStage());
}
SLANG_API void spReflectionEntryPoint_getComputeThreadGroupSize(
- SlangReflectionEntryPoint* inEntryPoint,
- SlangUInt axisCount,
- SlangUInt* outSizeAlongAxis)
+ SlangReflectionEntryPoint* inEntryPoint,
+ SlangUInt axisCount,
+ SlangUInt* outSizeAlongAxis)
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout) return;
- if(!axisCount) return;
- if(!outSizeAlongAxis) return;
+ if (!entryPointLayout)
+ return;
+ if (!axisCount)
+ return;
+ if (!outSizeAlongAxis)
+ return;
auto entryPointFunc = entryPointLayout->entryPoint;
- if(!entryPointFunc) return;
+ if (!entryPointFunc)
+ return;
- SlangUInt sizeAlongAxis[3] = { 1, 1, 1 };
+ SlangUInt sizeAlongAxis[3] = {1, 1, 1};
// First look for the HLSL case, where we have an attribute attached to the entry point function
auto numThreadsAttribute = entryPointFunc.getDecl()->findModifier<NumThreadsAttribute>();
@@ -3681,10 +3999,13 @@ SLANG_API void spReflectionEntryPoint_getComputeThreadGroupSize(
//
- if(axisCount > 0) outSizeAlongAxis[0] = sizeAlongAxis[0];
- if(axisCount > 1) outSizeAlongAxis[1] = sizeAlongAxis[1];
- if(axisCount > 2) outSizeAlongAxis[2] = sizeAlongAxis[2];
- for( SlangUInt aa = 3; aa < axisCount; ++aa )
+ if (axisCount > 0)
+ outSizeAlongAxis[0] = sizeAlongAxis[0];
+ if (axisCount > 1)
+ outSizeAlongAxis[1] = sizeAlongAxis[1];
+ if (axisCount > 2)
+ outSizeAlongAxis[2] = sizeAlongAxis[2];
+ for (SlangUInt aa = 3; aa < axisCount; ++aa)
{
outSizeAlongAxis[aa] = 1;
}
@@ -3696,11 +4017,14 @@ SLANG_API void spReflectionEntryPoint_getComputeWaveSize(
{
auto entryPointLayout = convert(inEntryPoint);
- if (!entryPointLayout) return;
- if (!outWaveSize) return;
+ if (!entryPointLayout)
+ return;
+ if (!outWaveSize)
+ return;
auto entryPointFunc = entryPointLayout->entryPoint;
- if (!entryPointFunc) return;
+ if (!entryPointFunc)
+ return;
// First look for the HLSL case, where we have an attribute attached to the entry point function
if (auto waveSizeAttribute = entryPointFunc.getDecl()->findModifier<WaveSizeAttribute>())
@@ -3712,11 +4036,10 @@ SLANG_API void spReflectionEntryPoint_getComputeWaveSize(
}
}
-SLANG_API int spReflectionEntryPoint_usesAnySampleRateInput(
- SlangReflectionEntryPoint* inEntryPoint)
+SLANG_API int spReflectionEntryPoint_usesAnySampleRateInput(SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout)
+ if (!entryPointLayout)
return 0;
if (entryPointLayout->profile.getStage() != Stage::Fragment)
@@ -3729,7 +4052,7 @@ SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getVarLayout(
SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout)
+ if (!entryPointLayout)
return nullptr;
return convert(entryPointLayout->parametersLayout);
@@ -3739,7 +4062,7 @@ SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getResultVarLayo
SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout)
+ if (!entryPointLayout)
return nullptr;
return convert(entryPointLayout->resultLayout);
@@ -3749,7 +4072,7 @@ SLANG_API int spReflectionEntryPoint_hasDefaultConstantBuffer(
SlangReflectionEntryPoint* inEntryPoint)
{
auto entryPointLayout = convert(inEntryPoint);
- if(!entryPointLayout)
+ if (!entryPointLayout)
return 0;
return hasDefaultConstantBuffer(entryPointLayout);
@@ -3757,31 +4080,34 @@ SLANG_API int spReflectionEntryPoint_hasDefaultConstantBuffer(
// SlangReflectionTypeParameter
-SLANG_API char const* spReflectionTypeParameter_GetName(SlangReflectionTypeParameter * inTypeParam)
+SLANG_API char const* spReflectionTypeParameter_GetName(SlangReflectionTypeParameter* inTypeParam)
{
auto specializationParam = convert(inTypeParam);
- if( auto genericParamLayout = as<GenericSpecializationParamLayout>(specializationParam) )
+ if (auto genericParamLayout = as<GenericSpecializationParamLayout>(specializationParam))
{
return genericParamLayout->decl->getName()->text.getBuffer();
}
- // TODO: Add case for existential type parameter? They don't have as simple of a notion of "name" as the generic case...
+ // TODO: Add case for existential type parameter? They don't have as simple of a notion of
+ // "name" as the generic case...
return nullptr;
}
-SLANG_API unsigned spReflectionTypeParameter_GetIndex(SlangReflectionTypeParameter * inTypeParam)
+SLANG_API unsigned spReflectionTypeParameter_GetIndex(SlangReflectionTypeParameter* inTypeParam)
{
auto typeParam = convert(inTypeParam);
return (unsigned)(typeParam->index);
}
-SLANG_API unsigned int spReflectionTypeParameter_GetConstraintCount(SlangReflectionTypeParameter* inTypeParam)
+SLANG_API unsigned int spReflectionTypeParameter_GetConstraintCount(
+ SlangReflectionTypeParameter* inTypeParam)
{
auto specializationParam = convert(inTypeParam);
- if(auto genericParamLayout = as<GenericSpecializationParamLayout>(specializationParam))
+ if (auto genericParamLayout = as<GenericSpecializationParamLayout>(specializationParam))
{
- if( auto globalGenericParamDecl = as<GlobalGenericParamDecl>(genericParamLayout->decl) )
+ if (auto globalGenericParamDecl = as<GlobalGenericParamDecl>(genericParamLayout->decl))
{
- auto constraints = globalGenericParamDecl->getMembersOfType<GenericTypeConstraintDecl>();
+ auto constraints =
+ globalGenericParamDecl->getMembersOfType<GenericTypeConstraintDecl>();
return (unsigned int)constraints.getCount();
}
// TODO: Add case for entry-point generic parameters.
@@ -3790,14 +4116,17 @@ SLANG_API unsigned int spReflectionTypeParameter_GetConstraintCount(SlangReflect
return 0;
}
-SLANG_API SlangReflectionType* spReflectionTypeParameter_GetConstraintByIndex(SlangReflectionTypeParameter * inTypeParam, unsigned index)
+SLANG_API SlangReflectionType* spReflectionTypeParameter_GetConstraintByIndex(
+ SlangReflectionTypeParameter* inTypeParam,
+ unsigned index)
{
auto specializationParam = convert(inTypeParam);
- if(auto genericParamLayout = as<GenericSpecializationParamLayout>(specializationParam))
+ if (auto genericParamLayout = as<GenericSpecializationParamLayout>(specializationParam))
{
- if( auto globalGenericParamDecl = as<GlobalGenericParamDecl>(genericParamLayout->decl) )
+ if (auto globalGenericParamDecl = as<GlobalGenericParamDecl>(genericParamLayout->decl))
{
- auto constraints = globalGenericParamDecl->getMembersOfType<GenericTypeConstraintDecl>();
+ auto constraints =
+ globalGenericParamDecl->getMembersOfType<GenericTypeConstraintDecl>();
return (SlangReflectionType*)constraints[index]->sup.Ptr();
}
// TODO: Add case for entry-point generic parameters.
@@ -3811,19 +4140,23 @@ SLANG_API SlangReflectionType* spReflectionTypeParameter_GetConstraintByIndex(Sl
SLANG_API unsigned spReflection_GetParameterCount(SlangReflection* inProgram)
{
auto program = convert(inProgram);
- if(!program) return 0;
+ if (!program)
+ return 0;
auto globalStructLayout = getGlobalStructLayout(program);
if (!globalStructLayout)
return 0;
- return (unsigned) globalStructLayout->fields.getCount();
+ return (unsigned)globalStructLayout->fields.getCount();
}
-SLANG_API SlangReflectionParameter* spReflection_GetParameterByIndex(SlangReflection* inProgram, unsigned index)
+SLANG_API SlangReflectionParameter* spReflection_GetParameterByIndex(
+ SlangReflection* inProgram,
+ unsigned index)
{
auto program = convert(inProgram);
- if(!program) return nullptr;
+ if (!program)
+ return nullptr;
auto globalStructLayout = getGlobalStructLayout(program);
if (!globalStructLayout)
@@ -3832,18 +4165,20 @@ SLANG_API SlangReflectionParameter* spReflection_GetParameterByIndex(SlangReflec
return convert(globalStructLayout->fields[index].Ptr());
}
-SLANG_API SlangReflectionVariableLayout* spReflection_getGlobalParamsVarLayout(SlangReflection* inProgram)
+SLANG_API SlangReflectionVariableLayout* spReflection_getGlobalParamsVarLayout(
+ SlangReflection* inProgram)
{
auto program = convert(inProgram);
- if(!program) return nullptr;
+ if (!program)
+ return nullptr;
return convert(program->parametersLayout);
}
-SLANG_API unsigned int spReflection_GetTypeParameterCount(SlangReflection * reflection)
+SLANG_API unsigned int spReflection_GetTypeParameterCount(SlangReflection* reflection)
{
auto program = convert(reflection);
- return (unsigned int) program->specializationParams.getCount();
+ return (unsigned int)program->specializationParams.getCount();
}
SLANG_API slang::ISession* spReflection_GetSession(SlangReflection* reflection)
@@ -3852,26 +4187,31 @@ SLANG_API slang::ISession* spReflection_GetSession(SlangReflection* reflection)
return program->getTargetProgram()->getTargetReq()->getLinkage();
}
-SLANG_API SlangReflectionTypeParameter* spReflection_GetTypeParameterByIndex(SlangReflection * reflection, unsigned int index)
+SLANG_API SlangReflectionTypeParameter* spReflection_GetTypeParameterByIndex(
+ SlangReflection* reflection,
+ unsigned int index)
{
auto program = convert(reflection);
- return (SlangReflectionTypeParameter*) program->specializationParams[index].Ptr();
+ return (SlangReflectionTypeParameter*)program->specializationParams[index].Ptr();
}
-SLANG_API SlangReflectionTypeParameter * spReflection_FindTypeParameter(SlangReflection * inProgram, char const * name)
+SLANG_API SlangReflectionTypeParameter* spReflection_FindTypeParameter(
+ SlangReflection* inProgram,
+ char const* name)
{
auto program = convert(inProgram);
- if (!program) return nullptr;
- for( auto& param : program->specializationParams )
+ if (!program)
+ return nullptr;
+ for (auto& param : program->specializationParams)
{
auto genericParamLayout = as<GenericSpecializationParamLayout>(param);
- if(!genericParamLayout)
+ if (!genericParamLayout)
continue;
- if(getText(genericParamLayout->decl->getName()) != UnownedTerminatedStringSlice(name))
+ if (getText(genericParamLayout->decl->getName()) != UnownedTerminatedStringSlice(name))
continue;
- return (SlangReflectionTypeParameter*) genericParamLayout;
+ return (SlangReflectionTypeParameter*)genericParamLayout;
}
return 0;
@@ -3880,28 +4220,35 @@ SLANG_API SlangReflectionTypeParameter * spReflection_FindTypeParameter(SlangRef
SLANG_API SlangUInt spReflection_getEntryPointCount(SlangReflection* inProgram)
{
auto program = convert(inProgram);
- if(!program) return 0;
+ if (!program)
+ return 0;
return SlangUInt(program->entryPoints.getCount());
}
-SLANG_API SlangReflectionEntryPoint* spReflection_getEntryPointByIndex(SlangReflection* inProgram, SlangUInt index)
+SLANG_API SlangReflectionEntryPoint* spReflection_getEntryPointByIndex(
+ SlangReflection* inProgram,
+ SlangUInt index)
{
auto program = convert(inProgram);
- if(!program) return 0;
+ if (!program)
+ return 0;
- return convert(program->entryPoints[(int) index].Ptr());
+ return convert(program->entryPoints[(int)index].Ptr());
}
-SLANG_API SlangReflectionEntryPoint* spReflection_findEntryPointByName(SlangReflection* inProgram, char const* name)
+SLANG_API SlangReflectionEntryPoint* spReflection_findEntryPointByName(
+ SlangReflection* inProgram,
+ char const* name)
{
auto program = convert(inProgram);
- if(!program) return 0;
+ if (!program)
+ return 0;
// TODO: improve on naive linear search
- for(auto ep : program->entryPoints)
+ for (auto ep : program->entryPoints)
{
- if(ep->entryPoint.getName()->text == name)
+ if (ep->entryPoint.getName()->text == name)
{
return convert(ep);
}
@@ -3913,40 +4260,50 @@ SLANG_API SlangReflectionEntryPoint* spReflection_findEntryPointByName(SlangRefl
SLANG_API SlangUInt spReflection_getGlobalConstantBufferBinding(SlangReflection* inProgram)
{
auto program = convert(inProgram);
- if (!program) return 0;
+ if (!program)
+ return 0;
auto cb = program->parametersLayout->FindResourceInfo(LayoutResourceKind::ConstantBuffer);
- if (!cb) return 0;
+ if (!cb)
+ return 0;
return cb->index;
}
SLANG_API size_t spReflection_getGlobalConstantBufferSize(SlangReflection* inProgram)
{
auto program = convert(inProgram);
- if (!program) return 0;
+ if (!program)
+ return 0;
auto structLayout = getGlobalStructLayout(program);
auto uniform = structLayout->FindResourceInfo(LayoutResourceKind::Uniform);
- if (!uniform) return 0;
+ if (!uniform)
+ return 0;
return getReflectionSize(uniform->count);
}
-SLANG_API SlangReflectionType* spReflection_specializeType(
- SlangReflection* inProgramLayout,
- SlangReflectionType* inType,
- SlangInt specializationArgCount,
+SLANG_API SlangReflectionType* spReflection_specializeType(
+ SlangReflection* inProgramLayout,
+ SlangReflectionType* inType,
+ SlangInt specializationArgCount,
SlangReflectionType* const* specializationArgs,
- ISlangBlob** outDiagnostics)
+ ISlangBlob** outDiagnostics)
{
auto programLayout = convert(inProgramLayout);
- if(!programLayout) return nullptr;
+ if (!programLayout)
+ return nullptr;
auto unspecializedType = convert(inType);
- if(!unspecializedType) return nullptr;
+ if (!unspecializedType)
+ return nullptr;
auto linkage = programLayout->getProgram()->getLinkage();
DiagnosticSink sink(linkage->getSourceManager(), Lexer::sourceLocationLexer);
- auto specializedType = linkage->specializeType(unspecializedType, specializationArgCount, (Type* const*) specializationArgs, &sink);
+ auto specializedType = linkage->specializeType(
+ unspecializedType,
+ specializationArgCount,
+ (Type* const*)specializationArgs,
+ &sink);
sink.getBlobIfNeeded(outDiagnostics);
@@ -3955,16 +4312,17 @@ SLANG_API SlangReflectionType* spReflection_specializeType(
SLANG_API SlangReflectionGeneric* spReflection_specializeGeneric(
- SlangReflection* inProgramLayout,
- SlangReflectionGeneric* generic,
- SlangInt argCount,
- SlangReflectionGenericArgType const* argTypes,
- SlangReflectionGenericArg const* args,
- ISlangBlob** outDiagnostics)
+ SlangReflection* inProgramLayout,
+ SlangReflectionGeneric* generic,
+ SlangInt argCount,
+ SlangReflectionGenericArgType const* argTypes,
+ SlangReflectionGenericArg const* args,
+ ISlangBlob** outDiagnostics)
{
auto programLayout = convert(inProgramLayout);
auto slangGeneric = convertGenericToDeclRef(generic);
- if (!slangGeneric) return nullptr;
+ if (!slangGeneric)
+ return nullptr;
auto astBuilder = getModule(slangGeneric.getDecl())->getLinkage()->getASTBuilder();
auto linkage = programLayout->getProgram()->getLinkage();
@@ -3979,7 +4337,7 @@ SLANG_API SlangReflectionGeneric* spReflection_specializeGeneric(
switch (argType)
{
- case SLANG_GENERIC_ARG_TYPE:
+ case SLANG_GENERIC_ARG_TYPE:
{
auto type = convert(arg.typeVal);
auto declRefType = as<DeclRefType>(type);
@@ -3989,7 +4347,7 @@ SLANG_API SlangReflectionGeneric* spReflection_specializeGeneric(
argExprs.add(declRefExpr);
break;
}
- case SLANG_GENERIC_ARG_INT:
+ case SLANG_GENERIC_ARG_INT:
{
auto literalExpr = astBuilder->create<IntegerLiteralExpr>();
literalExpr->value = args[i].intVal;
@@ -3997,7 +4355,7 @@ SLANG_API SlangReflectionGeneric* spReflection_specializeGeneric(
argExprs.add(literalExpr);
break;
}
- case SLANG_GENERIC_ARG_BOOL:
+ case SLANG_GENERIC_ARG_BOOL:
{
auto literalExpr = astBuilder->create<BoolLiteralExpr>();
literalExpr->value = args[i].boolVal;
@@ -4005,9 +4363,9 @@ SLANG_API SlangReflectionGeneric* spReflection_specializeGeneric(
argExprs.add(literalExpr);
break;
}
- default:
- // abort (TODO: throw a proper error)
- return nullptr;
+ default:
+ // abort (TODO: throw a proper error)
+ return nullptr;
}
}
@@ -4018,8 +4376,7 @@ SLANG_API SlangReflectionGeneric* spReflection_specializeGeneric(
}
-SLANG_API SlangUInt spReflection_getHashedStringCount(
- SlangReflection* reflection)
+SLANG_API SlangUInt spReflection_getHashedStringCount(SlangReflection* reflection)
{
auto programLayout = convert(reflection);
auto slices = programLayout->hashedStringLiteralPool.getAdded();
@@ -4027,7 +4384,7 @@ SLANG_API SlangUInt spReflection_getHashedStringCount(
}
SLANG_API const char* spReflection_getHashedString(
- SlangReflection* reflection,
+ SlangReflection* reflection,
SlangUInt index,
size_t* outCount)
{
@@ -4049,7 +4406,8 @@ SLANG_API SlangReflectionTypeLayout* spReflection_getGlobalParamsTypeLayout(
SlangReflection* reflection)
{
auto programLayout = convert(reflection);
- if(!programLayout) return nullptr;
+ if (!programLayout)
+ return nullptr;
return convert(programLayout->parametersLayout->typeLayout);
}