freedreno/a3xx+a4xx: move common VBOs to fd_context
authorRob Clark <robdclark@gmail.com>
Sat, 13 Aug 2016 15:39:25 +0000 (11:39 -0400)
committerRob Clark <robdclark@gmail.com>
Sat, 13 Aug 2016 17:59:03 +0000 (13:59 -0400)
These are the same for a3xx and later.  (a2xx could probably use them
too, but due to limited hw support and ancient downstream kernels, it
isn't so easy to test.)

Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/a3xx/fd3_context.c
src/gallium/drivers/freedreno/a3xx/fd3_context.h
src/gallium/drivers/freedreno/a3xx/fd3_draw.c
src/gallium/drivers/freedreno/a3xx/fd3_gmem.c
src/gallium/drivers/freedreno/a4xx/fd4_context.c
src/gallium/drivers/freedreno/a4xx/fd4_context.h
src/gallium/drivers/freedreno/a4xx/fd4_draw.c
src/gallium/drivers/freedreno/a4xx/fd4_gmem.c
src/gallium/drivers/freedreno/freedreno_context.c
src/gallium/drivers/freedreno/freedreno_context.h

index 2ffc2e0e53a465e75394e120dac9f5f9efdd18d7..af5e60a7e63967885b8431f7ef6b65659d994be1 100644 (file)
@@ -47,44 +47,13 @@ fd3_context_destroy(struct pipe_context *pctx)
        fd_bo_del(fd3_ctx->fs_pvt_mem);
        fd_bo_del(fd3_ctx->vsc_size_mem);
 
-       pctx->delete_vertex_elements_state(pctx, fd3_ctx->solid_vbuf_state.vtx);
-       pctx->delete_vertex_elements_state(pctx, fd3_ctx->blit_vbuf_state.vtx);
-
-       pipe_resource_reference(&fd3_ctx->solid_vbuf, NULL);
-       pipe_resource_reference(&fd3_ctx->blit_texcoord_vbuf, NULL);
+       fd_context_cleanup_common_vbos(&fd3_ctx->base);
 
        u_upload_destroy(fd3_ctx->border_color_uploader);
 
        fd_context_destroy(pctx);
 }
 
