Add a runtime-disabled dialog element skeleton
[WebKit-https.git] / LayoutTests / webgpu / whlsl-override-subscript.html
1 <!DOCTYPE html>
2 <html>
3 <meta charset=utf-8>
4 <meta name="timeout" content="long">
5 <title>Test override subscripts.</title>
6 <script src="js/whlsl-test-harness.js"></script>
7 <script src="js/webgpu-functions.js"></script>
8 <script src="../resources/testharness.js"></script>
9 <script src="../resources/testharnessreport.js"></script>
10 <script>
11 const whlslTests = {};
12
13 whlslTests.overrideSubscriptStruct = async () =>
14 {
15     let program = `
16         struct Foo {
17             int x;
18             int y;
19         }
20         thread int* operator&[](thread Foo* foo, uint index)
21         {
22             if (index == 0)
23                 return &foo->x;
24             if (index == 1)
25                 return &foo->y;
26             return null;
27         }
28         int foo()
29         {
30             Foo foo;
31             foo.x = 498;
32             foo.y = 19;
33             return foo[0] + foo[1] * 3;
34         }
35     `;
36     assert_equals(await callIntFunction(program, "foo", []), 498 + 19 * 3);
37 }
38
39 whlslTests.overrideSubscriptStructAndDoStores = async () =>
40 {
41     let program = `
42         struct Foo {
43             int x;
44             int y;
45         }
46         thread int* operator&[](thread Foo* foo, uint index)
47         {
48             if (index == 0)
49                 return &foo->x;
50             if (index == 1)
51                 return &foo->y;
52             return null;
53         }
54         int foo()
55         {
56             Foo foo;
57             foo[0] = 498;
58             foo[1] = 19;
59             return foo.x + foo.y;
60         }
61     `;
62     assert_equals(await callIntFunction(program, "foo", []), 498 + 19);
63 }
64
65 whlslTests.overrideSubscriptStructAndUsePointers = async () =>
66 {
67     let program = `
68         struct Foo {
69             int x;
70             int y;
71         }
72         thread int* operator&[](thread Foo* foo, uint index)
73         {
74             if (index == 0)
75                 return &foo->x;
76             if (index == 1)
77                 return &foo->y;
78             return null;
79         }
80         int bar(thread Foo* foo)
81         {
82             return (*foo)[0] + (*foo)[1];
83         }
84         int foo()
85         {
86             Foo foo;
87             foo.x = 498;
88             foo.y = 19;
89             return bar(&foo);
90         }
91     `;
92     assert_equals(await callIntFunction(program, "foo", []), 498 + 19);
93 }
94
95 whlslTests.overrideSubscriptStructAndUsePointersIncorrectly = async () =>
96 {
97     checkFail(
98         `
99             struct Foo {
100                 int x;
101                 int y;
102             }
103             thread int* operator&[](thread Foo* foo, uint index)
104             {
105                 if (index == 0)
106                     return &foo->x;
107                 if (index == 1)
108                     return &foo->y;
109                 return null;
110             }
111             int bar(thread Foo* foo)
112             {
113                 return foo[0] + foo[1];
114             }
115             int foo()
116             {
117                 Foo foo;
118                 foo.x = 498;
119                 foo.y = 19;
120                 return bar(&foo);
121             }
122         `);
123 }
124
125 runTests(whlslTests);
126 </script>
127 </html>
128