Merge ../mesa into vulkan
[mesa.git] / src / gallium / tests / trivial / compute.c
1 /*
2 * Copyright (C) 2011 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 #include <fcntl.h>
28 #include <stdio.h>
29 #include <sys/stat.h>
30 #include <inttypes.h>
31 #include "pipe/p_state.h"
32 #include "pipe/p_context.h"
33 #include "pipe/p_screen.h"
34 #include "pipe/p_defines.h"
35 #include "pipe/p_shader_tokens.h"
36 #include "util/u_memory.h"
37 #include "util/u_inlines.h"
38 #include "util/u_sampler.h"
39 #include "util/u_format.h"
40 #include "tgsi/tgsi_text.h"
41 #include "pipe-loader/pipe_loader.h"
42
43 #define MAX_RESOURCES 4
44
45 struct context {
46 struct pipe_loader_device *dev;
47 struct pipe_screen *screen;
48 struct pipe_context *pipe;
49 void *hwcs;
50 void *hwsmp[MAX_RESOURCES];
51 struct pipe_resource *tex[MAX_RESOURCES];
52 bool tex_rw[MAX_RESOURCES];
53 struct pipe_sampler_view *view[MAX_RESOURCES];
54 struct pipe_surface *surf[MAX_RESOURCES];
55 };
56
57 #define DUMP_COMPUTE_PARAM(p, c) do { \
58 uint64_t __v[4]; \
59 int __i, __n; \
60 \
61 __n = ctx->screen->get_compute_param(ctx->screen, c, __v); \
62 printf("%s: {", #c); \
63 \
64 for (__i = 0; __i < __n / sizeof(*__v); ++__i) \
65 printf(" %"PRIu64, __v[__i]); \
66 \
67 printf(" }\n"); \
68 } while (0)
69
70 static void init_ctx(struct context *ctx)
71 {
72 int ret;
73
74 ret = pipe_loader_probe(&ctx->dev, 1);
75 assert(ret);
76
77 ctx->screen = pipe_loader_create_screen(ctx->dev);
78 assert(ctx->screen);
79
80 ctx->pipe = ctx->screen->context_create(ctx->screen, NULL, 0);
81 assert(ctx->pipe);
82
83 DUMP_COMPUTE_PARAM(p, PIPE_COMPUTE_CAP_GRID_DIMENSION);
84 DUMP_COMPUTE_PARAM(p, PIPE_COMPUTE_CAP_MAX_GRID_SIZE);
85 DUMP_COMPUTE_PARAM(p, PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE);
86 }
87
88 static void destroy_ctx(struct context *ctx)
89 {
90 ctx->pipe->destroy(ctx->pipe);
91 ctx->screen->destroy(ctx->screen);
92 pipe_loader_release(&ctx->dev, 1);
93 FREE(ctx);
94 }
95
96 static char *
97 preprocess_prog(struct context *ctx, const char *src, const char *defs)
98 {
99 const char header[] =
100 "#define RGLOBAL RES[32767]\n"
101 "#define RLOCAL RES[32766]\n"
102 "#define RPRIVATE RES[32765]\n"
103 "#define RINPUT RES[32764]\n";
104 char cmd[512];
105 char tmp[] = "/tmp/test-compute.tgsi-XXXXXX";
106 char *buf;
107 int fd, ret;
108 struct stat st;
109 FILE *p;
110
111 /* Open a temporary file */
112 fd = mkstemp(tmp);
113 assert(fd >= 0);
114 snprintf(cmd, sizeof(cmd), "cpp -P -nostdinc -undef %s > %s",
115 defs ? defs : "", tmp);
116
117 /* Preprocess */
118 p = popen(cmd, "w");
119 fwrite(header, strlen(header), 1, p);
120 fwrite(src, strlen(src), 1, p);
121 ret = pclose(p);
122 assert(!ret);
123
124 /* Read back */
125 ret = fstat(fd, &st);
126 assert(!ret);
127
128 buf = malloc(st.st_size + 1);
129 ret = read(fd, buf, st.st_size);
130 assert(ret == st.st_size);
131 buf[ret] = 0;
132
133 /* Clean up */
134 close(fd);
135 unlink(tmp);
136
137 return buf;
138 }
139
140 static void init_prog(struct context *ctx, unsigned local_sz,
141 unsigned private_sz, unsigned input_sz,
142 const char *src, const char *defs)
143 {
144 struct pipe_context *pipe = ctx->pipe;
145 struct tgsi_token prog[1024];
146 struct pipe_compute_state cs = {
147 .prog = prog,
148 .req_local_mem = local_sz,
149 .req_private_mem = private_sz,
150 .req_input_mem = input_sz
151 };
152 char *psrc = preprocess_prog(ctx, src, defs);
153 int ret;
154
155 ret = tgsi_text_translate(psrc, prog, Elements(prog));
156 assert(ret);
157 free(psrc);
158
159 ctx->hwcs = pipe->create_compute_state(pipe, &cs);
160 assert(ctx->hwcs);
161
162 pipe->bind_compute_state(pipe, ctx->hwcs);
163 }
164
165 static void destroy_prog(struct context *ctx)
166 {
167 struct pipe_context *pipe = ctx->pipe;
168
169 pipe->delete_compute_state(pipe, ctx->hwcs);
170 ctx->hwcs = NULL;
171 }
172
173 static void init_tex(struct context *ctx, int slot,
174 enum pipe_texture_target target, bool rw,
175 enum pipe_format format, int w, int h,
176 void (*init)(void *, int, int, int))
177 {
178 struct pipe_context *pipe = ctx->pipe;
179 struct pipe_resource **tex = &ctx->tex[slot];
180 struct pipe_resource ttex = {
181 .target = target,
182 .format = format,
183 .width0 = w,
184 .height0 = h,
185 .depth0 = 1,
186 .array_size = 1,
187 .bind = (PIPE_BIND_SAMPLER_VIEW |
188 PIPE_BIND_COMPUTE_RESOURCE |
189 PIPE_BIND_GLOBAL)
190 };
191 int dx = util_format_get_blocksize(format);
192 int dy = util_format_get_stride(format, w);
193 int nx = (target == PIPE_BUFFER ? (w / dx) :
194 util_format_get_nblocksx(format, w));
195 int ny = (target == PIPE_BUFFER ? 1 :
196 util_format_get_nblocksy(format, h));
197 struct pipe_transfer *xfer;
198 char *map;
199 int x, y;
200
201 *tex = ctx->screen->resource_create(ctx->screen, &ttex);
202 assert(*tex);
203
204 map = pipe->transfer_map(pipe, *tex, 0, PIPE_TRANSFER_WRITE,
205 &(struct pipe_box) { .width = w,
206 .height = h,
207 .depth = 1 }, &xfer);
208 assert(xfer);
209 assert(map);
210
211 for (y = 0; y < ny; ++y) {
212 for (x = 0; x < nx; ++x) {
213 init(map + y * dy + x * dx, slot, x, y);
214 }
215 }
216
217 pipe->transfer_unmap(pipe, xfer);
218
219 ctx->tex_rw[slot] = rw;
220 }
221
222 static bool default_check(void *x, void *y, int sz) {
223 return !memcmp(x, y, sz);
224 }
225
226 static void check_tex(struct context *ctx, int slot,
227 void (*expect)(void *, int, int, int),
228 bool (*check)(void *, void *, int))
229 {
230 struct pipe_context *pipe = ctx->pipe;
231 struct pipe_resource *tex = ctx->tex[slot];
232 int dx = util_format_get_blocksize(tex->format);
233 int dy = util_format_get_stride(tex->format, tex->width0);
234 int nx = (tex->target == PIPE_BUFFER ? (tex->width0 / dx) :
235 util_format_get_nblocksx(tex->format, tex->width0));
236 int ny = (tex->target == PIPE_BUFFER ? 1 :
237 util_format_get_nblocksy(tex->format, tex->height0));
238 struct pipe_transfer *xfer;
239 char *map;
240 int x, y, i;
241 int err = 0;
242
243 if (!check)
244 check = default_check;
245
246 map = pipe->transfer_map(pipe, tex, 0, PIPE_TRANSFER_READ,
247 &(struct pipe_box) { .width = tex->width0,
248 .height = tex->height0,
249 .depth = 1 }, &xfer);
250 assert(xfer);
251 assert(map);
252
253 for (y = 0; y < ny; ++y) {
254 for (x = 0; x < nx; ++x) {
255 uint32_t exp[4];
256 uint32_t *res = (uint32_t *)(map + y * dy + x * dx);
257
258 expect(exp, slot, x, y);
259 if (check(res, exp, dx) || (++err) > 20)
260 continue;
261
262 if (dx < 4) {
263 uint32_t u = 0, v = 0;
264
265 for (i = 0; i < dx; i++) {
266 u |= ((uint8_t *)exp)[i] << (8 * i);
267 v |= ((uint8_t *)res)[i] << (8 * i);
268 }
269 printf("(%d, %d): got 0x%x, expected 0x%x\n",
270 x, y, v, u);
271 } else {
272 for (i = 0; i < dx / 4; i++) {
273 printf("(%d, %d)[%d]: got 0x%x/%f,"
274 " expected 0x%x/%f\n", x, y, i,
275 res[i], ((float *)res)[i],
276 exp[i], ((float *)exp)[i]);
277 }
278 }
279 }
280 }
281
282 pipe->transfer_unmap(pipe, xfer);
283
284 if (err)
285 printf("(%d, %d): \x1b[31mFAIL\x1b[0m (%d)\n", x, y, err);
286 else
287 printf("(%d, %d): \x1b[32mOK\x1b[0m\n", x, y);
288 }
289
290 static void destroy_tex(struct context *ctx)
291 {
292 int i;
293
294 for (i = 0; i < MAX_RESOURCES; ++i) {
295 if (ctx->tex[i])
296 pipe_resource_reference(&ctx->tex[i], NULL);
297 }
298 }
299
300 static void init_sampler_views(struct context *ctx, const int *slots)
301 {
302 struct pipe_context *pipe = ctx->pipe;
303 struct pipe_sampler_view tview;
304 int i;
305
306 for (i = 0; *slots >= 0; ++i, ++slots) {
307 u_sampler_view_default_template(&tview, ctx->tex[*slots],
308 ctx->tex[*slots]->format);
309
310 ctx->view[i] = pipe->create_sampler_view(pipe, ctx->tex[*slots],
311 &tview);
312 assert(ctx->view[i]);
313 }
314
315 pipe->set_sampler_views(pipe, PIPE_SHADER_COMPUTE, 0, i, ctx->view);
316 }
317
318 static void destroy_sampler_views(struct context *ctx)
319 {
320 struct pipe_context *pipe = ctx->pipe;
321 int i;
322
323 pipe->set_sampler_views(pipe, PIPE_SHADER_COMPUTE, 0, MAX_RESOURCES, NULL);
324
325 for (i = 0; i < MAX_RESOURCES; ++i) {
326 if (ctx->view[i]) {
327 pipe->sampler_view_destroy(pipe, ctx->view[i]);
328 ctx->view[i] = NULL;
329 }
330 }
331 }
332
333 static void init_compute_resources(struct context *ctx, const int *slots)
334 {
335 struct pipe_context *pipe = ctx->pipe;
336 int i;
337
338 for (i = 0; *slots >= 0; ++i, ++slots) {
339 struct pipe_surface tsurf = {
340 .format = ctx->tex[*slots]->format,
341 .writable = ctx->tex_rw[*slots]
342 };
343
344 if (ctx->tex[*slots]->target == PIPE_BUFFER)
345 tsurf.u.buf.last_element = ctx->tex[*slots]->width0 - 1;
346
347 ctx->surf[i] = pipe->create_surface(pipe, ctx->tex[*slots],
348 &tsurf);
349 assert(ctx->surf[i]);
350 }
351
352 pipe->set_compute_resources(pipe, 0, i, ctx->surf);
353 }
354
355 static void destroy_compute_resources(struct context *ctx)
356 {
357 struct pipe_context *pipe = ctx->pipe;
358 int i;
359
360 pipe->set_compute_resources(pipe, 0, MAX_RESOURCES, NULL);
361
362 for (i = 0; i < MAX_RESOURCES; ++i) {
363 if (ctx->surf[i]) {
364 pipe->surface_destroy(pipe, ctx->surf[i]);
365 ctx->surf[i] = NULL;
366 }
367 }
368 }
369
370 static void init_sampler_states(struct context *ctx, int n)
371 {
372 struct pipe_context *pipe = ctx->pipe;
373 struct pipe_sampler_state smp = {
374 .normalized_coords = 1,
375 };
376 int i;
377
378 for (i = 0; i < n; ++i) {
379 ctx->hwsmp[i] = pipe->create_sampler_state(pipe, &smp);
380 assert(ctx->hwsmp[i]);
381 }
382
383 pipe->bind_sampler_states(pipe, PIPE_SHADER_COMPUTE, 0, i, ctx->hwsmp);
384 }
385
386 static void destroy_sampler_states(struct context *ctx)
387 {
388 struct pipe_context *pipe = ctx->pipe;
389 int i;
390
391 pipe->bind_sampler_states(pipe, PIPE_SHADER_COMPUTE,
392 0, MAX_RESOURCES, NULL);
393
394 for (i = 0; i < MAX_RESOURCES; ++i) {
395 if (ctx->hwsmp[i]) {
396 pipe->delete_sampler_state(pipe, ctx->hwsmp[i]);
397 ctx->hwsmp[i] = NULL;
398 }
399 }
400 }
401
402 static void init_globals(struct context *ctx, const int *slots,
403 uint32_t **handles)
404 {
405 struct pipe_context *pipe = ctx->pipe;
406 struct pipe_resource *res[MAX_RESOURCES];
407 int i;
408
409 for (i = 0; *slots >= 0; ++i, ++slots)
410 res[i] = ctx->tex[*slots];
411
412 pipe->set_global_binding(pipe, 0, i, res, handles);
413 }
414
415 static void destroy_globals(struct context *ctx)
416 {
417 struct pipe_context *pipe = ctx->pipe;
418
419 pipe->set_global_binding(pipe, 0, MAX_RESOURCES, NULL, NULL);
420 }
421
422 static void launch_grid(struct context *ctx, const uint *block_layout,
423 const uint *grid_layout, uint32_t pc,
424 const void *input)
425 {
426 struct pipe_context *pipe = ctx->pipe;
427
428 pipe->launch_grid(pipe, block_layout, grid_layout, pc, input);
429 }
430
431 static void test_default_init(void *p, int s, int x, int y)
432 {
433 *(uint32_t *)p = 0xdeadbeef;
434 }
435
436 /* test_system_values */
437 static void test_system_values_expect(void *p, int s, int x, int y)
438 {
439 int id = x / 16, sv = (x % 16) / 4, c = x % 4;
440 int tid[] = { id % 20, (id % 240) / 20, id / 240, 0 };
441 int bsz[] = { 4, 3, 5, 1};
442 int gsz[] = { 5, 4, 1, 1};
443
444 switch (sv) {
445 case 0:
446 *(uint32_t *)p = tid[c] / bsz[c];
447 break;
448 case 1:
449 *(uint32_t *)p = bsz[c];
450 break;
451 case 2:
452 *(uint32_t *)p = gsz[c];
453 break;
454 case 3:
455 *(uint32_t *)p = tid[c] % bsz[c];
456 break;
457 }
458 }
459
460 static void test_system_values(struct context *ctx)
461 {
462 const char *src = "COMP\n"
463 "DCL RES[0], BUFFER, RAW, WR\n"
464 "DCL SV[0], BLOCK_ID[0]\n"
465 "DCL SV[1], BLOCK_SIZE[0]\n"
466 "DCL SV[2], GRID_SIZE[0]\n"
467 "DCL SV[3], THREAD_ID[0]\n"
468 "DCL TEMP[0], LOCAL\n"
469 "DCL TEMP[1], LOCAL\n"
470 "IMM UINT32 { 64, 0, 0, 0 }\n"
471 "IMM UINT32 { 16, 0, 0, 0 }\n"
472 "IMM UINT32 { 0, 0, 0, 0 }\n"
473 "\n"
474 "BGNSUB"
475 " UMUL TEMP[0], SV[0], SV[1]\n"
476 " UADD TEMP[0], TEMP[0], SV[3]\n"
477 " UMUL TEMP[1], SV[1], SV[2]\n"
478 " UMUL TEMP[0].w, TEMP[0], TEMP[1].zzzz\n"
479 " UMUL TEMP[0].zw, TEMP[0], TEMP[1].yyyy\n"
480 " UMUL TEMP[0].yzw, TEMP[0], TEMP[1].xxxx\n"
481 " UADD TEMP[0].xy, TEMP[0].xyxy, TEMP[0].zwzw\n"
482 " UADD TEMP[0].x, TEMP[0].xxxx, TEMP[0].yyyy\n"
483 " UMUL TEMP[0].x, TEMP[0], IMM[0]\n"
484 " STORE RES[0].xyzw, TEMP[0], SV[0]\n"
485 " UADD TEMP[0].x, TEMP[0], IMM[1]\n"
486 " STORE RES[0].xyzw, TEMP[0], SV[1]\n"
487 " UADD TEMP[0].x, TEMP[0], IMM[1]\n"
488 " STORE RES[0].xyzw, TEMP[0], SV[2]\n"
489 " UADD TEMP[0].x, TEMP[0], IMM[1]\n"
490 " STORE RES[0].xyzw, TEMP[0], SV[3]\n"
491 " RET\n"
492 "ENDSUB\n";
493
494 printf("- %s\n", __func__);
495
496 init_prog(ctx, 0, 0, 0, src, NULL);
497 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
498 76800, 0, test_default_init);
499 init_compute_resources(ctx, (int []) { 0, -1 });
500 launch_grid(ctx, (uint []){4, 3, 5}, (uint []){5, 4, 1}, 0, NULL);
501 check_tex(ctx, 0, test_system_values_expect, NULL);
502 destroy_compute_resources(ctx);
503 destroy_tex(ctx);
504 destroy_prog(ctx);
505 }
506
507 /* test_resource_access */
508 static void test_resource_access_init0(void *p, int s, int x, int y)
509 {
510 *(float *)p = 8.0 - (float)x;
511 }
512
513 static void test_resource_access_expect(void *p, int s, int x, int y)
514 {
515 *(float *)p = 8.0 - (float)((x + 4 * y) & 0x3f);
516 }
517
518 static void test_resource_access(struct context *ctx)
519 {
520 const char *src = "COMP\n"
521 "DCL RES[0], BUFFER, RAW, WR\n"
522 "DCL RES[1], 2D, RAW, WR\n"
523 "DCL SV[0], BLOCK_ID[0]\n"
524 "DCL TEMP[0], LOCAL\n"
525 "DCL TEMP[1], LOCAL\n"
526 "IMM UINT32 { 15, 0, 0, 0 }\n"
527 "IMM UINT32 { 16, 1, 0, 0 }\n"
528 "\n"
529 " BGNSUB\n"
530 " UADD TEMP[0].x, SV[0].xxxx, SV[0].yyyy\n"
531 " AND TEMP[0].x, TEMP[0], IMM[0]\n"
532 " UMUL TEMP[0].x, TEMP[0], IMM[1]\n"
533 " LOAD TEMP[0].xyzw, RES[0], TEMP[0]\n"
534 " UMUL TEMP[1], SV[0], IMM[1]\n"
535 " STORE RES[1].xyzw, TEMP[1], TEMP[0]\n"
536 " RET\n"
537 " ENDSUB\n";
538
539 printf("- %s\n", __func__);
540
541 init_prog(ctx, 0, 0, 0, src, NULL);
542 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
543 256, 0, test_resource_access_init0);
544 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
545 60, 12, test_default_init);
546 init_compute_resources(ctx, (int []) { 0, 1, -1 });
547 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){15, 12, 1}, 0, NULL);
548 check_tex(ctx, 1, test_resource_access_expect, NULL);
549 destroy_compute_resources(ctx);
550 destroy_tex(ctx);
551 destroy_prog(ctx);
552 }
553
554 /* test_function_calls */
555 static void test_function_calls_init(void *p, int s, int x, int y)
556 {
557 *(uint32_t *)p = 15 * y + x;
558 }
559
560 static void test_function_calls_expect(void *p, int s, int x, int y)
561 {
562 *(uint32_t *)p = (15 * y + x) < 4 ? 2 : 1 ;
563 }
564
565 static void test_function_calls(struct context *ctx)
566 {
567 const char *src = "COMP\n"
568 "DCL RES[0], 2D, RAW, WR\n"
569 "DCL SV[0], BLOCK_ID[0]\n"
570 "DCL SV[1], BLOCK_SIZE[0]\n"
571 "DCL SV[2], GRID_SIZE[0]\n"
572 "DCL SV[3], THREAD_ID[0]\n"
573 "DCL TEMP[0]\n"
574 "DCL TEMP[1]\n"
575 "DCL TEMP[2], LOCAL\n"
576 "IMM UINT32 { 0, 11, 22, 33 }\n"
577 "IMM FLT32 { 11, 33, 55, 99 }\n"
578 "IMM UINT32 { 4, 1, 0, 0 }\n"
579 "IMM UINT32 { 12, 0, 0, 0 }\n"
580 "\n"
581 "00: BGNSUB\n"
582 "01: UMUL TEMP[0].x, TEMP[0], TEMP[0]\n"
583 "02: UADD TEMP[1].x, TEMP[1], IMM[2].yyyy\n"
584 "03: USLT TEMP[0].x, TEMP[0], IMM[0]\n"
585 "04: RET\n"
586 "05: ENDSUB\n"
587 "06: BGNSUB\n"
588 "07: UMUL TEMP[0].x, TEMP[0], TEMP[0]\n"
589 "08: UADD TEMP[1].x, TEMP[1], IMM[2].yyyy\n"
590 "09: USLT TEMP[0].x, TEMP[0], IMM[0].yyyy\n"
591 "10: IF TEMP[0].xxxx\n"
592 "11: CAL :0\n"
593 "12: ENDIF\n"
594 "13: RET\n"
595 "14: ENDSUB\n"
596 "15: BGNSUB\n"
597 "16: UMUL TEMP[2], SV[0], SV[1]\n"
598 "17: UADD TEMP[2], TEMP[2], SV[3]\n"
599 "18: UMUL TEMP[2], TEMP[2], IMM[2]\n"
600 "00: MOV TEMP[1].x, IMM[2].wwww\n"
601 "19: LOAD TEMP[0].x, RES[0].xxxx, TEMP[2]\n"
602 "20: CAL :6\n"
603 "21: STORE RES[0].x, TEMP[2], TEMP[1].xxxx\n"
604 "22: RET\n"
605 "23: ENDSUB\n";
606
607 printf("- %s\n", __func__);
608
609 init_prog(ctx, 0, 0, 0, src, NULL);
610 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
611 15, 12, test_function_calls_init);
612 init_compute_resources(ctx, (int []) { 0, -1 });
613 launch_grid(ctx, (uint []){3, 3, 3}, (uint []){5, 4, 1}, 15, NULL);
614 check_tex(ctx, 0, test_function_calls_expect, NULL);
615 destroy_compute_resources(ctx);
616 destroy_tex(ctx);
617 destroy_prog(ctx);
618 }
619
620 /* test_input_global */
621 static void test_input_global_expect(void *p, int s, int x, int y)
622 {
623 *(uint32_t *)p = 0xdeadbeef - (x == 0 ? 0x10001 + 2 * s : 0);
624 }
625
626 static void test_input_global(struct context *ctx)
627 {
628 const char *src = "COMP\n"
629 "DCL SV[0], THREAD_ID[0]\n"
630 "DCL TEMP[0], LOCAL\n"
631 "DCL TEMP[1], LOCAL\n"
632 "IMM UINT32 { 8, 0, 0, 0 }\n"
633 "\n"
634 " BGNSUB\n"
635 " UMUL TEMP[0], SV[0], IMM[0]\n"
636 " LOAD TEMP[1].xy, RINPUT, TEMP[0]\n"
637 " LOAD TEMP[0].x, RGLOBAL, TEMP[1].yyyy\n"
638 " UADD TEMP[1].x, TEMP[0], -TEMP[1]\n"
639 " STORE RGLOBAL.x, TEMP[1].yyyy, TEMP[1]\n"
640 " RET\n"
641 " ENDSUB\n";
642 uint32_t input[8] = { 0x10001, 0x10002, 0x10003, 0x10004,
643 0x10005, 0x10006, 0x10007, 0x10008 };
644
645 printf("- %s\n", __func__);
646
647 init_prog(ctx, 0, 0, 32, src, NULL);
648 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
649 test_default_init);
650 init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
651 test_default_init);
652 init_tex(ctx, 2, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
653 test_default_init);
654 init_tex(ctx, 3, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
655 test_default_init);
656 init_globals(ctx, (int []){ 0, 1, 2, 3, -1 },
657 (uint32_t *[]){ &input[1], &input[3],
658 &input[5], &input[7] });
659 launch_grid(ctx, (uint []){4, 1, 1}, (uint []){1, 1, 1}, 0, input);
660 check_tex(ctx, 0, test_input_global_expect, NULL);
661 check_tex(ctx, 1, test_input_global_expect, NULL);
662 check_tex(ctx, 2, test_input_global_expect, NULL);
663 check_tex(ctx, 3, test_input_global_expect, NULL);
664 destroy_globals(ctx);
665 destroy_tex(ctx);
666 destroy_prog(ctx);
667 }
668
669 /* test_private */
670 static void test_private_expect(void *p, int s, int x, int y)
671 {
672 *(uint32_t *)p = (x / 32) + x % 32;
673 }
674
675 static void test_private(struct context *ctx)
676 {
677 const char *src = "COMP\n"
678 "DCL RES[0], BUFFER, RAW, WR\n"
679 "DCL SV[0], BLOCK_ID[0]\n"
680 "DCL SV[1], BLOCK_SIZE[0]\n"
681 "DCL SV[2], THREAD_ID[0]\n"
682 "DCL TEMP[0], LOCAL\n"
683 "DCL TEMP[1], LOCAL\n"
684 "DCL TEMP[2], LOCAL\n"
685 "IMM UINT32 { 128, 0, 0, 0 }\n"
686 "IMM UINT32 { 4, 0, 0, 0 }\n"
687 "\n"
688 " BGNSUB\n"
689 " UMUL TEMP[0].x, SV[0], SV[1]\n"
690 " UADD TEMP[0].x, TEMP[0], SV[2]\n"
691 " MOV TEMP[1].x, IMM[0].wwww\n"
692 " BGNLOOP\n"
693 " USEQ TEMP[2].x, TEMP[1], IMM[0]\n"
694 " IF TEMP[2]\n"
695 " BRK\n"
696 " ENDIF\n"
697 " UDIV TEMP[2].x, TEMP[1], IMM[1]\n"
698 " UADD TEMP[2].x, TEMP[2], TEMP[0]\n"
699 " STORE RPRIVATE.x, TEMP[1], TEMP[2]\n"
700 " UADD TEMP[1].x, TEMP[1], IMM[1]\n"
701 " ENDLOOP\n"
702 " MOV TEMP[1].x, IMM[0].wwww\n"
703 " UMUL TEMP[0].x, TEMP[0], IMM[0]\n"
704 " BGNLOOP\n"
705 " USEQ TEMP[2].x, TEMP[1], IMM[0]\n"
706 " IF TEMP[2]\n"
707 " BRK\n"
708 " ENDIF\n"
709 " LOAD TEMP[2].x, RPRIVATE, TEMP[1]\n"
710 " STORE RES[0].x, TEMP[0], TEMP[2]\n"
711 " UADD TEMP[0].x, TEMP[0], IMM[1]\n"
712 " UADD TEMP[1].x, TEMP[1], IMM[1]\n"
713 " ENDLOOP\n"
714 " RET\n"
715 " ENDSUB\n";
716
717 printf("- %s\n", __func__);
718
719 init_prog(ctx, 0, 128, 0, src, NULL);
720 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
721 32768, 0, test_default_init);
722 init_compute_resources(ctx, (int []) { 0, -1 });
723 launch_grid(ctx, (uint []){16, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
724 check_tex(ctx, 0, test_private_expect, NULL);
725 destroy_compute_resources(ctx);
726 destroy_tex(ctx);
727 destroy_prog(ctx);
728 }
729
730 /* test_local */
731 static void test_local_expect(void *p, int s, int x, int y)
732 {
733 *(uint32_t *)p = x & 0x20 ? 2 : 1;
734 }
735
736 static void test_local(struct context *ctx)
737 {
738 const char *src = "COMP\n"
739 "DCL RES[0], BUFFER, RAW, WR\n"
740 "DCL SV[0], BLOCK_ID[0]\n"
741 "DCL SV[1], BLOCK_SIZE[0]\n"
742 "DCL SV[2], THREAD_ID[0]\n"
743 "DCL TEMP[0], LOCAL\n"
744 "DCL TEMP[1], LOCAL\n"
745 "DCL TEMP[2], LOCAL\n"
746 "IMM UINT32 { 1, 0, 0, 0 }\n"
747 "IMM UINT32 { 2, 0, 0, 0 }\n"
748 "IMM UINT32 { 4, 0, 0, 0 }\n"
749 "IMM UINT32 { 32, 0, 0, 0 }\n"
750 "IMM UINT32 { 128, 0, 0, 0 }\n"
751 "\n"
752 " BGNSUB\n"
753 " UMUL TEMP[0].x, SV[2], IMM[2]\n"
754 " STORE RLOCAL.x, TEMP[0], IMM[0].wwww\n"
755 " MFENCE RLOCAL\n"
756 " USLT TEMP[1].x, SV[2], IMM[3]\n"
757 " IF TEMP[1]\n"
758 " UADD TEMP[1].x, TEMP[0], IMM[4]\n"
759 " BGNLOOP\n"
760 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
761 " USEQ TEMP[2].x, TEMP[2], IMM[0]\n"
762 " IF TEMP[2]\n"
763 " BRK\n"
764 " ENDIF\n"
765 " ENDLOOP\n"
766 " STORE RLOCAL.x, TEMP[0], IMM[0]\n"
767 " MFENCE RLOCAL\n"
768 " BGNLOOP\n"
769 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
770 " USEQ TEMP[2].x, TEMP[2], IMM[1]\n"
771 " IF TEMP[2]\n"
772 " BRK\n"
773 " ENDIF\n"
774 " ENDLOOP\n"
775 " ELSE\n"
776 " UADD TEMP[1].x, TEMP[0], -IMM[4]\n"
777 " BGNLOOP\n"
778 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
779 " USEQ TEMP[2].x, TEMP[2], IMM[0].wwww\n"
780 " IF TEMP[2]\n"
781 " BRK\n"
782 " ENDIF\n"
783 " ENDLOOP\n"
784 " STORE RLOCAL.x, TEMP[0], IMM[0]\n"
785 " MFENCE RLOCAL\n"
786 " BGNLOOP\n"
787 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
788 " USEQ TEMP[2].x, TEMP[2], IMM[0]\n"
789 " IF TEMP[2]\n"
790 " BRK\n"
791 " ENDIF\n"
792 " ENDLOOP\n"
793 " STORE RLOCAL.x, TEMP[0], IMM[1]\n"
794 " MFENCE RLOCAL\n"
795 " ENDIF\n"
796 " UMUL TEMP[1].x, SV[0], SV[1]\n"
797 " UMUL TEMP[1].x, TEMP[1], IMM[2]\n"
798 " UADD TEMP[1].x, TEMP[1], TEMP[0]\n"
799 " LOAD TEMP[0].x, RLOCAL, TEMP[0]\n"
800 " STORE RES[0].x, TEMP[1], TEMP[0]\n"
801 " RET\n"
802 " ENDSUB\n";
803
804 printf("- %s\n", __func__);
805
806 init_prog(ctx, 256, 0, 0, src, NULL);
807 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
808 4096, 0, test_default_init);
809 init_compute_resources(ctx, (int []) { 0, -1 });
810 launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
811 check_tex(ctx, 0, test_local_expect, NULL);
812 destroy_compute_resources(ctx);
813 destroy_tex(ctx);
814 destroy_prog(ctx);
815 }
816
817 /* test_sample */
818 static void test_sample_init(void *p, int s, int x, int y)
819 {
820 *(float *)p = s ? 1 : x * y;
821 }
822
823 static void test_sample_expect(void *p, int s, int x, int y)
824 {
825 switch (x % 4) {
826 case 0:
827 *(float *)p = x / 4 * y;
828 break;
829 case 1:
830 case 2:
831 *(float *)p = 0;
832 break;
833 case 3:
834 *(float *)p = 1;
835 break;
836 }
837 }
838
839 static void test_sample(struct context *ctx)
840 {
841 const char *src = "COMP\n"
842 "DCL SVIEW[0], 2D, FLOAT\n"
843 "DCL RES[0], 2D, RAW, WR\n"
844 "DCL SAMP[0]\n"
845 "DCL SV[0], BLOCK_ID[0]\n"
846 "DCL TEMP[0], LOCAL\n"
847 "DCL TEMP[1], LOCAL\n"
848 "IMM UINT32 { 16, 1, 0, 0 }\n"
849 "IMM FLT32 { 128, 32, 0, 0 }\n"
850 "\n"
851 " BGNSUB\n"
852 " I2F TEMP[1], SV[0]\n"
853 " DIV TEMP[1], TEMP[1], IMM[1]\n"
854 " SAMPLE TEMP[1], TEMP[1], SVIEW[0], SAMP[0]\n"
855 " UMUL TEMP[0], SV[0], IMM[0]\n"
856 " STORE RES[0].xyzw, TEMP[0], TEMP[1]\n"
857 " RET\n"
858 " ENDSUB\n";
859
860 printf("- %s\n", __func__);
861
862 init_prog(ctx, 0, 0, 0, src, NULL);
863 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
864 128, 32, test_sample_init);
865 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
866 512, 32, test_sample_init);
867 init_compute_resources(ctx, (int []) { 1, -1 });
868 init_sampler_views(ctx, (int []) { 0, -1 });
869 init_sampler_states(ctx, 2);
870 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0, NULL);
871 check_tex(ctx, 1, test_sample_expect, NULL);
872 destroy_sampler_states(ctx);
873 destroy_sampler_views(ctx);
874 destroy_compute_resources(ctx);
875 destroy_tex(ctx);
876 destroy_prog(ctx);
877 }
878
879 /* test_many_kern */
880 static void test_many_kern_expect(void *p, int s, int x, int y)
881 {
882 *(uint32_t *)p = x;
883 }
884
885 static void test_many_kern(struct context *ctx)
886 {
887 const char *src = "COMP\n"
888 "DCL RES[0], BUFFER, RAW, WR\n"
889 "DCL TEMP[0], LOCAL\n"
890 "IMM UINT32 { 0, 1, 2, 3 }\n"
891 "IMM UINT32 { 4, 0, 0, 0 }\n"
892 "\n"
893 " BGNSUB\n"
894 " UMUL TEMP[0].x, IMM[0].xxxx, IMM[1].xxxx\n"
895 " STORE RES[0].x, TEMP[0], IMM[0].xxxx\n"
896 " RET\n"
897 " ENDSUB\n"
898 " BGNSUB\n"
899 " UMUL TEMP[0].x, IMM[0].yyyy, IMM[1].xxxx\n"
900 " STORE RES[0].x, TEMP[0], IMM[0].yyyy\n"
901 " RET\n"
902 " ENDSUB\n"
903 " BGNSUB\n"
904 " UMUL TEMP[0].x, IMM[0].zzzz, IMM[1].xxxx\n"
905 " STORE RES[0].x, TEMP[0], IMM[0].zzzz\n"
906 " RET\n"
907 " ENDSUB\n"
908 " BGNSUB\n"
909 " UMUL TEMP[0].x, IMM[0].wwww, IMM[1].xxxx\n"
910 " STORE RES[0].x, TEMP[0], IMM[0].wwww\n"
911 " RET\n"
912 " ENDSUB\n";
913
914 printf("- %s\n", __func__);
915
916 init_prog(ctx, 0, 0, 0, src, NULL);
917 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
918 16, 0, test_default_init);
919 init_compute_resources(ctx, (int []) { 0, -1 });
920 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
921 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 5, NULL);
922 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 10, NULL);
923 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 15, NULL);
924 check_tex(ctx, 0, test_many_kern_expect, NULL);
925 destroy_compute_resources(ctx);
926 destroy_tex(ctx);
927 destroy_prog(ctx);
928 }
929
930 /* test_constant */
931 static void test_constant_init(void *p, int s, int x, int y)
932 {
933 *(float *)p = s ? 0xdeadbeef : 8.0 - (float)x;
934 }
935
936 static void test_constant_expect(void *p, int s, int x, int y)
937 {
938 *(float *)p = 8.0 - (float)x;
939 }
940
941 static void test_constant(struct context *ctx)
942 {
943 const char *src = "COMP\n"
944 "DCL RES[0], BUFFER, RAW\n"
945 "DCL RES[1], BUFFER, RAW, WR\n"
946 "DCL SV[0], BLOCK_ID[0]\n"
947 "DCL TEMP[0], LOCAL\n"
948 "DCL TEMP[1], LOCAL\n"
949 "IMM UINT32 { 4, 0, 0, 0 }\n"
950 "\n"
951 " BGNSUB\n"
952 " UMUL TEMP[0].x, SV[0], IMM[0]\n"
953 " LOAD TEMP[1].x, RES[0], TEMP[0]\n"
954 " STORE RES[1].x, TEMP[0], TEMP[1]\n"
955 " RET\n"
956 " ENDSUB\n";
957
958 printf("- %s\n", __func__);
959
960 init_prog(ctx, 0, 0, 0, src, NULL);
961 init_tex(ctx, 0, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
962 256, 0, test_constant_init);
963 init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
964 256, 0, test_constant_init);
965 init_compute_resources(ctx, (int []) { 0, 1, -1 });
966 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
967 check_tex(ctx, 1, test_constant_expect, NULL);
968 destroy_compute_resources(ctx);
969 destroy_tex(ctx);
970 destroy_prog(ctx);
971 }
972
973 /* test_resource_indirect */
974 static void test_resource_indirect_init(void *p, int s, int x, int y)
975 {
976 *(uint32_t *)p = s == 0 ? 0xdeadbeef :
977 s == 1 ? x % 2 :
978 s == 2 ? 2 * x :
979 2 * x + 1;
980 }
981
982 static void test_resource_indirect_expect(void *p, int s, int x, int y)
983 {
984 *(uint32_t *)p = 2 * x + (x % 2 ? 1 : 0);
985 }
986
987 static void test_resource_indirect(struct context *ctx)
988 {
989 const char *src = "COMP\n"
990 "DCL RES[0], BUFFER, RAW, WR\n"
991 "DCL RES[1..3], BUFFER, RAW\n"
992 "DCL SV[0], BLOCK_ID[0]\n"
993 "DCL TEMP[0], LOCAL\n"
994 "DCL TEMP[1], LOCAL\n"
995 "IMM UINT32 { 4, 0, 0, 0 }\n"
996 "\n"
997 " BGNSUB\n"
998 " UMUL TEMP[0].x, SV[0], IMM[0]\n"
999 " LOAD TEMP[1].x, RES[1], TEMP[0]\n"
1000 " LOAD TEMP[1].x, RES[TEMP[1].x+2], TEMP[0]\n"
1001 " STORE RES[0].x, TEMP[0], TEMP[1]\n"
1002 " RET\n"
1003 " ENDSUB\n";
1004
1005 printf("- %s\n", __func__);
1006
1007 init_prog(ctx, 0, 0, 0, src, NULL);
1008 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
1009 256, 0, test_resource_indirect_init);
1010 init_tex(ctx, 1, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
1011 256, 0, test_resource_indirect_init);
1012 init_tex(ctx, 2, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
1013 256, 0, test_resource_indirect_init);
1014 init_tex(ctx, 3, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
1015 256, 0, test_resource_indirect_init);
1016 init_compute_resources(ctx, (int []) { 0, 1, 2, 3, -1 });
1017 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
1018 check_tex(ctx, 0, test_resource_indirect_expect, NULL);
1019 destroy_compute_resources(ctx);
1020 destroy_tex(ctx);
1021 destroy_prog(ctx);
1022 }
1023
1024 /* test_surface_ld */
1025 enum pipe_format surface_fmts[] = {
1026 PIPE_FORMAT_B8G8R8A8_UNORM,
1027 PIPE_FORMAT_B8G8R8X8_UNORM,
1028 PIPE_FORMAT_A8R8G8B8_UNORM,
1029 PIPE_FORMAT_X8R8G8B8_UNORM,
1030 PIPE_FORMAT_X8R8G8B8_UNORM,
1031 PIPE_FORMAT_L8_UNORM,
1032 PIPE_FORMAT_A8_UNORM,
1033 PIPE_FORMAT_I8_UNORM,
1034 PIPE_FORMAT_L8A8_UNORM,
1035 PIPE_FORMAT_R32_FLOAT,
1036 PIPE_FORMAT_R32G32_FLOAT,
1037 PIPE_FORMAT_R32G32B32A32_FLOAT,
1038 PIPE_FORMAT_R32_UNORM,
1039 PIPE_FORMAT_R32G32_UNORM,
1040 PIPE_FORMAT_R32G32B32A32_UNORM,
1041 PIPE_FORMAT_R32_SNORM,
1042 PIPE_FORMAT_R32G32_SNORM,
1043 PIPE_FORMAT_R32G32B32A32_SNORM,
1044 PIPE_FORMAT_R8_UINT,
1045 PIPE_FORMAT_R8G8_UINT,
1046 PIPE_FORMAT_R8G8B8A8_UINT,
1047 PIPE_FORMAT_R8_SINT,
1048 PIPE_FORMAT_R8G8_SINT,
1049 PIPE_FORMAT_R8G8B8A8_SINT,
1050 PIPE_FORMAT_R32_UINT,
1051 PIPE_FORMAT_R32G32_UINT,
1052 PIPE_FORMAT_R32G32B32A32_UINT,
1053 PIPE_FORMAT_R32_SINT,
1054 PIPE_FORMAT_R32G32_SINT,
1055 PIPE_FORMAT_R32G32B32A32_SINT
1056 };
1057
1058 static void test_surface_ld_init0f(void *p, int s, int x, int y)
1059 {
1060 float v[] = { 1.0, -.75, .50, -.25 };
1061 int i = 0;
1062
1063 util_format_write_4f(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
1064 }
1065
1066 static void test_surface_ld_init0i(void *p, int s, int x, int y)
1067 {
1068 int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
1069 int i = 0;
1070
1071 util_format_write_4i(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
1072 }
1073
1074 static void test_surface_ld_expectf(void *p, int s, int x, int y)
1075 {
1076 float v[4], w[4];
1077 int i = 0;
1078
1079 test_surface_ld_init0f(v, s, x / 4, y);
1080 util_format_read_4f(surface_fmts[i], w, 0, v, 0, 0, 0, 1, 1);
1081 *(float *)p = w[x % 4];
1082 }
1083
1084 static void test_surface_ld_expecti(void *p, int s, int x, int y)
1085 {
1086 int32_t v[4], w[4];
1087 int i = 0;
1088
1089 test_surface_ld_init0i(v, s, x / 4, y);
1090 util_format_read_4i(surface_fmts[i], w, 0, v, 0, 0, 0, 1, 1);
1091 *(uint32_t *)p = w[x % 4];
1092 }
1093
1094 static void test_surface_ld(struct context *ctx)
1095 {
1096 const char *src = "COMP\n"
1097 "DCL RES[0], 2D\n"
1098 "DCL RES[1], 2D, RAW, WR\n"
1099 "DCL SV[0], BLOCK_ID[0]\n"
1100 "DCL TEMP[0], LOCAL\n"
1101 "DCL TEMP[1], LOCAL\n"
1102 "IMM UINT32 { 16, 1, 0, 0 }\n"
1103 "\n"
1104 " BGNSUB\n"
1105 " LOAD TEMP[1], RES[0], SV[0]\n"
1106 " UMUL TEMP[0], SV[0], IMM[0]\n"
1107 " STORE RES[1].xyzw, TEMP[0], TEMP[1]\n"
1108 " RET\n"
1109 " ENDSUB\n";
1110 int i = 0;
1111
1112 printf("- %s\n", __func__);
1113
1114 init_prog(ctx, 0, 0, 0, src, NULL);
1115
1116 for (i = 0; i < Elements(surface_fmts); i++) {
1117 bool is_int = util_format_is_pure_integer(surface_fmts[i]);
1118
1119 printf(" - %s\n", util_format_name(surface_fmts[i]));
1120
1121 if (!ctx->screen->is_format_supported(ctx->screen,
1122 surface_fmts[i], PIPE_TEXTURE_2D, 1,
1123 PIPE_BIND_COMPUTE_RESOURCE)) {
1124 printf("(unsupported)\n");
1125 continue;
1126 }
1127
1128 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, surface_fmts[i],
1129 128, 32, (is_int ? test_surface_ld_init0i : test_surface_ld_init0f));
1130 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
1131 512, 32, test_default_init);
1132 init_compute_resources(ctx, (int []) { 0, 1, -1 });
1133 init_sampler_states(ctx, 2);
1134 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
1135 NULL);
1136 check_tex(ctx, 1, (is_int ? test_surface_ld_expecti : test_surface_ld_expectf), NULL);
1137 destroy_sampler_states(ctx);
1138 destroy_compute_resources(ctx);
1139 destroy_tex(ctx);
1140 }
1141
1142 destroy_prog(ctx);
1143 }
1144
1145 /* test_surface_st */
1146 static void test_surface_st_init0f(void *p, int s, int x, int y)
1147 {
1148 float v[] = { 1.0, -.75, 0.5, -.25 };
1149 *(float *)p = v[x % 4];
1150 }
1151
1152 static void test_surface_st_init0i(void *p, int s, int x, int y)
1153 {
1154 int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
1155 *(int32_t *)p = v[x % 4];
1156 }
1157
1158 static void test_surface_st_init1(void *p, int s, int x, int y)
1159 {
1160 int i = 0;
1161 memset(p, 1, util_format_get_blocksize(surface_fmts[i]));
1162 }
1163
1164 static void test_surface_st_expectf(void *p, int s, int x, int y)
1165 {
1166 float vf[4];
1167 int i = 0, j;
1168
1169 for (j = 0; j < 4; j++)
1170 test_surface_st_init0f(&vf[j], s, 4 * x + j, y);
1171 util_format_write_4f(surface_fmts[i], vf, 0, p, 0, 0, 0, 1, 1);
1172 }
1173
1174 static void test_surface_st_expects(void *p, int s, int x, int y)
1175 {
1176 int32_t v[4];
1177 int i = 0, j;
1178
1179 for (j = 0; j < 4; j++)
1180 test_surface_st_init0i(&v[j], s, 4 * x + j, y);
1181 util_format_write_4i(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
1182 }
1183
1184 static void test_surface_st_expectu(void *p, int s, int x, int y)
1185 {
1186 uint32_t v[4];
1187 int i = 0, j;
1188
1189 for (j = 0; j < 4; j++)
1190 test_surface_st_init0i(&v[j], s, 4 * x + j, y);
1191 util_format_write_4ui(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
1192 }
1193
1194 static bool test_surface_st_check(void *x, void *y, int sz)
1195 {
1196 int i = 0, j;
1197
1198 if (util_format_is_float(surface_fmts[i])) {
1199 return fabs(*(float *)x - *(float *)y) < 3.92156863e-3;
1200
1201 } else if ((sz % 4) == 0) {
1202 for (j = 0; j < sz / 4; j++)
1203 if (abs(((uint32_t *)x)[j] -
1204 ((uint32_t *)y)[j]) > 1)
1205 return false;
1206 return true;
1207 } else {
1208 return !memcmp(x, y, sz);
1209 }
1210 }
1211
1212 static void test_surface_st(struct context *ctx)
1213 {
1214 const char *src = "COMP\n"
1215 "DCL RES[0], 2D, RAW\n"
1216 "DCL RES[1], 2D, WR\n"
1217 "DCL SV[0], BLOCK_ID[0]\n"
1218 "DCL TEMP[0], LOCAL\n"
1219 "DCL TEMP[1], LOCAL\n"
1220 "IMM UINT32 { 16, 1, 0, 0 }\n"
1221 "\n"
1222 " BGNSUB\n"
1223 " UMUL TEMP[0], SV[0], IMM[0]\n"
1224 " LOAD TEMP[1], RES[0], TEMP[0]\n"
1225 " STORE RES[1], SV[0], TEMP[1]\n"
1226 " RET\n"
1227 " ENDSUB\n";
1228 int i = 0;
1229
1230 printf("- %s\n", __func__);
1231
1232 init_prog(ctx, 0, 0, 0, src, NULL);
1233
1234 for (i = 0; i < Elements(surface_fmts); i++) {
1235 bool is_signed = (util_format_description(surface_fmts[i])
1236 ->channel[0].type == UTIL_FORMAT_TYPE_SIGNED);
1237 bool is_int = util_format_is_pure_integer(surface_fmts[i]);
1238
1239 printf(" - %s\n", util_format_name(surface_fmts[i]));
1240
1241 if (!ctx->screen->is_format_supported(ctx->screen,
1242 surface_fmts[i], PIPE_TEXTURE_2D, 1,
1243 PIPE_BIND_COMPUTE_RESOURCE)) {
1244 printf("(unsupported)\n");
1245 continue;
1246 }
1247
1248 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
1249 512, 32, (is_int ? test_surface_st_init0i : test_surface_st_init0f));
1250 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, surface_fmts[i],
1251 128, 32, test_surface_st_init1);
1252 init_compute_resources(ctx, (int []) { 0, 1, -1 });
1253 init_sampler_states(ctx, 2);
1254 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
1255 NULL);
1256 check_tex(ctx, 1, (is_int && is_signed ? test_surface_st_expects :
1257 is_int && !is_signed ? test_surface_st_expectu :
1258 test_surface_st_expectf), test_surface_st_check);
1259 destroy_sampler_states(ctx);
1260 destroy_compute_resources(ctx);
1261 destroy_tex(ctx);
1262 }
1263
1264 destroy_prog(ctx);
1265 }
1266
1267 /* test_barrier */
1268 static void test_barrier_expect(void *p, int s, int x, int y)
1269 {
1270 *(uint32_t *)p = 31;
1271 }
1272
1273 static void test_barrier(struct context *ctx)
1274 {
1275 const char *src = "COMP\n"
1276 "DCL RES[0], BUFFER, RAW, WR\n"
1277 "DCL SV[0], BLOCK_ID[0]\n"
1278 "DCL SV[1], BLOCK_SIZE[0]\n"
1279 "DCL SV[2], THREAD_ID[0]\n"
1280 "DCL TEMP[0], LOCAL\n"
1281 "DCL TEMP[1], LOCAL\n"
1282 "DCL TEMP[2], LOCAL\n"
1283 "DCL TEMP[3], LOCAL\n"
1284 "IMM UINT32 { 1, 0, 0, 0 }\n"
1285 "IMM UINT32 { 4, 0, 0, 0 }\n"
1286 "IMM UINT32 { 32, 0, 0, 0 }\n"
1287 "\n"
1288 " BGNSUB\n"
1289 " UMUL TEMP[0].x, SV[2], IMM[1]\n"
1290 " MOV TEMP[1].x, IMM[0].wwww\n"
1291 " BGNLOOP\n"
1292 " BARRIER\n"
1293 " STORE RLOCAL.x, TEMP[0], TEMP[1]\n"
1294 " BARRIER\n"
1295 " MOV TEMP[2].x, IMM[0].wwww\n"
1296 " BGNLOOP\n"
1297 " UMUL TEMP[3].x, TEMP[2], IMM[1]\n"
1298 " LOAD TEMP[3].x, RLOCAL, TEMP[3]\n"
1299 " USNE TEMP[3].x, TEMP[3], TEMP[1]\n"
1300 " IF TEMP[3]\n"
1301 " END\n"
1302 " ENDIF\n"
1303 " UADD TEMP[2].x, TEMP[2], IMM[0]\n"
1304 " USEQ TEMP[3].x, TEMP[2], SV[1]\n"
1305 " IF TEMP[3]\n"
1306 " BRK\n"
1307 " ENDIF\n"
1308 " ENDLOOP\n"
1309 " UADD TEMP[1].x, TEMP[1], IMM[0]\n"
1310 " USEQ TEMP[2].x, TEMP[1], IMM[2]\n"
1311 " IF TEMP[2]\n"
1312 " BRK\n"
1313 " ENDIF\n"
1314 " ENDLOOP\n"
1315 " UMUL TEMP[1].x, SV[0], SV[1]\n"
1316 " UMUL TEMP[1].x, TEMP[1], IMM[1]\n"
1317 " UADD TEMP[1].x, TEMP[1], TEMP[0]\n"
1318 " LOAD TEMP[0].x, RLOCAL, TEMP[0]\n"
1319 " STORE RES[0].x, TEMP[1], TEMP[0]\n"
1320 " RET\n"
1321 " ENDSUB\n";
1322
1323 printf("- %s\n", __func__);
1324
1325 init_prog(ctx, 256, 0, 0, src, NULL);
1326 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
1327 4096, 0, test_default_init);
1328 init_compute_resources(ctx, (int []) { 0, -1 });
1329 launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
1330 check_tex(ctx, 0, test_barrier_expect, NULL);
1331 destroy_compute_resources(ctx);
1332 destroy_tex(ctx);
1333 destroy_prog(ctx);
1334 }
1335
1336 /* test_atom_ops */
1337 static void test_atom_ops_init(void *p, int s, int x, int y)
1338 {
1339 *(uint32_t *)p = 0xbad;
1340 }
1341
1342 static void test_atom_ops_expect(void *p, int s, int x, int y)
1343 {
1344 switch (x) {
1345 case 0:
1346 *(uint32_t *)p = 0xce6c8eef;
1347 break;
1348 case 1:
1349 *(uint32_t *)p = 0xdeadbeef;
1350 break;
1351 case 2:
1352 *(uint32_t *)p = 0x11111111;
1353 break;
1354 case 3:
1355 *(uint32_t *)p = 0x10011001;
1356 break;
1357 case 4:
1358 *(uint32_t *)p = 0xdfbdbfff;
1359 break;
1360 case 5:
1361 *(uint32_t *)p = 0x11111111;
1362 break;
1363 case 6:
1364 *(uint32_t *)p = 0x11111111;
1365 break;
1366 case 7:
1367 *(uint32_t *)p = 0xdeadbeef;
1368 break;
1369 case 8:
1370 *(uint32_t *)p = 0xdeadbeef;
1371 break;
1372 case 9:
1373 *(uint32_t *)p = 0x11111111;
1374 break;
1375 }
1376 }
1377
1378 static void test_atom_ops(struct context *ctx, bool global)
1379 {
1380 const char *src = "COMP\n"
1381 "#ifdef TARGET_GLOBAL\n"
1382 "#define target RES[0]\n"
1383 "#else\n"
1384 "#define target RLOCAL\n"
1385 "#endif\n"
1386 ""
1387 "DCL RES[0], BUFFER, RAW, WR\n"
1388 "#define threadid SV[0]\n"
1389 "DCL threadid, THREAD_ID[0]\n"
1390 ""
1391 "#define offset TEMP[0]\n"
1392 "DCL offset, LOCAL\n"
1393 "#define tmp TEMP[1]\n"
1394 "DCL tmp, LOCAL\n"
1395 ""
1396 "#define k0 IMM[0]\n"
1397 "IMM UINT32 { 0, 0, 0, 0 }\n"
1398 "#define k1 IMM[1]\n"
1399 "IMM UINT32 { 1, 0, 0, 0 }\n"
1400 "#define k2 IMM[2]\n"
1401 "IMM UINT32 { 2, 0, 0, 0 }\n"
1402 "#define k3 IMM[3]\n"
1403 "IMM UINT32 { 3, 0, 0, 0 }\n"
1404 "#define k4 IMM[4]\n"
1405 "IMM UINT32 { 4, 0, 0, 0 }\n"
1406 "#define k5 IMM[5]\n"
1407 "IMM UINT32 { 5, 0, 0, 0 }\n"
1408 "#define k6 IMM[6]\n"
1409 "IMM UINT32 { 6, 0, 0, 0 }\n"
1410 "#define k7 IMM[7]\n"
1411 "IMM UINT32 { 7, 0, 0, 0 }\n"
1412 "#define k8 IMM[8]\n"
1413 "IMM UINT32 { 8, 0, 0, 0 }\n"
1414 "#define k9 IMM[9]\n"
1415 "IMM UINT32 { 9, 0, 0, 0 }\n"
1416 "#define korig IMM[10].xxxx\n"
1417 "#define karg IMM[10].yyyy\n"
1418 "IMM UINT32 { 3735928559, 286331153, 0, 0 }\n"
1419 "\n"
1420 " BGNSUB\n"
1421 " UMUL offset.x, threadid, k4\n"
1422 " STORE target.x, offset, korig\n"
1423 " USEQ tmp.x, threadid, k0\n"
1424 " IF tmp\n"
1425 " ATOMUADD tmp.x, target, offset, karg\n"
1426 " ATOMUADD tmp.x, target, offset, tmp\n"
1427 " ENDIF\n"
1428 " USEQ tmp.x, threadid, k1\n"
1429 " IF tmp\n"
1430 " ATOMXCHG tmp.x, target, offset, karg\n"
1431 " ATOMXCHG tmp.x, target, offset, tmp\n"
1432 " ENDIF\n"
1433 " USEQ tmp.x, threadid, k2\n"
1434 " IF tmp\n"
1435 " ATOMCAS tmp.x, target, offset, korig, karg\n"
1436 " ATOMCAS tmp.x, target, offset, tmp, k0\n"
1437 " ENDIF\n"
1438 " USEQ tmp.x, threadid, k3\n"
1439 " IF tmp\n"
1440 " ATOMAND tmp.x, target, offset, karg\n"
1441 " ATOMAND tmp.x, target, offset, tmp\n"
1442 " ENDIF\n"
1443 " USEQ tmp.x, threadid, k4\n"
1444 " IF tmp\n"
1445 " ATOMOR tmp.x, target, offset, karg\n"
1446 " ATOMOR tmp.x, target, offset, tmp\n"
1447 " ENDIF\n"
1448 " USEQ tmp.x, threadid, k5\n"
1449 " IF tmp\n"
1450 " ATOMXOR tmp.x, target, offset, karg\n"
1451 " ATOMXOR tmp.x, target, offset, tmp\n"
1452 " ENDIF\n"
1453 " USEQ tmp.x, threadid, k6\n"
1454 " IF tmp\n"
1455 " ATOMUMIN tmp.x, target, offset, karg\n"
1456 " ATOMUMIN tmp.x, target, offset, tmp\n"
1457 " ENDIF\n"
1458 " USEQ tmp.x, threadid, k7\n"
1459 " IF tmp\n"
1460 " ATOMUMAX tmp.x, target, offset, karg\n"
1461 " ATOMUMAX tmp.x, target, offset, tmp\n"
1462 " ENDIF\n"
1463 " USEQ tmp.x, threadid, k8\n"
1464 " IF tmp\n"
1465 " ATOMIMIN tmp.x, target, offset, karg\n"
1466 " ATOMIMIN tmp.x, target, offset, tmp\n"
1467 " ENDIF\n"
1468 " USEQ tmp.x, threadid, k9\n"
1469 " IF tmp\n"
1470 " ATOMIMAX tmp.x, target, offset, karg\n"
1471 " ATOMIMAX tmp.x, target, offset, tmp\n"
1472 " ENDIF\n"
1473 "#ifdef TARGET_LOCAL\n"
1474 " LOAD tmp.x, RLOCAL, offset\n"
1475 " STORE RES[0].x, offset, tmp\n"
1476 "#endif\n"
1477 " RET\n"
1478 " ENDSUB\n";
1479
1480 printf("- %s (%s)\n", __func__, global ? "global" : "local");
1481
1482 init_prog(ctx, 40, 0, 0, src,
1483 (global ? "-DTARGET_GLOBAL" : "-DTARGET_LOCAL"));
1484 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
1485 40, 0, test_atom_ops_init);
1486 init_compute_resources(ctx, (int []) { 0, -1 });
1487 launch_grid(ctx, (uint []){10, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
1488 check_tex(ctx, 0, test_atom_ops_expect, NULL);
1489 destroy_compute_resources(ctx);
1490 destroy_tex(ctx);
1491 destroy_prog(ctx);
1492 }
1493
1494 /* test_atom_race */
1495 static void test_atom_race_expect(void *p, int s, int x, int y)
1496 {
1497 *(uint32_t *)p = x & 0x20 ? 0x11111111 : 0xffffffff;
1498 }
1499
1500 static void test_atom_race(struct context *ctx, bool global)
1501 {
1502 const char *src = "COMP\n"
1503 "#ifdef TARGET_GLOBAL\n"
1504 "#define target RES[0]\n"
1505 "#else\n"
1506 "#define target RLOCAL\n"
1507 "#endif\n"
1508 ""
1509 "DCL RES[0], BUFFER, RAW, WR\n"
1510 ""
1511 "#define blockid SV[0]\n"
1512 "DCL blockid, BLOCK_ID[0]\n"
1513 "#define blocksz SV[1]\n"
1514 "DCL blocksz, BLOCK_SIZE[0]\n"
1515 "#define threadid SV[2]\n"
1516 "DCL threadid, THREAD_ID[0]\n"
1517 ""
1518 "#define offset TEMP[0]\n"
1519 "DCL offset, LOCAL\n"
1520 "#define arg TEMP[1]\n"
1521 "DCL arg, LOCAL\n"
1522 "#define count TEMP[2]\n"
1523 "DCL count, LOCAL\n"
1524 "#define vlocal TEMP[3]\n"
1525 "DCL vlocal, LOCAL\n"
1526 "#define vshared TEMP[4]\n"
1527 "DCL vshared, LOCAL\n"
1528 "#define last TEMP[5]\n"
1529 "DCL last, LOCAL\n"
1530 "#define tmp0 TEMP[6]\n"
1531 "DCL tmp0, LOCAL\n"
1532 "#define tmp1 TEMP[7]\n"
1533 "DCL tmp1, LOCAL\n"
1534 ""
1535 "#define k0 IMM[0]\n"
1536 "IMM UINT32 { 0, 0, 0, 0 }\n"
1537 "#define k1 IMM[1]\n"
1538 "IMM UINT32 { 1, 0, 0, 0 }\n"
1539 "#define k4 IMM[2]\n"
1540 "IMM UINT32 { 4, 0, 0, 0 }\n"
1541 "#define k32 IMM[3]\n"
1542 "IMM UINT32 { 32, 0, 0, 0 }\n"
1543 "#define k128 IMM[4]\n"
1544 "IMM UINT32 { 128, 0, 0, 0 }\n"
1545 "#define kdeadcafe IMM[5]\n"
1546 "IMM UINT32 { 3735931646, 0, 0, 0 }\n"
1547 "#define kallowed_set IMM[6]\n"
1548 "IMM UINT32 { 559035650, 0, 0, 0 }\n"
1549 "#define k11111111 IMM[7]\n"
1550 "IMM UINT32 { 286331153, 0, 0, 0 }\n"
1551 "\n"
1552 " BGNSUB\n"
1553 " MOV offset.x, threadid\n"
1554 "#ifdef TARGET_GLOBAL\n"
1555 " UMUL tmp0.x, blockid, blocksz\n"
1556 " UADD offset.x, offset, tmp0\n"
1557 "#endif\n"
1558 " UMUL offset.x, offset, k4\n"
1559 " USLT tmp0.x, threadid, k32\n"
1560 " STORE target.x, offset, k0\n"
1561 " BARRIER\n"
1562 " IF tmp0\n"
1563 " MOV vlocal.x, k0\n"
1564 " MOV arg.x, kdeadcafe\n"
1565 " BGNLOOP\n"
1566 " INEG arg.x, arg\n"
1567 " ATOMUADD vshared.x, target, offset, arg\n"
1568 " SFENCE target\n"
1569 " USNE tmp0.x, vshared, vlocal\n"
1570 " IF tmp0\n"
1571 " BRK\n"
1572 " ENDIF\n"
1573 " UADD vlocal.x, vlocal, arg\n"
1574 " ENDLOOP\n"
1575 " UADD vlocal.x, vshared, arg\n"
1576 " LOAD vshared.x, target, offset\n"
1577 " USEQ tmp0.x, vshared, vlocal\n"
1578 " STORE target.x, offset, tmp0\n"
1579 " ELSE\n"
1580 " UADD offset.x, offset, -k128\n"
1581 " MOV count.x, k0\n"
1582 " MOV last.x, k0\n"
1583 " BGNLOOP\n"
1584 " LOAD vshared.x, target, offset\n"
1585 " USEQ tmp0.x, vshared, kallowed_set.xxxx\n"
1586 " USEQ tmp1.x, vshared, kallowed_set.yyyy\n"
1587 " OR tmp0.x, tmp0, tmp1\n"
1588 " IF tmp0\n"
1589 " USEQ tmp0.x, vshared, last\n"
1590 " IF tmp0\n"
1591 " CONT\n"
1592 " ENDIF\n"
1593 " MOV last.x, vshared\n"
1594 " ELSE\n"
1595 " END\n"
1596 " ENDIF\n"
1597 " UADD count.x, count, k1\n"
1598 " USEQ tmp0.x, count, k128\n"
1599 " IF tmp0\n"
1600 " BRK\n"
1601 " ENDIF\n"
1602 " ENDLOOP\n"
1603 " ATOMXCHG tmp0.x, target, offset, k11111111\n"
1604 " UADD offset.x, offset, k128\n"
1605 " ATOMXCHG tmp0.x, target, offset, k11111111\n"
1606 " SFENCE target\n"
1607 " ENDIF\n"
1608 "#ifdef TARGET_LOCAL\n"
1609 " LOAD tmp0.x, RLOCAL, offset\n"
1610 " UMUL tmp1.x, blockid, blocksz\n"
1611 " UMUL tmp1.x, tmp1, k4\n"
1612 " UADD offset.x, offset, tmp1\n"
1613 " STORE RES[0].x, offset, tmp0\n"
1614 "#endif\n"
1615 " RET\n"
1616 " ENDSUB\n";
1617
1618 printf("- %s (%s)\n", __func__, global ? "global" : "local");
1619
1620 init_prog(ctx, 256, 0, 0, src,
1621 (global ? "-DTARGET_GLOBAL" : "-DTARGET_LOCAL"));
1622 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
1623 4096, 0, test_default_init);
1624 init_compute_resources(ctx, (int []) { 0, -1 });
1625 launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
1626 check_tex(ctx, 0, test_atom_race_expect, NULL);
1627 destroy_compute_resources(ctx);
1628 destroy_tex(ctx);
1629 destroy_prog(ctx);
1630 }
1631
1632 int main(int argc, char *argv[])
1633 {
1634 struct context *ctx = CALLOC_STRUCT(context);
1635
1636 unsigned tests = (argc > 1) ? strtoul(argv[1], NULL, 0) : ~0;
1637
1638 init_ctx(ctx);
1639
1640 if (tests & (1 << 0))
1641 test_system_values(ctx);
1642 if (tests & (1 << 1))
1643 test_resource_access(ctx);
1644 if (tests & (1 << 2))
1645 test_function_calls(ctx);
1646 if (tests & (1 << 3))
1647 test_input_global(ctx);
1648 if (tests & (1 << 4))
1649 test_private(ctx);
1650 if (tests & (1 << 5))
1651 test_local(ctx);
1652 if (tests & (1 << 6))
1653 test_sample(ctx);
1654 if (tests & (1 << 7))
1655 test_many_kern(ctx);
1656 if (tests & (1 << 8))
1657 test_constant(ctx);
1658 if (tests & (1 << 9))
1659 test_resource_indirect(ctx);
1660 if (tests & (1 << 10))
1661 test_surface_ld(ctx);
1662 if (tests & (1 << 11))
1663 test_surface_st(ctx);
1664 if (tests & (1 << 12))
1665 test_barrier(ctx);
1666 if (tests & (1 << 13))
1667 test_atom_ops(ctx, true);
1668 if (tests & (1 << 14))
1669 test_atom_race(ctx, true);
1670 if (tests & (1 << 15))
1671 test_atom_ops(ctx, false);
1672 if (tests & (1 << 16))
1673 test_atom_race(ctx, false);
1674
1675 destroy_ctx(ctx);
1676
1677 return 0;
1678 }