1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright 2014, 2015 Red Hat.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub
8bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom
9bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci#ifndef VIRGL_WINSYS_H
24bf215546Sopenharmony_ci#define VIRGL_WINSYS_H
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#include "pipe/p_defines.h"
27bf215546Sopenharmony_ci#include "virtio-gpu/virgl_hw.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_cistruct pipe_box;
30bf215546Sopenharmony_cistruct pipe_fence_handle;
31bf215546Sopenharmony_cistruct winsys_handle;
32bf215546Sopenharmony_cistruct virgl_hw_res;
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#define VIRGL_MAX_TBUF_DWORDS 1024
35bf215546Sopenharmony_ci#define VIRGL_MAX_CMDBUF_DWORDS ((64 * 1024) + VIRGL_MAX_TBUF_DWORDS)
36bf215546Sopenharmony_ci#define VIRGL_MAX_PLANE_COUNT 3
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_cistruct virgl_drm_caps {
39bf215546Sopenharmony_ci   union virgl_caps caps;
40bf215546Sopenharmony_ci};
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistruct virgl_cmd_buf {
43bf215546Sopenharmony_ci   unsigned cdw;
44bf215546Sopenharmony_ci   uint32_t *buf;
45bf215546Sopenharmony_ci};
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_cistruct virgl_winsys {
48bf215546Sopenharmony_ci   unsigned pci_id;
49bf215546Sopenharmony_ci   int supports_fences; /* In/Out fences are supported */
50bf215546Sopenharmony_ci   int supports_encoded_transfers; /* Encoded transfers are supported */
51bf215546Sopenharmony_ci   int supports_coherent;          /* Coherent memory is supported */
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci   void (*destroy)(struct virgl_winsys *vws);
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci   int (*transfer_put)(struct virgl_winsys *vws,
56bf215546Sopenharmony_ci                       struct virgl_hw_res *res,
57bf215546Sopenharmony_ci                       const struct pipe_box *box,
58bf215546Sopenharmony_ci                       uint32_t stride, uint32_t layer_stride,
59bf215546Sopenharmony_ci                       uint32_t buf_offset, uint32_t level);
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   int (*transfer_get)(struct virgl_winsys *vws,
62bf215546Sopenharmony_ci                       struct virgl_hw_res *res,
63bf215546Sopenharmony_ci                       const struct pipe_box *box,
64bf215546Sopenharmony_ci                       uint32_t stride, uint32_t layer_stride,
65bf215546Sopenharmony_ci                       uint32_t buf_offset, uint32_t level);
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci   struct virgl_hw_res *(*resource_create)(struct virgl_winsys *vws,
68bf215546Sopenharmony_ci                                           enum pipe_texture_target target,
69bf215546Sopenharmony_ci                                           const void *map_front_private,
70bf215546Sopenharmony_ci                                           uint32_t format, uint32_t bind,
71bf215546Sopenharmony_ci                                           uint32_t width, uint32_t height,
72bf215546Sopenharmony_ci                                           uint32_t depth, uint32_t array_size,
73bf215546Sopenharmony_ci                                           uint32_t last_level, uint32_t nr_samples,
74bf215546Sopenharmony_ci                                           uint32_t flags, uint32_t size);
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci   void (*resource_reference)(struct virgl_winsys *qws,
77bf215546Sopenharmony_ci                              struct virgl_hw_res **dres,
78bf215546Sopenharmony_ci                              struct virgl_hw_res *sres);
79bf215546Sopenharmony_ci
80bf215546Sopenharmony_ci   void *(*resource_map)(struct virgl_winsys *vws, struct virgl_hw_res *res);
81bf215546Sopenharmony_ci   void (*resource_wait)(struct virgl_winsys *vws, struct virgl_hw_res *res);
82bf215546Sopenharmony_ci   boolean (*resource_is_busy)(struct virgl_winsys *vws,
83bf215546Sopenharmony_ci                               struct virgl_hw_res *res);
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci   struct virgl_hw_res *(*resource_create_from_handle)(struct virgl_winsys *vws,
86bf215546Sopenharmony_ci                                                       struct winsys_handle *whandle,
87bf215546Sopenharmony_ci                                                       uint32_t *plane,
88bf215546Sopenharmony_ci                                                       uint32_t *stride,
89bf215546Sopenharmony_ci                                                       uint32_t *plane_offset,
90bf215546Sopenharmony_ci                                                       uint64_t *modifier,
91bf215546Sopenharmony_ci                                                       uint32_t *blob_mem);
92bf215546Sopenharmony_ci   void (*resource_set_type)(struct virgl_winsys *vws,
93bf215546Sopenharmony_ci                             struct virgl_hw_res *res,
94bf215546Sopenharmony_ci                             uint32_t format, uint32_t bind,
95bf215546Sopenharmony_ci                             uint32_t width, uint32_t height,
96bf215546Sopenharmony_ci                             uint32_t usage, uint64_t modifier,
97bf215546Sopenharmony_ci                             uint32_t plane_count,
98bf215546Sopenharmony_ci                             const uint32_t *plane_strides,
99bf215546Sopenharmony_ci                             const uint32_t *plane_offsets);
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   boolean (*resource_get_handle)(struct virgl_winsys *vws,
102bf215546Sopenharmony_ci                                  struct virgl_hw_res *res,
103bf215546Sopenharmony_ci                                  uint32_t stride,
104bf215546Sopenharmony_ci                                  struct winsys_handle *whandle);
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_ci   struct virgl_cmd_buf *(*cmd_buf_create)(struct virgl_winsys *ws, uint32_t size);
107bf215546Sopenharmony_ci   void (*cmd_buf_destroy)(struct virgl_cmd_buf *buf);
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   void (*emit_res)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf, struct virgl_hw_res *res, boolean write_buffer);
110bf215546Sopenharmony_ci   int (*submit_cmd)(struct virgl_winsys *vws, struct virgl_cmd_buf *buf,
111bf215546Sopenharmony_ci                     struct pipe_fence_handle **fence);
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci   boolean (*res_is_referenced)(struct virgl_winsys *vws,
114bf215546Sopenharmony_ci                                struct virgl_cmd_buf *buf,
115bf215546Sopenharmony_ci                                struct virgl_hw_res *res);
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci   int (*get_caps)(struct virgl_winsys *vws, struct virgl_drm_caps *caps);
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   /* fence */
120bf215546Sopenharmony_ci   struct pipe_fence_handle *(*cs_create_fence)(struct virgl_winsys *vws, int fd);
121bf215546Sopenharmony_ci   bool (*fence_wait)(struct virgl_winsys *vws,
122bf215546Sopenharmony_ci                      struct pipe_fence_handle *fence,
123bf215546Sopenharmony_ci                      uint64_t timeout);
124bf215546Sopenharmony_ci
125bf215546Sopenharmony_ci   void (*fence_reference)(struct virgl_winsys *vws,
126bf215546Sopenharmony_ci                           struct pipe_fence_handle **dst,
127bf215546Sopenharmony_ci                           struct pipe_fence_handle *src);
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   /* for sw paths */
130bf215546Sopenharmony_ci   void (*flush_frontbuffer)(struct virgl_winsys *vws,
131bf215546Sopenharmony_ci                             struct virgl_hw_res *res,
132bf215546Sopenharmony_ci                             unsigned level, unsigned layer,
133bf215546Sopenharmony_ci                             void *winsys_drawable_handle,
134bf215546Sopenharmony_ci                             struct pipe_box *sub_box);
135bf215546Sopenharmony_ci   void (*fence_server_sync)(struct virgl_winsys *vws,
136bf215546Sopenharmony_ci                             struct virgl_cmd_buf *cbuf,
137bf215546Sopenharmony_ci                             struct pipe_fence_handle *fence);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   int (*fence_get_fd)(struct virgl_winsys *vws,
140bf215546Sopenharmony_ci                       struct pipe_fence_handle *fence);
141bf215546Sopenharmony_ci};
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci/* this defaults all newer caps,
144bf215546Sopenharmony_ci * the kernel will overwrite these if newer version is available.
145bf215546Sopenharmony_ci */
146bf215546Sopenharmony_cistatic inline void virgl_ws_fill_new_caps_defaults(struct virgl_drm_caps *caps)
147bf215546Sopenharmony_ci{
148bf215546Sopenharmony_ci   caps->caps.v2.min_aliased_point_size = 1.f;
149bf215546Sopenharmony_ci   caps->caps.v2.max_aliased_point_size = 255.f;
150bf215546Sopenharmony_ci   caps->caps.v2.min_smooth_point_size = 1.f;
151bf215546Sopenharmony_ci   caps->caps.v2.max_smooth_point_size = 190.f;
152bf215546Sopenharmony_ci   caps->caps.v2.min_aliased_line_width = 1.f;
153bf215546Sopenharmony_ci   caps->caps.v2.max_aliased_line_width = 10.f;
154bf215546Sopenharmony_ci   caps->caps.v2.min_smooth_line_width = 0.f;
155bf215546Sopenharmony_ci   caps->caps.v2.max_smooth_line_width = 10.f;
156bf215546Sopenharmony_ci   caps->caps.v2.max_texture_lod_bias = 15.0f;
157bf215546Sopenharmony_ci   caps->caps.v2.max_geom_output_vertices = 256;
158bf215546Sopenharmony_ci   caps->caps.v2.max_geom_total_output_components = 1024;
159bf215546Sopenharmony_ci   caps->caps.v2.max_vertex_outputs = 32;
160bf215546Sopenharmony_ci   caps->caps.v2.max_vertex_attribs = 16;
161bf215546Sopenharmony_ci   caps->caps.v2.max_shader_patch_varyings = 30;
162bf215546Sopenharmony_ci   caps->caps.v2.min_texel_offset = -8;
163bf215546Sopenharmony_ci   caps->caps.v2.max_texel_offset = 7;
164bf215546Sopenharmony_ci   caps->caps.v2.min_texture_gather_offset = -8;
165bf215546Sopenharmony_ci   caps->caps.v2.max_texture_gather_offset = 7;
166bf215546Sopenharmony_ci   caps->caps.v2.texture_buffer_offset_alignment = 0;
167bf215546Sopenharmony_ci   caps->caps.v2.uniform_buffer_offset_alignment = 256;
168bf215546Sopenharmony_ci   caps->caps.v2.shader_buffer_offset_alignment = 32;
169bf215546Sopenharmony_ci   caps->caps.v2.capability_bits = 0;
170bf215546Sopenharmony_ci   caps->caps.v2.max_vertex_attrib_stride = 0;
171bf215546Sopenharmony_ci   caps->caps.v2.max_image_samples = 0;
172bf215546Sopenharmony_ci   caps->caps.v2.max_compute_work_group_invocations = 0;
173bf215546Sopenharmony_ci   caps->caps.v2.max_compute_shared_memory_size = 0;
174bf215546Sopenharmony_ci   caps->caps.v2.host_feature_check_version = 0;
175bf215546Sopenharmony_ci   caps->caps.v2.max_shader_sampler_views = 16;
176bf215546Sopenharmony_ci   for (int shader_type = 0; shader_type < PIPE_SHADER_TYPES; shader_type++) {
177bf215546Sopenharmony_ci      caps->caps.v2.max_const_buffer_size[shader_type] = 4096 * sizeof(float[4]);
178bf215546Sopenharmony_ci   }
179bf215546Sopenharmony_ci}
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ciextern enum virgl_formats pipe_to_virgl_format(enum pipe_format format);
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci#endif
184