Commit 22f60263 authored by Chia-I Wu's avatar Chia-I Wu

gallium: Use draw_set_index_buffer and others.

Update all drivers to use draw_set_index_buffer,
draw_set_mapped_index_buffer, and draw_vbo.  Remove
draw_set_mapped_element_buffer and draw_set_mapped_element_buffer_range.
parent 94e8d417
......@@ -518,48 +518,6 @@ draw_set_mapped_index_buffer(struct draw_context *draw,
}
/**
* Tell the drawing context about the index/element buffer to use
* (ala glDrawElements)
* If no element buffer is to be used (i.e. glDrawArrays) then this
* should be called with eltSize=0 and elements=NULL.
*
* \param draw the drawing context
* \param eltSize size of each element (1, 2 or 4 bytes)
* \param elements the element buffer ptr
*/
void
draw_set_mapped_element_buffer_range( struct draw_context *draw,
unsigned eltSize,
int eltBias,
unsigned min_index,
unsigned max_index,
const void *elements )
{
struct pipe_index_buffer ib;
memset(&ib, 0, sizeof(ib));
ib.index_size = eltSize;
draw_set_index_buffer(draw, &ib);
draw->pt.user.elts = elements;
draw->pt.user.eltBias = eltBias;
draw->pt.user.min_index = min_index;
draw->pt.user.max_index = max_index;
}
void
draw_set_mapped_element_buffer( struct draw_context *draw,
unsigned eltSize,
int eltBias,
const void *elements )
{
draw_set_mapped_element_buffer_range(draw,
eltSize, eltBias, 0, 0xffffffff, elements);
}
/* Revamp me please:
*/
void draw_do_flush( struct draw_context *draw, unsigned flags )
......
......@@ -166,19 +166,6 @@ void draw_set_index_buffer(struct draw_context *draw,
void draw_set_mapped_index_buffer(struct draw_context *draw,
const void *elements);
void
draw_set_mapped_element_buffer_range( struct draw_context *draw,
unsigned eltSize,
int eltBias,
unsigned min_index,
unsigned max_index,
const void *elements );
void draw_set_mapped_element_buffer( struct draw_context *draw,
unsigned eltSize,
int eltBias,
const void *elements );
void draw_set_mapped_vertex_buffer(struct draw_context *draw,
unsigned attr, const void *buffer);
......
......@@ -299,7 +299,6 @@ draw_arrays(struct draw_context *draw, unsigned prim,
/**
* Instanced drawing.
* draw_set_mapped_element_buffer must be called before calling this function.
* \sa draw_vbo
*/
void
......@@ -321,9 +320,10 @@ draw_arrays_instanced(struct draw_context *draw,
info.instance_count = instanceCount;
info.indexed = (draw->pt.user.elts != NULL);
info.index_bias = draw->pt.user.eltBias;
info.min_index = draw->pt.user.min_index;
info.max_index = draw->pt.user.max_index;
if (!info.indexed) {
info.min_index = start;
info.max_index = start + count - 1;
}
draw_vbo(draw, &info);
}
......
......@@ -78,20 +78,13 @@ cell_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
draw_set_mapped_vertex_buffer(draw, i, buf);
}
/* Map index buffer, if present */
if (info->indexed && cell->index_buffer.buffer) {
if (info->indexed && cell->index_buffer.buffer)
mapped_indices = cell_resource(cell->index_buffer.buffer)->data;
mapped_indices += cell->index_buffer.offset;
}
draw_set_mapped_element_buffer_range(draw, (mapped_indices) ?
lp->index_buffer.index_size : 0,
info->index_bias,
info->min_index,
info->max_index,
mapped_indices);
draw_set_mapped_index_buffer(draw, mapped_indices);
/* draw! */
draw_arrays(draw, info->mode, info->start, info->count);
draw_vbo(draw, info);
/*
* unmap vertex/index buffers - will cause draw module to flush
......@@ -100,7 +93,7 @@ cell_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (mapped_indices) {
draw_set_mapped_element_buffer(draw, 0, 0, NULL);
draw_set_mapped_index_buffer(draw, NULL);
}
/*
......
......@@ -102,7 +102,7 @@ cell_set_index_buffer(struct pipe_context *pipe,
else
memset(&cell->index_buffer, 0, sizeof(cell->index_buffer));
/* TODO make this more like a state */
draw_set_index_buffer(cell->draw, ib);
}
......
......@@ -66,18 +66,9 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
/*
* Map index buffer, if present
*/
if (info->indexed && i915->index_buffer.buffer) {
char *indices = (char *) i915_buffer(i915->index_buffer.buffer)->data;
mapped_indices = (void *) (indices + i915->index_buffer.offset);
}
draw_set_mapped_element_buffer_range(draw, (mapped_indices) ?
i915->index_buffer.index_size : 0,
info->index_bias,
info->min_index,
info->max_index,
mapped_indices);
if (info->indexed && i915->index_buffer.buffer)
mapped_indices = i915_buffer(i915->index_buffer.buffer)->data;
draw_set_mapped_index_buffer(draw, mapped_indices);
draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
i915->current.constants[PIPE_SHADER_VERTEX],
......@@ -87,7 +78,7 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
/*
* Do the drawing
*/
draw_arrays(i915->draw, info->mode, info->start, info->count);
draw_vbo(i915->draw, info);
/*
* unmap vertex/index buffers
......@@ -96,9 +87,8 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (mapped_indices) {
draw_set_mapped_element_buffer(draw, 0, 0, NULL);
}
if (mapped_indices)
draw_set_mapped_index_buffer(draw, NULL);
}
......
......@@ -817,7 +817,8 @@ static void i915_set_index_buffer(struct pipe_context *pipe,
else
memset(&i915->index_buffer, 0, sizeof(i915->index_buffer));
/* TODO make this more like a state */
/* pass-through to draw module */
draw_set_index_buffer(i915->draw, ib);
}
static void
......
......@@ -68,25 +68,17 @@ llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
}
/* Map index buffer, if present */
if (info->indexed && lp->index_buffer.buffer) {
char *indices = (char *) llvmpipe_resource_data(lp->index_buffer.buffer);
mapped_indices = (void *) (indices + lp->index_buffer.offset);
}
if (info->indexed && lp->index_buffer.buffer)
mapped_indices = llvmpipe_resource_data(lp->index_buffer.buffer);
draw_set_mapped_element_buffer_range(draw, (mapped_indices) ?
lp->index_buffer.index_size : 0,
info->index_bias,
info->min_index,
info->max_index,
mapped_indices);
draw_set_mapped_index_buffer(draw, mapped_indices);
llvmpipe_prepare_vertex_sampling(lp,
lp->num_vertex_sampler_views,
lp->vertex_sampler_views);
/* draw! */
draw_arrays_instanced(draw, info->mode, info->start, info->count,
info->start_instance, info->instance_count);
draw_vbo(draw, info);
/*
* unmap vertex/index buffers
......@@ -95,7 +87,7 @@ llvmpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (mapped_indices) {
draw_set_mapped_element_buffer(draw, 0, 0, NULL);
draw_set_mapped_index_buffer(draw, NULL);
}
llvmpipe_cleanup_vertex_sampling(lp);
......
......@@ -100,7 +100,7 @@ llvmpipe_set_index_buffer(struct pipe_context *pipe,
else
memset(&llvmpipe->index_buffer, 0, sizeof(llvmpipe->index_buffer));
/* TODO make this more like a state */
draw_set_index_buffer(llvmpipe->draw, ib);
}
void
......
......@@ -239,12 +239,10 @@ nvfx_draw_vbo_swtnl(struct pipe_context *pipe, const struct pipe_draw_info* info
draw_set_mapped_vertex_buffer(nvfx->draw, i, map);
}
if (info->indexed) {
map = nvfx_buffer(nvfx->idxbuf.buffer)->data + nvfx->idxbuf.offset;
draw_set_mapped_element_buffer_range(nvfx->draw, nvfx->idxbuf.index_size, info->index_bias, info->min_index, info->max_index, map);
} else {
draw_set_mapped_element_buffer(nvfx->draw, 0, 0, NULL);
}
map = NULL;
if (info->indexed && nvfx->idxbuf.buffer)
map = nvfx_buffer(nvfx->idxbuf.buffer)->data;
draw_set_mapped_index_buffer(nvfx->draw, map);
if (nvfx->constbuf[PIPE_SHADER_VERTEX]) {
const unsigned nr = nvfx->constbuf_nr[PIPE_SHADER_VERTEX];
......@@ -254,7 +252,7 @@ nvfx_draw_vbo_swtnl(struct pipe_context *pipe, const struct pipe_draw_info* info
map, nr);
}
draw_arrays_instanced(nvfx->draw, info->mode, info->start, info->count, info->start_instance, info->instance_count);
draw_vbo(nvfx->draw, info);
draw_flush(nvfx->draw);
}
......
......@@ -335,6 +335,9 @@ nvfx_state_validate_swtnl(struct nvfx_context *nvfx)
draw_set_vertex_elements(draw, nvfx->vtxelt->num_elements, nvfx->vtxelt->pipe);
}
if (nvfx->draw_dirty & NVFX_NEW_INDEX)
draw_set_index_buffer(draw, &nvfx->idxbuf);
nvfx_state_validate_common(nvfx);
nvfx->draw_dirty = 0;
......
......@@ -680,18 +680,11 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
if (info->indexed && r300->index_buffer.buffer) {
indices = pipe_buffer_map(pipe, r300->index_buffer.buffer,
PIPE_TRANSFER_READ, &ib_transfer);
if (indices)
indices = (void *) ((char *) indices + r300->index_buffer.offset);
}
draw_set_mapped_element_buffer_range(r300->draw, (indices) ?
r300->index_buffer.index_size : 0,
info->index_bias,
info->min_index,
info->max_index,
indices);
draw_set_mapped_index_buffer(r300->draw, indices);
draw_arrays(r300->draw, info->mode, info->start, count);
draw_vbo(r300->draw, info);
/* XXX Not sure whether this is the best fix.
* It prevents CS from being rejected and weird assertion failures. */
......@@ -707,8 +700,7 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
if (ib_transfer) {
pipe_buffer_unmap(pipe, r300->index_buffer.buffer, ib_transfer);
draw_set_mapped_element_buffer_range(r300->draw, 0, 0, info->start,
info->start + count - 1, NULL);
draw_set_mapped_index_buffer(r300->draw, NULL);
}
}
......
......@@ -1556,7 +1556,12 @@ static void r300_set_index_buffer(struct pipe_context* pipe,
memset(&r300->index_buffer, 0, sizeof(r300->index_buffer));
}
/* TODO make this more like a state */
if (r300->screen->caps.has_tcl) {
/* TODO make this more like a state */
}
else {
draw_set_index_buffer(r300->draw, ib);
}
}
/* Initialize the PSC tables. */
......
......@@ -75,14 +75,10 @@ softpipe_draw_stream_output(struct pipe_context *pipe, unsigned mode)
buf = (void*)((int32_t*)buf + offset);
draw_set_mapped_vertex_buffer(draw, 0, buf);
draw_set_mapped_element_buffer_range(draw,
0, 0,
start,
start + count - 1,
NULL);
draw_set_mapped_index_buffer(draw, NULL);
/* draw! */
draw_arrays_instanced(draw, mode, start, count, 0, 1);
draw_arrays(draw, mode, start, count);
/* unmap vertex/index buffers - will cause draw module to flush */
draw_set_mapped_vertex_buffer(draw, 0, NULL);
......@@ -138,28 +134,20 @@ softpipe_draw_vbo(struct pipe_context *pipe,
}
/* Map index buffer, if present */
if (info->indexed && sp->index_buffer.buffer) {
char *indices = (char *) softpipe_resource(sp->index_buffer.buffer)->data;
mapped_indices = (void *) (indices + sp->index_buffer.offset);
}
if (info->indexed && sp->index_buffer.buffer)
mapped_indices = softpipe_resource(sp->index_buffer.buffer)->data;
draw_set_mapped_element_buffer_range(draw, (mapped_indices) ?
sp->index_buffer.index_size : 0,
info->index_bias,
info->min_index,
info->max_index,
mapped_indices);
draw_set_mapped_index_buffer(draw, mapped_indices);
/* draw! */
draw_arrays_instanced(draw, info->mode, info->start, info->count,
info->start_instance, info->instance_count);
draw_vbo(draw, info);
/* unmap vertex/index buffers - will cause draw module to flush */
for (i = 0; i < sp->num_vertex_buffers; i++) {
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (mapped_indices) {
draw_set_mapped_element_buffer(draw, 0, 0, NULL);
draw_set_mapped_index_buffer(draw, NULL);
}
/*
......
......@@ -100,5 +100,5 @@ softpipe_set_index_buffer(struct pipe_context *pipe,
else
memset(&softpipe->index_buffer, 0, sizeof(softpipe->index_buffer));
/* TODO make this more like a state */
draw_set_index_buffer(softpipe->draw, ib);
}
......@@ -71,22 +71,17 @@ svga_swtnl_draw_vbo(struct svga_context *svga,
draw_set_mapped_vertex_buffer(draw, i, map);
}
/* TODO move this to update_swtnl_draw */
draw_set_index_buffer(draw, &svga->curr.ib);
/* Map index buffer, if present */
map = NULL;
if (info->indexed && svga->curr.ib.buffer) {
map = pipe_buffer_map(&svga->pipe, svga->curr.ib.buffer,
PIPE_TRANSFER_READ,
&ib_transfer);
if (map)
map = (const void *) ((const char *) map + svga->curr.ib.offset);
}
draw_set_mapped_element_buffer_range(draw, (map) ?
svga->curr.ib.index_size : 0,
info->index_bias,
info->min_index,
info->max_index,
map);
draw_set_mapped_index_buffer(draw, map);
if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
map = pipe_buffer_map(&svga->pipe,
......@@ -100,7 +95,7 @@ svga_swtnl_draw_vbo(struct svga_context *svga,
svga->curr.cb[PIPE_SHADER_VERTEX]->width0);
}
draw_arrays(draw, info->mode, info->start, info->count);
draw_vbo(draw, info);
draw_flush(svga->swtnl.draw);
......@@ -118,7 +113,7 @@ svga_swtnl_draw_vbo(struct svga_context *svga,
if (ib_transfer) {
pipe_buffer_unmap(&svga->pipe, svga->curr.ib.buffer, ib_transfer);
draw_set_mapped_element_buffer(draw, 0, 0, NULL);
draw_set_mapped_index_buffer(draw, NULL);
}
if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
......
......@@ -40,6 +40,7 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_draw.h"
#include "draw/draw_private.h"
#include "draw/draw_context.h"
......@@ -104,14 +105,15 @@ st_feedback_draw_vbo(GLcontext *ctx,
struct draw_context *draw = st->draw;
const struct st_vertex_program *vp;
const struct pipe_shader_state *vs;
struct pipe_resource *index_buffer_handle = 0;
struct pipe_vertex_buffer vbuffers[PIPE_MAX_SHADER_INPUTS];
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
struct pipe_index_buffer ibuffer;
struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS];
struct pipe_transfer *ib_transfer = NULL;
struct pipe_transfer *cb_transfer;
GLuint attr, i;
ubyte *mapped_constants;
const void *mapped_indices = NULL;
assert(draw);
......@@ -204,17 +206,19 @@ st_feedback_draw_vbo(GLcontext *ctx,
draw_set_vertex_buffers(draw, vp->num_inputs, vbuffers);
draw_set_vertex_elements(draw, vp->num_inputs, velements);
memset(&ibuffer, 0, sizeof(ibuffer));
if (ib) {
struct gl_buffer_object *bufobj = ib->obj;
unsigned indexSize;
void *map;
switch (ib->type) {
case GL_UNSIGNED_INT:
indexSize = 4;
ibuffer.index_size = 4;
break;
case GL_UNSIGNED_SHORT:
indexSize = 2;
ibuffer.index_size = 2;
break;
case GL_UNSIGNED_BYTE:
ibuffer.index_size = 1;
break;
default:
assert(0);
......@@ -224,23 +228,20 @@ st_feedback_draw_vbo(GLcontext *ctx,
if (bufobj && bufobj->Name) {
struct st_buffer_object *stobj = st_buffer_object(bufobj);
index_buffer_handle = stobj->buffer;
map = pipe_buffer_map(pipe, index_buffer_handle,
PIPE_TRANSFER_READ, &ib_transfer);
pipe_resource_reference(&ibuffer.buffer, stobj->buffer);
ibuffer.offset = pointer_to_offset(ib->ptr);
draw_set_mapped_element_buffer(draw, indexSize, 0, map);
mapped_indices = pipe_buffer_map(pipe, stobj->buffer,
PIPE_TRANSFER_READ, &ib_transfer);
}
else {
draw_set_mapped_element_buffer(draw, indexSize, 0, (void *) ib->ptr);
ib_transfer = NULL;
/* skip setting ibuffer.buffer as the draw module does not use it */
mapped_indices = ib->ptr;
}
}
else {
/* no index/element buffer */
draw_set_mapped_element_buffer(draw, 0, 0, NULL);
}
draw_set_index_buffer(draw, &ibuffer);
draw_set_mapped_index_buffer(draw, mapped_indices);
}
/* map constant buffers */
mapped_constants = pipe_buffer_map(pipe,
......@@ -273,9 +274,14 @@ st_feedback_draw_vbo(GLcontext *ctx,
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
}
if (index_buffer_handle) {
pipe_buffer_unmap(pipe, index_buffer_handle, ib_transfer);
draw_set_mapped_element_buffer(draw, 0, 0, NULL);
if (ib) {
draw_set_mapped_index_buffer(draw, NULL);
draw_set_index_buffer(draw, NULL);
if (ib_transfer)
pipe_buffer_unmap(pipe, ibuffer.buffer, ib_transfer);
pipe_resource_reference(&ibuffer.buffer, NULL);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment