mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-09 04:38:03 +02:00
gallium/u_tests: test a NULL texture sampler view
v2: allow one of the two values
This commit is contained in:
parent
63e51baedc
commit
9e8a6d8486
1 changed files with 84 additions and 16 deletions
|
|
@ -184,15 +184,24 @@ util_draw_fullscreen_quad(struct cso_context *cso)
|
||||||
util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
|
util_draw_user_vertex_buffer(cso, vertices, PIPE_PRIM_QUADS, 4, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Probe and test if the rectangle contains the expected color.
|
||||||
|
*
|
||||||
|
* If "num_expected_colors" > 1, at least one expected color must match
|
||||||
|
* the probed color. "expected" should be an array of 4*num_expected_colors
|
||||||
|
* floats.
|
||||||
|
*/
|
||||||
static bool
|
static bool
|
||||||
util_probe_rect_rgba(struct pipe_context *ctx, struct pipe_resource *tex,
|
util_probe_rect_rgba_multi(struct pipe_context *ctx, struct pipe_resource *tex,
|
||||||
unsigned offx, unsigned offy, unsigned w, unsigned h,
|
unsigned offx, unsigned offy, unsigned w,
|
||||||
const float *expected)
|
unsigned h,
|
||||||
|
const float *expected,
|
||||||
|
unsigned num_expected_colors)
|
||||||
{
|
{
|
||||||
struct pipe_transfer *transfer;
|
struct pipe_transfer *transfer;
|
||||||
void *map;
|
void *map;
|
||||||
float *pixels = malloc(w * h * 4 * sizeof(float));
|
float *pixels = malloc(w * h * 4 * sizeof(float));
|
||||||
int x,y,c;
|
int x,y,e,c;
|
||||||
bool pass = true;
|
bool pass = true;
|
||||||
|
|
||||||
map = pipe_transfer_map(ctx, tex, 0, 0, PIPE_TRANSFER_READ,
|
map = pipe_transfer_map(ctx, tex, 0, 0, PIPE_TRANSFER_READ,
|
||||||
|
|
@ -200,21 +209,31 @@ util_probe_rect_rgba(struct pipe_context *ctx, struct pipe_resource *tex,
|
||||||
pipe_get_tile_rgba(transfer, map, 0, 0, w, h, pixels);
|
pipe_get_tile_rgba(transfer, map, 0, 0, w, h, pixels);
|
||||||
pipe_transfer_unmap(ctx, transfer);
|
pipe_transfer_unmap(ctx, transfer);
|
||||||
|
|
||||||
for (y = 0; y < h; y++) {
|
for (e = 0; e < num_expected_colors; e++) {
|
||||||
for (x = 0; x < w; x++) {
|
for (y = 0; y < h; y++) {
|
||||||
float *probe = &pixels[(y*w + x)*4];
|
for (x = 0; x < w; x++) {
|
||||||
|
float *probe = &pixels[(y*w + x)*4];
|
||||||
|
|
||||||
for (c = 0; c < 4; c++)
|
for (c = 0; c < 4; c++) {
|
||||||
if (fabs(probe[c] - expected[c]) >= TOLERANCE) {
|
if (fabs(probe[c] - expected[e*4+c]) >= TOLERANCE) {
|
||||||
printf("Probe color at (%i,%i), ", offx+x, offy+y);
|
if (e < num_expected_colors-1)
|
||||||
printf("Expected: %.3f, %.3f, %.3f, %.3f, ",
|
goto next_color; /* test the next expected color */
|
||||||
expected[0], expected[1], expected[2], expected[3]);
|
|
||||||
printf("Got: %.3f, %.3f, %.3f, %.3f\n",
|
printf("Probe color at (%i,%i), ", offx+x, offy+y);
|
||||||
probe[0], probe[1], probe[2], probe[2]);
|
printf("Expected: %.3f, %.3f, %.3f, %.3f, ",
|
||||||
pass = false;
|
expected[e*4], expected[e*4+1],
|
||||||
goto done;
|
expected[e*4+2], expected[e*4+3]);
|
||||||
|
printf("Got: %.3f, %.3f, %.3f, %.3f\n",
|
||||||
|
probe[0], probe[1], probe[2], probe[2]);
|
||||||
|
pass = false;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
break; /* this color was successful */
|
||||||
|
|
||||||
|
next_color:;
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
|
|
||||||
|
|
@ -222,6 +241,14 @@ done:
|
||||||
return pass;
|
return pass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
util_probe_rect_rgba(struct pipe_context *ctx, struct pipe_resource *tex,
|
||||||
|
unsigned offx, unsigned offy, unsigned w, unsigned h,
|
||||||
|
const float *expected)
|
||||||
|
{
|
||||||
|
return util_probe_rect_rgba_multi(ctx, tex, offx, offy, w, h, expected, 1);
|
||||||
|
}
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SKIP = -1,
|
SKIP = -1,
|
||||||
FAIL = 0, /* also "false" */
|
FAIL = 0, /* also "false" */
|
||||||
|
|
@ -304,6 +331,46 @@ tgsi_vs_window_space_position(struct pipe_context *ctx)
|
||||||
util_report_result(pass);
|
util_report_result(pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
null_sampler_view(struct pipe_context *ctx)
|
||||||
|
{
|
||||||
|
struct cso_context *cso;
|
||||||
|
struct pipe_resource *cb;
|
||||||
|
void *fs, *vs;
|
||||||
|
bool pass = true;
|
||||||
|
/* 2 expected colors: */
|
||||||
|
static const float expected[] = {0, 0, 0, 1,
|
||||||
|
0, 0, 0, 0};
|
||||||
|
|
||||||
|
cso = cso_create_context(ctx);
|
||||||
|
cb = util_create_texture2d(ctx->screen, 256, 256,
|
||||||
|
PIPE_FORMAT_R8G8B8A8_UNORM);
|
||||||
|
util_set_common_states_and_clear(cso, ctx, cb);
|
||||||
|
|
||||||
|
ctx->set_sampler_views(ctx, PIPE_SHADER_FRAGMENT, 0, 1, NULL);
|
||||||
|
|
||||||
|
/* Fragment shader. */
|
||||||
|
fs = util_make_fragment_tex_shader(ctx, TGSI_TEXTURE_2D,
|
||||||
|
TGSI_INTERPOLATE_LINEAR);
|
||||||
|
cso_set_fragment_shader_handle(cso, fs);
|
||||||
|
|
||||||
|
/* Vertex shader. */
|
||||||
|
vs = util_set_passthrough_vertex_shader(cso, ctx, false);
|
||||||
|
util_draw_fullscreen_quad(cso);
|
||||||
|
|
||||||
|
/* Probe pixels. */
|
||||||
|
pass = pass && util_probe_rect_rgba_multi(ctx, cb, 0, 0,
|
||||||
|
cb->width0, cb->height0, expected, 2);
|
||||||
|
|
||||||
|
/* Cleanup. */
|
||||||
|
cso_destroy_context(cso);
|
||||||
|
ctx->delete_vs_state(ctx, vs);
|
||||||
|
ctx->delete_fs_state(ctx, fs);
|
||||||
|
pipe_resource_reference(&cb, NULL);
|
||||||
|
|
||||||
|
util_report_result(pass);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run all tests. This should be run with a clean context after
|
* Run all tests. This should be run with a clean context after
|
||||||
* context_create.
|
* context_create.
|
||||||
|
|
@ -314,6 +381,7 @@ util_run_tests(struct pipe_screen *screen)
|
||||||
struct pipe_context *ctx = screen->context_create(screen, NULL);
|
struct pipe_context *ctx = screen->context_create(screen, NULL);
|
||||||
|
|
||||||
tgsi_vs_window_space_position(ctx);
|
tgsi_vs_window_space_position(ctx);
|
||||||
|
null_sampler_view(ctx);
|
||||||
|
|
||||||
ctx->destroy(ctx);
|
ctx->destroy(ctx);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue