diff options
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.c | 91 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.h | 11 |
2 files changed, 61 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); diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index 868f1da5c9c..0dd896d3818 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -53,11 +53,20 @@ union blitter_attrib { } texcoord; }; +struct blitter_context; + +typedef void *(*blitter_get_vs_func)(struct blitter_context *blitter); + struct blitter_context { /** * Draw a rectangle. * + * \param get_vs Callback for obtaining the vertex shader for the draw call. + * It might invoke the shader compiler. The driver is + * responsible for setting the vertex shader, and the callback + * allows the driver to query the vertex shader CSO if it + * wants to use the default one. * \param x1 An X coordinate of the top-left corner. * \param y1 A Y coordinate of the top-left corner. * \param x2 An X coordinate of the bottom-right corner. @@ -82,6 +91,7 @@ struct blitter_context */ void (*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, @@ -157,6 +167,7 @@ void util_blitter_set_texture_multisample(struct blitter_context *blitter, * inside of the draw_rectangle callback if the driver overrides it. */ 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, |