Subversion Repositories Kolibri OS

Rev

Rev 4358 | 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.         if (pfb->cbufs[0])
  90.                 fd_resource(pfb->cbufs[0]->texture)->dirty = false;
  91.         if (pfb->zsbuf)
  92.                 fd_resource(pfb->zsbuf->texture)->dirty = false;
  93. }
  94.  
  95. static void
  96. fd_context_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
  97.                 unsigned flags)
  98. {
  99.         DBG("fence=%p", fence);
  100.  
  101. #if 0
  102.         if (fence) {
  103.                 fd_fence_ref(ctx->screen->fence.current,
  104.                                 (struct fd_fence **)fence);
  105.         }
  106. #endif
  107.  
  108.         fd_context_render(pctx);
  109. }
  110.  
  111. void
  112. fd_context_destroy(struct pipe_context *pctx)
  113. {
  114.         struct fd_context *ctx = fd_context(pctx);
  115.  
  116.         DBG("");
  117.  
  118.         if (ctx->blitter)
  119.                 util_blitter_destroy(ctx->blitter);
  120.  
  121.         fd_ringmarker_del(ctx->draw_start);
  122.         fd_ringmarker_del(ctx->draw_end);
  123.         fd_ringbuffer_del(ctx->ring);
  124.  
  125.         FREE(ctx);
  126. }
  127.  
  128. struct pipe_context *
  129. fd_context_init(struct fd_context *ctx,
  130.                 struct pipe_screen *pscreen, void *priv)
  131. {
  132.         struct fd_screen *screen = fd_screen(pscreen);
  133.         struct pipe_context *pctx;
  134.  
  135.         ctx->screen = screen;
  136.  
  137.         /* need some sane default in case state tracker doesn't
  138.          * set some state:
  139.          */
  140.         ctx->sample_mask = 0xffff;
  141.  
  142.         pctx = &ctx->base;
  143.         pctx->screen = pscreen;
  144.         pctx->priv = priv;
  145.         pctx->flush = fd_context_flush;
  146.  
  147.         ctx->ring = fd_ringbuffer_new(screen->pipe, 0x100000);
  148.         if (!ctx->ring)
  149.                 goto fail;
  150.  
  151.         ctx->draw_start = fd_ringmarker_new(ctx->ring);
  152.         ctx->draw_end = fd_ringmarker_new(ctx->ring);
  153.  
  154.         util_slab_create(&ctx->transfer_pool, sizeof(struct pipe_transfer),
  155.                         16, UTIL_SLAB_SINGLETHREADED);
  156.  
  157.         fd_draw_init(pctx);
  158.         fd_resource_context_init(pctx);
  159.         fd_texture_init(pctx);
  160.         fd_state_init(pctx);
  161.  
  162.         ctx->blitter = util_blitter_create(pctx);
  163.         if (!ctx->blitter)
  164.                 goto fail;
  165.  
  166.  
  167.         return pctx;
  168.  
  169. fail:
  170.         pctx->destroy(pctx);
  171.         return NULL;
  172. }
  173.