[Mesa-dev] [PATCH 05/11] st/mesa: Make feedback draw and rasterpos use _DrawVAO.
Mathias.Froehlich at gmx.net
Mathias.Froehlich at gmx.net
Mon May 7 06:14:59 UTC 2018
From: Mathias Fröhlich <mathias.froehlich at web.de>
Instead of playing with Array._DrawArrays, make the feedback draw
path use Array._DrawVAO. Also st_RasterPos needs to use the VAO then.
v2: Use helper methods to get the offset values for array and binding.
Update comments.
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
src/mesa/state_tracker/st_cb_rasterpos.c | 43 ++++++++++-------------------
src/mesa/state_tracker/st_draw_feedback.c | 46 ++++++-------------------------
2 files changed, 24 insertions(+), 65 deletions(-)
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index b73d543653..cf4718f8cb 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -38,9 +38,11 @@
#include "main/imports.h"
#include "main/macros.h"
+#include "main/arrayobj.h"
#include "main/feedback.h"
#include "main/rastpos.h"
-#include "glformats.h"
+#include "main/state.h"
+#include "main/varray.h"
#include "st_context.h"
#include "st_atom.h"
@@ -61,9 +63,7 @@ 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];
+ struct gl_vertex_array_object *VAO;
struct _mesa_prim prim;
};
@@ -103,6 +103,8 @@ rastpos_line( struct draw_stage *stage, struct prim_header *prim )
static void
rastpos_destroy(struct draw_stage *stage)
{
+ struct rastpos_stage *rstage = (struct rastpos_stage*)stage;
+ _mesa_reference_vao(rstage->ctx, &rstage->VAO, NULL);
free(stage);
}
@@ -182,8 +184,6 @@ static struct rastpos_stage *
new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw)
{
struct rastpos_stage *rs = ST_CALLOC_STRUCT(rastpos_stage);
- GLuint i;
- GLuint elementSize;
rs->stage.draw = draw;
rs->stage.next = NULL;
@@ -196,20 +196,11 @@ 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;
-
- elementSize = _mesa_bytes_per_vertex_attrib(4, GL_FLOAT);
- for (i = 0; i < ARRAY_SIZE(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->attrib[i]._ElementSize = elementSize;
- rs->array[i].BufferBinding = &rs->binding;
- rs->array[i].VertexAttrib = &rs->attrib[i];
- }
+ rs->VAO = _mesa_new_vao(ctx, ~((GLuint)0));
+ _mesa_vertex_attrib_binding(ctx, rs->VAO, VERT_ATTRIB_POS, 0, false);
+ _mesa_update_array_format(ctx, rs->VAO, VERT_ATTRIB_POS, 4, GL_FLOAT,
+ GL_RGBA, GL_FALSE, GL_FALSE, GL_FALSE, 0);
+ _mesa_enable_vertex_array_attrib(ctx, rs->VAO, 0, false);
rs->prim.mode = GL_POINTS;
rs->prim.indexed = 0;
@@ -229,7 +220,6 @@ 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;
if (!st->draw)
return;
@@ -265,16 +255,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->attrib[0].Ptr = (GLubyte *) v;
+ rs->VAO->VertexAttrib[VERT_ATTRIB_POS].Ptr = (GLubyte *) v;
+ rs->VAO->NewArrays |= VERT_BIT_POS;
+ _mesa_set_draw_vao(ctx, rs->VAO, VERT_BIT_POS);
- /* Draw the point.
- *
- * Don't set DriverFlags.NewArray.
- * st_feedback_draw_vbo doesn't check for that flag. */
- ctx->Array._DrawArrays = rs->array;
+ /* Draw the point. */
st_feedback_draw_vbo(ctx, &rs->prim, 1, NULL, GL_TRUE, 0, 1,
NULL, 0, NULL);
- ctx->Array._DrawArrays = saved_arrays;
/* restore draw's rasterization stage depending on rendermode */
if (ctx->RenderMode == GL_FEEDBACK) {
diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c
index fa96b4e2e2..eb05ac9669 100644
--- a/src/mesa/state_tracker/st_draw_feedback.c
+++ b/src/mesa/state_tracker/st_draw_feedback.c
@@ -26,6 +26,7 @@
**************************************************************************/
#include "main/imports.h"
+#include "main/arrayobj.h"
#include "main/image.h"
#include "main/macros.h"
#include "main/varray.h"
@@ -131,9 +132,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;
GLuint attr, i;
- const GLubyte *low_addr = NULL;
const void *mapped_indices = NULL;
if (!draw)
@@ -168,56 +167,28 @@ st_feedback_draw_vbo(struct gl_context *ctx,
draw_bind_vertex_shader(draw, st->vp_variant->draw_shader);
set_feedback_vertex_format(ctx);
- /* Find the lowest address of the arrays we're drawing */
- if (vp->num_inputs) {
- 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;
- 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);
- }
- }
-
/* loop over TGSI shader inputs to determine vertex buffer
* and attribute info
*/
for (attr = 0; attr < vp->num_inputs; attr++) {
const GLuint mesaAttr = vp->index_to_input[attr];
- 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;
+ _mesa_draw_attrib_and_binding(ctx, mesaAttr, &attrib, &binding);
- if (bufobj && bufobj->Name) {
- /* 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.
- */
- struct st_buffer_object *stobj = st_buffer_object(bufobj);
+ if (_mesa_is_bufferobj(binding->BufferObj)) {
+ /* Attribute data is in a VBO. */
+ struct st_buffer_object *stobj = st_buffer_object(binding->BufferObj);
assert(stobj->buffer);
vbuffers[attr].buffer.resource = NULL;
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 = binding->Offset
- + attrib->RelativeOffset - pointer_to_offset(low_addr);
+ vbuffers[attr].buffer_offset = _mesa_draw_binding_offset(binding);
+ velements[attr].src_offset =
+ _mesa_draw_attributes_relative_offset(attrib);
/* map the attrib buffer */
map = pipe_buffer_map(pipe, vbuffers[attr].buffer.resource,
@@ -227,6 +198,7 @@ st_feedback_draw_vbo(struct gl_context *ctx,
vbuffers[attr].buffer.resource->width0);
}
else {
+ /* Attribute data is in a user space array. */
vbuffers[attr].buffer.user = attrib->Ptr;
vbuffers[attr].is_user_buffer = true;
vbuffers[attr].buffer_offset = 0;
--
2.14.3
More information about the mesa-dev
mailing list