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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user