From 0f6af022225114c1d25bce6156f72cc812d27959 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Thu, 18 Feb 2021 10:15:44 +0100 Subject: [PATCH] shader: move FS specific key values into sub-structure Signed-off-by: Gert Wollny Reviewed-by: Rohan Garg --- src/vrend_renderer.c | 14 +++++++------- src/vrend_shader.c | 32 ++++++++++++++++---------------- src/vrend_shader.h | 16 ++++++++++------ 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index d25bd2b..3196eb2 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -3336,7 +3336,7 @@ static inline void vrend_fill_shader_key(struct vrend_sub_context *sub_ctx, key->flatshade = sub_ctx->rs_state.flatshade ? true : false; } - key->invert_fs_origin = !sub_ctx->inverted_fbo_content; + key->fs.invert_origin = !sub_ctx->inverted_fbo_content; key->gs_present = !!sub_ctx->shaders[PIPE_SHADER_GEOMETRY]; key->tcs_present = !!sub_ctx->shaders[PIPE_SHADER_TESS_CTRL]; @@ -3382,10 +3382,10 @@ static inline void vrend_fill_shader_key(struct vrend_sub_context *sub_ctx, int next_type = -1; if (type == PIPE_SHADER_FRAGMENT) { - key->fs_swizzle_output_rgb_to_bgr = sub_ctx->swizzle_output_rgb_to_bgr; + key->fs.swizzle_output_rgb_to_bgr = sub_ctx->swizzle_output_rgb_to_bgr; if (vrend_state.use_gles && can_emulate_logicop(sub_ctx->blend_state.logicop_func)) { - key->fs_logicop_enabled = sub_ctx->blend_state.logicop_enable; - key->fs_logicop_func = sub_ctx->blend_state.logicop_func; + key->fs.logicop_enabled = sub_ctx->blend_state.logicop_enable; + key->fs.logicop_func = sub_ctx->blend_state.logicop_func; } int fs_prim_mode = sub_ctx->prim_mode; // inherit draw-call's mode @@ -3399,9 +3399,9 @@ static inline void vrend_fill_shader_key(struct vrend_sub_context *sub_ctx, fs_prim_mode = sub_ctx->shaders[PIPE_SHADER_GEOMETRY]->sinfo.gs_out_prim; break; } - key->fs_prim_is_points = (fs_prim_mode == PIPE_PRIM_POINTS); - key->fs_coord_replace = sub_ctx->rs_state.point_quad_rasterization - && key->fs_prim_is_points + key->fs.prim_is_points = (fs_prim_mode == PIPE_PRIM_POINTS); + key->fs.coord_replace = sub_ctx->rs_state.point_quad_rasterization + && key->fs.prim_is_points ? sub_ctx->rs_state.sprite_coord_enable : 0x0; } else { diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 731766b..758732b 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -533,7 +533,7 @@ static inline bool fs_emit_layout(const struct dump_ctx *ctx) if coord_origin is 0 and invert is 1 - emit nothing (lower) if coord origin is 1 and invert is 0 - emit nothing (lower) if coord_origin is 1 and invert is 1 - emit origin upper left */ - if (!(ctx->fs_coord_origin ^ ctx->key->invert_fs_origin)) + if (!(ctx->fs_coord_origin ^ ctx->key->fs.invert_origin)) return true; return false; } @@ -919,10 +919,10 @@ iter_inputs(struct tgsi_iterate_context *iter, static bool logiop_require_inout(const struct vrend_shader_key *key) { - if (!key->fs_logicop_enabled) + if (!key->fs.logicop_enabled) return false; - switch (key->fs_logicop_func) { + switch (key->fs.logicop_func) { case PIPE_LOGICOP_CLEAR: case PIPE_LOGICOP_SET: case PIPE_LOGICOP_COPY: @@ -1171,7 +1171,7 @@ iter_declaration(struct tgsi_iterate_context *iter, case TGSI_SEMANTIC_PATCH: case TGSI_SEMANTIC_GENERIC: if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) { - if (ctx->key->fs_coord_replace & (1 << ctx->inputs[i].sid)) { + if (ctx->key->fs.coord_replace & (1 << ctx->inputs[i].sid)) { if (ctx->cfg->use_gles) name_prefix = "vec4(gl_PointCoord.x, mix(1.0 - gl_PointCoord.y, gl_PointCoord.y, clamp(winsys_adjust_y, 0.0, 1.0)), 0.0, 1.0)"; else @@ -1344,7 +1344,7 @@ iter_declaration(struct tgsi_iterate_context *iter, name_prefix = "ex"; break; } else if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT && - ctx->key->fs_logicop_enabled) { + ctx->key->fs.logicop_enabled) { name_prefix = "fsout_tmp"; break; } @@ -2060,7 +2060,7 @@ static void emit_fragment_logicop(const struct dump_ctx *ctx, for (unsigned i = 0; i < ctx->num_outputs; i++) { mask[i] = (1 << ctx->key->surface_component_bits[i]) - 1; scale[i] = mask[i]; - switch (ctx->key->fs_logicop_func) { + switch (ctx->key->fs.logicop_func) { case PIPE_LOGICOP_INVERT: snprintf(src_fb[i], ARRAY_SIZE(src_fb[i]), "ivec4(%f * fsout_c%d + 0.5)", scale[i], i); @@ -2091,7 +2091,7 @@ static void emit_fragment_logicop(const struct dump_ctx *ctx, } for (unsigned i = 0; i < ctx->num_outputs; i++) { - switch (ctx->key->fs_logicop_func) { + switch (ctx->key->fs.logicop_func) { case PIPE_LOGICOP_CLEAR: snprintf(full_op[i], ARRAY_SIZE(full_op[i]), "%s", "vec4(0)"); @@ -2159,7 +2159,7 @@ static void emit_fragment_logicop(const struct dump_ctx *ctx, } for (unsigned i = 0; i < ctx->num_outputs; i++) { - switch (ctx->key->fs_logicop_func) { + switch (ctx->key->fs.logicop_func) { case PIPE_LOGICOP_NOOP: break; case PIPE_LOGICOP_COPY: @@ -2177,7 +2177,7 @@ static void emit_cbuf_swizzle(const struct dump_ctx *ctx, struct vrend_glsl_strbufs *glsl_strbufs) { for (uint i = 0; i < ctx->num_outputs; i++) { - if (ctx->key->fs_swizzle_output_rgb_to_bgr & (1 << i)) { + if (ctx->key->fs.swizzle_output_rgb_to_bgr & (1 << i)) { emit_buff(glsl_strbufs, "fsout_c%d = fsout_c%d.zyxw;\n", i, i); } } @@ -2196,10 +2196,10 @@ static void handle_fragment_proc_exit(const struct dump_ctx *ctx, emit_alpha_test(ctx, glsl_strbufs); - if (ctx->key->fs_logicop_enabled) + if (ctx->key->fs.logicop_enabled) emit_fragment_logicop(ctx, glsl_strbufs); - if (ctx->key->fs_swizzle_output_rgb_to_bgr) + if (ctx->key->fs.swizzle_output_rgb_to_bgr) emit_cbuf_swizzle(ctx, glsl_strbufs); if (ctx->write_all_cbufs) @@ -4763,7 +4763,7 @@ static void handle_io_arrays(struct dump_ctx *ctx) if (ctx->num_inputs > 0) if (evaluate_layout_overlays(ctx->num_inputs, ctx->inputs, get_stage_input_name_prefix(ctx, ctx->prog_type), - ctx->key->fs_coord_replace)) { + ctx->key->fs.coord_replace)) { require_enhanced_layouts = true; } @@ -4779,7 +4779,7 @@ static void handle_io_arrays(struct dump_ctx *ctx) rewrite_io_ranged(ctx); rewrite_components(ctx->num_inputs, ctx->inputs, get_stage_input_name_prefix(ctx, ctx->prog_type), - ctx->key->fs_coord_replace, true); + ctx->key->fs.coord_replace, true); rewrite_components(ctx->num_outputs, ctx->outputs, get_stage_output_name_prefix(ctx->prog_type), 0, true); @@ -6328,7 +6328,7 @@ static void emit_ios_fs(const struct dump_ctx *ctx, uint32_t i; if (fs_emit_layout(ctx)) { - bool upper_left = !(ctx->fs_coord_origin ^ ctx->key->invert_fs_origin); + bool upper_left = !(ctx->fs_coord_origin ^ ctx->key->fs.invert_origin); char comma = (upper_left && ctx->fs_pixel_center) ? ',' : ' '; if (!ctx->cfg->use_gles) @@ -6364,7 +6364,7 @@ static void emit_ios_fs(const struct dump_ctx *ctx, } if (ctx->cfg->use_gles && !ctx->winsys_adjust_y_emitted && - (ctx->key->fs_coord_replace & (1 << ctx->inputs[i].sid))) { + (ctx->key->fs.coord_replace & (1 << ctx->inputs[i].sid))) { *winsys_adjust_y_emitted = true; emit_hdr(glsl_strbufs, "uniform float winsys_adjust_y;\n"); } @@ -6396,7 +6396,7 @@ static void emit_ios_fs(const struct dump_ctx *ctx, for (i = 0; i < (uint32_t)ctx->cfg->max_draw_buffers; i++) { if (ctx->cfg->use_gles) { - if (ctx->key->fs_logicop_enabled) + if (ctx->key->fs.logicop_enabled) emit_hdrf(glsl_strbufs, "%s fsout_tmp_c%d;\n", type, i); if (logiop_require_inout(ctx->key)) { diff --git a/src/vrend_shader.h b/src/vrend_shader.h index b26ed31..6819662 100644 --- a/src/vrend_shader.h +++ b/src/vrend_shader.h @@ -137,7 +137,15 @@ struct vrend_shader_key { struct vrend_shader_info_out input; struct vrend_shader_info_in output; - uint32_t fs_coord_replace; + struct { + uint32_t swizzle_output_rgb_to_bgr : 8; + uint32_t logicop_func : 4; + uint32_t logicop_enabled : 1; + uint32_t prim_is_points : 1; + uint32_t invert_origin : 1; + uint32_t coord_replace; + } fs; + uint32_t cbufs_are_a8_bitmask; uint32_t cbufs_signed_int_bitmask; uint32_t cbufs_unsigned_int_bitmask; @@ -145,8 +153,6 @@ struct vrend_shader_key { uint32_t attrib_unsigned_int_bitmask; uint32_t compiled_fs_uid; - uint32_t fs_prim_is_points : 1; - uint32_t invert_fs_origin : 1; uint32_t pstipple_tex : 1; uint32_t add_alpha_test : 1; uint32_t color_two_side : 1; @@ -154,12 +160,10 @@ struct vrend_shader_key { uint32_t tcs_present : 1; uint32_t tes_present : 1; uint32_t flatshade : 1; - uint32_t fs_logicop_enabled : 1; - uint32_t fs_logicop_func : 4; uint8_t alpha_test; uint8_t clip_plane_enable; - uint8_t fs_swizzle_output_rgb_to_bgr; + uint8_t surface_component_bits[PIPE_MAX_COLOR_BUFS]; struct vrend_layout_info prev_stage_generic_and_patch_outputs_layout[64]; };