gallium: change set_constant_buffer to be UBO-friendly
authorMarek Olšák <maraeo@gmail.com>
Tue, 24 Apr 2012 17:52:26 +0000 (19:52 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 29 Apr 2012 23:09:57 +0000 (01:09 +0200)
32 files changed:
src/gallium/auxiliary/postprocess/pp_mlaa.c
src/gallium/auxiliary/util/u_inlines.h
src/gallium/auxiliary/vl/vl_compositor.c
src/gallium/drivers/galahad/glhd_context.c
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/identity/id_context.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/noop/noop_state.c
src/gallium/drivers/nv30/nv30_state.c
src/gallium/drivers/nv50/nv50_state.c
src/gallium/drivers/nvc0/nvc0_state.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_state_common.c
src/gallium/drivers/radeonsi/r600_state_common.c
src/gallium/drivers/radeonsi/radeonsi_pipe.h
src/gallium/drivers/rbug/rbug_context.c
src/gallium/drivers/softpipe/sp_state_shader.c
src/gallium/drivers/svga/svga_pipe_constants.c
src/gallium/drivers/trace/tr_context.c
src/gallium/include/pipe/p_context.h
src/gallium/include/pipe/p_state.h
src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h
src/gallium/state_trackers/vega/renderer.c
src/gallium/state_trackers/xa/xa_renderer.c
src/gallium/state_trackers/xorg/xorg_renderer.c
src/gallium/tests/graw/fs-test.c
src/gallium/tests/graw/gs-test.c
src/gallium/tests/graw/vs-test.c
src/mesa/state_tracker/st_atom_constbuf.c

index 51bc02edacce1f19cfbe47ed34bd3a0e1f0bfaa6..b61cbaafb5e9529582bd8703e23528ec2033e90a 100644 (file)
@@ -99,8 +99,8 @@ pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
       dimensions[1] = p->framebuffer.height;
    }
 
-   p->pipe->set_constant_buffer(p->pipe, PIPE_SHADER_VERTEX, 0, constbuf);
-   p->pipe->set_constant_buffer(p->pipe, PIPE_SHADER_FRAGMENT, 0, constbuf);
+   pipe_set_constant_buffer(p->pipe, PIPE_SHADER_VERTEX, 0, constbuf);
+   pipe_set_constant_buffer(p->pipe, PIPE_SHADER_FRAGMENT, 0, constbuf);
 
    mstencil.stencil[0].enabled = 1;
    mstencil.stencil[0].valuemask = mstencil.stencil[0].writemask = ~0;
index 49b4531dbacbd862b7ef19c485b3b287443decfe..651f7c2d7270a1a0066fbbe64d536f02ac1584a6 100644 (file)
@@ -437,6 +437,21 @@ pipe_transfer_destroy( struct pipe_context *context,
    context->transfer_destroy(context, transfer);
 }
 
