From 507337864fa80caf9f26602324d2c28dd0a75d61 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Tue, 24 Apr 2012 19:52:26 +0200 Subject: gallium: change set_constant_buffer to be UBO-friendly --- src/gallium/state_trackers/vega/renderer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gallium/state_trackers/vega/renderer.c') diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index add1eec0038..bafe55257f6 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -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; -- cgit v1.2.3 From 0279d15c990d831c7cc4e76cbe7caeba1347b689 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 29 Apr 2012 21:32:52 +0200 Subject: st/vega: use cso_draw_arrays --- src/gallium/state_trackers/vega/renderer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gallium/state_trackers/vega/renderer.c') diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index bafe55257f6..4c20b1634c4 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -1054,7 +1054,7 @@ void renderer_polygon_stencil(struct renderer *renderer, cso_set_vertex_buffers(renderer->cso, 1, vbuf); if (!renderer->u.polygon_stencil.manual_two_sides) { - util_draw_arrays(renderer->pipe, mode, start, count); + cso_draw_arrays(renderer->cso, mode, start, count); } else { struct pipe_rasterizer_state raster; @@ -1069,7 +1069,7 @@ void renderer_polygon_stencil(struct renderer *renderer, cso_set_rasterizer(renderer->cso, &raster); cso_set_depth_stencil_alpha(renderer->cso, &dsa); - util_draw_arrays(renderer->pipe, mode, start, count); + cso_draw_arrays(renderer->cso, mode, start, count); /* back */ raster.cull_face = PIPE_FACE_FRONT; @@ -1077,7 +1077,7 @@ void renderer_polygon_stencil(struct renderer *renderer, cso_set_rasterizer(renderer->cso, &raster); cso_set_depth_stencil_alpha(renderer->cso, &dsa); - util_draw_arrays(renderer->pipe, mode, start, count); + cso_draw_arrays(renderer->cso, mode, start, count); } } -- cgit v1.2.3 From fa20733a622770eaaa941f64d570d7b63d8f37b6 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Sun, 29 Apr 2012 21:33:37 +0200 Subject: st/vega: don't use user_buffer_create --- src/gallium/auxiliary/util/u_draw_quad.c | 21 +++++++++++++++++++++ src/gallium/auxiliary/util/u_draw_quad.h | 3 +++ src/gallium/state_trackers/vega/polygon.c | 29 +++++++---------------------- src/gallium/state_trackers/vega/renderer.c | 17 +++-------------- 4 files changed, 34 insertions(+), 36 deletions(-) (limited to 'src/gallium/state_trackers/vega/renderer.c') diff --git a/src/gallium/auxiliary/util/u_draw_quad.c b/src/gallium/auxiliary/util/u_draw_quad.c index 1fbe12171c5..469c874988d 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.c +++ b/src/gallium/auxiliary/util/u_draw_quad.c @@ -69,6 +69,27 @@ util_draw_vertex_buffer(struct pipe_context *pipe, } +/** + * Draw a simple vertex buffer / primitive. + * Limited to float[4] vertex attribs, tightly packed. + */ +void +util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer, + uint prim_type, uint num_verts, uint num_attribs) +{ + struct pipe_vertex_buffer vbuffer = {0}; + + assert(num_attribs <= PIPE_MAX_ATTRIBS); + + vbuffer.user_buffer = buffer; + vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */ + + /* note: vertex elements already set by caller */ + + cso_set_vertex_buffers(cso, 1, &vbuffer); + cso_draw_arrays(cso, prim_type, 0, num_verts); +} + /** * Draw screen-aligned textured quad. diff --git a/src/gallium/auxiliary/util/u_draw_quad.h b/src/gallium/auxiliary/util/u_draw_quad.h index f1167786f0e..2834a4a8115 100644 --- a/src/gallium/auxiliary/util/u_draw_quad.h +++ b/src/gallium/auxiliary/util/u_draw_quad.h @@ -47,6 +47,9 @@ util_draw_vertex_buffer(struct pipe_context *pipe, struct cso_context *cso, struct pipe_resource *vbuf, uint offset, uint num_attribs, uint num_verts, uint prim_type); +void +util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer, + uint prim_type, uint num_verts, uint num_attribs); extern void util_draw_texquad(struct pipe_context *pipe, struct cso_context *cso, diff --git a/src/gallium/state_trackers/vega/polygon.c b/src/gallium/state_trackers/vega/polygon.c index bcc5cb272ca..3faec749e12 100644 --- a/src/gallium/state_trackers/vega/polygon.c +++ b/src/gallium/state_trackers/vega/polygon.c @@ -57,7 +57,7 @@ struct polygon VGint num_verts; VGboolean dirty; - struct pipe_resource *vbuf; + void *user_vbuf; struct pipe_screen *screen; }; @@ -89,7 +89,7 @@ struct polygon * polygon_create(int size) poly->size = size; poly->num_verts = 0; poly->dirty = VG_TRUE; - poly->vbuf = NULL; + poly->user_vbuf = NULL; return poly; } @@ -101,16 +101,13 @@ struct polygon * polygon_create_from_data(float *data, int size) memcpy(poly->data, data, sizeof(float) * COMPONENTS * size); poly->num_verts = size; poly->dirty = VG_TRUE; - poly->vbuf = NULL; + poly->user_vbuf = NULL; return poly; } void polygon_destroy(struct polygon *poly) { - if (poly->vbuf) - pipe_resource_reference(&poly->vbuf, NULL); - free(poly->data); free(poly); } @@ -247,25 +244,15 @@ VGboolean polygon_is_closed(struct polygon *p) static void polygon_prepare_buffer(struct vg_context *ctx, struct polygon *poly) { - int vert_size; struct pipe_context *pipe; - vert_size = poly->num_verts * COMPONENTS * sizeof(float); - /*polygon_print(poly);*/ pipe = ctx->pipe; - if (poly->vbuf == NULL || poly->dirty) { - if (poly->vbuf) { - pipe_resource_reference(&poly->vbuf, - NULL); - } + if (poly->user_vbuf == NULL || poly->dirty) { poly->screen = pipe->screen; - poly->vbuf= pipe_user_buffer_create(poly->screen, - poly->data, - vert_size, - PIPE_BIND_VERTEX_BUFFER); + poly->user_vbuf = poly->data; poly->dirty = VG_FALSE; } } @@ -300,9 +287,8 @@ void polygon_fill(struct polygon *poly, struct vg_context *ctx) /* tell renderer about the vertex buffer */ memset(&vbuffer, 0, sizeof(vbuffer)); - vbuffer.buffer = poly->vbuf; + vbuffer.user_buffer = poly->user_vbuf; vbuffer.stride = COMPONENTS * sizeof(float); /* vertex size */ - vbuffer.buffer_offset = 0; renderer_polygon_stencil_begin(ctx->renderer, &velement, ctx->state.vg.fill_rule, VG_FALSE); @@ -343,7 +329,6 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx) /* tell renderer about the vertex buffer */ memset(&vbuffer, 0, sizeof(vbuffer)); vbuffer.stride = COMPONENTS * sizeof(float); /* vertex size */ - vbuffer.buffer_offset = 0; /* prepare the stencil buffer */ renderer_polygon_stencil_begin(ctx->renderer, @@ -352,7 +337,7 @@ void polygon_array_fill(struct polygon_array *polyarray, struct vg_context *ctx) struct polygon *poly = (((struct polygon**)polys->data)[i]); polygon_prepare_buffer(ctx, poly); - vbuffer.buffer = poly->vbuf; + vbuffer.user_buffer = poly->user_vbuf; renderer_polygon_stencil(ctx->renderer, &vbuffer, PIPE_PRIM_TRIANGLE_FAN, 0, (VGuint) poly->num_verts); diff --git a/src/gallium/state_trackers/vega/renderer.c b/src/gallium/state_trackers/vega/renderer.c index 4c20b1634c4..23ec14ab84c 100644 --- a/src/gallium/state_trackers/vega/renderer.c +++ b/src/gallium/state_trackers/vega/renderer.c @@ -566,20 +566,9 @@ static void renderer_quad_texcoord(struct renderer *r, */ static void renderer_quad_draw(struct renderer *r) { - struct pipe_resource *buf; - - buf = pipe_user_buffer_create(r->pipe->screen, - r->vertices, - sizeof(r->vertices), - PIPE_BIND_VERTEX_BUFFER); - if (buf) { - util_draw_vertex_buffer(r->pipe, r->cso, buf, 0, - PIPE_PRIM_TRIANGLE_FAN, - Elements(r->vertices), /* verts */ - Elements(r->vertices[0])); /* attribs/vert */ - - pipe_resource_reference(&buf, NULL); - } + util_draw_user_vertex_buffer(r->cso, r->vertices, PIPE_PRIM_TRIANGLE_FAN, + Elements(r->vertices), /* verts */ + Elements(r->vertices[0])); /* attribs/vert */ } /** -- cgit v1.2.3