Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
  2.  
  3. /*
  4.  * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the "Software"),
  8.  * to deal in the Software without restriction, including without limitation
  9.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10.  * and/or sell copies of the Software, and to permit persons to whom the
  11.  * Software is furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice (including the next
  14.  * paragraph) shall be included in all copies or substantial portions of the
  15.  * Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  20.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23.  * SOFTWARE.
  24.  *
  25.  * Authors:
  26.  *    Rob Clark <robclark@freedesktop.org>
  27.  */
  28.  
  29. #include "freedreno_context.h"
  30. #include "freedreno_draw.h"
  31. #include "freedreno_resource.h"
  32. #include "freedreno_texture.h"
  33. #include "freedreno_state.h"
  34. #include "freedreno_gmem.h"
  35. #include "freedreno_util.h"
  36.  
  37. /* there are two cases where we currently need to wait for render complete:
  38.  * 1) pctx->flush() .. since at the moment we have no way for DDX to sync
  39.  *    the presentation blit with the 3d core
  40.  * 2) wrap-around for ringbuffer.. possibly we can do something more
  41.  *    Intelligent here.  Right now we need to ensure there is enough room
  42.  *    at the end of the drawcmds in the cmdstream buffer for all the per-
  43.  *    tile cmds.  We do this the lamest way possible, by making the ringbuffer
  44.  *    big, and flushing and resetting back to the beginning if we get too
  45.  *    close to the end.
  46.  */
  47. static void
  48. fd_context_wait(struct pipe_context *pctx)
  49. {
  50.         struct fd_context *ctx = fd_context(pctx);
  51.         uint32_t ts = fd_ringbuffer_timestamp(ctx->ring);
  52.  
  53.         DBG("wait: %u", ts);
  54.  
  55.         fd_pipe_wait(ctx->screen->pipe, ts);
  56.         fd_ringbuffer_reset(ctx->ring);
  57.         fd_ringmarker_mark(ctx->draw_start);
  58. }
  59.  
  60. /* emit accumulated render cmds, needed for example if render target has
  61.  * changed, or for flush()
  62.  */
  63. void
  64. fd_context_render(struct pipe_context *pctx)
  65. {
  66.         struct fd_context *ctx = fd_context(pctx);
  67.         struct pipe_framebuffer_state *pfb = &ctx->framebuffer;
  68.  
  69.         DBG("needs_flush: %d", ctx->needs_flush);
  70.  
  71.         if (!ctx->needs_flush)
  72.                 return;
  73.  
  74.         fd_gmem_render_tiles(pctx);
  75.  
  76.         DBG("%p/%p/%p", ctx->ring->start, ctx->ring->cur, ctx->ring->end);
  77.  
  78.         /* if size in dwords is more than half the buffer size, then wait and
  79.          * wrap around:
  80.          */
  81.         if ((ctx->ring->cur - ctx->ring->start) > ctx->ring->size/8)
  82.                 fd_context_wait(pctx);
  83.  
  84.         ctx->needs_flush = false;
  85.         ctx->cleared = ctx->restore = ctx->resolve = 0;
  86.         ctx->gmem_reason = 0;
  87.         ctx->num_draws = 0;
  88.  
  89.         fd_resource(pfb->cbufs[0]->texture)->dirty = false;
  90.         if (pfb->zsbuf)
  91.                 fd_resource(pfb->zsbuf->texture)->dirty = false;
  92. }
  93.  
  94. static void
  95. fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
  96.                 unsigned flags)
  97. {
  98.         DBG("fence=%p", fence);
  99.  
  100. #if 0
  101.         if (fence) {
  102.                 fd_fence_ref(ctx->screen->fence.current,
  103.                                 (struct fd_fence **)fence);
  104.         }
  105. #endif
  106.  
  107.         fd_context_render(pctx);
  108. }
  109.  
  110. void
  111. fd_context_destroy(struct pipe_context *pctx)
  112. {
  113.         struct fd_context *ctx = fd_context(pctx);
  114.  
  115.         DBG("");
  116.  
  117.         if (ctx->blitter)
  118.                 util_blitter_destroy(ctx->blitter);
  119.  
  120.         fd_ringmarker_del(ctx->draw_start);
  121.         fd_ringmarker_del(ctx->draw_end);
  122.         fd_ringbuffer_del(ctx->ring);
  123.  
  124.         FREE(ctx);
  125. }
  126.  
  127. struct pipe_context *
  128. fd_context_init(struct fd_context *ctx,
  129.                 struct pipe_screen *pscreen, void *priv)
  130. {
  131.         struct fd_screen *screen = fd_screen(pscreen);
  132.         struct pipe_context *pctx;
  133.  
  134.         ctx->screen = screen;
  135.  
  136.         /* need some sane default in case state tracker doesn't
  137.          * set some state:
  138.          */
  139.         ctx->sample_mask = 0xffff;
  140.  
  141.         pctx = &ctx->base;
  142.         pctx->screen = pscreen;
  143.         pctx->priv = priv;
  144.         pctx->flush = fd_context_flush;
  145.  
  146.         ctx->ring = fd_ringbuffer_new(screen->pipe, 0x100000);
  147.         if (!ctx->ring)
  148.                 goto fail;
  149.  
  150.         ctx->draw_start = fd_ringmarker_new(ctx->ring);
  151.         ctx->draw_end = fd_ringmarker_new(ctx->ring);
  152.  
  153.         util_slab_create(&ctx->transfer_pool, sizeof(struct pipe_transfer),
  154.                         16, UTIL_SLAB_SINGLETHREADED);
  155.  
  156.         fd_draw_init(pctx);
  157.         fd_resource_context_init(pctx);
  158.         fd_texture_init(pctx);
  159.         fd_state_init(pctx);
  160.  
  161.         ctx->blitter = util_blitter_create(pctx);
  162.         if (!ctx->blitter)
  163.                 goto fail;
  164.  
  165.  
  166.         return pctx;
  167.  
  168. fail:
  169.         pctx->destroy(pctx);
  170.         return NULL;
  171. }
  172.