summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2024-05-02 19:01:21 -0400
committerGitHub <noreply@github.com>2024-05-02 16:01:21 -0700
commitc763750a7305fbf12c1f5c177260294a32fe286d (patch)
treeec544212bd5bf0ac72cbe3c01d2ed85fc3f05cd9 /tests
parente5d49cf21db7a398afe6cfdb76f6b4a028e9eecb (diff)
Handle case where types can be used as their own `Differential` type. (#4057)
* Avoid synthesis for when types can be used as their own differenial + Add test * Add missing files.. * Fix issue with method synthesis for self-differential types + Add a generic test * Fix * Fix issue with out-of-date type resolution cache. Witness tables created during the conformance checking phase not being taken into account during the decl type resolution phase because the epoch is not updated after conformance checking. This leads to certain complex associated-type lookup chains (such as the one in tests/compute/assoctype-nested-lookup) not resolving properly and causing errors. * Delete self-differential-type-synthesis-extension.slang * Quick fix to repopulate stdlib cache for deferred stdlib loading * Update slang-check-decl.cpp
Diffstat (limited to 'tests')
-rw-r--r--tests/autodiff/self-differential-generic-type-synthesis.slang36
-rw-r--r--tests/autodiff/self-differential-generic-type-synthesis.slang.expected.txt6
-rw-r--r--tests/autodiff/self-differential-type-synthesis.slang36
-rw-r--r--tests/autodiff/self-differential-type-synthesis.slang.expected.txt6
-rw-r--r--tests/compute/assoctype-nested-lookup.slang44
-rw-r--r--tests/compute/assoctype-nested-lookup.slang.expected.txt2
6 files changed, 130 insertions, 0 deletions
diff --git a/tests/autodiff/self-differential-generic-type-synthesis.slang b/tests/autodiff/self-differential-generic-type-synthesis.slang
new file mode 100644
index 000000000..8d225dec2
--- /dev/null
+++ b/tests/autodiff/self-differential-generic-type-synthesis.slang
@@ -0,0 +1,36 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+// Test that struct types made up of differentiable members who are self-differential (i.e. their Differential type is the same as their type)
+// are considered self-differential as well. We should be able to assign T.Differential = T and T = T.Differential without errors.
+//
+
+
+struct Ray<let N: int> : IDifferentiable {
+ float a;
+ vector<float, N> dir, o;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ Ray<4> ray = Ray<4>();
+ Ray<4>.Differential ray2;
+
+ ray.a = 1.f;
+ ray.o = float4(3.f, 4.f, 2.5f, 1.f);
+
+ ray2 = ray;
+
+ float t = 0.f;
+ float.Differential dt = 0.f;
+
+ t = dt;
+
+ outputBuffer[0] = t;
+ outputBuffer[1] = ray2.o.y;
+ outputBuffer[2] = Ray<4>.dadd(ray2, ray2).o.w;
+}
diff --git a/tests/autodiff/self-differential-generic-type-synthesis.slang.expected.txt b/tests/autodiff/self-differential-generic-type-synthesis.slang.expected.txt
new file mode 100644
index 000000000..e3160fd7f
--- /dev/null
+++ b/tests/autodiff/self-differential-generic-type-synthesis.slang.expected.txt
@@ -0,0 +1,6 @@
+type: float
+0.000000
+4.000000
+2.000000
+0.000000
+0.000000
diff --git a/tests/autodiff/self-differential-type-synthesis.slang b/tests/autodiff/self-differential-type-synthesis.slang
new file mode 100644
index 000000000..7f95891c6
--- /dev/null
+++ b/tests/autodiff/self-differential-type-synthesis.slang
@@ -0,0 +1,36 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+// Test that struct types made up of differentiable members who are self-differential (i.e. their Differential type is the same as their type)
+// are considered self-differential as well. We should be able to assign T.Differential = T and T = T.Differential without errors.
+// 1
+
+struct Ray : IDifferentiable {
+ float a;
+ float3 dir, o;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ Ray ray = Ray();
+ Ray.Differential ray2;
+
+ ray.a = 1.f;
+ ray.o = float3(3.f, 4.f, 2.5f);
+
+ ray2 = ray;
+
+ float t = 0.f;
+ float.Differential dt = 0.f;
+
+ t = dt;
+
+ outputBuffer[0] = t;
+ outputBuffer[1] = ray2.o.y;
+ outputBuffer[2] = Ray.dadd(ray2, ray2).a;
+}
diff --git a/tests/autodiff/self-differential-type-synthesis.slang.expected.txt b/tests/autodiff/self-differential-type-synthesis.slang.expected.txt
new file mode 100644
index 000000000..e3160fd7f
--- /dev/null
+++ b/tests/autodiff/self-differential-type-synthesis.slang.expected.txt
@@ -0,0 +1,6 @@
+type: float
+0.000000
+4.000000
+2.000000
+0.000000
+0.000000
diff --git a/tests/compute/assoctype-nested-lookup.slang b/tests/compute/assoctype-nested-lookup.slang
new file mode 100644
index 000000000..518e88e25
--- /dev/null
+++ b/tests/compute/assoctype-nested-lookup.slang
@@ -0,0 +1,44 @@
+
+
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+interface IFoo
+{
+ associatedtype Bar : IFoo;
+};
+
+
+struct FooPair<T : IFoo> : IFoo
+{
+ T a;
+ T.Bar b;
+
+ typealias Bar = FooPair<T.Bar>;
+};
+
+
+struct ConcreteFoo : IFoo
+{
+ typealias Bar = ConcreteFoo;
+
+ float x;
+};
+
+void test(FooPair<ConcreteFoo>.Bar pair)
+{
+ pair.a.x = 1.0;
+ pair.b.x = 2.0;
+
+ outputBuffer[0] = pair.a.x + pair.b.x;
+}
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
+{
+ FooPair<ConcreteFoo>.Bar pair;
+ test(pair);
+} \ No newline at end of file
diff --git a/tests/compute/assoctype-nested-lookup.slang.expected.txt b/tests/compute/assoctype-nested-lookup.slang.expected.txt
new file mode 100644
index 000000000..a6122d7ce
--- /dev/null
+++ b/tests/compute/assoctype-nested-lookup.slang.expected.txt
@@ -0,0 +1,2 @@
+type: float
+3.000000