freedreno: Rename vp and fp to vs and fs in fd_program_stateobj
[mesa.git] / src / gallium / drivers / freedreno / a4xx / fd4_gmem.c
index 3f3847c2a2861b35f5374d47c3ae316d404157f8..663a49c69c88822c9cf2d8d412821186ad3cedb3 100644 (file)
@@ -1,5 +1,3 @@
-/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
-
 /*
  * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
  *
@@ -79,7 +77,7 @@ emit_mrt(struct fd_ringbuffer *ring, unsigned nr_bufs,
                         */
                        if (rsc->stencil) {
                                rsc = rsc->stencil;
-                               pformat = rsc->base.b.format;
+                               pformat = rsc->base.format;
                                if (bases)
                                        bases++;
                        }
@@ -135,10 +133,11 @@ static bool
 use_hw_binning(struct fd_batch *batch)
 {
        struct fd_gmem_stateobj *gmem = &batch->ctx->gmem;
-       struct pipe_framebuffer_state *pfb = &batch->framebuffer;
 
-       /* this seems to be a hw bug.. but this hack fixes piglit fbo-maxsize: */
-       if ((pfb->width > 4096) && (pfb->height > 4096))
+       if ((gmem->maxpw * gmem->maxph) > 32)
+               return false;
+
+       if ((gmem->maxpw > 15) || (gmem->maxph > 15))
                return false;
 
        return fd_binning_enabled && ((gmem->nbins_x * gmem->nbins_y) > 2);
@@ -156,10 +155,13 @@ emit_gmem2mem_surf(struct fd_batch *batch, bool stencil,
        struct fd_resource_slice *slice;
        uint32_t offset;
 
+       if (!rsc->valid)
+               return;
+
        if (stencil) {
                debug_assert(rsc->stencil);
                rsc = rsc->stencil;
-               pformat = rsc->base.b.format;
+               pformat = rsc->base.format;
        }
 
        slice = &rsc->slices[psurf->u.tex.level];
@@ -181,20 +183,19 @@ emit_gmem2mem_surf(struct fd_batch *batch, bool stencil,
                        A4XX_RB_COPY_DEST_INFO_SWAP(fd4_pipe2swap(pformat)));
 
        fd4_draw(batch, ring, DI_PT_RECTLIST, IGNORE_VISIBILITY,
-                       DI_SRC_SEL_AUTO_INDEX, 2, 1, INDEX_SIZE_IGN, 0, 0, NULL);
+                       DI_SRC_SEL_AUTO_INDEX, 2, 1, INDEX4_SIZE_8_BIT, 0, 0, NULL);
 }
 
 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,
@@ -228,7 +229,7 @@ fd4_emit_tile_gmem2mem(struct fd_batch *batch, struct fd_tile *tile)
        OUT_PKT0(ring, REG_A4XX_GRAS_SU_MODE_CONTROL, 1);
        OUT_RING(ring, A4XX_GRAS_SU_MODE_CONTROL_LINEHALFWIDTH(0));
 
-       fd_wfi(ctx, ring);
+       fd_wfi(batch, ring);
 
        OUT_PKT0(ring, REG_A4XX_GRAS_CL_CLIP_CNTL, 1);
        OUT_RING(ring, 0x80000);      /* GRAS_CL_CLIP_CNTL */
@@ -320,20 +321,19 @@ emit_mem2gmem_surf(struct fd_batch *batch, uint32_t *bases,
        fd4_emit_gmem_restore_tex(ring, nr_bufs, bufs);
 
        fd4_draw(batch, ring, DI_PT_RECTLIST, IGNORE_VISIBILITY,
-                       DI_SRC_SEL_AUTO_INDEX, 2, 1, INDEX_SIZE_IGN, 0, 0, NULL);
+                       DI_SRC_SEL_AUTO_INDEX, 2, 1, INDEX4_SIZE_8_BIT, 0, 0, NULL);
 }
 
 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 +355,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));
