summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/syntax-base-defs.h1
-rw-r--r--source/slang/syntax.cpp6
-rw-r--r--source/slang/type-defs.h3
-rw-r--r--tests/compute/typedef-member.slang38
-rw-r--r--tests/compute/typedef-member.slang.expected.txt4
5 files changed, 50 insertions, 2 deletions
diff --git a/source/slang/syntax-base-defs.h b/source/slang/syntax-base-defs.h
index fdb2694a9..1853125a8 100644
--- a/source/slang/syntax-base-defs.h
+++ b/source/slang/syntax-base-defs.h
@@ -121,6 +121,7 @@ protected:
virtual Type* CreateCanonicalType() = 0;
Type* canonicalType = nullptr;
+ RefPtr<Type> canonicalTypeRefPtr;
Session* session = nullptr;
)
diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp
index 9ca2dc827..ca66e2110 100644
--- a/source/slang/syntax.cpp
+++ b/source/slang/syntax.cpp
@@ -189,6 +189,8 @@ void Type::accept(IValVisitor* visitor, void* extra)
{
// TODO(tfoley): worry about thread safety here?
et->canonicalType = et->CreateCanonicalType();
+ if (dynamic_cast<Type*>(et->canonicalType) != this)
+ et->canonicalTypeRefPtr = et->canonicalType;
SLANG_ASSERT(et->canonicalType);
}
return et->canonicalType;
@@ -861,7 +863,9 @@ void Type::accept(IValVisitor* visitor, void* extra)
Type* NamedExpressionType::CreateCanonicalType()
{
- return GetType(declRef)->GetCanonicalType();
+ if (!innerType)
+ innerType = GetType(declRef);
+ return innerType->GetCanonicalType();
}
int NamedExpressionType::GetHashCode()
diff --git a/source/slang/type-defs.h b/source/slang/type-defs.h
index d0b2ebac1..e7310768a 100644
--- a/source/slang/type-defs.h
+++ b/source/slang/type-defs.h
@@ -420,9 +420,10 @@ END_SYNTAX_CLASS()
// A type alias of some kind (e.g., via `typedef`)
SYNTAX_CLASS(NamedExpressionType, Type)
- DECL_FIELD(DeclRef<TypeDefDecl>, declRef)
+DECL_FIELD(DeclRef<TypeDefDecl>, declRef)
RAW(
+ RefPtr<Type> innerType;
NamedExpressionType()
{}
NamedExpressionType(
diff --git a/tests/compute/typedef-member.slang b/tests/compute/typedef-member.slang
new file mode 100644
index 000000000..dbf4dcdc1
--- /dev/null
+++ b/tests/compute/typedef-member.slang
@@ -0,0 +1,38 @@
+//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+
+// Confirm that a struct type defined in a generic parent works
+
+RWStructuredBuffer<float> outputBuffer;
+
+struct SubType<T>
+{
+ T x;
+};
+
+struct GenStruct<T>
+{
+ typedef SubType<T> SubTypeT;
+ T getVal(SubTypeT v)
+ {
+ return v.x;
+ }
+};
+
+float test(float val)
+{
+ GenStruct<float>.SubTypeT sb;
+ sb.x = val;
+ GenStruct<float> obj;
+ return obj.getVal(sb);
+}
+
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ float inVal = float(tid);
+ float outVal = test(inVal);
+ outputBuffer[tid] = outVal.x;
+} \ No newline at end of file
diff --git a/tests/compute/typedef-member.slang.expected.txt b/tests/compute/typedef-member.slang.expected.txt
new file mode 100644
index 000000000..98798bd61
--- /dev/null
+++ b/tests/compute/typedef-member.slang.expected.txt
@@ -0,0 +1,4 @@
+0
+3F800000
+40000000
+40400000 \ No newline at end of file