r600g: refactor out code for buffer invalidation
authorMarek Olšák <marek.olsak@amd.com>
Fri, 29 Nov 2013 15:02:12 +0000 (16:02 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 12 Dec 2013 17:34:11 +0000 (18:34 +0100)
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state_common.c

index 6c892c052e76bcad15dab7810c1d1da9237ffcb2..7239e5a365f0e944aea88f3fb36a4b9dd129de82 100644 (file)
@@ -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) &&
index b3eb70cb4242ffdb20f4330b0658daeefdb6cad8..4b4d0957dbf71f3ac2a8bac93ae098e8f995270e 100644 (file)
@@ -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,
index 7d3c5bc20a782f4aeeeb690624a3a560b1aaa751..718a173236d7e5795ec363d4f3ecc5f24e4ac087 100644 (file)
@@ -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)
 {