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