summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-04-15 23:28:28 -0700
committerGitHub <noreply@github.com>2024-04-15 23:28:28 -0700
commit3192f34f57abd3245995342a0a5971ebbbbd945c (patch)
treedc139be9fe9f4995bac96513571cc9e0526ce547 /source
parent030d7f45726187b5b23a3cfb9743166aa60fae30 (diff)
[GFX] Fix d3d12 buffer view creation logic for StructuredBuffers. (#3954)
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-array.h4
-rw-r--r--source/slang/slang-check-conformance.cpp10
-rw-r--r--source/slang/slang-check-decl.cpp10
-rw-r--r--source/slang/slang-check-impl.h3
-rw-r--r--source/slang/slang-parameter-binding.cpp36
-rw-r--r--source/slang/slang-reflection-api.cpp32
-rw-r--r--source/slang/slang-type-layout.cpp13
-rw-r--r--source/slang/slang-type-layout.h8
8 files changed, 77 insertions, 39 deletions
diff --git a/source/core/slang-array.h b/source/core/slang-array.h
index f1ed4fe0d..d24ff0970 100644
--- a/source/core/slang-array.h
+++ b/source/core/slang-array.h
@@ -159,14 +159,14 @@ namespace Slang
void insertArray(Array<T, SIZE>& arr, const T& val, TArgs... args)
{
arr.add(val);
- insertArray(arr, args...);
+ insertArray<T>(arr, args...);
}
template<typename ...TArgs>
auto makeArray(TArgs ...args) -> Array<typename FirstType<TArgs...>::Type, sizeof...(args)>
{
Array<typename FirstType<TArgs...>::Type, Index(sizeof...(args))> rs;
- insertArray(rs, args...);
+ insertArray<typename FirstType<TArgs...>::Type>(rs, args...);
return rs;
}
diff --git a/source/slang/slang-check-conformance.cpp b/source/slang/slang-check-conformance.cpp
index ff4a40031..a0e51b180 100644
--- a/source/slang/slang-check-conformance.cpp
+++ b/source/slang/slang-check-conformance.cpp
@@ -227,16 +227,6 @@ namespace Slang
return nullptr;
}
- bool SemanticsVisitor::isInterfaceType(Type* type)
- {
- if (auto declRefType = as<DeclRefType>(type))
- {
- if (auto interfaceDeclRef = declRefType->getDeclRef().as<InterfaceDecl>())
- return true;
- }
- return false;
- }
-
bool SemanticsVisitor::isValidGenericConstraintType(Type* type)
{
if (auto andType = as<AndType>(type))
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 5190f8c0e..4f8dd3dc5 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -1329,6 +1329,16 @@ namespace Slang
return arrayType->isUnsized();
}
+ bool isInterfaceType(Type* type)
+ {
+ if (auto declRefType = as<DeclRefType>(type))
+ {
+ if (auto interfaceDeclRef = declRefType->getDeclRef().as<InterfaceDecl>())
+ return true;
+ }
+ return false;
+ }
+
EnumDecl* isEnumType(Type* type)
{
if (auto declRefType = as<DeclRefType>(type))
diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h
index e6e980fe8..ff7ce6978 100644
--- a/source/slang/slang-check-impl.h
+++ b/source/slang/slang-check-impl.h
@@ -2040,7 +2040,6 @@ namespace Slang
SubtypeWitness* checkAndConstructSubtypeWitness(Type* subType, Type* superType);
- bool isInterfaceType(Type* type);
bool isValidGenericConstraintType(Type* type);
bool isTypeDifferentiable(Type* type);
@@ -2763,6 +2762,8 @@ namespace Slang
bool isUnsizedArrayType(Type* type);
+ bool isInterfaceType(Type* type);
+
EnumDecl* isEnumType(Type* type);
DeclVisibility getDeclVisibility(Decl* decl);
diff --git a/source/slang/slang-parameter-binding.cpp b/source/slang/slang-parameter-binding.cpp
index 6725380f2..516b9eb44 100644
--- a/source/slang/slang-parameter-binding.cpp
+++ b/source/slang/slang-parameter-binding.cpp
@@ -935,13 +935,13 @@ static void addExplicitParameterBinding(
if (overlappedVarLayout)
{
//legal if atomicUint
- if(parameterInfo->varLayout->varDecl.getDecl()->getType()->astNodeType == ASTNodeType::GLSLAtomicUintType
- && overlappedVarLayout->varDecl.getDecl()->getType()->astNodeType == ASTNodeType::GLSLAtomicUintType)
+ if(parameterInfo->varLayout->getVariable()->getType()->astNodeType == ASTNodeType::GLSLAtomicUintType
+ && overlappedVarLayout->getVariable()->getType()->astNodeType == ASTNodeType::GLSLAtomicUintType)
{
return;
}
- auto paramA = parameterInfo->varLayout->varDecl.getDecl();
- auto paramB = overlappedVarLayout->varDecl.getDecl();
+ auto paramA = parameterInfo->varLayout->getVariable();
+ auto paramB = overlappedVarLayout->getVariable();
auto& diagnosticInfo = Diagnostics::parameterBindingsOverlap;
@@ -1024,7 +1024,8 @@ static void addExplicitParameterBindings_HLSL(
// TODO: warning here!
}
- addExplicitParameterBinding(context, parameterInfo, varDecl.getDecl(), semanticInfo, count);
+ if (auto varDeclBase = varDecl.as<VarDeclBase>())
+ addExplicitParameterBinding(context, parameterInfo, varDeclBase.getDecl(), semanticInfo, count);
}
}
@@ -1133,10 +1134,12 @@ static void addExplicitParameterBindings_GLSL(
auto count = resInfo->count;
semanticInfo.kind = kind;
- addExplicitParameterBinding(context, parameterInfo, varDecl.getDecl(), semanticInfo, count);
- if (foundSubpass)
- addExplicitParameterBinding(context, parameterInfo, varDecl.getDecl(), subpassSemanticInfo, count);
-
+ if (auto varDeclBase = varDecl.as<VarDeclBase>())
+ {
+ addExplicitParameterBinding(context, parameterInfo, varDeclBase.getDecl(), semanticInfo, count);
+ if (foundSubpass)
+ addExplicitParameterBinding(context, parameterInfo, varDeclBase.getDecl(), subpassSemanticInfo, count);
+ }
return;
}
@@ -1147,7 +1150,7 @@ static void addExplicitParameterBindings_GLSL(
// If we have the options, but cannot infer bindings, we don't need to go further
if (hlslToVulkanLayoutOptions == nullptr || !hlslToVulkanLayoutOptions->canInferBindings())
{
- _maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl);
+ _maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as<VarDeclBase>());
return;
}
@@ -1169,7 +1172,7 @@ static void addExplicitParameterBindings_GLSL(
// We can't infer TextureSampler from HLSL (it's not an HLSL concept)
// So use default layout
- auto varType = varDecl.getDecl()->getType();
+ auto varType = getType(context->getASTBuilder(), varDecl.as<VarDeclBase>());
if (auto textureType = as<TextureType>(varType))
{
if (textureType->isCombined())
@@ -1187,7 +1190,7 @@ static void addExplicitParameterBindings_GLSL(
// If inference is not enabled for this kind, we can issue a warning
if (!hlslToVulkanLayoutOptions->canInfer(vulkanKind, hlslInfo.space))
{
- _maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl);
+ _maybeDiagnoseMissingVulkanLayoutModifier(context, varDecl.as<VarDeclBase>());
return;
}
@@ -1201,7 +1204,7 @@ static void addExplicitParameterBindings_GLSL(
const LayoutSize count = resInfo->count;
- addExplicitParameterBinding(context, parameterInfo, varDecl.getDecl(), semanticInfo, count);
+ addExplicitParameterBinding(context, parameterInfo, as<VarDeclBase>(varDecl.getDecl()), semanticInfo, count);
}
// Given a single parameter, collect whatever information we have on
@@ -2408,7 +2411,10 @@ struct ScopeLayoutBuilder
{
auto rules = m_layoutContext.rules;
m_pendingDataTypeLayoutBuilder.beginLayoutIfNeeded(nullptr, rules);
- auto fieldPendingDataVarLayout = m_pendingDataTypeLayoutBuilder.addField(varLayout->varDecl, fieldPendingDataTypeLayout);
+ auto varDeclBase = varLayout->varDecl.as<VarDeclBase>();
+ if (!varDeclBase)
+ return;
+ auto fieldPendingDataVarLayout = m_pendingDataTypeLayoutBuilder.addField(varDeclBase, fieldPendingDataTypeLayout);
m_structLayout->pendingDataTypeLayout = m_pendingDataTypeLayoutBuilder.getTypeLayout();
@@ -4011,7 +4017,7 @@ RefPtr<ProgramLayout> generateParameterBindings(
if( varLayout->typeLayout->FindResourceInfo(LayoutResourceKind::Uniform) )
{
needDefaultConstantBuffer = true;
- diagnoseGlobalUniform(&sharedContext, varLayout->varDecl.getDecl());
+ diagnoseGlobalUniform(&sharedContext, as<VarDeclBase>(varLayout->varDecl.getDecl()));
}
}
}
diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp
index 90103d8d9..ab73ce7f4 100644
--- a/source/slang/slang-reflection-api.cpp
+++ b/source/slang/slang-reflection-api.cpp
@@ -55,12 +55,12 @@ static inline SpecializationParamLayout* convert(SlangReflectionTypeParameter *
return (SpecializationParamLayout*) typeParam;
}
-static inline VarDeclBase* convert(SlangReflectionVariable* var)
+static inline Decl* convert(SlangReflectionVariable* var)
{
- return (VarDeclBase*) var;
+ return (Decl*) var;
}
-static inline SlangReflectionVariable* convert(VarDeclBase* var)
+static inline SlangReflectionVariable* convert(Decl* var)
{
return (SlangReflectionVariable*) var;
}
@@ -932,7 +932,7 @@ SLANG_API SlangInt spReflectionTypeLayout_findFieldIndexByName(SlangReflectionTy
for(Index f = 0; f < fieldCount; ++f)
{
auto field = structTypeLayout->fields[f];
- if(getReflectionName(field->varDecl.getDecl())->text.getUnownedSlice() == name)
+ if(getReflectionName(field->getVariable())->text.getUnownedSlice() == name)
return f;
}
}
@@ -1059,6 +1059,18 @@ SLANG_API SlangParameterCategory spReflectionTypeLayout_GetParameterCategory(Sla
return getParameterCategory(typeLayout);
}
+SLANG_API uint32_t spReflectionTypeLayout_GetFieldCount(SlangReflectionTypeLayout* inTypeLayout)
+{
+ auto typeLayout = convert(inTypeLayout);
+ if (!typeLayout) return 0;
+
+ if (auto structTypeLayout = as<StructTypeLayout>(typeLayout))
+ {
+ return (uint32_t)structTypeLayout->fields.getCount();
+ }
+ return 0;
+}
+
SLANG_API unsigned spReflectionTypeLayout_GetCategoryCount(SlangReflectionTypeLayout* inTypeLayout)
{
auto typeLayout = convert(inTypeLayout);
@@ -2508,6 +2520,9 @@ SLANG_API SlangInt spReflectionTypeLayout_getSubObjectRangeDescriptorRangeSpaceO
SLANG_API char const* spReflectionVariable_GetName(SlangReflectionVariable* inVar)
{
auto var = convert(inVar);
+ if (as<InheritanceDecl>(var))
+ return "$base";
+
if(!var) return nullptr;
// If the variable is one that has an "external" name that is supposed
@@ -2521,14 +2536,19 @@ SLANG_API char const* spReflectionVariable_GetName(SlangReflectionVariable* inVa
SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVariable* inVar)
{
auto var = convert(inVar);
+
+ if (auto inheritanceDecl = as<InheritanceDecl>(var))
+ return convert(inheritanceDecl->base.type);
+
if(!var) return nullptr;
- return convert(var->getType());
+ return convert(as<VarDeclBase>(var)->getType());
}
SLANG_API SlangReflectionModifier* spReflectionVariable_FindModifier(SlangReflectionVariable* inVar, SlangModifierID modifierID)
{
auto var = convert(inVar);
+
if(!var) return nullptr;
Modifier* modifier = nullptr;
@@ -2571,7 +2591,7 @@ SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(SlangR
auto varLayout = convert(inVarLayout);
if(!varLayout) return nullptr;
- return convert(varLayout->varDecl.getDecl());
+ return (SlangReflectionVariable*)(varLayout->varDecl.getDecl());
}
SLANG_API SlangReflectionTypeLayout* spReflectionVariableLayout_GetTypeLayout(SlangReflectionVariableLayout* inVarLayout)
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp
index e791efadb..30c41d0fe 100644
--- a/source/slang/slang-type-layout.cpp
+++ b/source/slang/slang-type-layout.cpp
@@ -3,6 +3,7 @@
#include "slang-syntax.h"
#include "slang-ir-insts.h"
+#include "slang-check-impl.h"
#include "../compiler-core/slang-artifact-desc-util.h"
@@ -3331,7 +3332,7 @@ void StructTypeLayoutBuilder::beginLayoutIfNeeded(
}
RefPtr<VarLayout> StructTypeLayoutBuilder::addField(
- DeclRef<VarDeclBase> field,
+ DeclRef<Decl> field,
TypeLayoutResult fieldResult)
{
SLANG_ASSERT(m_typeLayout);
@@ -4082,6 +4083,16 @@ static TypeLayoutResult _createTypeLayout(
_addLayout(context, type, typeLayout);
+ // Add all base fields first.
+ for (auto inheritanceDeclRef : getMembersOfType<InheritanceDecl>(context.astBuilder, structDeclRef))
+ {
+ auto baseType = getSup(context.astBuilder, inheritanceDeclRef);
+ if (isInterfaceType(baseType))
+ continue;
+ auto baseTypeLayout = _createTypeLayout(context, baseType);
+ typeLayoutBuilder.addField(inheritanceDeclRef, baseTypeLayout);
+ }
+
// First, add all fields with explicit offsets.
for (auto field : getFields(context.astBuilder, structDeclRef, MemberFilterStyle::Instance))
{
diff --git a/source/slang/slang-type-layout.h b/source/slang/slang-type-layout.h
index eb0884287..a44efb085 100644
--- a/source/slang/slang-type-layout.h
+++ b/source/slang/slang-type-layout.h
@@ -514,8 +514,8 @@ class VarLayout : public Layout
{
public:
// The variable we are laying out
- DeclRef<VarDeclBase> varDecl;
- VarDeclBase* getVariable() { return varDecl.getDecl(); }
+ DeclRef<Decl> varDecl;
+ VarDeclBase* getVariable() { return varDecl.as<VarDeclBase>().getDecl(); }
Name* getName() { return getVariable()->getName(); }
@@ -721,7 +721,7 @@ public:
// TODO: This should map from a declaration to the *index*
// in the array above, rather than to the actual pointer,
// so that we
- Dictionary<VarDeclBase*, RefPtr<VarLayout>> mapVarToLayout;
+ Dictionary<Decl*, RefPtr<VarLayout>> mapVarToLayout;
};
class GenericParamTypeLayout : public TypeLayout
@@ -1207,7 +1207,7 @@ public:
/// One of the `beginLayout*()` functions must have been called previously.
///
RefPtr<VarLayout> addField(
- DeclRef<VarDeclBase> field,
+ DeclRef<Decl> field,
TypeLayoutResult fieldResult);
RefPtr<VarLayout> addExplicitUniformField(