summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2017-06-15 13:00:29 -0700
committerGitHub <noreply@github.com>2017-06-15 13:00:29 -0700
commitc34a433d7aa3fdbfefee22f20d5aac2d960f392a (patch)
tree493fd248f57444120588d4d0979d391875d7f5bb /tests
parent3491d3578c7fa3e88e7c16c394ec64238c636f04 (diff)
parent367edf757aff609b72de48732113ea756d878f52 (diff)
Merge pull request #25 from tfoleyNV/interfaces
Add basic support for `interface` declarations
Diffstat (limited to 'tests')
-rw-r--r--tests/front-end/interface.slang65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/front-end/interface.slang b/tests/front-end/interface.slang
new file mode 100644
index 000000000..754addf61
--- /dev/null
+++ b/tests/front-end/interface.slang
@@ -0,0 +1,65 @@
+//TEST:SIMPLE:
+
+// Confirm that basic `interface` syntax stuff type-checks.
+
+// The example here is adapted from examples in Matt Pharr's
+// chapter in GPU Gems: "An Introduction to Shader Interaces"
+
+struct LightSample
+{
+ float3 C; // radiance
+ float3 L; // direction
+};
+
+interface Light
+{
+ LightSample illuminate(float3 P_world);
+}
+
+struct PointLight : Light
+{
+ float3 Plight_world;
+ float3 C;
+
+ LightSample illuminate(float3 P_world)
+ {
+ float3 delta = Plight_world - P_world;
+ float3 L = normalize(delta);
+ float distance = length(delta);
+
+ LightSample result;
+ result.L = L;
+ result.C = C * (1 / (distance*distance));
+ return result;
+ }
+};
+
+// using the concrete type directly
+float3 A( float3 P_world, PointLight light )
+{
+ return light.illuminate(P_world).L;
+}
+
+// using the abstract interface type
+float3 B( float3 P_world, Light light )
+{
+ return light.illuminate(P_world).L;
+}
+
+//
+float3 Test(float3 P_world, PointLight pointLight, Light light)
+{
+ // dconcrete type expected, concrete type provided
+ float3 a = A(P_world, pointLight);
+
+ // abstract type expected, abstract type provided
+ float3 b = B(P_world, light);
+
+ // abstract type expected, concrete type provided
+ float3 c = B(P_world, pointLight);
+
+ // The remaining case (passing `Light` where `PointLight` is expected)
+ // should be an error, so we want a distinct test for that.
+
+ return a + b + c;
+} \ No newline at end of file