Path: blob/21.2-virgl/src/virtio/vulkan/vn_ring.h
4560 views
/*1* Copyright 2021 Google LLC2* SPDX-License-Identifier: MIT3*/45#ifndef VN_RING_H6#define VN_RING_H78#include "vn_common.h"910/**11* A ring is a single-producer and single-consumer circular buffer. The data12* in the buffer are produced and consumed in order. An externally-defined13* mechanism is required for ring setup and notifications in both directions.14* Notifications for new data from the producer are needed only when the15* consumer is not actively polling, which is indicated by the ring status.16*17* For venus, the data are plain venus commands. When a venus command is18* consumed from the ring's perspective, there can still be ongoing CPU and/or19* GPU works. This is not an issue when the works generated by following20* venus commands are correctly queued after the ongoing works. There are21* also venus commands that facilitate polling or waiting for ongoing works.22*/2324/* the layout of a ring in a shmem */25struct vn_ring_layout {26size_t head_offset;27size_t tail_offset;28size_t status_offset;2930size_t buffer_offset;31size_t buffer_size;3233size_t extra_offset;34size_t extra_size;3536size_t shmem_size;37};3839static_assert(ATOMIC_INT_LOCK_FREE == 2 && sizeof(atomic_uint) == 4,40"vn_ring_shared requires lock-free 32-bit atomic_uint");4142/* pointers to a ring in a BO */43struct vn_ring_shared {44const volatile atomic_uint *head;45volatile atomic_uint *tail;46const volatile atomic_uint *status;47void *buffer;48void *extra;49};5051struct vn_ring_submit {52uint32_t seqno;5354struct list_head head;5556/* BOs to keep alive (TODO make sure shmems are pinned) */57uint32_t shmem_count;58struct vn_renderer_shmem *shmems[];59};6061struct vn_ring {62struct vn_renderer *renderer;6364struct vn_ring_shared shared;65uint32_t cur;6667struct list_head submits;68struct list_head free_submits;69};7071void72vn_ring_get_layout(size_t extra_size, struct vn_ring_layout *layout);7374void75vn_ring_init(struct vn_ring *ring,76struct vn_renderer *renderer,77const struct vn_ring_layout *layout,78void *shared);7980void81vn_ring_fini(struct vn_ring *ring);8283struct vn_ring_submit *84vn_ring_get_submit(struct vn_ring *ring, uint32_t shmem_count);8586bool87vn_ring_submit(struct vn_ring *ring,88struct vn_ring_submit *submit,89const void *cs_data,90size_t cs_size,91uint32_t *seqno);9293void94vn_ring_wait(const struct vn_ring *ring, uint32_t seqno);9596#endif /* VN_RING_H */979899