+static INLINE void
+pipe_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
+                         struct pipe_resource *buf)
+{
+   if (buf) {
+      struct pipe_constant_buffer cb;
+      cb.buffer = buf;
+      cb.buffer_offset = 0;
+      cb.buffer_size = buf->width0;
+      pipe->set_constant_buffer(pipe, shader, index, &cb);
+   } else {
+      pipe->set_constant_buffer(pipe, shader, index, NULL);
+   }
+}
+
 
 static INLINE boolean util_get_offset( 
    const struct pipe_rasterizer_state *templ,
index cc213b748a54d8bbd44e27ecbe21f1b1568851f7..0cb1a9f38ad30b503ab4c197de4fc659fbf84fb1 100644 (file)
@@ -1015,7 +1015,7 @@ vl_compositor_render(struct vl_compositor_state *s,
    c->pipe->bind_vs_state(c->pipe, c->vs);
    c->pipe->set_vertex_buffers(c->pipe, 1, &c->vertex_buf);
    c->pipe->bind_vertex_elements_state(c->pipe, c->vertex_elems_state);
-   c->pipe->set_constant_buffer(c->pipe, PIPE_SHADER_FRAGMENT, 0, s->csc_matrix);
+   pipe_set_constant_buffer(c->pipe, PIPE_SHADER_FRAGMENT, 0, s->csc_matrix);
    c->pipe->bind_rasterizer_state(c->pipe, c->rast);
 
    draw_layers(c, s, dirty_area);
index 0bb18884c8dfdb5b4774e9e7ef2b00e3784c342d..f0bbf4e8a958a51c4776bb952905868fc77cbded 100644 (file)
@@ -458,12 +458,11 @@ static void
 galahad_set_constant_buffer(struct pipe_context *_pipe,
                              uint shader,
                              uint index,
-                             struct pipe_resource *_resource)
+                             struct pipe_constant_buffer *_cb)
 {
    struct galahad_context *glhd_pipe = galahad_context(_pipe);
    struct pipe_context *pipe = glhd_pipe->pipe;
-   struct pipe_resource *unwrapped_resource;
-   struct pipe_resource *resource = NULL;
+   struct pipe_constant_buffer cb;
 
    if (shader >= PIPE_SHADER_TYPES) {
       glhd_error("Unknown shader type %u", shader);
@@ -479,15 +478,15 @@ galahad_set_constant_buffer(struct pipe_context *_pipe,
    }
 
    /* XXX hmm? unwrap the input state */
-   if (_resource) {
-      unwrapped_resource = galahad_resource_unwrap(_resource);
-      resource = unwrapped_resource;
+   if (_cb) {
+      cb = *_cb;
+      cb.buffer = galahad_resource_unwrap(_cb->buffer);
    }
 
    pipe->set_constant_buffer(pipe,
                              shader,
                              index,
-                             resource);
+                             _cb ? &cb : NULL);
 }
 
 static void
index 4c284d9fcbb76532856b2633aac3d616dace9da1..40cef5a9d86914df498202099439fc83e4e1a762 100644 (file)
@@ -665,9 +665,10 @@ static void i915_delete_vs_state(struct pipe_context *pipe, void *shader)
 
 static void i915_set_constant_buffer(struct pipe_context *pipe,
                                      uint shader, uint index,
-                                     struct pipe_resource *buf)
+                                     struct pipe_constant_buffer *cb)
 {
    struct i915_context *i915 = i915_context(pipe);
+   struct pipe_resource *buf = cb ? cb->buffer : NULL;
    unsigned new_num = 0;
    boolean diff = TRUE;
 
index af3f8239ccd9372b228dbb6eeea55eaee31e0059..29421849079fd7d1180fc4cc0c1e133cfe6bb758 100644 (file)
@@ -411,23 +411,22 @@ static void
 identity_set_constant_buffer(struct pipe_context *_pipe,
                              uint shader,
                              uint index,
-                             struct pipe_resource *_resource)
+                             struct pipe_constant_buffer *_cb)
 {
    struct identity_context *id_pipe = identity_context(_pipe);
    struct pipe_context *pipe = id_pipe->pipe;
-   struct pipe_resource *unwrapped_resource;
-   struct pipe_resource *resource = NULL;
+   struct pipe_constant_buffer cb;
 
    /* XXX hmm? unwrap the input state */
-   if (_resource) {
-      unwrapped_resource = identity_resource_unwrap(_resource);
-      resource = unwrapped_resource;
+   if (_cb) {
+      cb = *_cb;
+      cb.buffer = identity_resource_unwrap(_cb->buffer);
    }
 
    pipe->set_constant_buffer(pipe,
                              shader,
                              index,
-                             resource);
+                             _cb ? &cb : NULL);
 }
 
 static void
index 482f4e3863221dea5a3455aaa2b974327fb56dc8..7a6c1ab5bc72fe664fc09edd153c936e5fa451f6 100644 (file)
@@ -1169,9 +1169,10 @@ llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
 static void
 llvmpipe_set_constant_buffer(struct pipe_context *pipe,
                              uint shader, uint index,
-                             struct pipe_resource *constants)
+                             struct pipe_constant_buffer *cb)
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
+   struct pipe_resource *constants = cb ? cb->buffer : NULL;
    unsigned size = constants ? constants->width0 : 0;
    const void *data = constants ? llvmpipe_resource_data(constants) : NULL;
 
index 9d8dbfc4e2589e15cad9cb28b530a51eb38d7e69..f1387af3a39c90bc644a4487951a834ed4a81f2b 100644 (file)
@@ -175,7 +175,7 @@ static void noop_set_framebuffer_state(struct pipe_context *ctx,
 
 static void noop_set_constant_buffer(struct pipe_context *ctx,
                                        uint shader, uint index,
-                                       struct pipe_resource *buffer)
+                                       struct pipe_constant_buffer *cb)
 {
 }
 
