Commit 330d0607 authored by Marek Olšák's avatar Marek Olšák
Browse files

gallium: remove pipe_index_buffer and set_index_buffer

pipe_draw_info::indexed is replaced with index_size. index_size == 0 means
non-indexed.

Instead of pipe_index_buffer::offset, pipe_draw_info::start is used.
For indexed indirect draws, pipe_draw_info::start is added to the indirect
start. This is the only case when "start" affects indirect draws.

pipe_draw_info::index is a union. Use either index::resource or
index::user depending on the value of pipe_draw_info::has_user_indices.

v2: fixes for nine, svga
parent 22f6624e
......@@ -349,8 +349,6 @@ void cso_destroy_context( struct cso_context *ctx )
unsigned i;
if (ctx->pipe) {
ctx->pipe->set_index_buffer(ctx->pipe, NULL);
ctx->pipe->bind_blend_state( ctx->pipe, NULL );
ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL );
......@@ -1696,20 +1694,6 @@ cso_restore_state(struct cso_context *cso)
/* drawing */
void
cso_set_index_buffer(struct cso_context *cso,
const struct pipe_index_buffer *ib)
{
struct u_vbuf *vbuf = cso->vbuf;
if (vbuf) {
u_vbuf_set_index_buffer(vbuf, ib);
} else {
struct pipe_context *pipe = cso->pipe;
pipe->set_index_buffer(pipe, ib);
}
}
void
cso_draw_vbo(struct cso_context *cso,
const struct pipe_draw_info *info)
......
......@@ -221,10 +221,6 @@ void cso_restore_constant_buffer_slot0(struct cso_context *cso,
/* drawing */
void
cso_set_index_buffer(struct cso_context *cso,
const struct pipe_index_buffer *ib);
void
cso_draw_vbo(struct cso_context *cso,
const struct pipe_draw_info *info);
......
......@@ -777,9 +777,6 @@ void draw_set_render( struct draw_context *draw,
/**
* Tell the draw module where vertex indexes/elements are located, and
* their size (in bytes).
*
* Note: the caller must apply the pipe_index_buffer::offset value to
* the address. The draw module doesn't do that.
*/
void
draw_set_indexes(struct draw_context *draw,
......
......@@ -443,7 +443,7 @@ resolve_draw_info(const struct pipe_draw_info *raw_info,
info->count = target->internal_offset / vertex_buffer->stride;
/* Stream output draw can not be indexed */
debug_assert(!info->indexed);
debug_assert(!info->index_size);
info->max_index = info->count - 1;
}
}
......@@ -473,7 +473,7 @@ draw_vbo(struct draw_context *draw,
info = &resolved_info;
assert(info->instance_count > 0);
if (info->indexed)
if (info->index_size)
assert(draw->pt.user.elts);
count = info->count;
......@@ -481,7 +481,7 @@ draw_vbo(struct draw_context *draw,
draw->pt.user.eltBias = info->index_bias;
draw->pt.user.min_index = info->min_index;
draw->pt.user.max_index = info->max_index;
draw->pt.user.eltSize = info->indexed ? draw->pt.user.eltSizeIB : 0;
draw->pt.user.eltSize = info->index_size ? draw->pt.user.eltSizeIB : 0;
if (0)
debug_printf("draw_vbo(mode=%u start=%u count=%u):\n",
......
......@@ -33,7 +33,6 @@
*
* // emulate unsupported primitives:
* if (info->mode needs emulating) {
* util_primconvert_save_index_buffer(ctx->primconvert, &ctx->indexbuf);
* util_primconvert_save_rasterizer_state(ctx->primconvert, ctx->rasterizer);
* util_primconvert_draw_vbo(ctx->primconvert, info);
* return;
......@@ -53,7 +52,6 @@
struct primconvert_context
{
struct pipe_context *pipe;
struct pipe_index_buffer saved_ib;
uint32_t primtypes_mask;
unsigned api_pv;
};
......@@ -73,25 +71,9 @@ util_primconvert_create(struct pipe_context *pipe, uint32_t primtypes_mask)
void
util_primconvert_destroy(struct primconvert_context *pc)
{
util_primconvert_save_index_buffer(pc, NULL);
FREE(pc);
}
void
util_primconvert_save_index_buffer(struct primconvert_context *pc,
const struct pipe_index_buffer *ib)
{
if (ib) {
pipe_resource_reference(&pc->saved_ib.buffer, ib->buffer);
pc->saved_ib.index_size = ib->index_size;
pc->saved_ib.offset = ib->offset;
pc->saved_ib.user_buffer = ib->user_buffer;
}
else {
pipe_resource_reference(&pc->saved_ib.buffer, NULL);
}
}
void
util_primconvert_save_rasterizer_state(struct primconvert_context *pc,
const struct pipe_rasterizer_state
......@@ -108,18 +90,15 @@ void
util_primconvert_draw_vbo(struct primconvert_context *pc,
const struct pipe_draw_info *info)
{
struct pipe_index_buffer *ib = &pc->saved_ib;
struct pipe_index_buffer new_ib;
struct pipe_draw_info new_info;
struct pipe_transfer *src_transfer = NULL;
u_translate_func trans_func;
u_generate_func gen_func;
const void *src = NULL;
void *dst;
unsigned ib_offset;
memset(&new_ib, 0, sizeof(new_ib));
util_draw_init_info(&new_info);
new_info.indexed = true;
new_info.min_index = info->min_index;
new_info.max_index = info->max_index;
new_info.index_bias = info->index_bias;
......@@ -127,38 +106,43 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
new_info.instance_count = info->instance_count;
new_info.primitive_restart = info->primitive_restart;
new_info.restart_index = info->restart_index;
if (info->indexed) {
if (info->index_size) {
enum pipe_prim_type mode = 0;
unsigned index_size;
u_index_translator(pc->primtypes_mask,
info->mode, pc->saved_ib.index_size, info->count,
info->mode, info->index_size, info->count,
pc->api_pv, pc->api_pv,
info->primitive_restart ? PR_ENABLE : PR_DISABLE,
&mode, &new_ib.index_size, &new_info.count,
&mode, &index_size, &new_info.count,
&trans_func);
new_info.mode = mode;
src = ib->user_buffer;
new_info.index_size = index_size;
src = info->has_user_indices ? info->index.user : NULL;
if (!src) {
src = pipe_buffer_map(pc->pipe, ib->buffer,
src = pipe_buffer_map(pc->pipe, info->index.resource,
PIPE_TRANSFER_READ, &src_transfer);
}
src = (const uint8_t *)src + ib->offset;
src = (const uint8_t *)src;
}
else {
enum pipe_prim_type mode = 0;
unsigned index_size;
u_index_generator(pc->primtypes_mask,
info->mode, info->start, info->count,
pc->api_pv, pc->api_pv,
&mode, &new_ib.index_size, &new_info.count,
&mode, &index_size, &new_info.count,
&gen_func);
new_info.mode = mode;
new_info.index_size = index_size;
}
u_upload_alloc(pc->pipe->stream_uploader, 0, new_ib.index_size * new_info.count, 4,
&new_ib.offset, &new_ib.buffer, &dst);
u_upload_alloc(pc->pipe->stream_uploader, 0, new_info.index_size * new_info.count, 4,
&ib_offset, &new_info.index.resource, &dst);
new_info.start = ib_offset / new_info.index_size;
if (info->indexed) {
if (info->index_size) {
trans_func(src, info->start, info->count, new_info.count, info->restart_index, dst);
}
else {
......@@ -170,14 +154,8 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
u_upload_unmap(pc->pipe->stream_uploader);
/* bind new index buffer: */
pc->pipe->set_index_buffer(pc->pipe, &new_ib);
/* to the translated draw: */
pc->pipe->draw_vbo(pc->pipe, &new_info);
/* and then restore saved ib: */
pc->pipe->set_index_buffer(pc->pipe, ib);
pipe_resource_reference(&new_ib.buffer, NULL);
pipe_resource_reference(&new_info.index.resource, NULL);
}
......@@ -34,8 +34,6 @@ struct primconvert_context;
struct primconvert_context *util_primconvert_create(struct pipe_context *pipe,
uint32_t primtypes_mask);
void util_primconvert_destroy(struct primconvert_context *pc);
void util_primconvert_save_index_buffer(struct primconvert_context *pc,
const struct pipe_index_buffer *ib);
void util_primconvert_save_rasterizer_state(struct primconvert_context *pc,
const struct pipe_rasterizer_state
*rast);
......
......@@ -136,7 +136,7 @@ util_draw_indirect(struct pipe_context *pipe,
struct pipe_draw_info info;
struct pipe_transfer *transfer;
uint32_t *params;
const unsigned num_params = info_in->indexed ? 5 : 4;
const unsigned num_params = info_in->index_size ? 5 : 4;
assert(info_in->indirect);
assert(!info_in->count_from_stream_output);
......@@ -158,8 +158,8 @@ util_draw_indirect(struct pipe_context *pipe,
info.count = params[0];
info.instance_count = params[1];
info.start = params[2];
info.index_bias = info_in->indexed ? params[3] : 0;
info.start_instance = info_in->indexed ? params[4] : params[3];
info.index_bias = info_in->index_size ? params[3] : 0;
info.start_instance = info_in->index_size ? params[4] : params[3];
info.indirect = NULL;
pipe_buffer_unmap(pipe, transfer);
......
......@@ -67,15 +67,15 @@ util_draw_arrays(struct pipe_context *pipe,
}
static inline void
util_draw_elements(struct pipe_context *pipe, int index_bias,
enum pipe_prim_type mode,
util_draw_elements(struct pipe_context *pipe, unsigned index_size,
int index_bias, enum pipe_prim_type mode,
uint start,
uint count)
{
struct pipe_draw_info info;
util_draw_init_info(&info);
info.indexed = TRUE;
info.index_size = index_size;
info.mode = mode;
info.start = start;
info.count = count;
......@@ -108,6 +108,7 @@ util_draw_arrays_instanced(struct pipe_context *pipe,
static inline void
util_draw_elements_instanced(struct pipe_context *pipe,
unsigned index_size,
int index_bias,
enum pipe_prim_type mode,
uint start,
......@@ -118,7 +119,7 @@ util_draw_elements_instanced(struct pipe_context *pipe,
struct pipe_draw_info info;
util_draw_init_info(&info);
info.indexed = TRUE;
info.index_size = index_size;
info.mode = mode;
info.start = start;
info.count = count;
......
......@@ -172,9 +172,6 @@ void
util_dump_constant_buffer(FILE *stream,
const struct pipe_constant_buffer *state);
void
util_dump_index_buffer(FILE *stream, const struct pipe_index_buffer *state);
void
util_dump_vertex_buffer(FILE *stream,
const struct pipe_vertex_buffer *state);
......
......@@ -833,25 +833,6 @@ util_dump_constant_buffer(FILE *stream,
}
void
util_dump_index_buffer(FILE *stream, const struct pipe_index_buffer *state)
{
if (!state) {
util_dump_null(stream);
return;
}
util_dump_struct_begin(stream, "pipe_index_buffer");
util_dump_member(stream, uint, state, index_size);
util_dump_member(stream, uint, state, offset);
util_dump_member(stream, ptr, state, buffer);
util_dump_member(stream, ptr, state, user_buffer);
util_dump_struct_end(stream);
}
void
util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state)
{
......@@ -919,7 +900,8 @@ util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
util_dump_struct_begin(stream, "pipe_draw_info");
util_dump_member(stream, bool, state, indexed);
util_dump_member(stream, uint, state, index_size);
util_dump_member(stream, uint, state, has_user_indices);
util_dump_member(stream, enum_prim_mode, state, mode);
util_dump_member(stream, uint, state, start);
......@@ -939,6 +921,7 @@ util_dump_draw_info(FILE *stream, const struct pipe_draw_info *state)
util_dump_member(stream, bool, state, primitive_restart);
util_dump_member(stream, uint, state, restart_index);
util_dump_member(stream, ptr, state, index.resource);
util_dump_member(stream, ptr, state, count_from_stream_output);
if (!state->indirect) {
......
......@@ -98,48 +98,24 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst,
*dst_count = util_last_bit(enabled_buffers);
}
void
util_set_index_buffer(struct pipe_index_buffer *dst,
const struct pipe_index_buffer *src)
{
if (src) {
pipe_resource_reference(&dst->buffer, src->buffer);
memcpy(dst, src, sizeof(*dst));
}
else {
pipe_resource_reference(&dst->buffer, NULL);
memset(dst, 0, sizeof(*dst));
}
}
/**
* Given a user index buffer, save the structure to "saved", and upload it.
*/
bool
util_save_and_upload_index_buffer(struct pipe_context *pipe,
const struct pipe_draw_info *info,
const struct pipe_index_buffer *ib,
struct pipe_index_buffer *out_saved)
util_upload_index_buffer(struct pipe_context *pipe,
const struct pipe_draw_info *info,
struct pipe_resource **out_buffer,
unsigned *out_offset)
{
struct pipe_index_buffer new_ib = {0};
unsigned start_offset = info->start * ib->index_size;
unsigned start_offset = info->start * info->index_size;
u_upload_data(pipe->stream_uploader, start_offset,
info->count * ib->index_size, 4,
(char*)ib->user_buffer + start_offset,
&new_ib.offset, &new_ib.buffer);
if (!new_ib.buffer)
return false;
info->count * info->index_size, 4,
(char*)info->index.user + start_offset,
out_offset, out_buffer);
u_upload_unmap(pipe->stream_uploader);
new_ib.offset -= start_offset;
new_ib.index_size = ib->index_size;
util_set_index_buffer(out_saved, ib);
pipe->set_index_buffer(pipe, &new_ib);
pipe_resource_reference(&new_ib.buffer, NULL);
return true;
*out_offset -= start_offset;
return *out_buffer != NULL;
}
struct pipe_query *
......
......@@ -45,13 +45,10 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst,
const struct pipe_vertex_buffer *src,
unsigned start_slot, unsigned count);
void util_set_index_buffer(struct pipe_index_buffer *dst,
const struct pipe_index_buffer *src);
bool util_save_and_upload_index_buffer(struct pipe_context *pipe,
const struct pipe_draw_info *info,
const struct pipe_index_buffer *ib,
struct pipe_index_buffer *out_saved);
bool util_upload_index_buffer(struct pipe_context *pipe,
const struct pipe_draw_info *info,
struct pipe_resource **out_buffer,
unsigned *out_offset);
struct pipe_query *
util_begin_pipestat_query(struct pipe_context *ctx);
......
......@@ -27,7 +27,7 @@
/* Ubyte indices. */
void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
const struct pipe_index_buffer *ib,
const struct pipe_draw_info *info,
unsigned add_transfer_flags,
int index_bias,
unsigned start,
......@@ -39,10 +39,10 @@ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
unsigned short *out_map = out;
unsigned i;
if (ib->user_buffer) {
in_map = ib->user_buffer;
if (info->has_user_indices) {
in_map = info->index.user;
} else {
in_map = pipe_buffer_map(context, ib->buffer,
in_map = pipe_buffer_map(context, info->index.resource,
PIPE_TRANSFER_READ |
add_transfer_flags,
&src_transfer);
......@@ -62,7 +62,7 @@ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
/* Ushort indices. */
void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,
const struct pipe_index_buffer *ib,
const struct pipe_draw_info *info,
unsigned add_transfer_flags,
int index_bias,
unsigned start, unsigned count,
......@@ -73,10 +73,10 @@ void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,
unsigned short *out_map = out;
unsigned i;
if (ib->user_buffer) {
in_map = ib->user_buffer;
if (info->has_user_indices) {
in_map = info->index.user;
} else {
in_map = pipe_buffer_map(context, ib->buffer,
in_map = pipe_buffer_map(context, info->index.resource,
PIPE_TRANSFER_READ |
add_transfer_flags,
&in_transfer);
......@@ -96,7 +96,7 @@ void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,
/* Uint indices. */
void util_rebuild_uint_elts_to_userptr(struct pipe_context *context,
const struct pipe_index_buffer *ib,
const struct pipe_draw_info *info,
unsigned add_transfer_flags,
int index_bias,
unsigned start, unsigned count,
......@@ -107,10 +107,10 @@ void util_rebuild_uint_elts_to_userptr(struct pipe_context *context,
unsigned int *out_map = out;
unsigned i;
if (ib->user_buffer) {
in_map = ib->user_buffer;
if (info->has_user_indices) {
in_map = info->index.user;
} else {
in_map = pipe_buffer_map(context, ib->buffer,
in_map = pipe_buffer_map(context, info->index.resource,
PIPE_TRANSFER_READ |
add_transfer_flags,
&in_transfer);
......
......@@ -25,10 +25,9 @@
struct pipe_context;
struct pipe_resource;
struct pipe_index_buffer;
void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
const struct pipe_index_buffer *ib,
const struct pipe_draw_info *info,
unsigned add_transfer_flags,
int index_bias,
unsigned start,
......@@ -36,14 +35,14 @@ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
void *out);
void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,
const struct pipe_index_buffer *ib,
const struct pipe_draw_info *info,
unsigned add_transfer_flags,
int index_bias,
unsigned start, unsigned count,
void *out);
void util_rebuild_uint_elts_to_userptr(struct pipe_context *context,
const struct pipe_index_buffer *ib,
const struct pipe_draw_info *info,
unsigned add_transfer_flags,
int index_bias,
unsigned start, unsigned count,
......
......@@ -39,28 +39,26 @@
*/
enum pipe_error
util_translate_prim_restart_ib(struct pipe_context *context,
struct pipe_index_buffer *src_buffer,
struct pipe_resource **dst_buffer,
unsigned num_indexes,
unsigned restart_index)
const struct pipe_draw_info *info,
struct pipe_resource **dst_buffer)
{
struct pipe_screen *screen = context->screen;
struct pipe_transfer *src_transfer = NULL, *dst_transfer = NULL;
void *src_map = NULL, *dst_map = NULL;
const unsigned src_index_size = src_buffer->index_size;
const unsigned src_index_size = info->index_size;
unsigned dst_index_size;
/* 1-byte indexes are converted to 2-byte indexes, 4-byte stays 4-byte */
dst_index_size = MAX2(2, src_buffer->index_size);
dst_index_size = MAX2(2, info->index_size);
assert(dst_index_size == 2 || dst_index_size == 4);
/* no user buffers for now */
assert(src_buffer->user_buffer == NULL);
assert(!info->has_user_indices);
/* Create new index buffer */
*dst_buffer = pipe_buffer_create(screen, PIPE_BIND_INDEX_BUFFER,
PIPE_USAGE_STREAM,
num_indexes * dst_index_size);
info->count * dst_index_size);
if (!*dst_buffer)
goto error;
......@@ -71,9 +69,9 @@ util_translate_prim_restart_ib(struct pipe_context *context,
goto error;
/* Map original / src index buffer */
src_map = pipe_buffer_map_range(context, src_buffer->buffer,
src_buffer->offset,
num_indexes * src_index_size,
src_map = pipe_buffer_map_range(context, info->index.resource,
info->start * src_index_size,
info->count * src_index_size,
PIPE_TRANSFER_READ,
&src_transfer);
if (!src_map)
......@@ -83,16 +81,16 @@ util_translate_prim_restart_ib(struct pipe_context *context,
uint8_t *src = (uint8_t *) src_map;
uint16_t *dst = (uint16_t *) dst_map;
unsigned i;
for (i = 0; i < num_indexes; i++) {
dst[i] = (src[i] == restart_index) ? 0xffff : src[i];
for (i = 0; i < info->count; i++) {
dst[i] = (src[i] == info->restart_index) ? 0xffff : src[i];
}
}
else if (src_index_size == 2 && dst_index_size == 2) {
uint16_t *src = (uint16_t *) src_map;
uint16_t *dst = (uint16_t *) dst_map;
unsigned i;
for (i = 0; i < num_indexes; i++) {
dst[i] = (src[i] == restart_index) ? 0xffff : src[i];
for (i = 0; i < info->count; i++) {
dst[i] = (src[i] == info->restart_index) ? 0xffff : src[i];
}
}
else {
......@@ -101,8 +99,8 @@ util_translate_prim_restart_ib(struct pipe_context *context,
unsigned i;
assert(src_index_size == 4);
assert(dst_index_size == 4);
for (i = 0; i < num_indexes; i++) {
dst[i] = (src[i] == restart_index) ? 0xffffffff : src[i];
for (i = 0; i < info->count; i++) {
dst[i] = (src[i] == info->restart_index) ? 0xffffffff : src[i];
}
}
......@@ -177,7 +175,6 @@ add_range(struct range_info *info, unsigned start, unsigned count)
*/
enum pipe_error
util_draw_vbo_without_prim_restart(struct pipe_context *context,
const struct pipe_index_buffer *ib,
const struct pipe_draw_info *info)
{
const void *src_map;
......@@ -186,15 +183,15 @@ util_draw_vbo_without_prim_restart(struct pipe_context *context,
struct pipe_transfer *src_transfer = NULL;