radeon/uvd: add UVD implementation v5
[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 "util/u_suballoc.h"
32 #include "util/u_double_list.h"
33 #include "util/u_transfer.h"
34 #include "r600_llvm.h"
35 #include "r600_public.h"
36 #include "r600_resource.h"
37
38 #define R600_NUM_ATOMS 40
39
40 #define R600_TRACE_CS 0
41
42 /* the number of CS dwords for flushing and drawing */
43 #define R600_MAX_FLUSH_CS_DWORDS 16
44 #define R600_MAX_DRAW_CS_DWORDS 34
45 #define R600_TRACE_CS_DWORDS 7
46
47 #define R600_MAX_USER_CONST_BUFFERS 13
48 #define R600_MAX_DRIVER_CONST_BUFFERS 3
49 #define R600_MAX_CONST_BUFFERS (R600_MAX_USER_CONST_BUFFERS + R600_MAX_DRIVER_CONST_BUFFERS)
50
51 /* start driver buffers after user buffers */
52 #define R600_UCP_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS)
53 #define R600_TXQ_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 1)
54 #define R600_BUFFER_INFO_CONST_BUFFER (R600_MAX_USER_CONST_BUFFERS + 2)
55
56 #define R600_MAX_CONST_BUFFER_SIZE 4096
57
58 #ifdef PIPE_ARCH_BIG_ENDIAN
59 #define R600_BIG_ENDIAN 1
60 #else
61 #define R600_BIG_ENDIAN 0
62 #endif
63
64 #define R600_MAP_BUFFER_ALIGNMENT 64
65
66 #define R600_ERR(fmt, args...) \
67 fprintf(stderr, "EE %s:%d %s - "fmt, __FILE__, __LINE__, __func__, ##args)
68
69 #define R600_CONTEXT_INVAL_READ_CACHES (1 << 0)
70 #define R600_CONTEXT_STREAMOUT_FLUSH (1 << 1)
71 #define R600_CONTEXT_WAIT_3D_IDLE (1 << 2)
72 #define R600_CONTEXT_WAIT_CP_DMA_IDLE (1 << 3)
73 #define R600_CONTEXT_FLUSH_AND_INV (1 << 4)
74 #define R600_CONTEXT_FLUSH_AND_INV_CB_META (1 << 5)
75 #define R600_CONTEXT_PS_PARTIAL_FLUSH (1 << 6)
76 #define R600_CONTEXT_FLUSH_AND_INV_DB_META (1 << 7)
77
78 #define R600_QUERY_DRAW_CALLS (PIPE_QUERY_DRIVER_SPECIFIC + 0)
79 #define R600_QUERY_REQUESTED_VRAM (PIPE_QUERY_DRIVER_SPECIFIC + 1)
80 #define R600_QUERY_REQUESTED_GTT (PIPE_QUERY_DRIVER_SPECIFIC + 2)
81
82 struct r600_context;
83 struct r600_bytecode;
84 struct r600_shader_key;
85
86 /* This encapsulates a state or an operation which can emitted into the GPU
87 * command stream. It's not limited to states only, it can be used for anything
88 * that wants to write commands into the CS (e.g. cache flushes). */
89 struct r600_atom {
90 void (*emit)(struct r600_context *ctx, struct r600_atom *state);
91 unsigned id;
92 unsigned num_dw;
93 bool dirty;
94 };
95
96 /* This is an atom containing GPU commands that never change.
97 * This is supposed to be copied directly into the CS. */
98 struct r600_command_buffer {
99 uint32_t *buf;
100 unsigned num_dw;
101 unsigned max_num_dw;
102 unsigned pkt_flags;
103 };
104
105 struct r600_db_state {
106 struct r600_atom atom;
107 struct r600_surface *rsurf;
108 };
109
110 struct r600_db_misc_state {
111 struct r600_atom atom;
112 bool occlusion_query_enabled;
113 bool flush_depthstencil_through_cb;
114 bool flush_depthstencil_in_place;
115 bool copy_depth, copy_stencil;
116 unsigned copy_sample;
117 unsigned log_samples;
118 unsigned db_shader_control;
119 bool htile_clear;
120 };
121
122 struct r600_cb_misc_state {
123 struct r600_atom atom;
124 unsigned cb_color_control; /* this comes from blend state */
125 unsigned blend_colormask; /* 8*4 bits for 8 RGBA colorbuffers */
126 unsigned nr_cbufs;
127 unsigned nr_ps_color_outputs;
128 bool multiwrite;
129 bool dual_src_blend;
130 };
131
132 struct r600_clip_misc_state {
133 struct r600_atom atom;
134 unsigned pa_cl_clip_cntl; /* from rasterizer */
135 unsigned pa_cl_vs_out_cntl; /* from vertex shader */
136 unsigned clip_plane_enable; /* from rasterizer */
137 unsigned clip_dist_write; /* from vertex shader */
138 };
139
140 struct r600_alphatest_state {
141 struct r600_atom atom;
142 unsigned sx_alpha_test_control; /* this comes from dsa state */
143 unsigned sx_alpha_ref; /* this comes from dsa state */
144 bool bypass;
145 bool cb0_export_16bpc; /* from set_framebuffer_state */
146 };
147
148 struct r600_vgt_state {
149 struct r600_atom atom;
150 uint32_t vgt_multi_prim_ib_reset_en;
151 uint32_t vgt_multi_prim_ib_reset_indx;
152 uint32_t vgt_indx_offset;
153 };
154
155 struct r600_blend_color {
156 struct r600_atom atom;
157 struct pipe_blend_color state;
158 };
159
160 struct r600_clip_state {
161 struct r600_atom atom;
162 struct pipe_clip_state state;
163 };
164
165 struct r600_cs_shader_state {
166 struct r600_atom atom;
167 unsigned kernel_index;
168 struct r600_pipe_compute *shader;
169 };
170
171 struct r600_framebuffer {
172 struct r600_atom atom;
173 struct pipe_framebuffer_state state;
174 unsigned compressed_cb_mask;
175 unsigned nr_samples;
176 bool export_16bpc;
177 bool cb0_is_integer;
178 bool is_msaa_resolve;
179 };
180
181 struct r600_sample_mask {
182 struct r600_atom atom;
183 uint16_t sample_mask; /* there are only 8 bits on EG, 16 bits on Cayman */
184 };
185
186 struct r600_config_state {
187 struct r600_atom atom;
188 unsigned sq_gpr_resource_mgmt_1;
189 };
190
191 struct r600_stencil_ref
192 {
193 ubyte ref_value[2];
194 ubyte valuemask[2];
195 ubyte writemask[2];
196 };
197
198 struct r600_stencil_ref_state {
199 struct r600_atom atom;
200 struct r600_stencil_ref state;
201 struct pipe_stencil_ref pipe_state;
202 };
203
204 struct r600_viewport_state {
205 struct r600_atom atom;
206 struct pipe_viewport_state state;
207 };
208
209 struct r600_pipe_fences {
210 struct r600_resource *bo;
211 unsigned *data;
212 unsigned next_index;
213 /* linked list of preallocated blocks */
214 struct list_head blocks;
215 /* linked list of freed fences */
216 struct list_head pool;
217 pipe_mutex mutex;
218 };
219
220 enum r600_msaa_texture_mode {
221 /* If the hw can fetch the first sample only (no decompression available).
222 * This means MSAA texturing is not fully implemented. */
223 MSAA_TEXTURE_SAMPLE_ZERO,
224
225 /* If the hw can fetch decompressed MSAA textures.
226 * Supported families: R600, R700, Evergreen.
227 * Cayman cannot use this, because it cannot do the decompression. */
228 MSAA_TEXTURE_DECOMPRESSED,
229
230 /* If the hw can fetch compressed MSAA textures, which means shaders can
231 * read resolved FMASK. This yields the best performance.
232 * Supported families: Evergreen, Cayman. */
233 MSAA_TEXTURE_COMPRESSED
234 };
235
236 typedef boolean (*r600g_dma_blit_t)(struct pipe_context *ctx,
237 struct pipe_resource *dst,
238 unsigned dst_level,
239 unsigned dst_x, unsigned dst_y, unsigned dst_z,
240 struct pipe_resource *src,
241 unsigned src_level,
242 const struct pipe_box *src_box);
243
244 /* logging */
245 #define DBG_TEX_DEPTH (1 << 0)
246 #define DBG_COMPUTE (1 << 1)
247 /* shaders */
248 #define DBG_FS (1 << 8)
249 #define DBG_VS (1 << 9)
250 #define DBG_GS (1 << 10)
251 #define DBG_PS (1 << 11)
252 #define DBG_CS (1 << 12)
253 /* features */
254 #define DBG_NO_HYPERZ (1 << 16)
255 #define DBG_NO_LLVM (1 << 17)
256 #define DBG_NO_CP_DMA (1 << 18)
257 #define DBG_NO_ASYNC_DMA (1 << 19)
258 #define DBG_NO_DISCARD_RANGE (1 << 20)
259
260 struct r600_tiling_info {
261 unsigned num_channels;
262 unsigned num_banks;
263 unsigned group_bytes;
264 };
265
266 struct r600_screen {
267 struct pipe_screen screen;
268 struct radeon_winsys *ws;
269 unsigned debug_flags;
270 unsigned family;
271 enum chip_class chip_class;
272 struct radeon_info info;
273 bool has_streamout;
274 bool has_msaa;
275 bool has_cp_dma;
276 enum r600_msaa_texture_mode msaa_texture_support;
277 struct r600_tiling_info tiling_info;
278 struct r600_pipe_fences fences;
279
280 /*for compute global memory binding, we allocate stuff here, instead of
281 * buffers.
282 * XXX: Not sure if this is the best place for global_pool. Also,
283 * it's not thread safe, so it won't work with multiple contexts. */
284 struct compute_memory_pool *global_pool;
285 #if R600_TRACE_CS
286 struct r600_resource *trace_bo;
287 uint32_t *trace_ptr;
288 unsigned cs_count;
289 #endif
290 r600g_dma_blit_t dma_blit;
291 };
292
293 struct r600_pipe_sampler_view {
294 struct pipe_sampler_view base;
295 struct r600_resource *tex_resource;
296 uint32_t tex_resource_words[8];
297 bool skip_mip_address_reloc;
298 };
299
300 struct r600_rasterizer_state {
301 struct r600_command_buffer buffer;
302 boolean flatshade;
303 boolean two_side;
304 unsigned sprite_coord_enable;
305 unsigned clip_plane_enable;
306 unsigned pa_sc_line_stipple;
307 unsigned pa_cl_clip_cntl;
308 float offset_units;
309 float offset_scale;
310 bool offset_enable;
311 bool scissor_enable;
312 bool multisample_enable;
313 };
314
315 struct r600_poly_offset_state {
316 struct r600_atom atom;
317 enum pipe_format zs_format;
318 float offset_units;
319 float offset_scale;
320 };
321
322 struct r600_blend_state {
323 struct r600_command_buffer buffer;
324 struct r600_command_buffer buffer_no_blend;
325 unsigned cb_target_mask;
326 unsigned cb_color_control;
327 unsigned cb_color_control_no_blend;
328 bool dual_src_blend;
329 bool alpha_to_one;
330 };
331
332 struct r600_dsa_state {
333 struct r600_command_buffer buffer;
334 unsigned alpha_ref;
335 ubyte valuemask[2];
336 ubyte writemask[2];
337 unsigned zwritemask;
338 unsigned sx_alpha_test_control;
339 };
340
341 struct r600_pipe_shader;
342
343 struct r600_pipe_shader_selector {
344 struct r600_pipe_shader *current;
345
346 struct tgsi_token *tokens;
347 struct pipe_stream_output_info so;
348
349 unsigned num_shaders;
350
351 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
352 unsigned type;
353
354 unsigned nr_ps_max_color_exports;
355 };
356
357 struct r600_pipe_sampler_state {
358 uint32_t tex_sampler_words[3];
359 union pipe_color_union border_color;
360 bool border_color_use;
361 bool seamless_cube_map;
362 };
363
364 /* needed for blitter save */
365 #define NUM_TEX_UNITS 16
366
367 struct r600_seamless_cube_map {
368 struct r600_atom atom;
369 bool enabled;
370 };
371
372 struct r600_samplerview_state {
373 struct r600_atom atom;
374 struct r600_pipe_sampler_view *views[NUM_TEX_UNITS];
375 uint32_t enabled_mask;
376 uint32_t dirty_mask;
377 uint32_t compressed_depthtex_mask; /* which textures are depth */
378 uint32_t compressed_colortex_mask;
379 boolean dirty_txq_constants;
380 boolean dirty_buffer_constants;
381 };
382
383 struct r600_sampler_states {
384 struct r600_atom atom;
385 struct r600_pipe_sampler_state *states[NUM_TEX_UNITS];
386 uint32_t enabled_mask;
387 uint32_t dirty_mask;
388 uint32_t has_bordercolor_mask; /* which states contain the border color */
389 };
390
391 struct r600_textures_info {
392 struct r600_samplerview_state views;
393 struct r600_sampler_states states;
394 bool is_array_sampler[NUM_TEX_UNITS];
395
396 /* cube array txq workaround */
397 uint32_t *txq_constants;
398 /* buffer related workarounds */
399 uint32_t *buffer_constants;
400 };
401
402 struct r600_fence {
403 struct pipe_reference reference;
404 unsigned index; /* in the shared bo */
405 struct r600_resource *sleep_bo;
406 struct list_head head;
407 };
408
409 #define FENCE_BLOCK_SIZE 16
410
411 struct r600_fence_block {
412 struct r600_fence fences[FENCE_BLOCK_SIZE];
413 struct list_head head;
414 };
415
416 #define R600_CONSTANT_ARRAY_SIZE 256
417 #define R600_RESOURCE_ARRAY_SIZE 160
418
419 struct r600_constbuf_state
420 {
421 struct r600_atom atom;
422 struct pipe_constant_buffer cb[PIPE_MAX_CONSTANT_BUFFERS];
423 uint32_t enabled_mask;
424 uint32_t dirty_mask;
425 };
426
427 struct r600_vertexbuf_state
428 {
429 struct r600_atom atom;
430 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
431 uint32_t enabled_mask; /* non-NULL buffers */
432 uint32_t dirty_mask;
433 };
434
435 /* CSO (constant state object, in other words, immutable state). */
436 struct r600_cso_state
437 {
438 struct r600_atom atom;
439 void *cso; /* e.g. r600_blend_state */
440 struct r600_command_buffer *cb;
441 };
442
443 struct r600_scissor_state
444 {
445 struct r600_atom atom;
446 struct pipe_scissor_state scissor;
447 bool enable; /* r6xx only */
448 };
449
450 struct r600_fetch_shader {
451 struct r600_resource *buffer;
452 unsigned offset;
453 };
454
455 struct r600_shader_state {
456 struct r600_atom atom;
457 struct r600_pipe_shader_selector *shader;
458 };
459
460 struct r600_query_buffer {
461 /* The buffer where query results are stored. */
462 struct r600_resource *buf;
463 /* Offset of the next free result after current query data */
464 unsigned results_end;
465 /* If a query buffer is full, a new buffer is created and the old one
466 * is put in here. When we calculate the result, we sum up the samples
467 * from all buffers. */
468 struct r600_query_buffer *previous;
469 };
470
471 struct r600_query {
472 /* The query buffer and how many results are in it. */
473 struct r600_query_buffer buffer;
474 /* The type of query */
475 unsigned type;
476 /* Size of the result in memory for both begin_query and end_query,
477 * this can be one or two numbers, or it could even be a size of a structure. */
478 unsigned result_size;
479 /* The number of dwords for begin_query or end_query. */
480 unsigned num_cs_dw;
481 /* linked list of queries */
482 struct list_head list;
483 /* for custom non-GPU queries */
484 uint64_t begin_result;
485 uint64_t end_result;
486 };
487
488 struct r600_so_target {
489 struct pipe_stream_output_target b;
490
491 /* The buffer where BUFFER_FILLED_SIZE is stored. */
492 struct r600_resource *buf_filled_size;
493 unsigned buf_filled_size_offset;
494
495 unsigned stride_in_dw;
496 unsigned so_index;
497 };
498
499 struct r600_streamout {
500 struct r600_atom begin_atom;
501 bool begin_emitted;
502 unsigned num_dw_for_end;
503
504 unsigned enabled_mask;
505 unsigned num_targets;
506 struct r600_so_target *targets[PIPE_MAX_SO_BUFFERS];
507
508 unsigned append_bitmask;
509 bool suspended;
510 };
511
512 struct r600_ring {
513 struct radeon_winsys_cs *cs;
514 bool flushing;
515 void (*flush)(void *ctx, unsigned flags);
516 };
517
518 struct r600_rings {
519 struct r600_ring gfx;
520 struct r600_ring dma;
521 };
522
523 struct r600_context {
524 struct pipe_context context;
525 struct r600_screen *screen;
526 struct radeon_winsys *ws;
527 struct r600_rings rings;
528 struct blitter_context *blitter;
529 struct u_upload_mgr *uploader;
530 struct u_suballocator *allocator_so_filled_size;
531 struct u_suballocator *allocator_fetch_shader;
532 struct util_slab_mempool pool_transfers;
533
534 /* Hardware info. */
535 enum radeon_family family;
536 enum chip_class chip_class;
537 boolean has_vertex_cache;
538 boolean keep_tiling_flags;
539 unsigned default_ps_gprs, default_vs_gprs;
540 unsigned r6xx_num_clause_temp_gprs;
541 unsigned backend_mask;
542 unsigned max_db; /* for OQ */
543
544 /* current unaccounted memory usage */
545 uint64_t vram;
546 uint64_t gtt;
547
548 /* Miscellaneous state objects. */
549 void *custom_dsa_flush;
550 void *custom_blend_resolve;
551 void *custom_blend_decompress;
552 void *custom_blend_fmask_decompress;
553 /* With rasterizer discard, there doesn't have to be a pixel shader.
554 * In that case, we bind this one: */
555 void *dummy_pixel_shader;
556 /* These dummy CMASK and FMASK buffers are used to get around the R6xx hardware
557 * bug where valid CMASK and FMASK are required to be present to avoid
558 * a hardlock in certain operations but aren't actually used
559 * for anything useful. */
560 struct r600_resource *dummy_fmask;
561 struct r600_resource *dummy_cmask;
562
563 /* State binding slots are here. */
564 struct r600_atom *atoms[R600_NUM_ATOMS];
565 /* States for CS initialization. */
566 struct r600_command_buffer start_cs_cmd; /* invariant state mostly */
567 /** Compute specific registers initializations. The start_cs_cmd atom
568 * must be emitted before start_compute_cs_cmd. */
569 struct r600_command_buffer start_compute_cs_cmd;
570 /* Register states. */
571 struct r600_alphatest_state alphatest_state;
572 struct r600_cso_state blend_state;
573 struct r600_blend_color blend_color;
574 struct r600_cb_misc_state cb_misc_state;
575 struct r600_clip_misc_state clip_misc_state;
576 struct r600_clip_state clip_state;
577 struct r600_db_misc_state db_misc_state;
578 struct r600_db_state db_state;
579 struct r600_cso_state dsa_state;
580 struct r600_framebuffer framebuffer;
581 struct r600_poly_offset_state poly_offset_state;
582 struct r600_cso_state rasterizer_state;
583 struct r600_sample_mask sample_mask;
584 struct r600_scissor_state scissor;
585 struct r600_seamless_cube_map seamless_cube_map;
586 struct r600_config_state config_state;
587 struct r600_stencil_ref_state stencil_ref;
588 struct r600_vgt_state vgt_state;
589 struct r600_viewport_state viewport;
590 /* Shaders and shader resources. */
591 struct r600_cso_state vertex_fetch_shader;
592 struct r600_shader_state vertex_shader;
593 struct r600_shader_state pixel_shader;
594 struct r600_cs_shader_state cs_shader_state;
595 struct r600_constbuf_state constbuf_state[PIPE_SHADER_TYPES];
596 struct r600_textures_info samplers[PIPE_SHADER_TYPES];
597 /** Vertex buffers for fetch shaders */
598 struct r600_vertexbuf_state vertex_buffer_state;
599 /** Vertex buffers for compute shaders */
600 struct r600_vertexbuf_state cs_vertex_buffer_state;
601 struct r600_streamout streamout;
602
603 /* Additional context states. */
604 unsigned flags;
605 unsigned compute_cb_target_mask;
606 struct r600_pipe_shader_selector *ps_shader;
607 struct r600_pipe_shader_selector *vs_shader;
608 struct r600_rasterizer_state *rasterizer;
609 bool alpha_to_one;
610 bool force_blend_disable;
611 boolean dual_src_blend;
612 unsigned zwritemask;
613
614 /* Index buffer. */
615 struct pipe_index_buffer index_buffer;
616
617 /* Last draw state (-1 = unset). */
618 int last_primitive_type; /* Last primitive type used in draw_vbo. */
619 int last_start_instance;
620
621 /* Queries. */
622 /* The list of active queries. Only one query of each type can be active. */
623 int num_occlusion_queries;
624 /* Keep track of non-timer queries, because they should be suspended
625 * during context flushing.
626 * The timer queries (TIME_ELAPSED) shouldn't be suspended. */
627 struct list_head active_nontimer_queries;
628 unsigned num_cs_dw_nontimer_queries_suspend;
629 /* If queries have been suspended. */
630 bool nontimer_queries_suspended;
631 unsigned num_draw_calls;
632
633 /* Render condition. */
634 struct pipe_query *current_render_cond;
635 unsigned current_render_cond_mode;
636 boolean predicate_drawing;
637
638 struct r600_isa *isa;
639 };
640
641 static INLINE void r600_emit_command_buffer(struct radeon_winsys_cs *cs,
642 struct r600_command_buffer *cb)
643 {
644 assert(cs->cdw + cb->num_dw <= RADEON_MAX_CMDBUF_DWORDS);
645 memcpy(cs->buf + cs->cdw, cb->buf, 4 * cb->num_dw);
646 cs->cdw += cb->num_dw;
647 }
648
649 #if R600_TRACE_CS
650 void r600_trace_emit(struct r600_context *rctx);
651 #endif
652
653 static INLINE void r600_emit_atom(struct r600_context *rctx, struct r600_atom *atom)
654 {
655 atom->emit(rctx, atom);
656 atom->dirty = false;
657 #if R600_TRACE_CS
658 if (rctx->screen->trace_bo) {
659 r600_trace_emit(rctx);
660 }
661 #endif
662 }
663
664 static INLINE void r600_set_cso_state(struct r600_cso_state *state, void *cso)
665 {
666 state->cso = cso;
667 state->atom.dirty = cso != NULL;
668 }
669
670 static INLINE void r600_set_cso_state_with_cb(struct r600_cso_state *state, void *cso,
671 struct r600_command_buffer *cb)
672 {
673 state->cb = cb;
674 state->atom.num_dw = cb->num_dw;
675 r600_set_cso_state(state, cso);
676 }
677
678 /* compute_memory_pool.c */
679 struct compute_memory_pool;
680 void compute_memory_pool_delete(struct compute_memory_pool* pool);
681 struct compute_memory_pool* compute_memory_pool_new(
682 struct r600_screen *rscreen);
683
684 /* evergreen_state.c */
685 struct pipe_sampler_view *
686 evergreen_create_sampler_view_custom(struct pipe_context *ctx,
687 struct pipe_resource *texture,
688 const struct pipe_sampler_view *state,
689 unsigned width0, unsigned height0);
690 void evergreen_init_common_regs(struct r600_command_buffer *cb,
691 enum chip_class ctx_chip_class,
692 enum radeon_family ctx_family,
693 int ctx_drm_minor);
694 void cayman_init_common_regs(struct r600_command_buffer *cb,
695 enum chip_class ctx_chip_class,
696 enum radeon_family ctx_family,
697 int ctx_drm_minor);
698
699 void evergreen_init_state_functions(struct r600_context *rctx);
700 void evergreen_init_atom_start_cs(struct r600_context *rctx);
701 void evergreen_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
702 void evergreen_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
703 void *evergreen_create_db_flush_dsa(struct r600_context *rctx);
704 void *evergreen_create_resolve_blend(struct r600_context *rctx);
705 void *evergreen_create_decompress_blend(struct r600_context *rctx);
706 void *evergreen_create_fmask_decompress_blend(struct r600_context *rctx);
707 boolean evergreen_is_format_supported(struct pipe_screen *screen,
708 enum pipe_format format,
709 enum pipe_texture_target target,
710 unsigned sample_count,
711 unsigned usage);
712 void evergreen_init_color_surface(struct r600_context *rctx,
713 struct r600_surface *surf);
714 void evergreen_init_color_surface_rat(struct r600_context *rctx,
715 struct r600_surface *surf);
716 void evergreen_update_db_shader_control(struct r600_context * rctx);
717
718 /* r600_blit.c */
719 void r600_copy_buffer(struct pipe_context *ctx, struct pipe_resource *dst, unsigned dstx,
720 struct pipe_resource *src, const struct pipe_box *src_box);
721 void r600_init_blit_functions(struct r600_context *rctx);
722 void r600_blit_decompress_depth(struct pipe_context *ctx,
723 struct r600_texture *texture,
724 struct r600_texture *staging,
725 unsigned first_level, unsigned last_level,
726 unsigned first_layer, unsigned last_layer,
727 unsigned first_sample, unsigned last_sample);
728 void r600_decompress_depth_textures(struct r600_context *rctx,
729 struct r600_samplerview_state *textures);
730 void r600_decompress_color_textures(struct r600_context *rctx,
731 struct r600_samplerview_state *textures);
732
733 /* r600_buffer.c */
734 bool r600_init_resource(struct r600_screen *rscreen,
735 struct r600_resource *res,
736 unsigned size, unsigned alignment,
737 bool use_reusable_pool, unsigned usage);
738 struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
739 const struct pipe_resource *templ,
740 unsigned alignment);
741
742 /* r600_pipe.c */
743 boolean r600_rings_is_buffer_referenced(struct r600_context *ctx,
744 struct radeon_winsys_cs_handle *buf,
745 enum radeon_bo_usage usage);
746 void *r600_buffer_mmap_sync_with_rings(struct r600_context *ctx,
747 struct r600_resource *resource,
748 unsigned usage);
749 const char * r600_llvm_gpu_string(enum radeon_family family);
750
751
752 /* r600_query.c */
753 void r600_init_query_functions(struct r600_context *rctx);
754 void r600_suspend_nontimer_queries(struct r600_context *ctx);
755 void r600_resume_nontimer_queries(struct r600_context *ctx);
756
757 /* r600_resource.c */
758 void r600_init_context_resource_functions(struct r600_context *r600);
759
760 /* r600_shader.c */
761 int r600_pipe_shader_create(struct pipe_context *ctx,
762 struct r600_pipe_shader *shader,
763 struct r600_shader_key key);
764 #ifdef HAVE_OPENCL
765 int r600_compute_shader_create(struct pipe_context * ctx,
766 LLVMModuleRef mod, struct r600_bytecode * bytecode);
767 #endif
768 void r600_pipe_shader_destroy(struct pipe_context *ctx, struct r600_pipe_shader *shader);
769
770 /* r600_state.c */
771 struct pipe_sampler_view *
772 r600_create_sampler_view_custom(struct pipe_context *ctx,
773 struct pipe_resource *texture,
774 const struct pipe_sampler_view *state,
775 unsigned width_first_level, unsigned height_first_level);
776 void r600_init_state_functions(struct r600_context *rctx);
777 void r600_init_atom_start_cs(struct r600_context *rctx);
778 void r600_update_ps_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
779 void r600_update_vs_state(struct pipe_context *ctx, struct r600_pipe_shader *shader);
780 void *r600_create_db_flush_dsa(struct r600_context *rctx);
781 void *r600_create_resolve_blend(struct r600_context *rctx);
782 void *r700_create_resolve_blend(struct r600_context *rctx);
783 void *r600_create_decompress_blend(struct r600_context *rctx);
784 bool r600_adjust_gprs(struct r600_context *rctx);
785 boolean r600_is_format_supported(struct pipe_screen *screen,
786 enum pipe_format format,
787 enum pipe_texture_target target,
788 unsigned sample_count,
789 unsigned usage);
790 void r600_update_db_shader_control(struct r600_context * rctx);
791
792 /* r600_texture.c */
793 void r600_init_screen_texture_functions(struct pipe_screen *screen);
794 void r600_init_surface_functions(struct r600_context *r600);
795 uint32_t r600_translate_texformat(struct pipe_screen *screen, enum pipe_format format,
796 const unsigned char *swizzle_view,
797 uint32_t *word4_p, uint32_t *yuv_format_p);
798 unsigned r600_texture_get_offset(struct r600_texture *rtex,
799 unsigned level, unsigned layer);
800 struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
801 struct pipe_resource *texture,
802 const struct pipe_surface *templ,
803 unsigned width, unsigned height);
804
805 unsigned r600_get_swizzle_combined(const unsigned char *swizzle_format,
806 const unsigned char *swizzle_view,
807 boolean vtx);
808
809 /* r600_hw_context.c */
810 void r600_get_backend_mask(struct r600_context *ctx);
811 void r600_context_flush(struct r600_context *ctx, unsigned flags);
812 void r600_begin_new_cs(struct r600_context *ctx);
813 void r600_context_emit_fence(struct r600_context *ctx, struct r600_resource *fence,
814 unsigned offset, unsigned value);
815 void r600_flush_emit(struct r600_context *ctx);
816 void r600_need_cs_space(struct r600_context *ctx, unsigned num_dw, boolean count_draw_in);
817 void r600_need_dma_space(struct r600_context *ctx, unsigned num_dw);
818 void r600_cp_dma_copy_buffer(struct r600_context *rctx,
819 struct pipe_resource *dst, uint64_t dst_offset,
820 struct pipe_resource *src, uint64_t src_offset,
821 unsigned size);
822 void r600_dma_copy(struct r600_context *rctx,
823 struct pipe_resource *dst,
824 struct pipe_resource *src,
825 uint64_t dst_offset,
826 uint64_t src_offset,
827 uint64_t size);
828 boolean r600_dma_blit(struct pipe_context *ctx,
829 struct pipe_resource *dst,
830 unsigned dst_level,
831 unsigned dst_x, unsigned dst_y, unsigned dst_z,
832 struct pipe_resource *src,
833 unsigned src_level,
834 const struct pipe_box *src_box);
835 void r600_emit_streamout_begin(struct r600_context *ctx, struct r600_atom *atom);
836 void r600_emit_streamout_end(struct r600_context *ctx);
837
838 /*
839 * evergreen_hw_context.c
840 */
841 void evergreen_flush_vgt_streamout(struct r600_context *ctx);
842 void evergreen_set_streamout_enable(struct r600_context *ctx, unsigned buffer_enable_bit);
843 void evergreen_dma_copy(struct r600_context *rctx,
844 struct pipe_resource *dst,
845 struct pipe_resource *src,
846 uint64_t dst_offset,
847 uint64_t src_offset,
848 uint64_t size);
849 boolean evergreen_dma_blit(struct pipe_context *ctx,
850 struct pipe_resource *dst,
851 unsigned dst_level,
852 unsigned dst_x, unsigned dst_y, unsigned dst_z,
853 struct pipe_resource *src,
854 unsigned src_level,
855 const struct pipe_box *src_box);
856
857 /* r600_state_common.c */
858 void r600_init_common_state_functions(struct r600_context *rctx);
859 void r600_emit_cso_state(struct r600_context *rctx, struct r600_atom *atom);
860 void r600_emit_alphatest_state(struct r600_context *rctx, struct r600_atom *atom);
861 void r600_emit_blend_color(struct r600_context *rctx, struct r600_atom *atom);
862 void r600_emit_vgt_state(struct r600_context *rctx, struct r600_atom *atom);
863 void r600_emit_clip_misc_state(struct r600_context *rctx, struct r600_atom *atom);
864 void r600_emit_stencil_ref(struct r600_context *rctx, struct r600_atom *atom);
865 void r600_emit_viewport_state(struct r600_context *rctx, struct r600_atom *atom);
866 void r600_emit_shader(struct r600_context *rctx, struct r600_atom *a);
867 void r600_init_atom(struct r600_context *rctx, struct r600_atom *atom, unsigned id,
868 void (*emit)(struct r600_context *ctx, struct r600_atom *state),
869 unsigned num_dw);
870 void r600_vertex_buffers_dirty(struct r600_context *rctx);
871 void r600_sampler_views_dirty(struct r600_context *rctx,
872 struct r600_samplerview_state *state);
873 void r600_sampler_states_dirty(struct r600_context *rctx,
874 struct r600_sampler_states *state);
875 void r600_constant_buffers_dirty(struct r600_context *rctx, struct r600_constbuf_state *state);
876 void r600_streamout_buffers_dirty(struct r600_context *rctx);
877 void r600_draw_rectangle(struct blitter_context *blitter,
878 int x1, int y1, int x2, int y2, float depth,
879 enum blitter_attrib_type type, const union pipe_color_union *attrib);
880 uint32_t r600_translate_stencil_op(int s_op);
881 uint32_t r600_translate_fill(uint32_t func);
882 unsigned r600_tex_wrap(unsigned wrap);
883 unsigned r600_tex_filter(unsigned filter);
884 unsigned r600_tex_mipfilter(unsigned filter);
885 unsigned r600_tex_compare(unsigned compare);
886 bool sampler_state_needs_border_color(const struct pipe_sampler_state *state);
887
888 /* r600_uvd.c */
889 struct pipe_video_decoder *r600_uvd_create_decoder(struct pipe_context *context,
890 enum pipe_video_profile profile,
891 enum pipe_video_entrypoint entrypoint,
892 enum pipe_video_chroma_format chroma_format,
893 unsigned width, unsigned height,
894 unsigned max_references, bool expect_chunked_decode);
895
896 struct pipe_video_buffer *r600_video_buffer_create(struct pipe_context *pipe,
897 const struct pipe_video_buffer *tmpl);
898
899
900 /*
901 * Helpers for building command buffers
902 */
903
904 #define PKT3_SET_CONFIG_REG 0x68
905 #define PKT3_SET_CONTEXT_REG 0x69
906 #define PKT3_SET_CTL_CONST 0x6F
907 #define PKT3_SET_LOOP_CONST 0x6C
908
909 #define R600_CONFIG_REG_OFFSET 0x08000
910 #define R600_CONTEXT_REG_OFFSET 0x28000
911 #define R600_CTL_CONST_OFFSET 0x3CFF0
912 #define R600_LOOP_CONST_OFFSET 0X0003E200
913 #define EG_LOOP_CONST_OFFSET 0x0003A200
914
915 #define PKT_TYPE_S(x) (((x) & 0x3) << 30)
916 #define PKT_COUNT_S(x) (((x) & 0x3FFF) << 16)
917 #define PKT3_IT_OPCODE_S(x) (((x) & 0xFF) << 8)
918 #define PKT3_PREDICATE(x) (((x) >> 0) & 0x1)
919 #define PKT3(op, count, predicate) (PKT_TYPE_S(3) | PKT_COUNT_S(count) | PKT3_IT_OPCODE_S(op) | PKT3_PREDICATE(predicate))
920
921 #define RADEON_CP_PACKET3_COMPUTE_MODE 0x00000002
922
923 /*Evergreen Compute packet3*/
924 #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)
925
926 static INLINE void r600_store_value(struct r600_command_buffer *cb, unsigned value)
927 {
928 cb->buf[cb->num_dw++] = value;
929 }
930
931 static INLINE void r600_store_array(struct r600_command_buffer *cb, unsigned num, unsigned *ptr)
932 {
933 assert(cb->num_dw+num <= cb->max_num_dw);
934 memcpy(&cb->buf[cb->num_dw], ptr, num * sizeof(ptr[0]));
935 cb->num_dw += num;
936 }
937
938 static INLINE void r600_store_config_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
939 {
940 assert(reg < R600_CONTEXT_REG_OFFSET);
941 assert(cb->num_dw+2+num <= cb->max_num_dw);
942 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONFIG_REG, num, 0);
943 cb->buf[cb->num_dw++] = (reg - R600_CONFIG_REG_OFFSET) >> 2;
944 }
945
946 /**
947 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
948 * shaders.
949 */
950 static INLINE void r600_store_context_reg_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
951 {
952 assert(reg >= R600_CONTEXT_REG_OFFSET && reg < R600_CTL_CONST_OFFSET);
953 assert(cb->num_dw+2+num <= cb->max_num_dw);
954 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CONTEXT_REG, num, 0) | cb->pkt_flags;
955 cb->buf[cb->num_dw++] = (reg - R600_CONTEXT_REG_OFFSET) >> 2;
956 }
957
958 /**
959 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
960 * shaders.
961 */
962 static INLINE void r600_store_ctl_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
963 {
964 assert(reg >= R600_CTL_CONST_OFFSET);
965 assert(cb->num_dw+2+num <= cb->max_num_dw);
966 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_CTL_CONST, num, 0) | cb->pkt_flags;
967 cb->buf[cb->num_dw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
968 }
969
970 static INLINE void r600_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
971 {
972 assert(reg >= R600_LOOP_CONST_OFFSET);
973 assert(cb->num_dw+2+num <= cb->max_num_dw);
974 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0);
975 cb->buf[cb->num_dw++] = (reg - R600_LOOP_CONST_OFFSET) >> 2;
976 }
977
978 /**
979 * Needs cb->pkt_flags set to RADEON_CP_PACKET3_COMPUTE_MODE for compute
980 * shaders.
981 */
982 static INLINE void eg_store_loop_const_seq(struct r600_command_buffer *cb, unsigned reg, unsigned num)
983 {
984 assert(reg >= EG_LOOP_CONST_OFFSET);
985 assert(cb->num_dw+2+num <= cb->max_num_dw);
986 cb->buf[cb->num_dw++] = PKT3(PKT3_SET_LOOP_CONST, num, 0) | cb->pkt_flags;
987 cb->buf[cb->num_dw++] = (reg - EG_LOOP_CONST_OFFSET) >> 2;
988 }
989
990 static INLINE void r600_store_config_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
991 {
992 r600_store_config_reg_seq(cb, reg, 1);
993 r600_store_value(cb, value);
994 }
995
996 static INLINE void r600_store_context_reg(struct r600_command_buffer *cb, unsigned reg, unsigned value)
997 {
998 r600_store_context_reg_seq(cb, reg, 1);
999 r600_store_value(cb, value);
1000 }
1001
1002 static INLINE void r600_store_ctl_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
1003 {
1004 r600_store_ctl_const_seq(cb, reg, 1);
1005 r600_store_value(cb, value);
1006 }
1007
1008 static INLINE void r600_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
1009 {
1010 r600_store_loop_const_seq(cb, reg, 1);
1011 r600_store_value(cb, value);
1012 }
1013
1014 static INLINE void eg_store_loop_const(struct r600_command_buffer *cb, unsigned reg, unsigned value)
1015 {
1016 eg_store_loop_const_seq(cb, reg, 1);
1017 r600_store_value(cb, value);
1018 }
1019
1020 void r600_init_command_buffer(struct r600_command_buffer *cb, unsigned num_dw);
1021 void r600_release_command_buffer(struct r600_command_buffer *cb);
1022
1023 /*
1024 * Helpers for emitting state into a command stream directly.
1025 */
1026 static INLINE unsigned r600_context_bo_reloc(struct r600_context *ctx,
1027 struct r600_ring *ring,
1028 struct r600_resource *rbo,
1029 enum radeon_bo_usage usage)
1030 {
1031 assert(usage);
1032 /* make sure that all previous ring use are flushed so everything
1033 * look serialized from driver pov
1034 */
1035 if (!ring->flushing) {
1036 if (ring == &ctx->rings.gfx) {
1037 if (ctx->rings.dma.cs) {
1038 /* flush dma ring */
1039 ctx->rings.dma.flush(ctx, RADEON_FLUSH_ASYNC);
1040 }
1041 } else {
1042 /* flush gfx ring */
1043 ctx->rings.gfx.flush(ctx, RADEON_FLUSH_ASYNC);
1044 }
1045 }
1046 return ctx->ws->cs_add_reloc(ring->cs, rbo->cs_buf, usage, rbo->domains) * 4;
1047 }
1048
1049 static INLINE void r600_write_value(struct radeon_winsys_cs *cs, unsigned value)
1050 {
1051 cs->buf[cs->cdw++] = value;
1052 }
1053
1054 static INLINE void r600_write_array(struct radeon_winsys_cs *cs, unsigned num, unsigned *ptr)
1055 {
1056 assert(cs->cdw+num <= RADEON_MAX_CMDBUF_DWORDS);
1057 memcpy(&cs->buf[cs->cdw], ptr, num * sizeof(ptr[0]));
1058 cs->cdw += num;
1059 }
1060
1061 static INLINE void r600_write_config_reg_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
1062 {
1063 assert(reg < R600_CONTEXT_REG_OFFSET);
1064 assert(cs->cdw+2+num <= RADEON_MAX_CMDBUF_DWORDS);
1065 cs->buf[cs->cdw++] = PKT3(PKT3_SET_CONFIG_REG, num, 0);
1066 cs->buf[cs->cdw++] = (reg - R600_CONFIG_REG_OFFSET) >> 2;
1067 }
1068
1069 static INLINE void r600_write_context_reg_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
1070 {
1071 assert(reg >= R600_CONTEXT_REG_OFFSET && reg < R600_CTL_CONST_OFFSET);
1072 assert(cs->cdw+2+num <= RADEON_MAX_CMDBUF_DWORDS);
1073 cs->buf[cs->cdw++] = PKT3(PKT3_SET_CONTEXT_REG, num, 0);
1074 cs->buf[cs->cdw++] = (reg - R600_CONTEXT_REG_OFFSET) >> 2;
1075 }
1076
1077 static INLINE void r600_write_compute_context_reg_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
1078 {
1079 r600_write_context_reg_seq(cs, reg, num);
1080 /* Set the compute bit on the packet header */
1081 cs->buf[cs->cdw - 2] |= RADEON_CP_PACKET3_COMPUTE_MODE;
1082 }
1083
1084 static INLINE void r600_write_ctl_const_seq(struct radeon_winsys_cs *cs, unsigned reg, unsigned num)
1085 {
1086 assert(reg >= R600_CTL_CONST_OFFSET);
1087 assert(cs->cdw+2+num <= RADEON_MAX_CMDBUF_DWORDS);
1088 cs->buf[cs->cdw++] = PKT3(PKT3_SET_CTL_CONST, num, 0);
1089 cs->buf[cs->cdw++] = (reg - R600_CTL_CONST_OFFSET) >> 2;
1090 }
1091
1092 static INLINE void r600_write_config_reg(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
1093 {
1094 r600_write_config_reg_seq(cs, reg, 1);
1095 r600_write_value(cs, value);
1096 }
1097
1098 static INLINE void r600_write_context_reg(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
1099 {
1100 r600_write_context_reg_seq(cs, reg, 1);
1101 r600_write_value(cs, value);
1102 }
1103
1104 static INLINE void r600_write_compute_context_reg(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
1105 {
1106 r600_write_compute_context_reg_seq(cs, reg, 1);
1107 r600_write_value(cs, value);
1108 }
1109
1110 static INLINE void r600_write_ctl_const(struct radeon_winsys_cs *cs, unsigned reg, unsigned value)
1111 {
1112 r600_write_ctl_const_seq(cs, reg, 1);
1113 r600_write_value(cs, value);
1114 }
1115
1116 /*
1117 * common helpers
1118 */
1119 static INLINE uint32_t S_FIXED(float value, uint32_t frac_bits)
1120 {
1121 return value * (1 << frac_bits);
1122 }
1123 #define ALIGN_DIVUP(x, y) (((x) + (y) - 1) / (y))
1124
1125 static inline unsigned r600_tex_aniso_filter(unsigned filter)
1126 {
1127 if (filter <= 1) return 0;
1128 if (filter <= 2) return 1;
1129 if (filter <= 4) return 2;
1130 if (filter <= 8) return 3;
1131 /* else */ return 4;
1132 }
1133
1134 /* 12.4 fixed-point */
1135 static INLINE unsigned r600_pack_float_12p4(float x)
1136 {
1137 return x <= 0 ? 0 :
1138 x >= 4096 ? 0xffff : x * 16;
1139 }
1140
1141 static INLINE uint64_t r600_resource_va(struct pipe_screen *screen, struct pipe_resource *resource)
1142 {
1143 struct r600_screen *rscreen = (struct r600_screen*)screen;
1144 struct r600_resource *rresource = (struct r600_resource*)resource;
1145
1146 return rscreen->ws->buffer_get_virtual_address(rresource->cs_buf);
1147 }
1148
1149 static INLINE void r600_context_add_resource_size(struct pipe_context *ctx, struct pipe_resource *r)
1150 {
1151 struct r600_context *rctx = (struct r600_context *)ctx;
1152 struct r600_resource *rr = (struct r600_resource *)r;
1153
1154 if (r == NULL) {
1155 return;
1156 }
1157
1158 /*
1159 * The idea is to compute a gross estimate of memory requirement of
1160 * each draw call. After each draw call, memory will be precisely
1161 * accounted. So the uncertainty is only on the current draw call.
1162 * In practice this gave very good estimate (+/- 10% of the target
1163 * memory limit).
1164 */
1165 if (rr->domains & RADEON_DOMAIN_GTT) {
1166 rctx->gtt += rr->buf->size;
1167 }
1168 if (rr->domains & RADEON_DOMAIN_VRAM) {
1169 rctx->vram += rr->buf->size;
1170 }
1171 }
1172
1173 #endif