index 64a8f33d466f9acf886e99d194b01234f8bc0417..534d1f0794b3b8982e7468e4453d9689f41470b8 100644 (file)
@@ -317,9 +317,10 @@ nv30_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask)
 
 static void
 nv30_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
-                         struct pipe_resource *buf)
+                         struct pipe_constant_buffer *cb)
 {
    struct nv30_context *nv30 = nv30_context(pipe);
+   struct pipe_resource *buf = cb ? cb->buffer : NULL;
    unsigned size;
 
    size = 0;
index 5b783da7ad7fbab85f0de1afa8fe415c80eec3c5..34d2b6daeadfb51d9269ecc0a016cd35d566649c 100644 (file)
@@ -744,9 +744,10 @@ nv50_gp_state_bind(struct pipe_context *pipe, void *hwcso)
 
 static void
 nv50_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
-                         struct pipe_resource *res)
+                         struct pipe_constant_buffer *cb)
 {
    struct nv50_context *nv50 = nv50_context(pipe);
+   struct pipe_resource *res = cb ? cb->buffer : NULL;
 
    pipe_resource_reference(&nv50->constbuf[shader][index], res);
 
index a2be53a433d4ba59c11432d4ae97f0bef2677f86..0a23ecd27b1ad46be4356d8da323c8d0795cdeb2 100644 (file)
@@ -616,9 +616,10 @@ nvc0_gp_state_bind(struct pipe_context *pipe, void *hwcso)
 
 static void
 nvc0_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
-                         struct pipe_resource *res)
+                         struct pipe_constant_buffer *cb)
 {
    struct nvc0_context *nvc0 = nvc0_context(pipe);
+   struct pipe_resource *res = cb ? cb->buffer : NULL;
 
    switch (shader) {
    case PIPE_SHADER_VERTEX: shader = 0; break;
index 337008be47ee6102f2ff9cbcd6b1369ad5b9c853..058e6f881f0fafbb0e832d756e76b07e568b549f 100644 (file)
@@ -1819,9 +1819,10 @@ static void r300_delete_vs_state(struct pipe_context* pipe, void* shader)
 
 static void r300_set_constant_buffer(struct pipe_context *pipe,
                                      uint shader, uint index,
-                                     struct pipe_resource *buf)
+                                     struct pipe_constant_buffer *cb)
 {
     struct r300_context* r300 = r300_context(pipe);
+    struct pipe_resource *buf = cb ? cb->buffer : NULL;
     struct r300_constant_buffer *cbuf;
     struct r300_resource *rbuf = r300_resource(buf);
     uint32_t *mapped;
index 97a27d242c037a5308edf709fe1bf26aa70d52f3..07771c177681caa5fbbca0732e4fc99d071988e7 100644 (file)
@@ -1177,7 +1177,7 @@ static void evergreen_set_clip_state(struct pipe_context *ctx,
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
        struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
-       struct pipe_resource *cbuf;
+       struct pipe_constant_buffer cb;
 
        if (rstate == NULL)
                return;
@@ -1203,12 +1203,14 @@ static void evergreen_set_clip_state(struct pipe_context *ctx,
        rctx->states[R600_PIPE_STATE_CLIP] = rstate;
        r600_context_pipe_state_set(rctx, rstate);
 
-       cbuf = pipe_user_buffer_create(ctx->screen,
-                                   state->ucp,
-                                   4*4*8, /* 8*4 floats */
-                                   PIPE_BIND_CONSTANT_BUFFER);
-       r600_set_constant_buffer(ctx, PIPE_SHADER_VERTEX, 1, cbuf);
-       pipe_resource_reference(&cbuf, NULL);
+       cb.buffer = pipe_user_buffer_create(ctx->screen,
+                                           state->ucp,
+                                           4*4*8, /* 8*4 floats */
+                                           PIPE_BIND_CONSTANT_BUFFER);
+       cb.buffer_offset = 0;
+       cb.buffer_size = 4*4*8;
+       r600_set_constant_buffer(ctx, PIPE_SHADER_VERTEX, 1, &cb);
+       pipe_resource_reference(&cb.buffer, NULL);
 }
 
 static void evergreen_set_polygon_stipple(struct pipe_context *ctx,
@@ -1762,7 +1764,7 @@ static void evergreen_emit_constant_buffer(struct r600_context *rctx,
        uint32_t dirty_mask = state->dirty_mask;
 
        while (dirty_mask) {
-               struct r600_constant_buffer *cb;
+               struct pipe_constant_buffer *cb;
                struct r600_resource *rbuffer;
                uint64_t va;
                unsigned buffer_index = ffs(dirty_mask) - 1;
index e17011bfb685c5f962d11b88cb63691948a43f6d..63fc27564d7454e510934588361e88fd4eb75ebc 100644 (file)
@@ -227,17 +227,10 @@ struct r600_stencil_ref
        ubyte writemask[2];
 };
 
-struct r600_constant_buffer
-{
-       struct pipe_resource            *buffer;
-       unsigned                        buffer_offset;
-       unsigned                        buffer_size;
-};
-
 struct r600_constbuf_state
 {
        struct r600_atom                atom;
-       struct r600_constant_buffer     cb[PIPE_MAX_CONSTANT_BUFFERS];
+       struct pipe_constant_buffer     cb[PIPE_MAX_CONSTANT_BUFFERS];
        uint32_t                        enabled_mask;
        uint32_t                        dirty_mask;
 };
@@ -496,7 +489,7 @@ void r600_delete_ps_shader(struct pipe_context *ctx, void *state);
 void r600_delete_vs_shader(struct pipe_context *ctx, void *state);
 void r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf_state *state);
 void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
-                             struct pipe_resource *buffer);
+                             struct pipe_constant_buffer *cb);
 struct pipe_stream_output_target *
 r600_create_so_target(struct pipe_context *ctx,
                      struct pipe_resource *buffer,
index 116ec5fca0e5fa1f77e027e3652dc3845d7327d9..1e7c5a43c02be85d7337d88480aa5b6176cbd693 100644 (file)
@@ -1260,7 +1260,7 @@ static void r600_set_clip_state(struct pipe_context *ctx,
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
        struct r600_pipe_state *rstate = CALLOC_STRUCT(r600_pipe_state);
-       struct pipe_resource * cbuf;
+       struct pipe_constant_buffer cb;
 
        if (rstate == NULL)
                return;
@@ -1286,12 +1286,14 @@ static void r600_set_clip_state(struct pipe_context *ctx,
        rctx->states[R600_PIPE_STATE_CLIP] = rstate;
        r600_context_pipe_state_set(rctx, rstate);
 
-       cbuf = pipe_user_buffer_create(ctx->screen,
-                                   state->ucp,
-                                   4*4*8, /* 8*4 floats */
-                                   PIPE_BIND_CONSTANT_BUFFER);
-       r600_set_constant_buffer(ctx, PIPE_SHADER_VERTEX, 1, cbuf);
-       pipe_resource_reference(&cbuf, NULL);
+       cb.buffer = pipe_user_buffer_create(ctx->screen,
+                                           state->ucp,
+                                           4*4*8, /* 8*4 floats */
+                                           PIPE_BIND_CONSTANT_BUFFER);
+       cb.buffer_offset = 0;
+       cb.buffer_size = 4*4*8;
+       r600_set_constant_buffer(ctx, PIPE_SHADER_VERTEX, 1, &cb);
+       pipe_resource_reference(&cb.buffer, NULL);
 }
 
 static void r600_set_polygon_stipple(struct pipe_context *ctx,
@@ -1733,7 +1735,7 @@ static void r600_emit_constant_buffers(struct r600_context *rctx,
        uint32_t dirty_mask = state->dirty_mask;
 
        while (dirty_mask) {
-               struct r600_constant_buffer *cb;
+               struct pipe_constant_buffer *cb;
                struct r600_resource *rbuffer;
                unsigned offset;
                unsigned buffer_index = ffs(dirty_mask) - 1;
index 02577ef61a240d2ba5a638fd05964ea2b7eb13e2..6f888df6a301603c04adc868a66536363263b3c4 100644 (file)
@@ -530,11 +530,11 @@ void r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf
 }
 
 void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
-                             struct pipe_resource *buffer)
+                             struct pipe_constant_buffer *input)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
        struct r600_constbuf_state *state;
-       struct r600_constant_buffer *cb;
+       struct pipe_constant_buffer *cb;
        uint8_t *ptr;
 
        switch (shader) {
@@ -551,7 +551,7 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
        /* Note that the state tracker can unbind constant buffers by
         * passing NULL here.
         */
-       if (unlikely(!buffer)) {
+       if (unlikely(!input)) {
                state->enabled_mask &= ~(1 << index);
                state->dirty_mask &= ~(1 << index);
                pipe_resource_reference(&state->cb[index].buffer, NULL);
@@ -559,15 +559,15 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
        }
 
        cb = &state->cb[index];
-       cb->buffer_size = buffer->width0;
+       cb->buffer_size = input->buffer_size;
 
-       ptr = buffer->user_ptr;
+       ptr = input->buffer->user_ptr;
 
        if (ptr) {
                /* Upload the user buffer. */
                if (R600_BIG_ENDIAN) {
                        uint32_t *tmpPtr;
-                       unsigned i, size = buffer->width0;
+                       unsigned i, size = input->buffer_size;
 
                        if (!(tmpPtr = malloc(size))) {
                                R600_ERR("Failed to allocate BE swap buffer.\n");
@@ -581,12 +581,12 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
                        u_upload_data(rctx->uploader, 0, size, tmpPtr, &cb->buffer_offset, &cb->buffer);
                        free(tmpPtr);
                } else {
-                       u_upload_data(rctx->uploader, 0, buffer->width0, ptr, &cb->buffer_offset, &cb->buffer);
+                       u_upload_data(rctx->uploader, 0, input->buffer_size, ptr, &cb->buffer_offset, &cb->buffer);
                }
        } else {
                /* Setup the hw buffer. */
-               cb->buffer_offset = 0;
-               pipe_resource_reference(&cb->buffer, buffer);
+               cb->buffer_offset = input->buffer_offset;
+               pipe_resource_reference(&cb->buffer, input->buffer);
        }
 
        state->enabled_mask |= 1 << index;
index d283e41e6813b0396a8365b6ce8f1d3ba7d64117..1970b52312deccd9601cbc7e728b97eba8dfb15d 100644 (file)
@@ -424,10 +424,10 @@ static void r600_update_alpha_ref(struct r600_context *rctx)
 }
 
 void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
-                             struct pipe_resource *buffer)
+                             struct pipe_constant_buffer *cb)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
-       struct r600_resource *rbuffer = r600_resource(buffer);
+       struct r600_resource *rbuffer = cb ? r600_resource(cb->buffer) : NULL;
        struct r600_pipe_state *rstate;
        uint64_t va_offset;
        uint32_t offset;
@@ -435,7 +435,7 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
        /* Note that the state tracker can unbind constant buffers by
         * passing NULL here.
         */
-       if (buffer == NULL) {
+       if (cb == NULL) {
                return;
        }
 
@@ -474,7 +474,7 @@ void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
 
        r600_context_pipe_state_set(rctx, rstate);
 
-       if (buffer != &rbuffer->b.b)
+       if (cb->buffer != &rbuffer->b.b)
                pipe_resource_reference((struct pipe_resource**)&rbuffer, NULL);
 }
 
index 64ddd5de25321acc09c76cb70cbaabcc59f3ba56..ab30892d51a31238922f32d20332ff22c8e79717 100644 (file)
@@ -442,7 +442,7 @@ void r600_bind_vs_shader(struct pipe_context *ctx, void *state);
 void r600_delete_ps_shader(struct pipe_context *ctx, void *state);
 void r600_delete_vs_shader(struct pipe_context *ctx, void *state);
 void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
-                             struct pipe_resource *buffer);
+                             struct pipe_constant_buffer *cb);
 struct pipe_stream_output_target *
 r600_create_so_target(struct pipe_context *ctx,
                      struct pipe_resource *buffer,
index 46518cd6977ffb178b8e2ac48e61e63105a6876b..799b3a30c6302a5b4fe438f4c3067f025528e8ed 100644 (file)
@@ -614,24 +614,23 @@ static void
 rbug_set_constant_buffer(struct pipe_context *_pipe,
                          uint shader,
                          uint index,
-                         struct pipe_resource *_resource)
+                         struct pipe_constant_buffer *_cb)
 {
    struct rbug_context *rb_pipe = rbug_context(_pipe);
    struct pipe_context *pipe = rb_pipe->pipe;
-   struct pipe_resource *unwrapped_resource;
-   struct pipe_resource *resource = NULL;
+   struct pipe_constant_buffer cb;
 
    /* XXX hmm? unwrap the input state */
-   if (_resource) {
-      unwrapped_resource = rbug_resource_unwrap(_resource);
-      resource = unwrapped_resource;
+   if (_cb) {
+      cb = *_cb;
+      cb.buffer = rbug_resource_unwrap(_cb->buffer);
    }
 
    pipe_mutex_lock(rb_pipe->call_mutex);
    pipe->set_constant_buffer(pipe,
                              shader,
                              index,
-                             resource);
+                             _cb ? &cb : NULL);
    pipe_mutex_unlock(rb_pipe->call_mutex);
 }
 
index 6acb57b3fe6d8cb8a367e1231e549ff961e8385e..af05d0d5d686a6bd9cfa4bc46f141968451478d5 100644 (file)
@@ -342,9 +342,10 @@ softpipe_delete_gs_state(struct pipe_context *pipe, void *gs)
 static void
 softpipe_set_constant_buffer(struct pipe_context *pipe,
                              uint shader, uint index,
-                             struct pipe_resource *constants)
+                             struct pipe_constant_buffer *cb)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
+   struct pipe_resource *constants = cb ? cb->buffer : NULL;
    unsigned size = constants ? constants->width0 : 0;
    const void *data = constants ? softpipe_resource(constants)->data : NULL;
 
index 2fa2142d07d7beaa15528c2e2ce96eec226c94a1..5de547bc08a619a7f983ddaf13fbc606d6c47344 100644 (file)
@@ -45,9 +45,10 @@ struct svga_constbuf
 
 static void svga_set_constant_buffer(struct pipe_context *pipe,
                                      uint shader, uint index,
-                                     struct pipe_resource *buf)
+                                     struct pipe_constant_buffer *cb)
 {
    struct svga_context *svga = svga_context(pipe);
+   struct pipe_resource *buf = cb ? cb->buffer : NULL;
 
    assert(shader < PIPE_SHADER_TYPES);
    assert(index == 0);
index 51a8b259a0497d1c1a61d4cd3e23d9dea0e58949..23f854ae9b85a27d4342ecdf2481140670667d62 100644 (file)
@@ -721,13 +721,15 @@ trace_context_set_sample_mask(struct pipe_context *_pipe,
 static INLINE void
 trace_context_set_constant_buffer(struct pipe_context *_pipe,
                                   uint shader, uint index,
-                                  struct pipe_resource *buffer)
+                                  struct pipe_constant_buffer *constant_buffer)
 {
    struct trace_context *tr_ctx = trace_context(_pipe);
    struct pipe_context *pipe = tr_ctx->pipe;
+   struct pipe_constant_buffer cb;
 
-   if (buffer) {
-      buffer = trace_resource_unwrap(tr_ctx, buffer);
+   if (constant_buffer) {
+      cb = *constant_buffer;
+      cb.buffer = trace_resource_unwrap(tr_ctx, constant_buffer->buffer);
    }
 
    trace_dump_call_begin("pipe_context", "set_constant_buffer");
@@ -735,9 +737,18 @@ trace_context_set_constant_buffer(struct pipe_context *_pipe,
    trace_dump_arg(ptr, pipe);
    trace_dump_arg(uint, shader);
    trace_dump_arg(uint, index);
-   trace_dump_arg(ptr, buffer);
+   if (constant_buffer) {
+      trace_dump_struct_begin("pipe_constant_buffer");
+      trace_dump_member(ptr, constant_buffer, buffer);
+      trace_dump_member(uint, constant_buffer, buffer_offset);
+      trace_dump_member(uint, constant_buffer, buffer_size);
+      trace_dump_struct_end();
+   } else {
+      trace_dump_arg(ptr, constant_buffer);
+   }
 
-   pipe->set_constant_buffer(pipe, shader, index, buffer);
+   pipe->set_constant_buffer(pipe, shader, index,
+                             constant_buffer ? &cb : NULL);
 
    trace_dump_call_end();
 }
index 8b4a1588b86c11e1492a342a676c6e957388520a..1871b21461004fb350898de5faede857c9797233 100644 (file)
@@ -41,6 +41,7 @@ struct pipe_blend_color;
 struct pipe_blend_state;
 struct pipe_box;
 struct pipe_clip_state;
+struct pipe_constant_buffer;
 struct pipe_depth_stencil_alpha_state;
 struct pipe_draw_info;
 struct pipe_fence_handle;
@@ -194,7 +195,7 @@ struct pipe_context {
 
    void (*set_constant_buffer)( struct pipe_context *,
                                 uint shader, uint index,
-                                struct pipe_resource *buf );
+                                struct pipe_constant_buffer *buf );
 
    void (*set_framebuffer_state)( struct pipe_context *,
                                   const struct pipe_framebuffer_state * );
index a459a56a760e40b1973111ca50a26b0dcc03fc45..42510a685bf1954180f9fb15529cad9fb096f271 100644 (file)
@@ -450,6 +450,17 @@ struct pipe_vertex_buffer
 };
 
 
+/**
+ * A constant buffer.  A subrange of an existing buffer can be set
+ * as a constant buffer.
+ */
+struct pipe_constant_buffer {
+   struct pipe_resource *buffer; /**< the actual buffer */
+   unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */
+   unsigned buffer_size;   /**< how much data can be read in shader */
+};
+
+
 /**
  * A stream output target. The structure specifies the range vertices can
  * be written to.
index d5c366ffd4f0b13d4ea31ba3de8c3f557ec25c29..a7b761c707fa163505dc60949828a37796b650a3 100644 (file)
@@ -344,7 +344,7 @@ struct GalliumD3D10Device : public GalliumD3D10ScreenImpl<threadsafe>
                        {
                                constant_buffers[s][start + i] = constbufs[i];
                                if(s < caps.stages && start + i < caps.constant_buffers[s])
-                                       pipe->set_constant_buffer(pipe, s, start + i, constbufs[i] ? constbufs[i]->resource : NULL);
+                                       pipe_set_constant_buffer(pipe, s, start + i, constbufs[i] ? constbufs[i]->resource : NULL);
                        }
                }
        }
@@ -1715,7 +1715,7 @@ struct GalliumD3D10Device : public GalliumD3D10ScreenImpl<threadsafe>
                {
                        unsigned num = std::min(caps.constant_buffers[s], (unsigned)D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
                        for(unsigned i = 0; i < num; ++i)
-                               pipe->set_constant_buffer(pipe, s, i, constant_buffers[s][i].p ? constant_buffers[s][i].p->resource : 0);
+                               pipe_set_constant_buffer(pipe, s, i, constant_buffers[s][i].p ? constant_buffers[s][i].p->resource : 0);
                }
 
                update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_VS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_VS));
@@ -1961,7 +1961,7 @@ struct GalliumD3D10Device : public GalliumD3D10ScreenImpl<threadsafe>
                                if(constant_buffers[s][i] == buffer)
                                {
                                        constant_buffers[s][i] = (ID3D10Buffer*)NULL;
-                                       pipe->set_constant_buffer(pipe, s, i, NULL);
+                                       pipe_set_constant_buffer(pipe, s, i, NULL);
                                }
                        }
                }
index add1eec00385b11473aebace171a08f6e638488d..bafe55257f64f2de5a8ce1d270eebb55f5c4b89d 100644 (file)
@@ -179,7 +179,7 @@ static void renderer_set_mvp(struct renderer *renderer,
       pipe_buffer_write(renderer->pipe, cbuf,
             0, sizeof(consts), consts);
    }
-   renderer->pipe->set_constant_buffer(renderer->pipe,
+   pipe_set_constant_buffer(renderer->pipe,
          PIPE_SHADER_VERTEX, 0, cbuf);
 
    memcpy(cur, mvp, sizeof(*mvp));
@@ -478,7 +478,7 @@ static void renderer_set_custom_fs(struct renderer *renderer,
                const_buffer_len);
          pipe_buffer_write(renderer->pipe, cbuf, 0,
                const_buffer_len, const_buffer);
-         renderer->pipe->set_constant_buffer(renderer->pipe,
+         pipe_set_constant_buffer(renderer->pipe,
                PIPE_SHADER_FRAGMENT, 0, cbuf);
 
          renderer->fs_cbuf = cbuf;
index 7052f396c3aadb81fe235bab53250d09d68a958f..8ba6e1ead691e01ba07c3b5a8f4895520fffb6f6 100644 (file)
@@ -408,7 +408,7 @@ renderer_set_constants(struct xa_context *r,
     if (*cbuf) {
        pipe_buffer_write(r->pipe, *cbuf, 0, param_bytes, params);
     }
-    r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
+    pipe_set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
 }
 
 void
index eba72d81908defcda8d81a87445b1a937dddf096..e28e06a9261f026737af6a72ba56e8321dea1ae2 100644 (file)
@@ -437,7 +437,7 @@ void renderer_set_constants(struct xorg_renderer *r,
       pipe_buffer_write(r->pipe, *cbuf,
                         0, param_bytes, params);
    }
-   r->pipe->set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
+   pipe_set_constant_buffer(r->pipe, shader_type, 0, *cbuf);
 }
 
 
index f8b2a0a77a0a36425bf3df664bcaafc1f51f7198..b42a86cfc8ed85c4bc98887f4ffe5a7fa5e92840 100644 (file)
@@ -148,7 +148,7 @@ static void init_fs_constbuf( void )
                                  sizeof constants1);
 
 
-      ctx->set_constant_buffer(ctx,
+      pipe_set_constant_buffer(ctx,
                                PIPE_SHADER_FRAGMENT, 0,
                                constbuf1);
    }
@@ -165,7 +165,7 @@ static void init_fs_constbuf( void )
                                  sizeof constants2);
 
 
-      ctx->set_constant_buffer(ctx,
+      pipe_set_constant_buffer(ctx,
                                PIPE_SHADER_FRAGMENT, 1,
                                constbuf2);
    }
index ef2440291fc28f95bbee360eca596c353bd0b638..a471abd9a3d1e2e07dfac6669f4714ae9a09792d 100644 (file)
@@ -181,7 +181,7 @@ static void init_fs_constbuf( void )
                                  sizeof constants1);
 
 
-      ctx->set_constant_buffer(ctx,
+      pipe_set_constant_buffer(ctx,
                                PIPE_SHADER_GEOMETRY, 0,
                                constbuf1);
    }
@@ -198,7 +198,7 @@ static void init_fs_constbuf( void )
                                  sizeof constants2);
 
 
-      ctx->set_constant_buffer(ctx,
+      pipe_set_constant_buffer(ctx,
                                PIPE_SHADER_GEOMETRY, 1,
                                constbuf2);
    }
index 83d86fbf5b253ea73434d9add08a9d897849e6e3..23b7ada98ad49799232cc41d9740f33055c73efc 100644 (file)
@@ -110,7 +110,7 @@ static void init_fs_constbuf( void )
                               sizeof constants);
 
 
-   ctx->set_constant_buffer(ctx,
+   pipe_set_constant_buffer(ctx,
                             PIPE_SHADER_FRAGMENT, 0,
                             constbuf);
 }
index 05667a743053b59b2a751fd7b8a3cc220dab67e5..87bb51543f5af1aa82408dc4bf98f28635a6c012 100644 (file)
@@ -63,7 +63,7 @@ void st_upload_constants( struct st_context *st,
 
    /* update constants */
    if (params && params->NumParameters) {
-      struct pipe_resource *cbuf;
+      struct pipe_constant_buffer cb;
       const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
 
       /* Update the constants which come from fixed-function state, such as
@@ -77,10 +77,12 @@ void st_upload_constants( struct st_context *st,
        * avoid gratuitous rendering synchronization.
        * Let's use a user buffer to avoid an unnecessary copy.
        */
-      cbuf = pipe_user_buffer_create(pipe->screen,
-                                     params->ParameterValues,
-                                     paramBytes,
-                                     PIPE_BIND_CONSTANT_BUFFER);
+      cb.buffer = pipe_user_buffer_create(pipe->screen,
+                                          params->ParameterValues,
+                                          paramBytes,
+                                          PIPE_BIND_CONSTANT_BUFFER);
+      cb.buffer_offset = 0;
+      cb.buffer_size = paramBytes;
 
       if (ST_DEBUG & DEBUG_CONSTANTS) {
         debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n", 
@@ -89,8 +91,8 @@ void st_upload_constants( struct st_context *st,
          _mesa_print_parameter_list(params);
       }
 
-      st->pipe->set_constant_buffer(st->pipe, shader_type, 0, cbuf);
-      pipe_resource_reference(&cbuf, NULL);
+      st->pipe->set_constant_buffer(st->pipe, shader_type, 0, &cb);
+      pipe_resource_reference(&cb.buffer, NULL);
 
       st->state.constants[shader_type].ptr = params->ParameterValues;
       st->state.constants[shader_type].size = paramBytes;