@@ -459,7 +459,7 @@ fd4_emit_tile_mem2gmem(struct fd_batch *batch, struct fd_tile *tile)
 
        if (fd_gmem_needs_restore(batch, tile, FD_BUFFER_COLOR)) {
                emit.prog = &ctx->blit_prog[pfb->nr_cbufs - 1];
-               emit.fp = NULL;      /* frag shader changed so clear cache */
+               emit.fs = NULL;      /* frag shader changed so clear cache */
                fd4_program_emit(ring, &emit, pfb->nr_cbufs, pfb->cbufs);
                emit_mem2gmem_surf(batch, gmem->cbuf_base, pfb->cbufs, pfb->nr_cbufs, bin_w);
        }
@@ -493,7 +493,7 @@ fd4_emit_tile_mem2gmem(struct fd_batch *batch, struct fd_tile *tile)
                        emit.key.half_precision = true;
                        break;
                }
-               emit.fp = NULL;      /* frag shader changed so clear cache */
+               emit.fs = NULL;      /* frag shader changed so clear cache */
                fd4_program_emit(ring, &emit, 1, &pfb->zsbuf);
                emit_mem2gmem_surf(batch, gmem->zsbuf_base, &pfb->zsbuf, 1, bin_w);
        }
@@ -517,7 +517,7 @@ patch_draws(struct fd_batch *batch, enum pc_di_vis_cull_mode vismode)
                struct fd_cs_patch *patch = fd_patch_element(&batch->draw_patches, i);
                *patch->cs = patch->val | DRAW4(0, 0, 0, vismode);
        }
-       util_dynarray_resize(&batch->draw_patches, 0);
+       util_dynarray_clear(&batch->draw_patches);
 }
 
 /* for rendering directly to system memory: */
@@ -570,7 +570,7 @@ update_vsc_pipe(struct fd_batch *batch)
 
        OUT_PKT0(ring, REG_A4XX_VSC_PIPE_CONFIG_REG(0), 8);
        for (i = 0; i < 8; i++) {
-               struct fd_vsc_pipe *pipe = &ctx->pipe[i];
+               struct fd_vsc_pipe *pipe = &ctx->vsc_pipe[i];
                OUT_RING(ring, A4XX_VSC_PIPE_CONFIG_REG_X(pipe->x) |
                                A4XX_VSC_PIPE_CONFIG_REG_Y(pipe->y) |
                                A4XX_VSC_PIPE_CONFIG_REG_W(pipe->w) |
@@ -579,17 +579,17 @@ update_vsc_pipe(struct fd_batch *batch)
 
        OUT_PKT0(ring, REG_A4XX_VSC_PIPE_DATA_ADDRESS_REG(0), 8);
        for (i = 0; i < 8; i++) {
-               struct fd_vsc_pipe *pipe = &ctx->pipe[i];
+               struct fd_vsc_pipe *pipe = &ctx->vsc_pipe[i];
                if (!pipe->bo) {
                        pipe->bo = fd_bo_new(ctx->dev, 0x40000,
-                                       DRM_FREEDRENO_GEM_TYPE_KMEM);
+                                       DRM_FREEDRENO_GEM_TYPE_KMEM, "vsc_pipe[%u]", i);
                }
                OUT_RELOCW(ring, pipe->bo, 0, 0, 0);       /* VSC_PIPE_DATA_ADDRESS[i] */
        }
 
        OUT_PKT0(ring, REG_A4XX_VSC_PIPE_DATA_LENGTH_REG(0), 8);
        for (i = 0; i < 8; i++) {
-               struct fd_vsc_pipe *pipe = &ctx->pipe[i];
+               struct fd_vsc_pipe *pipe = &ctx->vsc_pipe[i];
                OUT_RING(ring, fd_bo_size(pipe->bo) - 32); /* VSC_PIPE_DATA_LENGTH[i] */
        }
 }
