[Mesa-dev] [PATCH 05/12] gallium/u_blitter: let drivers decide which VS to use for draw_rectangle
Marek Olšák
maraeo at gmail.com
Fri Oct 6 14:10:08 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
This approach allows drivers to set their own vertex shader and skip
compilation of u_blitter vertex shaders.
---
src/gallium/auxiliary/util/u_blitter.c | 91 +++++++++++++++-------------
src/gallium/auxiliary/util/u_blitter.h | 11 ++++
src/gallium/drivers/r300/r300_context.h | 1 +
src/gallium/drivers/r300/r300_render.c | 5 +-
src/gallium/drivers/r600/r600_pipe_common.c | 2 +
src/gallium/drivers/r600/r600_pipe_common.h | 1 +
src/gallium/drivers/radeonsi/si_state.h | 1 +
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 ec03e5f..47042e4 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -343,62 +343,62 @@ static void bind_vs_pos_only(struct blitter_context_priv *ctx,
ctx->vs_pos_only[index] =
util_make_vertex_passthrough_shader_with_so(pipe, 1, semantic_names,
semantic_indices, false,
false, &so);
}
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) {
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_GENERIC };
const uint semantic_indices[] = { 0, 0 };
ctx->vs =
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) {
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION };
const uint semantic_indices[] = { 0 };
ctx->vs_nogeneric =
util_make_vertex_passthrough_shader(pipe, 1,
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)
{
struct pipe_context *pipe = ctx->base.pipe;
if (!ctx->fs_empty) {
assert(!ctx->cached_all_shaders);
ctx->fs_empty = util_make_empty_fragment_shader(pipe);
}
@@ -1204,72 +1204,66 @@ void util_blitter_cache_all_shaders(struct blitter_context *blitter)
TGSI_INTERPOLATE_CONSTANT, false);
ctx->fs_write_all_cbufs =
util_make_fragment_passthrough_shader(pipe, TGSI_SEMANTIC_GENERIC,
TGSI_INTERPOLATE_CONSTANT, true);
ctx->cached_all_shaders = true;
}
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) {
pipe->bind_tcs_state(pipe, NULL);
pipe->bind_tes_state(pipe, NULL);
}
if (ctx->has_stream_out)
pipe->set_stream_output_targets(pipe, 0, NULL, NULL);
}
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)
{
struct pipe_context *pipe = ctx->base.pipe;
struct pipe_vertex_buffer vb = {0};
blitter_set_rectangle(ctx, x1, y1, x2, y2, depth);
vb.stride = 8 * sizeof(float);
u_upload_data(pipe->stream_uploader, 0, sizeof(ctx->vertices), 4, ctx->vertices,
&vb.buffer_offset, &vb.buffer.resource);
if (!vb.buffer.resource)
return;
u_upload_unmap(pipe->stream_uploader);
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);
}
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,
const union blitter_attrib *attrib)
{
struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
unsigned i;
switch (type) {
case UTIL_BLITTER_ATTRIB_COLOR:
@@ -1282,21 +1276,22 @@ void util_blitter_draw_rectangle(struct blitter_context *blitter,
ctx->vertices[i][1][3] = attrib->texcoord.w;
}
/* fall through */
case UTIL_BLITTER_ATTRIB_TEXCOORD_XY:
set_texcoords_in_vertices(attrib, &ctx->vertices[0][1][0], 8);
break;
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,
unsigned clear_buffers)
{
struct pipe_context *pipe = ctx->base.pipe;
int index;
clear_buffers &= PIPE_CLEAR_COLOR;
@@ -1386,26 +1381,37 @@ static void util_blitter_clear_custom(struct blitter_context *blitter,
bind_fs_write_all_cbufs(ctx);
union blitter_attrib attrib;
memcpy(attrib.color, color->ui, sizeof(color->ui));
bool pass_generic = (clear_buffers & PIPE_CLEAR_COLOR) != 0;
enum blitter_attrib_type type = pass_generic ? UTIL_BLITTER_ATTRIB_COLOR :
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);
}
util_blitter_restore_vertex_states(blitter);
util_blitter_restore_fragment_states(blitter);
util_blitter_restore_render_cond(blitter);
util_blitter_unset_running_flag(blitter);
}
void util_blitter_clear(struct blitter_context *blitter,
@@ -1605,43 +1611,44 @@ void util_blitter_copy_texture(struct blitter_context *blitter,
static void
blitter_draw_tex(struct blitter_context_priv *ctx,
int dst_x1, int dst_y1, int dst_x2, int dst_y2,
struct pipe_sampler_view *src,
unsigned src_width0, unsigned src_height0,
int src_x1, int src_y1, int src_x2, int src_y2,
float layer, unsigned sample,
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,
uses_txf, &coord);
if (src->target == PIPE_TEXTURE_CUBE ||
src->target == PIPE_TEXTURE_CUBE_ARRAY) {
float face_coord[4][2];
set_texcoords_in_vertices(&coord, &face_coord[0][0], 2);
util_map_texcoords2d_onto_cubemap((unsigned)layer % 6,
/* pointer, stride in floats */
&face_coord[0][0], 2,
&ctx->vertices[0][1][0], 8,
false);
for (unsigned i = 0; i < 4; i++)
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);
}
}
static void do_blits(struct blitter_context_priv *ctx,
struct pipe_surface *dst,
const struct pipe_box *dstbox,
struct pipe_sampler_view *src,
unsigned src_width0,
@@ -1939,21 +1946,21 @@ void util_blitter_blit_generic(struct blitter_context *blitter,
} else {
pipe->set_sampler_views(pipe, PIPE_SHADER_FRAGMENT, 0, 1, &src);
pipe->bind_sampler_states(pipe, PIPE_SHADER_FRAGMENT,
0, 1, &sampler_state);
}
if (scissor) {
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);
util_blitter_restore_vertex_states(blitter);
util_blitter_restore_fragment_states(blitter);
util_blitter_restore_textures(blitter);
util_blitter_restore_fb_state(blitter);
if (scissor) {
pipe->set_scissor_states(pipe, 0, 1, &ctx->base.saved_scissor);
@@ -2045,21 +2052,21 @@ void util_blitter_generate_mipmap(struct blitter_context *blitter,
}
if (target == PIPE_TEXTURE_RECT) {
sampler_state = ctx->sampler_state_rect_linear;
} else {
sampler_state = ctx->sampler_state_linear;
}
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};
unsigned dst_level = src_level + 1;
dstbox.width = u_minify(tex->width0, dst_level);
dstbox.height = u_minify(tex->height0, dst_level);
srcbox.width = u_minify(tex->width0, src_level);
srcbox.height = u_minify(tex->height0, src_level);
@@ -2137,27 +2144,28 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
pipe->set_framebuffer_state(pipe, &fb_state);
pipe->set_sample_mask(pipe, ~0);
blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
union blitter_attrib attrib;
memcpy(attrib.color, color->ui, sizeof(color->ui));
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);
}
util_blitter_restore_vertex_states(blitter);
util_blitter_restore_fragment_states(blitter);
util_blitter_restore_fb_state(blitter);
util_blitter_restore_render_cond(blitter);
util_blitter_unset_running_flag(blitter);
}
@@ -2215,27 +2223,28 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
fb_state.nr_cbufs = 0;
fb_state.cbufs[0] = 0;
fb_state.zsbuf = dstsurf;
pipe->set_framebuffer_state(pipe, &fb_state);
pipe->set_sample_mask(pipe, ~0);
blitter_set_dst_dimensions(ctx, dstsurf->width, dstsurf->height);
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);
}
util_blitter_restore_vertex_states(blitter);
util_blitter_restore_fragment_states(blitter);
util_blitter_restore_fb_state(blitter);
util_blitter_restore_render_cond(blitter);
util_blitter_unset_running_flag(blitter);
}
@@ -2279,24 +2288,24 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
fb_state.cbufs[0] = cbsurf;
fb_state.nr_cbufs = 1;
} else {
fb_state.cbufs[0] = NULL;
fb_state.nr_cbufs = 0;
}
fb_state.zsbuf = zsurf;
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);
util_blitter_restore_fragment_states(blitter);
util_blitter_restore_fb_state(blitter);
util_blitter_restore_render_cond(blitter);
util_blitter_unset_running_flag(blitter);
}
void util_blitter_copy_buffer(struct blitter_context *blitter,
@@ -2479,23 +2488,23 @@ void util_blitter_custom_resolve_color(struct blitter_context *blitter,
/* set a framebuffer state */
fb_state.width = src->width0;
fb_state.height = src->height0;
fb_state.nr_cbufs = 2;
fb_state.cbufs[0] = srcsurf;
fb_state.cbufs[1] = dstsurf;
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);
util_blitter_restore_vertex_states(blitter);
util_blitter_restore_fragment_states(blitter);
util_blitter_restore_render_cond(blitter);
util_blitter_unset_running_flag(blitter);
pipe_surface_reference(&srcsurf, NULL);
pipe_surface_reference(&dstsurf, NULL);
@@ -2529,22 +2538,22 @@ void util_blitter_custom_color(struct blitter_context *blitter,
/* set a framebuffer state */
fb_state.width = dstsurf->width;
fb_state.height = dstsurf->height;
fb_state.nr_cbufs = 1;
fb_state.cbufs[0] = dstsurf;
fb_state.zsbuf = 0;
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);
util_blitter_restore_vertex_states(blitter);
util_blitter_restore_fragment_states(blitter);
util_blitter_restore_fb_state(blitter);
util_blitter_restore_render_cond(blitter);
util_blitter_unset_running_flag(blitter);
}
diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h
index 868f1da..0dd896d 100644
--- a/src/gallium/auxiliary/util/u_blitter.h
+++ b/src/gallium/auxiliary/util/u_blitter.h
@@ -46,25 +46,34 @@ enum blitter_attrib_type {
};
union blitter_attrib {
float color[4];
struct {
float x1, y1, x2, y2, z, w;
} 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.
* \param y2 A Y coordinate of the bottom-right corner.
* \param depth A depth which the rectangle is rendered at.
*
* \param type Semantics of the attributes "attrib".
* If type is UTIL_BLITTER_ATTRIB_NONE, ignore them.
* If type is UTIL_BLITTER_ATTRIB_COLOR, the attributes
* make up a constant RGBA color, and should go
@@ -75,20 +84,21 @@ struct blitter_context
* to the GENERIC0 varying slot of a fragment shader.
*
* \param attrib See type.
*
* \note A driver may optionally override this callback to implement
* a specialized hardware path for drawing a rectangle, e.g. using
* a rectangular point sprite.
*/
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,
const union blitter_attrib *attrib);
/* Whether the blitter is running. */
bool running;
/* Private members, really. */
struct pipe_context *pipe; /**< pipe context */
@@ -150,20 +160,21 @@ struct pipe_context *util_blitter_get_pipe(struct blitter_context *blitter)
/**
* Override PIPE_CAP_TEXTURE_MULTISAMPLE as reported by the driver.
*/
void util_blitter_set_texture_multisample(struct blitter_context *blitter,
bool supported);
/* The default function to draw a rectangle. This can only be used
* 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,
const union blitter_attrib *attrib);
/*
* These states must be saved before any of the following functions are called:
* - vertex buffers
* - vertex elements
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index b2d7f6d..2202515 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -737,20 +737,21 @@ void r300_translate_index_buffer(struct r300_context *r300,
unsigned *index_size, unsigned index_offset,
unsigned *start, unsigned count);
/* r300_render_stencilref.c */
void r300_plug_in_stencil_ref_fallback(struct r300_context *r300);
/* r300_render.c */
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,
const union blitter_attrib *attrib);
/* r300_state.c */
enum r300_fb_state_change {
R300_CHANGED_FB_STATE = 0,
R300_CHANGED_HYPERZ_FLAG,
R300_CHANGED_MULTIWRITE,
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index 7808669..4cae766 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -1107,20 +1107,21 @@ struct draw_stage* r300_draw_stage(struct r300_context* r300)
* End of SW TCL functions *
***************************************************************************/
/* This functions is used to draw a rectangle for the blitter module.
*
* If we rendered a quad, the pixels on the main diagonal
* would be computed and stored twice, which makes the clear/copy codepaths
* 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,
const union blitter_attrib *attrib)
{
struct r300_context *r300 = r300_context(util_blitter_get_pipe(blitter));
unsigned last_sprite_coord_enable = r300->sprite_coord_enable;
unsigned width = x2 - x1;
unsigned height = y2 - y1;
unsigned vertex_size =
@@ -1128,29 +1129,31 @@ void r300_blitter_draw_rectangle(struct blitter_context *blitter,
unsigned dwords = 13 + vertex_size +
(type == UTIL_BLITTER_ATTRIB_TEXCOORD_XY ? 7 : 0);
static const union blitter_attrib zeros;
CS_LOCALS(r300);
/* XXX workaround for a lockup in MSAA resolve on SWTCL chipsets, this
* function most probably doesn't handle type=NONE correctly */
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;
}
if (r300->skip_rendering)
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;
r300_update_derived_state(r300);
/* Mark some states we don't care about as non-dirty. */
r300->viewport_state.dirty = FALSE;
if (!r300_prepare_for_rendering(r300, PREP_EMIT_STATES, NULL, dwords, 0, 0, -1))
diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c
index 0e8a12a..56297cf 100644
--- a/src/gallium/drivers/r600/r600_pipe_common.c
+++ b/src/gallium/drivers/r600/r600_pipe_common.c
@@ -205,33 +205,35 @@ void r600_gfx_wait_fence(struct r600_common_context *ctx,
radeon_emit(cs, WAIT_REG_MEM_EQUAL | WAIT_REG_MEM_MEM_SPACE(1));
radeon_emit(cs, va);
radeon_emit(cs, va >> 32);
radeon_emit(cs, ref); /* reference value */
radeon_emit(cs, mask); /* mask */
radeon_emit(cs, 4); /* poll interval */
}
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,
const union blitter_attrib *attrib)
{
struct r600_common_context *rctx =
(struct r600_common_context*)util_blitter_get_pipe(blitter);
struct pipe_viewport_state viewport;
struct pipe_resource *buf = NULL;
unsigned offset = 0;
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.
* One that works is PT_RECTLIST, which we use here. */
/* setup viewport */
viewport.scale[0] = 1.0f;
viewport.scale[1] = 1.0f;
viewport.scale[2] = 1.0f;
viewport.translate[0] = 0.0f;
diff --git a/src/gallium/drivers/r600/r600_pipe_common.h b/src/gallium/drivers/r600/r600_pipe_common.h
index 37dcbd3..52f39cd 100644
--- a/src/gallium/drivers/r600/r600_pipe_common.h
+++ b/src/gallium/drivers/r600/r600_pipe_common.h
@@ -756,20 +756,21 @@ void r600_replace_buffer_storage(struct pipe_context *ctx,
void r600_gfx_write_event_eop(struct r600_common_context *ctx,
unsigned event, unsigned event_flags,
unsigned data_sel,
struct r600_resource *buf, uint64_t va,
uint32_t new_fence, unsigned query_type);
unsigned r600_gfx_write_fence_dwords(struct r600_common_screen *screen);
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,
const union blitter_attrib *attrib);
bool r600_common_screen_init(struct r600_common_screen *rscreen,
struct radeon_winsys *ws);
void r600_destroy_common_screen(struct r600_common_screen *rscreen);
void r600_preflush_suspend_features(struct r600_common_context *ctx);
void r600_postflush_resume_features(struct r600_common_context *ctx);
bool r600_common_context_init(struct r600_common_context *rctx,
diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h
index c9745a5..9cc323d 100644
--- a/src/gallium/drivers/radeonsi/si_state.h
+++ b/src/gallium/drivers/radeonsi/si_state.h
@@ -402,20 +402,21 @@ void si_destroy_shader_cache(struct si_screen *sscreen);
void si_get_active_slot_masks(const struct tgsi_shader_info *info,
uint32_t *const_and_shader_buffers,
uint64_t *samplers_and_images);
/* si_state_draw.c */
void si_init_ia_multi_vgt_param_table(struct si_context *sctx);
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,
const union blitter_attrib *attrib);
void si_trace_emit(struct si_context *sctx);
static inline unsigned
si_tile_mode_index(struct r600_texture *rtex, unsigned level, bool stencil)
{
diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c
index ceb90d2..9cb4274 100644
--- a/src/gallium/drivers/radeonsi/si_state_draw.c
+++ b/src/gallium/drivers/radeonsi/si_state_draw.c
@@ -1485,20 +1485,21 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
sctx->b.num_prim_restart_calls++;
if (G_0286E8_WAVESIZE(sctx->spi_tmpring_size))
sctx->b.num_spill_draw_calls++;
}
if (index_size && indexbuf != info->index.resource)
pipe_resource_reference(&indexbuf, NULL);
}
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,
const union blitter_attrib *attrib)
{
struct pipe_context *pipe = util_blitter_get_pipe(blitter);
struct si_context *sctx = (struct si_context*)pipe;
struct pipe_viewport_state viewport;
struct pipe_resource *buf = NULL;
unsigned offset = 0;
@@ -1558,20 +1559,21 @@ void si_draw_rectangle(struct blitter_context *blitter,
default:; /* Nothing to do. */
}
/* draw */
struct pipe_vertex_buffer vbuffer = {};
vbuffer.buffer.resource = buf;
vbuffer.stride = 2 * 4 * sizeof(float); /* vertex size */
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);
struct pipe_draw_info info = {};
info.mode = R600_PRIM_RECTANGLE_LIST;
info.count = 3;
info.instance_count = num_instances;
si_draw_vbo(pipe, &info);
--
2.7.4
More information about the mesa-dev
mailing list