radeonsi: move si_upload_const_buffer to a better place
[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 SI_BIG_ENDIAN 1
45 #else
46 #define SI_BIG_ENDIAN 0
47 #endif
48
49 #define SI_TRACE_CS 0
50 #define SI_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 };
59
60 struct si_pipe_sampler_view {
61 struct pipe_sampler_view base;
62 struct r600_resource *resource;
63 uint32_t state[8];
64 uint32_t fmask_state[8];
65 };
66
67 struct si_pipe_sampler_state {
68 uint32_t val[4];
69 uint32_t border_color[4];
70 };
71
72 struct si_cs_shader_state {
73 struct si_pipe_compute *program;
74 };
75
76 struct si_textures_info {
77 struct si_sampler_views views;
78 struct si_pipe_sampler_state *samplers[NUM_TEX_UNITS];
79 unsigned n_views;
80 uint32_t depth_texture_mask; /* which textures are depth */
81 uint32_t compressed_colortex_mask;
82 unsigned n_samplers;
83 };
84
85 #define SI_NUM_ATOMS(sctx) (sizeof((sctx)->atoms)/sizeof((sctx)->atoms.array[0]))
86 #define SI_NUM_SHADERS (PIPE_SHADER_FRAGMENT+1)
87
88 struct si_context {
89 struct r600_common_context b;
90 struct blitter_context *blitter;
91 void *custom_dsa_flush_depth_stencil[8];
92 void *custom_dsa_flush_depth[8];
93 void *custom_dsa_flush_stencil[8];
94 void *custom_dsa_flush_inplace;
95 void *custom_blend_resolve;
96 void *custom_blend_decompress;
97 struct si_screen *screen;
98
99 union {
100 struct {
101 /* The order matters. */
102 struct r600_atom *const_buffers[SI_NUM_SHADERS];
103 struct r600_atom *sampler_views[SI_NUM_SHADERS];
104 struct r600_atom *streamout_buffers;
105 /* Caches must be flushed after resource descriptors are
106 * updated in memory. */
107 struct r600_atom *cache_flush;
108 struct r600_atom *streamout_begin;
109 };
110 struct r600_atom *array[0];
111 } atoms;
112
113 struct si_vertex_element *vertex_elements;
114 struct pipe_framebuffer_state framebuffer;
115 unsigned fb_log_samples;
116 unsigned fb_cb0_is_integer;
117 unsigned fb_compressed_cb_mask;
118 unsigned pa_sc_line_stipple;
119 unsigned pa_su_sc_mode_cntl;
120 /* for saving when using blitter */
121 struct pipe_stencil_ref stencil_ref;
122 struct si_pipe_shader_selector *ps_shader;
123 struct si_pipe_shader_selector *vs_shader;
124 struct si_cs_shader_state cs_shader_state;
125 /* shader information */
126 unsigned sprite_coord_enable;
127 unsigned export_16bpc;
128 struct si_buffer_resources const_buffers[SI_NUM_SHADERS];
129 struct si_buffer_resources streamout_buffers;
130 struct si_textures_info samplers[SI_NUM_SHADERS];
131 struct r600_resource *border_color_table;
132 unsigned border_color_offset;
133
134 unsigned default_ps_gprs, default_vs_gprs;
135
136 /* Below are variables from the old r600_context.
137 */
138 unsigned pm4_dirty_cdwords;
139
140 /* Vertex and index buffers. */
141 bool vertex_buffers_dirty;
142 struct pipe_index_buffer index_buffer;
143 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
144 unsigned nr_vertex_buffers;
145
146 /* With rasterizer discard, there doesn't have to be a pixel shader.
147 * In that case, we bind this one: */
148 void *dummy_pixel_shader;
149 struct r600_atom cache_flush;
150 struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on CIK */
151
152 /* SI state handling */
153 union si_state queued;
154 union si_state emitted;
155 };
156
157 /* si_blit.c */
158 void si_init_blit_functions(struct si_context *sctx);
159 void si_flush_depth_textures(struct si_context *sctx,
160 struct si_textures_info *textures);
161 void si_decompress_color_textures(struct si_context *sctx,
162 struct si_textures_info *textures);
163
164 /* si_pipe.c */
165 void si_flush(struct pipe_context *ctx, struct pipe_fence_handle **fence,
166 unsigned flags);
167
168 #if SI_TRACE_CS
169 void si_trace_emit(struct si_context *sctx);
170 #endif
171
172 /* si_compute.c */
173 void si_init_compute_functions(struct si_context *sctx);
174
175 /* si_uvd.c */
176 struct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context,
177 const struct pipe_video_codec *templ);
178
179 struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
180 const struct pipe_video_buffer *tmpl);
181
182 /*
183 * common helpers
184 */
185 static INLINE uint32_t S_FIXED(float value, uint32_t frac_bits)
186 {
187 return value * (1 << frac_bits);
188 }
189 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
190
191 static INLINE unsigned si_map_swizzle(unsigned swizzle)
192 {
193 switch (swizzle) {
194 case UTIL_FORMAT_SWIZZLE_Y:
195 return V_008F0C_SQ_SEL_Y;
196 case UTIL_FORMAT_SWIZZLE_Z:
197 return V_008F0C_SQ_SEL_Z;
198 case UTIL_FORMAT_SWIZZLE_W:
199 return V_008F0C_SQ_SEL_W;
200 case UTIL_FORMAT_SWIZZLE_0:
201 return V_008F0C_SQ_SEL_0;
202 case UTIL_FORMAT_SWIZZLE_1:
203 return V_008F0C_SQ_SEL_1;
204 default: /* UTIL_FORMAT_SWIZZLE_X */
205 return V_008F0C_SQ_SEL_X;
206 }
207 }
208
209 static inline unsigned si_tex_aniso_filter(unsigned filter)
210 {
211 if (filter <= 1) return 0;
212 if (filter <= 2) return 1;
213 if (filter <= 4) return 2;
214 if (filter <= 8) return 3;
215 /* else */ return 4;
216 }
217
218 /* 12.4 fixed-point */
219 static INLINE unsigned si_pack_float_12p4(float x)
220 {
221 return x <= 0 ? 0 :
222 x >= 4096 ? 0xffff : x * 16;
223 }
224
225 #endif