2 * Copyright (C) 2011 Francisco Jerez.
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:
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.
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.
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"
43 #define MAX_RESOURCES 4
46 struct pipe_loader_device
*dev
;
47 struct pipe_screen
*screen
;
48 struct pipe_context
*pipe
;
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
];
57 #define DUMP_COMPUTE_PARAM(p, c) do { \
61 __n = ctx->screen->get_compute_param(ctx->screen, c, __v); \
62 printf("%s: {", #c); \
64 for (__i = 0; __i < __n / sizeof(*__v); ++__i) \
65 printf(" %"PRIu64, __v[__i]); \
70 static void init_ctx(struct context
*ctx
)
74 ret
= pipe_loader_probe(&ctx
->dev
, 1);
77 ctx
->screen
= pipe_loader_create_screen(ctx
->dev
);
80 ctx
->pipe
= ctx
->screen
->context_create(ctx
->screen
, NULL
, 0);
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
);
88 static void destroy_ctx(struct context
*ctx
)
90 ctx
->pipe
->destroy(ctx
->pipe
);
91 ctx
->screen
->destroy(ctx
->screen
);
92 pipe_loader_release(&ctx
->dev
, 1);
97 preprocess_prog(struct context
*ctx
, const char *src
, const char *defs
)
100 "#define RGLOBAL RES[32767]\n"
101 "#define RLOCAL RES[32766]\n"
102 "#define RPRIVATE RES[32765]\n"
103 "#define RINPUT RES[32764]\n";
105 char tmp
[] = "/tmp/test-compute.tgsi-XXXXXX";
111 /* Open a temporary file */
114 snprintf(cmd
, sizeof(cmd
), "cpp -P -nostdinc -undef %s > %s",
115 defs
? defs
: "", tmp
);
119 fwrite(header
, strlen(header
), 1, p
);
120 fwrite(src
, strlen(src
), 1, p
);
125 ret
= fstat(fd
, &st
);
128 buf
= malloc(st
.st_size
+ 1);
129 ret
= read(fd
, buf
, st
.st_size
);
130 assert(ret
== st
.st_size
);
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
)
144 struct pipe_context
*pipe
= ctx
->pipe
;
145 struct tgsi_token prog
[1024];
146 struct pipe_compute_state cs
= {
148 .req_local_mem
= local_sz
,
149 .req_private_mem
= private_sz
,
150 .req_input_mem
= input_sz
152 char *psrc
= preprocess_prog(ctx
, src
, defs
);
155 ret
= tgsi_text_translate(psrc
, prog
, Elements(prog
));
159 ctx
->hwcs
= pipe
->create_compute_state(pipe
, &cs
);
162 pipe
->bind_compute_state(pipe
, ctx
->hwcs
);
165 static void destroy_prog(struct context
*ctx
)
167 struct pipe_context
*pipe
= ctx
->pipe
;
169 pipe
->delete_compute_state(pipe
, ctx
->hwcs
);
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))
178 struct pipe_context
*pipe
= ctx
->pipe
;
179 struct pipe_resource
**tex
= &ctx
->tex
[slot
];
180 struct pipe_resource ttex
= {
187 .bind
= (PIPE_BIND_SAMPLER_VIEW
|
188 PIPE_BIND_COMPUTE_RESOURCE
|
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
;
201 *tex
= ctx
->screen
->resource_create(ctx
->screen
, &ttex
);
204 map
= pipe
->transfer_map(pipe
, *tex
, 0, PIPE_TRANSFER_WRITE
,
205 &(struct pipe_box
) { .width
= w
,
207 .depth
= 1 }, &xfer
);
211 for (y
= 0; y
< ny
; ++y
) {
212 for (x
= 0; x
< nx
; ++x
) {
213 init(map
+ y
* dy
+ x
* dx
, slot
, x
, y
);
217 pipe
->transfer_unmap(pipe
, xfer
);
219 ctx
->tex_rw
[slot
] = rw
;
222 static bool default_check(void *x
, void *y
, int sz
) {
223 return !memcmp(x
, y
, sz
);
226 static void check_tex(struct context
*ctx
, int slot
,
227 void (*expect
)(void *, int, int, int),
228 bool (*check
)(void *, void *, int))
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
;
244 check
= default_check
;
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
);
253 for (y
= 0; y
< ny
; ++y
) {
254 for (x
= 0; x
< nx
; ++x
) {
256 uint32_t *res
= (uint32_t *)(map
+ y
* dy
+ x
* dx
);
258 expect(exp
, slot
, x
, y
);
259 if (check(res
, exp
, dx
) || (++err
) > 20)
263 uint32_t u
= 0, v
= 0;
265 for (i
= 0; i
< dx
; i
++) {
266 u
|= ((uint8_t *)exp
)[i
] << (8 * i
);
267 v
|= ((uint8_t *)res
)[i
] << (8 * i
);
269 printf("(%d, %d): got 0x%x, expected 0x%x\n",
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
]);
282 pipe
->transfer_unmap(pipe
, xfer
);
285 printf("(%d, %d): \x1b[31mFAIL\x1b[0m (%d)\n", x
, y
, err
);
287 printf("(%d, %d): \x1b[32mOK\x1b[0m\n", x
, y
);
290 static void destroy_tex(struct context
*ctx
)
294 for (i
= 0; i
< MAX_RESOURCES
; ++i
) {
296 pipe_resource_reference(&ctx
->tex
[i
], NULL
);
300 static void init_sampler_views(struct context
*ctx
, const int *slots
)
302 struct pipe_context
*pipe
= ctx
->pipe
;
303 struct pipe_sampler_view tview
;
306 for (i
= 0; *slots
>= 0; ++i
, ++slots
) {
307 u_sampler_view_default_template(&tview
, ctx
->tex
[*slots
],
308 ctx
->tex
[*slots
]->format
);
310 ctx
->view
[i
] = pipe
->create_sampler_view(pipe
, ctx
->tex
[*slots
],
312 assert(ctx
->view
[i
]);
315 pipe
->set_sampler_views(pipe
, PIPE_SHADER_COMPUTE
, 0, i
, ctx
->view
);
318 static void destroy_sampler_views(struct context
*ctx
)
320 struct pipe_context
*pipe
= ctx
->pipe
;
323 pipe
->set_sampler_views(pipe
, PIPE_SHADER_COMPUTE
, 0, MAX_RESOURCES
, NULL
);
325 for (i
= 0; i
< MAX_RESOURCES
; ++i
) {
327 pipe
->sampler_view_destroy(pipe
, ctx
->view
[i
]);
333 static void init_compute_resources(struct context
*ctx
, const int *slots
)
335 struct pipe_context
*pipe
= ctx
->pipe
;
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
]
344 if (ctx
->tex
[*slots
]->target
== PIPE_BUFFER
)
345 tsurf
.u
.buf
.last_element
= ctx
->tex
[*slots
]->width0
- 1;
347 ctx
->surf
[i
] = pipe
->create_surface(pipe
, ctx
->tex
[*slots
],
349 assert(ctx
->surf
[i
]);
352 pipe
->set_compute_resources(pipe
, 0, i
, ctx
->surf
);
355 static void destroy_compute_resources(struct context
*ctx
)
357 struct pipe_context
*pipe
= ctx
->pipe
;
360 pipe
->set_compute_resources(pipe
, 0, MAX_RESOURCES
, NULL
);
362 for (i
= 0; i
< MAX_RESOURCES
; ++i
) {
364 pipe
->surface_destroy(pipe
, ctx
->surf
[i
]);
370 static void init_sampler_states(struct context
*ctx
, int n
)
372 struct pipe_context
*pipe
= ctx
->pipe
;
373 struct pipe_sampler_state smp
= {
374 .normalized_coords
= 1,
378 for (i
= 0; i
< n
; ++i
) {
379 ctx
->hwsmp
[i
] = pipe
->create_sampler_state(pipe
, &smp
);
380 assert(ctx
->hwsmp
[i
]);
383 pipe
->bind_sampler_states(pipe
, PIPE_SHADER_COMPUTE
, 0, i
, ctx
->hwsmp
);
386 static void destroy_sampler_states(struct context
*ctx
)
388 struct pipe_context
*pipe
= ctx
->pipe
;
391 pipe
->bind_sampler_states(pipe
, PIPE_SHADER_COMPUTE
,
392 0, MAX_RESOURCES
, NULL
);
394 for (i
= 0; i
< MAX_RESOURCES
; ++i
) {
396 pipe
->delete_sampler_state(pipe
, ctx
->hwsmp
[i
]);
397 ctx
->hwsmp
[i
] = NULL
;
402 static void init_globals(struct context
*ctx
, const int *slots
,
405 struct pipe_context
*pipe
= ctx
->pipe
;
406 struct pipe_resource
*res
[MAX_RESOURCES
];
409 for (i
= 0; *slots
>= 0; ++i
, ++slots
)
410 res
[i
] = ctx
->tex
[*slots
];
412 pipe
->set_global_binding(pipe
, 0, i
, res
, handles
);
415 static void destroy_globals(struct context
*ctx
)
417 struct pipe_context
*pipe
= ctx
->pipe
;
419 pipe
->set_global_binding(pipe
, 0, MAX_RESOURCES
, NULL
, NULL
);
422 static void launch_grid(struct context
*ctx
, const uint
*block_layout
,
423 const uint
*grid_layout
, uint32_t pc
,
426 struct pipe_context
*pipe
= ctx
->pipe
;
428 pipe
->launch_grid(pipe
, block_layout
, grid_layout
, pc
, input
);
431 static void test_default_init(void *p
, int s
, int x
, int y
)
433 *(uint32_t *)p
= 0xdeadbeef;
436 /* test_system_values */
437 static void test_system_values_expect(void *p
, int s
, int x
, int y
)
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};
446 *(uint32_t *)p
= tid
[c
] / bsz
[c
];
449 *(uint32_t *)p
= bsz
[c
];
452 *(uint32_t *)p
= gsz
[c
];
455 *(uint32_t *)p
= tid
[c
] % bsz
[c
];
460 static void test_system_values(struct context
*ctx
)
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"
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"
494 printf("- %s\n", __func__
);
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
);
507 /* test_resource_access */
508 static void test_resource_access_init0(void *p
, int s
, int x
, int y
)
510 *(float *)p
= 8.0 - (float)x
;
513 static void test_resource_access_expect(void *p
, int s
, int x
, int y
)
515 *(float *)p
= 8.0 - (float)((x
+ 4 * y
) & 0x3f);
518 static void test_resource_access(struct context
*ctx
)
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"
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"
539 printf("- %s\n", __func__
);
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
);
554 /* test_function_calls */
555 static void test_function_calls_init(void *p
, int s
, int x
, int y
)
557 *(uint32_t *)p
= 15 * y
+ x
;
560 static void test_function_calls_expect(void *p
, int s
, int x
, int y
)
562 *(uint32_t *)p
= (15 * y
+ x
) < 4 ? 2 : 1 ;
565 static void test_function_calls(struct context
*ctx
)
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"
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"
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"
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"
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"
603 "21: STORE RES[0].x, TEMP[2], TEMP[1].xxxx\n"
607 printf("- %s\n", __func__
);
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
);
620 /* test_input_global */
621 static void test_input_global_expect(void *p
, int s
, int x
, int y
)
623 *(uint32_t *)p
= 0xdeadbeef - (x
== 0 ? 0x10001 + 2 * s
: 0);
626 static void test_input_global(struct context
*ctx
)
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"
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"
642 uint32_t input
[8] = { 0x10001, 0x10002, 0x10003, 0x10004,
643 0x10005, 0x10006, 0x10007, 0x10008 };
645 printf("- %s\n", __func__
);
647 init_prog(ctx
, 0, 0, 32, src
, NULL
);
648 init_tex(ctx
, 0, PIPE_BUFFER
, true, PIPE_FORMAT_R32_FLOAT
, 32, 0,
650 init_tex(ctx
, 1, PIPE_BUFFER
, true, PIPE_FORMAT_R32_FLOAT
, 32, 0,
652 init_tex(ctx
, 2, PIPE_BUFFER
, true, PIPE_FORMAT_R32_FLOAT
, 32, 0,
654 init_tex(ctx
, 3, PIPE_BUFFER
, true, PIPE_FORMAT_R32_FLOAT
, 32, 0,
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
);
670 static void test_private_expect(void *p
, int s
, int x
, int y
)
672 *(uint32_t *)p
= (x
/ 32) + x
% 32;
675 static void test_private(struct context
*ctx
)
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"
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"
693 " USEQ TEMP[2].x, TEMP[1], IMM[0]\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"
702 " MOV TEMP[1].x, IMM[0].wwww\n"
703 " UMUL TEMP[0].x, TEMP[0], IMM[0]\n"
705 " USEQ TEMP[2].x, TEMP[1], IMM[0]\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"
717 printf("- %s\n", __func__
);
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
);
731 static void test_local_expect(void *p
, int s
, int x
, int y
)
733 *(uint32_t *)p
= x
& 0x20 ? 2 : 1;
736 static void test_local(struct context
*ctx
)
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"
753 " UMUL TEMP[0].x, SV[2], IMM[2]\n"
754 " STORE RLOCAL.x, TEMP[0], IMM[0].wwww\n"
756 " USLT TEMP[1].x, SV[2], IMM[3]\n"
758 " UADD TEMP[1].x, TEMP[0], IMM[4]\n"
760 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
761 " USEQ TEMP[2].x, TEMP[2], IMM[0]\n"
766 " STORE RLOCAL.x, TEMP[0], IMM[0]\n"
769 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
770 " USEQ TEMP[2].x, TEMP[2], IMM[1]\n"
776 " UADD TEMP[1].x, TEMP[0], -IMM[4]\n"
778 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
779 " USEQ TEMP[2].x, TEMP[2], IMM[0].wwww\n"
784 " STORE RLOCAL.x, TEMP[0], IMM[0]\n"
787 " LOAD TEMP[2].x, RLOCAL, TEMP[1]\n"
788 " USEQ TEMP[2].x, TEMP[2], IMM[0]\n"
793 " STORE RLOCAL.x, TEMP[0], IMM[1]\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"
804 printf("- %s\n", __func__
);
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
);
818 static void test_sample_init(void *p
, int s
, int x
, int y
)
820 *(float *)p
= s
? 1 : x
* y
;
823 static void test_sample_expect(void *p
, int s
, int x
, int y
)
827 *(float *)p
= x
/ 4 * y
;
839 static void test_sample(struct context
*ctx
)
841 const char *src
= "COMP\n"
842 "DCL SVIEW[0], 2D, FLOAT\n"
843 "DCL RES[0], 2D, RAW, WR\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"
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"
860 printf("- %s\n", __func__
);
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
);
880 static void test_many_kern_expect(void *p
, int s
, int x
, int y
)
885 static void test_many_kern(struct context
*ctx
)
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"
894 " UMUL TEMP[0].x, IMM[0].xxxx, IMM[1].xxxx\n"
895 " STORE RES[0].x, TEMP[0], IMM[0].xxxx\n"
899 " UMUL TEMP[0].x, IMM[0].yyyy, IMM[1].xxxx\n"
900 " STORE RES[0].x, TEMP[0], IMM[0].yyyy\n"
904 " UMUL TEMP[0].x, IMM[0].zzzz, IMM[1].xxxx\n"
905 " STORE RES[0].x, TEMP[0], IMM[0].zzzz\n"
909 " UMUL TEMP[0].x, IMM[0].wwww, IMM[1].xxxx\n"
910 " STORE RES[0].x, TEMP[0], IMM[0].wwww\n"
914 printf("- %s\n", __func__
);
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
);
931 static void test_constant_init(void *p
, int s
, int x
, int y
)
933 *(float *)p
= s
? 0xdeadbeef : 8.0 - (float)x
;
936 static void test_constant_expect(void *p
, int s
, int x
, int y
)
938 *(float *)p
= 8.0 - (float)x
;
941 static void test_constant(struct context
*ctx
)
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"
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"
958 printf("- %s\n", __func__
);
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
);
973 /* test_resource_indirect */
974 static void test_resource_indirect_init(void *p
, int s
, int x
, int y
)
976 *(uint32_t *)p
= s
== 0 ? 0xdeadbeef :
982 static void test_resource_indirect_expect(void *p
, int s
, int x
, int y
)
984 *(uint32_t *)p
= 2 * x
+ (x
% 2 ? 1 : 0);
987 static void test_resource_indirect(struct context
*ctx
)
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"
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"
1005 printf("- %s\n", __func__
);
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
);
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
1058 static void test_surface_ld_init0f(void *p
, int s
, int x
, int y
)
1060 float v
[] = { 1.0, -.75, .50, -.25 };
1063 util_format_write_4f(surface_fmts
[i
], v
, 0, p
, 0, 0, 0, 1, 1);
1066 static void test_surface_ld_init0i(void *p
, int s
, int x
, int y
)
1068 int v
[] = { 0xffffffff, 0xffff, 0xff, 0xf };
1071 util_format_write_4i(surface_fmts
[i
], v
, 0, p
, 0, 0, 0, 1, 1);
1074 static void test_surface_ld_expectf(void *p
, int s
, int x
, int y
)
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];
1084 static void test_surface_ld_expecti(void *p
, int s
, int x
, int y
)
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];
1094 static void test_surface_ld(struct context
*ctx
)
1096 const char *src
= "COMP\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"
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"
1112 printf("- %s\n", __func__
);
1114 init_prog(ctx
, 0, 0, 0, src
, NULL
);
1116 for (i
= 0; i
< Elements(surface_fmts
); i
++) {
1117 bool is_int
= util_format_is_pure_integer(surface_fmts
[i
]);
1119 printf(" - %s\n", util_format_name(surface_fmts
[i
]));
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");
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,
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
);
1145 /* test_surface_st */
1146 static void test_surface_st_init0f(void *p
, int s
, int x
, int y
)
1148 float v
[] = { 1.0, -.75, 0.5, -.25 };
1149 *(float *)p
= v
[x
% 4];
1152 static void test_surface_st_init0i(void *p
, int s
, int x
, int y
)
1154 int v
[] = { 0xffffffff, 0xffff, 0xff, 0xf };
1155 *(int32_t *)p
= v
[x
% 4];
1158 static void test_surface_st_init1(void *p
, int s
, int x
, int y
)
1161 memset(p
, 1, util_format_get_blocksize(surface_fmts
[i
]));
1164 static void test_surface_st_expectf(void *p
, int s
, int x
, int y
)
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);
1174 static void test_surface_st_expects(void *p
, int s
, int x
, int y
)
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);
1184 static void test_surface_st_expectu(void *p
, int s
, int x
, int y
)
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);
1194 static bool test_surface_st_check(void *x
, void *y
, int sz
)
1198 if (util_format_is_float(surface_fmts
[i
])) {
1199 return fabs(*(float *)x
- *(float *)y
) < 3.92156863e-3;
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)
1208 return !memcmp(x
, y
, sz
);
1212 static void test_surface_st(struct context
*ctx
)
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"
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"
1230 printf("- %s\n", __func__
);
1232 init_prog(ctx
, 0, 0, 0, src
, NULL
);
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
]);
1239 printf(" - %s\n", util_format_name(surface_fmts
[i
]));
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");
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,
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
);
1268 static void test_barrier_expect(void *p
, int s
, int x
, int y
)
1270 *(uint32_t *)p
= 31;
1273 static void test_barrier(struct context
*ctx
)
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"
1289 " UMUL TEMP[0].x, SV[2], IMM[1]\n"
1290 " MOV TEMP[1].x, IMM[0].wwww\n"
1293 " STORE RLOCAL.x, TEMP[0], TEMP[1]\n"
1295 " MOV TEMP[2].x, IMM[0].wwww\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"
1303 " UADD TEMP[2].x, TEMP[2], IMM[0]\n"
1304 " USEQ TEMP[3].x, TEMP[2], SV[1]\n"
1309 " UADD TEMP[1].x, TEMP[1], IMM[0]\n"
1310 " USEQ TEMP[2].x, TEMP[1], IMM[2]\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"
1323 printf("- %s\n", __func__
);
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
);
1337 static void test_atom_ops_init(void *p
, int s
, int x
, int y
)
1339 *(uint32_t *)p
= 0xbad;
1342 static void test_atom_ops_expect(void *p
, int s
, int x
, int y
)
1346 *(uint32_t *)p
= 0xce6c8eef;
1349 *(uint32_t *)p
= 0xdeadbeef;
1352 *(uint32_t *)p
= 0x11111111;
1355 *(uint32_t *)p
= 0x10011001;
1358 *(uint32_t *)p
= 0xdfbdbfff;
1361 *(uint32_t *)p
= 0x11111111;
1364 *(uint32_t *)p
= 0x11111111;
1367 *(uint32_t *)p
= 0xdeadbeef;
1370 *(uint32_t *)p
= 0xdeadbeef;
1373 *(uint32_t *)p
= 0x11111111;
1378 static void test_atom_ops(struct context
*ctx
, bool global
)
1380 const char *src
= "COMP\n"
1381 "#ifdef TARGET_GLOBAL\n"
1382 "#define target RES[0]\n"
1384 "#define target RLOCAL\n"
1387 "DCL RES[0], BUFFER, RAW, WR\n"
1388 "#define threadid SV[0]\n"
1389 "DCL threadid, THREAD_ID[0]\n"
1391 "#define offset TEMP[0]\n"
1392 "DCL offset, LOCAL\n"
1393 "#define tmp TEMP[1]\n"
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"
1421 " UMUL offset.x, threadid, k4\n"
1422 " STORE target.x, offset, korig\n"
1423 " USEQ tmp.x, threadid, k0\n"
1425 " ATOMUADD tmp.x, target, offset, karg\n"
1426 " ATOMUADD tmp.x, target, offset, tmp\n"
1428 " USEQ tmp.x, threadid, k1\n"
1430 " ATOMXCHG tmp.x, target, offset, karg\n"
1431 " ATOMXCHG tmp.x, target, offset, tmp\n"
1433 " USEQ tmp.x, threadid, k2\n"
1435 " ATOMCAS tmp.x, target, offset, korig, karg\n"
1436 " ATOMCAS tmp.x, target, offset, tmp, k0\n"
1438 " USEQ tmp.x, threadid, k3\n"
1440 " ATOMAND tmp.x, target, offset, karg\n"
1441 " ATOMAND tmp.x, target, offset, tmp\n"
1443 " USEQ tmp.x, threadid, k4\n"
1445 " ATOMOR tmp.x, target, offset, karg\n"
1446 " ATOMOR tmp.x, target, offset, tmp\n"
1448 " USEQ tmp.x, threadid, k5\n"
1450 " ATOMXOR tmp.x, target, offset, karg\n"
1451 " ATOMXOR tmp.x, target, offset, tmp\n"
1453 " USEQ tmp.x, threadid, k6\n"
1455 " ATOMUMIN tmp.x, target, offset, karg\n"
1456 " ATOMUMIN tmp.x, target, offset, tmp\n"
1458 " USEQ tmp.x, threadid, k7\n"
1460 " ATOMUMAX tmp.x, target, offset, karg\n"
1461 " ATOMUMAX tmp.x, target, offset, tmp\n"
1463 " USEQ tmp.x, threadid, k8\n"
1465 " ATOMIMIN tmp.x, target, offset, karg\n"
1466 " ATOMIMIN tmp.x, target, offset, tmp\n"
1468 " USEQ tmp.x, threadid, k9\n"
1470 " ATOMIMAX tmp.x, target, offset, karg\n"
1471 " ATOMIMAX tmp.x, target, offset, tmp\n"
1473 "#ifdef TARGET_LOCAL\n"
1474 " LOAD tmp.x, RLOCAL, offset\n"
1475 " STORE RES[0].x, offset, tmp\n"
1480 printf("- %s (%s)\n", __func__
, global
? "global" : "local");
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
);
1494 /* test_atom_race */
1495 static void test_atom_race_expect(void *p
, int s
, int x
, int y
)
1497 *(uint32_t *)p
= x
& 0x20 ? 0x11111111 : 0xffffffff;
1500 static void test_atom_race(struct context
*ctx
, bool global
)
1502 const char *src
= "COMP\n"
1503 "#ifdef TARGET_GLOBAL\n"
1504 "#define target RES[0]\n"
1506 "#define target RLOCAL\n"
1509 "DCL RES[0], BUFFER, RAW, WR\n"
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"
1518 "#define offset TEMP[0]\n"
1519 "DCL offset, LOCAL\n"
1520 "#define arg TEMP[1]\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"
1530 "#define tmp0 TEMP[6]\n"
1532 "#define tmp1 TEMP[7]\n"
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"
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"
1558 " UMUL offset.x, offset, k4\n"
1559 " USLT tmp0.x, threadid, k32\n"
1560 " STORE target.x, offset, k0\n"
1563 " MOV vlocal.x, k0\n"
1564 " MOV arg.x, kdeadcafe\n"
1566 " INEG arg.x, arg\n"
1567 " ATOMUADD vshared.x, target, offset, arg\n"
1569 " USNE tmp0.x, vshared, vlocal\n"
1573 " UADD vlocal.x, vlocal, arg\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"
1580 " UADD offset.x, offset, -k128\n"
1581 " MOV count.x, k0\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"
1589 " USEQ tmp0.x, vshared, last\n"
1593 " MOV last.x, vshared\n"
1597 " UADD count.x, count, k1\n"
1598 " USEQ tmp0.x, count, k128\n"
1603 " ATOMXCHG tmp0.x, target, offset, k11111111\n"
1604 " UADD offset.x, offset, k128\n"
1605 " ATOMXCHG tmp0.x, target, offset, k11111111\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"
1618 printf("- %s (%s)\n", __func__
, global
? "global" : "local");
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
);
1632 int main(int argc
, char *argv
[])
1634 struct context
*ctx
= CALLOC_STRUCT(context
);
1636 unsigned tests
= (argc
> 1) ? strtoul(argv
[1], NULL
, 0) : ~0;
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))
1650 if (tests
& (1 << 5))
1652 if (tests
& (1 << 6))
1654 if (tests
& (1 << 7))
1655 test_many_kern(ctx
);
1656 if (tests
& (1 << 8))
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))
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);