summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util/u_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/util/u_tests.c')
-rw-r--r--src/gallium/auxiliary/util/u_tests.c109
1 files changed, 89 insertions, 20 deletions
diff --git a/src/gallium/auxiliary/util/u_tests.c b/src/gallium/auxiliary/util/u_tests.c
index 6a67f63e219..61a7836f9f0 100644
--- a/src/gallium/auxiliary/util/u_tests.c
+++ b/src/gallium/auxiliary/util/u_tests.c
@@ -48,7 +48,7 @@ util_create_texture2d(struct pipe_screen *screen, unsigned width,
unsigned height, enum pipe_format format,
unsigned num_samples)
{
- struct pipe_resource templ = {{0}};
+ struct pipe_resource templ = {0};
templ.target = PIPE_TEXTURE_2D;
templ.width0 = width;
@@ -134,8 +134,8 @@ util_set_max_viewport(struct cso_context *cso, struct pipe_resource *tex)
cso_set_viewport(cso, &viewport);
}
-static void
-util_set_interleaved_vertex_elements(struct cso_context *cso,
+static struct cso_velems_state
+util_get_interleaved_vertex_elements(struct cso_context *cso,
unsigned num_elements)
{
struct cso_velems_state velem;
@@ -146,9 +146,10 @@ util_set_interleaved_vertex_elements(struct cso_context *cso,
for (i = 0; i < num_elements; i++) {
velem.velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
velem.velems[i].src_offset = i * 16;
+ velem.velems[i].src_stride = num_elements * 4 * sizeof(float);
}
- cso_set_vertex_elements(cso, &velem);
+ return velem;
}
static void *
@@ -160,7 +161,7 @@ util_set_passthrough_vertex_shader(struct cso_context *cso,
TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_GENERIC
};
- static const uint vs_indices[] = {0, 0};
+ static const unsigned vs_indices[] = {0, 0};
void *vs;
vs = util_make_vertex_passthrough_shader(ctx, 2, vs_attribs, vs_indices,
@@ -193,8 +194,9 @@ util_draw_fullscreen_quad(struct cso_context *cso)
1, 1, 0, 1, 1, 1, 0, 0,
1, -1, 0, 1, 1, 0, 0, 0
};
- util_set_interleaved_vertex_elements(cso, 2);
- util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
+ struct cso_velems_state ve = util_get_interleaved_vertex_elements(cso, 2);
+
+ util_draw_user_vertices(cso, &ve, vertices, MESA_PRIM_QUADS, 4);
}
static void
@@ -207,8 +209,9 @@ util_draw_fullscreen_quad_fill(struct cso_context *cso,
1, 1, 0, 1, r, g, b, a,
1, -1, 0, 1, r, g, b, a,
};
- util_set_interleaved_vertex_elements(cso, 2);
- util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
+ struct cso_velems_state ve = util_get_interleaved_vertex_elements(cso, 2);
+
+ util_draw_user_vertices(cso, &ve, vertices, MESA_PRIM_QUADS, 4);
}
/**
@@ -322,7 +325,7 @@ tgsi_vs_window_space_position(struct pipe_context *ctx)
static const float red[] = {1, 0, 0, 1};
if (!ctx->screen->get_param(ctx->screen,
- PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION)) {
+ PIPE_CAP_VS_WINDOW_SPACE_POSITION)) {
util_report_result(SKIP);
return;
}
@@ -334,7 +337,7 @@ tgsi_vs_window_space_position(struct pipe_context *ctx)
/* Fragment shader. */
fs = util_make_fragment_passthrough_shader(ctx, TGSI_SEMANTIC_GENERIC,
- TGSI_INTERPOLATE_LINEAR, TRUE);
+ TGSI_INTERPOLATE_LINEAR, true);
cso_set_fragment_shader_handle(cso, fs);
/* Vertex shader. */
@@ -348,8 +351,9 @@ tgsi_vs_window_space_position(struct pipe_context *ctx)
256, 256, 0, 0, 1, 0, 0, 1,
256, 0, 0, 0, 1, 0, 0, 1,
};
- util_set_interleaved_vertex_elements(cso, 2);
- util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
+ struct cso_velems_state ve = util_get_interleaved_vertex_elements(cso, 2);
+
+ util_draw_user_vertices(cso, &ve, vertices, MESA_PRIM_QUADS, 4);
}
/* Probe pixels. */
@@ -396,7 +400,6 @@ null_sampler_view(struct pipe_context *ctx, unsigned tgsi_tex_target)
/* Fragment shader. */
fs = util_make_fragment_tex_shader(ctx, tgsi_tex_target,
- TGSI_INTERPOLATE_LINEAR,
TGSI_RETURN_TYPE_FLOAT,
TGSI_RETURN_TYPE_FLOAT, false, false);
cso_set_fragment_shader_handle(cso, fs);
@@ -517,7 +520,7 @@ disabled_fragment_shader(struct pipe_context *ctx)
util_report_result(qresult.u64 == 2);
}
-#if defined(PIPE_OS_LINUX) && defined(HAVE_LIBDRM)
+#if DETECT_OS_LINUX && defined(HAVE_LIBDRM)
#include <libsync.h>
#else
#define sync_merge(str, fd1, fd2) (-1)
@@ -595,7 +598,7 @@ test_sync_file_fences(struct pipe_context *ctx)
pass = pass && screen->fence_finish(screen, NULL, final_fence, 0);
/* Cleanup. */
-#ifndef PIPE_OS_WINDOWS
+#if !DETECT_OS_WINDOWS
if (buf_fd >= 0)
close(buf_fd);
if (tex_fd >= 0)
@@ -654,7 +657,7 @@ test_texture_barrier(struct pipe_context *ctx, bool use_fbfetch,
if (num_samples > 1) {
void *fs =
util_make_fragment_passthrough_shader(ctx, TGSI_SEMANTIC_GENERIC,
- TGSI_INTERPOLATE_LINEAR, TRUE);
+ TGSI_INTERPOLATE_LINEAR, true);
cso_set_fragment_shader_handle(cso, fs);
/* Vertex shader. */
@@ -698,7 +701,7 @@ test_texture_barrier(struct pipe_context *ctx, bool use_fbfetch,
"ADD OUT[0], TEMP[0], IMM[0]\n"
"END\n";
} else {
- struct pipe_sampler_view templ = {{0}};
+ struct pipe_sampler_view templ = {0};
templ.format = cb->format;
templ.target = cb->target;
templ.swizzle_r = PIPE_SWIZZLE_X;
@@ -797,7 +800,7 @@ test_texture_barrier(struct pipe_context *ctx, bool use_fbfetch,
}
static void
-test_compute_clear_image(struct pipe_context *ctx)
+test_compute_clear_image_shader(struct pipe_context *ctx)
{
struct pipe_resource *cb;
const char *text;
@@ -867,6 +870,70 @@ test_compute_clear_image(struct pipe_context *ctx)
util_report_result(pass);
}
+static void
+test_compute_clear_texture(struct pipe_context *ctx)
+{
+ struct pipe_resource *tex;
+
+ tex = util_create_texture2d(ctx->screen, 256, 256,
+ PIPE_FORMAT_R8G8B8A8_UNORM, 1);
+ srand(time(NULL));
+ uint8_t data[] = {rand() % 256, rand() % 256, rand() % 256, rand() % 256};
+ float expected[] = {
+ ubyte_to_float(data[0]),
+ ubyte_to_float(data[1]),
+ ubyte_to_float(data[2]),
+ ubyte_to_float(data[3]),
+ };
+
+ struct pipe_box box;
+ u_box_2d(0, 0, tex->width0, tex->height0, &box);
+ ctx->clear_texture(ctx, tex, 0, &box, &data);
+
+ /* Check pixels. */
+ bool pass = util_probe_rect_rgba(ctx, tex, 0, 0,
+ tex->width0, tex->height0, expected);
+
+ /* Cleanup. */
+ pipe_resource_reference(&tex, NULL);
+
+ util_report_result(pass);
+}
+
+static void
+test_compute_resource_copy_region(struct pipe_context *ctx)
+{
+ struct pipe_resource *src, *dst;
+
+ src = util_create_texture2d(ctx->screen, 256, 256,
+ PIPE_FORMAT_R8G8B8A8_UNORM, 1);
+ dst = util_create_texture2d(ctx->screen, 256, 256,
+ PIPE_FORMAT_R8G8B8A8_UNORM, 1);
+ srand(time(NULL));
+ uint8_t data[] = {rand() % 256, rand() % 256, rand() % 256, rand() % 256};
+ float expected[] = {
+ ubyte_to_float(data[0]),
+ ubyte_to_float(data[1]),
+ ubyte_to_float(data[2]),
+ ubyte_to_float(data[3]),
+ };
+
+ struct pipe_box box;
+ u_box_2d(0, 0, src->width0, src->height0, &box);
+ ctx->clear_texture(ctx, src, 0, &box, &data);
+ ctx->resource_copy_region(ctx, dst, 0, 0, 0, 0, src, 0, &box);
+
+ /* Check pixels. */
+ bool pass = util_probe_rect_rgba(ctx, dst, 0, 0,
+ dst->width0, dst->height0, expected);
+
+ /* Cleanup. */
+ pipe_resource_reference(&src, NULL);
+ pipe_resource_reference(&dst, NULL);
+
+ util_report_result(pass);
+}
+
#define NV12_WIDTH 2560
#define NV12_HEIGHT 1440
@@ -1046,7 +1113,9 @@ util_run_tests(struct pipe_screen *screen)
ctx->destroy(ctx);
ctx = screen->context_create(screen, NULL, PIPE_CONTEXT_COMPUTE_ONLY);
- test_compute_clear_image(ctx);
+ test_compute_clear_image_shader(ctx);
+ test_compute_clear_texture(ctx);
+ test_compute_resource_copy_region(ctx);
ctx->destroy(ctx);
test_nv12(screen);