From 76528644988623b29d145e617090b8516bd4eb69 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Thu, 6 Jun 2019 15:31:45 +0200 Subject: [PATCH] vrend: Correctly handle FakeMSAA textures If nr_samples is 1 we allocate textures as MULTISAMPLE, so we also need to handle the textures in later use as a multisample texture. In addition, on GLES blits to a multisample texture are not allowed as target, and we must use the GL blit fallback for all texture types. v2: Correct more checks including the one in check_resource_valid (Gurchetan) v3: Also update the tests to use only 0 for no samples and >= 1 for samples Signed-off-by: Gert Wollny Reviewed-by: Gurchetan Singh --- src/vrend_blitter.c | 12 ++++++------ src/vrend_renderer.c | 14 +++++++------- tests/test_virgl_resource.c | 26 +++++++++++++------------- tests/test_virgl_transfer.c | 4 ++-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/vrend_blitter.c b/src/vrend_blitter.c index 907a6a0..c2d11ff 100644 --- a/src/vrend_blitter.c +++ b/src/vrend_blitter.c @@ -380,7 +380,7 @@ static GLuint blit_get_frag_tex_writedepth(struct vrend_blitter_ctx *blit_ctx, i { assert(pipe_tex_target < PIPE_MAX_TEXTURE_TYPES); - if (nr_samples > 1) { + if (nr_samples > 0) { GLuint *shader = &blit_ctx->fs_texfetch_depth_msaa[pipe_tex_target]; if (!*shader) { @@ -423,7 +423,7 @@ static GLuint blit_get_frag_tex_col(struct vrend_blitter_ctx *blit_ctx, unsigned tgsi_tex = util_pipe_tex_to_tgsi_tex(pipe_tex_target, nr_samples); enum tgsi_return_type tgsi_ret = tgsi_ret_for_format(src_entry->format); - if (nr_samples > 1) { + if (nr_samples > 0) { // Integer textures are resolved using just one sample int msaa_samples = tgsi_ret == TGSI_RETURN_TYPE_UNORM ? nr_samples : 1; *shader = blit_build_frag_tex_col_msaa(blit_ctx, tgsi_tex, tgsi_ret, @@ -530,7 +530,7 @@ static void get_texcoords(struct vrend_blitter_ctx *blit_ctx, float out[4]) { bool normalized = (src_res->base.target != PIPE_TEXTURE_RECT || blit_ctx->use_gles) && - src_res->base.nr_samples <= 1; + src_res->base.nr_samples < 1; if (normalized) { out[0] = x1 / (float)u_minify(src_res->base.width0, src_level); @@ -822,10 +822,10 @@ void vrend_renderer_blit_gl(struct vrend_context *ctx, /* Just make sure that no stale state disabled decoding */ if (has_texture_srgb_decode && util_format_is_srgb(info->src.format) && - src_res->base.nr_samples < 2) + src_res->base.nr_samples < 1) glTexParameteri(src_res->target, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); - if (src_res->base.nr_samples <= 1) { + if (src_res->base.nr_samples < 1) { glTexParameteri(src_res->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(src_res->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(src_res->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); @@ -834,7 +834,7 @@ void vrend_renderer_blit_gl(struct vrend_context *ctx, glTexParameteri(src_res->target, GL_TEXTURE_BASE_LEVEL, info->src.level); glTexParameteri(src_res->target, GL_TEXTURE_MAX_LEVEL, info->src.level); - if (src_res->base.nr_samples <= 1) { + if (src_res->base.nr_samples < 1) { glTexParameterf(src_res->target, GL_TEXTURE_MAG_FILTER, filter); glTexParameterf(src_res->target, GL_TEXTURE_MIN_FILTER, filter); } diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index af1c86c..7ff95f3 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -5350,7 +5350,7 @@ static void vrend_apply_sampler_state(struct vrend_context *ctx, vrend_printf( "cannot find sampler state for %d %d\n", shader_type, id); return; } - if (res->base.nr_samples > 1) { + if (res->base.nr_samples > 0) { tex->state = *state; return; } @@ -5994,7 +5994,7 @@ static int check_resource_valid(struct vrend_renderer_resource_create_args *args return -1; /* only texture 2d and 2d array can have multiple samples */ - if (args->nr_samples > 1) { + if (args->nr_samples > 0) { if (!has_feature(feat_texture_multisample)) return -1; @@ -7960,7 +7960,7 @@ static void vrend_renderer_blit_int(struct vrend_context *ctx, /* for scaled MS blits we either need extensions or hand roll */ if (info->mask & PIPE_MASK_RGBA && - src_res->base.nr_samples > 1 && + src_res->base.nr_samples > 0 && src_res->base.nr_samples != dst_res->base.nr_samples && (info->src.box.width != info->dst.box.width || info->src.box.height != info->dst.box.height)) { @@ -7991,9 +7991,9 @@ static void vrend_renderer_blit_int(struct vrend_context *ctx, * source and target format are different. For * downsampling DS blits to zero samples we solve this by doing two blits */ if (vrend_state.use_gles && - (info->mask & PIPE_MASK_RGBA) && - (dst_res->base.nr_samples > 1 || - (src_res->base.nr_samples > 1 && + ((dst_res->base.nr_samples > 0) || + ((info->mask & PIPE_MASK_RGBA) && + (src_res->base.nr_samples > 0) && (info->src.box.x != info->dst.box.x || info->src.box.width != info->dst.box.width || dst_y1 != src_y1 || dst_y2 != src_y2 || @@ -8065,7 +8065,7 @@ static void vrend_renderer_blit_int(struct vrend_context *ctx, */ if (vrend_state.use_gles && (info->mask & PIPE_MASK_ZS) && - ((src_res->base.nr_samples > 1) && + ((src_res->base.nr_samples > 0) && (src_res->base.nr_samples != dst_res->base.nr_samples)) && ((info->src.box.x != info->dst.box.x) || (src_y1 != dst_y1) || diff --git a/tests/test_virgl_resource.c b/tests/test_virgl_resource.c index 77a5106..050185f 100644 --- a/tests/test_virgl_resource.c +++ b/tests/test_virgl_resource.c @@ -150,7 +150,7 @@ static struct res_test testlist[] = { /* 1D texture with samples - FAIL */ TEST(1, PIPE_TEXTURE_1D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, EINVAL), /* 1D texture with miplevels - PASS */ - TEST_MIP(1, PIPE_TEXTURE_1D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 1, 4, 0), + TEST_MIP(1, PIPE_TEXTURE_1D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 4, 0), /* 1D array texture - PASS */ TEST(1, PIPE_TEXTURE_1D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 0), @@ -163,7 +163,7 @@ static struct res_test testlist[] = { /* 1D texture with samples - FAIL */ TEST(1, PIPE_TEXTURE_1D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, EINVAL), /* 1D array texture with miplevels - PASS */ - TEST_MIP(1, PIPE_TEXTURE_1D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 1, 4, 0), + TEST_MIP(1, PIPE_TEXTURE_1D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 4, 0), /* 2D texture - PASS */ TEST(1, PIPE_TEXTURE_2D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 0), @@ -177,7 +177,7 @@ static struct res_test testlist[] = { /* 2D texture with samples - PASS */ TEST(1, PIPE_TEXTURE_2D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, 0), /* 2D texture with miplevels - PASS */ - TEST_MIP(1, PIPE_TEXTURE_2D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 1, 4, 0), + TEST_MIP(1, PIPE_TEXTURE_2D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 4, 0), /* 2D texture with samples and miplevels - FAIL */ TEST_MIP(1, PIPE_TEXTURE_2D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, 4, EINVAL), @@ -192,7 +192,7 @@ static struct res_test testlist[] = { /* RECT texture with samples - FAIL */ TEST(1, PIPE_TEXTURE_RECT, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, EINVAL), /* RECT texture with miplevels - FAIL */ - TEST_MIP(1, PIPE_TEXTURE_RECT, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 1, 4, EINVAL), + TEST_MIP(1, PIPE_TEXTURE_RECT, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 4, EINVAL), /* 2D texture array - PASS */ TEST(1, PIPE_TEXTURE_2D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 0), @@ -205,7 +205,7 @@ static struct res_test testlist[] = { /* 2D texture with samples - PASS */ TEST(1, PIPE_TEXTURE_2D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, 0), /* 2D texture with miplevels - PASS */ - TEST_MIP(1, PIPE_TEXTURE_2D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 1, 4, 0), + TEST_MIP(1, PIPE_TEXTURE_2D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 4, 0), /* 2D texture with samplesmiplevels - FAIL */ TEST_MIP(1, PIPE_TEXTURE_2D_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, 4, EINVAL), @@ -220,7 +220,7 @@ static struct res_test testlist[] = { /* 3D texture with samples - FAIL */ TEST(1, PIPE_TEXTURE_3D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 4, EINVAL), /* 3D texture with miplevels - PASS */ - TEST_MIP(1, PIPE_TEXTURE_3D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 1, 4, 0), + TEST_MIP(1, PIPE_TEXTURE_3D, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 1, 0, 4, 0), /* CUBE texture with array size == 6 - PASS */ TEST(1, PIPE_TEXTURE_CUBE, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 6, 0, 0), @@ -233,25 +233,25 @@ static struct res_test testlist[] = { /* CUBE texture with samples - FAIL */ TEST(1, PIPE_TEXTURE_CUBE, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 6, 4, EINVAL), /* CUBE texture with miplevels - PASS */ - TEST_MIP(1, PIPE_TEXTURE_CUBE, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 6, 1, 4, 0), + TEST_MIP(1, PIPE_TEXTURE_CUBE, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 6, 0, 4, 0), }; /* separate since these may fail on a GL that doesn't support cube map arrays */ static struct res_test cubemaparray_testlist[] = { /* CUBE array with array size = 6 - PASS */ - TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 6, 1, 0), + TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 6, 0, 0), /* CUBE array with array size = 12 - PASS */ - TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 12, 1, 0), + TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 12, 0, 0), /* CUBE array with array size = 10 - FAIL */ - TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 10, 1, EINVAL), + TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 1, 1, 10, 0, EINVAL), /* CUBE array with array size = 12 and height - PASS */ - TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 50, 1, 12, 1, 0), + TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 50, 1, 12, 0, 0), /* CUBE array with array size = 12 and depth - FAIL */ - TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 50, 5, 12, 1, EINVAL), + TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 50, 5, 12, 0, EINVAL), /* CUBE array with array size = 12 and samples - FAIL */ TEST(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 50, 1, 12, 4, EINVAL), /* CUBE array with array size = 12 and miplevels - PASS */ - TEST_MIP(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 50, 1, 12, 1, 4, 0), + TEST_MIP(1, PIPE_TEXTURE_CUBE_ARRAY, PIPE_FORMAT_B8G8R8X8_UNORM, PIPE_BIND_SAMPLER_VIEW, 50, 50, 1, 12, 0, 4, 0), }; START_TEST(virgl_res_tests) diff --git a/tests/test_virgl_transfer.c b/tests/test_virgl_transfer.c index 55a1da7..05bca2e 100644 --- a/tests/test_virgl_transfer.c +++ b/tests/test_virgl_transfer.c @@ -614,7 +614,7 @@ static void virgl_test_transfer_res(enum pipe_texture_target target, int ret; int size; - get_resource_args(target, invalid, &res, &box, 1, 0); + get_resource_args(target, invalid, &res, &box, 0, 0); size = get_box_size(&box, target == PIPE_BUFFER ? 1 : 4); data = calloc(1, size); @@ -677,7 +677,7 @@ static void virgl_test_transfer_inline(enum pipe_texture_target target, ret = testvirgl_init_ctx_cmdbuf(&ctx); ck_assert_int_eq(ret, 0); - get_resource_args(target, invalid, &args, &box, 1, large_flags); + get_resource_args(target, invalid, &args, &box, 0, large_flags); size = get_box_size(&box, elsize); data = calloc(1, size);