xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/virgl/virgl_winsys.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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_WINSYS_H
24 #define VIRGL_WINSYS_H
25 
26 #include "pipe/p_defines.h"
27 #include "virtio-gpu/virgl_hw.h"
28 
29 struct pipe_box;
30 struct pipe_resource;
31 struct pipe_fence_handle;
32 struct winsys_handle;
33 struct virgl_hw_res;
34 
35 #define VIRGL_MAX_TBUF_DWORDS 1024
36 #define VIRGL_MAX_CMDBUF_DWORDS ((64 * 1024) + VIRGL_MAX_TBUF_DWORDS)
37 #define VIRGL_MAX_PLANE_COUNT 3
38 
39 struct virgl_drm_caps {
40    union virgl_caps caps;
41 };
42 
43 struct virgl_cmd_buf {
44    unsigned cdw;
45    uint32_t *buf;
46 };
47 
48 struct virgl_winsys {
49    unsigned pci_id;
50    int supports_fences; /* In/Out fences are supported */
51    int supports_encoded_transfers; /* Encoded transfers are supported */
52    int supports_coherent;          /* Coherent memory is supported */
53 
54    void (*destroy)(struct virgl_winsys *vws);
55 
56    int (*get_fd)(struct virgl_winsys *vws);
57 
58    int (*transfer_put)(struct virgl_winsys *vws,
59                        struct virgl_hw_res *res,
60                        const struct pipe_box *box,
61                        uint32_t stride, uint32_t layer_stride,
62                        uint32_t buf_offset, uint32_t level);
63 
64    int (*transfer_get)(struct virgl_winsys *vws,
65                        struct virgl_hw_res *res,
66                        const struct pipe_box *box,
67                        uint32_t stride, uint32_t layer_stride,
68                        uint32_t buf_offset, uint32_t level);
69 
70    struct virgl_hw_res *(*resource_create)(struct virgl_winsys *vws,
71                                            enum pipe_texture_target target,
72                                            const void *map_front_private,
73                                            uint32_t format, uint32_t bind,
74                                            uint32_t width, uint32_t height,
75                                            uint32_t depth, uint32_t array_size,
76                                            uint32_t last_level, uint32_t nr_samples,
77                                            uint32_t flags, uint32_t size);
78 
79    void (*resource_reference)(struct virgl_winsys *qws,
80                               struct virgl_hw_res **dres,
81                               struct virgl_hw_res *sres);
82 
83    void *(*resource_map)(struct virgl_winsys *vws, struct virgl_hw_res *res);
84    void (*resource_wait)(struct virgl_winsys *vws, struct virgl_hw_res *res);
85    bool (*resource_is_busy)(struct virgl_winsys *vws,
86                             struct virgl_hw_res *res);
87 
88    struct virgl_hw_res *(*resource_create_from_handle)(struct virgl_winsys *vws,
89                                                        struct winsys_handle *whandle,
90                                                        struct pipe_resource *templ,
91                                                        uint32_t *plane,
92                                                        uint32_t *stride,
93                                                        uint32_t *plane_offset,
94                                                        uint64_t *modifier,
95                                                        uint32_t *blob_mem);
96    void (*resource_set_type)(struct virgl_winsys *vws,
97                              struct virgl_hw_res *res,
98                              uint32_t format, uint32_t bind,
99                              uint32_t width, uint32_t height,
100                              uint32_t usage, uint64_t modifier,
101                              uint32_t plane_count,
102                              const uint32_t *plane_strides,
103                              const uint32_t *plane_offsets);
104 
105    bool (*resource_get_handle)(struct virgl_winsys *vws,
106                                struct virgl_hw_res *res,
107                                uint32_t stride,
108                                struct winsys_handle *whandle);
109 
110    uint32_t (*resource_get_storage_size)(struct virgl_winsys* vws,
111                                          struct virgl_hw_res* res);
112 
113    struct virgl_cmd_buf *(*cmd_buf_create)(struct virgl_winsys *ws, uint32_t size);
114    void (*cmd_buf_destroy)(struct virgl_cmd_buf *buf);
115 
116    void (*emit_res)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf, struct virgl_hw_res *res, bool write_buffer);
117    int (*submit_cmd)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf,
118                      struct pipe_fence_handle **fence);
119 
120    bool (*res_is_referenced)(struct virgl_winsys *vws,
121                              struct virgl_cmd_buf *buf,
122                              struct virgl_hw_res *res);
123 
124    int (*get_caps)(struct virgl_winsys *vws, struct virgl_drm_caps *caps);
125 
126    /* fence */
127    struct pipe_fence_handle *(*cs_create_fence)(struct virgl_winsys *vws, int fd);
128    bool (*fence_wait)(struct virgl_winsys *vws,
129                       struct pipe_fence_handle *fence,
130                       uint64_t timeout);
131 
132    void (*fence_reference)(struct virgl_winsys *vws,
133                            struct pipe_fence_handle **dst,
134                            struct pipe_fence_handle *src);
135 
136    /* for sw paths */
137    void (*flush_frontbuffer)(struct virgl_winsys *vws,
138                              struct virgl_cmd_buf *cbuf,
139                              struct virgl_hw_res *res,
140                              unsigned level, unsigned layer,
141                              void *winsys_drawable_handle,
142                              struct pipe_box *sub_box);
143    void (*fence_server_sync)(struct virgl_winsys *vws,
144                              struct virgl_cmd_buf *cbuf,
145                              struct pipe_fence_handle *fence);
146 
147    int (*fence_get_fd)(struct virgl_winsys *vws,
148                        struct pipe_fence_handle *fence);
149 };
150 
151 /* this defaults all newer caps,
152  * the kernel will overwrite these if newer version is available.
153  */
virgl_ws_fill_new_caps_defaults(struct virgl_drm_caps * caps)154 static inline void virgl_ws_fill_new_caps_defaults(struct virgl_drm_caps *caps)
155 {
156    caps->caps.v2.min_aliased_point_size = 1.f;
157    caps->caps.v2.max_aliased_point_size = 255.f;
158    caps->caps.v2.min_smooth_point_size = 1.f;
159    caps->caps.v2.max_smooth_point_size = 190.f;
160    caps->caps.v2.min_aliased_line_width = 1.f;
161    caps->caps.v2.max_aliased_line_width = 10.f;
162    caps->caps.v2.min_smooth_line_width = 0.f;
163    caps->caps.v2.max_smooth_line_width = 10.f;
164    caps->caps.v2.max_texture_lod_bias = 15.0f;
165    caps->caps.v2.max_geom_output_vertices = 256;
166    caps->caps.v2.max_geom_total_output_components = 1024;
167    caps->caps.v2.max_vertex_outputs = 32;
168    caps->caps.v2.max_vertex_attribs = 16;
169    caps->caps.v2.max_shader_patch_varyings = 30;
170    caps->caps.v2.min_texel_offset = -8;
171    caps->caps.v2.max_texel_offset = 7;
172    caps->caps.v2.min_texture_gather_offset = -8;
173    caps->caps.v2.max_texture_gather_offset = 7;
174    caps->caps.v2.texture_buffer_offset_alignment = 0;
175    caps->caps.v2.uniform_buffer_offset_alignment = 256;
176    caps->caps.v2.shader_buffer_offset_alignment = 32;
177    caps->caps.v2.capability_bits = 0;
178    caps->caps.v2.max_vertex_attrib_stride = 0;
179    caps->caps.v2.max_image_samples = 0;
180    caps->caps.v2.max_compute_work_group_invocations = 0;
181    caps->caps.v2.max_compute_shared_memory_size = 0;
182    caps->caps.v2.host_feature_check_version = 0;
183    caps->caps.v2.max_shader_sampler_views = 16;
184    for (int shader_type = 0; shader_type < PIPE_SHADER_TYPES; shader_type++) {
185       caps->caps.v2.max_const_buffer_size[shader_type] = 4096 * sizeof(float[4]);
186    }
187 }
188 
189 extern enum virgl_formats pipe_to_virgl_format(enum pipe_format format);
190 extern enum pipe_format virgl_to_pipe_format(enum virgl_formats format);
191 #endif
192