aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2013-11-29 16:02:12 +0100
committerMarek Olšák <[email protected]>2013-12-12 18:34:11 +0100
commit43ea10eb1d6b597b57faaeb5993ca23ed7a537d2 (patch)
treec0a27d7765404366480a7e322365636997cfc19d
parentbba39d88046670bdd4db2ab1e7ba07b7e4ae277c (diff)
r600g: refactor out code for buffer invalidation
Reviewed-by: Michel Dänzer <[email protected]>
-rw-r--r--src/gallium/drivers/r600/r600_buffer.c56
-rw-r--r--src/gallium/drivers/r600/r600_pipe.h1
-rw-r--r--src/gallium/drivers/r600/r600_state_common.c55
3 files changed, 57 insertions, 55 deletions
diff --git a/src/gallium/drivers/r600/r600_buffer.c b/src/gallium/drivers/r600/r600_buffer.c
index 6c892c052e7..7239e5a365f 100644
--- a/src/gallium/drivers/r600/r600_buffer.c
+++ b/src/gallium/drivers/r600/r600_buffer.c
@@ -39,29 +39,6 @@ static void r600_buffer_destroy(struct pipe_screen *screen,
FREE(rbuffer);
}
-static void r600_set_constants_dirty_if_bound(struct r600_context *rctx,
- struct r600_resource *rbuffer)
-{
- unsigned shader;
-
- for (shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
- struct r600_constbuf_state *state = &rctx->constbuf_state[shader];
- bool found = false;
- uint32_t mask = state->enabled_mask;
-
- while (mask) {
- unsigned i = u_bit_scan(&mask);
- if (state->cb[i].buffer == &rbuffer->b.b) {
- found = true;
- state->dirty_mask |= 1 << i;
- }
- }
- if (found) {
- r600_constant_buffers_dirty(rctx, state);
- }
- }
-}
-
static void *r600_buffer_get_transfer(struct pipe_context *ctx,
struct pipe_resource *resource,
unsigned level,
@@ -114,38 +91,7 @@ static void *r600_buffer_transfer_map(struct pipe_context *ctx,
/* Check if mapping this buffer would cause waiting for the GPU. */
if (r600_rings_is_buffer_referenced(&rctx->b, rbuffer->cs_buf, RADEON_USAGE_READWRITE) ||
rctx->b.ws->buffer_is_busy(rbuffer->buf, RADEON_USAGE_READWRITE)) {
- unsigned i, mask;
-
- /* Discard the buffer. */
- pb_reference(&rbuffer->buf, NULL);
-
- /* Create a new one in the same pipe_resource. */
- /* XXX We probably want a different alignment for buffers and textures. */
- r600_init_resource(&rctx->screen->b, rbuffer, rbuffer->b.b.width0, 4096,
- TRUE, rbuffer->b.b.usage);
-
- /* We changed the buffer, now we need to bind it where the old one was bound. */
- /* Vertex buffers. */
- mask = rctx->vertex_buffer_state.enabled_mask;
- while (mask) {
- i = u_bit_scan(&mask);
- if (rctx->vertex_buffer_state.vb[i].buffer == &rbuffer->b.b) {
- rctx->vertex_buffer_state.dirty_mask |= 1 << i;
- r600_vertex_buffers_dirty(rctx);
- }
- }
- /* Streamout buffers. */
- for (i = 0; i < rctx->b.streamout.num_targets; i++) {
- if (rctx->b.streamout.targets[i]->b.buffer == &rbuffer->b.b) {
- if (rctx->b.streamout.begin_emitted) {
- r600_emit_streamout_end(&rctx->b);
- }
- rctx->b.streamout.append_bitmask = rctx->b.streamout.enabled_mask;
- r600_streamout_buffers_dirty(&rctx->b);
- }
- }
- /* Constant buffers. */
- r600_set_constants_dirty_if_bound(rctx, rbuffer);
+ r600_invalidate_buffer(&rctx->b.b, &rbuffer->b.b);
}
}
else if ((usage & PIPE_TRANSFER_DISCARD_RANGE) &&
diff --git a/src/gallium/drivers/r600/r600_pipe.h b/src/gallium/drivers/r600/r600_pipe.h
index b3eb70cb424..4b4d0957dbf 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -718,6 +718,7 @@ unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
uint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
const unsigned char *swizzle_view,
uint32_t *word4_p, uint32_t *yuv_format_p);
+void r600_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource *buf);
/* r600_uvd.c */
struct pipe_video_codec *r600_uvd_create_decoder(struct pipe_context *context,
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index 7d3c5bc20a7..718a173236d 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -2072,6 +2072,61 @@ out_unknown:
return ~0;
}
+void r600_invalidate_buffer(struct pipe_context *ctx, struct pipe_resource *buf)
+{
+ struct r600_context *rctx = (struct r600_context*)ctx;
+ struct r600_resource *rbuffer = r600_resource(buf);
+ unsigned i, shader, mask, alignment = rbuffer->buf->alignment;
+
+ /* Discard the buffer. */
+ pb_reference(&rbuffer->buf, NULL);
+
+ /* Create a new one in the same pipe_resource. */
+ r600_init_resource(&rctx->screen->b, rbuffer, rbuffer->b.b.width0, alignment,
+ TRUE, rbuffer->b.b.usage);
+
+ /* We changed the buffer, now we need to bind it where the old one was bound. */
+ /* Vertex buffers. */
+ mask = rctx->vertex_buffer_state.enabled_mask;
+ while (mask) {
+ i = u_bit_scan(&mask);
+ if (rctx->vertex_buffer_state.vb[i].buffer == &rbuffer->b.b) {
+ rctx->vertex_buffer_state.dirty_mask |= 1 << i;
+ r600_vertex_buffers_dirty(rctx);
+ }
+ }
+ /* Streamout buffers. */
+ for (i = 0; i < rctx->b.streamout.num_targets; i++) {
+ if (rctx->b.streamout.targets[i]->b.buffer == &rbuffer->b.b) {
+ if (rctx->b.streamout.begin_emitted) {
+ r600_emit_streamout_end(&rctx->b);
+ }
+ rctx->b.streamout.append_bitmask = rctx->b.streamout.enabled_mask;
+ r600_streamout_buffers_dirty(&rctx->b);
+ }
+ }
+
+ /* Constant buffers. */
+ for (shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
+ struct r600_constbuf_state *state = &rctx->constbuf_state[shader];
+ bool found = false;
+ uint32_t mask = state->enabled_mask;
+
+ while (mask) {
+ unsigned i = u_bit_scan(&mask);
+ if (state->cb[i].buffer == &rbuffer->b.b) {
+ found = true;
+ state->dirty_mask |= 1 << i;
+ }
+ }
+ if (found) {
+ r600_constant_buffers_dirty(rctx, state);
+ }
+ }
+
+ /* XXX TODO: texture buffer objects */
+}
+
/* keep this at the end of this file, please */
void r600_init_common_state_functions(struct r600_context *rctx)
{