[Mesa-dev] [PATCH 10/10] gallium/u_tests: test user-specified transfer stride

Marek Olšák maraeo at gmail.com
Wed Apr 25 21:16:31 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/auxiliary/util/u_tests.c | 62 ++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_tests.c b/src/gallium/auxiliary/util/u_tests.c
index e7d11ce117e..32c543027cb 100644
--- a/src/gallium/auxiliary/util/u_tests.c
+++ b/src/gallium/auxiliary/util/u_tests.c
@@ -778,35 +778,97 @@ test_texture_barrier(struct pipe_context *ctx, bool use_fbfetch,
    /* 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, name);
 }
 
+/* Write a value into a texture, or read and check a value inside a texture,
+ * while using a user-specified stride.
+ */
+static bool
+test_one_transfer(struct pipe_context *ctx, struct pipe_resource *tex,
+                  unsigned x, unsigned y, unsigned value,
+                  unsigned user_stride, bool read)
+{
+   struct pipe_transfer *transfer = NULL;
+   struct pipe_box box;
+   uint32_t *map;
+
+   assert(y >= 1);
+   u_box_2d(x, y - 1, 1, 2, &box);
+   map = ctx->transfer_map(ctx, tex, 0,
+                           read ? PIPE_TRANSFER_READ : PIPE_TRANSFER_WRITE,
+                           &box, user_stride, &transfer);
+
+   if (transfer->stride != user_stride) {
+      ctx->transfer_unmap(ctx, transfer);
+      return false;
+   }
+
+   if (read) {
+      if (map[transfer->stride / 4] != value) {
+         ctx->transfer_unmap(ctx, transfer);
+         return false;
+      }
+   } else {
+      map[transfer->stride / 4] = value;
+   }
+
+   ctx->transfer_unmap(ctx, transfer);
+   return true;
+}
+
+static void
+test_transfer_user_stride(struct pipe_context *ctx)
+{
+   struct pipe_screen *screen = ctx->screen;
+   struct pipe_resource *tex =
+      util_create_texture2d(screen, 320, 240, PIPE_FORMAT_R8G8B8A8_UNORM, 1);
+   unsigned stride =
+      screen->get_param(screen, PIPE_CAP_TRANSFER_USER_STRIDE_ALIGNMENT);
+   bool status = true;
+
+   /* Write pixels. Strides are in the ascending order. */
+   for (unsigned i = 0; i < 20; i++) {
+      status = status && test_one_transfer(ctx, tex, 2 + i, 2 + i, i + 1,
+                                           stride * (i + 1), false);
+   }
+   /* Read pixels and compare values. Strides are in the descending order. */
+   for (unsigned i = 0; i < 20; i++) {
+      status = status && test_one_transfer(ctx, tex, 2 + i, 2 + i, i + 1,
+                                           stride * (20 - i), true);
+   }
+
+   pipe_resource_reference(&tex, NULL);
+   util_report_result(status);
+}
+
 /**
  * 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_transfer_user_stride(ctx);
 
    for (int i = 1; i <= 8; i = i * 2)
       test_texture_barrier(ctx, false, i);
    for (int i = 1; i <= 8; i = i * 2)
       test_texture_barrier(ctx, true, i);
 
    ctx->destroy(ctx);
 
    puts("Done. Exiting..");
    exit(0);
-- 
2.17.0



More information about the mesa-dev mailing list