r600g: allow constant buffers to be user buffers.
authorDave Airlie <airlied@redhat.com>
Fri, 7 Jan 2011 00:35:41 +0000 (10:35 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 7 Jan 2011 00:35:41 +0000 (10:35 +1000)
This provides an upload facility for the constant buffers since Marek's
constants in user buffers changes.

gears at least work on my evergreen now.

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/r600_buffer.c
src/gallium/drivers/r600/r600_pipe.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_resource.h
src/gallium/drivers/r600/r600_state.c

index c4675fe..94eef77 100644 (file)
@@ -842,6 +842,7 @@ static void evergreen_set_constant_buffer(struct pipe_context *ctx, uint shader,
 {
        struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
        struct r600_resource *rbuffer = (struct r600_resource*)buffer;
+       uint32_t offset;
 
        /* Note that the state tracker can unbind constant buffers by
         * passing NULL here.
@@ -850,6 +851,8 @@ static void evergreen_set_constant_buffer(struct pipe_context *ctx, uint shader,
                return;
        }
 
+       r600_upload_const_buffer(rctx, buffer, &offset);
+
        switch (shader) {
        case PIPE_SHADER_VERTEX:
                rctx->vs_const_buffer.nregs = 0;
@@ -859,7 +862,7 @@ static void evergreen_set_constant_buffer(struct pipe_context *ctx, uint shader,
                                        0xFFFFFFFF, NULL);
                r600_pipe_state_add_reg(&rctx->vs_const_buffer,
                                        R_028980_ALU_CONST_CACHE_VS_0,
-                                       (r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo);
+                                       (r600_bo_offset(rbuffer->bo) + offset) >> 8, 0xFFFFFFFF, rbuffer->bo);
                r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_const_buffer);
                break;
        case PIPE_SHADER_FRAGMENT:
@@ -870,7 +873,7 @@ static void evergreen_set_constant_buffer(struct pipe_context *ctx, uint shader,
                                        0xFFFFFFFF, NULL);
                r600_pipe_state_add_reg(&rctx->ps_const_buffer,
                                        R_028940_ALU_CONST_CACHE_PS_0,
-                                       (r600_bo_offset(rbuffer->bo)) >> 8, 0xFFFFFFFF, rbuffer->bo);
+                                       (r600_bo_offset(rbuffer->bo) + offset) >> 8, 0xFFFFFFFF, rbuffer->bo);
                r600_context_pipe_state_set(&rctx->ctx, &rctx->ps_const_buffer);
                break;
        default:
index a17c54d..1b0000b 100644 (file)
@@ -250,3 +250,27 @@ int r600_upload_user_buffers(struct r600_pipe_context *rctx)
        }
        return ret;
 }
+
+
+int r600_upload_const_buffer(struct r600_pipe_context *rctx, struct pipe_resource *cbuffer,
+                            uint32_t *const_offset)
+{
+       if (r600_buffer_is_user_buffer(cbuffer)) {
+               struct r600_resource_buffer *rbuffer = r600_buffer(cbuffer);
+               unsigned upload_offset;
+               int ret = 0;
+
+               ret = r600_upload_buffer(rctx->rupload_const,
+                                        0, cbuffer->width0,
+                                        rbuffer,
+                                        &upload_offset,
+                                        &rbuffer->r.bo_size,
+                                        &rbuffer->r.bo);
+               if (ret)
+                       return ret;
+               rbuffer->uploaded = TRUE;
+               *const_offset = upload_offset;
+       }
+
+       return 0;
+}
index 0bf8760..20838e4 100644 (file)
@@ -69,6 +69,7 @@ static void r600_flush(struct pipe_context *ctx, unsigned flags,
        r600_context_flush(&rctx->ctx);
 
        r600_upload_flush(rctx->rupload_vb);
+       r600_upload_flush(rctx->rupload_const);
 }
 
 static void r600_destroy_context(struct pipe_context *context)
@@ -88,6 +89,7 @@ static void r600_destroy_context(struct pipe_context *context)
        }
 
        r600_upload_destroy(rctx->rupload_vb);
+       r600_upload_destroy(rctx->rupload_const);
 
        if (rctx->tran.translate_cache)
                translate_cache_destroy(rctx->tran.translate_cache);
@@ -171,6 +173,12 @@ static struct pipe_context *r600_create_context(struct pipe_screen *screen, void
                return NULL;
        }
 
+       rctx->rupload_const = r600_upload_create(rctx, 128 * 1024, 256);
+       if (rctx->rupload_const == NULL) {
+               r600_destroy_context(&rctx->context);
+               return NULL;
+       }
+
        rctx->blitter = util_blitter_create(&rctx->context);
        if (rctx->blitter == NULL) {
                FREE(rctx);
index 1cdca9c..2112a40 100644 (file)
@@ -169,6 +169,7 @@ struct r600_pipe_context {
        struct r600_textures_info       ps_samplers;
        unsigned                        vb_max_index;
        struct r600_translate_context   tran;
+       struct r600_upload              *rupload_const;
 };
 
 struct r600_drawl {
index 9b1af5e..28b3e1e 100644 (file)
@@ -131,4 +131,5 @@ int r600_upload_buffer(struct r600_upload *upload, unsigned offset,
                        unsigned *out_offset, unsigned *out_size,
                        struct r600_bo **out_buffer);
 
+int r600_upload_const_buffer(struct r600_pipe_context *rctx, struct pipe_resource *cbuffer, uint32_t *offset);
 #endif
index b68203f..96b02d7 100644 (file)
@@ -1109,6 +1109,7 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
 {
        struct r600_pipe_context *rctx = (struct r600_pipe_context *)ctx;
        struct r600_resource *rbuffer = (struct r600_resource*)buffer;
+       uint32_t offset;
 
        /* Note that the state tracker can unbind constant buffers by
         * passing NULL here.
@@ -1117,6 +1118,8 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
                return;
        }
 
+       r600_upload_const_buffer(rctx, buffer, &offset);
+
        switch (shader) {
        case PIPE_SHADER_VERTEX:
                rctx->vs_const_buffer.nregs = 0;
@@ -1126,7 +1129,7 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
                                        0xFFFFFFFF, NULL);
                r600_pipe_state_add_reg(&rctx->vs_const_buffer,
                                        R_028980_ALU_CONST_CACHE_VS_0,
-                                       r600_bo_offset(rbuffer->bo) >> 8, 0xFFFFFFFF, rbuffer->bo);
+                                       (r600_bo_offset(rbuffer->bo) + offset) >> 8, 0xFFFFFFFF, rbuffer->bo);
                r600_context_pipe_state_set(&rctx->ctx, &rctx->vs_const_buffer);
                break;
        case PIPE_SHADER_FRAGMENT:
@@ -1137,7 +1140,7 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
                                        0xFFFFFFFF, NULL);
                r600_pipe_state_add_reg(&rctx->ps_const_buffer,
                                        R_028940_ALU_CONST_CACHE_PS_0,
-                                       r600_bo_offset(rbuffer->bo) >> 8, 0xFFFFFFFF, rbuffer->bo);
+                                       (r600_bo_offset(rbuffer->bo) + offset) >> 8, 0xFFFFFFFF, rbuffer->bo);
                r600_context_pipe_state_set(&rctx->ctx, &rctx->ps_const_buffer);
                break;
        default: