summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArielG-NV <159081215+ArielG-NV@users.noreply.github.com>2025-05-21 21:11:01 -0700
committerGitHub <noreply@github.com>2025-05-22 04:11:01 +0000
commit27c6e9b01f7386263bde90e16812be46327015c2 (patch)
treea640d6882da0c9ee90ef64872b1b94c721039cdf /tests
parent21346ded32be9091389ca53815c1ba56feff8a01 (diff)
Initial `dyn` keyword support & `-lang 2026` compiler option (#7172)
fixes: [#7143](https://github.com/shader-slang/slang/issues/7143) fixes: [#7146](https://github.com/shader-slang/slang/issues/7146) Goal of PR: * This PR is part of the larger #7115 refactor to how dynamic dispatch works. * The first step is to add the `-std <std-revision>` flag. * The second step is to provide basic `dyn` keyword support in AST. This does not include `varDecl` support since most of these interactions require `some` keyword support. Future PR(s) goal: * Support `some` keyword in AST. With this we will also implement all varDecl interactions between `dyn` and `some`. * Add IR support for `some` and `dyn`. Breakdown of PR: * most of the logic is in `validateDyn.*`. This was done so that in the future when we implement more features we will have an easy time removing/adding restrictions to `dyn` interfaces. Breaking changes: * As per spec (https://github.com/shader-slang/spec/pull/14/files), any type conforming to a `dyn` interface errors if member list contains one of the following: opaque type, non copyable type, or unsized type. * Due to the breaking change, the test `tests\compute\dynamic-dispatch-bindless-texture.slang` is incorrect. This has been fixed.
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/dynamic-dispatch-bindless-texture.slang36
-rw-r--r--tests/compute/interface-qualifiers/dyn-on-type-uses.slang186
-rw-r--r--tests/compute/interface-qualifiers/some-and-dyn-vardecl-uses.slang1
3 files changed, 201 insertions, 22 deletions
diff --git a/tests/compute/dynamic-dispatch-bindless-texture.slang b/tests/compute/dynamic-dispatch-bindless-texture.slang
index b02ca9686..ec21afeda 100644
--- a/tests/compute/dynamic-dispatch-bindless-texture.slang
+++ b/tests/compute/dynamic-dispatch-bindless-texture.slang
@@ -2,37 +2,29 @@
//TEST(compute):COMPARE_COMPUTE:-cpu
//TEST(compute):COMPARE_COMPUTE:-cuda
-[anyValueSize(16)]
-interface IInterface
+// Type must be marked `public` to ensure it is visible in the generated DLL.
+
+export struct MyImpl
{
- float run();
-}
+ Texture2D tex;
+ float run()
+ {
+ return tex.Load({0, 0, 0}).x;
+ }
+};
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=gOutputBuffer
RWStructuredBuffer<uint> gOutputBuffer;
-//TEST_INPUT: set gCb = new StructuredBuffer<IInterface>{new MyImpl{Texture2D(size=8, content = one), Sampler}}
-StructuredBuffer<IInterface> gCb;
+//TEST_INPUT: set gCb = new StructuredBuffer<MyImpl>{new MyImpl{Texture2D(size=8, content = one)}}
+StructuredBuffer<MyImpl> gCb;
[numthreads(4, 1, 1)]
-void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
let tid = dispatchThreadID.x;
let inputVal : int = tid;
- IInterface v0 = gCb.Load(0);
- SamplerState sampler;
+ MyImpl v0 = gCb.Load(0);
let outputVal = v0.run();
gOutputBuffer[tid] = uint(trunc(outputVal));
-}
-
-
-// Type must be marked `public` to ensure it is visible in the generated DLL.
-export struct MyImpl : IInterface
-{
- Texture2D tex;
- SamplerState sampler;
- float run()
- {
- return tex.Sample(sampler, float2(0.0, 0.0)).x;
- }
-};
+} \ No newline at end of file
diff --git a/tests/compute/interface-qualifiers/dyn-on-type-uses.slang b/tests/compute/interface-qualifiers/dyn-on-type-uses.slang
new file mode 100644
index 000000000..16e9e6efa
--- /dev/null
+++ b/tests/compute/interface-qualifiers/dyn-on-type-uses.slang
@@ -0,0 +1,186 @@
+//TEST:SIMPLE(filecheck=CHECK_2026): -target spirv -stage compute -entry computeMain -lang slang -std 2026
+//TEST:SIMPLE(filecheck=CHECK_2025_OR_EXP): -target spirv -stage compute -entry computeMain
+//TEST:SIMPLE(filecheck=CHECK_2025_OR_EXP): -target spirv -stage compute -entry computeMain -lang slang -std 2026 -enable-experimental-dynamic-dispatch
+
+// Validate AST side of `dyn` keyword use-cases
+
+// `experimental-dynamic-dispatch` and `-lang 2025` have fewer restrictions
+//
+// CHECK_2025_OR_EXP-NOT: error 33072
+// CHECK_2025_OR_EXP-NOT: error 33073
+// CHECK_2025_OR_EXP-NOT: error 33074
+// CHECK_2025_OR_EXP-NOT: error 33075
+// CHECK_2025_OR_EXP-NOT: error 33076
+// CHECK_2025_OR_EXP-NOT: error 33077
+// CHECK_2025_OR_EXP-NOT: error 33078
+// CHECK_2025_OR_EXP-NOT: error 33082
+
+/////////////////////////////////////////////////////
+
+// `dyn` interfaces are not allowed to be generics
+// CHECK_2026-DAG: error 33072
+dyn interface interface1<T>
+{
+ static const int member;
+};
+
+// `dyn` interfaces must not define any associated types.
+// CHECK_2026-DAG: error 33073
+interface IBase1
+{
+};
+dyn interface interface2
+{
+ associatedtype IBase1;
+};
+
+// `dyn` interfaces must not define any generic methods.
+// CHECK_2026-DAG: error 33074
+dyn interface interface3
+{
+ T genericFunc<T : IArithmetic>(T val)
+ {
+ return val*(T)2;
+ }
+};
+
+// `dyn` interfaces must not define any mutating methods
+// CHECK_2026-DAG: error 33075
+dyn interface interface4
+{
+ [mutating]
+ void mutate(int val);
+};
+
+// `dyn` interfaces cannot inherit from any interfaces that are not dyn.
+// CHECK_2026-DAG: error 33077
+
+interface IBase2
+{
+};
+
+dyn interface interface5 : IBase2
+{
+ int myFunc(int val)
+ {
+ return val*2;
+ }
+};
+
+dyn interface IBase3
+{
+};
+
+dyn interface interface6 : IBase3
+{
+ int myFunc(int val)
+ {
+ return val*2;
+ }
+};
+
+// `dyn` interfaces cannot contain any function requirements that are marked as [Differentiable].
+// CHECK_2026-DAG: error 33076
+dyn interface interface7
+{
+ [Differentiable]
+ int myFunc(int val)
+ {
+ return val*2;
+ }
+};
+
+// The type which is conforming to a dyn (myType in interface myType : IBase) cannot be generic.
+// CHECK_2026-DAG: error 33082
+// CHECK_2026-DAG: error 33082
+dyn interface IBase4
+{
+ int doMath(int val);
+};
+
+struct genericStruct1<T : IArithmetic> : IBase4
+{
+ T a;
+ int doMath(int v)
+ {
+ return v * (int)2;
+ }
+};
+
+interface genericInterface1<T : IArithmetic> : IBase4
+{
+ T doMath(T v)
+ {
+ return v * (T)3;
+ }
+};
+
+// Extensions that make a type conform/inherit to dyn interfaces are not allowed.
+// CHECK_2026-DAG: error 33078
+dyn interface IBase5
+{
+};
+interface interface9
+{
+};
+
+extension<T:interface9> T : IBase5
+{
+ int doMath()
+ {
+ return 5;
+ }
+};
+
+// Type conforming to `dyn` interface must be an ordinary data type, meaning that it cannot contain any fields that are opaque or non-copyable or unsized.
+// CHECK_2026-DAG: error 33079
+// CHECK_2026-DAG: error 33080
+// CHECK_2026-DAG: error 33081
+// CHECK_2026-DAG: error 33081
+
+// CHECK_2025_OR_EXP-DAG: error 33079
+// CHECK_2025_OR_EXP-DAG: error 33080
+// CHECK_2025_OR_EXP-DAG: error 33081
+
+struct structWithUnsized : IBase6
+{
+ int v[];
+};
+
+struct structWithOpaque : IBase6
+{
+ Texture2D<float> v;
+};
+
+dyn interface IBase6
+{
+};
+[__NonCopyableType]
+struct NonCopyableStruct1
+{
+ float v;
+}
+struct structWithNonCopyable1 : IBase6
+{
+ NonCopyableStruct1 v;
+};
+[__NonCopyableType]
+struct NonCopyableStruct2<T : IArithmetic>
+{
+ T v;
+}
+struct structWithNonCopyable2 : IBase6
+{
+ NonCopyableStruct2<int> v;
+};
+
+// `dyn` interfaces cannot contain any methods that has a `some` IFoo return type, or has any `some` IFoo parameters.
+// TODO-INTERFACE-QUALIFIERS-ADDITION-OF-SOME
+//
+
+RWStructuredBuffer<int> outputBuffer;
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ outputBuffer[0] = 0;
+}
diff --git a/tests/compute/interface-qualifiers/some-and-dyn-vardecl-uses.slang b/tests/compute/interface-qualifiers/some-and-dyn-vardecl-uses.slang
new file mode 100644
index 000000000..4caa3ec56
--- /dev/null
+++ b/tests/compute/interface-qualifiers/some-and-dyn-vardecl-uses.slang
@@ -0,0 +1 @@
+// TODO-INTERFACE-QUALIFIERS-ADDITION-OF-SOME \ No newline at end of file