summaryrefslogtreecommitdiffstats
path: root/tests/compute
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2017-11-17 21:26:21 -0500
committerTim Foley <tfoleyNV@users.noreply.github.com>2017-11-17 18:26:21 -0800
commit54bf54bd0dda378f8400860b25855558f39cb52b (patch)
tree955931f37df819f3c6e22bc981089f644c1141e1 /tests/compute
parent0298a0427bbfe19700169c4e239a1b9e91baa410 (diff)
Add support for global generic parameters (#285)
* Add support for global generic parameters (In-progress work) This commit include: 1. Update Slang API to allow specification of generic type arguments in an `EntryPointRequest` 2. Add parsing of `__generic_param` construct, which becomes a GlobalGenericParamDecl, contains members of `GenericTypeConstraintDecl`. 3. Semantics checking will check whether the provided type arguments conform to the interfaces as defined by the generic parameter, and store SubtypeWitness values in the EntryPointRequest, which will be used by `specializeIRForEntryPoint` when generating final IR. 4. Add a new type of substitution - `GlobalGenericParamSubstitution` for subsittuting references to `__generic_param` decls or to its member `GenericTypeConsraintDecl` with the actual type argument or witness tables. 5. Update `IRSpecContext` to apply `GlobalGenericParamSubstitution` when specializing the IR for an EntryPointRequest. 6. Update `render-test` to take additional `type` inputs, which specifies the type arguments to substitute into the global `__generic_param` types. This commit does not include ProgramLayout specialization. * IR: pass through `[unroll]` attribute (#284) The initial lowering was adding an `IRLoopControlDecoration` to the instruction at the head of a loop, but this was getting dropped when the IR gets cloned for a particular entry point. The fix was simply to add a case for loop-control decorations to `cloneDecoration`. * fix warnings * IR: support `CompileTimeForStmt` (#286) This statement type is a bit of a hack, to support loops that *must* be unrolled. The AST-to-AST pass handles them by cloning the AST for the loop body N times, and it was easy enough to do the same thing for the IR: emit the instructions for the body N times. The only thing that requires a bit of care is that now we might see the same variable declarations multiple times, so we need to play it safe and overwrite existing entries in our map from declarations to their IR values. Of course a better answer long-term would be to do the actual unrolling in the IR. This is especially true because we might some day want to support compile-time/must-unroll loops in functions, where the loop counter comes in as a parameter (but must still be compile-time-constant at every call site). * Add support for global generic parameters (In-progress work) This commit include: 1. Update Slang API to allow specification of generic type arguments in an `EntryPointRequest` 2. Add parsing of `__generic_param` construct, which becomes a GlobalGenericParamDecl, contains members of `GenericTypeConstraintDecl`. 3. Semantics checking will check whether the provided type arguments conform to the interfaces as defined by the generic parameter, and store SubtypeWitness values in the EntryPointRequest, which will be used by `specializeIRForEntryPoint` when generating final IR. 4. Add a new type of substitution - `GlobalGenericParamSubstitution` for subsittuting references to `__generic_param` decls or to its member `GenericTypeConsraintDecl` with the actual type argument or witness tables. 5. Update `IRSpecContext` to apply `GlobalGenericParamSubstitution` when specializing the IR for an EntryPointRequest. 6. Update `render-test` to take additional `type` inputs, which specifies the type arguments to substitute into the global `__generic_param` types. progress on parameter binding * Add a more contrived test case for specializing parameter bindings * update render-test to align buffers to 256 bytes (to get rid of D3D complains on minimal buffer size). * adding one more test case for parameter binding specialization. * Cleanup according to @tfoleyNV 's suggestions. * fix a bug introduced in the cleanup
Diffstat (limited to 'tests/compute')
-rw-r--r--tests/compute/global-type-param.slang30
-rw-r--r--tests/compute/global-type-param.slang.expected.txt1
-rw-r--r--tests/compute/global-type-param1.slang46
-rw-r--r--tests/compute/global-type-param1.slang.expected.txt1
-rw-r--r--tests/compute/global-type-param2.slang61
-rw-r--r--tests/compute/global-type-param2.slang.expected.txt1
6 files changed, 140 insertions, 0 deletions
diff --git a/tests/compute/global-type-param.slang b/tests/compute/global-type-param.slang
new file mode 100644
index 000000000..301ef1021
--- /dev/null
+++ b/tests/compute/global-type-param.slang
@@ -0,0 +1,30 @@
+//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir
+//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 compute()
+ {
+ return 1.0;
+ }
+};
+
+__generic_param TImpl : IBase;
+
+TImpl impl;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ float outVal = impl.compute();
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/global-type-param.slang.expected.txt b/tests/compute/global-type-param.slang.expected.txt
new file mode 100644
index 000000000..47b9ba0c8
--- /dev/null
+++ b/tests/compute/global-type-param.slang.expected.txt
@@ -0,0 +1 @@
+3F800000 \ No newline at end of file
diff --git a/tests/compute/global-type-param1.slang b/tests/compute/global-type-param1.slang
new file mode 100644
index 000000000..c9b754aa3
--- /dev/null
+++ b/tests/compute/global-type-param1.slang
@@ -0,0 +1,46 @@
+//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT: cbuffer(data=[0.5 0 0 0 1.0], stride=4):dxbinding(0),glbinding(0)
+//TEST_INPUT: cbuffer(data=[1.0], stride=4):dxbinding(1),glbinding(1)
+//TEST_INPUT: Texture2D(size=4, content = zero) : dxbinding(0),glbinding(0)
+//TEST_INPUT: Texture2D(size=4, content = one) : dxbinding(1),glbinding(1)
+//TEST_INPUT: Sampler : dxbinding(0),glbinding(0,1,2,3,4,5,6)
+//TEST_INPUT: Sampler : dxbinding(1),glbinding(0,1,2,3,4,5,6)
+//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
+ Texture2D tex;
+ SamplerState sampler;
+ float compute()
+ {
+ return tex.SampleLevel(sampler, float2(0.0), 0.0).x + base;
+ }
+};
+
+__generic_param TImpl : IBase;
+
+TImpl impl;
+
+float base0; // = 0.5
+
+Texture2D tex1; // = 0.0
+SamplerState sampler;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ float b0 = tex1.SampleLevel(sampler, float2(0.0), 0.0).x + base0; // = 0.5
+ float outVal = impl.compute(); // = 2.0
+ outVal = b0 / outVal; // = 0.25
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/global-type-param1.slang.expected.txt b/tests/compute/global-type-param1.slang.expected.txt
new file mode 100644
index 000000000..4846e7be2
--- /dev/null
+++ b/tests/compute/global-type-param1.slang.expected.txt
@@ -0,0 +1 @@
+3E800000
diff --git a/tests/compute/global-type-param2.slang b/tests/compute/global-type-param2.slang
new file mode 100644
index 000000000..b54f4c430
--- /dev/null
+++ b/tests/compute/global-type-param2.slang
@@ -0,0 +1,61 @@
+//TEST(smoke,compute):COMPARE_COMPUTE:-xslang -use-ir
+//TEST_INPUT: cbuffer(data=[0.5 0 0 0], stride=4):dxbinding(0),glbinding(0)
+//TEST_INPUT: cbuffer(data=[1.0], stride=4):dxbinding(1),glbinding(1)
+//TEST_INPUT: Texture2D(size=4, content = zero) : dxbinding(0),glbinding(0)
+//TEST_INPUT: Texture2D(size=4, content = one) : dxbinding(1),glbinding(1)
+//TEST_INPUT: Sampler : dxbinding(0),glbinding(0,1,2,3,4,5,6)
+//TEST_INPUT: Sampler : dxbinding(1),glbinding(0,1,2,3,4,5,6)
+//TEST_INPUT: ubuffer(data=[0], stride=4):dxbinding(0),glbinding(0),out
+//TEST_INPUT: type Impl
+
+
+/* Testing this scenario:
+The ProgramLayout before specializeIRForEntryPoint() has no global cbuffer
+allocated because the program before specialization does not define any
+global uniform variables.
+
+However, after specialization, we find ourselves needing a global constant
+buffer. The compiler should allocate the next available constant buffer slot
+(here c1 because c0 is already used by the explicit cbuffer decl `existingBuffer`)
+for the newly generated global constant buffer.
+*/
+
+RWStructuredBuffer<float> outputBuffer;
+
+interface IBase
+{
+ float compute();
+}
+
+struct Impl : IBase
+{
+ float base; // = 1.0
+ Texture2D tex;
+ SamplerState sampler;
+ float compute()
+ {
+ return tex.SampleLevel(sampler, float2(0.0), 0.0).x + base;
+ }
+};
+
+__generic_param TImpl : IBase;
+
+TImpl impl;
+
+// at binding c0:
+cbuffer existingBuffer
+{
+ float base0; // = 0.5
+}
+Texture2D tex1; // = 0.0
+SamplerState sampler;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+ float b0 = tex1.SampleLevel(sampler, float2(0.0), 0.0).x + base0; // = 0.5
+ float outVal = impl.compute(); // = 2.0
+ outVal = b0 / outVal; // = 0.25
+ outputBuffer[tid] = outVal;
+} \ No newline at end of file
diff --git a/tests/compute/global-type-param2.slang.expected.txt b/tests/compute/global-type-param2.slang.expected.txt
new file mode 100644
index 000000000..4846e7be2
--- /dev/null
+++ b/tests/compute/global-type-param2.slang.expected.txt
@@ -0,0 +1 @@
+3E800000