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_CONTEXT_H
24bf215546Sopenharmony_ci#define VIRGL_CONTEXT_H
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#include "pipe/p_state.h"
27bf215546Sopenharmony_ci#include "pipe/p_context.h"
28bf215546Sopenharmony_ci#include "util/slab.h"
29bf215546Sopenharmony_ci#include "util/list.h"
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "virgl_staging_mgr.h"
32bf215546Sopenharmony_ci#include "virgl_transfer_queue.h"
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_cistruct pipe_screen;
35bf215546Sopenharmony_cistruct tgsi_token;
36bf215546Sopenharmony_cistruct u_upload_mgr;
37bf215546Sopenharmony_cistruct virgl_cmd_buf;
38bf215546Sopenharmony_cistruct virgl_vertex_elements_state;
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistruct virgl_sampler_view {
41bf215546Sopenharmony_ci   struct pipe_sampler_view base;
42bf215546Sopenharmony_ci   uint32_t handle;
43bf215546Sopenharmony_ci};
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_cistruct virgl_so_target {
46bf215546Sopenharmony_ci   struct pipe_stream_output_target base;
47bf215546Sopenharmony_ci   uint32_t handle;
48bf215546Sopenharmony_ci};
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_cistruct virgl_rasterizer_state {
51bf215546Sopenharmony_ci   struct pipe_rasterizer_state rs;
52bf215546Sopenharmony_ci   uint32_t handle;
53bf215546Sopenharmony_ci};
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_cistruct virgl_shader_binding_state {
56bf215546Sopenharmony_ci   struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci   struct pipe_constant_buffer ubos[PIPE_MAX_CONSTANT_BUFFERS];
59bf215546Sopenharmony_ci   uint32_t ubo_enabled_mask;
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   struct pipe_shader_buffer ssbos[PIPE_MAX_SHADER_BUFFERS];
62bf215546Sopenharmony_ci   uint32_t ssbo_enabled_mask;
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   struct pipe_image_view images[PIPE_MAX_SHADER_IMAGES];
65bf215546Sopenharmony_ci   uint32_t image_enabled_mask;
66bf215546Sopenharmony_ci};
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_cistruct virgl_context {
69bf215546Sopenharmony_ci   struct pipe_context base;
70bf215546Sopenharmony_ci   struct virgl_cmd_buf *cbuf;
71bf215546Sopenharmony_ci   unsigned cbuf_initial_cdw;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci   struct virgl_shader_binding_state shader_bindings[PIPE_SHADER_TYPES];
74bf215546Sopenharmony_ci   struct pipe_shader_buffer atomic_buffers[PIPE_MAX_HW_ATOMIC_BUFFERS];
75bf215546Sopenharmony_ci   uint32_t atomic_buffer_enabled_mask;
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci   struct virgl_vertex_elements_state *vertex_elements;
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci   struct pipe_framebuffer_state framebuffer;
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   struct slab_child_pool transfer_pool;
82bf215546Sopenharmony_ci   struct virgl_transfer_queue queue;
83bf215546Sopenharmony_ci   struct u_upload_mgr *uploader;
84bf215546Sopenharmony_ci   struct virgl_staging_mgr staging;
85bf215546Sopenharmony_ci   bool encoded_transfers;
86bf215546Sopenharmony_ci   bool supports_staging;
87bf215546Sopenharmony_ci   uint8_t patch_vertices;
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
90bf215546Sopenharmony_ci   unsigned num_vertex_buffers;
91bf215546Sopenharmony_ci   boolean vertex_array_dirty;
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   struct virgl_rasterizer_state rs_state;
94bf215546Sopenharmony_ci   struct virgl_so_target so_targets[PIPE_MAX_SO_BUFFERS];
95bf215546Sopenharmony_ci   unsigned num_so_targets;
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci   uint32_t num_draws, num_compute;
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci   struct primconvert_context *primconvert;
100bf215546Sopenharmony_ci   uint32_t hw_sub_ctx_id;
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   /* The total size of staging resources used in queued copy transfers. */
103bf215546Sopenharmony_ci   uint64_t queued_staging_res_size;
104bf215546Sopenharmony_ci};
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_cistatic inline struct virgl_sampler_view *
107bf215546Sopenharmony_civirgl_sampler_view(struct pipe_sampler_view *view)
108bf215546Sopenharmony_ci{
109bf215546Sopenharmony_ci   return (struct virgl_sampler_view *)view;
110bf215546Sopenharmony_ci};
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_cistatic inline struct virgl_so_target *
113bf215546Sopenharmony_civirgl_so_target(struct pipe_stream_output_target *target)
114bf215546Sopenharmony_ci{
115bf215546Sopenharmony_ci   return (struct virgl_so_target *)target;
116bf215546Sopenharmony_ci}
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_cistatic inline struct virgl_context *virgl_context(struct pipe_context *ctx)
119bf215546Sopenharmony_ci{
120bf215546Sopenharmony_ci   return (struct virgl_context *)ctx;
121bf215546Sopenharmony_ci}
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_cistruct pipe_context *virgl_context_create(struct pipe_screen *pscreen,
124bf215546Sopenharmony_ci                                          void *priv, unsigned flags);
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_civoid virgl_init_blit_functions(struct virgl_context *vctx);
127bf215546Sopenharmony_civoid virgl_init_query_functions(struct virgl_context *vctx);
128bf215546Sopenharmony_civoid virgl_init_so_functions(struct virgl_context *vctx);
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_cistruct tgsi_token *virgl_tgsi_transform(struct virgl_screen *vscreen, const struct tgsi_token *tokens_in,
131bf215546Sopenharmony_ci                                        bool is_separable);
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_cibool
134bf215546Sopenharmony_civirgl_can_rebind_resource(struct virgl_context *vctx,
135bf215546Sopenharmony_ci                          struct pipe_resource *res);
136bf215546Sopenharmony_ci
137bf215546Sopenharmony_civoid
138bf215546Sopenharmony_civirgl_rebind_resource(struct virgl_context *vctx,
139bf215546Sopenharmony_ci                      struct pipe_resource *res);
140bf215546Sopenharmony_ci
141bf215546Sopenharmony_civoid virgl_flush_eq(struct virgl_context *ctx, void *closure, struct pipe_fence_handle **fence);
142bf215546Sopenharmony_ci
143bf215546Sopenharmony_ci#endif
144