1 /* 2 * Copyright 2021 Google LLC 3 * SPDX-License-Identifier: MIT 4 */ 5 6 #ifndef PROXY_CONTEXT_H 7 #define PROXY_CONTEXT_H 8 9 #include "proxy_common.h" 10 11 #include "c11/threads.h" 12 #include "virgl_context.h" 13 14 /* matches virtio-gpu */ 15 #define PROXY_CONTEXT_TIMELINE_COUNT 64 16 17 static_assert(ATOMIC_INT_LOCK_FREE == 2, "proxy renderer requires lock-free atomic_uint"); 18 19 struct proxy_timeline { 20 uint32_t cur_seqno; 21 uint32_t next_seqno; 22 struct list_head fences; 23 24 int cur_seqno_stall_count; 25 }; 26 27 struct proxy_context { 28 struct virgl_context base; 29 30 struct proxy_client *client; 31 struct proxy_socket socket; 32 33 /* this tracks resources early attached in get_blob */ 34 struct hash_table *resource_table; 35 36 /* this is shared with the render worker */ 37 struct { 38 int fd; 39 size_t size; 40 void *ptr; 41 } shmem; 42 43 mtx_t timeline_mutex; 44 struct proxy_timeline timelines[PROXY_CONTEXT_TIMELINE_COUNT]; 45 /* which timelines have fences */ 46 uint64_t timeline_busy_mask; 47 /* this points a region of shmem updated by the render worker */ 48 const volatile atomic_uint *timeline_seqnos; 49 50 mtx_t free_fences_mutex; 51 struct list_head free_fences; 52 53 struct { 54 /* when VIRGL_RENDERER_THREAD_SYNC is set */ 55 int fence_eventfd; 56 57 /* when VIRGL_RENDERER_ASYNC_FENCE_CB is also set */ 58 thrd_t thread; 59 bool created; 60 bool stop; 61 } sync_thread; 62 }; 63 64 #endif /* PROXY_CONTEXT_H */ 65