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 c4675fedad217cc29a4949d3adbf3f42eaaae272..94eef77945b166c486027c1fb453f6849686e431 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 a17c54d6eeb8958635fb0b4251a1ce1419541a21..1b0000ba46294350d3ebd8047d632b587d296beb 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 0bf87607b5bc5a2d6676949d7f6044ef14f82fab..20838e4d98ffbda18928e7dea2cfd7a22ae9543d 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 1cdca9cb3d0b07c8482d8393bc186d34dc47c91d..2112a40f6962b3761db3a765e3cbbd03bc73fd67 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 9b1af5e6f2c5b8c969861288b1149825e12ebcf5..28b3e1e5e40b22e978a217c82b32d7f9babf9be2 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 b68203f78f8669dc9e0a8217931aac8e261678fe..96b02d72b943806ef3939637957758b9cf496088 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: