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,
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);
*/
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;
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,
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),
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,
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) |
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,
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],
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));
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,
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);
*/
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;
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,
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};
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),
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,
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],
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));
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)
/* 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 *
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);