@@ -639,10 +639,10 @@ emit_binning_pass(struct fd_batch *batch)
        }
 
        /* emit IB to binning drawcmds: */
-       ctx->emit_ib(ring, batch->binning);
+       fd4_emit_ib(ring, batch->binning);
 
-       fd_reset_wfi(ctx);
-       fd_wfi(ctx, ring);
+       fd_reset_wfi(batch);
+       fd_wfi(batch, ring);
 
        /* and then put stuff back the way it was: */
 
@@ -655,8 +655,8 @@ emit_binning_pass(struct fd_batch *batch)
                        A4XX_GRAS_SC_CONTROL_MSAA_SAMPLES(MSAA_ONE) |
                        A4XX_GRAS_SC_CONTROL_RASTER_MODE(0));
 
-       fd_event_write(ctx, ring, CACHE_FLUSH);
-       fd_wfi(ctx, ring);
+       fd_event_write(batch, ring, CACHE_FLUSH);
+       fd_wfi(batch, ring);
 }
 
 /* before first tile */
@@ -664,6 +664,7 @@ static void
 fd4_emit_tile_init(struct fd_batch *batch)
 {
        struct fd_ringbuffer *ring = batch->gmem;
+       struct pipe_framebuffer_state *pfb = &batch->framebuffer;
        struct fd_gmem_stateobj *gmem = &batch->ctx->gmem;
 
        fd4_emit_restore(batch, ring);
@@ -674,6 +675,11 @@ fd4_emit_tile_init(struct fd_batch *batch)
 
        update_vsc_pipe(batch);
 
+       fd_wfi(batch, ring);
+       OUT_PKT0(ring, REG_A4XX_RB_FRAME_BUFFER_DIMENSION, 1);
+       OUT_RING(ring, A4XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb->width) |
+                       A4XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb->height));
+
        if (use_hw_binning(batch)) {
                OUT_PKT0(ring, REG_A4XX_RB_MODE_CONTROL, 1);
                OUT_RING(ring, A4XX_RB_MODE_CONTROL_WIDTH(gmem->bin_w) |
@@ -744,14 +750,6 @@ fd4_emit_tile_prep(struct fd_batch *batch, struct fd_tile *tile)
        } else {
                OUT_RING(ring, A4XX_GRAS_DEPTH_CONTROL_FORMAT(DEPTH4_NONE));
        }
-
-       if (ctx->needs_rb_fbd) {
-               fd_wfi(ctx, ring);
-               OUT_PKT0(ring, REG_A4XX_RB_FRAME_BUFFER_DIMENSION, 1);
-               OUT_RING(ring, A4XX_RB_FRAME_BUFFER_DIMENSION_WIDTH(pfb->width) |
-                               A4XX_RB_FRAME_BUFFER_DIMENSION_HEIGHT(pfb->height));
-               ctx->needs_rb_fbd = false;
-       }
 }
 
 /* before IB to rendering cmds: */
@@ -770,12 +768,12 @@ fd4_emit_tile_renderprep(struct fd_batch *batch, struct fd_tile *tile)
        uint32_t y2 = tile->yoff + tile->bin_h - 1;
 
        if (use_hw_binning(batch)) {
-               struct fd_vsc_pipe *pipe = &ctx->pipe[tile->p];
+               struct fd_vsc_pipe *pipe = &ctx->vsc_pipe[tile->p];
 
-               assert(pipe->w * pipe->h);
+               assert(pipe->w && pipe->h);
 
-               fd_event_write(ctx, ring, HLSQ_FLUSH);
-               fd_wfi(ctx, ring);
+               fd_event_write(batch, ring, HLSQ_FLUSH);
+               fd_wfi(batch, ring);
 
                OUT_PKT0(ring, REG_A4XX_PC_VSTREAM_CONTROL, 1);
                OUT_RING(ring, A4XX_PC_VSTREAM_CONTROL_SIZE(pipe->w * pipe->h) |