summaryrefslogtreecommitdiffstats
path: root/tests/compute/default-parameter.slang
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-03-29 10:39:21 -0700
committerGitHub <noreply@github.com>2018-03-29 10:39:21 -0700
commitb4c4dc92c0b21f0253c4ccf34107638f7c36b62e (patch)
tree9ead4b91a302fa3ad1e940686022d4ccbab3329c /tests/compute/default-parameter.slang
parent184dc5cd6998b6277881fae4a68d91de86e2d63f (diff)
Add support for default parameter values in IR codegen (#459)
Fixes #61 When lowering from AST to IR, if a call site doesn't supply an argument expression for each of the parameters to the callee, then use the default value expressions (stored as the "initializer" of the parameter decl) for each omitted parameter. This relies on the front-end to have already checked the call site for validity. Along the way I also cleaned up some of the checking of parameter declarations so that it is more like the checking of ordinary variable declarations (although the code is not yet shared). I also cleaned out some dead cases in the lowering logic for when we don't actually have a declaration available for a callee (these would only matter if we supported functions as first-class values). I added a simple test case to confirm that call sites both with and without the optional parameter work as expected. The strategy in this change is extremely simplistic, and might only be appropriate for default parameter value expressions that are compile-time constants (which should be the 99% case). This may require a major overhaul if we decide to handle default parameter values differently (e.g., by generating extra functions to ensure that the separate compilation story is what we want). Another issue that could change a lot of this logic would be if we start to support by-name parameters at call sites, since we could no longer assume that the argument and parameter lists align one-to-one (with the argument list possibly being shorter). Any work to add more flexible argument passing conventions would need to build a suitable structure to map from arguments to parameters, or vice-versa.
Diffstat (limited to 'tests/compute/default-parameter.slang')
-rw-r--r--tests/compute/default-parameter.slang24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/compute/default-parameter.slang b/tests/compute/default-parameter.slang
new file mode 100644
index 000000000..6e6631bb4
--- /dev/null
+++ b/tests/compute/default-parameter.slang
@@ -0,0 +1,24 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out
+
+RWStructuredBuffer<int> outputBuffer;
+
+int helper(int val, int a = 16)
+{
+ return val + a;
+}
+
+int test(int val)
+{
+ return helper(val) + helper(val, 256);
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int inVal = (int) dispatchThreadID.x;
+ int outVal = test(inVal);
+ outputBuffer[dispatchThreadID.x] = outVal;
+} \ No newline at end of file