Could you also add comments to all the u_upload_mgr.c functions? In
particular, what are the possible values for the usage/bind
parameters? A follow-on patch is fine. I know that comments have
been missing all along.
-Brian
On 12/29/2010 12:00 PM, Marek Olšák wrote:
- Added a parameter to specify a minimum offset that should be returned.
r300g needs this to better implement user buffer uploads. This weird
requirement comes from the fact that the Radeon DRM doesn't support negative
offsets.
- Added a parameter to notify a driver that the upload flush occured.
A driver may skip buffer validation if there was no flush, resulting
in a better performance.
- Added a new upload function that returns a pointer to the upload buffer
directly, so that the buffer can be filled e.g. by the translate module.
---
src/gallium/auxiliary/util/u_upload_mgr.c | 75 +
src/gallium/auxiliary/util/u_upload_mgr.h | 43 +-
src/gallium/drivers/i965/brw_draw_upload.c| 12 +++-
src/gallium/drivers/r300/r300_screen_buffer.c | 10 ++-
src/gallium/drivers/svga/svga_draw_elements.c |5 +-
src/gallium/drivers/svga/svga_state_vdecl.c |6 +-
6 files changed, 115 insertions(+), 36 deletions(-)
diff --git a/src/gallium/auxiliary/util/u_upload_mgr.c
b/src/gallium/auxiliary/util/u_upload_mgr.c
index 4d97bf0..80c9b63 100644
--- a/src/gallium/auxiliary/util/u_upload_mgr.c
+++ b/src/gallium/auxiliary/util/u_upload_mgr.c
@@ -43,7 +43,7 @@ struct u_upload_mgr {
unsigned default_size;
unsigned alignment;
- unsigned usage;
+ unsigned bind;
/* The active buffer:
*/
@@ -58,7 +58,7 @@ struct u_upload_mgr {
struct u_upload_mgr *u_upload_create( struct pipe_context *pipe,
unsigned default_size,
unsigned alignment,
- unsigned usage )
+ unsigned bind )
{
struct u_upload_mgr *upload = CALLOC_STRUCT( u_upload_mgr );
if (!upload)
@@ -67,7 +67,7 @@ struct u_upload_mgr *u_upload_create( struct pipe_context
*pipe,
upload-pipe = pipe;
upload-default_size = default_size;
upload-alignment = alignment;
- upload-usage = usage;
+ upload-bind = bind;
upload-buffer = NULL;
return upload;
@@ -115,7 +115,7 @@ u_upload_alloc_buffer( struct u_upload_mgr *upload,
size = align(MAX2(upload-default_size, min_size), 4096);
upload-buffer = pipe_buffer_create( upload-pipe-screen,
-upload-usage,
+upload-bind,
size );
if (upload-buffer == NULL)
goto fail;
@@ -135,33 +135,61 @@ fail:
return PIPE_ERROR_OUT_OF_MEMORY;
}
-
-enum pipe_error u_upload_data( struct u_upload_mgr *upload,
- unsigned size,
- const void *data,
- unsigned *out_offset,
- struct pipe_resource **outbuf )
+enum pipe_error u_upload_alloc( struct u_upload_mgr *upload,
+unsigned min_out_offset,
+unsigned size,
+unsigned *out_offset,
+struct pipe_resource **outbuf,
+boolean *flushed,
+void **ptr )
{
unsigned alloc_size = align( size, upload-alignment );
- enum pipe_error ret = PIPE_OK;
+ unsigned alloc_offset = align(min_out_offset, upload-alignment);
+ unsigned offset;
- if (upload-offset + alloc_size upload-size) {
- ret = u_upload_alloc_buffer( upload, alloc_size );
+ if (MAX2(upload-offset, alloc_offset) + alloc_size upload-size) {
+ enum pipe_error ret = u_upload_alloc_buffer(upload,
+ alloc_offset + alloc_size);
if (ret)
return ret;
+
+ *flushed = TRUE;
+ } else {
+ *flushed = FALSE;
}
- assert(upload-offset upload-buffer-width0);
- assert(upload-offset + size= upload-buffer-width0);
+ offset = MAX2(upload-offset, alloc_offset);
+
+ assert(offset upload-buffer-width0);
+ assert(offset + size= upload-buffer-width0);
assert(size);
- memcpy(upload-map + upload-offset, data, size);
+ *ptr = upload-map + offset;
/* Emit the return values:
*/
pipe_resource_reference( outbuf, upload-buffer );
- *out_offset = upload-offset;
- upload-offset += alloc_size;
+ *out_offset = offset;
+ upload-offset = offset + alloc_size;
+ return PIPE_OK;
+}
+
+enum pipe_error u_upload_data( struct u_upload_mgr *upload,
+ unsigned min_out_offset,
+ unsigned size,
+ const void *data,
+