From 8f7010371762dd36bcd018a6b801dac43832b1bc Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Thu, 18 Feb 2021 14:35:13 +0100 Subject: [PATCH] vrend/shader: make cbuf masks 8 bit and move them into fs specific section Mesa clamps the number of cbufs to eight, so we can use uint8_t bitmask for cbufs states. Be save for the future by only reporting support for at most eight cbufs. Signed-off-by: Gert Wollny Reviewed-by: Rohan Garg --- src/vrend_renderer.c | 12 +++++++++--- src/vrend_shader.c | 10 +++++----- src/vrend_shader.h | 8 ++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index af760cd..56cb8df 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -3312,12 +3312,12 @@ static inline void vrend_fill_shader_key(struct vrend_sub_context *sub_ctx, if (!sub_ctx->surf[i]) continue; if (vrend_format_is_emulated_alpha(sub_ctx->surf[i]->format)) - key->cbufs_are_a8_bitmask |= (1 << i); + key->fs.cbufs_are_a8_bitmask |= (1 << i); if (util_format_is_pure_integer(sub_ctx->surf[i]->format)) { add_alpha_test = false; UPDATE_INT_SIGN_MASK(sub_ctx->surf[i]->format, i, - key->cbufs_signed_int_bitmask, - key->cbufs_unsigned_int_bitmask); + key->fs.cbufs_signed_int_bitmask, + key->fs.cbufs_unsigned_int_bitmask); } key->surface_component_bits[i] = util_format_get_component_bits(sub_ctx->surf[i]->format, UTIL_FORMAT_COLORSPACE_RGB, 0); } @@ -6186,6 +6186,12 @@ int vrend_renderer_init(const struct vrend_if_cbs *cbs, uint32_t flags) glGetIntegerv(GL_MAX_DRAW_BUFFERS, (GLint *) &vrend_state.max_draw_buffers); + /* Mesa clamps this value to 8 anyway, so just make sure that this side + * doesn't exceed the number to be on the save side when using 8-bit masks + * for the color buffers */ + if (vrend_state.max_draw_buffers > 8) + vrend_state.max_draw_buffers = 8; + if (!has_feature(feat_arb_robustness) && !has_feature(feat_gles_khr_robustness)) { vrend_printf("WARNING: running without ARB/KHR robustness in place may crash\n"); diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 758732b..810647b 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -1328,8 +1328,8 @@ iter_declaration(struct tgsi_iterate_context *iter, break; case TGSI_SEMANTIC_COLOR: if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) { - ctx->outputs[i].type = get_type(ctx->key->cbufs_signed_int_bitmask, - ctx->key->cbufs_unsigned_int_bitmask, + ctx->outputs[i].type = get_type(ctx->key->fs.cbufs_signed_int_bitmask, + ctx->key->fs.cbufs_unsigned_int_bitmask, ctx->outputs[i].sid); } @@ -2189,7 +2189,7 @@ static void handle_fragment_proc_exit(const struct dump_ctx *ctx, if (ctx->key->pstipple_tex) emit_pstipple_pass(glsl_strbufs); - if (ctx->key->cbufs_are_a8_bitmask) + if (ctx->key->fs.cbufs_are_a8_bitmask) emit_a8_swizzle(glsl_strbufs); if (ctx->key->add_alpha_test) @@ -6389,9 +6389,9 @@ static void emit_ios_fs(const struct dump_ctx *ctx, if (ctx->write_all_cbufs) { const char* type = "vec4"; - if (ctx->key->cbufs_unsigned_int_bitmask) + if (ctx->key->fs.cbufs_unsigned_int_bitmask) type = "uvec4"; - else if (ctx->key->cbufs_signed_int_bitmask) + else if (ctx->key->fs.cbufs_signed_int_bitmask) type = "ivec4"; for (i = 0; i < (uint32_t)ctx->cfg->max_draw_buffers; i++) { diff --git a/src/vrend_shader.h b/src/vrend_shader.h index 6819662..6f86437 100644 --- a/src/vrend_shader.h +++ b/src/vrend_shader.h @@ -138,7 +138,10 @@ struct vrend_shader_key { struct vrend_shader_info_in output; struct { - uint32_t swizzle_output_rgb_to_bgr : 8; + uint8_t swizzle_output_rgb_to_bgr; + uint8_t cbufs_are_a8_bitmask; + uint8_t cbufs_signed_int_bitmask; + uint8_t cbufs_unsigned_int_bitmask; uint32_t logicop_func : 4; uint32_t logicop_enabled : 1; uint32_t prim_is_points : 1; @@ -146,9 +149,6 @@ struct vrend_shader_key { uint32_t coord_replace; } fs; - uint32_t cbufs_are_a8_bitmask; - uint32_t cbufs_signed_int_bitmask; - uint32_t cbufs_unsigned_int_bitmask; uint32_t attrib_signed_int_bitmask; uint32_t attrib_unsigned_int_bitmask; uint32_t compiled_fs_uid;