Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2014 Broadcom
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21.  * IN THE SOFTWARE.
  22.  */
  23.  
  24. /** @file vc4_fence.c
  25.  *
  26.  * Seqno-based fence management.
  27.  *
  28.  * We have two mechanisms for waiting in our kernel API: You can wait on a BO
  29.  * to have all rendering to from any process to be completed, or wait on a
  30.  * seqno for that particular seqno to be passed.  The fence API we're
  31.  * implementing is based on waiting for all rendering in the context to have
  32.  * completed (with no reference to what other processes might be doing with
  33.  * the same BOs), so we can just use the seqno of the last rendering we'd
  34.  * fired off as our fence marker.
  35.  */
  36.  
  37. #include "util/u_inlines.h"
  38.  
  39. #include "vc4_screen.h"
  40. #include "vc4_bufmgr.h"
  41.  
  42. struct vc4_fence {
  43.         struct pipe_reference reference;
  44.         uint64_t seqno;
  45. };
  46.  
  47. static void
  48. vc4_fence_reference(struct pipe_screen *pscreen,
  49.                     struct pipe_fence_handle **pp,
  50.                     struct pipe_fence_handle *pf)
  51. {
  52.         struct vc4_fence **p = (struct vc4_fence **)pp;
  53.         struct vc4_fence *f = (struct vc4_fence *)pf;
  54.         struct vc4_fence *old = *p;
  55.  
  56.         if (pipe_reference(&(*p)->reference, &f->reference)) {
  57.                 free(old);
  58.         }
  59.         *p = f;
  60. }
  61.  
  62. static boolean
  63. vc4_fence_signalled(struct pipe_screen *pscreen,
  64.                     struct pipe_fence_handle *pf)
  65. {
  66.         struct vc4_screen *screen = vc4_screen(pscreen);
  67.         struct vc4_fence *f = (struct vc4_fence *)pf;
  68.  
  69.         return vc4_wait_seqno(screen, f->seqno, 0);
  70. }
  71.  
  72. static boolean
  73. vc4_fence_finish(struct pipe_screen *pscreen,
  74.                  struct pipe_fence_handle *pf,
  75.                  uint64_t timeout_ns)
  76. {
  77.         struct vc4_screen *screen = vc4_screen(pscreen);
  78.         struct vc4_fence *f = (struct vc4_fence *)pf;
  79.  
  80.         return vc4_wait_seqno(screen, f->seqno, timeout_ns);
  81. }
  82.  
  83. struct vc4_fence *
  84. vc4_fence_create(struct vc4_screen *screen, uint64_t seqno)
  85. {
  86.         struct vc4_fence *f = calloc(1, sizeof(*f));
  87.  
  88.         if (!f)
  89.                 return NULL;
  90.  
  91.         pipe_reference_init(&f->reference, 1);
  92.         f->seqno = seqno;
  93.  
  94.         return f;
  95. }
  96.  
  97. void
  98. vc4_fence_init(struct vc4_screen *screen)
  99. {
  100.         screen->base.fence_reference = vc4_fence_reference;
  101.         screen->base.fence_signalled = vc4_fence_signalled;
  102.         screen->base.fence_finish = vc4_fence_finish;
  103. }
  104.