diff options
author | Marek Olšák <[email protected]> | 2017-04-02 14:30:16 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2017-05-10 19:00:16 +0200 |
commit | c24c3b94ed29ecd99b1101c74c6c4606f9b5580e (patch) | |
tree | 81f6966bc59a68d9867693c65d35fae9bb1d9819 /src/gallium/auxiliary/util | |
parent | fe437882ea2d60e91c244cc95beb4b79c615af49 (diff) |
gallium: decrease the size of pipe_vertex_buffer - 24 -> 16 bytes
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.c | 17 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_blitter.h | 6 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_draw.c | 8 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_draw_quad.c | 5 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_dump_state.c | 4 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_helpers.c | 17 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_inlines.h | 19 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_vbuf.c | 80 |
8 files changed, 86 insertions, 70 deletions
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c index 447d8d2281f..13fa9651392 100644 --- a/src/gallium/auxiliary/util/u_blitter.c +++ b/src/gallium/auxiliary/util/u_blitter.c @@ -539,7 +539,7 @@ void util_blitter_restore_vertex_states(struct blitter_context *blitter) /* Vertex buffer. */ pipe->set_vertex_buffers(pipe, ctx->base.vb_slot, 1, &ctx->base.saved_vertex_buffer); - pipe_resource_reference(&ctx->base.saved_vertex_buffer.buffer, NULL); + pipe_vertex_buffer_unreference(&ctx->base.saved_vertex_buffer); /* Vertex elements. */ pipe->bind_vertex_elements_state(pipe, ctx->base.saved_velem_state); @@ -1209,15 +1209,15 @@ static void blitter_draw(struct blitter_context_priv *ctx, vb.stride = 8 * sizeof(float); u_upload_data(pipe->stream_uploader, 0, sizeof(ctx->vertices), 4, ctx->vertices, - &vb.buffer_offset, &vb.buffer); - if (!vb.buffer) + &vb.buffer_offset, &vb.buffer.resource); + if (!vb.buffer.resource) return; u_upload_unmap(pipe->stream_uploader); pipe->set_vertex_buffers(pipe, ctx->base.vb_slot, 1, &vb); util_draw_arrays_instanced(pipe, PIPE_PRIM_TRIANGLE_FAN, 0, 4, 0, num_instances); - pipe_resource_reference(&vb.buffer, NULL); + pipe_resource_reference(&vb.buffer.resource, NULL); } void util_blitter_draw_rectangle(struct blitter_context *blitter, @@ -2199,7 +2199,8 @@ void util_blitter_copy_buffer(struct blitter_context *blitter, blitter_check_saved_vertex_states(ctx); blitter_disable_render_cond(ctx); - vb.buffer = src; + vb.is_user_buffer = false; + vb.buffer.resource = src; vb.buffer_offset = srcx; vb.stride = 4; @@ -2259,8 +2260,8 @@ void util_blitter_clear_buffer(struct blitter_context *blitter, } u_upload_data(pipe->stream_uploader, 0, num_channels*4, 4, clear_value, - &vb.buffer_offset, &vb.buffer); - if (!vb.buffer) + &vb.buffer_offset, &vb.buffer.resource); + if (!vb.buffer.resource) goto out; vb.stride = 0; @@ -2291,7 +2292,7 @@ out: util_blitter_restore_render_cond(blitter); util_blitter_unset_running_flag(blitter); pipe_so_target_reference(&so_target, NULL); - pipe_resource_reference(&vb.buffer, NULL); + pipe_resource_reference(&vb.buffer.resource, NULL); } /* probably radeon specific */ diff --git a/src/gallium/auxiliary/util/u_blitter.h b/src/gallium/auxiliary/util/u_blitter.h index f47c3dd07e9..fd4fe7a233a 100644 --- a/src/gallium/auxiliary/util/u_blitter.h +++ b/src/gallium/auxiliary/util/u_blitter.h @@ -503,10 +503,8 @@ static inline void util_blitter_save_vertex_buffer_slot(struct blitter_context *blitter, struct pipe_vertex_buffer *vertex_buffers) { - pipe_resource_reference(&blitter->saved_vertex_buffer.buffer, - vertex_buffers[blitter->vb_slot].buffer); - memcpy(&blitter->saved_vertex_buffer, &vertex_buffers[blitter->vb_slot], - sizeof(struct pipe_vertex_buffer)); + pipe_vertex_buffer_reference(&blitter->saved_vertex_buffer, + &vertex_buffers[blitter->vb_slot]); } static inline void diff --git a/src/gallium/auxiliary/util/u_draw.c b/src/gallium/auxiliary/util/u_draw.c index b9f8fcd3c2a..ca786489786 100644 --- a/src/gallium/auxiliary/util/u_draw.c +++ b/src/gallium/auxiliary/util/u_draw.c @@ -62,13 +62,13 @@ util_draw_max_index( const struct util_format_description *format_desc; unsigned format_size; - if (!buffer->buffer) { + if (buffer->is_user_buffer || !buffer->buffer.resource) { continue; } - assert(buffer->buffer->height0 == 1); - assert(buffer->buffer->depth0 == 1); - buffer_size = buffer->buffer->width0; + assert(buffer->buffer.resource->height0 == 1); + assert(buffer->buffer.resource->depth0 == 1); + buffer_size = buffer->buffer.resource->width0; format_desc = util_format_description(element->src_format); assert(format_desc->block.width == 1); diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c index ce3fa41d9b0..fe9558e6c90 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.c +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -54,7 +54,7 @@ util_draw_vertex_buffer(struct pipe_context *pipe, /* tell pipe about the vertex buffer */ memset(&vbuffer, 0, sizeof(vbuffer)); - vbuffer.buffer = vbuf; + vbuffer.buffer.resource = vbuf; vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ vbuffer.buffer_offset = offset; @@ -82,7 +82,8 @@ util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer, assert(num_attribs <= PIPE_MAX_ATTRIBS); - vbuffer.user_buffer = buffer; + vbuffer.is_user_buffer = true; + vbuffer.buffer.user = buffer; vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ /* note: vertex elements already set by caller */ diff --git a/src/gallium/auxiliary/util/u_dump_state.c b/src/gallium/auxiliary/util/u_dump_state.c index bf27a4e0eea..b9e6b522589 100644 --- a/src/gallium/auxiliary/util/u_dump_state.c +++ b/src/gallium/auxiliary/util/u_dump_state.c @@ -863,9 +863,9 @@ util_dump_vertex_buffer(FILE *stream, const struct pipe_vertex_buffer *state) util_dump_struct_begin(stream, "pipe_vertex_buffer"); util_dump_member(stream, uint, state, stride); + util_dump_member(stream, bool, state, is_user_buffer); util_dump_member(stream, uint, state, buffer_offset); - util_dump_member(stream, ptr, state, buffer); - util_dump_member(stream, ptr, state, user_buffer); + util_dump_member(stream, ptr, state, buffer.resource); util_dump_struct_end(stream); } diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c index 5b46fa1351f..f91cb0c158d 100644 --- a/src/gallium/auxiliary/util/u_helpers.c +++ b/src/gallium/auxiliary/util/u_helpers.c @@ -51,10 +51,13 @@ void util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst, if (src) { for (i = 0; i < count; i++) { - if (src[i].buffer || src[i].user_buffer) { + if (src[i].buffer.resource) bitmask |= 1 << i; - } - pipe_resource_reference(&dst[i].buffer, src[i].buffer); + + pipe_vertex_buffer_unreference(&dst[i]); + + if (!src[i].is_user_buffer) + pipe_resource_reference(&dst[i].buffer.resource, src[i].buffer.resource); } /* Copy over the other members of pipe_vertex_buffer. */ @@ -65,10 +68,8 @@ void util_set_vertex_buffers_mask(struct pipe_vertex_buffer *dst, } else { /* Unreference the buffers. */ - for (i = 0; i < count; i++) { - pipe_resource_reference(&dst[i].buffer, NULL); - dst[i].user_buffer = NULL; - } + for (i = 0; i < count; i++) + pipe_vertex_buffer_unreference(&dst[i]); *enabled_buffers &= ~(((1ull << count) - 1) << start_slot); } @@ -87,7 +88,7 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst, uint32_t enabled_buffers = 0; for (i = 0; i < *dst_count; i++) { - if (dst[i].buffer || dst[i].user_buffer) + if (dst[i].buffer.resource) enabled_buffers |= (1ull << i); } diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index 6bc5e6660f9..6a3d5043cf2 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -188,6 +188,25 @@ pipe_so_target_reference(struct pipe_stream_output_target **ptr, } static inline void +pipe_vertex_buffer_unreference(struct pipe_vertex_buffer *dst) +{ + if (dst->is_user_buffer) + dst->buffer.user = NULL; + else + pipe_resource_reference(&dst->buffer.resource, NULL); +} + +static inline void +pipe_vertex_buffer_reference(struct pipe_vertex_buffer *dst, + const struct pipe_vertex_buffer *src) +{ + pipe_vertex_buffer_unreference(dst); + if (!src->is_user_buffer) + pipe_resource_reference(&dst->buffer.resource, src->buffer.resource); + memcpy(dst, src, sizeof(*src)); +} + +static inline void pipe_surface_reset(struct pipe_context *ctx, struct pipe_surface* ps, struct pipe_resource *pt, unsigned level, unsigned layer) { diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c index f040f4a882d..62b88acca58 100644 --- a/src/gallium/auxiliary/util/u_vbuf.c +++ b/src/gallium/auxiliary/util/u_vbuf.c @@ -377,13 +377,12 @@ void u_vbuf_destroy(struct u_vbuf *mgr) mgr->pipe->set_vertex_buffers(mgr->pipe, 0, num_vb, NULL); - for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { - pipe_resource_reference(&mgr->vertex_buffer[i].buffer, NULL); - } - for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { - pipe_resource_reference(&mgr->real_vertex_buffer[i].buffer, NULL); - } - pipe_resource_reference(&mgr->aux_vertex_buffer_saved.buffer, NULL); + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) + pipe_vertex_buffer_unreference(&mgr->vertex_buffer[i]); + for (i = 0; i < PIPE_MAX_ATTRIBS; i++) + pipe_vertex_buffer_unreference(&mgr->real_vertex_buffer[i]); + + pipe_vertex_buffer_unreference(&mgr->aux_vertex_buffer_saved); translate_cache_destroy(mgr->translate_cache); cso_cache_delete(mgr->cso_cache); @@ -417,17 +416,17 @@ u_vbuf_translate_buffers(struct u_vbuf *mgr, struct translate_key *key, vb = &mgr->vertex_buffer[i]; offset = vb->buffer_offset + vb->stride * start_vertex; - if (vb->user_buffer) { - map = (uint8_t*)vb->user_buffer + offset; + if (vb->is_user_buffer) { + map = (uint8_t*)vb->buffer.user + offset; } else { unsigned size = vb->stride ? num_vertices * vb->stride : sizeof(double)*4; - if (offset+size > vb->buffer->width0) { - size = vb->buffer->width0 - offset; + if (offset+size > vb->buffer.resource->width0) { + size = vb->buffer.resource->width0 - offset; } - map = pipe_buffer_map_range(mgr->pipe, vb->buffer, offset, size, + map = pipe_buffer_map_range(mgr->pipe, vb->buffer.resource, offset, size, PIPE_TRANSFER_READ, &vb_transfer[i]); } @@ -510,8 +509,8 @@ u_vbuf_translate_buffers(struct u_vbuf *mgr, struct translate_key *key, /* Move the buffer reference. */ pipe_resource_reference( - &mgr->real_vertex_buffer[out_vb].buffer, NULL); - mgr->real_vertex_buffer[out_vb].buffer = out_buffer; + &mgr->real_vertex_buffer[out_vb].buffer.resource, NULL); + mgr->real_vertex_buffer[out_vb].buffer.resource = out_buffer; return PIPE_OK; } @@ -721,7 +720,7 @@ static void u_vbuf_translate_end(struct u_vbuf *mgr) for (i = 0; i < VB_NUM; i++) { unsigned vb = mgr->fallback_vbs[i]; if (vb != ~0u) { - pipe_resource_reference(&mgr->real_vertex_buffer[vb].buffer, NULL); + pipe_resource_reference(&mgr->real_vertex_buffer[vb].buffer.resource, NULL); mgr->fallback_vbs[i] = ~0; /* This will cause the buffer to be unbound in the driver later. */ @@ -830,8 +829,8 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, for (i = 0; i < count; i++) { unsigned dst_index = start_slot + i; - pipe_resource_reference(&mgr->vertex_buffer[dst_index].buffer, NULL); - pipe_resource_reference(&mgr->real_vertex_buffer[dst_index].buffer, + pipe_vertex_buffer_unreference(&mgr->vertex_buffer[dst_index]); + pipe_resource_reference(&mgr->real_vertex_buffer[dst_index].buffer.resource, NULL); } @@ -845,18 +844,13 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, struct pipe_vertex_buffer *orig_vb = &mgr->vertex_buffer[dst_index]; struct pipe_vertex_buffer *real_vb = &mgr->real_vertex_buffer[dst_index]; - if (!vb->buffer && !vb->user_buffer) { - pipe_resource_reference(&orig_vb->buffer, NULL); - pipe_resource_reference(&real_vb->buffer, NULL); - real_vb->user_buffer = NULL; + if (!vb->buffer.resource) { + pipe_vertex_buffer_unreference(orig_vb); + pipe_vertex_buffer_unreference(real_vb); continue; } - pipe_resource_reference(&orig_vb->buffer, vb->buffer); - orig_vb->user_buffer = vb->user_buffer; - - real_vb->buffer_offset = orig_vb->buffer_offset = vb->buffer_offset; - real_vb->stride = orig_vb->stride = vb->stride; + pipe_vertex_buffer_reference(orig_vb, vb); if (vb->stride) { nonzero_stride_vb_mask |= 1 << dst_index; @@ -866,18 +860,23 @@ void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, if ((!mgr->caps.buffer_offset_unaligned && vb->buffer_offset % 4 != 0) || (!mgr->caps.buffer_stride_unaligned && vb->stride % 4 != 0)) { incompatible_vb_mask |= 1 << dst_index; - pipe_resource_reference(&real_vb->buffer, NULL); + real_vb->buffer_offset = vb->buffer_offset; + real_vb->stride = vb->stride; + pipe_vertex_buffer_unreference(real_vb); + real_vb->is_user_buffer = false; continue; } - if (!mgr->caps.user_vertex_buffers && vb->user_buffer) { + if (!mgr->caps.user_vertex_buffers && vb->is_user_buffer) { user_vb_mask |= 1 << dst_index; - pipe_resource_reference(&real_vb->buffer, NULL); + real_vb->buffer_offset = vb->buffer_offset; + real_vb->stride = vb->stride; + pipe_vertex_buffer_unreference(real_vb); + real_vb->is_user_buffer = false; continue; } - pipe_resource_reference(&real_vb->buffer, vb->buffer); - real_vb->user_buffer = vb->user_buffer; + pipe_vertex_buffer_reference(real_vb, vb); } mgr->user_vb_mask |= user_vb_mask; @@ -933,7 +932,7 @@ u_vbuf_upload_buffers(struct u_vbuf *mgr, continue; } - if (!vb->user_buffer) { + if (!vb->is_user_buffer) { continue; } @@ -983,11 +982,11 @@ u_vbuf_upload_buffers(struct u_vbuf *mgr, assert(start < end); real_vb = &mgr->real_vertex_buffer[i]; - ptr = mgr->vertex_buffer[i].user_buffer; + ptr = mgr->vertex_buffer[i].buffer.user; - u_upload_data(mgr->pipe->stream_uploader, start, end - start, 4, ptr + start, - &real_vb->buffer_offset, &real_vb->buffer); - if (!real_vb->buffer) + u_upload_data(mgr->pipe->stream_uploader, start, end - start, 4, + ptr + start, &real_vb->buffer_offset, &real_vb->buffer.resource); + if (!real_vb->buffer.resource) return PIPE_ERROR_OUT_OF_MEMORY; real_vb->buffer_offset -= start; @@ -1320,16 +1319,13 @@ void u_vbuf_restore_vertex_elements(struct u_vbuf *mgr) void u_vbuf_save_aux_vertex_buffer_slot(struct u_vbuf *mgr) { - struct pipe_vertex_buffer *vb = - &mgr->vertex_buffer[mgr->aux_vertex_buffer_slot]; - - pipe_resource_reference(&mgr->aux_vertex_buffer_saved.buffer, vb->buffer); - memcpy(&mgr->aux_vertex_buffer_saved, vb, sizeof(*vb)); + pipe_vertex_buffer_reference(&mgr->aux_vertex_buffer_saved, + &mgr->vertex_buffer[mgr->aux_vertex_buffer_slot]); } void u_vbuf_restore_aux_vertex_buffer_slot(struct u_vbuf *mgr) { u_vbuf_set_vertex_buffers(mgr, mgr->aux_vertex_buffer_slot, 1, &mgr->aux_vertex_buffer_saved); - pipe_resource_reference(&mgr->aux_vertex_buffer_saved.buffer, NULL); + pipe_vertex_buffer_unreference(&mgr->aux_vertex_buffer_saved); } |