summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gallium/tests/trivial/compute.c603
1 files changed, 330 insertions, 273 deletions
diff --git a/src/gallium/tests/trivial/compute.c b/src/gallium/tests/trivial/compute.c
index bcdfb11c4f1..5ce12abe227 100644
--- a/src/gallium/tests/trivial/compute.c
+++ b/src/gallium/tests/trivial/compute.c
@@ -428,6 +428,35 @@ static void launch_grid(struct context *ctx, const uint *block_layout,
pipe->launch_grid(pipe, block_layout, grid_layout, pc, input);
}
+static void test_default_init(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = 0xdeadbeef;
+}
+
+/* test_system_values */
+static void test_system_values_expect(void *p, int s, int x, int y)
+{
+ int id = x / 16, sv = (x % 16) / 4, c = x % 4;
+ int tid[] = { id % 20, (id % 240) / 20, id / 240, 0 };
+ int bsz[] = { 4, 3, 5, 1};
+ int gsz[] = { 5, 4, 1, 1};
+
+ switch (sv) {
+ case 0:
+ *(uint32_t *)p = tid[c] / bsz[c];
+ break;
+ case 1:
+ *(uint32_t *)p = bsz[c];
+ break;
+ case 2:
+ *(uint32_t *)p = gsz[c];
+ break;
+ case 3:
+ *(uint32_t *)p = tid[c] % bsz[c];
+ break;
+ }
+}
+
static void test_system_values(struct context *ctx)
{
const char *src = "COMP\n"
@@ -461,44 +490,31 @@ static void test_system_values(struct context *ctx)
" STORE RES[0].xyzw, TEMP[0], SV[3]\n"
" RET\n"
"ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- int id = x / 16, sv = (x % 16) / 4, c = x % 4;
- int tid[] = { id % 20, (id % 240) / 20, id / 240, 0 };
- int bsz[] = { 4, 3, 5, 1};
- int gsz[] = { 5, 4, 1, 1};
-
- switch (sv) {
- case 0:
- *(uint32_t *)p = tid[c] / bsz[c];
- break;
- case 1:
- *(uint32_t *)p = bsz[c];
- break;
- case 2:
- *(uint32_t *)p = gsz[c];
- break;
- case 3:
- *(uint32_t *)p = tid[c] % bsz[c];
- break;
- }
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 76800, 0, init);
+ 76800, 0, test_default_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){4, 3, 5}, (uint []){5, 4, 1}, 0, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_system_values_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_resource_access */
+static void test_resource_access_init0(void *p, int s, int x, int y)
+{
+ *(float *)p = 8.0 - (float)x;
+}
+
+static void test_resource_access_expect(void *p, int s, int x, int y)
+{
+ *(float *)p = 8.0 - (float)((x + 4 * y) & 0x3f);
+}
+
static void test_resource_access(struct context *ctx)
{
const char *src = "COMP\n"
@@ -519,31 +535,33 @@ static void test_resource_access(struct context *ctx)
" STORE RES[1].xyzw, TEMP[1], TEMP[0]\n"
" RET\n"
" ENDSUB\n";
- void init0(void *p, int s, int x, int y) {
- *(float *)p = 8.0 - (float)x;
- }
- void init1(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- *(float *)p = 8.0 - (float)((x + 4*y) & 0x3f);
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 256, 0, init0);
+ 256, 0, test_resource_access_init0);
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
- 60, 12, init1);
+ 60, 12, test_default_init);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){15, 12, 1}, 0, NULL);
- check_tex(ctx, 1, expect, NULL);
+ check_tex(ctx, 1, test_resource_access_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_function_calls */
+static void test_function_calls_init(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = 15 * y + x;
+}
+
+static void test_function_calls_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = (15 * y + x) < 4 ? 2 : 1 ;
+}
+
static void test_function_calls(struct context *ctx)
{
const char *src = "COMP\n"
@@ -585,26 +603,26 @@ static void test_function_calls(struct context *ctx)
"21: STORE RES[0].x, TEMP[2], TEMP[1].xxxx\n"
"22: RET\n"
"23: ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 15 * y + x;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = (15 * y + x) < 4 ? 2 : 1 ;
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
- 15, 12, init);
+ 15, 12, test_function_calls_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){3, 3, 3}, (uint []){5, 4, 1}, 15, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_function_calls_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_input_global */
+static void test_input_global_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = 0xdeadbeef - (x == 0 ? 0x10001 + 2 * s : 0);
+}
+
static void test_input_global(struct context *ctx)
{
const char *src = "COMP\n"
@@ -621,35 +639,39 @@ static void test_input_global(struct context *ctx)
" STORE RGLOBAL.x, TEMP[1].yyyy, TEMP[1]\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef - (x == 0 ? 0x10001 + 2 * s : 0);
- }
uint32_t input[8] = { 0x10001, 0x10002, 0x10003, 0x10004,
0x10005, 0x10006, 0x10007, 0x10008 };
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 32, src, NULL);
- init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
- init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
- init_tex(ctx, 2, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
- init_tex(ctx, 3, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0, init);
+ init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
+ test_default_init);
+ init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
+ test_default_init);
+ init_tex(ctx, 2, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
+ test_default_init);
+ init_tex(ctx, 3, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT, 32, 0,
+ test_default_init);
init_globals(ctx, (int []){ 0, 1, 2, 3, -1 },
(uint32_t *[]){ &input[1], &input[3],
&input[5], &input[7] });
launch_grid(ctx, (uint []){4, 1, 1}, (uint []){1, 1, 1}, 0, input);
- check_tex(ctx, 0, expect, NULL);
- check_tex(ctx, 1, expect, NULL);
- check_tex(ctx, 2, expect, NULL);
- check_tex(ctx, 3, expect, NULL);
+ check_tex(ctx, 0, test_input_global_expect, NULL);
+ check_tex(ctx, 1, test_input_global_expect, NULL);
+ check_tex(ctx, 2, test_input_global_expect, NULL);
+ check_tex(ctx, 3, test_input_global_expect, NULL);
destroy_globals(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_private */
+static void test_private_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = (x / 32) + x % 32;
+}
+
static void test_private(struct context *ctx)
{
const char *src = "COMP\n"
@@ -691,26 +713,26 @@ static void test_private(struct context *ctx)
" ENDLOOP\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = (x / 32) + x % 32;
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 128, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 32768, 0, init);
+ 32768, 0, test_default_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){16, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_private_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_local */
+static void test_local_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = x & 0x20 ? 2 : 1;
+}
+
static void test_local(struct context *ctx)
{
const char *src = "COMP\n"
@@ -778,26 +800,42 @@ static void test_local(struct context *ctx)
" STORE RES[0].x, TEMP[1], TEMP[0]\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = x & 0x20 ? 2 : 1;
- }
printf("- %s\n", __func__);
init_prog(ctx, 256, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 4096, 0, init);
+ 4096, 0, test_default_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_local_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_sample */
+static void test_sample_init(void *p, int s, int x, int y)
+{
+ *(float *)p = s ? 1 : x * y;
+}
+
+static void test_sample_expect(void *p, int s, int x, int y)
+{
+ switch (x % 4) {
+ case 0:
+ *(float *)p = x / 4 * y;
+ break;
+ case 1:
+ case 2:
+ *(float *)p = 0;
+ break;
+ case 3:
+ *(float *)p = 1;
+ break;
+ }
+}
+
static void test_sample(struct context *ctx)
{
const char *src = "COMP\n"
@@ -818,36 +856,19 @@ static void test_sample(struct context *ctx)
" STORE RES[0].xyzw, TEMP[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(float *)p = s ? 1 : x * y;
- }
- void expect(void *p, int s, int x, int y) {
- switch (x % 4) {
- case 0:
- *(float *)p = x / 4 * y;
- break;
- case 1:
- case 2:
- *(float *)p = 0;
- break;
- case 3:
- *(float *)p = 1;
- break;
- }
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
- 128, 32, init);
+ 128, 32, test_sample_init);
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
- 512, 32, init);
+ 512, 32, test_sample_init);
init_compute_resources(ctx, (int []) { 1, -1 });
init_sampler_views(ctx, (int []) { 0, -1 });
init_sampler_states(ctx, 2);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0, NULL);
- check_tex(ctx, 1, expect, NULL);
+ check_tex(ctx, 1, test_sample_expect, NULL);
destroy_sampler_states(ctx);
destroy_sampler_views(ctx);
destroy_compute_resources(ctx);
@@ -855,6 +876,12 @@ static void test_sample(struct context *ctx)
destroy_prog(ctx);
}
+/* test_many_kern */
+static void test_many_kern_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = x;
+}
+
static void test_many_kern(struct context *ctx)
{
const char *src = "COMP\n"
@@ -883,29 +910,34 @@ static void test_many_kern(struct context *ctx)
" STORE RES[0].x, TEMP[0], IMM[0].wwww\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = x;
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 16, 0, init);
+ 16, 0, test_default_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 5, NULL);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 10, NULL);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){1, 1, 1}, 15, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_many_kern_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_constant */
+static void test_constant_init(void *p, int s, int x, int y)
+{
+ *(float *)p = s ? 0xdeadbeef : 8.0 - (float)x;
+}
+
+static void test_constant_expect(void *p, int s, int x, int y)
+{
+ *(float *)p = 8.0 - (float)x;
+}
+
static void test_constant(struct context *ctx)
{
const char *src = "COMP\n"
@@ -922,28 +954,36 @@ static void test_constant(struct context *ctx)
" STORE RES[1].x, TEMP[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(float *)p = s ? 0xdeadbeef : 8.0 - (float)x;
- }
- void expect(void *p, int s, int x, int y) {
- *(float *)p = 8.0 - (float)x;
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
- 256, 0, init);
+ 256, 0, test_constant_init);
init_tex(ctx, 1, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 256, 0, init);
+ 256, 0, test_constant_init);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
- check_tex(ctx, 1, expect, NULL);
+ check_tex(ctx, 1, test_constant_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_resource_indirect */
+static void test_resource_indirect_init(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = s == 0 ? 0xdeadbeef :
+ s == 1 ? x % 2 :
+ s == 2 ? 2 * x :
+ 2 * x + 1;
+}
+
+static void test_resource_indirect_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = 2 * x + (x % 2 ? 1 : 0);
+}
+
static void test_resource_indirect(struct context *ctx)
{
const char *src = "COMP\n"
@@ -961,35 +1001,27 @@ static void test_resource_indirect(struct context *ctx)
" STORE RES[0].x, TEMP[0], TEMP[1]\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = s == 0 ? 0xdeadbeef :
- s == 1 ? x % 2 :
- s == 2 ? 2 * x :
- 2 * x + 1;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = 2 * x + (x % 2 ? 1 : 0);
- }
printf("- %s\n", __func__);
init_prog(ctx, 0, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 256, 0, init);
+ 256, 0, test_resource_indirect_init);
init_tex(ctx, 1, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
- 256, 0, init);
+ 256, 0, test_resource_indirect_init);
init_tex(ctx, 2, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
- 256, 0, init);
+ 256, 0, test_resource_indirect_init);
init_tex(ctx, 3, PIPE_BUFFER, false, PIPE_FORMAT_R32_FLOAT,
- 256, 0, init);
+ 256, 0, test_resource_indirect_init);
init_compute_resources(ctx, (int []) { 0, 1, 2, 3, -1 });
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){64, 1, 1}, 0, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_resource_indirect_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_surface_ld */
enum pipe_format surface_fmts[] = {
PIPE_FORMAT_B8G8R8A8_UNORM,
PIPE_FORMAT_B8G8R8X8_UNORM,
@@ -1023,6 +1055,42 @@ enum pipe_format surface_fmts[] = {
PIPE_FORMAT_R32G32B32A32_SINT
};
+static void test_surface_ld_init0f(void *p, int s, int x, int y)
+{
+ float v[] = { 1.0, -.75, .50, -.25 };
+ int i = 0;
+
+ util_format_write_4f(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+}
+
+static void test_surface_ld_init0i(void *p, int s, int x, int y)
+{
+ int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
+ int i = 0;
+
+ util_format_write_4i(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+}
+
+static void test_surface_ld_expectf(void *p, int s, int x, int y)
+{
+ float v[4], w[4];
+ int i = 0;
+
+ test_surface_ld_init0f(v, s, x / 4, y);
+ util_format_read_4f(surface_fmts[i], w, 0, v, 0, 0, 0, 1, 1);
+ *(float *)p = w[x % 4];
+}
+
+static void test_surface_ld_expecti(void *p, int s, int x, int y)
+{
+ int32_t v[4], w[4];
+ int i = 0;
+
+ test_surface_ld_init0i(v, s, x / 4, y);
+ util_format_read_4i(surface_fmts[i], w, 0, v, 0, 0, 0, 1, 1);
+ *(uint32_t *)p = w[x % 4];
+}
+
static void test_surface_ld(struct context *ctx)
{
const char *src = "COMP\n"
@@ -1040,33 +1108,6 @@ static void test_surface_ld(struct context *ctx)
" RET\n"
" ENDSUB\n";
int i = 0;
- void init0f(void *p, int s, int x, int y) {
- float v[] = { 1.0, -.75, .50, -.25 };
- util_format_write_4f(surface_fmts[i], v, 0,
- p, 0, 0, 0, 1, 1);
- }
- void init0i(void *p, int s, int x, int y) {
- int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
- util_format_write_4i(surface_fmts[i], v, 0,
- p, 0, 0, 0, 1, 1);
- }
- void init1(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expectf(void *p, int s, int x, int y) {
- float v[4], w[4];
- init0f(v, s, x / 4, y);
- util_format_read_4f(surface_fmts[i], w, 0,
- v, 0, 0, 0, 1, 1);
- *(float *)p = w[x % 4];
- }
- void expecti(void *p, int s, int x, int y) {
- int32_t v[4], w[4];
- init0i(v, s, x / 4, y);
- util_format_read_4i(surface_fmts[i], w, 0,
- v, 0, 0, 0, 1, 1);
- *(uint32_t *)p = w[x % 4];
- }
printf("- %s\n", __func__);
@@ -1085,14 +1126,14 @@ static void test_surface_ld(struct context *ctx)
}
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, surface_fmts[i],
- 128, 32, (is_int ? init0i : init0f));
+ 128, 32, (is_int ? test_surface_ld_init0i : test_surface_ld_init0f));
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
- 512, 32, init1);
+ 512, 32, test_default_init);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
init_sampler_states(ctx, 2);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
NULL);
- check_tex(ctx, 1, (is_int ? expecti : expectf), NULL);
+ check_tex(ctx, 1, (is_int ? test_surface_ld_expecti : test_surface_ld_expectf), NULL);
destroy_sampler_states(ctx);
destroy_compute_resources(ctx);
destroy_tex(ctx);
@@ -1101,6 +1142,73 @@ static void test_surface_ld(struct context *ctx)
destroy_prog(ctx);
}
+/* test_surface_st */
+static void test_surface_st_init0f(void *p, int s, int x, int y)
+{
+ float v[] = { 1.0, -.75, 0.5, -.25 };
+ *(float *)p = v[x % 4];
+}
+
+static void test_surface_st_init0i(void *p, int s, int x, int y)
+{
+ int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
+ *(int32_t *)p = v[x % 4];
+}
+
+static void test_surface_st_init1(void *p, int s, int x, int y)
+{
+ int i = 0;
+ memset(p, 1, util_format_get_blocksize(surface_fmts[i]));
+}
+
+static void test_surface_st_expectf(void *p, int s, int x, int y)
+{
+ float vf[4];
+ int i = 0, j;
+
+ for (j = 0; j < 4; j++)
+ test_surface_st_init0f(&vf[j], s, 4 * x + j, y);
+ util_format_write_4f(surface_fmts[i], vf, 0, p, 0, 0, 0, 1, 1);
+}
+
+static void test_surface_st_expects(void *p, int s, int x, int y)
+{
+ int32_t v[4];
+ int i = 0, j;
+
+ for (j = 0; j < 4; j++)
+ test_surface_st_init0i(&v[j], s, 4 * x + j, y);
+ util_format_write_4i(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+}
+
+static void test_surface_st_expectu(void *p, int s, int x, int y)
+{
+ uint32_t v[4];
+ int i = 0, j;
+
+ for (j = 0; j < 4; j++)
+ test_surface_st_init0i(&v[j], s, 4 * x + j, y);
+ util_format_write_4ui(surface_fmts[i], v, 0, p, 0, 0, 0, 1, 1);
+}
+
+static bool test_surface_st_check(void *x, void *y, int sz)
+{
+ int i = 0, j;
+
+ if (util_format_is_float(surface_fmts[i])) {
+ return fabs(*(float *)x - *(float *)y) < 3.92156863e-3;
+
+ } else if ((sz % 4) == 0) {
+ for (j = 0; j < sz / 4; j++)
+ if (abs(((uint32_t *)x)[j] -
+ ((uint32_t *)y)[j]) > 1)
+ return false;
+ return true;
+ } else {
+ return !memcmp(x, y, sz);
+ }
+}
+
static void test_surface_st(struct context *ctx)
{
const char *src = "COMP\n"
@@ -1118,60 +1226,6 @@ static void test_surface_st(struct context *ctx)
" RET\n"
" ENDSUB\n";
int i = 0;
- void init0f(void *p, int s, int x, int y) {
- float v[] = { 1.0, -.75, 0.5, -.25 };
- *(float *)p = v[x % 4];
- }
- void init0i(void *p, int s, int x, int y) {
- int v[] = { 0xffffffff, 0xffff, 0xff, 0xf };
- *(int32_t *)p = v[x % 4];
- }
- void init1(void *p, int s, int x, int y) {
- memset(p, 1, util_format_get_blocksize(surface_fmts[i]));
- }
- void expectf(void *p, int s, int x, int y) {
- float vf[4];
- int j;
-
- for (j = 0; j < 4; j++)
- init0f(&vf[j], s, 4 * x + j, y);
- util_format_write_4f(surface_fmts[i], vf, 0,
- p, 0, 0, 0, 1, 1);
- }
- void expects(void *p, int s, int x, int y) {
- int32_t v[4];
- int j;
-
- for (j = 0; j < 4; j++)
- init0i(&v[j], s, 4 * x + j, y);
- util_format_write_4i(surface_fmts[i], v, 0,
- p, 0, 0, 0, 1, 1);
- }
- void expectu(void *p, int s, int x, int y) {
- uint32_t v[4];
- int j;
-
- for (j = 0; j < 4; j++)
- init0i(&v[j], s, 4 * x + j, y);
- util_format_write_4ui(surface_fmts[i], v, 0,
- p, 0, 0, 0, 1, 1);
- }
- bool check(void *x, void *y, int sz) {
- int j;
-
- if (util_format_is_float(surface_fmts[i])) {
- return fabs(*(float *)x - *(float *)y) < 3.92156863e-3;
-
- } else if ((sz % 4) == 0) {
- for (j = 0; j < sz / 4; j++)
- if (abs(((uint32_t *)x)[j] -
- ((uint32_t *)y)[j]) > 1)
- return false;
- return true;
- } else {
- return !memcmp(x, y, sz);
- }
- }
printf("- %s\n", __func__);
@@ -1192,16 +1246,16 @@ static void test_surface_st(struct context *ctx)
}
init_tex(ctx, 0, PIPE_TEXTURE_2D, true, PIPE_FORMAT_R32_FLOAT,
- 512, 32, (is_int ? init0i : init0f));
+ 512, 32, (is_int ? test_surface_st_init0i : test_surface_st_init0f));
init_tex(ctx, 1, PIPE_TEXTURE_2D, true, surface_fmts[i],
- 128, 32, init1);
+ 128, 32, test_surface_st_init1);
init_compute_resources(ctx, (int []) { 0, 1, -1 });
init_sampler_states(ctx, 2);
launch_grid(ctx, (uint []){1, 1, 1}, (uint []){128, 32, 1}, 0,
NULL);
- check_tex(ctx, 1, (is_int && is_signed ? expects :
- is_int && !is_signed ? expectu :
- expectf), check);
+ check_tex(ctx, 1, (is_int && is_signed ? test_surface_st_expects :
+ is_int && !is_signed ? test_surface_st_expectu :
+ test_surface_st_expectf), test_surface_st_check);
destroy_sampler_states(ctx);
destroy_compute_resources(ctx);
destroy_tex(ctx);
@@ -1210,6 +1264,12 @@ static void test_surface_st(struct context *ctx)
destroy_prog(ctx);
}
+/* test_barrier */
+static void test_barrier_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = 31;
+}
+
static void test_barrier(struct context *ctx)
{
const char *src = "COMP\n"
@@ -1259,26 +1319,62 @@ static void test_barrier(struct context *ctx)
" STORE RES[0].x, TEMP[1], TEMP[0]\n"
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = 31;
- }
printf("- %s\n", __func__);
init_prog(ctx, 256, 0, 0, src, NULL);
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 4096, 0, init);
+ 4096, 0, test_default_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_barrier_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_atom_ops */
+static void test_atom_ops_init(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = 0xbad;
+}
+
+static void test_atom_ops_expect(void *p, int s, int x, int y)
+{
+ switch (x) {
+ case 0:
+ *(uint32_t *)p = 0xce6c8eef;
+ break;
+ case 1:
+ *(uint32_t *)p = 0xdeadbeef;
+ break;
+ case 2:
+ *(uint32_t *)p = 0x11111111;
+ break;
+ case 3:
+ *(uint32_t *)p = 0x10011001;
+ break;
+ case 4:
+ *(uint32_t *)p = 0xdfbdbfff;
+ break;
+ case 5:
+ *(uint32_t *)p = 0x11111111;
+ break;
+ case 6:
+ *(uint32_t *)p = 0x11111111;
+ break;
+ case 7:
+ *(uint32_t *)p = 0xdeadbeef;
+ break;
+ case 8:
+ *(uint32_t *)p = 0xdeadbeef;
+ break;
+ case 9:
+ *(uint32_t *)p = 0x11111111;
+ break;
+ }
+}
+
static void test_atom_ops(struct context *ctx, bool global)
{
const char *src = "COMP\n"
@@ -1381,58 +1477,26 @@ static void test_atom_ops(struct context *ctx, bool global)
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xbad;
- }
- void expect(void *p, int s, int x, int y) {
- switch (x) {
- case 0:
- *(uint32_t *)p = 0xce6c8eef;
- break;
- case 1:
- *(uint32_t *)p = 0xdeadbeef;
- break;
- case 2:
- *(uint32_t *)p = 0x11111111;
- break;
- case 3:
- *(uint32_t *)p = 0x10011001;
- break;
- case 4:
- *(uint32_t *)p = 0xdfbdbfff;
- break;
- case 5:
- *(uint32_t *)p = 0x11111111;
- break;
- case 6:
- *(uint32_t *)p = 0x11111111;
- break;
- case 7:
- *(uint32_t *)p = 0xdeadbeef;
- break;
- case 8:
- *(uint32_t *)p = 0xdeadbeef;
- break;
- case 9:
- *(uint32_t *)p = 0x11111111;
- break;
- }
- }
-
printf("- %s (%s)\n", __func__, global ? "global" : "local");
init_prog(ctx, 40, 0, 0, src,
(global ? "-DTARGET_GLOBAL" : "-DTARGET_LOCAL"));
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 40, 0, init);
+ 40, 0, test_atom_ops_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){10, 1, 1}, (uint []){1, 1, 1}, 0, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_atom_ops_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);
}
+/* test_atom_race */
+static void test_atom_race_expect(void *p, int s, int x, int y)
+{
+ *(uint32_t *)p = x & 0x20 ? 0x11111111 : 0xffffffff;
+}
+
static void test_atom_race(struct context *ctx, bool global)
{
const char *src = "COMP\n"
@@ -1551,22 +1615,15 @@ static void test_atom_race(struct context *ctx, bool global)
" RET\n"
" ENDSUB\n";
- void init(void *p, int s, int x, int y) {
- *(uint32_t *)p = 0xdeadbeef;
- }
- void expect(void *p, int s, int x, int y) {
- *(uint32_t *)p = x & 0x20 ? 0x11111111 : 0xffffffff;
- }
-
printf("- %s (%s)\n", __func__, global ? "global" : "local");
init_prog(ctx, 256, 0, 0, src,
(global ? "-DTARGET_GLOBAL" : "-DTARGET_LOCAL"));
init_tex(ctx, 0, PIPE_BUFFER, true, PIPE_FORMAT_R32_FLOAT,
- 4096, 0, init);
+ 4096, 0, test_default_init);
init_compute_resources(ctx, (int []) { 0, -1 });
launch_grid(ctx, (uint []){64, 1, 1}, (uint []){16, 1, 1}, 0, NULL);
- check_tex(ctx, 0, expect, NULL);
+ check_tex(ctx, 0, test_atom_race_expect, NULL);
destroy_compute_resources(ctx);
destroy_tex(ctx);
destroy_prog(ctx);