-/* TODO we could combine a few of these small buffers (solid_vbuf,
- * blit_texcoord_vbuf, and vsc_size_mem, into a single buffer and
- * save a tiny bit of memory
- */
-
-static struct pipe_resource *
-create_solid_vertexbuf(struct pipe_context *pctx)
-{
-       static const float init_shader_const[] = {
-                       -1.000000, +1.000000, +1.000000,
-                       +1.000000, -1.000000, +1.000000,
-       };
-       struct pipe_resource *prsc = pipe_buffer_create(pctx->screen,
-                       PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE, sizeof(init_shader_const));
-       pipe_buffer_write(pctx, prsc, 0,
-                       sizeof(init_shader_const), init_shader_const);
-       return prsc;
-}
-
-static struct pipe_resource *
-create_blit_texcoord_vertexbuf(struct pipe_context *pctx)
-{
-       struct pipe_resource *prsc = pipe_buffer_create(pctx->screen,
-                       PIPE_BIND_CUSTOM, PIPE_USAGE_DYNAMIC, 16);
-       return prsc;
-}
-
 static const uint8_t primtypes[PIPE_PRIM_MAX] = {
                [PIPE_PRIM_POINTS]         = DI_PT_POINTLIST,
                [PIPE_PRIM_LINES]          = DI_PT_LINELIST,
@@ -134,36 +103,7 @@ fd3_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        fd3_ctx->vsc_size_mem = fd_bo_new(screen->dev, 0x1000,
                        DRM_FREEDRENO_GEM_TYPE_KMEM);
 
-       fd3_ctx->solid_vbuf = create_solid_vertexbuf(pctx);
-       fd3_ctx->blit_texcoord_vbuf = create_blit_texcoord_vertexbuf(pctx);
-
-       /* setup solid_vbuf_state: */
-       fd3_ctx->solid_vbuf_state.vtx = pctx->create_vertex_elements_state(
-                       pctx, 1, (struct pipe_vertex_element[]){{
-                               .vertex_buffer_index = 0,
-                               .src_offset = 0,
-                               .src_format = PIPE_FORMAT_R32G32B32_FLOAT,
-                       }});
-       fd3_ctx->solid_vbuf_state.vertexbuf.count = 1;
-       fd3_ctx->solid_vbuf_state.vertexbuf.vb[0].stride = 12;
-       fd3_ctx->solid_vbuf_state.vertexbuf.vb[0].buffer = fd3_ctx->solid_vbuf;
-
-       /* setup blit_vbuf_state: */
-       fd3_ctx->blit_vbuf_state.vtx = pctx->create_vertex_elements_state(
-                       pctx, 2, (struct pipe_vertex_element[]){{
-                               .vertex_buffer_index = 0,
-                               .src_offset = 0,
-                               .src_format = PIPE_FORMAT_R32G32_FLOAT,
-                       }, {
-                               .vertex_buffer_index = 1,
-                               .src_offset = 0,
-                               .src_format = PIPE_FORMAT_R32G32B32_FLOAT,
-                       }});
-       fd3_ctx->blit_vbuf_state.vertexbuf.count = 2;
-       fd3_ctx->blit_vbuf_state.vertexbuf.vb[0].stride = 8;
-       fd3_ctx->blit_vbuf_state.vertexbuf.vb[0].buffer = fd3_ctx->blit_texcoord_vbuf;
-       fd3_ctx->blit_vbuf_state.vertexbuf.vb[1].stride = 12;
-       fd3_ctx->blit_vbuf_state.vertexbuf.vb[1].buffer = fd3_ctx->solid_vbuf;
+       fd_context_setup_common_vbos(&fd3_ctx->base);
 
        fd3_query_context_init(pctx);
 
index 0735411036146e7e0dd03fba3eb33032c24697f9..873c344ad137f559ee869dce54d3e11042f9c260 100644 (file)
@@ -48,26 +48,6 @@ struct fd3_context {
         */
        struct fd_bo *vsc_size_mem;
 
-       /* vertex buf used for clear/gmem->mem vertices, and mem->gmem
-        * vertices:
-        */
-       struct pipe_resource *solid_vbuf;
-
-       /* vertex buf used for mem->gmem tex coords:
-        */
-       struct pipe_resource *blit_texcoord_vbuf;
-
-       /* vertex state for solid_vbuf:
-        *    - solid_vbuf / 12 / R32G32B32_FLOAT
-        */
-       struct fd_vertex_state solid_vbuf_state;
-
-       /* vertex state for blit_prog:
-        *    - blit_texcoord_vbuf / 8 / R32G32_FLOAT
-        *    - solid_vbuf / 12 / R32G32B32_FLOAT
-        */
-       struct fd_vertex_state blit_vbuf_state;
-
        struct u_upload_mgr *border_color_uploader;
        struct pipe_resource *border_color_buf;
 
index 44ae1f9db8a3f3756f234f9e7f67e554107e10c0..9e6a8bc919367691cb0562b4b26b4bbca1c26713 100644 (file)
@@ -207,11 +207,10 @@ reset_viewport(struct fd_ringbuffer *ring, struct pipe_framebuffer_state *pfb)
 static void
 fd3_clear_binning(struct fd_context *ctx, unsigned dirty)
 {
-       struct fd3_context *fd3_ctx = fd3_context(ctx);
        struct fd_ringbuffer *ring = ctx->batch->binning;
        struct fd3_emit emit = {
                .debug = &ctx->debug,
-               .vtx  = &fd3_ctx->solid_vbuf_state,
+               .vtx  = &ctx->solid_vbuf_state,
                .prog = &ctx->solid_prog,
                .key = {
                        .binning_pass = true,
@@ -247,14 +246,13 @@ static void
 fd3_clear(struct fd_context *ctx, unsigned buffers,
                const union pipe_color_union *color, double depth, unsigned stencil)
 {
-       struct fd3_context *fd3_ctx = fd3_context(ctx);
        struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
        struct fd_ringbuffer *ring = ctx->batch->draw;
        unsigned dirty = ctx->dirty;
        unsigned i;
        struct fd3_emit emit = {
                .debug = &ctx->debug,
-               .vtx  = &fd3_ctx->solid_vbuf_state,
+               .vtx  = &ctx->solid_vbuf_state,
                .prog = &ctx->solid_prog,
                .key = {
                        .half_precision = fd_half_precision(pfb),
index ec0a77b414006c9d8290560be08622d386974ff6..51c858ace9ea94aab147da6bdafd459d73fea5d4 100644 (file)
@@ -158,12 +158,11 @@ static void
 emit_binning_workaround(struct fd_batch *batch)
 {
        struct fd_context *ctx = batch->ctx;
-       struct fd3_context *fd3_ctx = fd3_context(ctx);
        struct fd_gmem_stateobj *gmem = &ctx->gmem;
        struct fd_ringbuffer *ring = batch->gmem;
        struct fd3_emit emit = {
                        .debug = &ctx->debug,
-                       .vtx = &fd3_ctx->solid_vbuf_state,
+                       .vtx = &ctx->solid_vbuf_state,
                        .prog = &ctx->solid_prog,
                        .key = {
                                .half_precision = true,
@@ -182,7 +181,7 @@ emit_binning_workaround(struct fd_batch *batch)
        OUT_RING(ring, A3XX_RB_COPY_CONTROL_MSAA_RESOLVE(MSAA_ONE) |
                        A3XX_RB_COPY_CONTROL_MODE(0) |
                        A3XX_RB_COPY_CONTROL_GMEM_BASE(0));
-       OUT_RELOCW(ring, fd_resource(fd3_ctx->solid_vbuf)->bo, 0x20, 0, -1);  /* RB_COPY_DEST_BASE */
+       OUT_RELOCW(ring, fd_resource(ctx->solid_vbuf)->bo, 0x20, 0, -1);  /* RB_COPY_DEST_BASE */
        OUT_RING(ring, A3XX_RB_COPY_DEST_PITCH_PITCH(128));
        OUT_RING(ring, A3XX_RB_COPY_DEST_INFO_TILE(LINEAR) |
                        A3XX_RB_COPY_DEST_INFO_FORMAT(RB_R8G8B8A8_UNORM) |
@@ -351,12 +350,11 @@ static void
 fd3_emit_tile_gmem2mem(struct fd_batch *batch, struct fd_tile *tile)
 {
        struct fd_context *ctx = batch->ctx;
-       struct fd3_context *fd3_ctx = fd3_context(ctx);
        struct fd_ringbuffer *ring = batch->gmem;
        struct pipe_framebuffer_state *pfb = &batch->framebuffer;
        struct fd3_emit emit = {
                        .debug = &ctx->debug,
-                       .vtx = &fd3_ctx->solid_vbuf_state,
+                       .vtx = &ctx->solid_vbuf_state,
                        .prog = &ctx->solid_prog,
                        .key = {
                                .half_precision = true,
@@ -533,13 +531,12 @@ static void
 fd3_emit_tile_mem2gmem(struct fd_batch *batch, struct fd_tile *tile)
 {
        struct fd_context *ctx = batch->ctx;
-       struct fd3_context *fd3_ctx = fd3_context(ctx);
        struct fd_gmem_stateobj *gmem = &ctx->gmem;
        struct fd_ringbuffer *ring = batch->gmem;
        struct pipe_framebuffer_state *pfb = &batch->framebuffer;
        struct fd3_emit emit = {
                        .debug = &ctx->debug,
-                       .vtx = &fd3_ctx->blit_vbuf_state,
+                       .vtx = &ctx->blit_vbuf_state,
                        .sprite_coord_enable = 1,
                        /* NOTE: They all use the same VP, this is for vtx bufs. */
                        .prog = &ctx->blit_prog[0],
@@ -559,7 +556,7 @@ fd3_emit_tile_mem2gmem(struct fd_batch *batch, struct fd_tile *tile)
        y1 = ((float)tile->yoff + bin_h) / ((float)pfb->height);
 
        OUT_PKT3(ring, CP_MEM_WRITE, 5);
-       OUT_RELOCW(ring, fd_resource(fd3_ctx->blit_texcoord_vbuf)->bo, 0, 0, 0);
+       OUT_RELOCW(ring, fd_resource(ctx->blit_texcoord_vbuf)->bo, 0, 0, 0);
        OUT_RING(ring, fui(x0));
        OUT_RING(ring, fui(y0));
        OUT_RING(ring, fui(x1));
index 62cfda97ac374e888ff0f319789a838478e79296..8ef715f1b7f69c8a0a338b128df7c2bdd478af1c 100644 (file)
@@ -47,44 +47,13 @@ fd4_context_destroy(struct pipe_context *pctx)
        fd_bo_del(fd4_ctx->fs_pvt_mem);
        fd_bo_del(fd4_ctx->vsc_size_mem);
 
-       pctx->delete_vertex_elements_state(pctx, fd4_ctx->solid_vbuf_state.vtx);
-       pctx->delete_vertex_elements_state(pctx, fd4_ctx->blit_vbuf_state.vtx);
-
-       pipe_resource_reference(&fd4_ctx->solid_vbuf, NULL);
-       pipe_resource_reference(&fd4_ctx->blit_texcoord_vbuf, NULL);
+       fd_context_cleanup_common_vbos(&fd4_ctx->base);
 
        u_upload_destroy(fd4_ctx->border_color_uploader);
 
        fd_context_destroy(pctx);
 }
 
-/* TODO we could combine a few of these small buffers (solid_vbuf,
- * blit_texcoord_vbuf, and vsc_size_mem, into a single buffer and
- * save a tiny bit of memory
- */
-
-static struct pipe_resource *
-create_solid_vertexbuf(struct pipe_context *pctx)
-{
-       static const float init_shader_const[] = {
-                       -1.000000, +1.000000, +1.000000,
-                       +1.000000, -1.000000, +1.000000,
-       };
-       struct pipe_resource *prsc = pipe_buffer_create(pctx->screen,
-                       PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE, sizeof(init_shader_const));
-       pipe_buffer_write(pctx, prsc, 0,
-                       sizeof(init_shader_const), init_shader_const);
-       return prsc;
-}
-
-static struct pipe_resource *
-create_blit_texcoord_vertexbuf(struct pipe_context *pctx)
-{
-       struct pipe_resource *prsc = pipe_buffer_create(pctx->screen,
-                       PIPE_BIND_CUSTOM, PIPE_USAGE_DYNAMIC, 16);
-       return prsc;
-}
-
 static const uint8_t primtypes[PIPE_PRIM_MAX] = {
                [PIPE_PRIM_POINTS]         = DI_PT_POINTLIST,
                [PIPE_PRIM_LINES]          = DI_PT_LINELIST,
@@ -134,36 +103,7 @@ fd4_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
        fd4_ctx->vsc_size_mem = fd_bo_new(screen->dev, 0x1000,
                        DRM_FREEDRENO_GEM_TYPE_KMEM);
 
-       fd4_ctx->solid_vbuf = create_solid_vertexbuf(pctx);
-       fd4_ctx->blit_texcoord_vbuf = create_blit_texcoord_vertexbuf(pctx);
-
-       /* setup solid_vbuf_state: */
-       fd4_ctx->solid_vbuf_state.vtx = pctx->create_vertex_elements_state(
-                       pctx, 1, (struct pipe_vertex_element[]){{
-                               .vertex_buffer_index = 0,
-                               .src_offset = 0,
-                               .src_format = PIPE_FORMAT_R32G32B32_FLOAT,
-                       }});
-       fd4_ctx->solid_vbuf_state.vertexbuf.count = 1;
-       fd4_ctx->solid_vbuf_state.vertexbuf.vb[0].stride = 12;
-       fd4_ctx->solid_vbuf_state.vertexbuf.vb[0].buffer = fd4_ctx->solid_vbuf;
-
-       /* setup blit_vbuf_state: */
-       fd4_ctx->blit_vbuf_state.vtx = pctx->create_vertex_elements_state(
-                       pctx, 2, (struct pipe_vertex_element[]){{
-                               .vertex_buffer_index = 0,
-                               .src_offset = 0,
-                               .src_format = PIPE_FORMAT_R32G32_FLOAT,
-                       }, {
-                               .vertex_buffer_index = 1,
-                               .src_offset = 0,
-                               .src_format = PIPE_FORMAT_R32G32B32_FLOAT,
-                       }});
-       fd4_ctx->blit_vbuf_state.vertexbuf.count = 2;
-       fd4_ctx->blit_vbuf_state.vertexbuf.vb[0].stride = 8;
-       fd4_ctx->blit_vbuf_state.vertexbuf.vb[0].buffer = fd4_ctx->blit_texcoord_vbuf;
-       fd4_ctx->blit_vbuf_state.vertexbuf.vb[1].stride = 12;
-       fd4_ctx->blit_vbuf_state.vertexbuf.vb[1].buffer = fd4_ctx->solid_vbuf;
+       fd_context_setup_common_vbos(&fd4_ctx->base);
 
        fd4_query_context_init(pctx);
 
index 9467fc529bf65527f5c8bc7b09d2bece2cc218c5..4c06644a9fa091771cd43a2ae54f76cea78777db 100644 (file)
@@ -49,26 +49,6 @@ struct fd4_context {
         */
        struct fd_bo *vsc_size_mem;
 
-       /* vertex buf used for clear/gmem->mem vertices, and mem->gmem
-        * vertices:
-        */
-       struct pipe_resource *solid_vbuf;
-
-       /* vertex buf used for mem->gmem tex coords:
-        */
-       struct pipe_resource *blit_texcoord_vbuf;
-
-       /* vertex state for solid_vbuf:
-        *    - solid_vbuf / 12 / R32G32B32_FLOAT
-        */
-       struct fd_vertex_state solid_vbuf_state;
-
-       /* vertex state for blit_prog:
-        *    - blit_texcoord_vbuf / 8 / R32G32_FLOAT
-        *    - solid_vbuf / 12 / R32G32B32_FLOAT
-        */
-       struct fd_vertex_state blit_vbuf_state;
-
        struct u_upload_mgr *border_color_uploader;
        struct pipe_resource *border_color_buf;
 
index f217619848aa2069116c892ffa800a519cb39f5b..200e4f26876b11d5c3e977a0ea37033cec4c72d0 100644 (file)
@@ -217,11 +217,10 @@ reset_viewport(struct fd_ringbuffer *ring, struct pipe_framebuffer_state *pfb)
 static void
 fd4_clear_binning(struct fd_context *ctx, unsigned dirty)
 {
-       struct fd4_context *fd4_ctx = fd4_context(ctx);
        struct fd_ringbuffer *ring = ctx->batch->binning;
        struct fd4_emit emit = {
                .debug = &ctx->debug,
-               .vtx  = &fd4_ctx->solid_vbuf_state,
+               .vtx  = &ctx->solid_vbuf_state,
                .prog = &ctx->solid_prog,
                .key = {
                        .binning_pass = true,
@@ -251,7 +250,6 @@ static void
 fd4_clear(struct fd_context *ctx, unsigned buffers,
                const union pipe_color_union *color, double depth, unsigned stencil)
 {
-       struct fd4_context *fd4_ctx = fd4_context(ctx);
        struct fd_ringbuffer *ring = ctx->batch->draw;
        struct pipe_framebuffer_state *pfb = &ctx->batch->framebuffer;
        unsigned char mrt_comp[A4XX_MAX_RENDER_TARGETS] = {0};
@@ -259,7 +257,7 @@ fd4_clear(struct fd_context *ctx, unsigned buffers,
        unsigned i;
        struct fd4_emit emit = {
                .debug = &ctx->debug,
-               .vtx  = &fd4_ctx->solid_vbuf_state,
+               .vtx  = &ctx->solid_vbuf_state,
                .prog = &ctx->solid_prog,
                .key = {
                        .half_precision = fd_half_precision(pfb),
index 32541fe06f02f8fe7b584e6d5e12f2bdd5856d28..5b7dc0320458cf5acf6e349889c60c644aeb81f8 100644 (file)
@@ -188,13 +188,12 @@ static void
 fd4_emit_tile_gmem2mem(struct fd_batch *batch, struct fd_tile *tile)
 {
        struct fd_context *ctx = batch->ctx;
-       struct fd4_context *fd4_ctx = fd4_context(ctx);
        struct fd_gmem_stateobj *gmem = &ctx->gmem;
        struct fd_ringbuffer *ring = batch->gmem;
        struct pipe_framebuffer_state *pfb = &batch->framebuffer;
        struct fd4_emit emit = {
                        .debug = &ctx->debug,
-                       .vtx = &fd4_ctx->solid_vbuf_state,
+                       .vtx = &ctx->solid_vbuf_state,
                        .prog = &ctx->solid_prog,
                        .key = {
                                .half_precision = true,
@@ -327,13 +326,12 @@ static void
 fd4_emit_tile_mem2gmem(struct fd_batch *batch, struct fd_tile *tile)
 {
        struct fd_context *ctx = batch->ctx;
-       struct fd4_context *fd4_ctx = fd4_context(ctx);
        struct fd_gmem_stateobj *gmem = &ctx->gmem;
        struct fd_ringbuffer *ring = batch->gmem;
        struct pipe_framebuffer_state *pfb = &batch->framebuffer;
        struct fd4_emit emit = {
                        .debug = &ctx->debug,
-                       .vtx = &fd4_ctx->blit_vbuf_state,
+                       .vtx = &ctx->blit_vbuf_state,
                        .sprite_coord_enable = 1,
                        /* NOTE: They all use the same VP, this is for vtx bufs. */
                        .prog = &ctx->blit_prog[0],
@@ -355,7 +353,7 @@ fd4_emit_tile_mem2gmem(struct fd_batch *batch, struct fd_tile *tile)
        y1 = ((float)tile->yoff + bin_h) / ((float)pfb->height);
 
        OUT_PKT3(ring, CP_MEM_WRITE, 5);
-       OUT_RELOCW(ring, fd_resource(fd4_ctx->blit_texcoord_vbuf)->bo, 0, 0, 0);
+       OUT_RELOCW(ring, fd_resource(ctx->blit_texcoord_vbuf)->bo, 0, 0, 0);
        OUT_RING(ring, fui(x0));
        OUT_RING(ring, fui(y0));
        OUT_RING(ring, fui(x1));
index ab2faa429d6133ee3fb9085e78fa550881e5c2c0..402e88f7ca99b23bb9df47e49ada8f86f68a49b1 100644 (file)
@@ -150,6 +150,82 @@ fd_set_debug_callback(struct pipe_context *pctx,
                memset(&ctx->debug, 0, sizeof(ctx->debug));
 }
 
+/* TODO we could combine a few of these small buffers (solid_vbuf,
+ * blit_texcoord_vbuf, and vsc_size_mem, into a single buffer and
+ * save a tiny bit of memory
+ */
+
+static struct pipe_resource *
+create_solid_vertexbuf(struct pipe_context *pctx)
+{
+       static const float init_shader_const[] = {
+                       -1.000000, +1.000000, +1.000000,
+                       +1.000000, -1.000000, +1.000000,
+       };
+       struct pipe_resource *prsc = pipe_buffer_create(pctx->screen,
+                       PIPE_BIND_CUSTOM, PIPE_USAGE_IMMUTABLE, sizeof(init_shader_const));
+       pipe_buffer_write(pctx, prsc, 0,
+                       sizeof(init_shader_const), init_shader_const);
+       return prsc;
+}
+
+static struct pipe_resource *
+create_blit_texcoord_vertexbuf(struct pipe_context *pctx)
+{
+       struct pipe_resource *prsc = pipe_buffer_create(pctx->screen,
+                       PIPE_BIND_CUSTOM, PIPE_USAGE_DYNAMIC, 16);
+       return prsc;
+}
+
+void
+fd_context_setup_common_vbos(struct fd_context *ctx)
+{
+       struct pipe_context *pctx = &ctx->base;
+
+       ctx->solid_vbuf = create_solid_vertexbuf(pctx);
+       ctx->blit_texcoord_vbuf = create_blit_texcoord_vertexbuf(pctx);
+
+       /* setup solid_vbuf_state: */
+       ctx->solid_vbuf_state.vtx = pctx->create_vertex_elements_state(
+                       pctx, 1, (struct pipe_vertex_element[]){{
+                               .vertex_buffer_index = 0,
+                               .src_offset = 0,
+                               .src_format = PIPE_FORMAT_R32G32B32_FLOAT,
+                       }});
+       ctx->solid_vbuf_state.vertexbuf.count = 1;
+       ctx->solid_vbuf_state.vertexbuf.vb[0].stride = 12;
+       ctx->solid_vbuf_state.vertexbuf.vb[0].buffer = ctx->solid_vbuf;
+
+       /* setup blit_vbuf_state: */
+       ctx->blit_vbuf_state.vtx = pctx->create_vertex_elements_state(
+                       pctx, 2, (struct pipe_vertex_element[]){{
+                               .vertex_buffer_index = 0,
+                               .src_offset = 0,
+                               .src_format = PIPE_FORMAT_R32G32_FLOAT,
+                       }, {
+                               .vertex_buffer_index = 1,
+                               .src_offset = 0,
+                               .src_format = PIPE_FORMAT_R32G32B32_FLOAT,
+                       }});
+       ctx->blit_vbuf_state.vertexbuf.count = 2;
+       ctx->blit_vbuf_state.vertexbuf.vb[0].stride = 8;
+       ctx->blit_vbuf_state.vertexbuf.vb[0].buffer = ctx->blit_texcoord_vbuf;
+       ctx->blit_vbuf_state.vertexbuf.vb[1].stride = 12;
+       ctx->blit_vbuf_state.vertexbuf.vb[1].buffer = ctx->solid_vbuf;
+}
+
+void
+fd_context_cleanup_common_vbos(struct fd_context *ctx)
+{
+       struct pipe_context *pctx = &ctx->base;
+
+       pctx->delete_vertex_elements_state(pctx, ctx->solid_vbuf_state.vtx);
+       pctx->delete_vertex_elements_state(pctx, ctx->blit_vbuf_state.vtx);
+
+       pipe_resource_reference(&ctx->solid_vbuf, NULL);
+       pipe_resource_reference(&ctx->blit_texcoord_vbuf, NULL);
+}
+
 struct pipe_context *
 fd_context_init(struct fd_context *ctx, struct pipe_screen *pscreen,
                const uint8_t *primtypes, void *priv)
index b3674b8115c9a036c965c3b433d58c1da45de934..ffc4d9ef47ce1df7819e44ecd79f9be531ddaa57 100644 (file)
@@ -275,6 +275,27 @@ struct fd_context {
 
        /* indirect-branch emit: */
        void (*emit_ib)(struct fd_ringbuffer *ring, struct fd_ringbuffer *target);
+
+       /*
+        * Common pre-cooked VBO state (used for a3xx and later):
+        */
+
+       /* for clear/gmem->mem vertices, and mem->gmem */
+       struct pipe_resource *solid_vbuf;
+
+       /* for mem->gmem tex coords: */
+       struct pipe_resource *blit_texcoord_vbuf;
+
+       /* vertex state for solid_vbuf:
+        *    - solid_vbuf / 12 / R32G32B32_FLOAT
+        */
+       struct fd_vertex_state solid_vbuf_state;
+
+       /* vertex state for blit_prog:
+        *    - blit_texcoord_vbuf / 8 / R32G32_FLOAT
+        *    - solid_vbuf / 12 / R32G32B32_FLOAT
+        */
+       struct fd_vertex_state blit_vbuf_state;
 };
 
 static inline struct fd_context *
@@ -315,6 +336,9 @@ fd_supported_prim(struct fd_context *ctx, unsigned prim)
        return (1 << prim) & ctx->primtype_mask;
 }
 
+void fd_context_setup_common_vbos(struct fd_context *ctx);
+void fd_context_cleanup_common_vbos(struct fd_context *ctx);
+
 struct pipe_context * fd_context_init(struct fd_context *ctx,
                struct pipe_screen *pscreen, const uint8_t *primtypes,
                void *priv);