winsys/radeon: fold cs_set_flush_callback into cs_create
[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 #define SI_TRACE_CS 0
38 #define SI_TRACE_CS_DWORDS 6
39
40 #define SI_MAX_DRAW_CS_DWORDS 18
41
42 struct si_pipe_compute;
43
44 struct si_screen {
45 struct r600_common_screen b;
46 };
47
48 struct si_pipe_sampler_view {
49 struct pipe_sampler_view base;
50 struct r600_resource *resource;
51 uint32_t state[8];
52 uint32_t fmask_state[8];
53 };
54
55 struct si_pipe_sampler_state {
56 uint32_t val[4];
57 uint32_t border_color[4];
58 };
59
60 struct si_cs_shader_state {
61 struct si_pipe_compute *program;
62 };
63
64 struct si_textures_info {
65 struct si_sampler_views views;
66 struct si_pipe_sampler_state *samplers[NUM_TEX_UNITS];
67 unsigned n_views;
68 uint32_t depth_texture_mask; /* which textures are depth */
69 uint32_t compressed_colortex_mask;
70 unsigned n_samplers;
71 };
72
73 struct si_framebuffer {
74 struct r600_atom atom;
75 struct pipe_framebuffer_state state;
76 unsigned nr_samples;
77 unsigned log_samples;
78 unsigned cb0_is_integer;
79 unsigned compressed_cb_mask;
80 unsigned export_16bpc;
81 };
82
83 #define SI_NUM_ATOMS(sctx) (sizeof((sctx)->atoms)/sizeof((sctx)->atoms.array[0]))
84
85 #define SI_NUM_SHADERS (PIPE_SHADER_GEOMETRY+1)
86
87 #define SI_RW_SO 2 /* Streamout buffer descriptors after ring buffers */
88
89 struct si_context {
90 struct r600_common_context b;
91 struct blitter_context *blitter;
92 void *custom_dsa_flush_depth_stencil[8];
93 void *custom_dsa_flush_depth[8];
94 void *custom_dsa_flush_stencil[8];
95 void *custom_dsa_flush_inplace;
96 void *custom_blend_resolve;
97 void *custom_blend_decompress;
98 void *custom_blend_fastclear;
99 struct si_screen *screen;
100
101 union {
102 struct {
103 /* The order matters. */
104 struct r600_atom *const_buffers[SI_NUM_SHADERS];
105 struct r600_atom *rw_buffers[SI_NUM_SHADERS];
106 struct r600_atom *sampler_views[SI_NUM_SHADERS];
107 /* Caches must be flushed after resource descriptors are
108 * updated in memory. */
109 struct r600_atom *cache_flush;
110 struct r600_atom *streamout_begin;
111 struct r600_atom *streamout_enable; /* must be after streamout_begin */
112 struct r600_atom *framebuffer;
113 };
114 struct r600_atom *array[0];
115 } atoms;
116
117 struct si_framebuffer framebuffer;
118 struct si_vertex_element *vertex_elements;
119 unsigned pa_sc_line_stipple;
120 unsigned pa_su_sc_mode_cntl;
121 /* for saving when using blitter */
122 struct pipe_stencil_ref stencil_ref;
123 struct si_pipe_shader_selector *ps_shader;
124 struct si_pipe_shader_selector *gs_shader;
125 struct si_pipe_shader_selector *vs_shader;
126 struct si_cs_shader_state cs_shader_state;
127 /* shader information */
128 unsigned sprite_coord_enable;
129 struct si_buffer_resources const_buffers[SI_NUM_SHADERS];
130 struct si_buffer_resources rw_buffers[SI_NUM_SHADERS];
131 struct si_textures_info samplers[SI_NUM_SHADERS];
132 struct r600_resource *border_color_table;
133 unsigned border_color_offset;
134
135 unsigned default_ps_gprs, default_vs_gprs;
136
137 /* Below are variables from the old r600_context.
138 */
139 unsigned pm4_dirty_cdwords;
140
141 /* Vertex and index buffers. */
142 bool vertex_buffers_dirty;
143 struct pipe_index_buffer index_buffer;
144 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
145 unsigned nr_vertex_buffers;
146
147 /* With rasterizer discard, there doesn't have to be a pixel shader.
148 * In that case, we bind this one: */
149 void *dummy_pixel_shader;
150 struct si_pm4_state *gs_on;
151 struct si_pm4_state *gs_off;
152 struct si_pm4_state *gs_rings;
153 struct r600_atom cache_flush;
154 struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on CIK */
155 struct pipe_constant_buffer esgs_ring;
156 struct pipe_constant_buffer gsvs_ring;
157
158 /* SI state handling */
159 union si_state queued;
160 union si_state emitted;
161 };
162
163 /* si_blit.c */
164 void si_init_blit_functions(struct si_context *sctx);
165 void si_flush_depth_textures(struct si_context *sctx,
166 struct si_textures_info *textures);
167 void si_decompress_color_textures(struct si_context *sctx,
168 struct si_textures_info *textures);
169
170 /* si_dma.c */
171 void si_dma_copy(struct pipe_context *ctx,
172 struct pipe_resource *dst,
173 unsigned dst_level,
174 unsigned dstx, unsigned dsty, unsigned dstz,
175 struct pipe_resource *src,
176 unsigned src_level,
177 const struct pipe_box *src_box);
178
179 /* si_hw_context.c */
180 void si_context_flush(struct si_context *ctx, unsigned flags);
181 void si_begin_new_cs(struct si_context *ctx);
182 void si_need_cs_space(struct si_context *ctx, unsigned num_dw, boolean count_draw_in);
183
184 /* si_pipe.c */
185 void si_flush(struct pipe_context *ctx, struct pipe_fence_handle **fence,
186 unsigned flags);
187
188 #if SI_TRACE_CS
189 void si_trace_emit(struct si_context *sctx);
190 #endif
191
192 /* si_compute.c */
193 void si_init_compute_functions(struct si_context *sctx);
194
195 /* si_uvd.c */
196 struct pipe_video_codec *si_uvd_create_decoder(struct pipe_context *context,
197 const struct pipe_video_codec *templ);
198
199 struct pipe_video_buffer *si_video_buffer_create(struct pipe_context *pipe,
200 const struct pipe_video_buffer *tmpl);
201
202 /*
203 * common helpers
204 */
205
206 static INLINE struct r600_resource *
207 si_resource_create_custom(struct pipe_screen *screen,
208 unsigned usage, unsigned size)
209 {
210 assert(size);
211 return r600_resource(pipe_buffer_create(screen,
212 PIPE_BIND_CUSTOM, usage, size));
213 }
214
215 #endif