2 * Copyright (c) 2012-2015 Etnaviv Project
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:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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.
24 * Wladimir J. van der Laan <laanwj@gmail.com>
25 * Christian Gmeiner <christian.gmeiner@gmail.com>
28 #ifndef H_ETNAVIV_CONTEXT
29 #define H_ETNAVIV_CONTEXT
33 #include "etnaviv_resource.h"
34 #include "etnaviv_tiling.h"
35 #include "indices/u_primconvert.h"
36 #include "pipe/p_context.h"
37 #include "pipe/p_defines.h"
38 #include "pipe/p_format.h"
39 #include "pipe/p_shader_tokens.h"
40 #include "pipe/p_state.h"
41 #include "util/slab.h"
44 struct etna_shader_variant
;
46 struct etna_index_buffer
{
47 struct etna_reloc FE_INDEX_STREAM_BASE_ADDR
;
48 uint32_t FE_INDEX_STREAM_CONTROL
;
49 uint32_t FE_PRIMITIVE_RESTART_INDEX
;
52 struct etna_shader_input
{
53 int vs_reg
; /* VS input register */
56 enum etna_varying_special
{
57 ETNA_VARYING_VSOUT
= 0, /* from VS */
58 ETNA_VARYING_POINTCOORD
, /* point texture coord */
61 struct etna_shader_varying
{
63 enum etna_varying_special special
;
65 int vs_reg
; /* VS output register */
68 struct etna_transfer
{
69 struct pipe_transfer base
;
70 struct pipe_resource
*rsc
;
74 struct etna_vertexbuf_state
{
75 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
76 struct compiled_set_vertex_buffer cvb
[PIPE_MAX_ATTRIBS
];
78 uint32_t enabled_mask
;
81 struct etna_shader_state
{
82 void *bind_vs
, *bind_fs
;
83 struct etna_shader_variant
*vs
, *fs
;
86 enum etna_immediate_contents
{
87 ETNA_IMMEDIATE_UNUSED
= 0,
88 ETNA_IMMEDIATE_CONSTANT
,
89 ETNA_IMMEDIATE_TEXRECT_SCALE_X
,
90 ETNA_IMMEDIATE_TEXRECT_SCALE_Y
,
93 struct etna_shader_uniform_info
{
94 enum etna_immediate_contents
*imm_contents
;
100 struct etna_context
{
101 struct pipe_context base
;
103 struct etna_specs specs
;
104 struct etna_screen
*screen
;
105 struct etna_cmd_stream
*stream
;
107 /* which state objects need to be re-emit'd: */
109 ETNA_DIRTY_BLEND
= (1 << 0),
110 ETNA_DIRTY_SAMPLERS
= (1 << 1),
111 ETNA_DIRTY_RASTERIZER
= (1 << 2),
112 ETNA_DIRTY_ZSA
= (1 << 3),
113 ETNA_DIRTY_VERTEX_ELEMENTS
= (1 << 4),
114 ETNA_DIRTY_BLEND_COLOR
= (1 << 6),
115 ETNA_DIRTY_STENCIL_REF
= (1 << 7),
116 ETNA_DIRTY_SAMPLE_MASK
= (1 << 8),
117 ETNA_DIRTY_VIEWPORT
= (1 << 9),
118 ETNA_DIRTY_FRAMEBUFFER
= (1 << 10),
119 ETNA_DIRTY_SCISSOR
= (1 << 11),
120 ETNA_DIRTY_SAMPLER_VIEWS
= (1 << 12),
121 ETNA_DIRTY_CONSTBUF
= (1 << 13),
122 ETNA_DIRTY_VERTEX_BUFFERS
= (1 << 14),
123 ETNA_DIRTY_INDEX_BUFFER
= (1 << 15),
124 ETNA_DIRTY_SHADER
= (1 << 16),
125 ETNA_DIRTY_TS
= (1 << 17),
126 ETNA_DIRTY_TEXTURE_CACHES
= (1 << 18),
127 ETNA_DIRTY_DERIVE_TS
= (1 << 19),
130 uint32_t prim_hwsupport
;
131 struct primconvert_context
*primconvert
;
133 /* list of resources used by currently-unsubmitted renders */
134 struct list_head used_resources
;
136 struct slab_child_pool transfer_pool
;
137 struct blitter_context
*blitter
;
139 /* compiled bindable state */
140 unsigned sample_mask
;
141 struct pipe_blend_state
*blend
;
142 unsigned num_fragment_samplers
;
143 uint32_t active_samplers
;
144 struct pipe_sampler_state
*sampler
[PIPE_MAX_SAMPLERS
];
145 struct pipe_rasterizer_state
*rasterizer
;
146 struct pipe_depth_stencil_alpha_state
*zsa
;
147 struct compiled_vertex_elements_state
*vertex_elements
;
148 struct compiled_shader_state shader_state
;
150 /* to simplify the emit process we store pre compiled state objects,
151 * which got 'compiled' during state change. */
152 struct compiled_blend_color blend_color
;
153 struct compiled_stencil_ref stencil_ref
;
154 struct compiled_framebuffer_state framebuffer
;
155 struct compiled_scissor_state scissor
;
156 struct compiled_viewport_state viewport
;
157 unsigned num_fragment_sampler_views
;
158 uint32_t active_sampler_views
;
159 uint32_t dirty_sampler_views
;
160 struct pipe_sampler_view
*sampler_view
[PIPE_MAX_SAMPLERS
];
161 struct pipe_constant_buffer constant_buffer
[PIPE_SHADER_TYPES
];
162 struct etna_vertexbuf_state vertex_buffer
;
163 struct etna_index_buffer index_buffer
;
164 struct etna_shader_state shader
;
166 /* saved parameter-like state. these are mainly kept around for the blitter */
167 struct pipe_framebuffer_state framebuffer_s
;
168 struct pipe_stencil_ref stencil_ref_s
;
169 struct pipe_viewport_state viewport_s
;
170 struct pipe_scissor_state scissor_s
;
172 /* cached state of entire GPU */
173 struct etna_3d_state gpu3d
;
177 uint64_t prims_emitted
;
179 uint64_t rs_operations
;
182 struct pipe_debug_callback debug
;
185 /* list of active hardware queries */
186 struct list_head active_hw_queries
;
189 static inline struct etna_context
*
190 etna_context(struct pipe_context
*pctx
)
192 return (struct etna_context
*)pctx
;
195 static inline struct etna_transfer
*
196 etna_transfer(struct pipe_transfer
*p
)
198 return (struct etna_transfer
*)p
;
201 struct pipe_context
*
202 etna_context_create(struct pipe_screen
*pscreen
, void *priv
, unsigned flags
);