summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2018-03-04 18:15:53 +0100
committerMathias Fröhlich <[email protected]>2018-03-10 07:33:51 +0100
commit64d2a20480547d5897fd9d7b8fd306f2625138cb (patch)
tree15d831310fe0a2e2ff7d3c58eac8fceecc738f15 /src/mesa/state_tracker
parentd62f0df3541ab9ee7a4999f0ecedc52f8d1ab8cc (diff)
mesa: Make gl_vertex_array contain pointers to first order VAO members.
Instead of keeping a copy of the vertex array content in struct gl_vertex_array only keep pointers to the first order information originaly in the VAO. For that represent the current values by struct gl_array_attributes and struct gl_vertex_buffer_binding. v2: Change comments. Remove gl... prefix from variables except in the i965 directory where it was like that before. Reindent because of that. Reviewed-by: Brian Paul <[email protected]> Signed-off-by: Mathias Fröhlich <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_atom.c7
-rw-r--r--src/mesa/state_tracker/st_atom_array.c115
-rw-r--r--src/mesa/state_tracker/st_cb_rasterpos.c26
-rw-r--r--src/mesa/state_tracker/st_draw_feedback.c46
4 files changed, 123 insertions, 71 deletions
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c
index b597c62632e..45a45960a30 100644
--- a/src/mesa/state_tracker/st_atom.c
+++ b/src/mesa/state_tracker/st_atom.c
@@ -138,7 +138,8 @@ static void check_program_state( struct st_context *st )
static void check_attrib_edgeflag(struct st_context *st)
{
- const struct gl_vertex_array **arrays = st->ctx->Array._DrawArrays;
+ const struct gl_vertex_array *arrays = st->ctx->Array._DrawArrays;
+ const struct gl_vertex_buffer_binding *binding;
GLboolean vertdata_edgeflags, edgeflag_culls_prims, edgeflags_enabled;
struct gl_program *vp = st->ctx->VertexProgram._Current;
@@ -148,8 +149,8 @@ static void check_attrib_edgeflag(struct st_context *st)
edgeflags_enabled = st->ctx->Polygon.FrontMode != GL_FILL ||
st->ctx->Polygon.BackMode != GL_FILL;
- vertdata_edgeflags = edgeflags_enabled &&
- arrays[VERT_ATTRIB_EDGEFLAG]->StrideB != 0;
+ binding = arrays[VERT_ATTRIB_EDGEFLAG].BufferBinding;
+ vertdata_edgeflags = edgeflags_enabled && binding->Stride != 0;
if (vertdata_edgeflags != st->vertdata_edgeflags) {
st->vertdata_edgeflags = vertdata_edgeflags;
if (vp)
diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c
index 6af1355ee17..ff7a5d07467 100644
--- a/src/mesa/state_tracker/st_atom_array.c
+++ b/src/mesa/state_tracker/st_atom_array.c
@@ -47,6 +47,7 @@
#include "util/u_upload_mgr.h"
#include "main/bufferobj.h"
#include "main/glformats.h"
+#include "main/varray.h"
/* vertex_formats[gltype - GL_BYTE][integer*2 + normalized][size - 1] */
static const uint16_t vertex_formats[][4][4] = {
@@ -301,13 +302,13 @@ st_pipe_vertex_format(GLenum type, GLuint size, GLenum format,
}
static const struct gl_vertex_array *
-get_client_array(const struct gl_vertex_array **arrays,
+get_client_array(const struct gl_vertex_array *arrays,
unsigned mesaAttr)
{
/* st_program uses 0xffffffff to denote a double placeholder attribute */
if (mesaAttr == ST_DOUBLE_ATTRIB_PLACEHOLDER)
return NULL;
- return arrays[mesaAttr];
+ return &arrays[mesaAttr];
}
/**
@@ -316,7 +317,7 @@ get_client_array(const struct gl_vertex_array **arrays,
*/
static GLboolean
is_interleaved_arrays(const struct st_vertex_program *vp,
- const struct gl_vertex_array **arrays,
+ const struct gl_vertex_array *arrays,
unsigned num_inputs)
{
GLuint attr;
@@ -327,6 +328,9 @@ is_interleaved_arrays(const struct st_vertex_program *vp,
for (attr = 0; attr < num_inputs; attr++) {
const struct gl_vertex_array *array;
+ const struct gl_vertex_buffer_binding *binding;
+ const struct gl_array_attributes *attrib;
+ const GLubyte *ptr;
const struct gl_buffer_object *bufObj;
GLsizei stride;
@@ -334,19 +338,22 @@ is_interleaved_arrays(const struct st_vertex_program *vp,
if (!array)
continue;
- stride = array->StrideB; /* in bytes */
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+ stride = binding->Stride; /* in bytes */
+ ptr = _mesa_vertex_attrib_address(attrib, binding);
/* To keep things simple, don't allow interleaved zero-stride attribs. */
if (stride == 0)
return false;
- bufObj = array->BufferObj;
+ bufObj = binding->BufferObj;
if (attr == 0) {
/* save info about the first array */
firstStride = stride;
- firstPtr = array->Ptr;
+ firstPtr = ptr;
firstBufObj = bufObj;
- userSpaceBuffer = !bufObj || !bufObj->Name;
+ userSpaceBuffer = !_mesa_is_bufferobj(bufObj);
}
else {
/* check if other arrays interleave with the first, in same buffer */
@@ -356,7 +363,7 @@ is_interleaved_arrays(const struct st_vertex_program *vp,
if (bufObj != firstBufObj)
return GL_FALSE; /* arrays in different VBOs */
- if (llabs(array->Ptr - firstPtr) > firstStride)
+ if (llabs(ptr - firstPtr) > firstStride)
return GL_FALSE; /* arrays start too far apart */
if ((!_mesa_is_bufferobj(bufObj)) != userSpaceBuffer)
@@ -454,7 +461,7 @@ set_vertex_attribs(struct st_context *st,
static void
setup_interleaved_attribs(struct st_context *st,
const struct st_vertex_program *vp,
- const struct gl_vertex_array **arrays,
+ const struct gl_vertex_array *arrays,
unsigned num_inputs)
{
struct pipe_vertex_buffer vbuffer;
@@ -470,25 +477,32 @@ setup_interleaved_attribs(struct st_context *st,
*/
if (num_inputs) {
const struct gl_vertex_array *array;
+ const struct gl_vertex_buffer_binding *binding;
+ const struct gl_array_attributes *attrib;
array = get_client_array(arrays, vp->index_to_input[0]);
assert(array);
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+
/* 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;
+ bufobj = binding->BufferObj;
+ stride = binding->Stride;
- low_addr = arrays[vp->index_to_input[0]]->Ptr;
+ low_addr = _mesa_vertex_attrib_address(attrib, binding);
for (attr = 1; attr < num_inputs; attr++) {
const GLubyte *start;
array = get_client_array(arrays, vp->index_to_input[attr]);
if (!array)
continue;
- start = array->Ptr;
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+ start = _mesa_vertex_attrib_address(attrib, binding);
low_addr = MIN2(low_addr, start);
}
}
@@ -504,25 +518,32 @@ setup_interleaved_attribs(struct st_context *st,
for (attr = 0; attr < num_inputs;) {
const struct gl_vertex_array *array;
+ const struct gl_vertex_buffer_binding *binding;
+ const struct gl_array_attributes *attrib;
+ const GLubyte *ptr;
unsigned src_offset;
unsigned src_format;
array = get_client_array(arrays, vp->index_to_input[attr]);
assert(array);
- src_offset = (unsigned) (array->Ptr - low_addr);
- assert(array->_ElementSize ==
- _mesa_bytes_per_vertex_attrib(array->Size, array->Type));
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+ ptr = _mesa_vertex_attrib_address(attrib, binding);
+
+ src_offset = (unsigned) (ptr - low_addr);
+ assert(attrib->_ElementSize ==
+ _mesa_bytes_per_vertex_attrib(attrib->Size, attrib->Type));
- src_format = st_pipe_vertex_format(array->Type,
- array->Size,
- array->Format,
- array->Normalized,
- array->Integer);
+ src_format = st_pipe_vertex_format(attrib->Type,
+ attrib->Size,
+ attrib->Format,
+ attrib->Normalized,
+ attrib->Integer);
init_velement_lowered(vp, velements, src_offset, src_format,
- array->InstanceDivisor, 0,
- array->Size, array->Doubles, &attr);
+ binding->InstanceDivisor, 0,
+ attrib->Size, attrib->Doubles, &attr);
}
/*
@@ -573,7 +594,7 @@ setup_interleaved_attribs(struct st_context *st,
static void
setup_non_interleaved_attribs(struct st_context *st,
const struct st_vertex_program *vp,
- const struct gl_vertex_array **arrays,
+ const struct gl_vertex_array *arrays,
unsigned num_inputs)
{
struct gl_context *ctx = st->ctx;
@@ -586,6 +607,8 @@ setup_non_interleaved_attribs(struct st_context *st,
for (attr = 0; attr < num_inputs;) {
const unsigned mesaAttr = vp->index_to_input[attr];
const struct gl_vertex_array *array;
+ const struct gl_vertex_buffer_binding *binding;
+ const struct gl_array_attributes *attrib;
struct gl_buffer_object *bufobj;
GLsizei stride;
unsigned src_format;
@@ -596,10 +619,12 @@ setup_non_interleaved_attribs(struct st_context *st,
bufidx = num_vbuffers++;
- stride = array->StrideB;
- bufobj = array->BufferObj;
- assert(array->_ElementSize ==
- _mesa_bytes_per_vertex_attrib(array->Size, array->Type));
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+ stride = binding->Stride;
+ bufobj = binding->BufferObj;
+ assert(attrib->_ElementSize ==
+ _mesa_bytes_per_vertex_attrib(attrib->Size, attrib->Type));
if (_mesa_is_bufferobj(bufobj)) {
/* Attribute data is in a VBO.
@@ -615,17 +640,21 @@ setup_non_interleaved_attribs(struct st_context *st,
vbuffer[bufidx].buffer.resource = stobj->buffer;
vbuffer[bufidx].is_user_buffer = false;
- vbuffer[bufidx].buffer_offset = pointer_to_offset(array->Ptr);
+ vbuffer[bufidx].buffer_offset =
+ binding->Offset + attrib->RelativeOffset;
}
else {
if (stride == 0) {
- unsigned size = array->_ElementSize;
+ unsigned size = attrib->_ElementSize;
/* This is optimal for GPU cache line usage if the upload size
* is <= cache line size.
*/
unsigned alignment = util_next_power_of_two(size);
- void *ptr = array->Ptr ? (void*)array->Ptr :
- (void*)ctx->Current.Attrib[mesaAttr];
+
+ assert(attrib->Ptr);
+ vbuffer[bufidx].buffer.user = attrib->Ptr;
+ void *ptr = attrib->Ptr ? (void*)attrib->Ptr :
+ (void*)ctx->Current.Attrib[mesaAttr];
vbuffer[bufidx].is_user_buffer = false;
vbuffer[bufidx].buffer.resource = NULL;
@@ -646,12 +675,12 @@ setup_non_interleaved_attribs(struct st_context *st,
&vbuffer[bufidx].buffer.resource);
unref_buffers |= 1u << bufidx;
} else {
- assert(array->Ptr);
- vbuffer[bufidx].buffer.user = array->Ptr;
+ assert(attrib->Ptr);
+ vbuffer[bufidx].buffer.user = attrib->Ptr;
vbuffer[bufidx].is_user_buffer = true;
vbuffer[bufidx].buffer_offset = 0;
- if (!array->InstanceDivisor)
+ if (!binding->InstanceDivisor)
st->draw_needs_minmax_index = true;
}
}
@@ -659,15 +688,15 @@ setup_non_interleaved_attribs(struct st_context *st,
/* common-case setup */
vbuffer[bufidx].stride = stride; /* in bytes */
- src_format = st_pipe_vertex_format(array->Type,
- array->Size,
- array->Format,
- array->Normalized,
- array->Integer);
+ src_format = st_pipe_vertex_format(attrib->Type,
+ attrib->Size,
+ attrib->Format,
+ attrib->Normalized,
+ attrib->Integer);
init_velement_lowered(vp, velements, 0, src_format,
- array->InstanceDivisor, bufidx,
- array->Size, array->Doubles, &attr);
+ binding->InstanceDivisor, bufidx,
+ attrib->Size, attrib->Doubles, &attr);
}
if (!ctx->Const.AllowMappedBuffersDuringExecution) {
@@ -686,7 +715,7 @@ setup_non_interleaved_attribs(struct st_context *st,
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 gl_vertex_array *arrays = ctx->Array._DrawArrays;
const struct st_vertex_program *vp;
unsigned num_inputs;
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index e266296a775..4e5417baada 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -60,8 +60,9 @@ struct rastpos_stage
struct gl_context *ctx; /**< Rendering context */
/* vertex attrib info we can setup once and re-use */
+ struct gl_vertex_buffer_binding binding;
+ struct gl_array_attributes attrib[VERT_ATTRIB_MAX];
struct gl_vertex_array array[VERT_ATTRIB_MAX];
- const struct gl_vertex_array *arrays[VERT_ATTRIB_MAX];
struct _mesa_prim prim;
};
@@ -193,15 +194,16 @@ new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw)
rs->stage.destroy = rastpos_destroy;
rs->ctx = ctx;
+ rs->binding.Stride = 0;
+ rs->binding.BufferObj = NULL;
for (i = 0; i < ARRAY_SIZE(rs->array); i++) {
- rs->array[i].Size = 4;
- rs->array[i].Type = GL_FLOAT;
- rs->array[i].Format = GL_RGBA;
- rs->array[i].StrideB = 0;
- rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i];
- rs->array[i].Normalized = GL_TRUE;
- rs->array[i].BufferObj = NULL;
- rs->arrays[i] = &rs->array[i];
+ rs->attrib[i].Size = 4;
+ rs->attrib[i].Type = GL_FLOAT;
+ rs->attrib[i].Format = GL_RGBA;
+ rs->attrib[i].Ptr = (GLubyte *) ctx->Current.Attrib[i];
+ rs->attrib[i].Normalized = GL_TRUE;
+ rs->array[i].BufferBinding = &rs->binding;
+ rs->array[i].VertexAttrib = &rs->attrib[i];
}
rs->prim.mode = GL_POINTS;
@@ -222,7 +224,7 @@ st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
struct st_context *st = st_context(ctx);
struct draw_context *draw = st_get_draw_context(st);
struct rastpos_stage *rs;
- const struct gl_vertex_array **saved_arrays = ctx->Array._DrawArrays;
+ const struct gl_vertex_array *saved_arrays = ctx->Array._DrawArrays;
if (!st->draw)
return;
@@ -258,13 +260,13 @@ st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
/* All vertex attribs but position were previously initialized above.
* Just plug in position pointer now.
*/
- rs->array[0].Ptr = (GLubyte *) v;
+ rs->attrib[0].Ptr = (GLubyte *) v;
/* Draw the point.
*
* Don't set DriverFlags.NewArray.
* st_feedback_draw_vbo doesn't check for that flag. */
- ctx->Array._DrawArrays = rs->arrays;
+ ctx->Array._DrawArrays = rs->array;
st_feedback_draw_vbo(ctx, &rs->prim, 1, NULL, GL_TRUE, 0, 1,
NULL, 0, NULL);
ctx->Array._DrawArrays = saved_arrays;
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index 987a1564e28..46a12848c0d 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -28,6 +28,7 @@
#include "main/imports.h"
#include "main/image.h"
#include "main/macros.h"
+#include "main/varray.h"
#include "vbo/vbo.h"
@@ -130,7 +131,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = {NULL};
struct pipe_transfer *ib_transfer = NULL;
- const struct gl_vertex_array **arrays = ctx->Array._DrawArrays;
+ const struct gl_vertex_array *arrays = ctx->Array._DrawArrays;
GLuint attr, i;
const GLubyte *low_addr = NULL;
const void *mapped_indices = NULL;
@@ -169,10 +170,21 @@ st_feedback_draw_vbo(struct gl_context *ctx,
/* Find the lowest address of the arrays we're drawing */
if (vp->num_inputs) {
- low_addr = arrays[vp->index_to_input[0]]->Ptr;
+ const struct gl_vertex_array *array;
+ const struct gl_vertex_buffer_binding *binding;
+ const struct gl_array_attributes *attrib;
+ array = &arrays[vp->index_to_input[0]];
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+
+ low_addr = _mesa_vertex_attrib_address(attrib, binding);
for (attr = 1; attr < vp->num_inputs; attr++) {
- const GLubyte *start = arrays[vp->index_to_input[attr]]->Ptr;
+ const GLubyte *start;
+ array = &arrays[vp->index_to_input[attr]];
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+ start = _mesa_vertex_attrib_address(attrib, binding);
low_addr = MIN2(low_addr, start);
}
}
@@ -182,9 +194,16 @@ st_feedback_draw_vbo(struct gl_context *ctx,
*/
for (attr = 0; attr < vp->num_inputs; attr++) {
const GLuint mesaAttr = vp->index_to_input[attr];
- struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj;
+ const struct gl_vertex_array *array = &arrays[mesaAttr];
+ const struct gl_vertex_buffer_binding *binding;
+ const struct gl_array_attributes *attrib;
+ struct gl_buffer_object *bufobj;
void *map;
+ binding = array->BufferBinding;
+ attrib = array->VertexAttrib;
+ bufobj = binding->BufferObj;
+
if (bufobj && bufobj->Name) {
/* Attribute data is in a VBO.
* Recall that for VBOs, the gl_vertex_array->Ptr field is
@@ -197,7 +216,8 @@ st_feedback_draw_vbo(struct gl_context *ctx,
vbuffers[attr].is_user_buffer = false;
pipe_resource_reference(&vbuffers[attr].buffer.resource, stobj->buffer);
vbuffers[attr].buffer_offset = pointer_to_offset(low_addr);
- velements[attr].src_offset = arrays[mesaAttr]->Ptr - low_addr;
+ velements[attr].src_offset = binding->Offset
+ + attrib->RelativeOffset - pointer_to_offset(low_addr);
/* map the attrib buffer */
map = pipe_buffer_map(pipe, vbuffers[attr].buffer.resource,
@@ -207,7 +227,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
vbuffers[attr].buffer.resource->width0);
}
else {
- vbuffers[attr].buffer.user = arrays[mesaAttr]->Ptr;
+ vbuffers[attr].buffer.user = attrib->Ptr;
vbuffers[attr].is_user_buffer = true;
vbuffers[attr].buffer_offset = 0;
velements[attr].src_offset = 0;
@@ -217,15 +237,15 @@ st_feedback_draw_vbo(struct gl_context *ctx,
}
/* common-case setup */
- vbuffers[attr].stride = arrays[mesaAttr]->StrideB; /* in bytes */
+ vbuffers[attr].stride = binding->Stride; /* in bytes */
velements[attr].instance_divisor = 0;
velements[attr].vertex_buffer_index = attr;
- velements[attr].src_format =
- st_pipe_vertex_format(arrays[mesaAttr]->Type,
- arrays[mesaAttr]->Size,
- arrays[mesaAttr]->Format,
- arrays[mesaAttr]->Normalized,
- arrays[mesaAttr]->Integer);
+ velements[attr].src_format =
+ st_pipe_vertex_format(attrib->Type,
+ attrib->Size,
+ attrib->Format,
+ attrib->Normalized,
+ attrib->Integer);
assert(velements[attr].src_format);
/* tell draw about this attribute */