yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Tim FoleyRemove non-IR codegen paths (#398)662f43fff

master
1.6 KiB72 linesraw
1//TEST_DISABLED:SIMPLE:
2
3// Note: This test is disabled because we don't currently
4// have support for generating code from files that use
5// interfaces as parameter types.
6//
7// TODO: We need to add a check for this and generate an
8// error!
9
10// Confirm that basic `interface` syntax stuff type-checks.
11
12// The example here is adapted from examples in Matt Pharr's
13// chapter in GPU Gems: "An Introduction to Shader Interaces"
14
15struct LightSample
16{
17	float3 C; // radiance
18	float3 L; // direction	
19};
20
21interface Light
22{
23	LightSample illuminate(float3 P_world);
24}
25
26struct PointLight : Light
27{
28	float3 Plight_world;
29	float3 C;
30
31	LightSample illuminate(float3 P_world)
32	{
33		float3 delta = Plight_world - P_world;
34		float3 L = normalize(delta);
35		float distance = length(delta);
36
37		LightSample result;
38		result.L = L;
39		result.C = C * (1 / (distance*distance));
40		return result;
41	}	
42};
43
44// using the concrete type directly
45float3 A( float3 P_world, PointLight light )
46{
47	return light.illuminate(P_world).L;
48}
49
50// using the abstract interface type
51float3 B( float3 P_world, Light light )
52{
53	return light.illuminate(P_world).L;
54}
55
56//
57float3 Test(float3 P_world, PointLight pointLight, Light light)
58{
59	// dconcrete type expected, concrete type provided
60	float3 a = A(P_world, pointLight);
61
62	// abstract type expected, abstract type provided
63	float3 b = B(P_world, light);
64
65	// abstract type expected, concrete type provided
66	float3 c = B(P_world, pointLight);
67
68	// The remaining case (passing `Light` where `PointLight` is expected)
69	// should be an error, so we want a distinct test for that.
70
71	return a + b + c;
72}