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 | |
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]>
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.c | 91 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.h | 11 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_context.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_render.c | 5 | ||||
-rw-r--r-- | src/gallium/drivers/r600/r600_pipe_common.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/r600/r600_pipe_common.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_state.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_state_draw.c | 2 |
8 files changed, 72 insertions, 42 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, diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h index b2d7f6da30e..22025157764 100644 --- a/src/gallium/drivers/r300/r300_context.h +++ b/src/gallium/drivers/r300/r300_context.h @@ -744,6 +744,7 @@ void r300_plug_in_stencil_ref_fallback(struct r300_context *r300); void r500_emit_index_bias(struct r300_context *r300, int index_bias); void r300_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, diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c index 7808669e253..4cae7660347 100644 --- a/src/gallium/drivers/r300/r300_render.c +++ b/src/gallium/drivers/r300/r300_render.c @@ -1114,6 +1114,7 @@ struct draw_stage* r300_draw_stage(struct r300_context* r300) * somewhat inefficient. Instead we use a rectangular point sprite. */ void r300_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, @@ -1135,7 +1136,8 @@ void r300_blitter_draw_rectangle(struct blitter_context *blitter, if ((!r300->screen->caps.has_tcl && type == UTIL_BLITTER_ATTRIB_NONE) || type == UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW || num_instances > 1) { - util_blitter_draw_rectangle(blitter, vertex_elements_cso, x1, y1, x2, y2, + util_blitter_draw_rectangle(blitter, vertex_elements_cso, get_vs, + x1, y1, x2, y2, depth, num_instances, type, attrib); return; } @@ -1144,6 +1146,7 @@ void r300_blitter_draw_rectangle(struct blitter_context *blitter, return; r300->context.bind_vertex_elements_state(&r300->context, vertex_elements_cso); + r300->context.bind_vs_state(&r300->context, get_vs(blitter)); if (type == UTIL_BLITTER_ATTRIB_TEXCOORD_XY) r300->sprite_coord_enable = 1; diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c index 0e8a12a1b64..56297cf4db8 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.c +++ b/src/gallium/drivers/r600/r600_pipe_common.c @@ -212,6 +212,7 @@ void r600_gfx_wait_fence(struct r600_common_context *ctx, void r600_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, @@ -225,6 +226,7 @@ void r600_draw_rectangle(struct blitter_context *blitter, float *vb; rctx->b.bind_vertex_elements_state(&rctx->b, vertex_elements_cso); + rctx->b.bind_vs_state(&rctx->b, get_vs(blitter)); /* Some operations (like color resolve on r6xx) don't work * with the conventional primitive types. diff --git a/src/gallium/drivers/r600/r600_pipe_common.h b/src/gallium/drivers/r600/r600_pipe_common.h index 37dcbd3d316..52f39cdb7ac 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.h +++ b/src/gallium/drivers/r600/r600_pipe_common.h @@ -763,6 +763,7 @@ void r600_gfx_wait_fence(struct r600_common_context *ctx, uint64_t va, uint32_t ref, uint32_t mask); void r600_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, diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h index c9745a58cb7..9cc323dc9be 100644 --- a/src/gallium/drivers/radeonsi/si_state.h +++ b/src/gallium/drivers/radeonsi/si_state.h @@ -409,6 +409,7 @@ void si_emit_cache_flush(struct si_context *sctx); void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *dinfo); void si_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, diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c index ceb90d287f5..9cb42741153 100644 --- a/src/gallium/drivers/radeonsi/si_state_draw.c +++ b/src/gallium/drivers/radeonsi/si_state_draw.c @@ -1492,6 +1492,7 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info) void si_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, @@ -1565,6 +1566,7 @@ void si_draw_rectangle(struct blitter_context *blitter, vbuffer.buffer_offset = offset; pipe->set_vertex_buffers(pipe, blitter->vb_slot, 1, &vbuffer); + pipe->bind_vs_state(pipe, get_vs(blitter)); if (sctx->vertex_elements != vertex_elements_cso) pipe->bind_vertex_elements_state(pipe, vertex_elements_cso); |