From: Marek Olšák <marek.ol...@amd.com> --- src/gallium/auxiliary/util/u_tests.c | 111 ++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-)
diff --git a/src/gallium/auxiliary/util/u_tests.c b/src/gallium/auxiliary/util/u_tests.c index 2548b46..cb337a2 100644 --- a/src/gallium/auxiliary/util/u_tests.c +++ b/src/gallium/auxiliary/util/u_tests.c @@ -221,21 +221,21 @@ util_probe_rect_rgba_multi(struct pipe_context *ctx, struct pipe_resource *tex, for (c = 0; c < 4; c++) { if (fabs(probe[c] - expected[e*4+c]) >= TOLERANCE) { if (e < num_expected_colors-1) goto next_color; /* test the next expected color */ printf("Probe color at (%i,%i), ", offx+x, offy+y); printf("Expected: %.3f, %.3f, %.3f, %.3f, ", expected[e*4], expected[e*4+1], expected[e*4+2], expected[e*4+3]); printf("Got: %.3f, %.3f, %.3f, %.3f\n", - probe[0], probe[1], probe[2], probe[2]); + probe[0], probe[1], probe[2], probe[3]); pass = false; goto done; } } } } break; /* this color was successful */ next_color:; } @@ -585,31 +585,140 @@ test_sync_file_fences(struct pipe_context *ctx) screen->fence_reference(screen, &merged_fence, NULL); screen->fence_reference(screen, &final_fence, NULL); cso_destroy_context(cso); pipe_resource_reference(&buf, NULL); pipe_resource_reference(&tex, NULL); util_report_result(pass); } +static void +test_texture_barrier(struct pipe_context *ctx, bool use_fbfetch) +{ + struct cso_context *cso; + struct pipe_resource *cb; + void *fs, *vs; + struct pipe_sampler_view *view = NULL; + const char *text; + + if (!ctx->screen->get_param(ctx->screen, PIPE_CAP_TEXTURE_BARRIER)) { + util_report_result_helper(SKIP, "%s: %s", __func__, + use_fbfetch ? "FBFETCH" : "sampler"); + return; + } + if (use_fbfetch && + !ctx->screen->get_param(ctx->screen, PIPE_CAP_TGSI_FS_FBFETCH)) { + util_report_result_helper(SKIP, "%s: %s", __func__, + use_fbfetch ? "FBFETCH" : "sampler"); + return; + } + + cso = cso_create_context(ctx, 0); + cb = util_create_texture2d(ctx->screen, 256, 256, + PIPE_FORMAT_R8G8B8A8_UNORM); + util_set_common_states_and_clear(cso, ctx, cb); + + if (use_fbfetch) { + /* Fragment shader. */ + text = "FRAG\n" + "DCL OUT[0], COLOR[0]\n" + "DCL TEMP[0]\n" + "IMM[0] FLT32 { 0.1, 0.2, 0.3, 0.4}\n" + + "FBFETCH TEMP[0], OUT[0]\n" + "ADD OUT[0], TEMP[0], IMM[0]\n" + "END\n"; + } else { + struct pipe_sampler_view templ = {{0}}; + templ.format = cb->format; + templ.target = cb->target; + templ.swizzle_r = PIPE_SWIZZLE_X; + templ.swizzle_g = PIPE_SWIZZLE_Y; + templ.swizzle_b = PIPE_SWIZZLE_Z; + templ.swizzle_a = PIPE_SWIZZLE_W; + view = ctx->create_sampler_view(ctx, cb, &templ); + ctx->set_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, &view); + + /* Fragment shader. */ + text = "FRAG\n" + "DCL SV[0], POSITION\n" + "DCL SAMP[0]\n" + "DCL SVIEW[0], 2D, FLOAT\n" + "DCL OUT[0], COLOR[0]\n" + "DCL TEMP[0]\n" + "IMM[0] FLT32 { 0.1, 0.2, 0.3, 0.4}\n" + "IMM[1] INT32 { 0, 0, 0, 0}\n" + + "F2I TEMP[0].xy, SV[0].xyyy\n" + "MOV TEMP[0].z, IMM[1].xxxx\n" + "TXF TEMP[0], TEMP[0].xyzz, SAMP[0], 2D\n" + "ADD OUT[0], TEMP[0], IMM[0]\n" + "END\n"; + } + + struct tgsi_token tokens[1000]; + struct pipe_shader_state state; + + if (!tgsi_text_translate(text, tokens, ARRAY_SIZE(tokens))) { + assert(0); + util_report_result_helper(FAIL, "%s: %s", __func__, + use_fbfetch ? "FBFETCH" : "sampler"); + return; + } + pipe_shader_state_from_tgsi(&state, tokens); +#if 0 + tgsi_dump(state.tokens, 0); +#endif + + fs = ctx->create_fs_state(ctx, &state); + cso_set_fragment_shader_handle(cso, fs); + + /* Vertex shader. */ + vs = util_set_passthrough_vertex_shader(cso, ctx, false); + + for (int i = 0; i < 2; i++) { + ctx->texture_barrier(ctx, + use_fbfetch ? PIPE_TEXTURE_BARRIER_FRAMEBUFFER : + PIPE_TEXTURE_BARRIER_SAMPLER); + util_draw_fullscreen_quad(cso); + } + + /* Probe pixels. */ + static const float expected[] = {0.3, 0.5, 0.7, 0.9}; + bool pass = util_probe_rect_rgba(ctx, cb, 0, 0, + cb->width0, cb->height0, expected); + + /* Cleanup. */ + cso_destroy_context(cso); + ctx->delete_vs_state(ctx, vs); + ctx->delete_fs_state(ctx, fs); + pipe_sampler_view_reference(&view, NULL); + pipe_resource_reference(&cb, NULL); + + util_report_result_helper(pass, "%s: %s", __func__, + use_fbfetch ? "FBFETCH" : "sampler"); +} + /** * Run all tests. This should be run with a clean context after * context_create. */ void util_run_tests(struct pipe_screen *screen) { struct pipe_context *ctx = screen->context_create(screen, NULL, 0); null_fragment_shader(ctx); tgsi_vs_window_space_position(ctx); null_sampler_view(ctx, TGSI_TEXTURE_2D); null_sampler_view(ctx, TGSI_TEXTURE_BUFFER); util_test_constant_buffer(ctx, NULL); test_sync_file_fences(ctx); + test_texture_barrier(ctx, false); + test_texture_barrier(ctx, true); ctx->destroy(ctx); puts("Done. Exiting.."); exit(0); } -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev