OSDN Git Service

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