radeonsi: emit GS_OUT_PRIM_TYPE only if it changes
[mesa.git] / src / gallium / drivers / radeonsi / si_pipe.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * 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 AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #ifndef SI_PIPE_H
27 #define SI_PIPE_H
28
29 #include "si_state.h"
30
31 #ifdef PIPE_ARCH_BIG_ENDIAN
32 #define SI_BIG_ENDIAN 1
33 #else
34 #define SI_BIG_ENDIAN 0
35 #endif
36
37 /* The base vertex and primitive restart can be any number, but we must pick
38 * one which will mean "unknown" for the purpose of state tracking and
39 * the number shouldn't be a commonly-used one. */
40 #define SI_BASE_VERTEX_UNKNOWN INT_MIN
41 #define SI_RESTART_INDEX_UNKNOWN INT_MIN
42
43 #define SI_TRACE_CS 0
44 #define SI_TRACE_CS_DWORDS 6
45
46 #define SI_MAX_DRAW_CS_DWORDS \
47 (/*derived prim state:*/ 6 + /*draw regs:*/ 16 + /*draw packets:*/ 31)
48
49 struct si_compute;
50
51 struct si_screen {
52 struct r600_common_screen b;
53 };
54
55 struct si_sampler_view {
56 struct pipe_sampler_view base;
57 struct list_head list;
58 struct r600_resource *resource;
59 uint32_t state[8];
60 uint32_t fmask_state[8];
61 };
62
63 struct si_sampler_state {
64 uint32_t val[4];
65 uint32_t border_color[4];
66 };
67
68 struct si_cs_shader_state {
69 struct si_compute *program;
70 };
71
72 struct si_textures_info {
73 struct si_sampler_views views;
74 struct si_sampler_states states;
75 uint32_t depth_texture_mask; /* which textures are depth */
76 uint32_t compressed_colortex_mask;
77 };
78
79 struct si_framebuffer {
80 struct r600_atom atom;
81 struct pipe_framebuffer_state state;
82 unsigned nr_samples;
83 unsigned log_samples;
84 unsigned cb0_is_integer;
85 unsigned compressed_cb_mask;
86 unsigned export_16bpc;
87 };
88
89 #define SI_NUM_ATOMS(sctx) (sizeof((sctx)->atoms)/sizeof((sctx)->atoms.array[0]))
90
91 #define SI_NUM_SHADERS (PIPE_SHADER_GEOMETRY+1)
92
93 struct si_context {
94 struct r600_common_context b;
95 struct blitter_context *blitter;
96 void *custom_dsa_flush;
97 void *custom_blend_resolve;
98 void *custom_blend_decompress;
99 void *custom_blend_fastclear;
100 struct si_screen *screen;
101
102 union {
103 struct {
104 /* The order matters. */
105 struct r600_atom *vertex_buffers;
106 struct r600_atom *const_buffers[SI_NUM_SHADERS];
107 struct r600_atom *rw_buffers[SI_NUM_SHADERS];
108 struct r600_atom *sampler_views[SI_NUM_SHADERS];
109 struct r600_atom *sampler_states[SI_NUM_SHADERS];
110 /* Caches must be flushed after resource descriptors are
111 * updated in memory. */
112 struct r600_atom *cache_flush;
113 struct r600_atom *streamout_begin;
114 struct r600_atom *streamout_enable; /* must be after streamout_begin */
115 struct r600_atom *framebuffer;
116 struct r600_atom *db_render_state;
117 struct r600_atom *msaa_config;
118 struct r600_atom *clip_regs;
119 } s;
120 struct r600_atom *array[0];
121 } atoms;
122
123 struct si_framebuffer framebuffer;
124 struct si_vertex_element *vertex_elements;
125 unsigned pa_sc_line_stipple;
126 unsigned pa_su_sc_mode_cntl;
127 /* for saving when using blitter */
128 struct pipe_stencil_ref stencil_ref;
129 /* shaders */
130 struct si_shader_selector *ps_shader;
131 struct si_shader_selector *gs_shader;
132 struct si_shader_selector *vs_shader;
133 struct si_cs_shader_state cs_shader_state;
134 /* shader information */
135 unsigned sprite_coord_enable;
136 struct si_descriptors vertex_buffers;
137 struct si_buffer_resources const_buffers[SI_NUM_SHADERS];
138 struct si_buffer_resources rw_buffers[SI_NUM_SHADERS];
139 struct si_textures_info samplers[SI_NUM_SHADERS];
140 struct r600_resource *border_color_table;
141 unsigned border_color_offset;
142
143 struct r600_atom clip_regs;
144 struct r600_atom msaa_config;
145 int ps_iter_samples;
146
147 unsigned default_ps_gprs, default_vs_gprs;
148
149 /* Vertex and index buffers. */
150 bool vertex_buffers_dirty;
151 struct pipe_index_buffer index_buffer;
152 struct pipe_vertex_buffer vertex_buffer[SI_NUM_VERTEX_BUFFERS];
153
154 /* With rasterizer discard, there doesn't have to be a pixel shader.
155 * In that case, we bind this one: */
156 void *dummy_pixel_shader;
157 struct si_pm4_state *gs_on;
158 struct si_pm4_state *gs_off;
159 struct si_pm4_state *gs_rings;
160 struct r600_atom cache_flush;
161 struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on CIK */
162 struct pipe_resource *esgs_ring;
163 struct pipe_resource *gsvs_ring;
164
165 /* SI state handling */
166 union si_state queued;
167 union si_state emitted;
168
169 /* DB render state. */
170 struct r600_atom db_render_state;
171 bool dbcb_depth_copy_enabled;
172 bool dbcb_stencil_copy_enabled;
173 unsigned dbcb_copy_sample;
174 bool db_inplace_flush_enabled;
175 bool db_depth_clear;
176 bool db_depth_disable_expclear;
177 unsigned ps_db_shader_control;
178
179 /* Draw state. */
180 int last_base_vertex;
181 int last_start_instance;
182 int last_sh_base_reg;
183 int last_primitive_restart_en;
184 int last_restart_index;
185 int last_gs_out_prim;
186 };
187
188 /* si_blit.c */
189 void si_init_blit_functions(struct si_context *sctx);
190 void si_flush_depth_textures(struct si_context *sctx,
191 struct si_textures_info *textures);
192 void si_decompress_color_textures(struct si_context *sctx,
193 struct si_textures_info *textures);
194 void si_resource_copy_region(struct pipe_context *ctx,
195 struct pipe_resource *dst,
196 unsigned dst_level,
197 unsigned dstx, unsigned dsty, unsigned dstz,
198 struct pipe_resource *src,
199 unsigned src_level,
200 const struct pipe_box *src_box);
201
202 /* si_dma.c */
203 void si_dma_copy(struct pipe_context *ctx,
204 struct pipe_resource *dst,
205 unsigned dst_level,
206 unsigned dstx, unsigned dsty, unsigned dstz,
207 struct pipe_resource *src,
208 unsigned src_level,
209 const struct pipe_box *src_box);
210
211 /* si_hw_context.c */
212 void si_context_gfx_flush(void *context, unsigned flags,
213 struct pipe_fence_handle **fence);
214 void si_begin_new_cs(struct si_context *ctx);
215 void si_need_cs_space(struct si_context *ctx, unsigned num_dw, boolean count_draw_in);
216
217 #if SI_TRACE_CS
218 void si_trace_emit(struct si_context *sctx);
219 #endif
220
221 /* si_compute.c */
222 void si_init_compute_functions(struct si_context *sctx);
223
224 /* si_uvd.c */
225 struct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context,
226 const struct pipe_video_codec *templ);
227
228 struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
229 const struct pipe_video_buffer *tmpl);
230
231 /*
232 * common helpers
233 */
234
235 static INLINE struct r600_resource *
236 si_resource_create_custom(struct pipe_screen *screen,
237 unsigned usage, unsigned size)
238 {
239 assert(size);
240 return r600_resource(pipe_buffer_create(screen,
241 PIPE_BIND_CUSTOM, usage, size));
242 }
243
244 static INLINE void
245 si_invalidate_draw_sh_constants(struct si_context *sctx)
246 {
247 sctx->last_base_vertex = SI_BASE_VERTEX_UNKNOWN;
248 sctx->last_start_instance = -1; /* reset to an unknown value */
249 sctx->last_sh_base_reg = -1; /* reset to an unknown value */
250 }
251
252 #endif