summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2017-10-19 15:17:41 -0700
committerEric Anholt <[email protected]>2017-10-20 15:53:55 -0700
commitfb15168919613fd913addc5d2d90673e506ae0cc (patch)
tree3f0c7e43a5ec8d98029608ea60940f030a9929a2
parentf4ff8f74ee74b97b9b058f41e404eb41aa5e6359 (diff)
broadcom/vc5: Move most of the shader state attribute record to the CSO.
This should reduce our draw-time overhead, and puts the code where it should go long term.
-rw-r--r--src/gallium/drivers/vc5/vc5_context.h5
-rw-r--r--src/gallium/drivers/vc5/vc5_draw.c83
-rw-r--r--src/gallium/drivers/vc5/vc5_screen.h1
-rw-r--r--src/gallium/drivers/vc5/vc5_state.c66
4 files changed, 90 insertions, 65 deletions
diff --git a/src/gallium/drivers/vc5/vc5_context.h b/src/gallium/drivers/vc5/vc5_context.h
index d4f9e1eac6b..08d96f36ecf 100644
--- a/src/gallium/drivers/vc5/vc5_context.h
+++ b/src/gallium/drivers/vc5/vc5_context.h
@@ -33,6 +33,7 @@
#include "util/slab.h"
#include "xf86drm.h"
#include "vc5_drm.h"
+#include "vc5_screen.h"
struct vc5_job;
struct vc5_bo;
@@ -159,8 +160,10 @@ struct vc5_vertexbuf_stateobj {
};
struct vc5_vertex_stateobj {
- struct pipe_vertex_element pipe[PIPE_MAX_ATTRIBS];
+ struct pipe_vertex_element pipe[VC5_MAX_ATTRIBUTES];
unsigned num_elements;
+
+ uint8_t attrs[12 * VC5_MAX_ATTRIBUTES];
};
struct vc5_streamout_stateobj {
diff --git a/src/gallium/drivers/vc5/vc5_draw.c b/src/gallium/drivers/vc5/vc5_draw.c
index fe5a2c21293..f6c22c9d182 100644
--- a/src/gallium/drivers/vc5/vc5_draw.c
+++ b/src/gallium/drivers/vc5/vc5_draw.c
@@ -244,71 +244,26 @@ vc5_emit_gl_shader_state(struct vc5_context *vc5,
struct pipe_vertex_buffer *vb =
&vertexbuf->vb[elem->vertex_buffer_index];
struct vc5_resource *rsc = vc5_resource(vb->buffer.resource);
- const struct util_format_description *desc =
- util_format_description(elem->src_format);
-
- uint32_t offset = vb->buffer_offset + elem->src_offset;
-
- cl_emit(&job->indirect, GL_SHADER_STATE_ATTRIBUTE_RECORD, attr) {
- uint32_t r_size = desc->channel[0].size;
-
- /* vec_size == 0 means 4 */
- attr.vec_size = desc->nr_channels & 3;
-
- switch (desc->channel[0].type) {
- case UTIL_FORMAT_TYPE_FLOAT:
- if (r_size == 32) {
- attr.type = ATTRIBUTE_FLOAT;
- } else {
- assert(r_size == 16);
- attr.type = ATTRIBUTE_HALF_FLOAT;
- }
- break;
-
- case UTIL_FORMAT_TYPE_SIGNED:
- case UTIL_FORMAT_TYPE_UNSIGNED:
- switch (r_size) {
- case 32:
- attr.type = ATTRIBUTE_INT;
- break;
- case 16:
- attr.type = ATTRIBUTE_SHORT;
- break;
- case 10:
- attr.type = ATTRIBUTE_INT2_10_10_10;
- break;
- case 8:
- attr.type = ATTRIBUTE_BYTE;
- break;
- default:
- fprintf(stderr,
- "format %s unsupported\n",
- desc->name);
- attr.type = ATTRIBUTE_BYTE;
- abort();
- }
- break;
-
- default:
- fprintf(stderr,
- "format %s unsupported\n",
- desc->name);
- abort();
- }
- attr.signed_int_type =
- desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED;
-
- attr.normalized_int_type = desc->channel[0].normalized;
- attr.read_as_int_uint = desc->channel[0].pure_integer;
- attr.address = cl_address(rsc->bo, offset);
- attr.stride = vb->stride;
- attr.instance_divisor = elem->instance_divisor;
- attr.number_of_values_read_by_coordinate_shader =
- vc5->prog.cs->prog_data.vs->vattr_sizes[i];
- attr.number_of_values_read_by_vertex_shader =
- vc5->prog.vs->prog_data.vs->vattr_sizes[i];
- }
+ struct V3D33_GL_SHADER_STATE_ATTRIBUTE_RECORD attr_unpacked = {
+ .stride = vb->stride,
+ .address = cl_address(rsc->bo,
+ vb->buffer_offset +
+ elem->src_offset),
+ .number_of_values_read_by_coordinate_shader =
+ vc5->prog.cs->prog_data.vs->vattr_sizes[i],
+ .number_of_values_read_by_vertex_shader =
+ vc5->prog.vs->prog_data.vs->vattr_sizes[i],
+ };
+ const uint32_t size =
+ cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD);
+ uint8_t attr_packed[size];
+ V3D33_GL_SHADER_STATE_ATTRIBUTE_RECORD_pack(&job->indirect,
+ attr_packed,
+ &attr_unpacked);
+ for (int j = 0; j < size; j++)
+ attr_packed[j] |= vtx->attrs[i * size + j];
+ cl_emit_prepacked(&job->indirect, &attr_packed);
}
cl_emit(&job->bcl, GL_SHADER_STATE, state) {
diff --git a/src/gallium/drivers/vc5/vc5_screen.h b/src/gallium/drivers/vc5/vc5_screen.h
index d804efa1bb7..28925d791c9 100644
--- a/src/gallium/drivers/vc5/vc5_screen.h
+++ b/src/gallium/drivers/vc5/vc5_screen.h
@@ -38,6 +38,7 @@ struct vc5_bo;
#define VC5_MAX_TEXTURE_SAMPLERS 32
#define VC5_MAX_SAMPLES 4
#define VC5_MAX_DRAW_BUFFERS 4
+#define VC5_MAX_ATTRIBUTES 16
struct vc5_simulator_file;
diff --git a/src/gallium/drivers/vc5/vc5_state.c b/src/gallium/drivers/vc5/vc5_state.c
index b289d20cb62..98426de977b 100644
--- a/src/gallium/drivers/vc5/vc5_state.c
+++ b/src/gallium/drivers/vc5/vc5_state.c
@@ -246,6 +246,72 @@ vc5_vertex_state_create(struct pipe_context *pctx, unsigned num_elements,
memcpy(so->pipe, elements, sizeof(*elements) * num_elements);
so->num_elements = num_elements;
+ for (int i = 0; i < so->num_elements; i++) {
+ const struct pipe_vertex_element *elem = &elements[i];
+ const struct util_format_description *desc =
+ util_format_description(elem->src_format);
+ uint32_t r_size = desc->channel[0].size;
+
+ struct V3D33_GL_SHADER_STATE_ATTRIBUTE_RECORD attr_unpacked = {
+ /* vec_size == 0 means 4 */
+ .vec_size = desc->nr_channels & 3,
+ .signed_int_type = (desc->channel[0].type ==
+ UTIL_FORMAT_TYPE_SIGNED),
+
+ .normalized_int_type = desc->channel[0].normalized,
+ .read_as_int_uint = desc->channel[0].pure_integer,
+ .instance_divisor = elem->instance_divisor,
+ };
+
+ switch (desc->channel[0].type) {
+ case UTIL_FORMAT_TYPE_FLOAT:
+ if (r_size == 32) {
+ attr_unpacked.type = ATTRIBUTE_FLOAT;
+ } else {
+ assert(r_size == 16);
+ attr_unpacked.type = ATTRIBUTE_HALF_FLOAT;
+ }
+ break;
+
+ case UTIL_FORMAT_TYPE_SIGNED:
+ case UTIL_FORMAT_TYPE_UNSIGNED:
+ switch (r_size) {
+ case 32:
+ attr_unpacked.type = ATTRIBUTE_INT;
+ break;
+ case 16:
+ attr_unpacked.type = ATTRIBUTE_SHORT;
+ break;
+ case 10:
+ attr_unpacked.type = ATTRIBUTE_INT2_10_10_10;
+ break;
+ case 8:
+ attr_unpacked.type = ATTRIBUTE_BYTE;
+ break;
+ default:
+ fprintf(stderr,
+ "format %s unsupported\n",
+ desc->name);
+ attr_unpacked.type = ATTRIBUTE_BYTE;
+ abort();
+ }
+ break;
+
+ default:
+ fprintf(stderr,
+ "format %s unsupported\n",
+ desc->name);
+ abort();
+ }
+
+ const uint32_t size =
+ cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD);
+ V3D33_GL_SHADER_STATE_ATTRIBUTE_RECORD_pack(NULL,
+ (uint8_t *)&so->attrs[i * size],
+ &attr_unpacked);
+ }
+
+
return so;
}