evergreen_state.c \
eg_asm.c \
r600_translate.c \
- r600_state_common.c
+ r600_state_common.c \
+ r600_upload.c
include ../../Makefile.template
r600_pipe_state_add_reg(rstate, R_030000_RESOURCE0_WORD0,
offset, 0xFFFFFFFF, rbuffer->bo);
r600_pipe_state_add_reg(rstate, R_030004_RESOURCE0_WORD1,
- rbuffer->size - offset - 1, 0xFFFFFFFF, NULL);
+ rbuffer->bo_size - offset - 1, 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_030008_RESOURCE0_WORD2,
S_030008_STRIDE(vertex_buffer->stride),
0xFFFFFFFF, NULL);
#include <util/u_math.h>
#include <util/u_inlines.h>
#include <util/u_memory.h>
-#include <util/u_upload_mgr.h>
#include "state_tracker/drm_driver.h"
#include <xf86drm.h>
#include "radeon_drm.h"
rbuffer->magic = R600_BUFFER_MAGIC;
rbuffer->user_buffer = NULL;
- rbuffer->num_ranges = 0;
rbuffer->r.base.b = *templ;
pipe_reference_init(&rbuffer->r.base.b.reference, 1);
rbuffer->r.base.b.screen = screen;
rbuffer->r.base.vtbl = &r600_buffer_vtbl;
rbuffer->r.size = rbuffer->r.base.b.width0;
+ rbuffer->r.bo_size = rbuffer->r.size;
+ rbuffer->uploaded = FALSE;
bo = r600_bo((struct radeon*)screen->winsys, rbuffer->r.base.b.width0, alignment, rbuffer->r.base.b.bind, rbuffer->r.base.b.usage);
if (bo == NULL) {
FREE(rbuffer);
rbuffer->r.base.b.depth0 = 1;
rbuffer->r.base.b.array_size = 1;
rbuffer->r.base.b.flags = 0;
- rbuffer->num_ranges = 0;
rbuffer->r.bo = NULL;
+ rbuffer->r.bo_size = 0;
rbuffer->user_buffer = ptr;
+ rbuffer->uploaded = FALSE;
return &rbuffer->r.base.b;
}
{
struct r600_resource_buffer *rbuffer = r600_buffer(buf);
- if (rbuffer->r.bo) {
+ if (!rbuffer->uploaded && rbuffer->r.bo) {
r600_bo_reference((struct radeon*)screen->winsys, &rbuffer->r.bo, NULL);
}
+ rbuffer->r.bo = NULL;
FREE(rbuffer);
}
struct r600_resource_buffer *rbuffer = r600_buffer(transfer->resource);
int write = 0;
uint8_t *data;
- int i;
- boolean flush = FALSE;
if (rbuffer->user_buffer)
return (uint8_t*)rbuffer->user_buffer + transfer->box.x;
- if (transfer->usage & PIPE_TRANSFER_DISCARD) {
- for (i = 0; i < rbuffer->num_ranges; i++) {
- if ((transfer->box.x >= rbuffer->ranges[i].start) &&
- (transfer->box.x < rbuffer->ranges[i].end))
- flush = TRUE;
-
- if (flush) {
- r600_bo_reference((struct radeon*)pipe->winsys, &rbuffer->r.bo, NULL);
- rbuffer->num_ranges = 0;
- rbuffer->r.bo = r600_bo((struct radeon*)pipe->winsys,
- rbuffer->r.base.b.width0, 0,
- rbuffer->r.base.b.bind,
- rbuffer->r.base.b.usage);
- break;
- }
- }
- }
if (transfer->usage & PIPE_TRANSFER_DONTBLOCK) {
/* FIXME */
}
{
struct r600_resource_buffer *rbuffer = r600_buffer(transfer->resource);
+ if (rbuffer->user_buffer)
+ return;
+
if (rbuffer->r.bo)
r600_bo_unmap((struct radeon*)pipe->winsys, rbuffer->r.bo);
}
static void r600_buffer_transfer_flush_region(struct pipe_context *pipe,
- struct pipe_transfer *transfer,
- const struct pipe_box *box)
+ struct pipe_transfer *transfer,
+ const struct pipe_box *box)
{
- struct r600_resource_buffer *rbuffer = r600_buffer(transfer->resource);
- unsigned i;
- unsigned offset = transfer->box.x + box->x;
- unsigned length = box->width;
-
- assert(box->x + box->width <= transfer->box.width);
-
- if (rbuffer->user_buffer)
- return;
-
- /* mark the range as used */
- for(i = 0; i < rbuffer->num_ranges; ++i) {
- if(offset <= rbuffer->ranges[i].end && rbuffer->ranges[i].start <= (offset+box->width)) {
- rbuffer->ranges[i].start = MIN2(rbuffer->ranges[i].start, offset);
- rbuffer->ranges[i].end = MAX2(rbuffer->ranges[i].end, (offset+length));
- return;
- }
- }
-
- rbuffer->ranges[rbuffer->num_ranges].start = offset;
- rbuffer->ranges[rbuffer->num_ranges].end = offset+length;
- rbuffer->num_ranges++;
}
unsigned r600_buffer_is_referenced_by_cs(struct pipe_context *context,
int r600_upload_index_buffer(struct r600_pipe_context *rctx, struct r600_drawl *draw)
{
- struct pipe_resource *upload_buffer = NULL;
- unsigned index_offset = draw->index_buffer_offset;
- int ret = 0;
-
if (r600_buffer_is_user_buffer(draw->index_buffer)) {
- ret = u_upload_buffer(rctx->upload_ib,
- index_offset,
- draw->count * draw->index_size,
- draw->index_buffer,
- &index_offset,
- &upload_buffer);
- if (ret) {
- goto done;
- }
- draw->index_buffer_offset = index_offset;
-
- /* Transfer ownership. */
- pipe_resource_reference(&draw->index_buffer, upload_buffer);
- pipe_resource_reference(&upload_buffer, NULL);
+ struct r600_resource_buffer *rbuffer = r600_buffer(draw->index_buffer);
+ unsigned upload_offset;
+ int ret = 0;
+
+ ret = r600_upload_buffer(rctx->rupload_vb,
+ draw->index_buffer_offset,
+ draw->count * draw->index_size,
+ rbuffer,
+ &upload_offset,
+ &rbuffer->r.bo_size,
+ &rbuffer->r.bo);
+ if (ret)
+ return ret;
+ rbuffer->uploaded = TRUE;
+ draw->index_buffer_offset = upload_offset;
}
-done:
- return ret;
+ return 0;
}
int r600_upload_user_buffers(struct r600_pipe_context *rctx)
nr = rctx->nvertex_buffer;
for (i = 0; i < nr; i++) {
-// struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[rctx->vertex_elements->elements[i].vertex_buffer_index];
struct pipe_vertex_buffer *vb = &rctx->vertex_buffer[i];
if (r600_buffer_is_user_buffer(vb->buffer)) {
- struct pipe_resource *upload_buffer = NULL;
- unsigned offset = 0; /*vb->buffer_offset * 4;*/
- unsigned size = vb->buffer->width0;
+ struct r600_resource_buffer *rbuffer = r600_buffer(vb->buffer);
unsigned upload_offset;
- ret = u_upload_buffer(rctx->upload_vb,
- offset, size,
- vb->buffer,
- &upload_offset, &upload_buffer);
+
+ ret = r600_upload_buffer(rctx->rupload_vb,
+ 0, vb->buffer->width0,
+ rbuffer,
+ &upload_offset,
+ &rbuffer->r.bo_size,
+ &rbuffer->r.bo);
if (ret)
return ret;
-
- pipe_resource_reference(&vb->buffer, NULL);
- vb->buffer = upload_buffer;
+ rbuffer->uploaded = TRUE;
vb->buffer_offset = upload_offset;
}
}
#include <util/u_pack_color.h>
#include <util/u_memory.h>
#include <util/u_inlines.h>
-#include <util/u_upload_mgr.h>
#include <pipebuffer/pb_buffer.h>
#include "r600.h"
#include "r600d.h"
if (!rctx->ctx.pm4_cdwords)
return;
- u_upload_flush(rctx->upload_vb);
- u_upload_flush(rctx->upload_ib);
-
#if 0
sprintf(dname, "gallium-%08d.bof", dc);
if (dc < 20) {
dc++;
#endif
r600_context_flush(&rctx->ctx);
+
+ r600_upload_flush(rctx->rupload_vb);
}
static void r600_destroy_context(struct pipe_context *context)
free(rctx->states[i]);
}
- u_upload_destroy(rctx->upload_vb);
- u_upload_destroy(rctx->upload_ib);
+ r600_upload_destroy(rctx->rupload_vb);
if (rctx->tran.translate_cache)
translate_cache_destroy(rctx->tran.translate_cache);
return NULL;
}
- rctx->upload_ib = u_upload_create(&rctx->context, 32 * 1024, 16,
- PIPE_BIND_INDEX_BUFFER);
- if (rctx->upload_ib == NULL) {
- r600_destroy_context(&rctx->context);
- return NULL;
- }
-
- rctx->upload_vb = u_upload_create(&rctx->context, 128 * 1024, 16,
- PIPE_BIND_VERTEX_BUFFER);
- if (rctx->upload_vb == NULL) {
+ rctx->rupload_vb = r600_upload_create(rctx, 128 * 1024, 16);
+ if (rctx->rupload_vb == NULL) {
r600_destroy_context(&rctx->context);
return NULL;
}
#define R600_CONSTANT_ARRAY_SIZE 256
#define R600_RESOURCE_ARRAY_SIZE 160
+struct r600_upload;
+
struct r600_pipe_context {
struct pipe_context context;
struct blitter_context *blitter;
/* shader information */
unsigned sprite_coord_enable;
bool flatshade;
- struct u_upload_mgr *upload_vb;
- struct u_upload_mgr *upload_ib;
+ struct r600_upload *rupload_vb;
unsigned any_user_vbs;
struct r600_textures_info ps_samplers;
unsigned vb_max_index;
struct u_resource base;
struct r600_bo *bo;
u32 size;
+ unsigned bo_size;
};
struct r600_resource_texture {
struct winsys_handle *whandle);
#define R600_BUFFER_MAGIC 0xabcd1600
-#define R600_BUFFER_MAX_RANGES 32
-
-struct r600_buffer_range {
- uint32_t start;
- uint32_t end;
-};
struct r600_resource_buffer {
struct r600_resource r;
uint32_t magic;
void *user_buffer;
- struct r600_buffer_range ranges[R600_BUFFER_MAX_RANGES];
- unsigned num_ranges;
+ bool uploaded;
};
/* r600_buffer */
static INLINE boolean r600_buffer_is_user_buffer(struct pipe_resource *buffer)
{
- return r600_buffer(buffer)->user_buffer ? TRUE : FALSE;
+ if (r600_buffer(buffer)->uploaded)
+ return FALSE;
+ return r600_buffer(buffer)->user_buffer ? TRUE : FALSE;
}
int r600_texture_depth_flush(struct pipe_context *ctx,
unsigned aligned_height;
};
+struct r600_pipe_context;
+struct r600_upload *r600_upload_create(struct r600_pipe_context *rctx,
+ unsigned default_size,
+ unsigned alignment);
+void r600_upload_flush(struct r600_upload *upload);
+void r600_upload_destroy(struct r600_upload *upload);
+int r600_upload_buffer(struct r600_upload *upload, unsigned offset,
+ unsigned size, struct r600_resource_buffer *in_buffer,
+ unsigned *out_offset, unsigned *out_size,
+ struct r600_bo **out_buffer);
+
#endif
#include <util/u_pack_color.h>
#include <util/u_memory.h>
#include <util/u_inlines.h>
-#include <util/u_upload_mgr.h>
#include <util/u_framebuffer.h>
#include <pipebuffer/pb_buffer.h>
#include "r600.h"
r600_pipe_state_add_reg(rstate, R_038000_RESOURCE0_WORD0,
offset, 0xFFFFFFFF, rbuffer->bo);
r600_pipe_state_add_reg(rstate, R_038004_RESOURCE0_WORD1,
- rbuffer->size - offset - 1, 0xFFFFFFFF, NULL);
+ rbuffer->bo_size - offset - 1, 0xFFFFFFFF, NULL);
r600_pipe_state_add_reg(rstate, R_038008_RESOURCE0_WORD2,
S_038008_STRIDE(vertex_buffer->stride),
0xFFFFFFFF, NULL);
--- /dev/null
+/*
+ * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Jerome Glisse <jglisse@redhat.com>
+ */
+#include <errno.h>
+#include "util/u_inlines.h"
+#include "util/u_memory.h"
+#include "r600.h"
+#include "r600_pipe.h"
+#include "r600_resource.h"
+
+struct r600_upload {
+ struct r600_pipe_context *rctx;
+ struct r600_bo *buffer;
+ char *ptr;
+ unsigned size;
+ unsigned default_size;
+ unsigned total_alloc_size;
+ unsigned offset;
+ unsigned alignment;
+};
+
+struct r600_upload *r600_upload_create(struct r600_pipe_context *rctx,
+ unsigned default_size,
+ unsigned alignment)
+{
+ struct r600_upload *upload = CALLOC_STRUCT(r600_upload);
+
+ if (upload == NULL)
+ return NULL;
+
+ upload->rctx = rctx;
+ upload->size = 0;
+ upload->default_size = default_size;
+ upload->alignment = alignment;
+ upload->ptr = NULL;
+ upload->buffer = NULL;
+ upload->total_alloc_size = 0;
+
+ return upload;
+}
+
+void r600_upload_flush(struct r600_upload *upload)
+{
+ if (upload->buffer) {
+ r600_bo_reference(upload->rctx->radeon, &upload->buffer, NULL);
+ }
+ upload->default_size = MAX2(upload->total_alloc_size, upload->default_size);
+ upload->total_alloc_size = 0;
+ upload->size = 0;
+ upload->ptr = NULL;
+ upload->buffer = NULL;
+}
+
+void r600_upload_destroy(struct r600_upload *upload)
+{
+ r600_upload_flush(upload);
+ FREE(upload);
+}
+
+int r600_upload_buffer(struct r600_upload *upload, unsigned offset,
+ unsigned size, struct r600_resource_buffer *in_buffer,
+ unsigned *out_offset, unsigned *out_size,
+ struct r600_bo **out_buffer)
+{
+ unsigned alloc_size = align(size, upload->alignment);
+ const void *in_ptr = NULL;
+
+ if (upload->offset + alloc_size > upload->size) {
+ if (upload->size) {
+ r600_bo_reference(upload->rctx->radeon, &upload->buffer, NULL);
+ }
+ upload->size = align(MAX2(upload->default_size, alloc_size), 4096);
+ upload->total_alloc_size += upload->size;
+ upload->offset = 0;
+ upload->buffer = r600_bo(upload->rctx->radeon, upload->size, 4096, PIPE_BIND_VERTEX_BUFFER, 0);
+ if (upload->buffer == NULL) {
+ return -ENOMEM;
+ }
+ upload->ptr = r600_bo_map(upload->rctx->radeon, upload->buffer, 0, NULL);
+ }
+
+ in_ptr = in_buffer->user_buffer;
+ memcpy(upload->ptr + upload->offset, in_ptr + offset, size);
+ *out_offset = upload->offset;
+ *out_size = upload->size;
+ *out_buffer = upload->buffer;
+ upload->offset += alloc_size;
+
+ return 0;
+}