summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2018-01-04 13:41:09 -0800
committerTim Foley <tfoleyNV@users.noreply.github.com>2018-01-04 13:41:09 -0800
commit3d435f7321c3f9241d33a0f7521573f21b548186 (patch)
tree3a4f2d21250f1dbad1ca9bf4668b566a6c87ea89
parente90dfcfd6a0a6d92688012b1216c46c24965cfc0 (diff)
Bug fixes for Slang integration (#356)
* fix #353 * move validateEntryPoint to after all entrypoints has been checked * bug fix: DeclRefType::SubstituteImpl should change ioDiff * bug fix: generic resource usage should have count of 1 instead of 0. * update test case
-rw-r--r--source/slang/check.cpp17
-rw-r--r--source/slang/ir.cpp22
-rw-r--r--source/slang/parameter-binding.cpp7
-rw-r--r--source/slang/slang.cpp20
-rw-r--r--source/slang/syntax.cpp18
-rw-r--r--source/slang/type-defs.h1
-rw-r--r--tests/compute/global-type-param3.slang37
-rw-r--r--tests/compute/global-type-param3.slang.expected.txt1
-rw-r--r--tools/render-test/test.txt1
9 files changed, 101 insertions, 23 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp
index 46ed9da15..ca9e0e7e5 100644
--- a/source/slang/check.cpp
+++ b/source/slang/check.cpp
@@ -6830,7 +6830,7 @@ namespace Slang
entryPoint->genericParameterTypes.Count());
return;
}
- // if number of entry-point type arguments matches parameters, try find
+ // if entry-point type arguments matches parameters, try find
// SubtypeWitness for each argument
int index = 0;
for (auto & gParam : globalGenericParams)
@@ -6871,21 +6871,6 @@ namespace Slang
// checking that is required on all declarations
// in the translation unit.
visitor.checkDecl(translationUnit->SyntaxNode);
-
- // Next, do follow-up validation on any entry
- // points that the user declared via API or
- // command line, to ensure that they meet
- // requirements.
- //
- // Note: We may eventually have syntax to
- // identify entry points via a modifier on
- // declarations, and in this case they should
- // probably get validated as part of orindary
- // checking above.
- for (auto entryPoint : translationUnit->entryPoints)
- {
- validateEntryPoint(entryPoint);
- }
}
diff --git a/source/slang/ir.cpp b/source/slang/ir.cpp
index e0f703cbd..088139953 100644
--- a/source/slang/ir.cpp
+++ b/source/slang/ir.cpp
@@ -3095,6 +3095,12 @@ namespace Slang
{
return declRef;
}
+
+ // A callback used to clone (or not) a Val
+ virtual RefPtr<Val> maybeCloneVal(Val* val)
+ {
+ return val;
+ }
};
void registerClonedValue(
@@ -3203,6 +3209,7 @@ namespace Slang
virtual DeclRef<Decl> maybeCloneDeclRef(DeclRef<Decl> const& declRef) override;
virtual RefPtr<Type> maybeCloneType(Type* originalType) override;
+ virtual RefPtr<Val> maybeCloneVal(Val* val) override;
};
@@ -3216,6 +3223,11 @@ namespace Slang
return originalType->Substitute(subst).As<Type>();
}
+ RefPtr<Val> IRSpecContext::maybeCloneVal(Val * val)
+ {
+ return val->Substitute(subst);
+ }
+
IRValue* IRSpecContext::maybeCloneValue(IRValue* originalValue)
{
switch (originalValue->op)
@@ -3316,7 +3328,7 @@ namespace Slang
}
else
{
- return val;
+ return context->maybeCloneVal(val);
}
}
@@ -3439,7 +3451,7 @@ namespace Slang
IRGlobalVar* originalVar,
IROriginalValuesForClone const& originalValues)
{
- auto clonedVar = context->builder->createGlobalVar(context->maybeCloneType(originalVar->getType()->getValueType()));
+ auto clonedVar = context->builder->createGlobalVar(context->maybeCloneType(originalVar->getType()->getValueType()));
registerClonedValue(context, clonedVar, originalValues);
auto mangledName = originalVar->mangledName;
@@ -4229,6 +4241,7 @@ namespace Slang
virtual IRValue* maybeCloneValue(IRValue* originalVal) override;
virtual RefPtr<Type> maybeCloneType(Type* originalType) override;
+ virtual RefPtr<Val> maybeCloneVal(Val* val) override;
};
// Convert a type-level value into an IR-level equivalent.
@@ -4352,6 +4365,11 @@ namespace Slang
return originalType->Substitute(subst).As<Type>();
}
+ RefPtr<Val> IRGenericSpecContext::maybeCloneVal(Val * val)
+ {
+ return val->Substitute(subst);
+ }
+
// Given a list of substitutions, return the inner-most
// generic substitution in the list, or NULL if there
// are no generic substitutions.
diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp
index 6dac47631..fcd3fa525 100644
--- a/source/slang/parameter-binding.cpp
+++ b/source/slang/parameter-binding.cpp
@@ -1077,7 +1077,7 @@ static void completeBindingsForParameter(
else if (kind == LayoutResourceKind::GenericResource)
{
bindingInfo.space = 0;
- bindingInfo.count = 0;
+ bindingInfo.count = 1;
bindingInfo.index = 0;
continue;
}
@@ -2118,8 +2118,7 @@ RefPtr<ProgramLayout> specializeProgramLayout(
for (auto & varLayout : globalStructLayout->fields)
{
// To recover layout context, we skip generic resources in the first pass
- // If the var is a generic resource, its resourceInfos will be empty.
- if (varLayout->resourceInfos.Count() == 0)
+ if (varLayout->FindResourceInfo(LayoutResourceKind::GenericResource))
continue;
SLANG_ASSERT(varLayout->resourceInfos.Count() == varLayout->typeLayout->resourceInfos.Count());
auto uniformInfo = varLayout->FindResourceInfo(LayoutResourceKind::Uniform);
@@ -2140,7 +2139,7 @@ RefPtr<ProgramLayout> specializeProgramLayout(
usedRangeSet->usedResourceRanges[(int)resInfo.kind].Add(
nullptr, // we don't need to track parameter info here
resInfo.index,
- resInfo.index + varLayout->typeLayout->resourceInfos[0].count);
+ resInfo.index + tresInfo.count);
}
structLayout->fields.Add(varLayout);
varLayoutMapping[varLayout] = varLayout;
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index 0b3e0ceb7..2ebf024e3 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -174,6 +174,8 @@ void CompileRequest::parseTranslationUnit(
}
}
+void validateEntryPoint(EntryPointRequest*);
+
void CompileRequest::checkAllTranslationUnits()
{
// Iterate over all translation units and
@@ -182,6 +184,24 @@ void CompileRequest::checkAllTranslationUnits()
{
checkTranslationUnit(translationUnit.Ptr());
}
+
+ for (auto& translationUnit : translationUnits)
+ {
+ // Next, do follow-up validation on any entry
+ // points that the user declared via API or
+ // command line, to ensure that they meet
+ // requirements.
+ //
+ // Note: We may eventually have syntax to
+ // identify entry points via a modifier on
+ // declarations, and in this case they should
+ // probably get validated as part of orindary
+ // checking above.
+ for (auto entryPoint : translationUnit->entryPoints)
+ {
+ validateEntryPoint(entryPoint);
+ }
+ }
}
void CompileRequest::generateIR()
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index c49cd3648..cdc112846 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -358,6 +358,21 @@ void Type::accept(IValVisitor* visitor, void* extra)
return (ArrayLength == arrType->ArrayLength && baseType->Equals(arrType->baseType.Ptr()));
}
+ RefPtr<Val> ArrayExpressionType::SubstituteImpl(Substitutions* subst, int* ioDiff)
+ {
+ int diff = 0;
+ auto elementType = baseType->SubstituteImpl(subst, &diff).As<Type>();
+ if (diff)
+ {
+ *ioDiff = 1;
+ auto rsType = getArrayType(
+ elementType,
+ ArrayLength);
+ return rsType;
+ }
+ return this;
+ }
+
Type* ArrayExpressionType::CreateCanonicalType()
{
auto canonicalElementType = baseType->GetCanonicalType();
@@ -531,6 +546,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
{
if (genericSubst->paramDecl == globalGenParam)
{
+ (*ioDiff)++;
return genericSubst->actualType;
}
}
@@ -1393,7 +1409,7 @@ void Type::accept(IValVisitor* visitor, void* extra)
{
int diff = 0;
RefPtr<Substitutions> substSubst = substituteSubstitutions(substitutions, subst, &diff);
-
+
if (!diff)
return *this;
diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h
index e7310768a..4efbc7ec1 100644
--- a/source/slang/type-defs.h
+++ b/source/slang/type-defs.h
@@ -310,6 +310,7 @@ RAW(
protected:
virtual bool EqualsImpl(Type * type) override;
virtual Type* CreateCanonicalType() override;
+ virtual RefPtr<Val> SubstituteImpl(Substitutions* subst, int* ioDiff) override;
virtual int GetHashCode() override;
)
END_SYNTAX_CLASS()
diff --git a/tests/compute/global-type-param3.slang b/tests/compute/global-type-param3.slang
new file mode 100644
index 000000000..05793dce4
--- /dev/null
+++ b/tests/compute/global-type-param3.slang
@@ -0,0 +1,37 @@
+//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT: cbuffer(data=[1.0], stride=4):dxbinding(0),glbinding(0)
+//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(0),glbinding(0),out
+//TEST_INPUT: type Impl
+
+RWStructuredBuffer<float> outputBuffer;
+
+interface IBase
+{
+ float compute();
+}
+
+struct Impl : IBase
+{
+ float base; // = 1.0
+ float compute()
+ {
+ return 1.0;
+ }
+};
+
+__generic_param TImpl : IBase;
+
+ParameterBlock<TImpl> impl;
+
+float doCompute<T:IBase>(T t)
+{
+ return t.compute();
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ float outVal = doCompute<TImpl>(impl);
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/global-type-param3.slang.expected.txt b/tests/compute/global-type-param3.slang.expected.txt
new file mode 100644
index 000000000..deb1c3630
--- /dev/null
+++ b/tests/compute/global-type-param3.slang.expected.txt
@@ -0,0 +1 @@
+3F800000
diff --git a/tools/render-test/test.txt b/tools/render-test/test.txt
new file mode 100644
index 000000000..deb1c3630
--- /dev/null
+++ b/tools/render-test/test.txt
@@ -0,0 +1 @@
+3F800000