r600g: fixup VP->FP output->input routing.
[mesa.git] / src / gallium / drivers / r600 / r600_context.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 #ifndef R600_CONTEXT_H
24 #define R600_CONTEXT_H
25
26 #include <stdio.h>
27 #include <pipe/p_state.h>
28 #include <pipe/p_context.h>
29 #include <tgsi/tgsi_scan.h>
30 #include <tgsi/tgsi_parse.h>
31 #include <tgsi/tgsi_util.h>
32 #include <util/u_blitter.h>
33 #include <util/u_double_list.h>
34 #include "radeon.h"
35 #include "r600_shader.h"
36
37 struct u_upload_mgr;
38
39 #define R600_QUERY_STATE_STARTED (1 << 0)
40 #define R600_QUERY_STATE_ENDED (1 << 1)
41 #define R600_QUERY_STATE_SUSPENDED (1 << 2)
42
43 struct r600_query {
44 u64 result;
45 /* The kind of query. Currently only OQ is supported. */
46 unsigned type;
47 /* How many results have been written, in dwords. It's incremented
48 * after end_query and flush. */
49 unsigned num_results;
50 /* if we've flushed the query */
51 boolean flushed;
52 unsigned state;
53 /* The buffer where query results are stored. */
54 struct radeon_ws_bo *buffer;
55 unsigned buffer_size;
56 /* linked list of queries */
57 struct list_head list;
58 struct radeon_state rstate;
59 };
60
61 /* XXX move this to a more appropriate place */
62 union pipe_states {
63 struct pipe_rasterizer_state rasterizer;
64 struct pipe_poly_stipple poly_stipple;
65 struct pipe_scissor_state scissor;
66 struct pipe_clip_state clip;
67 struct pipe_shader_state shader;
68 struct pipe_depth_state depth;
69 struct pipe_stencil_state stencil;
70 struct pipe_alpha_state alpha;
71 struct pipe_depth_stencil_alpha_state dsa;
72 struct pipe_blend_state blend;
73 struct pipe_blend_color blend_color;
74 struct pipe_stencil_ref stencil_ref;
75 struct pipe_framebuffer_state framebuffer;
76 struct pipe_sampler_state sampler;
77 struct pipe_sampler_view sampler_view;
78 struct pipe_viewport_state viewport;
79 };
80
81 enum pipe_state_type {
82 pipe_rasterizer_type = 1,
83 pipe_poly_stipple_type,
84 pipe_scissor_type,
85 pipe_clip_type,
86 pipe_shader_type,
87 pipe_depth_type,
88 pipe_stencil_type,
89 pipe_alpha_type,
90 pipe_dsa_type,
91 pipe_blend_type,
92 pipe_stencil_ref_type,
93 pipe_framebuffer_type,
94 pipe_sampler_type,
95 pipe_sampler_view_type,
96 pipe_viewport_type,
97 pipe_type_count
98 };
99
100 #define R600_MAX_RSTATE 16
101 #define R600_STATE_FLAG_DSA_FLUSH 1
102
103 struct r600_context_state {
104 union pipe_states state;
105 unsigned refcount;
106 unsigned type;
107 struct radeon_state rstate[R600_MAX_RSTATE];
108 struct r600_shader shader;
109 struct radeon_ws_bo *bo;
110 unsigned nrstate;
111 unsigned flags;
112 };
113
114 struct r600_vertex_element
115 {
116 unsigned refcount;
117 unsigned count;
118 struct pipe_vertex_element elements[32];
119 };
120
121 struct r600_draw {
122 struct pipe_context *ctx;
123 struct radeon_state draw;
124 struct radeon_state vgt;
125 unsigned mode;
126 unsigned start;
127 unsigned count;
128 unsigned index_size;
129 struct pipe_resource *index_buffer;
130 unsigned index_buffer_offset;
131 unsigned min_index, max_index;
132 unsigned index_bias;
133 };
134
135 struct r600_context_hw_states {
136 struct radeon_state rasterizer;
137 struct radeon_state scissor;
138 struct radeon_state dsa;
139 struct radeon_state cb_cntl;
140
141 struct radeon_state db_flush;
142 struct radeon_state cb_flush;
143 };
144
145 #define R600_MAX_CONSTANT 256 /* magic */
146 #define R600_MAX_RESOURCE 160 /* magic */
147
148 struct r600_shader_sampler_states {
149 unsigned nsampler;
150 unsigned nview;
151 unsigned nborder;
152 struct radeon_state *sampler[PIPE_MAX_ATTRIBS];
153 struct radeon_state *view[PIPE_MAX_ATTRIBS];
154 struct radeon_state *border[PIPE_MAX_ATTRIBS];
155 };
156
157 struct r600_context;
158 struct r600_screen;
159 struct r600_resource;
160 struct r600_resource_texture;
161
162 struct r600_context_hw_state_vtbl {
163 void (*blend)(struct r600_context *rctx,
164 struct radeon_state *rstate,
165 const struct pipe_blend_state *state);
166 void (*ucp)(struct r600_context *rctx, struct radeon_state *rstate,
167 const struct pipe_clip_state *state);
168 void (*cb)(struct r600_context *rctx, struct radeon_state *rstate,
169 const struct pipe_framebuffer_state *state, int cb);
170 void (*db)(struct r600_context *rctx, struct radeon_state *rstate,
171 const struct pipe_framebuffer_state *state);
172 void (*rasterizer)(struct r600_context *rctx, struct radeon_state *rstate);
173 void (*scissor)(struct r600_context *rctx, struct radeon_state *rstate);
174 void (*viewport)(struct r600_context *rctx, struct radeon_state *rstate, const struct pipe_viewport_state *state);
175 void (*dsa)(struct r600_context *rctx, struct radeon_state *rstate);
176 void (*sampler_border)(struct r600_context *rctx, struct radeon_state *rstate,
177 const struct pipe_sampler_state *state, unsigned id);
178 void (*sampler)(struct r600_context *rctx, struct radeon_state *rstate,
179 const struct pipe_sampler_state *state, unsigned id);
180 void (*resource)(struct pipe_context *ctx, struct radeon_state *rstate,
181 const struct pipe_sampler_view *view, unsigned id);
182 void (*cb_cntl)(struct r600_context *rctx, struct radeon_state *rstate);
183 int (*vs_resource)(struct r600_context *rctx, int id, struct r600_resource *rbuffer, uint32_t offset,
184 uint32_t stride, uint32_t format);
185 int (*vgt_init)(struct r600_draw *draw,
186 int vgt_draw_initiator);
187 int (*vgt_prim)(struct r600_draw *draw,
188 uint32_t prim, uint32_t vgt_dma_index_type);
189
190 int (*ps_shader)(struct r600_context *rctx, struct r600_context_state *rshader,
191 struct radeon_state *state);
192 int (*vs_shader)(struct r600_context *rctx, struct r600_context_state *rpshader,
193 struct radeon_state *state);
194 void (*init_config)(struct r600_context *rctx);
195 };
196 extern struct r600_context_hw_state_vtbl r600_hw_state_vtbl;
197 extern struct r600_context_hw_state_vtbl eg_hw_state_vtbl;
198
199 struct r600_context {
200 struct pipe_context context;
201 struct r600_screen *screen;
202 struct radeon *rw;
203 struct radeon_ctx *ctx;
204 struct blitter_context *blitter;
205 struct radeon_draw draw;
206 struct r600_context_hw_state_vtbl *vtbl;
207 struct radeon_state config;
208 boolean use_mem_constant;
209 /* FIXME get rid of those vs_resource,vs/ps_constant */
210 struct radeon_state *vs_resource;
211 unsigned vs_nresource;
212 struct radeon_state *vs_constant;
213 struct radeon_state *ps_constant;
214 /* hw states */
215 struct r600_context_hw_states hw_states;
216 /* pipe states */
217 unsigned flat_shade;
218
219 unsigned nvertex_buffer;
220 struct r600_context_state *rasterizer;
221 struct r600_context_state *poly_stipple;
222 struct r600_context_state *scissor;
223 struct r600_context_state *clip;
224 struct r600_context_state *ps_shader;
225 struct r600_context_state *vs_shader;
226 struct r600_context_state *depth;
227 struct r600_context_state *stencil;
228 struct r600_context_state *alpha;
229 struct r600_context_state *dsa;
230 struct r600_context_state *blend;
231 struct r600_context_state *stencil_ref;
232 struct r600_context_state *viewport;
233 struct r600_context_state *framebuffer;
234 struct r600_shader_sampler_states vs_sampler;
235 struct r600_shader_sampler_states ps_sampler;
236 /* can add gs later */
237 struct r600_vertex_element *vertex_elements;
238 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
239 struct pipe_index_buffer index_buffer;
240 struct pipe_blend_color blend_color;
241 struct list_head query_list;
242
243 /* upload managers */
244 struct u_upload_mgr *upload_vb;
245 struct u_upload_mgr *upload_ib;
246 bool any_user_vbs;
247
248 void *custom_dsa_flush;
249 };
250
251 /* Convenience cast wrapper. */
252 static INLINE struct r600_context *r600_context(struct pipe_context *pipe)
253 {
254 return (struct r600_context*)pipe;
255 }
256
257 static INLINE struct r600_query* r600_query(struct pipe_query* q)
258 {
259 return (struct r600_query*)q;
260 }
261
262 struct r600_context_state *r600_context_state_incref(struct r600_context_state *rstate);
263 struct r600_context_state *r600_context_state_decref(struct r600_context_state *rstate);
264 void r600_flush(struct pipe_context *ctx, unsigned flags,
265 struct pipe_fence_handle **fence);
266
267 int r600_context_hw_states(struct pipe_context *ctx);
268
269 void r600_draw_vbo(struct pipe_context *ctx,
270 const struct pipe_draw_info *info);
271
272 void r600_init_blit_functions(struct r600_context *rctx);
273 void r600_init_state_functions(struct r600_context *rctx);
274 void r600_init_query_functions(struct r600_context* rctx);
275 struct pipe_context *r600_create_context(struct pipe_screen *screen, void *priv);
276
277 extern int r600_pipe_shader_create(struct pipe_context *ctx,
278 struct r600_context_state *rstate,
279 const struct tgsi_token *tokens);
280 extern int r600_pipe_shader_update(struct pipe_context *ctx,
281 struct r600_context_state *rstate);
282 extern int r600_find_vs_semantic_index(struct r600_context *rctx, struct r600_shader *rshader, int id);
283
284 #define R600_ERR(fmt, args...) \
285 fprintf(stderr, "EE %s/%s:%d - "fmt, __FILE__, __func__, __LINE__, ##args)
286
287 uint32_t r600_translate_texformat(enum pipe_format format,
288 const unsigned char *swizzle_view,
289 uint32_t *word4_p, uint32_t *yuv_format_p);
290
291 /* query */
292 extern void r600_queries_resume(struct pipe_context *ctx);
293 extern void r600_queries_suspend(struct pipe_context *ctx);
294
295 int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf);
296
297 void r600_set_constant_buffer_file(struct pipe_context *ctx,
298 uint shader, uint index,
299 struct pipe_resource *buffer);
300 void r600_set_constant_buffer_mem(struct pipe_context *ctx,
301 uint shader, uint index,
302 struct pipe_resource *buffer);
303 void eg_set_constant_buffer(struct pipe_context *ctx,
304 uint shader, uint index,
305 struct pipe_resource *buffer);
306
307 int r600_upload_index_buffer(struct r600_context *rctx,
308 struct r600_draw *draw);
309 int r600_upload_user_buffers(struct r600_context *rctx);
310
311 #endif