[Mesa-dev] [PATCH 12/17] st/mesa: remove vpv->num_inputs dereferences in st_update_array
Marek Olšák
maraeo at gmail.com
Mon May 1 12:53:01 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
---
src/mesa/state_tracker/st_atom_array.c | 40 +++++++++++++++++-----------------
1 file changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c
index cb6e355..3e6e3c1 100644
--- a/src/mesa/state_tracker/st_atom_array.c
+++ b/src/mesa/state_tracker/st_atom_array.c
@@ -310,30 +310,30 @@ get_client_array(const struct st_vertex_program *vp,
return NULL;
return arrays[mesaAttr];
}
/**
* Examine the active arrays to determine if we have interleaved
* vertex arrays all living in one VBO, or all living in user space.
*/
static GLboolean
is_interleaved_arrays(const struct st_vertex_program *vp,
- const struct st_vp_variant *vpv,
- const struct gl_vertex_array **arrays)
+ const struct gl_vertex_array **arrays,
+ unsigned num_inputs)
{
GLuint attr;
const struct gl_buffer_object *firstBufObj = NULL;
GLint firstStride = -1;
const GLubyte *firstPtr = NULL;
GLboolean userSpaceBuffer = GL_FALSE;
- for (attr = 0; attr < vpv->num_inputs; attr++) {
+ for (attr = 0; attr < num_inputs; attr++) {
const struct gl_vertex_array *array;
const struct gl_buffer_object *bufObj;
GLsizei stride;
array = get_client_array(vp, arrays, attr);
if (!array)
continue;
stride = array->StrideB; /* in bytes */
bufObj = array->BufferObj;
@@ -444,69 +444,69 @@ set_vertex_attribs(struct st_context *st,
/**
* 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 void
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)
+ const struct gl_vertex_array **arrays,
+ unsigned num_inputs)
{
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) {
+ if (num_inputs) {
const struct gl_vertex_array *array;
array = get_client_array(vp, arrays, 0);
assert(array);
/* Since we're doing interleaved arrays, we know there'll be at most
* one buffer object and the stride will be the same for all arrays.
* Grab them now.
*/
bufobj = array->BufferObj;
stride = array->StrideB;
low_addr = arrays[vp->index_to_input[0]]->Ptr;
- for (attr = 1; attr < vpv->num_inputs; attr++) {
+ for (attr = 1; attr < num_inputs; attr++) {
const GLubyte *start;
array = get_client_array(vp, arrays, attr);
if (!array)
continue;
start = array->Ptr;
low_addr = MIN2(low_addr, start);
}
}
else {
/* not sure we'll ever have zero inputs, but play it safe */
bufobj = NULL;
stride = 0;
low_addr = 0;
}
/* are the arrays in user space? */
usingVBO = _mesa_is_bufferobj(bufobj);
- for (attr = 0; attr < vpv->num_inputs;) {
+ for (attr = 0; attr < num_inputs;) {
const struct gl_vertex_array *array;
unsigned src_offset;
unsigned src_format;
array = get_client_array(vp, arrays, attr);
assert(array);
src_offset = (unsigned) (array->Ptr - low_addr);
assert(array->_ElementSize ==
_mesa_bytes_per_vertex_attrib(array->Size, array->Type));
@@ -518,21 +518,21 @@ setup_interleaved_attribs(struct st_context *st,
array->Integer);
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) {
+ if (num_inputs == 0) {
/* just defensive coding here */
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);
@@ -547,43 +547,43 @@ setup_interleaved_attribs(struct st_context *st,
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;
}
- set_vertex_attribs(st, &vbuffer, vpv->num_inputs ? 1 : 0,
- velements, vpv->num_inputs);
+ set_vertex_attribs(st, &vbuffer, num_inputs ? 1 : 0,
+ velements, num_inputs);
}
/**
* 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 void
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)
+ const struct gl_vertex_array **arrays,
+ unsigned num_inputs)
{
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;
- for (attr = 0; attr < vpv->num_inputs;) {
+ for (attr = 0; attr < 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);
@@ -637,35 +637,35 @@ 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);
+ set_vertex_attribs(st, vbuffer, num_vbuffers, velements, num_inputs);
}
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;
+ unsigned num_inputs;
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;
+ num_inputs = st->vp_variant->num_inputs;
- if (is_interleaved_arrays(vp, vpv, arrays))
- setup_interleaved_attribs(st, vp, vpv, arrays);
+ if (is_interleaved_arrays(vp, arrays, num_inputs))
+ setup_interleaved_attribs(st, vp, arrays, num_inputs);
else
- setup_non_interleaved_attribs(st, vp, vpv, arrays);
+ setup_non_interleaved_attribs(st, vp, arrays, num_inputs);
}
--
2.7.4
More information about the mesa-dev
mailing list