Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright © 2014-2015 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_job.c
  25.  *
  26.  * Functions for submitting VC4 render jobs to the kernel.
  27.  */
  28.  
  29. #include <xf86drm.h>
  30. #include "vc4_context.h"
  31.  
  32. void
  33. vc4_job_init(struct vc4_context *vc4)
  34. {
  35.         vc4_init_cl(vc4, &vc4->bcl);
  36.         vc4_init_cl(vc4, &vc4->rcl);
  37.         vc4_init_cl(vc4, &vc4->shader_rec);
  38.         vc4_init_cl(vc4, &vc4->uniforms);
  39.         vc4_init_cl(vc4, &vc4->bo_handles);
  40.         vc4_init_cl(vc4, &vc4->bo_pointers);
  41.         vc4_job_reset(vc4);
  42. }
  43.  
  44. void
  45. vc4_job_reset(struct vc4_context *vc4)
  46. {
  47.         struct vc4_bo **referenced_bos = vc4->bo_pointers.base;
  48.         for (int i = 0; i < (vc4->bo_handles.next -
  49.                              vc4->bo_handles.base) / 4; i++) {
  50.                 vc4_bo_unreference(&referenced_bos[i]);
  51.         }
  52.         vc4_reset_cl(&vc4->bcl);
  53.         vc4_reset_cl(&vc4->rcl);
  54.         vc4_reset_cl(&vc4->shader_rec);
  55.         vc4_reset_cl(&vc4->uniforms);
  56.         vc4_reset_cl(&vc4->bo_handles);
  57.         vc4_reset_cl(&vc4->bo_pointers);
  58.         vc4->shader_rec_count = 0;
  59.  
  60.         vc4->needs_flush = false;
  61.         vc4->draw_call_queued = false;
  62.  
  63.         /* We have no hardware context saved between our draw calls, so we
  64.          * need to flag the next draw as needing all state emitted.  Emitting
  65.          * all state at the start of our draws is also what ensures that we
  66.          * return to the state we need after a previous tile has finished.
  67.          */
  68.         vc4->dirty = ~0;
  69.         vc4->resolve = 0;
  70.         vc4->cleared = 0;
  71.  
  72.         vc4->draw_min_x = ~0;
  73.         vc4->draw_min_y = ~0;
  74.         vc4->draw_max_x = 0;
  75.         vc4->draw_max_y = 0;
  76. }
  77.  
  78. /**
  79.  * Submits the job to the kernel and then reinitializes it.
  80.  */
  81. void
  82. vc4_job_submit(struct vc4_context *vc4)
  83. {
  84.         if (vc4_debug & VC4_DEBUG_CL) {
  85.                 fprintf(stderr, "BCL:\n");
  86.                 vc4_dump_cl(vc4->bcl.base, vc4->bcl.next - vc4->bcl.base, false);
  87.                 fprintf(stderr, "RCL:\n");
  88.                 vc4_dump_cl(vc4->rcl.base, vc4->rcl.next - vc4->rcl.base, true);
  89.         }
  90.  
  91.         struct drm_vc4_submit_cl submit;
  92.         memset(&submit, 0, sizeof(submit));
  93.  
  94.         submit.bo_handles = (uintptr_t)vc4->bo_handles.base;
  95.         submit.bo_handle_count = (vc4->bo_handles.next -
  96.                                   vc4->bo_handles.base) / 4;
  97.         submit.bin_cl = (uintptr_t)vc4->bcl.base;
  98.         submit.bin_cl_size = vc4->bcl.next - vc4->bcl.base;
  99.         submit.render_cl = (uintptr_t)vc4->rcl.base;
  100.         submit.render_cl_size = vc4->rcl.next - vc4->rcl.base;
  101.         submit.shader_rec = (uintptr_t)vc4->shader_rec.base;
  102.         submit.shader_rec_size = vc4->shader_rec.next - vc4->shader_rec.base;
  103.         submit.shader_rec_count = vc4->shader_rec_count;
  104.         submit.uniforms = (uintptr_t)vc4->uniforms.base;
  105.         submit.uniforms_size = vc4->uniforms.next - vc4->uniforms.base;
  106.  
  107.         if (!(vc4_debug & VC4_DEBUG_NORAST)) {
  108.                 int ret;
  109.  
  110. #ifndef USE_VC4_SIMULATOR
  111.                 ret = drmIoctl(vc4->fd, DRM_IOCTL_VC4_SUBMIT_CL, &submit);
  112. #else
  113.                 ret = vc4_simulator_flush(vc4, &submit);
  114. #endif
  115.                 if (ret) {
  116.                         fprintf(stderr, "VC4 submit failed\n");
  117.                         abort();
  118.                 }
  119.         }
  120.  
  121.         vc4->last_emit_seqno = submit.seqno;
  122.  
  123.         if (vc4_debug & VC4_DEBUG_ALWAYS_SYNC) {
  124.                 if (!vc4_wait_seqno(vc4->screen, vc4->last_emit_seqno,
  125.                                     PIPE_TIMEOUT_INFINITE)) {
  126.                         fprintf(stderr, "Wait failed.\n");
  127.                         abort();
  128.                 }
  129.         }
  130.  
  131.         vc4_job_reset(vc4);
  132. }
  133.