ee021ed8980a3a2bb921d6f9e845bdd3bfa3a431
[mesa.git] / src / gallium / drivers / r600 / r600_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 R600_PIPE_H
27 #define R600_PIPE_H
28
29 #include "util/u_blitter.h"
30 #include "util/u_slab.h"
31 #include "r600.h"
32 #include "r600_llvm.h"
33 #include "r600_public.h"
34 #include "r600_shader.h"
35 #include "r600_resource.h"
36 #include "evergreen_compute.h"
37
38 #define R600_MAX_ATOM 17
39
40 #define R600_MAX_CONST_BUFFERS 2
41 #define R600_MAX_CONST_BUFFER_SIZE 4096
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 /* This encapsulates a state or an operation which can emitted into the GPU
50 * command stream. It's not limited to states only, it can be used for anything
51 * that wants to write commands into the CS (e.g. cache flushes). */
52 struct r600_atom {
53 void (*emit)(struct r600_context *ctx, struct r600_atom *state);
54 unsigned id;
55 unsigned num_dw;
56 bool dirty;
57 };
58
59 /* This is an atom containing GPU commands that never change.
60 * This is supposed to be copied directly into the CS. */
61 struct r600_command_buffer {
62 struct r600_atom atom;
63 uint32_t *buf;
64 unsigned max_num_dw;
65 unsigned pkt_flags;
66 };
67
68 struct r600_db_misc_state {
69 struct r600_atom atom;
70 bool occlusion_query_enabled;
71 bool flush_depthstencil_through_cb;
72 bool copy_depth, copy_stencil;
73 unsigned copy_sample;
74 unsigned log_samples;
75 };
76
77 struct r600_cb_misc_state {
78 struct r600_atom atom;
79 unsigned cb_color_control; /* this comes from blend state */
80 unsigned blend_colormask; /* 8*4 bits for 8 RGBA colorbuffers */
81 unsigned nr_cbufs;
82 unsigned nr_ps_color_outputs;
83 bool multiwrite;
84 bool dual_src_blend;
85 };
86
87 struct r600_alphatest_state {
88 struct r600_atom atom;
89 unsigned sx_alpha_test_control; /* this comes from dsa state */
90 unsigned sx_alpha_ref; /* this comes from dsa state */
91 bool bypass;
92 bool cb0_export_16bpc; /* from set_framebuffer_state */
93 };
94
95 struct r600_cs_shader_state {
96 struct r600_atom atom;
97 struct r600_pipe_compute *shader;
98 };
99
100 struct r600_sample_mask {
101 struct r600_atom atom;
102 uint16_t sample_mask; /* there are only 8 bits on EG, 16 bits on Cayman */
103 };
104
105 enum r600_pipe_state_id {
106 R600_PIPE_STATE_BLEND = 0,
107 R600_PIPE_STATE_BLEND_COLOR,
108 R600_PIPE_STATE_CONFIG,
109 R600_PIPE_STATE_SEAMLESS_CUBEMAP,
110 R600_PIPE_STATE_CLIP,
111 R600_PIPE_STATE_SCISSOR,
112 R600_PIPE_STATE_VIEWPORT,
113 R600_PIPE_STATE_RASTERIZER,
114 R600_PIPE_STATE_VGT,
115 R600_PIPE_STATE_FRAMEBUFFER,
116 R600_PIPE_STATE_DSA,
117 R600_PIPE_STATE_STENCIL_REF,
118 R600_PIPE_STATE_PS_SHADER,
119 R600_PIPE_STATE_VS_SHADER,
120 R600_PIPE_STATE_CONSTANT,
121 R600_PIPE_STATE_SAMPLER,
122 R600_PIPE_STATE_RESOURCE,
123 R600_PIPE_STATE_POLYGON_OFFSET,
124 R600_PIPE_STATE_FETCH_SHADER,
125 R600_PIPE_STATE_SPI,
126 R600_PIPE_NSTATES
127 };
128
129 struct compute_memory_pool;
130 void compute_memory_pool_delete(struct compute_memory_pool* pool);
131 struct compute_memory_pool* compute_memory_pool_new(
132 struct r600_screen *rscreen);
133
134 struct r600_pipe_fences {
135 struct r600_resource *bo;
136 unsigned *data;
137 unsigned next_index;
138 /* linked list of preallocated blocks */
139 struct list_head blocks;
140 /* linked list of freed fences */
141 struct list_head pool;
142 pipe_mutex mutex;
143 };
144
145 struct r600_screen {
146 struct pipe_screen screen;
147 struct radeon_winsys *ws;
148 unsigned family;
149 enum chip_class chip_class;
150 struct radeon_info info;
151 bool has_streamout;
152 struct r600_tiling_info tiling_info;
153 struct r600_pipe_fences fences;
154
155 /*for compute global memory binding, we allocate stuff here, instead of
156 * buffers.
157 * XXX: Not sure if this is the best place for global_pool. Also,
158 * it's not thread safe, so it won't work with multiple contexts. */
159 struct compute_memory_pool *global_pool;
160 };
161
162 struct r600_pipe_sampler_view {
163 struct pipe_sampler_view base;
164 struct r600_resource *tex_resource;
165 uint32_t tex_resource_words[8];
166 };
167
168 struct r600_pipe_rasterizer {
169 struct r600_pipe_state rstate;
170 boolean flatshade;
171 boolean two_side;
172 unsigned sprite_coord_enable;
173 unsigned clip_plane_enable;
174 unsigned pa_sc_line_stipple;
175 unsigned pa_cl_clip_cntl;
176 float offset_units;
177 float offset_scale;
178 bool scissor_enable;
179 bool multisample_enable;
180 };
181
182 struct r600_pipe_blend {
183 struct r600_pipe_state rstate;
184 unsigned cb_target_mask;
185 unsigned cb_color_control;
186 bool dual_src_blend;
187 bool alpha_to_one;
188 };
189
190 struct r600_pipe_dsa {
191 struct r600_pipe_state rstate;
192 unsigned alpha_ref;
193 ubyte valuemask[2];
194 ubyte writemask[2];
195 unsigned sx_alpha_test_control;
196 };
197
198 struct r600_vertex_element
199 {
200 unsigned count;
201 struct pipe_vertex_element elements[PIPE_MAX_ATTRIBS];
202 struct r600_resource *fetch_shader;
203 unsigned fs_size;
204 struct r600_pipe_state rstate;
205 };
206
207 struct r600_pipe_shader;
208
209 struct r600_pipe_shader_selector {
210 struct r600_pipe_shader *current;
211
212 struct tgsi_token *tokens;
213 struct pipe_stream_output_info so;
214
215 unsigned num_shaders;
216
217 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
218 unsigned type;
219
220 unsigned nr_ps_max_color_exports;
221 };
222
223 struct r600_pipe_shader {
224 struct r600_pipe_shader_selector *selector;
225 struct r600_pipe_shader *next_variant;
226 struct r600_shader shader;
227 struct r600_pipe_state rstate;
228 struct r600_resource *bo;
229 struct r600_resource *bo_fetch;
230 struct r600_vertex_element vertex_elements;
231 unsigned sprite_coord_enable;
232 unsigned flatshade;
233 unsigned pa_cl_vs_out_cntl;
234 unsigned nr_ps_color_outputs;
235 unsigned key;
236 unsigned db_shader_control;
237 unsigned ps_depth_export;
238 };
239
240 struct r600_pipe_sampler_state {
241 uint32_t tex_sampler_words[3];
242 uint32_t border_color[4];
243 bool border_color_use;
244 bool seamless_cube_map;
245 };
246
247 /* needed for blitter save */
248 #define NUM_TEX_UNITS 16
249
250 struct r600_seamless_cube_map {
251 struct r600_atom atom;
252 bool enabled;
253 };
254
255 struct r600_samplerview_state {
256 struct r600_atom atom;
257 struct r600_pipe_sampler_view *views[NUM_TEX_UNITS];
258 uint32_t enabled_mask;
259 uint32_t dirty_mask;
260 uint32_t compressed_depthtex_mask; /* which textures are depth */
261 uint32_t compressed_colortex_mask;
262 };
263
264 struct r600_textures_info {
265 struct r600_samplerview_state views;
266 struct r600_atom atom_sampler;
267 struct r600_pipe_sampler_state *samplers[NUM_TEX_UNITS];
268 unsigned n_samplers;
269 bool is_array_sampler[NUM_TEX_UNITS];
270 };
271
272 struct r600_fence {
273 struct pipe_reference reference;
274 unsigned index; /* in the shared bo */
275 struct r600_resource *sleep_bo;
276 struct list_head head;
277 };
278
279 #define FENCE_BLOCK_SIZE 16
280
281 struct r600_fence_block {
282 struct r600_fence fences[FENCE_BLOCK_SIZE];
283 struct list_head head;
284 };
285
286 #define R600_CONSTANT_ARRAY_SIZE 256
287 #define R600_RESOURCE_ARRAY_SIZE 160
288
289 struct r600_stencil_ref
290 {
291 ubyte ref_value[2];
292 ubyte valuemask[2];
293 ubyte writemask[2];
294 };
295
296 struct r600_constbuf_state
297 {
298 struct r600_atom atom;
299 struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
300 uint32_t enabled_mask;
301 uint32_t dirty_mask;
302 };
303
304 struct r600_vertexbuf_state
305 {
306 struct r600_atom atom;
307 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
308 uint32_t enabled_mask; /* non-NULL buffers */
309 uint32_t dirty_mask;
310 };
311
312 struct r600_context {
313 struct pipe_context context;
314 struct blitter_context *blitter;
315 enum radeon_family family;
316 enum chip_class chip_class;
317 boolean has_vertex_cache;
318 unsigned r6xx_num_clause_temp_gprs;
319 void *custom_dsa_flush;
320 void *custom_blend_resolve;
321 void *custom_blend_decompress;
322
323 struct r600_screen *screen;
324 struct radeon_winsys *ws;
325 struct r600_pipe_state *states[R600_PIPE_NSTATES];
326 struct r600_vertex_element *vertex_elements;
327 struct pipe_framebuffer_state framebuffer;
328 unsigned compressed_cb_mask;
329 unsigned compute_cb_target_mask;
330 unsigned db_shader_control;
331 unsigned pa_sc_line_stipple;
332 unsigned pa_cl_clip_cntl;
333 /* for saving when using blitter */
334 struct pipe_stencil_ref stencil_ref;
335 struct pipe_viewport_state viewport;
336 struct pipe_clip_state clip;
337 struct r600_pipe_shader_selector *ps_shader;
338 struct r600_pipe_shader_selector *vs_shader;
339 struct r600_pipe_rasterizer *rasterizer;
340 struct r600_pipe_state vgt;
341 struct r600_pipe_state spi;
342 struct pipe_query *current_render_cond;
343 unsigned current_render_cond_mode;
344 struct pipe_query *saved_render_cond;
345 unsigned saved_render_cond_mode;
346 /* shader information */
347 boolean two_side;
348 boolean spi_dirty;
349 unsigned sprite_coord_enable;
350 boolean flatshade;
351 boolean export_16bpc;
352 unsigned nr_cbufs;
353 bool alpha_to_one;
354 bool multisample_enable;
355 bool cb0_is_integer;
356
357 struct u_upload_mgr *uploader;
358 struct util_slab_mempool pool_transfers;
359
360 unsigned default_ps_gprs, default_vs_gprs;
361
362 /* States based on r600_atom. */
363 struct r600_command_buffer start_cs_cmd; /* invariant state mostly */
364 struct r600_atom *atoms[R600_MAX_ATOM];
365 /** Compute specific registers initializations. The start_cs_cmd atom
366 * must be emitted before start_compute_cs_cmd. */
367 struct r600_command_buffer start_compute_cs_cmd;
368 struct r600_alphatest_state alphatest_state;
369 struct r600_cb_misc_state cb_misc_state;
370 struct r600_db_misc_state db_misc_state;
371 /** Vertex buffers for fetch shaders */
372 struct r600_vertexbuf_state vertex_buffer_state;
373 /** Vertex buffers for compute shaders */
374 struct r600_vertexbuf_state cs_vertex_buffer_state;
375 struct r600_constbuf_state vs_constbuf_state;
376 struct r600_constbuf_state ps_constbuf_state;
377 struct r600_textures_info vs_samplers;
378 struct r600_textures_info ps_samplers;
379 struct r600_seamless_cube_map seamless_cube_map;
380 struct r600_cs_shader_state cs_shader_state;
381 struct r600_sample_mask sample_mask;
382
383 /* current external blend state (from state tracker) */
384 struct r600_pipe_blend *blend;
385 /* state with disabled blending - used internally with blend_override */
386 struct r600_pipe_blend *no_blend;
387
388 /* 1 - override current blend state with no_blend, 0 - use external state */
389 unsigned blend_override;
390
391 struct radeon_winsys_cs *cs;
392
393 struct r600_range *range;
394 unsigned nblocks;
395 struct r600_block **blocks;
396 struct list_head dirty;
397 struct list_head enable_list;
398 unsigned pm4_dirty_cdwords;
399 unsigned ctx_pm4_ndwords;
400
401 /* The list of active queries. Only one query of each type can be active. */
402 int num_occlusion_queries;
403
404 /* Manage queries in two separate groups:
405 * The timer ones and the others (streamout, occlusion).
406 *
407 * We do this because we should only suspend non-timer queries for u_blitter,
408 * and later if the non-timer queries are suspended, the context flush should
409 * only suspend and resume the timer queries. */
410 struct list_head active_timer_queries;
411 unsigned num_cs_dw_timer_queries_suspend;
412 struct list_head active_nontimer_queries;
413 unsigned num_cs_dw_nontimer_queries_suspend;
414
415 unsigned num_cs_dw_streamout_end;
416
417 unsigned backend_mask;
418 unsigned max_db; /* for OQ */
419 unsigned flags;
420 boolean predicate_drawing;
421
422 unsigned num_so_targets;
423 struct r600_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
424 boolean streamout_start;
425 unsigned streamout_append_bitmask;
426
427 /* There is no scissor enable bit on r6xx, so we must use a workaround.
428 * These track the current scissor state. */
429 bool scissor_enable;
430 struct pipe_scissor_state scissor_state;
431
432 /* With rasterizer discard, there doesn't have to be a pixel shader.
433 * In that case, we bind this one: */
434 void *dummy_pixel_shader;
435
436 boolean dual_src_blend;
437
438 /* Index buffer. */
439 struct pipe_index_buffer index_buffer;
440
441 /* Dummy CMASK and FMASK buffers used to get around the R6xx hardware
442 * bug where valid CMASK and FMASK are required to be present to avoid
443 * a hardlock in certain operations but aren't actually used
444 * for anything useful. */
445 struct r600_resource *dummy_fmask;
446 struct r600_resource *dummy_cmask;
447 };
448
449 static INLINE void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom)
450 {
451 atom->emit(rctx, atom);
452 atom->dirty = false;
453 }
454
455 static INLINE void r600_atom_dirty(struct r600_context *rctx, struct r600_atom *state)
456 {
457 state->dirty = true;
458 }
459
460 /* evergreen_state.c */
461 void evergreen_init_common_regs(struct r600_command_buffer *cb,
462 enum chip_class ctx_chip_class,
463 enum radeon_family ctx_family,
464 int ctx_drm_minor);
465
466 void evergreen_init_state_functions(struct r600_context *rctx);
467 void evergreen_init_atom_start_cs(struct r600_context *rctx);
468 void evergreen_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader);
469 void evergreen_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader);
470 void evergreen_fetch_shader(struct pipe_context *ctx, struct r600_vertex_element *ve);
471 void *evergreen_create_db_flush_dsa(struct r600_context *rctx);
472 void *evergreen_create_resolve_blend(struct r600_context *rctx);
473 void *evergreen_create_decompress_blend(struct r600_context *rctx);
474 void evergreen_polygon_offset_update(struct r600_context *rctx);
475 boolean evergreen_is_format_supported(struct pipe_screen *screen,
476 enum pipe_format format,
477 enum pipe_texture_target target,
478 unsigned sample_count,
479 unsigned usage);
480 void evergreen_init_color_surface(struct r600_context *rctx,
481 struct r600_surface *surf);
482 void evergreen_update_dual_export_state(struct r600_context * rctx);
483
484 /* r600_blit.c */
485 void r600_copy_buffer(struct pipe_context *ctx, struct
486 pipe_resource *dst, unsigned dstx,
487 struct pipe_resource *src, const struct pipe_box *src_box);
488 void r600_init_blit_functions(struct r600_context *rctx);
489 void r600_blit_decompress_depth(struct pipe_context *ctx,
490 struct r600_texture *texture,
491 struct r600_texture *staging,
492 unsigned first_level, unsigned last_level,
493 unsigned first_layer, unsigned last_layer,
494 unsigned first_sample, unsigned last_sample);
495 void r600_decompress_depth_textures(struct r600_context *rctx,
496 struct r600_samplerview_state *textures);
497 void r600_decompress_color_textures(struct r600_context *rctx,
498 struct r600_samplerview_state *textures);
499
500 /* r600_buffer.c */
501 bool r600_init_resource(struct r600_screen *rscreen,
502 struct r600_resource *res,
503 unsigned size, unsigned alignment,
504 unsigned bind, unsigned usage);
505 struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
506 const struct pipe_resource *templ,
507 unsigned alignment);
508
509 /* r600_pipe.c */
510 void r600_flush(struct pipe_context *ctx, struct pipe_fence_handle **fence,
511 unsigned flags);
512
513 /* r600_query.c */
514 void r600_init_query_functions(struct r600_context *rctx);
515 void r600_suspend_nontimer_queries(struct r600_context *ctx);
516 void r600_resume_nontimer_queries(struct r600_context *ctx);
517 void r600_suspend_timer_queries(struct r600_context *ctx);
518 void r600_resume_timer_queries(struct r600_context *ctx);
519
520 /* r600_resource.c */
521 void r600_init_context_resource_functions(struct r600_context *r600);
522
523 /* r600_shader.c */
524 int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader);
525 #ifdef HAVE_OPENCL
526 int r600_compute_shader_create(struct pipe_context * ctx,
527 LLVMModuleRef mod, struct r600_bytecode * bytecode);
528 #endif
529 void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
530
531 /* r600_state.c */
532 void r600_set_scissor_state(struct r600_context *rctx,
533 const struct pipe_scissor_state *state);
534 void r600_init_state_functions(struct r600_context *rctx);
535 void r600_init_atom_start_cs(struct r600_context *rctx);
536 void r600_pipe_shader_ps(struct pipe_context *ctx, struct r600_pipe_shader *shader);
537 void r600_pipe_shader_vs(struct pipe_context *ctx, struct r600_pipe_shader *shader);
538 void r600_fetch_shader(struct pipe_context *ctx, struct r600_vertex_element *ve);
539 void *r600_create_db_flush_dsa(struct r600_context *rctx);
540 void *r600_create_resolve_blend(struct r600_context *rctx);
541 void *r700_create_resolve_blend(struct r600_context *rctx);
542 void *r600_create_decompress_blend(struct r600_context *rctx);
543 void r600_polygon_offset_update(struct r600_context *rctx);
544 void r600_adjust_gprs(struct r600_context *rctx);
545 boolean r600_is_format_supported(struct pipe_screen *screen,
546 enum pipe_format format,
547 enum pipe_texture_target target,
548 unsigned sample_count,
549 unsigned usage);
550 void r600_update_dual_export_state(struct r600_context * rctx);
551
552 /* r600_texture.c */
553 void r600_init_screen_texture_functions(struct pipe_screen *screen);
554 void r600_init_surface_functions(struct r600_context *r600);
555 uint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
556 const unsigned char *swizzle_view,
557 uint32_t *word4_p, uint32_t *yuv_format_p);
558 unsigned r600_texture_get_offset(struct r600_texture *rtex,
559 unsigned level, unsigned layer);
560
561 /* r600_translate.c */
562 void r600_translate_index_buffer(struct r600_context *r600,
563 struct pipe_index_buffer *ib,
564 unsigned count);
565
566 /* r600_state_common.c */
567 void r600_emit_alphatest_state(struct r600_context *rctx, struct r600_atom *atom);
568 void r600_init_atom(struct r600_context *rctx, struct r600_atom *atom, unsigned id,
569 void (*emit)(struct r600_context *ctx, struct r600_atom *state),
570 unsigned num_dw);
571 void r600_texture_barrier(struct pipe_context *ctx);
572 void r600_set_index_buffer(struct pipe_context *ctx,
573 const struct pipe_index_buffer *ib);
574 void r600_vertex_buffers_dirty(struct r600_context *rctx);
575 void r600_set_vertex_buffers(struct pipe_context *ctx, unsigned count,
576 const struct pipe_vertex_buffer *input);
577 void r600_sampler_views_dirty(struct r600_context *rctx,
578 struct r600_samplerview_state *state);
579 void r600_set_sampler_views(struct pipe_context *pipe,
580 unsigned shader,
581 unsigned start,
582 unsigned count,
583 struct pipe_sampler_view **views);
584 void r600_bind_vs_samplers(struct pipe_context *ctx, unsigned count, void **states);
585 void r600_bind_ps_samplers(struct pipe_context *ctx, unsigned count, void **states);
586 void *r600_create_vertex_elements(struct pipe_context *ctx,
587 unsigned count,
588 const struct pipe_vertex_element *elements);
589 void r600_delete_vertex_element(struct pipe_context *ctx, void *state);
590 void r600_bind_blend_state(struct pipe_context *ctx, void *state);
591 void r600_set_blend_color(struct pipe_context *ctx,
592 const struct pipe_blend_color *state);
593 void r600_bind_dsa_state(struct pipe_context *ctx, void *state);
594 void r600_set_max_scissor(struct r600_context *rctx);
595 void r600_bind_rs_state(struct pipe_context *ctx, void *state);
596 void r600_delete_rs_state(struct pipe_context *ctx, void *state);
597 void r600_sampler_view_destroy(struct pipe_context *ctx,
598 struct pipe_sampler_view *state);
599 void r600_delete_sampler(struct pipe_context *ctx, void *state);
600 void r600_delete_state(struct pipe_context *ctx, void *state);
601 void r600_bind_vertex_elements(struct pipe_context *ctx, void *state);
602 void *r600_create_shader_state_ps(struct pipe_context *ctx,
603 const struct pipe_shader_state *state);
604 void *r600_create_shader_state_vs(struct pipe_context *ctx,
605 const struct pipe_shader_state *state);
606 void r600_bind_ps_shader(struct pipe_context *ctx, void *state);
607 void r600_bind_vs_shader(struct pipe_context *ctx, void *state);
608 void r600_delete_ps_shader(struct pipe_context *ctx, void *state);
609 void r600_delete_vs_shader(struct pipe_context *ctx, void *state);
610 void r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf_state *state);
611 void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint index,
612 struct pipe_constant_buffer *cb);
613 struct pipe_stream_output_target *
614 r600_create_so_target(struct pipe_context *ctx,
615 struct pipe_resource *buffer,
616 unsigned buffer_offset,
617 unsigned buffer_size);
618 void r600_so_target_destroy(struct pipe_context *ctx,
619 struct pipe_stream_output_target *target);
620 void r600_set_so_targets(struct pipe_context *ctx,
621 unsigned num_targets,
622 struct pipe_stream_output_target **targets,
623 unsigned append_bitmask);
624 void r600_set_sample_mask(struct pipe_context *pipe, unsigned sample_mask);
625 void r600_set_pipe_stencil_ref(struct pipe_context *ctx,
626 const struct pipe_stencil_ref *state);
627 void r600_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info);
628 void r600_draw_rectangle(struct blitter_context *blitter,
629 unsigned x1, unsigned y1, unsigned x2, unsigned y2, float depth,
630 enum blitter_attrib_type type, const union pipe_color_union *attrib);
631 uint32_t r600_translate_stencil_op(int s_op);
632 uint32_t r600_translate_fill(uint32_t func);
633 unsigned r600_tex_wrap(unsigned wrap);
634 unsigned r600_tex_filter(unsigned filter);
635 unsigned r600_tex_mipfilter(unsigned filter);
636 unsigned r600_tex_compare(unsigned compare);
637
638 /*
639 * Helpers for building command buffers
640 */
641
642 #define PKT3_SET_CONFIG_REG 0x68
643 #define PKT3_SET_CONTEXT_REG 0x69
644 #define PKT3_SET_CTL_CONST 0x6F
645 #define PKT3_SET_LOOP_CONST 0x6C
646
647 #define R600_CONFIG_REG_OFFSET 0x08000
648 #define R600_CONTEXT_REG_OFFSET 0x28000
649 #define R600_CTL_CONST_OFFSET 0x3CFF0
650 #define R600_LOOP_CONST_OFFSET 0X0003E200
651 #define EG_LOOP_CONST_OFFSET 0x0003A200
652
653 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
654 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
655 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
656 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
657 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
658
659 #define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
660
661 /*Evergreen Compute packet3*/
662 #define PKT3C(op, count, predicate) (PKT_TYPE_S(3) | PKT3_IT_OPCODE_S(op) | PKT_COUNT_S(count) | PKT3_PREDICATE(predicate) | RADEON_CP_PACKET3_COMPUTE_MODE)
663
664 static INLINE void r600_store_value(struct r600_command_buffer *cb, unsigned value)
665 {
666 cb->buf[cb->atom.num_dw++] = value;
667 }
668
669 static INLINE void r600_store_config_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
670 {
671 assert(reg < R600_CONTEXT_REG_OFFSET);
672 assert(cb->atom.num_dw+2+num <= cb->max_num_dw);
673 cb->buf[cb->atom.num_dw++] = PKT3(PKT3_SET_CONFIG_REG, num, 0);
674 cb->buf[cb->atom.num_dw++] = (reg - R600_CONFIG_REG_OFFSET) >> 2;
675 }
676
677 /**
678 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
679 * shaders.
680 */
681 static INLINE void r600_store_context_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
682 {
683 assert(reg >= R600_CONTEXT_REG_OFFSET && reg < R600_CTL_CONST_OFFSET);
684 assert(cb->atom.num_dw+2+num <= cb->max_num_dw);
685 cb->buf[cb->atom.num_dw++] = PKT3(PKT3_SET_CONTEXT_REG, num, 0) | cb->pkt_flags;
686 cb->buf[cb->atom.num_dw++] = (reg - R600_CONTEXT_REG_OFFSET) >> 2;
687 }
688
689 /**
690 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
691 * shaders.
692 */
693 static INLINE void r600_store_ctl_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
694 {
695 assert(reg >= R600_CTL_CONST_OFFSET);
696 assert(cb->atom.num_dw+2+num <= cb->max_num_dw);
697 cb->buf[cb->atom.num_dw++] = PKT3(PKT3_SET_CTL_CONST, num, 0) | cb->pkt_flags;
698 cb->buf[cb->atom.num_dw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
699 }
700
701 static INLINE void r600_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
702 {
703 assert(reg >= R600_LOOP_CONST_OFFSET);
704 assert(cb->atom.num_dw+2+num <= cb->max_num_dw);
705 cb->buf[cb->atom.num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0);
706 cb->buf[cb->atom.num_dw++] = (reg - R600_LOOP_CONST_OFFSET) >> 2;
707 }
708
709 /**
710 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
711 * shaders.
712 */
713 static INLINE void eg_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
714 {
715 assert(reg >= EG_LOOP_CONST_OFFSET);
716 assert(cb->atom.num_dw+2+num <= cb->max_num_dw);
717 cb->buf[cb->atom.num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0) | cb->pkt_flags;
718 cb->buf[cb->atom.num_dw++] = (reg - EG_LOOP_CONST_OFFSET) >> 2;
719 }
720
721 static INLINE void r600_store_config_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
722 {
723 r600_store_config_reg_seq(cb, reg, 1);
724 r600_store_value(cb, value);
725 }
726
727 static INLINE void r600_store_context_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
728 {
729 r600_store_context_reg_seq(cb, reg, 1);
730 r600_store_value(cb, value);
731 }
732
733 static INLINE void r600_store_ctl_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
734 {
735 r600_store_ctl_const_seq(cb, reg, 1);
736 r600_store_value(cb, value);
737 }
738
739 static INLINE void r600_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
740 {
741 r600_store_loop_const_seq(cb, reg, 1);
742 r600_store_value(cb, value);
743 }
744
745 static INLINE void eg_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
746 {
747 eg_store_loop_const_seq(cb, reg, 1);
748 r600_store_value(cb, value);
749 }
750
751 void r600_init_command_buffer(struct r600_context *rctx, struct r600_command_buffer *cb, unsigned id, unsigned num_dw);
752 void r600_release_command_buffer(struct r600_command_buffer *cb);
753
754 /*
755 * Helpers for emitting state into a command stream directly.
756 */
757
758 static INLINE unsigned r600_context_bo_reloc(struct r600_context *ctx, struct r600_resource *rbo,
759 enum radeon_bo_usage usage)
760 {
761 assert(usage);
762 return ctx->ws->cs_add_reloc(ctx->cs, rbo->cs_buf, usage, rbo->domains) * 4;
763 }
764
765 static INLINE void r600_write_value(struct radeon_winsys_cs *cs, unsigned value)
766 {
767 cs->buf[cs->cdw++] = value;
768 }
769
770 static INLINE void r600_write_array(struct radeon_winsys_cs *cs, unsigned num, unsigned *ptr)
771 {
772 assert(cs->cdw+num <= RADEON_MAX_CMDBUF_DWORDS);
773 memcpy(&cs->buf[cs->cdw], ptr, num * sizeof(ptr[0]));
774 cs->cdw += num;
775 }
776
777 static INLINE void r600_write_config_reg_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
778 {
779 assert(reg < R600_CONTEXT_REG_OFFSET);
780 assert(cs->cdw+2+num <= RADEON_MAX_CMDBUF_DWORDS);
781 cs->buf[cs->cdw++] = PKT3(PKT3_SET_CONFIG_REG, num, 0);
782 cs->buf[cs->cdw++] = (reg - R600_CONFIG_REG_OFFSET) >> 2;
783 }
784
785 static INLINE void r600_write_context_reg_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
786 {
787 assert(reg >= R600_CONTEXT_REG_OFFSET && reg < R600_CTL_CONST_OFFSET);
788 assert(cs->cdw+2+num <= RADEON_MAX_CMDBUF_DWORDS);
789 cs->buf[cs->cdw++] = PKT3(PKT3_SET_CONTEXT_REG, num, 0);
790 cs->buf[cs->cdw++] = (reg - R600_CONTEXT_REG_OFFSET) >> 2;
791 }
792
793 static INLINE void r600_write_compute_context_reg_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
794 {
795 r600_write_context_reg_seq(cs, reg, num);
796 /* Set the compute bit on the packet header */
797 cs->buf[cs->cdw - 2] |= RADEON_CP_PACKET3_COMPUTE_MODE;
798 }
799
800 static INLINE void r600_write_ctl_const_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
801 {
802 assert(reg >= R600_CTL_CONST_OFFSET);
803 assert(cs->cdw+2+num <= RADEON_MAX_CMDBUF_DWORDS);
804 cs->buf[cs->cdw++] = PKT3(PKT3_SET_CTL_CONST, num, 0);
805 cs->buf[cs->cdw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
806 }
807
808 static INLINE void r600_write_config_reg(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
809 {
810 r600_write_config_reg_seq(cs, reg, 1);
811 r600_write_value(cs, value);
812 }
813
814 static INLINE void r600_write_context_reg(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
815 {
816 r600_write_context_reg_seq(cs, reg, 1);
817 r600_write_value(cs, value);
818 }
819
820 static INLINE void r600_write_compute_context_reg(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
821 {
822 r600_write_compute_context_reg_seq(cs, reg, 1);
823 r600_write_value(cs, value);
824 }
825
826 static INLINE void r600_write_ctl_const(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
827 {
828 r600_write_ctl_const_seq(cs, reg, 1);
829 r600_write_value(cs, value);
830 }
831
832 /*
833 * common helpers
834 */
835 static INLINE uint32_t S_FIXED(float value, uint32_t frac_bits)
836 {
837 return value * (1 << frac_bits);
838 }
839 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
840
841 static inline unsigned r600_tex_aniso_filter(unsigned filter)
842 {
843 if (filter <= 1) return 0;
844 if (filter <= 2) return 1;
845 if (filter <= 4) return 2;
846 if (filter <= 8) return 3;
847 /* else */ return 4;
848 }
849
850 /* 12.4 fixed-point */
851 static INLINE unsigned r600_pack_float_12p4(float x)
852 {
853 return x <= 0 ? 0 :
854 x >= 4096 ? 0xffff : x * 16;
855 }
856
857 static INLINE uint64_t r600_resource_va(struct pipe_screen *screen, struct pipe_resource *resource)
858 {
859 struct r600_screen *rscreen = (struct r600_screen*)screen;
860 struct r600_resource *rresource = (struct r600_resource*)resource;
861
862 return rscreen->ws->buffer_get_virtual_address(rresource->cs_buf);
863 }
864
865 #endif