[Mesa-dev] [PATCH 10/17] st/mesa: fold cso calls into setup_(non_)interleaved_attribs
Marek Olšák
maraeo at gmail.com
Mon May 1 12:52:59 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
---
src/mesa/state_tracker/st_atom_array.c | 91 +++++++++++++++++-----------------
1 file changed, 45 insertions(+), 46 deletions(-)
diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c
index be8c13c..57f0ec1 100644
--- a/src/mesa/state_tracker/st_atom_array.c
+++ b/src/mesa/state_tracker/st_atom_array.c
@@ -416,34 +416,53 @@ static void init_velement_lowered(struct st_context *st,
idx++;
}
} else {
init_velement(&velements[idx], src_offset,
format, instance_divisor, vbo_index);
idx++;
}
*attr_idx = idx;
}
+static void
+set_vertex_attribs(struct st_context *st,
+ struct pipe_vertex_buffer *vbuffers,
+ unsigned num_vbuffers,
+ struct pipe_vertex_element *velements,
+ unsigned num_velements)
+{
+ struct cso_context *cso = st->cso_context;
+
+ cso_set_vertex_buffers(cso, 0, num_vbuffers, vbuffers);
+ if (st->last_num_vbuffers > num_vbuffers) {
+ /* Unbind remaining buffers, if any. */
+ cso_set_vertex_buffers(cso, num_vbuffers,
+ st->last_num_vbuffers - num_vbuffers, NULL);
+ }
+ st->last_num_vbuffers = num_vbuffers;
+ cso_set_vertex_elements(cso, num_velements, velements);
+}
+
/**
* Set up for drawing interleaved arrays that all live in one VBO
* or all live in user space.
* \param vbuffer returns vertex buffer info
* \param velements returns vertex element info
*/
static boolean
setup_interleaved_attribs(struct st_context *st,
const struct st_vertex_program *vp,
const struct st_vp_variant *vpv,
- const struct gl_vertex_array **arrays,
- struct pipe_vertex_buffer *vbuffer,
- struct pipe_vertex_element velements[])
+ const struct gl_vertex_array **arrays)
{
+ struct pipe_vertex_buffer vbuffer;
+ struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS] = {{0}};
GLuint attr;
const GLubyte *low_addr = NULL;
GLboolean usingVBO; /* all arrays in a VBO? */
struct gl_buffer_object *bufobj;
GLsizei stride;
/* Find the lowest address of the arrays we're drawing,
* Init bufobj and stride.
*/
if (vpv->num_inputs) {
@@ -501,80 +520,81 @@ setup_interleaved_attribs(struct st_context *st,
init_velement_lowered(st, vp, velements, src_offset, src_format,
array->InstanceDivisor, 0,
array->Size, array->Doubles, &attr);
}
/*
* Return the vbuffer info and setup user-space attrib info, if needed.
*/
if (vpv->num_inputs == 0) {
/* just defensive coding here */
- vbuffer->buffer.resource = NULL;
- vbuffer->is_user_buffer = false;
- vbuffer->buffer_offset = 0;
- vbuffer->stride = 0;
+ vbuffer.buffer.resource = NULL;
+ vbuffer.is_user_buffer = false;
+ vbuffer.buffer_offset = 0;
+ vbuffer.stride = 0;
}
else if (usingVBO) {
/* all interleaved arrays in a VBO */
struct st_buffer_object *stobj = st_buffer_object(bufobj);
if (!stobj || !stobj->buffer) {
return FALSE; /* out-of-memory error probably */
}
- vbuffer->buffer.resource = stobj->buffer;
- vbuffer->is_user_buffer = false;
- vbuffer->buffer_offset = pointer_to_offset(low_addr);
- vbuffer->stride = stride;
+ vbuffer.buffer.resource = stobj->buffer;
+ vbuffer.is_user_buffer = false;
+ vbuffer.buffer_offset = pointer_to_offset(low_addr);
+ vbuffer.stride = stride;
}
else {
/* all interleaved arrays in user memory */
- vbuffer->buffer.user = low_addr;
- vbuffer->is_user_buffer = !!low_addr; /* if NULL, then unbind */
- vbuffer->buffer_offset = 0;
- vbuffer->stride = stride;
+ vbuffer.buffer.user = low_addr;
+ vbuffer.is_user_buffer = !!low_addr; /* if NULL, then unbind */
+ vbuffer.buffer_offset = 0;
+ vbuffer.stride = stride;
}
+
+ set_vertex_attribs(st, &vbuffer, vpv->num_inputs ? 1 : 0,
+ velements, vpv->num_inputs);
return TRUE;
}
/**
* Set up a separate pipe_vertex_buffer and pipe_vertex_element for each
* vertex attribute.
* \param vbuffer returns vertex buffer info
* \param velements returns vertex element info
*/
static boolean
setup_non_interleaved_attribs(struct st_context *st,
const struct st_vertex_program *vp,
const struct st_vp_variant *vpv,
- const struct gl_vertex_array **arrays,
- struct pipe_vertex_buffer vbuffer[],
- struct pipe_vertex_element velements[],
- unsigned *num_vbuffers)
+ const struct gl_vertex_array **arrays)
{
struct gl_context *ctx = st->ctx;
+ struct pipe_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS];
+ struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS] = {{0}};
+ unsigned num_vbuffers = 0;
GLuint attr;
- *num_vbuffers = 0;
-
for (attr = 0; attr < vpv->num_inputs;) {
const GLuint mesaAttr = vp->index_to_input[attr];
const struct gl_vertex_array *array;
struct gl_buffer_object *bufobj;
GLsizei stride;
unsigned src_format;
unsigned bufidx;
array = get_client_array(vp, arrays, attr);
assert(array);
- bufidx = (*num_vbuffers)++;
+ bufidx = num_vbuffers++;
stride = array->StrideB;
bufobj = array->BufferObj;
assert(array->_ElementSize ==
_mesa_bytes_per_vertex_attrib(array->Size, array->Type));
if (_mesa_is_bufferobj(bufobj)) {
/* Attribute data is in a VBO.
* Recall that for VBOs, the gl_vertex_array->Ptr field is
* really an offset from the start of the VBO, not a pointer.
@@ -616,65 +636,44 @@ setup_non_interleaved_attribs(struct st_context *st,
array->Size,
array->Format,
array->Normalized,
array->Integer);
init_velement_lowered(st, vp, velements, 0, src_format,
array->InstanceDivisor, bufidx,
array->Size, array->Doubles, &attr);
}
+ set_vertex_attribs(st, vbuffer, num_vbuffers, velements, vpv->num_inputs);
return TRUE;
}
void st_update_array(struct st_context *st)
{
struct gl_context *ctx = st->ctx;
const struct gl_vertex_array **arrays = ctx->Array._DrawArrays;
const struct st_vertex_program *vp;
const struct st_vp_variant *vpv;
- struct pipe_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS];
- struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
- unsigned num_vbuffers;
st->vertex_array_out_of_memory = FALSE;
/* No drawing has been done yet, so do nothing. */
if (!arrays)
return;
/* vertex program validation must be done before this */
vp = st->vp;
vpv = st->vp_variant;
- memset(velements, 0, sizeof(struct pipe_vertex_element) * vpv->num_inputs);
-
- /*
- * Setup the vbuffer[] and velements[] arrays.
- */
if (is_interleaved_arrays(vp, vpv, arrays)) {
- if (!setup_interleaved_attribs(st, vp, vpv, arrays, vbuffer, velements)) {
+ if (!setup_interleaved_attribs(st, vp, vpv, arrays)) {
st->vertex_array_out_of_memory = TRUE;
return;
}
-
- num_vbuffers = 1;
- if (vpv->num_inputs == 0)
- num_vbuffers = 0;
}
else {
- if (!setup_non_interleaved_attribs(st, vp, vpv, arrays, vbuffer,
- velements, &num_vbuffers)) {
+ if (!setup_non_interleaved_attribs(st, vp, vpv, arrays)) {
st->vertex_array_out_of_memory = TRUE;
return;
}
}
-
- cso_set_vertex_buffers(st->cso_context, 0, num_vbuffers, vbuffer);
- if (st->last_num_vbuffers > num_vbuffers) {
- /* Unbind remaining buffers, if any. */
- cso_set_vertex_buffers(st->cso_context, num_vbuffers,
- st->last_num_vbuffers - num_vbuffers, NULL);
- }
- st->last_num_vbuffers = num_vbuffers;
- cso_set_vertex_elements(st->cso_context, vpv->num_inputs, velements);
}
--
2.7.4
More information about the mesa-dev
mailing list