radeonsi: add si_get_shader_buffers/get_pipe_constant_buffers (v2)
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 14 Sep 2016 07:45:37 +0000 (09:45 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 29 Sep 2016 09:14:33 +0000 (11:14 +0200)
These functions extract the pipe state structure from the current
descriptors, for state saving.

v2: correctly dereference *buf (Bas)

Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/radeonsi/si_descriptors.c
src/gallium/drivers/radeonsi/si_state.h

index b1a8594c87e3ddde4bd1e4b9018f511c96a18395..21dad3cd2b91ad61af0c58e350c13944273b2f98 100644 (file)
@@ -837,6 +837,27 @@ static void si_buffer_resources_begin_new_cs(struct si_context *sctx,
        }
 }
 
+static void si_get_buffer_from_descriptors(struct si_buffer_resources *buffers,
+                                          struct si_descriptors *descs,
+                                          unsigned idx, struct pipe_resource **buf,
+                                          unsigned *offset, unsigned *size)
+{
+       pipe_resource_reference(buf, buffers->buffers[idx]);
+       if (*buf) {
+               struct r600_resource *res = r600_resource(*buf);
+               const uint32_t *desc = descs->list + idx * 4;
+               uint64_t va;
+
+               *size = desc[2];
+
+               assert(G_008F04_STRIDE(desc[1]) == 0);
+               va = ((uint64_t)desc[1] << 32) | desc[0];
+
+               assert(va >= res->gpu_address && va + *size <= res->gpu_address + res->bo_size);
+               *offset = va - res->gpu_address;
+       }
+}
+
 /* VERTEX BUFFERS */
 
 static void si_vertex_buffers_begin_new_cs(struct si_context *sctx)
@@ -1062,6 +1083,16 @@ static void si_pipe_set_constant_buffer(struct pipe_context *ctx,
                               slot, input);
 }
 
+void si_get_pipe_constant_buffer(struct si_context *sctx, uint shader,
+                                uint slot, struct pipe_constant_buffer *cbuf)
+{
+       cbuf->user_buffer = NULL;
+       si_get_buffer_from_descriptors(
+               &sctx->const_buffers[shader],
+               si_const_buffer_descriptors(sctx, shader),
+               slot, &cbuf->buffer, &cbuf->buffer_offset, &cbuf->buffer_size);
+}
+
 /* SHADER BUFFERS */
 
 static unsigned
@@ -1132,6 +1163,21 @@ static void si_set_shader_buffers(struct pipe_context *ctx,
        }
 }
 
+void si_get_shader_buffers(struct si_context *sctx, uint shader,
+                          uint start_slot, uint count,
+                          struct pipe_shader_buffer *sbuf)
+{
+       struct si_buffer_resources *buffers = &sctx->shader_buffers[shader];
+       struct si_descriptors *descs = si_shader_buffer_descriptors(sctx, shader);
+
+       for (unsigned i = 0; i < count; ++i) {
+               si_get_buffer_from_descriptors(
+                       buffers, descs, start_slot + i,
+                       &sbuf[i].buffer, &sbuf[i].buffer_offset,
+                       &sbuf[i].buffer_size);
+       }
+}
+
 /* RING BUFFERS */
 
 void si_set_ring_buffer(struct pipe_context *ctx, uint slot,
index e83b42843009e8d0e5acd8e877deb4735db1d0a5..3ebf578e59313aed43763761fc87f6e75a6cbb12 100644 (file)
@@ -281,6 +281,11 @@ void si_set_mutable_tex_desc_fields(struct r600_texture *tex,
                                    unsigned base_level, unsigned first_level,
                                    unsigned block_width, bool is_stencil,
                                    uint32_t *state);
+void si_get_pipe_constant_buffer(struct si_context *sctx, uint shader,
+                                uint slot, struct pipe_constant_buffer *cbuf);
+void si_get_shader_buffers(struct si_context *sctx, uint shader,
+                          uint start_slot, uint count,
+                          struct pipe_shader_buffer *sbuf);
 void si_set_ring_buffer(struct pipe_context *ctx, uint slot,
                        struct pipe_resource *buffer,
                        unsigned stride, unsigned num_records,