1/* 2 * Copyright 2014, 2015 Red Hat. 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 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. 22 */ 23#ifndef VIRGL_DRM_WINSYS_H 24#define VIRGL_DRM_WINSYS_H 25 26#include <stdint.h> 27#include "pipe/p_compiler.h" 28#include "pipe/p_defines.h" 29#include "pipe/p_state.h" 30#include "util/list.h" 31#include "os/os_thread.h" 32 33#include "virgl/virgl_winsys.h" 34#include "vtest/vtest_protocol.h" 35#include "virgl_resource_cache.h" 36 37struct pipe_fence_handle; 38struct sw_winsys; 39struct sw_displaytarget; 40 41struct virgl_vtest_winsys { 42 struct virgl_winsys base; 43 44 struct sw_winsys *sws; 45 46 /* fd to remote renderer */ 47 int sock_fd; 48 49 struct virgl_resource_cache cache; 50 mtx_t mutex; 51 52 unsigned protocol_version; 53}; 54 55struct virgl_hw_res { 56 struct pipe_reference reference; 57 uint32_t res_handle; 58 int num_cs_references; 59 60 void *ptr; 61 int size; 62 63 uint32_t format; 64 uint32_t stride; 65 uint32_t width; 66 uint32_t height; 67 68 struct sw_displaytarget *dt; 69 void *mapped; 70 71 uint32_t bind; 72 struct virgl_resource_cache_entry cache_entry; 73}; 74 75struct virgl_vtest_cmd_buf { 76 struct virgl_cmd_buf base; 77 uint32_t *buf; 78 unsigned nres; 79 unsigned cres; 80 struct virgl_winsys *ws; 81 struct virgl_hw_res **res_bo; 82 83 char is_handle_added[512]; 84 unsigned reloc_indices_hashlist[512]; 85}; 86 87static inline struct virgl_hw_res * 88virgl_hw_res(struct pipe_fence_handle *f) 89{ 90 return (struct virgl_hw_res *)f; 91} 92 93static inline struct virgl_vtest_winsys * 94virgl_vtest_winsys(struct virgl_winsys *iws) 95{ 96 return (struct virgl_vtest_winsys *)iws; 97} 98 99static inline struct virgl_vtest_cmd_buf * 100virgl_vtest_cmd_buf(struct virgl_cmd_buf *cbuf) 101{ 102 return (struct virgl_vtest_cmd_buf *)cbuf; 103} 104 105 106int virgl_vtest_connect(struct virgl_vtest_winsys *vws); 107int virgl_vtest_send_get_caps(struct virgl_vtest_winsys *vws, 108 struct virgl_drm_caps *caps); 109 110int virgl_vtest_send_resource_create(struct virgl_vtest_winsys *vws, 111 uint32_t handle, 112 enum pipe_texture_target target, 113 uint32_t format, 114 uint32_t bind, 115 uint32_t width, 116 uint32_t height, 117 uint32_t depth, 118 uint32_t array_size, 119 uint32_t last_level, 120 uint32_t nr_samples, 121 uint32_t size, 122 int *out_fd); 123 124int virgl_vtest_send_resource_unref(struct virgl_vtest_winsys *vws, 125 uint32_t handle); 126int virgl_vtest_submit_cmd(struct virgl_vtest_winsys *vtws, 127 struct virgl_vtest_cmd_buf *cbuf); 128 129int virgl_vtest_send_transfer_get(struct virgl_vtest_winsys *vws, 130 uint32_t handle, 131 uint32_t level, uint32_t stride, 132 uint32_t layer_stride, 133 const struct pipe_box *box, 134 uint32_t data_size, 135 uint32_t offset); 136 137int virgl_vtest_send_transfer_put(struct virgl_vtest_winsys *vws, 138 uint32_t handle, 139 uint32_t level, uint32_t stride, 140 uint32_t layer_stride, 141 const struct pipe_box *box, 142 uint32_t data_size, 143 uint32_t offset); 144 145int virgl_vtest_send_transfer_put_data(struct virgl_vtest_winsys *vws, 146 void *data, 147 uint32_t data_size); 148int virgl_vtest_recv_transfer_get_data(struct virgl_vtest_winsys *vws, 149 void *data, 150 uint32_t data_size, 151 uint32_t stride, 152 const struct pipe_box *box, 153 uint32_t format); 154 155int virgl_vtest_busy_wait(struct virgl_vtest_winsys *vws, int handle, 156 int flags); 157#endif 158