1#!amber
2# Copyright 2020 The Amber Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     https:#www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16SET ENGINE_DATA fence_timeout_ms 1000000
17
18VIRTUAL_FILE "compute.hlsl"
19
20[[vk::binding(0)]]
21StructuredBuffer<int> data;
22
23int C(int x)
24{
25  int y = x*x;
26  return y;
27}
28
29int B(int x)
30{
31  int y = x + 2;
32  return C(y) * 2;
33}
34
35int A(int x)
36{
37  int y = B(x + 1);
38  int z = B(y) + B(y+1);
39  return x + y + z;
40}
41
42[numthreads(1,1,1)]
43void main() {
44  data[0] = A(data[0]);
45}
46END
47
48SHADER compute shader HLSL VIRTUAL_FILE "compute.hlsl"
49
50BUFFER data DATA_TYPE int32 DATA
51  10
52END
53
54PIPELINE compute pipeline
55  ATTACH shader
56  SHADER_OPTIMIZATION shader
57    --legalize-hlsl
58  END
59  BIND BUFFER data AS storage DESCRIPTOR_SET 0 BINDING 0
60END
61
62DEBUG pipeline 1 1 1
63    THREAD GLOBAL_INVOCATION_ID 0 0 0
64        EXPECT CALLSTACK
65          "main" "compute.hlsl" 26
66        END
67        EXPECT LOCATION "compute.hlsl" 26  "  data[0] = A(data[0]);"
68        STEP_IN
69
70        EXPECT CALLSTACK
71          "A"    "compute.hlsl" 18
72          "main" "compute.hlsl" 26
73        END
74        EXPECT LOCATION "compute.hlsl" 18  "{"
75        STEP_IN
76
77        EXPECT CALLSTACK
78          "A"    "compute.hlsl" 19
79          "main" "compute.hlsl" 26
80        END
81        EXPECT LOCATION "compute.hlsl" 19  "  int y = B(x + 1);"
82        EXPECT LOCAL "x" EQ 10
83        STEP_IN
84
85        EXPECT CALLSTACK
86          "B"    "compute.hlsl" 12
87          "A"    "compute.hlsl" 19
88          "main" "compute.hlsl" 26
89        END
90        EXPECT LOCATION "compute.hlsl" 12  "{"
91        STEP_IN
92
93        EXPECT CALLSTACK
94          "B"    "compute.hlsl" 13
95          "A"    "compute.hlsl" 19
96          "main" "compute.hlsl" 26
97        END
98        EXPECT LOCATION "compute.hlsl" 13  "  int y = x + 2;"
99        EXPECT LOCAL "x" EQ 11
100        STEP_IN
101
102        EXPECT CALLSTACK
103          "B"    "compute.hlsl" 14
104          "A"    "compute.hlsl" 19
105          "main" "compute.hlsl" 26
106        END
107        EXPECT LOCATION "compute.hlsl" 14  "  return C(y) * 2;"
108        EXPECT LOCAL "x" EQ 11
109        EXPECT LOCAL "y" EQ 13
110        STEP_IN
111
112        EXPECT CALLSTACK
113          "C"    "compute.hlsl" 6
114          "B"    "compute.hlsl" 14
115          "A"    "compute.hlsl" 19
116          "main" "compute.hlsl" 26
117        END
118        EXPECT LOCATION "compute.hlsl" 6  "{"
119        STEP_IN
120
121        EXPECT CALLSTACK
122          "C"    "compute.hlsl" 7
123          "B"    "compute.hlsl" 14
124          "A"    "compute.hlsl" 19
125          "main" "compute.hlsl" 26
126        END
127        EXPECT LOCATION "compute.hlsl" 7   "  int y = x*x;"
128        EXPECT LOCAL "x" EQ 13
129        STEP_IN
130
131        # TODO: Returns are non-steppable. Fix
132        # EXPECT LOCATION "compute.hlsl" 8   "  return y;"
133        # EXPECT LOCAL "x" EQ 11 # TODO: "x" should be visible
134        # EXPECT LOCAL "y" EQ 0
135        # STEP_IN
136        # EXPECT CALLSTACK
137        #   "B"    "compute.hlsl" 14
138        #   "A"    "compute.hlsl" 19
139        #   "main" "compute.hlsl" 26
140        # END
141
142        EXPECT CALLSTACK
143          "B"    "compute.hlsl" 14
144          "A"    "compute.hlsl" 19
145          "main" "compute.hlsl" 26
146        END
147        EXPECT LOCATION "compute.hlsl" 14  "  return C(y) * 2;"
148        STEP_IN
149        EXPECT CALLSTACK
150          "A"    "compute.hlsl" 19
151          "main" "compute.hlsl" 26
152        END
153
154        EXPECT CALLSTACK
155          "A"    "compute.hlsl" 19
156          "main" "compute.hlsl" 26
157        END
158        EXPECT LOCATION "compute.hlsl" 19  "  int y = B(x + 1);"
159        STEP_IN
160
161        EXPECT CALLSTACK
162          "A"    "compute.hlsl" 20
163          "main" "compute.hlsl" 26
164        END
165        EXPECT LOCATION "compute.hlsl" 20  "  int z = B(y) + B(y+1);"
166        EXPECT LOCAL "y" EQ 338
167        STEP_IN
168
169        EXPECT CALLSTACK
170          "B"    "compute.hlsl" 12
171          "A"    "compute.hlsl" 20
172          "main" "compute.hlsl" 26
173        END
174        EXPECT LOCATION "compute.hlsl" 12  "{"
175        STEP_IN
176
177        EXPECT CALLSTACK
178          "B"    "compute.hlsl" 13
179          "A"    "compute.hlsl" 20
180          "main" "compute.hlsl" 26
181        END
182        EXPECT LOCATION "compute.hlsl" 13  "  int y = x + 2;"
183        STEP_OUT
184
185        EXPECT CALLSTACK
186          "A"    "compute.hlsl" 20
187          "main" "compute.hlsl" 26
188        END
189        EXPECT LOCATION "compute.hlsl" 20  "  int z = B(y) + B(y+1);"
190        EXPECT LOCAL "y" EQ 338
191        STEP_OVER
192        STEP_OVER
193
194        EXPECT CALLSTACK
195          "A"    "compute.hlsl" 21
196          "main" "compute.hlsl" 26
197        END
198        EXPECT LOCATION "compute.hlsl" 21  "  return x + y + z;"
199        EXPECT LOCAL "y" EQ 338
200        EXPECT LOCAL "z" EQ 463762
201        STEP_OUT
202
203        EXPECT CALLSTACK
204          "main" "compute.hlsl" 26
205        END
206        EXPECT LOCATION "compute.hlsl" 26  "  data[0] = A(data[0]);"
207
208        CONTINUE
209    END
210END
211
212EXPECT data IDX 0 EQ 464110
213