diff options
author | Marek Olšák <[email protected]> | 2017-10-05 04:02:05 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2017-10-07 18:26:35 +0200 |
commit | 0a3b5a0232cef1598ff0417e588a2d32e81d4f6a (patch) | |
tree | 22cbff599fedf33b6a93de7d00038972220934d9 /src/gallium/auxiliary/util/u_blitter.c | |
parent | a46bcf0a771575ce68e0a0585a84ca6029b96b4e (diff) |
gallium/u_blitter: let drivers decide which VS to use for draw_rectangle
This approach allows drivers to set their own vertex shader and skip
compilation of u_blitter vertex shaders.
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util/u_blitter.c')
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.c | 91 |
1 files changed, 50 insertions, 41 deletions
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index ec03e5f7d12..47042e4e826 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -350,8 +350,9 @@ static void bind_vs_pos_only(struct blitter_context_priv *ctx, pipe->bind_vs_state(pipe, ctx->vs_pos_only[index]); } -static void bind_vs_passthrough_pos_generic(struct blitter_context_priv *ctx) +static void *get_vs_passthrough_pos_generic(struct blitter_context *blitter) { + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_context *pipe = ctx->base.pipe; if (!ctx->vs) { @@ -362,12 +363,12 @@ static void bind_vs_passthrough_pos_generic(struct blitter_context_priv *ctx) util_make_vertex_passthrough_shader(pipe, 2, semantic_names, semantic_indices, false); } - - pipe->bind_vs_state(pipe, ctx->vs); + return ctx->vs; } -static void bind_vs_passthrough_pos(struct blitter_context_priv *ctx) +static void *get_vs_passthrough_pos(struct blitter_context *blitter) { + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_context *pipe = ctx->base.pipe; if (!ctx->vs_nogeneric) { @@ -379,19 +380,18 @@ static void bind_vs_passthrough_pos(struct blitter_context_priv *ctx) semantic_names, semantic_indices, false); } - - pipe->bind_vs_state(pipe, ctx->vs_nogeneric); + return ctx->vs_nogeneric; } -static void bind_vs_layered(struct blitter_context_priv *ctx) +static void *get_vs_layered(struct blitter_context *blitter) { + struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter; struct pipe_context *pipe = ctx->base.pipe; if (!ctx->vs_layered) { ctx->vs_layered = util_make_layered_clear_vertex_shader(pipe); } - - pipe->bind_vs_state(pipe, ctx->vs_layered); + return ctx->vs_layered; } static void bind_fs_empty(struct blitter_context_priv *ctx) @@ -1211,21 +1211,12 @@ void util_blitter_cache_all_shaders(struct blitter_context *blitter) } static void blitter_set_common_draw_rect_state(struct blitter_context_priv *ctx, - bool scissor, - bool vs_layered, - bool vs_pass_generic) + bool scissor) { struct pipe_context *pipe = ctx->base.pipe; pipe->bind_rasterizer_state(pipe, scissor ? ctx->rs_state_scissor : ctx->rs_state); - if (vs_layered) - bind_vs_layered(ctx); - else if (vs_pass_generic) - bind_vs_passthrough_pos_generic(ctx); - else - bind_vs_passthrough_pos(ctx); - if (ctx->has_geometry_shader) pipe->bind_gs_state(pipe, NULL); if (ctx->has_tessellation) { @@ -1238,6 +1229,7 @@ static void blitter_set_common_draw_rect_state(struct blitter_context_priv *ctx, static void blitter_draw(struct blitter_context_priv *ctx, void *vertex_elements_cso, + blitter_get_vs_func get_vs, int x1, int y1, int x2, int y2, float depth, unsigned num_instances) { @@ -1256,6 +1248,7 @@ static void blitter_draw(struct blitter_context_priv *ctx, pipe->set_vertex_buffers(pipe, ctx->base.vb_slot, 1, &vb); pipe->bind_vertex_elements_state(pipe, vertex_elements_cso); + pipe->bind_vs_state(pipe, get_vs(&ctx->base)); util_draw_arrays_instanced(pipe, PIPE_PRIM_TRIANGLE_FAN, 0, 4, 0, num_instances); pipe_resource_reference(&vb.buffer.resource, NULL); @@ -1263,6 +1256,7 @@ static void blitter_draw(struct blitter_context_priv *ctx, void util_blitter_draw_rectangle(struct blitter_context *blitter, void *vertex_elements_cso, + blitter_get_vs_func get_vs, int x1, int y1, int x2, int y2, float depth, unsigned num_instances, enum blitter_attrib_type type, @@ -1289,7 +1283,8 @@ void util_blitter_draw_rectangle(struct blitter_context *blitter, default:; } - blitter_draw(ctx, vertex_elements_cso, x1, y1, x2, y2, depth, num_instances); + blitter_draw(ctx, vertex_elements_cso, get_vs, x1, y1, x2, y2, depth, + num_instances); } static void *get_clear_blend_state(struct blitter_context_priv *ctx, @@ -1393,12 +1388,23 @@ static void util_blitter_clear_custom(struct blitter_context *blitter, UTIL_BLITTER_ATTRIB_NONE; if (num_layers > 1 && ctx->has_layered) { - blitter_set_common_draw_rect_state(ctx, false, true, pass_generic); - blitter->draw_rectangle(blitter, ctx->velem_state, 0, 0, width, height, + blitter_get_vs_func get_vs = get_vs_layered; + + blitter_set_common_draw_rect_state(ctx, false); + blitter->draw_rectangle(blitter, ctx->velem_state, get_vs, + 0, 0, width, height, (float) depth, num_layers, type, &attrib); } else { - blitter_set_common_draw_rect_state(ctx, false, false, pass_generic); - blitter->draw_rectangle(blitter, ctx->velem_state, 0, 0, width, height, + blitter_get_vs_func get_vs; + + if (pass_generic) + get_vs = get_vs_passthrough_pos_generic; + else + get_vs = get_vs_passthrough_pos; + + blitter_set_common_draw_rect_state(ctx, false); + blitter->draw_rectangle(blitter, ctx->velem_state, get_vs, + 0, 0, width, height, (float) depth, 1, type, &attrib); } @@ -1612,6 +1618,7 @@ blitter_draw_tex(struct blitter_context_priv *ctx, bool uses_txf, enum blitter_attrib_type type) { union blitter_attrib coord; + blitter_get_vs_func get_vs = get_vs_passthrough_pos_generic; get_texcoords(src, src_width0, src_height0, src_x1, src_y1, src_x2, src_y2, layer, sample, @@ -1631,10 +1638,10 @@ blitter_draw_tex(struct blitter_context_priv *ctx, ctx->vertices[i][1][3] = coord.texcoord.w; /* Cubemaps don't use draw_rectangle. */ - blitter_draw(ctx, ctx->velem_state, + blitter_draw(ctx, ctx->velem_state, get_vs, dst_x1, dst_y1, dst_x2, dst_y2, 0, 1); } else { - ctx->base.draw_rectangle(&ctx->base, ctx->velem_state, + ctx->base.draw_rectangle(&ctx->base, ctx->velem_state, get_vs, dst_x1, dst_y1, dst_x2, dst_y2, 0, 1, type, &coord); } @@ -1946,7 +1953,7 @@ void util_blitter_blit_generic(struct blitter_context *blitter, pipe->set_scissor_states(pipe, 0, 1, scissor); } - blitter_set_common_draw_rect_state(ctx, scissor != NULL, false, true); + blitter_set_common_draw_rect_state(ctx, scissor != NULL); do_blits(ctx, dst, dstbox, src, src_width0, src_height0, srcbox, blit_depth || blit_stencil, use_txf); @@ -2052,7 +2059,7 @@ void util_blitter_generate_mipmap(struct blitter_context *blitter, pipe->bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT, 0, 1, &sampler_state); - blitter_set_common_draw_rect_state(ctx, false, false, true); + blitter_set_common_draw_rect_state(ctx, false); for (src_level = base_level; src_level < last_level; src_level++) { struct pipe_box dstbox = {0}, srcbox = {0}; @@ -2144,13 +2151,14 @@ void util_blitter_clear_render_target(struct blitter_context *blitter, num_layers = dstsurf->u.tex.last_layer - dstsurf->u.tex.first_layer + 1; if (num_layers > 1 && ctx->has_layered) { - blitter_set_common_draw_rect_state(ctx, false, true, true); - blitter->draw_rectangle(blitter, ctx->velem_state, + blitter_set_common_draw_rect_state(ctx, false); + blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_layered, dstx, dsty, dstx+width, dsty+height, 0, num_layers, UTIL_BLITTER_ATTRIB_COLOR, &attrib); } else { - blitter_set_common_draw_rect_state(ctx, false, false, true); + blitter_set_common_draw_rect_state(ctx, false); blitter->draw_rectangle(blitter, ctx->velem_state, + get_vs_passthrough_pos_generic, dstx, dsty, dstx+width, dsty+height, 0, 1, UTIL_BLITTER_ATTRIB_COLOR, &attrib); } @@ -2222,13 +2230,14 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter, num_layers = dstsurf->u.tex.last_layer - dstsurf->u.tex.first_layer + 1; if (num_layers > 1 && ctx->has_layered) { - blitter_set_common_draw_rect_state(ctx, false, true, false); - blitter->draw_rectangle(blitter, ctx->velem_state, + blitter_set_common_draw_rect_state(ctx, false); + blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_layered, dstx, dsty, dstx+width, dsty+height, depth, num_layers, UTIL_BLITTER_ATTRIB_NONE, NULL); } else { - blitter_set_common_draw_rect_state(ctx, false, false, false); + blitter_set_common_draw_rect_state(ctx, false); blitter->draw_rectangle(blitter, ctx->velem_state, + get_vs_passthrough_pos, dstx, dsty, dstx+width, dsty+height, depth, 1, UTIL_BLITTER_ATTRIB_NONE, NULL); } @@ -2286,10 +2295,10 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter, pipe->set_framebuffer_state(pipe, &fb_state); pipe->set_sample_mask(pipe, sample_mask); - blitter_set_common_draw_rect_state(ctx, false, false, false); + blitter_set_common_draw_rect_state(ctx, false); blitter_set_dst_dimensions(ctx, zsurf->width, zsurf->height); - blitter->draw_rectangle(blitter, ctx->velem_state, 0, 0, - zsurf->width, zsurf->height, depth, + blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_passthrough_pos, + 0, 0, zsurf->width, zsurf->height, depth, 1, UTIL_BLITTER_ATTRIB_NONE, NULL); util_blitter_restore_vertex_states(blitter); @@ -2486,9 +2495,9 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter, fb_state.zsbuf = NULL; pipe->set_framebuffer_state(pipe, &fb_state); - blitter_set_common_draw_rect_state(ctx, false, false, false); + blitter_set_common_draw_rect_state(ctx, false); blitter_set_dst_dimensions(ctx, src->width0, src->height0); - blitter->draw_rectangle(blitter, ctx->velem_state, + blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_passthrough_pos, 0, 0, src->width0, src->height0, 0, 1, UTIL_BLITTER_ATTRIB_NONE, NULL); util_blitter_restore_fb_state(blitter); @@ -2536,9 +2545,9 @@ void util_blitter_custom_color(struct blitter_context *blitter, pipe->set_framebuffer_state(pipe, &fb_state); pipe->set_sample_mask(pipe, ~0); - blitter_set_common_draw_rect_state(ctx, false, false, false); + blitter_set_common_draw_rect_state(ctx, false); blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height); - blitter->draw_rectangle(blitter, ctx->velem_state, + blitter->draw_rectangle(blitter, ctx->velem_state, get_vs_passthrough_pos, 0, 0, dstsurf->width, dstsurf->height, 0, 1, UTIL_BLITTER_ATTRIB_NONE, NULL); |