xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/etnaviv/etnaviv_context.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (c) 2012-2015 Etnaviv Project
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  * the rights to use, copy, modify, merge, publish, distribute, sub license,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the 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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Wladimir J. van der Laan <[email protected]>
25  *    Christian Gmeiner <[email protected]>
26  */
27 
28 #ifndef H_ETNAVIV_CONTEXT
29 #define H_ETNAVIV_CONTEXT
30 
31 #include <stdint.h>
32 
33 #include "etnaviv_resource.h"
34 #include "etnaviv_tiling.h"
35 #include "pipe/p_context.h"
36 #include "pipe/p_defines.h"
37 #include "util/format/u_formats.h"
38 #include "pipe/p_shader_tokens.h"
39 #include "pipe/p_state.h"
40 #include "util/slab.h"
41 #include <util/u_suballoc.h>
42 
43 struct pipe_screen;
44 struct etna_shader_variant;
45 struct etna_sampler_ts;
46 
47 struct etna_index_buffer {
48    struct etna_reloc FE_INDEX_STREAM_BASE_ADDR;
49    uint32_t FE_INDEX_STREAM_CONTROL;
50    uint32_t FE_PRIMITIVE_RESTART_INDEX;
51 };
52 
53 struct etna_shader_input {
54    int vs_reg; /* VS input register */
55 };
56 
57 enum etna_varying_special {
58    ETNA_VARYING_VSOUT = 0, /* from VS */
59    ETNA_VARYING_POINTCOORD, /* point texture coord */
60 };
61 
62 struct etna_shader_varying {
63    int num_components;
64    enum etna_varying_special special;
65    int pa_attributes;
66    int vs_reg; /* VS output register */
67 };
68 
69 struct etna_transfer {
70    struct pipe_transfer base;
71    struct pipe_resource *rsc;
72    void *staging;
73    void *mapped;
74 };
75 
76 struct etna_constbuf_state {
77    struct pipe_constant_buffer cb[ETNA_MAX_CONST_BUF];
78    uint32_t enabled_mask;
79 };
80 
81 struct etna_vertexbuf_state {
82    struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
83    struct compiled_set_vertex_buffer cvb[PIPE_MAX_ATTRIBS];
84    unsigned count;
85    uint32_t enabled_mask;
86 };
87 
88 struct etna_shader_state {
89    void *bind_vs, *bind_fs;
90    struct etna_shader_variant *vs, *fs;
91 };
92 
93 enum etna_uniform_contents {
94    ETNA_UNIFORM_UNUSED = 0,
95    ETNA_UNIFORM_CONSTANT,
96    ETNA_UNIFORM_UNIFORM,
97    ETNA_UNIFORM_TEXRECT_SCALE_X,
98    ETNA_UNIFORM_TEXRECT_SCALE_Y,
99    ETNA_UNIFORM_TEXTURE_WIDTH,
100    ETNA_UNIFORM_TEXTURE_HEIGHT,
101    ETNA_UNIFORM_TEXTURE_DEPTH,
102    ETNA_UNIFORM_UBO_ADDR,
103 };
104 
105 struct etna_shader_uniform_info {
106    enum etna_uniform_contents *contents;
107    uint32_t *data;
108    uint32_t count;
109 };
110 
111 struct etna_context {
112    struct pipe_context base;
113 
114    /* GPU-specific implementation to emit texture state */
115    void (*emit_texture_state)(struct etna_context *pctx);
116    /* Get sampler TS pointer for sampler view */
117    struct etna_sampler_ts *(*ts_for_sampler_view)(struct pipe_sampler_view *pview);
118    /* GPU-specific blit implementation */
119    bool (*blit)(struct pipe_context *pipe, const struct pipe_blit_info *info);
120 
121    struct etna_screen *screen;
122    struct etna_cmd_stream *stream;
123 
124    /* which state objects need to be re-emit'd: */
125    enum {
126       ETNA_DIRTY_BLEND           = (1 << 0),
127       ETNA_DIRTY_SAMPLERS        = (1 << 1),
128       ETNA_DIRTY_RASTERIZER      = (1 << 2),
129       ETNA_DIRTY_ZSA             = (1 << 3),
130       ETNA_DIRTY_VERTEX_ELEMENTS = (1 << 4),
131       ETNA_DIRTY_BLEND_COLOR     = (1 << 6),
132       ETNA_DIRTY_STENCIL_REF     = (1 << 7),
133       ETNA_DIRTY_SAMPLE_MASK     = (1 << 8),
134       ETNA_DIRTY_VIEWPORT        = (1 << 9),
135       ETNA_DIRTY_FRAMEBUFFER     = (1 << 10),
136       ETNA_DIRTY_SCISSOR         = (1 << 11),
137       ETNA_DIRTY_SAMPLER_VIEWS   = (1 << 12),
138       ETNA_DIRTY_CONSTBUF        = (1 << 13),
139       ETNA_DIRTY_VERTEX_BUFFERS  = (1 << 14),
140       ETNA_DIRTY_INDEX_BUFFER    = (1 << 15),
141       ETNA_DIRTY_SHADER          = (1 << 16),
142       ETNA_DIRTY_TS              = (1 << 17),
143       ETNA_DIRTY_TEXTURE_CACHES  = (1 << 18),
144       ETNA_DIRTY_DERIVE_TS       = (1 << 19),
145       ETNA_DIRTY_SCISSOR_CLIP    = (1 << 20),
146    } dirty;
147 
148    struct slab_child_pool transfer_pool;
149    struct u_suballocator tex_desc_allocator;
150    struct blitter_context *blitter;
151 
152    /* compiled bindable state */
153    unsigned sample_mask;
154    struct pipe_blend_state *blend;
155    unsigned num_fragment_samplers;
156    uint32_t active_samplers;
157    uint32_t prev_active_samplers;
158    struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
159    struct pipe_rasterizer_state *rasterizer;
160    struct pipe_depth_stencil_alpha_state *zsa;
161    struct compiled_vertex_elements_state *vertex_elements;
162    struct compiled_shader_state shader_state;
163    struct pipe_scissor_state clipping;
164 
165    /* to simplify the emit process we store pre compiled state objects,
166     * which got 'compiled' during state change. */
167    struct compiled_blend_color blend_color;
168    struct compiled_stencil_ref stencil_ref;
169    struct compiled_framebuffer_state framebuffer;
170    struct compiled_viewport_state viewport;
171    unsigned num_fragment_sampler_views;
172    uint32_t active_sampler_views;
173    uint32_t dirty_sampler_views;
174    struct pipe_sampler_view *sampler_view[PIPE_MAX_SAMPLERS];
175    struct etna_constbuf_state constant_buffer[PIPE_SHADER_TYPES];
176    struct etna_vertexbuf_state vertex_buffer;
177    struct etna_index_buffer index_buffer;
178    struct etna_shader_state shader;
179 
180    /* saved parameter-like state. these are mainly kept around for the blitter */
181    struct pipe_framebuffer_state framebuffer_s;
182    struct pipe_stencil_ref stencil_ref_s;
183    struct pipe_viewport_state viewport_s;
184    struct pipe_scissor_state scissor;
185 
186    /* stats/counters */
187    struct {
188       uint64_t prims_generated;
189       uint64_t draw_calls;
190       uint64_t rs_operations;
191    } stats;
192 
193    int in_fence_fd;
194 
195    /* list of accumulated HW queries */
196    struct list_head active_acc_queries;
197 
198    /* set of resources used by currently-unsubmitted renders */
199    struct hash_table *pending_resources;
200 
201    /* resources that must be flushed implicitly at the context flush time */
202    struct set *flush_resources;
203    /* resources that need to be updated after a context flush */
204    struct set *updated_resources;
205 
206    bool is_noop;
207 
208    bool compute_only;
209 
210    /* conditional rendering */
211    struct pipe_query *cond_query;
212    bool cond_cond; /* inverted rendering condition */
213    uint cond_mode;
214 };
215 
216 static inline struct etna_context *
etna_context(struct pipe_context * pctx)217 etna_context(struct pipe_context *pctx)
218 {
219    return (struct etna_context *)pctx;
220 }
221 
222 static inline struct etna_transfer *
etna_transfer(struct pipe_transfer * p)223 etna_transfer(struct pipe_transfer *p)
224 {
225    return (struct etna_transfer *)p;
226 }
227 
228 struct pipe_context *
229 etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags);
230 
231 void
232 etna_context_add_flush_resource(struct etna_context *ctx,
233                                 struct pipe_resource *rsc);
234 
235 void
236 etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
237            enum pipe_flush_flags flags, bool internal);
238 
239 bool
240 etna_render_condition_check(struct pipe_context *pctx);
241 
242 #endif
243