radeonsi: Rename r600->si for functions in si_pipe.h.
[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 "../radeon/r600_pipe_common.h"
30
31 #include "pipe/p_screen.h"
32 #include "pipe/p_context.h"
33 #include "util/u_format.h"
34 #include "util/u_math.h"
35 #include "util/u_slab.h"
36 #include "si.h"
37 #include "sid.h"
38 #include "si_public.h"
39 #include "si_pm4.h"
40 #include "si_resource.h"
41 #include "si_state.h"
42
43 #ifdef PIPE_ARCH_BIG_ENDIAN
44 #define R600_BIG_ENDIAN 1
45 #else
46 #define R600_BIG_ENDIAN 0
47 #endif
48
49 #define R600_TRACE_CS 0
50 #define R600_TRACE_CS_DWORDS 6
51
52 #define SI_MAX_DRAW_CS_DWORDS 18
53
54 struct si_pipe_compute;
55
56 struct si_screen {
57 struct r600_common_screen b;
58 #if R600_TRACE_CS
59 struct r600_resource *trace_bo;
60 uint32_t *trace_ptr;
61 unsigned cs_count;
62 #endif
63 };
64
65 struct si_pipe_sampler_view {
66 struct pipe_sampler_view base;
67 struct r600_resource *resource;
68 uint32_t state[8];
69 uint32_t fmask_state[8];
70 };
71
72 struct si_pipe_sampler_state {
73 uint32_t val[4];
74 uint32_t border_color[4];
75 };
76
77 struct si_cs_shader_state {
78 struct si_pipe_compute *program;
79 };
80
81 struct si_textures_info {
82 struct si_sampler_views views;
83 struct si_pipe_sampler_state *samplers[NUM_TEX_UNITS];
84 unsigned n_views;
85 uint32_t depth_texture_mask; /* which textures are depth */
86 uint32_t compressed_colortex_mask;
87 unsigned n_samplers;
88 };
89
90 #define SI_NUM_ATOMS(rctx) (sizeof((rctx)->atoms)/sizeof((rctx)->atoms.array[0]))
91 #define SI_NUM_SHADERS (PIPE_SHADER_FRAGMENT+1)
92
93 struct si_context {
94 struct r600_common_context b;
95 struct blitter_context *blitter;
96 void *custom_dsa_flush_depth_stencil[8];
97 void *custom_dsa_flush_depth[8];
98 void *custom_dsa_flush_stencil[8];
99 void *custom_dsa_flush_inplace;
100 void *custom_blend_resolve;
101 void *custom_blend_decompress;
102 struct si_screen *screen;
103
104 union {
105 struct {
106 /* The order matters. */
107 struct r600_atom *const_buffers[SI_NUM_SHADERS];
108 struct r600_atom *sampler_views[SI_NUM_SHADERS];
109 struct r600_atom *streamout_buffers;
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 };
115 struct r600_atom *array[0];
116 } atoms;
117
118 struct si_vertex_element *vertex_elements;
119 struct pipe_framebuffer_state framebuffer;
120 unsigned fb_log_samples;
121 unsigned fb_cb0_is_integer;
122 unsigned fb_compressed_cb_mask;
123 unsigned pa_sc_line_stipple;
124 unsigned pa_su_sc_mode_cntl;
125 /* for saving when using blitter */
126 struct pipe_stencil_ref stencil_ref;
127 struct si_pipe_shader_selector *ps_shader;
128 struct si_pipe_shader_selector *vs_shader;
129 struct si_cs_shader_state cs_shader_state;
130 struct pipe_query *current_render_cond;
131 unsigned current_render_cond_mode;
132 boolean current_render_cond_cond;
133 struct pipe_query *saved_render_cond;
134 unsigned saved_render_cond_mode;
135 boolean saved_render_cond_cond;
136 /* shader information */
137 unsigned sprite_coord_enable;
138 unsigned export_16bpc;
139 struct si_buffer_resources const_buffers[SI_NUM_SHADERS];
140 struct si_buffer_resources streamout_buffers;
141 struct si_textures_info samplers[SI_NUM_SHADERS];
142 struct r600_resource *border_color_table;
143 unsigned border_color_offset;
144
145 unsigned default_ps_gprs, default_vs_gprs;
146
147 /* Below are variables from the old r600_context.
148 */
149 unsigned pm4_dirty_cdwords;
150
151 /* The list of active queries. Only one query of each type can be active. */
152 struct list_head active_nontimer_query_list;
153 unsigned num_cs_dw_nontimer_queries_suspend;
154 /* If queries have been suspended. */
155 bool nontimer_queries_suspended;
156
157 unsigned backend_mask;
158 unsigned max_db; /* for OQ */
159 boolean predicate_drawing;
160
161 /* Vertex and index buffers. */
162 bool vertex_buffers_dirty;
163 struct pipe_index_buffer index_buffer;
164 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
165 unsigned nr_vertex_buffers;
166
167 /* With rasterizer discard, there doesn't have to be a pixel shader.
168 * In that case, we bind this one: */
169 void *dummy_pixel_shader;
170 struct r600_atom cache_flush;
171 struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on CIK */
172
173 /* SI state handling */
174 union si_state queued;
175 union si_state emitted;
176 };
177
178 /* si_blit.c */
179 void si_init_blit_functions(struct si_context *rctx);
180 void si_flush_depth_textures(struct si_context *rctx,
181 struct si_textures_info *textures);
182 void si_decompress_color_textures(struct si_context *rctx,
183 struct si_textures_info *textures);
184
185 /* si_buffer.c */
186 void si_upload_index_buffer(struct si_context *rctx,
187 struct pipe_index_buffer *ib, unsigned count);
188
189
190 /* si_pipe.c */
191 void si_flush(struct pipe_context *ctx, struct pipe_fence_handle **fence,
192 unsigned flags);
193 const char *si_get_llvm_processor_name(enum radeon_family family);
194
195 /* si_query.c */
196 void si_init_query_functions(struct si_context *rctx);
197
198 /* si_resource.c */
199 void si_init_context_resource_functions(struct si_context *r600);
200
201 /* si_translate.c */
202 void si_translate_index_buffer(struct si_context *r600,
203 struct pipe_index_buffer *ib,
204 unsigned count);
205
206 #if R600_TRACE_CS
207 void si_trace_emit(struct si_context *rctx);
208 #endif
209
210 /* si_compute.c */
211 void si_init_compute_functions(struct si_context *rctx);
212
213 /* si_uvd.c */
214 struct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context,
215 const struct pipe_video_codec *templ);
216
217 struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
218 const struct pipe_video_buffer *tmpl);
219
220 /*
221 * common helpers
222 */
223 static INLINE uint32_t S_FIXED(float value, uint32_t frac_bits)
224 {
225 return value * (1 << frac_bits);
226 }
227 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
228
229 static INLINE unsigned si_map_swizzle(unsigned swizzle)
230 {
231 switch (swizzle) {
232 case UTIL_FORMAT_SWIZZLE_Y:
233 return V_008F0C_SQ_SEL_Y;
234 case UTIL_FORMAT_SWIZZLE_Z:
235 return V_008F0C_SQ_SEL_Z;
236 case UTIL_FORMAT_SWIZZLE_W:
237 return V_008F0C_SQ_SEL_W;
238 case UTIL_FORMAT_SWIZZLE_0:
239 return V_008F0C_SQ_SEL_0;
240 case UTIL_FORMAT_SWIZZLE_1:
241 return V_008F0C_SQ_SEL_1;
242 default: /* UTIL_FORMAT_SWIZZLE_X */
243 return V_008F0C_SQ_SEL_X;
244 }
245 }
246
247 static inline unsigned si_tex_aniso_filter(unsigned filter)
248 {
249 if (filter <= 1) return 0;
250 if (filter <= 2) return 1;
251 if (filter <= 4) return 2;
252 if (filter <= 8) return 3;
253 /* else */ return 4;
254 }
255
256 /* 12.4 fixed-point */
257 static INLINE unsigned si_pack_float_12p4(float x)
258 {
259 return x <= 0 ? 0 :
260 x >= 4096 ? 0xffff : x * 16;
261 }
262
263 #endif