Path: blob/21.2-virgl/src/freedreno/drm/msm_ringbuffer_sp.h
4564 views
/*1* Copyright © 2021 Google, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#ifdef X24#undef X25#endif2627#if PTRSZ == 3228#define X(n) n##_3229#else30#define X(n) n##_6431#endif3233static void X(emit_reloc_common)(struct fd_ringbuffer *ring,34const struct fd_reloc *reloc)35{36(*ring->cur++) = (uint32_t)reloc->iova;37#if PTRSZ == 6438(*ring->cur++) = (uint32_t)(reloc->iova >> 32);39#endif40}4142static void X(msm_ringbuffer_sp_emit_reloc_nonobj)(struct fd_ringbuffer *ring,43const struct fd_reloc *reloc)44{45X(emit_reloc_common)(ring, reloc);4647assert(!(ring->flags & _FD_RINGBUFFER_OBJECT));4849struct msm_ringbuffer_sp *msm_ring = to_msm_ringbuffer_sp(ring);5051struct msm_submit_sp *msm_submit = to_msm_submit_sp(msm_ring->u.submit);5253msm_submit_append_bo(msm_submit, reloc->bo);54}5556static void X(msm_ringbuffer_sp_emit_reloc_obj)(struct fd_ringbuffer *ring,57const struct fd_reloc *reloc)58{59X(emit_reloc_common)(ring, reloc);6061assert(ring->flags & _FD_RINGBUFFER_OBJECT);6263struct msm_ringbuffer_sp *msm_ring = to_msm_ringbuffer_sp(ring);6465/* Avoid emitting duplicate BO references into the list. Ringbuffer66* objects are long-lived, so this saves ongoing work at draw time in67* exchange for a bit at context setup/first draw. And the number of68* relocs per ringbuffer object is fairly small, so the O(n^2) doesn't69* hurt much.70*/71if (!msm_ringbuffer_references_bo(ring, reloc->bo)) {72APPEND(&msm_ring->u, reloc_bos, fd_bo_ref(reloc->bo));73}74}7576static uint32_t X(msm_ringbuffer_sp_emit_reloc_ring)(77struct fd_ringbuffer *ring, struct fd_ringbuffer *target, uint32_t cmd_idx)78{79struct msm_ringbuffer_sp *msm_target = to_msm_ringbuffer_sp(target);80struct fd_bo *bo;81uint32_t size;8283if ((target->flags & FD_RINGBUFFER_GROWABLE) &&84(cmd_idx < msm_target->u.nr_cmds)) {85bo = msm_target->u.cmds[cmd_idx].ring_bo;86size = msm_target->u.cmds[cmd_idx].size;87} else {88bo = msm_target->ring_bo;89size = offset_bytes(target->cur, target->start);90}9192if (ring->flags & _FD_RINGBUFFER_OBJECT) {93X(msm_ringbuffer_sp_emit_reloc_obj)(ring, &(struct fd_reloc){94.bo = bo,95.iova = bo->iova + msm_target->offset,96.offset = msm_target->offset,97});98} else {99X(msm_ringbuffer_sp_emit_reloc_nonobj)(ring, &(struct fd_reloc){100.bo = bo,101.iova = bo->iova + msm_target->offset,102.offset = msm_target->offset,103});104}105106if (!(target->flags & _FD_RINGBUFFER_OBJECT))107return size;108109struct msm_ringbuffer_sp *msm_ring = to_msm_ringbuffer_sp(ring);110111if (ring->flags & _FD_RINGBUFFER_OBJECT) {112for (unsigned i = 0; i < msm_target->u.nr_reloc_bos; i++) {113struct fd_bo *target_bo = msm_target->u.reloc_bos[i];114if (!msm_ringbuffer_references_bo(ring, target_bo))115APPEND(&msm_ring->u, reloc_bos, fd_bo_ref(target_bo));116}117} else {118// TODO it would be nice to know whether we have already119// seen this target before. But hopefully we hit the120// append_bo() fast path enough for this to not matter:121struct msm_submit_sp *msm_submit = to_msm_submit_sp(msm_ring->u.submit);122123for (unsigned i = 0; i < msm_target->u.nr_reloc_bos; i++) {124msm_submit_append_bo(msm_submit, msm_target->u.reloc_bos[i]);125}126}127128return size;129}130131132