1 #ifndef VIRTIO_GOLDFISH_PIPE 2 #define VIRTIO_GOLDFISH_PIPE 3 4 /* An override of virtio-gpu-3d (virgl) that runs goldfish pipe. One could 5 * implement an actual virtio goldfish pipe, but this hijacking of virgl is 6 * done in order to avoid any guest kernel changes. */ 7 8 #include "virglrenderer.h" 9 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 typedef uint32_t VirtioGpuCtxId; 15 struct virgl_renderer_virtio_interface* 16 get_goldfish_pipe_virgl_renderer_virtio_interface(void); 17 18 /* Needed for goldfish pipe */ 19 void virgl_write_fence(void *opaque, uint32_t fence); 20 21 #ifdef _WIN32 22 #define VG_EXPORT __declspec(dllexport) 23 #else 24 #define VG_EXPORT __attribute__((visibility("default"))) 25 #endif 26 27 VG_EXPORT void virtio_goldfish_pipe_reset(void* hwpipe, void* hostpipe); 28 29 #define VIRTIO_GOLDFISH_EXPORT_API 30 #ifdef VIRTIO_GOLDFISH_EXPORT_API 31 32 VG_EXPORT int pipe_virgl_renderer_init(void *cookie, 33 int flags, 34 struct virgl_renderer_callbacks *cb); 35 VG_EXPORT void pipe_virgl_renderer_poll(void); 36 VG_EXPORT void* pipe_virgl_renderer_get_cursor_data( 37 uint32_t resource_id, uint32_t *width, uint32_t *height); 38 VG_EXPORT int pipe_virgl_renderer_resource_create( 39 struct virgl_renderer_resource_create_args *args, 40 struct iovec *iov, uint32_t num_iovs); 41 VG_EXPORT void pipe_virgl_renderer_resource_unref(uint32_t res_handle); 42 VG_EXPORT int pipe_virgl_renderer_context_create( 43 uint32_t handle, uint32_t nlen, const char *name); 44 VG_EXPORT void pipe_virgl_renderer_context_destroy(uint32_t handle); 45 VG_EXPORT int pipe_virgl_renderer_submit_cmd(void *buffer, 46 int ctx_id, 47 int bytes); 48 VG_EXPORT int pipe_virgl_renderer_transfer_read_iov( 49 uint32_t handle, uint32_t ctx_id, 50 uint32_t level, uint32_t stride, 51 uint32_t layer_stride, 52 struct virgl_box *box, 53 uint64_t offset, struct iovec *iov, 54 int iovec_cnt); 55 VG_EXPORT int pipe_virgl_renderer_transfer_write_iov( 56 uint32_t handle, 57 uint32_t ctx_id, 58 int level, 59 uint32_t stride, 60 uint32_t layer_stride, 61 struct virgl_box *box, 62 uint64_t offset, 63 struct iovec *iovec, 64 unsigned int iovec_cnt); 65 VG_EXPORT void pipe_virgl_renderer_get_cap_set(uint32_t, uint32_t*, uint32_t*); 66 VG_EXPORT void pipe_virgl_renderer_fill_caps(uint32_t, uint32_t, void *caps); 67 68 VG_EXPORT int pipe_virgl_renderer_resource_attach_iov( 69 int res_handle, struct iovec *iov, 70 int num_iovs); 71 VG_EXPORT void pipe_virgl_renderer_resource_detach_iov( 72 int res_handle, struct iovec **iov, int *num_iovs); 73 VG_EXPORT int pipe_virgl_renderer_create_fence( 74 int client_fence_id, uint32_t cmd_type); 75 VG_EXPORT void pipe_virgl_renderer_force_ctx_0(void); 76 VG_EXPORT void pipe_virgl_renderer_ctx_attach_resource( 77 int ctx_id, int res_handle); 78 VG_EXPORT void pipe_virgl_renderer_ctx_detach_resource( 79 int ctx_id, int res_handle); 80 VG_EXPORT int pipe_virgl_renderer_resource_get_info( 81 int res_handle, 82 struct virgl_renderer_resource_info *info); 83 84 VG_EXPORT void stream_renderer_flush_resource_and_readback( 85 uint32_t res_handle, uint32_t x, uint32_t y, uint32_t width, uint32_t height, 86 void* pixels, uint32_t max_bytes); 87 88 VG_EXPORT void stream_renderer_resource_create_v2( 89 uint32_t res_handle, uint64_t hvaId); 90 91 #define STREAM_MEM_HANDLE_TYPE_OPAQUE_FD 0x1 92 #define STREAM_MEM_HANDLE_TYPE_DMABUF 0x2 93 #define STREAM_MEM_HANDLE_TYPE_OPAQUE_WIN32 0x3 94 #define STREAM_MEM_HANDLE_TYPE_SHM 0x4 95 #define STREAM_FENCE_HANDLE_TYPE_OPAQUE_FD 0x10 96 #define STREAM_FENCE_HANDLE_TYPE_SYNC_FD 0x11 97 #define STREAM_FENCE_HANDLE_TYPE_OPAQUE_WIN32 0x12 98 struct stream_renderer_handle { 99 int64_t os_handle; 100 uint32_t handle_type; 101 }; 102 103 struct stream_renderer_create_blob { 104 uint32_t blob_mem; 105 uint32_t blob_flags; 106 uint64_t blob_id; 107 uint64_t size; 108 }; 109 110 #define STREAM_BLOB_MEM_GUEST 1 111 #define STREAM_BLOB_MEM_HOST3D 2 112 #define STREAM_BLOB_MEM_HOST3D_GUEST 3 113 114 #define STREAM_BLOB_FLAG_USE_MAPPABLE 1 115 #define STREAM_BLOB_FLAG_USE_SHAREABLE 2 116 #define STREAM_BLOB_FLAG_USE_CROSS_DEVICE 4 117 #define STREAM_BLOB_FLAG_CREATE_GUEST_HANDLE 8 118 119 VG_EXPORT int stream_renderer_create_blob(uint32_t ctx_id, uint32_t res_handle, 120 const struct stream_renderer_create_blob *create_blob, 121 const struct iovec *iovecs, uint32_t num_iovs, 122 const struct stream_renderer_handle *handle); 123 124 VG_EXPORT int stream_renderer_export_blob(uint32_t res_handle, 125 struct stream_renderer_handle *handle); 126 127 VG_EXPORT int stream_renderer_resource_map(uint32_t res_handle, void** hvaOut, uint64_t* sizeOut); 128 VG_EXPORT int stream_renderer_resource_unmap(uint32_t res_handle); 129 130 VG_EXPORT int stream_renderer_context_create(uint32_t ctx_id, uint32_t nlen, const char *name, 131 uint32_t context_init); 132 133 VG_EXPORT int stream_renderer_context_create_fence( 134 uint64_t fence_id, uint32_t ctx_id, uint8_t ring_idx); 135 136 // Platform resources and contexts support 137 #define STREAM_RENDERER_PLATFORM_RESOURCE_TYPE_EGL_NATIVE_PIXMAP 0x01 138 #define STREAM_RENDERER_PLATFORM_RESOURCE_TYPE_EGL_IMAGE 0x02 139 140 VG_EXPORT int stream_renderer_platform_import_resource(int res_handle, int res_type, void* resource); 141 VG_EXPORT int stream_renderer_platform_resource_info(int res_handle, int* width, int* height, int* internal_format); 142 VG_EXPORT void* stream_renderer_platform_create_shared_egl_context(void); 143 VG_EXPORT int stream_renderer_platform_destroy_shared_egl_context(void*); 144 145 #define STREAM_RENDERER_MAP_CACHE_MASK 0x0f 146 #define STREAM_RENDERER_MAP_CACHE_NONE 0x00 147 #define STREAM_RENDERER_MAP_CACHE_CACHED 0x01 148 #define STREAM_RENDERER_MAP_CACHE_UNCACHED 0x02 149 #define STREAM_RENDERER_MAP_CACHE_WC 0x03 150 VG_EXPORT int stream_renderer_resource_map_info(uint32_t res_handle, uint32_t *map_info); 151 152 #else 153 154 #define VG_EXPORT 155 156 #endif // !VIRTIO_GOLDFISH_EXPORT_API 157 158 #ifdef __cplusplus 159 } // extern "C" 160 #endif 161 162 // based on VIRGL_RENDERER_USE* and friends 163 enum RendererFlags { 164 GFXSTREAM_RENDERER_FLAGS_USE_EGL_BIT = 1 << 0, 165 GFXSTREAM_RENDERER_FLAGS_THREAD_SYNC = 1 << 1, 166 GFXSTREAM_RENDERER_FLAGS_USE_GLX_BIT = 1 << 2, 167 GFXSTREAM_RENDERER_FLAGS_USE_SURFACELESS_BIT = 1 << 3, 168 GFXSTREAM_RENDERER_FLAGS_USE_GLES_BIT = 1 << 4, 169 GFXSTREAM_RENDERER_FLAGS_NO_VK_BIT = 1 << 5, // for disabling vk 170 GFXSTREAM_RENDERER_FLAGS_IGNORE_HOST_GL_ERRORS_BIT = 171 1 << 6, // control IgnoreHostOpenGLErrors flag 172 GFXSTREAM_RENDERER_FLAGS_NATIVE_TEXTURE_DECOMPRESSION_BIT = 173 1 << 7, // Attempt GPU texture decompression 174 GFXSTREAM_RENDERER_FLAGS_ENABLE_BPTC_TEXTURES_BIT = 175 1 << 8, // enable BPTC texture support if available 176 GFXSTREAM_RENDERER_FLAGS_ENABLE_GLES31_BIT = 177 1 << 9, // disables the PlayStoreImage flag 178 GFXSTREAM_RENDERER_FLAGS_ENABLE_S3TC_TEXTURES_BIT = 179 1 << 10, // enable S3TC texture support if available 180 GFXSTREAM_RENDERER_FLAGS_NO_SYNCFD_BIT = 1 << 20, // for disabling syncfd 181 GFXSTREAM_RENDERER_FLAGS_GUEST_USES_ANGLE = 1 << 21, 182 GFXSTREAM_RENDERER_FLAGS_VULKAN_NATIVE_SWAPCHAIN_BIT = 1 << 22, 183 GFXSTREAM_RENDERER_FLAGS_ASYNC_FENCE_CB = 1 << 23, 184 }; 185 186 #endif 187