Home | History | Annotate | Download | only in trivial

Lines Matching refs:ctx

61                 __n = ctx->screen->get_compute_param(ctx->screen, c, __v); \
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, PIPE_SEARCH_DIR);
78 assert(ctx->screen);
80 ctx->pipe = ctx->screen->context_create(ctx->screen, NULL);
81 assert(ctx->pipe);
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);
93 FREE(ctx);
97 preprocess_prog(struct context *ctx, const char *src, const char *defs)
140 static void init_prog(struct context *ctx, unsigned local_sz,
144 struct pipe_context *pipe = ctx->pipe;
152 char *psrc = preprocess_prog(ctx, src, defs);
159 ctx->hwcs = pipe->create_compute_state(pipe, &cs);
160 assert(ctx->hwcs);
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);
170 ctx->hwcs = NULL;
173 static void init_tex(struct context *ctx, int slot,
178 struct pipe_context *pipe = ctx->pipe;
179 struct pipe_resource **tex = &ctx->tex[slot];
201 *tex = ctx->screen->resource_create(ctx->screen, &ttex);
222 ctx->tex_rw[slot] = rw;
229 static void check_tex(struct context *ctx, int slot,
233 struct pipe_context *pipe = ctx->pipe;
234 struct pipe_resource *tex = ctx->tex[slot];
296 static void destroy_tex(struct context *ctx)
301 if (ctx->tex[i])
302 pipe_resource_reference(&ctx->tex[i], NULL);
306 static void init_sampler_views(struct context *ctx, const int *slots)
308 struct pipe_context *pipe = ctx->pipe;
313 u_sampler_view_default_template(&tview, ctx->tex[*slots],
314 ctx->tex[*slots]->format);
316 ctx->view[i] = pipe->create_sampler_view(pipe, ctx->tex[*slots],
318 assert(ctx->view[i]);
321 pipe->set_compute_sampler_views(pipe, 0, i, ctx->view);
324 static void destroy_sampler_views(struct context *ctx)
326 struct pipe_context *pipe = ctx->pipe;
332 if (ctx->view[i]) {
333 pipe->sampler_view_destroy(pipe, ctx->view[i]);
334 ctx->view[i] = NULL;
339 static void init_compute_resources(struct context *ctx, const int *slots)
341 struct pipe_context *pipe = ctx->pipe;
346 .format = ctx->tex[*slots]->format,
347 .usage = ctx->tex[*slots]->bind,
348 .writable = ctx->tex_rw[*slots]
351 if (ctx->tex[*slots]->target == PIPE_BUFFER)
352 tsurf.u.buf.last_element = ctx->tex[*slots]->width0 - 1;
354 ctx->surf[i] = pipe->create_surface(pipe, ctx->tex[*slots],
356 assert(ctx->surf[i]);
359 pipe->set_compute_resources(pipe, 0, i, ctx->surf);
362 static void destroy_compute_resources(struct context *ctx)
364 struct pipe_context *pipe = ctx->pipe;
370 if (ctx->surf[i]) {
371 pipe->surface_destroy(pipe, ctx->surf[i]);
372 ctx->surf[i] = NULL;
377 static void init_sampler_states(struct context *ctx, int n)
379 struct pipe_context *pipe = ctx->pipe;
386 ctx->hwsmp[i] = pipe->create_sampler_state(pipe, &smp);
387 assert(ctx->hwsmp[i]);
390 pipe->bind_compute_sampler_states(pipe, 0, i, ctx->hwsmp);
393 static void destroy_sampler_states(struct context *ctx)
395 struct pipe_context *pipe = ctx->pipe;
401 if (ctx->hwsmp[i]) {
402 pipe->delete_sampler_state(pipe, ctx->hwsmp[i]);
403 ctx->hwsmp[i] = NULL;
408 static void init_globals(struct context *ctx, const int *slots,
411 struct pipe_context *pipe = ctx->pipe;
416 res[i] = ctx->tex[*slots];
421 static void destroy_globals(struct context *ctx)
423 struct pipe_context *pipe = ctx->pipe;
428 static void launch_grid(struct context *ctx, const uint *block_layout,
432 struct pipe_context *pipe = ctx->pipe;
437 static void test_system_values(struct context *ctx)
497 init_prog(ctx, 0, 0, 0, src, NULL);
498 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
500 init_compute_resources(ctx, (int []) { 0, -1 });
501 launch_grid(ctx, (uint []){4, 3, 5}, (uint []){5, 4, 1}, 0, NULL);
502 check_tex(ctx, 0, expect, NULL);
503 destroy_compute_resources(ctx);
504 destroy_tex(ctx);
505 destroy_prog(ctx);
508 static void test_resource_access(struct context *ctx)
540 init_prog(ctx, 0, 0, 0, src, NULL);
541 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
543 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
545 init_compute_resources(ctx, (int []) { 0, 1, -1 });
546 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){15, 12, 1}, 0, NULL);
547 check_tex(ctx, 1, expect, NULL);
548 destroy_compute_resources(ctx);
549 destroy_tex(ctx);
550 destroy_prog(ctx);
553 static void test_function_calls(struct context *ctx)
603 init_prog(ctx, 0, 0, 0, src, NULL);
604 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
606 init_compute_resources(ctx, (int []) { 0, -1 });
607 launch_grid(ctx, (uint []){3, 3, 3}, (uint []){5, 4, 1}, 15, NULL);
608 check_tex(ctx, 0, expect, NULL);
609 destroy_compute_resources(ctx);
610 destroy_tex(ctx);
611 destroy_prog(ctx);
614 static void test_input_global(struct context *ctx)
641 init_prog(ctx, 0, 0, 32, src, NULL);
642 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
643 init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
644 init_tex(ctx, 2, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
645 init_tex(ctx, 3, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
646 init_globals(ctx, (int []){ 0, 1, 2, 3, -1 },
649 launch_grid(ctx, (uint []){4, 1, 1}, (uint []){1, 1, 1}, 0, input);
650 check_tex(ctx, 0, expect, NULL);
651 check_tex(ctx, 1, expect, NULL);
652 check_tex(ctx, 2, expect, NULL);
653 check_tex(ctx, 3, expect, NULL);
654 destroy_globals(ctx);
655 destroy_tex(ctx);
656 destroy_prog(ctx);
659 static void test_private(struct context *ctx)
709 init_prog(ctx, 0, 128, 0, src, NULL);
710 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
712 init_compute_resources(ctx, (int []) { 0, -1 });
713 launch_grid(ctx, (uint []){16, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
714 check_tex(ctx, 0, expect, NULL);
715 destroy_compute_resources(ctx);
716 destroy_tex(ctx);
717 destroy_prog(ctx);
720 static void test_local(struct context *ctx)
796 init_prog(ctx, 256, 0, 0, src, NULL);
797 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
799 init_compute_resources(ctx, (int []) { 0, -1 });
800 launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
801 check_tex(ctx, 0, expect, NULL);
802 destroy_compute_resources(ctx);
803 destroy_tex(ctx);
804 destroy_prog(ctx);
807 static void test_sample(struct context *ctx)
847 init_prog(ctx, 0, 0, 0, src, NULL);
848 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
850 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
852 init_compute_resources(ctx, (int []) { 1, -1 });
853 init_sampler_views(ctx, (int []) { 0, -1 });
854 init_sampler_states(ctx, 2);
855 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0, NULL);
856 check_tex(ctx, 1, expect, NULL);
857 destroy_sampler_states(ctx);
858 destroy_sampler_views(ctx);
859 destroy_compute_resources(ctx);
860 destroy_tex(ctx);
861 destroy_prog(ctx);
864 static void test_many_kern(struct context *ctx)
901 init_prog(ctx, 0, 0, 0, src, NULL);
902 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
904 init_compute_resources(ctx, (int []) { 0, -1 });
905 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
906 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 5, NULL);
907 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 10, NULL);
908 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 15, NULL);
909 check_tex(ctx, 0, expect, NULL);
910 destroy_compute_resources(ctx);
911 destroy_tex(ctx);
912 destroy_prog(ctx);
915 static void test_constant(struct context *ctx)
940 init_prog(ctx, 0, 0, 0, src, NULL);
941 init_tex(ctx, 0, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
943 init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
945 init_compute_resources(ctx, (int []) { 0, 1, -1 });
946 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
947 check_tex(ctx, 1, expect, NULL);
948 destroy_compute_resources(ctx);
949 destroy_tex(ctx);
950 destroy_prog(ctx);
953 static void test_resource_indirect(struct context *ctx)
982 init_prog(ctx, 0, 0, 0, src, NULL);
983 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
985 init_tex(ctx, 1, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
987 init_tex(ctx, 2, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
989 init_tex(ctx, 3, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
991 init_compute_resources(ctx, (int []) { 0, 1, 2, 3, -1 });
992 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
993 check_tex(ctx, 0, expect, NULL);
994 destroy_compute_resources(ctx);
995 destroy_tex(ctx);
996 destroy_prog(ctx);
1032 static void test_surface_ld(struct context *ctx)
1079 init_prog(ctx, 0, 0, 0, src, NULL);
1086 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, surface_fmts[i],
1088 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
1090 init_compute_resources(ctx, (int []) { 0, 1, -1 });
1091 init_sampler_states(ctx, 2);
1092 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
1094 check_tex(ctx, 1, (is_int ? expecti : expectf), NULL);
1095 destroy_sampler_states(ctx);
1096 destroy_compute_resources(ctx);
1097 destroy_tex(ctx);
1100 destroy_prog(ctx);
1103 static void test_surface_st(struct context *ctx)
1177 init_prog(ctx, 0, 0, 0, src, NULL);
1186 init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
1188 init_tex(ctx, 1, PIPE_TEXTURE_2D, true, surface_fmts[i],
1190 init_compute_resources(ctx, (int []) { 0, 1, -1 });
1191 init_sampler_states(ctx, 2);
1192 launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
1194 check_tex(ctx, 1, (is_int && is_signed ? expects :
1197 destroy_sampler_states(ctx);
1198 destroy_compute_resources(ctx);
1199 destroy_tex(ctx);
1202 destroy_prog(ctx);
1205 static void test_barrier(struct context *ctx)
1263 init_prog(ctx, 256, 0, 0, src, NULL);
1264 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
1266 init_compute_resources(ctx, (int []) { 0, -1 });
1267 launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
1268 check_tex(ctx, 0, expect, NULL);
1269 destroy_compute_resources(ctx);
1270 destroy_tex(ctx);
1271 destroy_prog(ctx);
1274 static void test_atom_ops(struct context *ctx, bool global)
1416 init_prog(ctx, 40, 0, 0, src,
1418 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
1420 init_compute_resources(ctx, (int []) { 0, -1 });
1421 launch_grid(ctx, (uint []){10, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
1422 check_tex(ctx, 0, expect, NULL);
1423 destroy_compute_resources(ctx);
1424 destroy_tex(ctx);
1425 destroy_prog(ctx);
1428 static void test_atom_race(struct context *ctx, bool global)
1555 init_prog(ctx, 256, 0, 0, src,
1557 init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
1559 init_compute_resources(ctx, (int []) { 0, -1 });
1560 launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
1561 check_tex(ctx, 0, expect, NULL);
1562 destroy_compute_resources(ctx);
1563 destroy_tex(ctx);
1564 destroy_prog(ctx);
1569 struct context *ctx = CALLOC_STRUCT(context);
1571 init_ctx(ctx);
1572 test_system_values(ctx);
1573 test_resource_access(ctx);
1574 test_function_calls(ctx);
1575 test_input_global(ctx);
1576 test_private(ctx);
1577 test_local(ctx);
1578 test_sample(ctx);
1579 test_many_kern(ctx);
1580 test_constant(ctx);
1581 test_resource_indirect(ctx);
1582 test_surface_ld(ctx);
1583 test_surface_st(ctx);
1584 test_barrier(ctx);
1585 test_atom_ops(ctx, true);
1586 test_atom_race(ctx, true);
1587 test_atom_ops(ctx, false);
1588 test_atom_race(ctx, false);
1589 destroy_ctx(ctx);