r600/radeonsi: enable glsl/tgsi on-disk cache
[mesa.git] / src / gallium / drivers / radeon / r600_pipe_common.h
1 /*
2 * Copyright 2013 Advanced Micro Devices, Inc.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors: Marek Olšák <maraeo@gmail.com>
24 *
25 */
26
27 /**
28 * This file contains common screen and context structures and functions
29 * for r600g and radeonsi.
30 */
31
32 #ifndef R600_PIPE_COMMON_H
33 #define R600_PIPE_COMMON_H
34
35 #include <stdio.h>
36
37 #include "radeon/radeon_winsys.h"
38
39 #include "util/disk_cache.h"
40 #include "util/u_blitter.h"
41 #include "util/list.h"
42 #include "util/u_range.h"
43 #include "util/slab.h"
44 #include "util/u_suballoc.h"
45 #include "util/u_transfer.h"
46
47 #define ATI_VENDOR_ID 0x1002
48
49 #define R600_RESOURCE_FLAG_TRANSFER (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
50 #define R600_RESOURCE_FLAG_FLUSHED_DEPTH (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
51 #define R600_RESOURCE_FLAG_FORCE_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
52 #define R600_RESOURCE_FLAG_DISABLE_DCC (PIPE_RESOURCE_FLAG_DRV_PRIV << 3)
53 #define R600_RESOURCE_FLAG_UNMAPPABLE (PIPE_RESOURCE_FLAG_DRV_PRIV << 4)
54
55 #define R600_CONTEXT_STREAMOUT_FLUSH (1u << 0)
56 /* Pipeline & streamout query controls. */
57 #define R600_CONTEXT_START_PIPELINE_STATS (1u << 1)
58 #define R600_CONTEXT_STOP_PIPELINE_STATS (1u << 2)
59 #define R600_CONTEXT_PRIVATE_FLAG (1u << 3)
60
61 /* special primitive types */
62 #define R600_PRIM_RECTANGLE_LIST PIPE_PRIM_MAX
63
64 /* Debug flags. */
65 /* logging */
66 #define DBG_TEX (1 << 0)
67 /* gap - reuse */
68 #define DBG_COMPUTE (1 << 2)
69 #define DBG_VM (1 << 3)
70 /* gap - reuse */
71 /* shader logging */
72 #define DBG_FS (1 << 5)
73 #define DBG_VS (1 << 6)
74 #define DBG_GS (1 << 7)
75 #define DBG_PS (1 << 8)
76 #define DBG_CS (1 << 9)
77 #define DBG_TCS (1 << 10)
78 #define DBG_TES (1 << 11)
79 #define DBG_NO_IR (1 << 12)
80 #define DBG_NO_TGSI (1 << 13)
81 #define DBG_NO_ASM (1 << 14)
82 #define DBG_PREOPT_IR (1 << 15)
83 #define DBG_CHECK_IR (1 << 16)
84 #define DBG_NO_OPT_VARIANT (1 << 17)
85 /* gaps */
86 #define DBG_TEST_DMA (1 << 20)
87 /* Bits 21-31 are reserved for the r600g driver. */
88 /* features */
89 #define DBG_NO_ASYNC_DMA (1llu << 32)
90 #define DBG_NO_HYPERZ (1llu << 33)
91 #define DBG_NO_DISCARD_RANGE (1llu << 34)
92 #define DBG_NO_2D_TILING (1llu << 35)
93 #define DBG_NO_TILING (1llu << 36)
94 #define DBG_SWITCH_ON_EOP (1llu << 37)
95 #define DBG_FORCE_DMA (1llu << 38)
96 #define DBG_PRECOMPILE (1llu << 39)
97 #define DBG_INFO (1llu << 40)
98 #define DBG_NO_WC (1llu << 41)
99 #define DBG_CHECK_VM (1llu << 42)
100 #define DBG_NO_DCC (1llu << 43)
101 #define DBG_NO_DCC_CLEAR (1llu << 44)
102 #define DBG_NO_RB_PLUS (1llu << 45)
103 #define DBG_SI_SCHED (1llu << 46)
104 #define DBG_MONOLITHIC_SHADERS (1llu << 47)
105 #define DBG_NO_CE (1llu << 48)
106 #define DBG_UNSAFE_MATH (1llu << 49)
107 #define DBG_NO_DCC_FB (1llu << 50)
108
109 #define R600_MAP_BUFFER_ALIGNMENT 64
110 #define R600_MAX_VIEWPORTS 16
111
112 #define SI_MAX_VARIABLE_THREADS_PER_BLOCK 1024
113
114 enum r600_coherency {
115 R600_COHERENCY_NONE, /* no cache flushes needed */
116 R600_COHERENCY_SHADER,
117 R600_COHERENCY_CB_META,
118 };
119
120 #ifdef PIPE_ARCH_BIG_ENDIAN
121 #define R600_BIG_ENDIAN 1
122 #else
123 #define R600_BIG_ENDIAN 0
124 #endif
125
126 struct r600_common_context;
127 struct r600_perfcounters;
128 struct tgsi_shader_info;
129 struct r600_qbo_state;
130
131 struct radeon_shader_reloc {
132 char name[32];
133 uint64_t offset;
134 };
135
136 struct radeon_shader_binary {
137 /** Shader code */
138 unsigned char *code;
139 unsigned code_size;
140
141 /** Config/Context register state that accompanies this shader.
142 * This is a stream of dword pairs. First dword contains the
143 * register address, the second dword contains the value.*/
144 unsigned char *config;
145 unsigned config_size;
146
147 /** The number of bytes of config information for each global symbol.
148 */
149 unsigned config_size_per_symbol;
150
151 /** Constant data accessed by the shader. This will be uploaded
152 * into a constant buffer. */
153 unsigned char *rodata;
154 unsigned rodata_size;
155
156 /** List of symbol offsets for the shader */
157 uint64_t *global_symbol_offsets;
158 unsigned global_symbol_count;
159
160 struct radeon_shader_reloc *relocs;
161 unsigned reloc_count;
162
163 /** Disassembled shader in a string. */
164 char *disasm_string;
165 char *llvm_ir_string;
166 };
167
168 void radeon_shader_binary_init(struct radeon_shader_binary *b);
169 void radeon_shader_binary_clean(struct radeon_shader_binary *b);
170
171 /* Only 32-bit buffer allocations are supported, gallium doesn't support more
172 * at the moment.
173 */
174 struct r600_resource {
175 struct u_resource b;
176
177 /* Winsys objects. */
178 struct pb_buffer *buf;
179 uint64_t gpu_address;
180 /* Memory usage if the buffer placement is optimal. */
181 uint64_t vram_usage;
182 uint64_t gart_usage;
183
184 /* Resource properties. */
185 uint64_t bo_size;
186 unsigned bo_alignment;
187 enum radeon_bo_domain domains;
188 enum radeon_bo_flag flags;
189 unsigned bind_history;
190
191 /* The buffer range which is initialized (with a write transfer,
192 * streamout, DMA, or as a random access target). The rest of
193 * the buffer is considered invalid and can be mapped unsynchronized.
194 *
195 * This allows unsychronized mapping of a buffer range which hasn't
196 * been used yet. It's for applications which forget to use
197 * the unsynchronized map flag and expect the driver to figure it out.
198 */
199 struct util_range valid_buffer_range;
200
201 /* For buffers only. This indicates that a write operation has been
202 * performed by TC L2, but the cache hasn't been flushed.
203 * Any hw block which doesn't use or bypasses TC L2 should check this
204 * flag and flush the cache before using the buffer.
205 *
206 * For example, TC L2 must be flushed if a buffer which has been
207 * modified by a shader store instruction is about to be used as
208 * an index buffer. The reason is that VGT DMA index fetching doesn't
209 * use TC L2.
210 */
211 bool TC_L2_dirty;
212
213 /* Whether the resource has been exported via resource_get_handle. */
214 bool is_shared;
215 unsigned external_usage; /* PIPE_HANDLE_USAGE_* */
216 };
217
218 struct r600_transfer {
219 struct pipe_transfer transfer;
220 struct r600_resource *staging;
221 unsigned offset;
222 };
223
224 struct r600_fmask_info {
225 uint64_t offset;
226 uint64_t size;
227 unsigned alignment;
228 unsigned pitch_in_pixels;
229 unsigned bank_height;
230 unsigned slice_tile_max;
231 unsigned tile_mode_index;
232 };
233
234 struct r600_cmask_info {
235 uint64_t offset;
236 uint64_t size;
237 unsigned alignment;
238 unsigned slice_tile_max;
239 unsigned base_address_reg;
240 };
241
242 struct r600_texture {
243 struct r600_resource resource;
244
245 uint64_t size;
246 unsigned num_level0_transfers;
247 enum pipe_format db_render_format;
248 bool is_depth;
249 bool db_compatible;
250 bool can_sample_z;
251 bool can_sample_s;
252 unsigned dirty_level_mask; /* each bit says if that mipmap is compressed */
253 unsigned stencil_dirty_level_mask; /* each bit says if that mipmap is compressed */
254 struct r600_texture *flushed_depth_texture;
255 struct radeon_surf surface;
256
257 /* Colorbuffer compression and fast clear. */
258 struct r600_fmask_info fmask;
259 struct r600_cmask_info cmask;
260 struct r600_resource *cmask_buffer;
261 uint64_t dcc_offset; /* 0 = disabled */
262 unsigned cb_color_info; /* fast clear enable bit */
263 unsigned color_clear_value[2];
264 unsigned last_msaa_resolve_target_micro_mode;
265
266 /* Depth buffer compression and fast clear. */
267 struct r600_resource *htile_buffer;
268 bool tc_compatible_htile;
269 bool depth_cleared; /* if it was cleared at least once */
270 float depth_clear_value;
271 bool stencil_cleared; /* if it was cleared at least once */
272 uint8_t stencil_clear_value;
273
274 bool non_disp_tiling; /* R600-Cayman only */
275
276 /* Whether the texture is a displayable back buffer and needs DCC
277 * decompression, which is expensive. Therefore, it's enabled only
278 * if statistics suggest that it will pay off and it's allocated
279 * separately. It can't be bound as a sampler by apps. Limited to
280 * target == 2D and last_level == 0. If enabled, dcc_offset contains
281 * the absolute GPUVM address, not the relative one.
282 */
283 struct r600_resource *dcc_separate_buffer;
284 /* When DCC is temporarily disabled, the separate buffer is here. */
285 struct r600_resource *last_dcc_separate_buffer;
286 /* We need to track DCC dirtiness, because st/dri usually calls
287 * flush_resource twice per frame (not a bug) and we don't wanna
288 * decompress DCC twice. Also, the dirty tracking must be done even
289 * if DCC isn't used, because it's required by the DCC usage analysis
290 * for a possible future enablement.
291 */
292 bool separate_dcc_dirty;
293 /* Statistics gathering for the DCC enablement heuristic. */
294 bool dcc_gather_statistics;
295 /* Estimate of how much this color buffer is written to in units of
296 * full-screen draws: ps_invocations / (width * height)
297 * Shader kills, late Z, and blending with trivial discards make it
298 * inaccurate (we need to count CB updates, not PS invocations).
299 */
300 unsigned ps_draw_ratio;
301 /* The number of clears since the last DCC usage analysis. */
302 unsigned num_slow_clears;
303
304 /* Counter that should be non-zero if the texture is bound to a
305 * framebuffer. Implemented in radeonsi only.
306 */
307 uint32_t framebuffers_bound;
308 };
309
310 struct r600_surface {
311 struct pipe_surface base;
312
313 bool color_initialized;
314 bool depth_initialized;
315
316 /* Misc. color flags. */
317 bool alphatest_bypass;
318 bool export_16bpc;
319 bool color_is_int8;
320 bool color_is_int10;
321
322 /* Color registers. */
323 unsigned cb_color_info;
324 unsigned cb_color_base;
325 unsigned cb_color_view;
326 unsigned cb_color_size; /* R600 only */
327 unsigned cb_color_dim; /* EG only */
328 unsigned cb_color_pitch; /* EG and later */
329 unsigned cb_color_slice; /* EG and later */
330 unsigned cb_color_attrib; /* EG and later */
331 unsigned cb_dcc_control; /* VI and later */
332 unsigned cb_color_fmask; /* CB_COLORn_FMASK (EG and later) or CB_COLORn_FRAG (r600) */
333 unsigned cb_color_fmask_slice; /* EG and later */
334 unsigned cb_color_cmask; /* CB_COLORn_TILE (r600 only) */
335 unsigned cb_color_mask; /* R600 only */
336 unsigned spi_shader_col_format; /* SI+, no blending, no alpha-to-coverage. */
337 unsigned spi_shader_col_format_alpha; /* SI+, alpha-to-coverage */
338 unsigned spi_shader_col_format_blend; /* SI+, blending without alpha. */
339 unsigned spi_shader_col_format_blend_alpha; /* SI+, blending with alpha. */
340 struct r600_resource *cb_buffer_fmask; /* Used for FMASK relocations. R600 only */
341 struct r600_resource *cb_buffer_cmask; /* Used for CMASK relocations. R600 only */
342
343 /* DB registers. */
344 unsigned db_depth_info; /* R600 only, then SI and later */
345 unsigned db_z_info; /* EG and later */
346 unsigned db_depth_base; /* DB_Z_READ/WRITE_BASE (EG and later) or DB_DEPTH_BASE (r600) */
347 unsigned db_depth_view;
348 unsigned db_depth_size;
349 unsigned db_depth_slice; /* EG and later */
350 unsigned db_stencil_base; /* EG and later */
351 unsigned db_stencil_info; /* EG and later */
352 unsigned db_prefetch_limit; /* R600 only */
353 unsigned db_htile_surface;
354 unsigned db_htile_data_base;
355 unsigned db_preload_control; /* EG and later */
356 };
357
358 struct r600_mmio_counter {
359 unsigned busy;
360 unsigned idle;
361 };
362
363 union r600_mmio_counters {
364 struct {
365 /* For global GPU load including SDMA. */
366 struct r600_mmio_counter gpu;
367
368 /* GRBM_STATUS */
369 struct r600_mmio_counter spi;
370 struct r600_mmio_counter gui;
371 struct r600_mmio_counter ta;
372 struct r600_mmio_counter gds;
373 struct r600_mmio_counter vgt;
374 struct r600_mmio_counter ia;
375 struct r600_mmio_counter sx;
376 struct r600_mmio_counter wd;
377 struct r600_mmio_counter bci;
378 struct r600_mmio_counter sc;
379 struct r600_mmio_counter pa;
380 struct r600_mmio_counter db;
381 struct r600_mmio_counter cp;
382 struct r600_mmio_counter cb;
383
384 /* SRBM_STATUS2 */
385 struct r600_mmio_counter sdma;
386
387 /* CP_STAT */
388 struct r600_mmio_counter pfp;
389 struct r600_mmio_counter meq;
390 struct r600_mmio_counter me;
391 struct r600_mmio_counter surf_sync;
392 struct r600_mmio_counter dma;
393 struct r600_mmio_counter scratch_ram;
394 struct r600_mmio_counter ce;
395 } named;
396 unsigned array[0];
397 };
398
399 struct r600_common_screen {
400 struct pipe_screen b;
401 struct radeon_winsys *ws;
402 enum radeon_family family;
403 enum chip_class chip_class;
404 struct radeon_info info;
405 uint64_t debug_flags;
406 bool has_cp_dma;
407 bool has_streamout;
408
409 struct disk_cache *disk_shader_cache;
410
411 struct slab_parent_pool pool_transfers;
412
413 /* Texture filter settings. */
414 int force_aniso; /* -1 = disabled */
415
416 /* Auxiliary context. Mainly used to initialize resources.
417 * It must be locked prior to using and flushed before unlocking. */
418 struct pipe_context *aux_context;
419 pipe_mutex aux_context_lock;
420
421 /* This must be in the screen, because UE4 uses one context for
422 * compilation and another one for rendering.
423 */
424 unsigned num_compilations;
425 /* Along with ST_DEBUG=precompile, this should show if applications
426 * are loading shaders on demand. This is a monotonic counter.
427 */
428 unsigned num_shaders_created;
429 unsigned num_shader_cache_hits;
430
431 /* GPU load thread. */
432 pipe_mutex gpu_load_mutex;
433 pipe_thread gpu_load_thread;
434 union r600_mmio_counters mmio_counters;
435 volatile unsigned gpu_load_stop_thread; /* bool */
436
437 char renderer_string[100];
438
439 /* Performance counters. */
440 struct r600_perfcounters *perfcounters;
441
442 /* If pipe_screen wants to recompute and re-emit the framebuffer,
443 * sampler, and image states of all contexts, it should atomically
444 * increment this.
445 *
446 * Each context will compare this with its own last known value of
447 * the counter before drawing and re-emit the states accordingly.
448 */
449 unsigned dirty_tex_counter;
450
451 /* Atomically increment this counter when an existing texture's
452 * metadata is enabled or disabled in a way that requires changing
453 * contexts' compressed texture binding masks.
454 */
455 unsigned compressed_colortex_counter;
456
457 struct {
458 /* Context flags to set so that all writes from earlier jobs
459 * in the CP are seen by L2 clients.
460 */
461 unsigned cp_to_L2;
462
463 /* Context flags to set so that all writes from earlier
464 * compute jobs are seen by L2 clients.
465 */
466 unsigned compute_to_L2;
467 } barrier_flags;
468
469 void (*query_opaque_metadata)(struct r600_common_screen *rscreen,
470 struct r600_texture *rtex,
471 struct radeon_bo_metadata *md);
472
473 void (*apply_opaque_metadata)(struct r600_common_screen *rscreen,
474 struct r600_texture *rtex,
475 struct radeon_bo_metadata *md);
476 };
477
478 /* This encapsulates a state or an operation which can emitted into the GPU
479 * command stream. */
480 struct r600_atom {
481 void (*emit)(struct r600_common_context *ctx, struct r600_atom *state);
482 unsigned num_dw;
483 unsigned short id;
484 };
485
486 struct r600_so_target {
487 struct pipe_stream_output_target b;
488
489 /* The buffer where BUFFER_FILLED_SIZE is stored. */
490 struct r600_resource *buf_filled_size;
491 unsigned buf_filled_size_offset;
492 bool buf_filled_size_valid;
493
494 unsigned stride_in_dw;
495 };
496
497 struct r600_streamout {
498 struct r600_atom begin_atom;
499 bool begin_emitted;
500 unsigned num_dw_for_end;
501
502 unsigned enabled_mask;
503 unsigned num_targets;
504 struct r600_so_target *targets[PIPE_MAX_SO_BUFFERS];
505
506 unsigned append_bitmask;
507 bool suspended;
508
509 /* External state which comes from the vertex shader,
510 * it must be set explicitly when binding a shader. */
511 unsigned *stride_in_dw;
512 unsigned enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */
513
514 /* The state of VGT_STRMOUT_BUFFER_(CONFIG|EN). */
515 unsigned hw_enabled_mask;
516
517 /* The state of VGT_STRMOUT_(CONFIG|EN). */
518 struct r600_atom enable_atom;
519 bool streamout_enabled;
520 bool prims_gen_query_enabled;
521 int num_prims_gen_queries;
522 };
523
524 struct r600_signed_scissor {
525 int minx;
526 int miny;
527 int maxx;
528 int maxy;
529 };
530
531 struct r600_scissors {
532 struct r600_atom atom;
533 unsigned dirty_mask;
534 struct pipe_scissor_state states[R600_MAX_VIEWPORTS];
535 };
536
537 struct r600_viewports {
538 struct r600_atom atom;
539 unsigned dirty_mask;
540 unsigned depth_range_dirty_mask;
541 struct pipe_viewport_state states[R600_MAX_VIEWPORTS];
542 struct r600_signed_scissor as_scissor[R600_MAX_VIEWPORTS];
543 };
544
545 struct r600_ring {
546 struct radeon_winsys_cs *cs;
547 void (*flush)(void *ctx, unsigned flags,
548 struct pipe_fence_handle **fence);
549 };
550
551 /* Saved CS data for debugging features. */
552 struct radeon_saved_cs {
553 uint32_t *ib;
554 unsigned num_dw;
555
556 struct radeon_bo_list_item *bo_list;
557 unsigned bo_count;
558 };
559
560 struct r600_common_context {
561 struct pipe_context b; /* base class */
562
563 struct r600_common_screen *screen;
564 struct radeon_winsys *ws;
565 struct radeon_winsys_ctx *ctx;
566 enum radeon_family family;
567 enum chip_class chip_class;
568 struct r600_ring gfx;
569 struct r600_ring dma;
570 struct pipe_fence_handle *last_gfx_fence;
571 struct pipe_fence_handle *last_sdma_fence;
572 unsigned num_gfx_cs_flushes;
573 unsigned initial_gfx_cs_size;
574 unsigned gpu_reset_counter;
575 unsigned last_dirty_tex_counter;
576 unsigned last_compressed_colortex_counter;
577
578 struct u_suballocator *allocator_zeroed_memory;
579 struct slab_child_pool pool_transfers;
580
581 /* Current unaccounted memory usage. */
582 uint64_t vram;
583 uint64_t gtt;
584
585 /* States. */
586 struct r600_streamout streamout;
587 struct r600_scissors scissors;
588 struct r600_viewports viewports;
589 bool scissor_enabled;
590 bool clip_halfz;
591 bool vs_writes_viewport_index;
592 bool vs_disables_clipping_viewport;
593
594 /* Additional context states. */
595 unsigned flags; /* flush flags */
596
597 /* Queries. */
598 /* Maintain the list of active queries for pausing between IBs. */
599 int num_occlusion_queries;
600 int num_perfect_occlusion_queries;
601 struct list_head active_queries;
602 unsigned num_cs_dw_queries_suspend;
603 /* Misc stats. */
604 unsigned num_draw_calls;
605 unsigned num_spill_draw_calls;
606 unsigned num_compute_calls;
607 unsigned num_spill_compute_calls;
608 unsigned num_dma_calls;
609 unsigned num_cp_dma_calls;
610 unsigned num_vs_flushes;
611 unsigned num_ps_flushes;
612 unsigned num_cs_flushes;
613 unsigned num_fb_cache_flushes;
614 unsigned num_L2_invalidates;
615 unsigned num_L2_writebacks;
616 uint64_t num_alloc_tex_transfer_bytes;
617 unsigned last_tex_ps_draw_ratio; /* for query */
618
619 /* Render condition. */
620 struct r600_atom render_cond_atom;
621 struct pipe_query *render_cond;
622 unsigned render_cond_mode;
623 bool render_cond_invert;
624 bool render_cond_force_off; /* for u_blitter */
625
626 /* MSAA sample locations.
627 * The first index is the sample index.
628 * The second index is the coordinate: X, Y. */
629 float sample_locations_1x[1][2];
630 float sample_locations_2x[2][2];
631 float sample_locations_4x[4][2];
632 float sample_locations_8x[8][2];
633 float sample_locations_16x[16][2];
634
635 /* Statistics gathering for the DCC enablement heuristic. It can't be
636 * in r600_texture because r600_texture can be shared by multiple
637 * contexts. This is for back buffers only. We shouldn't get too many
638 * of those.
639 *
640 * X11 DRI3 rotates among a finite set of back buffers. They should
641 * all fit in this array. If they don't, separate DCC might never be
642 * enabled by DCC stat gathering.
643 */
644 struct {
645 struct r600_texture *tex;
646 /* Query queue: 0 = usually active, 1 = waiting, 2 = readback. */
647 struct pipe_query *ps_stats[3];
648 /* If all slots are used and another slot is needed,
649 * the least recently used slot is evicted based on this. */
650 int64_t last_use_timestamp;
651 bool query_active;
652 } dcc_stats[5];
653
654 struct pipe_debug_callback debug;
655 struct pipe_device_reset_callback device_reset_callback;
656
657 void *query_result_shader;
658
659 /* Copy one resource to another using async DMA. */
660 void (*dma_copy)(struct pipe_context *ctx,
661 struct pipe_resource *dst,
662 unsigned dst_level,
663 unsigned dst_x, unsigned dst_y, unsigned dst_z,
664 struct pipe_resource *src,
665 unsigned src_level,
666 const struct pipe_box *src_box);
667
668 void (*dma_clear_buffer)(struct pipe_context *ctx, struct pipe_resource *dst,
669 uint64_t offset, uint64_t size, unsigned value);
670
671 void (*clear_buffer)(struct pipe_context *ctx, struct pipe_resource *dst,
672 uint64_t offset, uint64_t size, unsigned value,
673 enum r600_coherency coher);
674
675 void (*blit_decompress_depth)(struct pipe_context *ctx,
676 struct r600_texture *texture,
677 struct r600_texture *staging,
678 unsigned first_level, unsigned last_level,
679 unsigned first_layer, unsigned last_layer,
680 unsigned first_sample, unsigned last_sample);
681
682 void (*decompress_dcc)(struct pipe_context *ctx,
683 struct r600_texture *rtex);
684
685 /* Reallocate the buffer and update all resource bindings where
686 * the buffer is bound, including all resource descriptors. */
687 void (*invalidate_buffer)(struct pipe_context *ctx, struct pipe_resource *buf);
688
689 /* Enable or disable occlusion queries. */
690 void (*set_occlusion_query_state)(struct pipe_context *ctx, bool enable);
691
692 void (*save_qbo_state)(struct pipe_context *ctx, struct r600_qbo_state *st);
693
694 /* This ensures there is enough space in the command stream. */
695 void (*need_gfx_cs_space)(struct pipe_context *ctx, unsigned num_dw,
696 bool include_draw_vbo);
697
698 void (*set_atom_dirty)(struct r600_common_context *ctx,
699 struct r600_atom *atom, bool dirty);
700
701 void (*check_vm_faults)(struct r600_common_context *ctx,
702 struct radeon_saved_cs *saved,
703 enum ring_type ring);
704 };
705
706 /* r600_buffer.c */
707 bool r600_rings_is_buffer_referenced(struct r600_common_context *ctx,
708 struct pb_buffer *buf,
709 enum radeon_bo_usage usage);
710 void *r600_buffer_map_sync_with_rings(struct r600_common_context *ctx,
711 struct r600_resource *resource,
712 unsigned usage);
713 void r600_buffer_subdata(struct pipe_context *ctx,
714 struct pipe_resource *buffer,
715 unsigned usage, unsigned offset,
716 unsigned size, const void *data);
717 void r600_init_resource_fields(struct r600_common_screen *rscreen,
718 struct r600_resource *res,
719 uint64_t size, unsigned alignment);
720 bool r600_alloc_resource(struct r600_common_screen *rscreen,
721 struct r600_resource *res);
722 struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,
723 const struct pipe_resource *templ,
724 unsigned alignment);
725 struct pipe_resource * r600_aligned_buffer_create(struct pipe_screen *screen,
726 unsigned flags,
727 unsigned usage,
728 unsigned size,
729 unsigned alignment);
730 struct pipe_resource *
731 r600_buffer_from_user_memory(struct pipe_screen *screen,
732 const struct pipe_resource *templ,
733 void *user_memory);
734 void
735 r600_invalidate_resource(struct pipe_context *ctx,
736 struct pipe_resource *resource);
737
738 /* r600_common_pipe.c */
739 void r600_gfx_write_event_eop(struct r600_common_context *ctx,
740 unsigned event, unsigned event_flags,
741 unsigned data_sel,
742 struct r600_resource *buf, uint64_t va,
743 uint32_t old_fence, uint32_t new_fence);
744 unsigned r600_gfx_write_fence_dwords(struct r600_common_screen *screen);
745 void r600_gfx_wait_fence(struct r600_common_context *ctx,
746 uint64_t va, uint32_t ref, uint32_t mask);
747 void r600_draw_rectangle(struct blitter_context *blitter,
748 int x1, int y1, int x2, int y2, float depth,
749 enum blitter_attrib_type type,
750 const union pipe_color_union *attrib);
751 bool r600_common_screen_init(struct r600_common_screen *rscreen,
752 struct radeon_winsys *ws);
753 void r600_destroy_common_screen(struct r600_common_screen *rscreen);
754 void r600_preflush_suspend_features(struct r600_common_context *ctx);
755 void r600_postflush_resume_features(struct r600_common_context *ctx);
756 bool r600_common_context_init(struct r600_common_context *rctx,
757 struct r600_common_screen *rscreen,
758 unsigned context_flags);
759 void r600_common_context_cleanup(struct r600_common_context *rctx);
760 bool r600_can_dump_shader(struct r600_common_screen *rscreen,
761 unsigned processor);
762 bool r600_extra_shader_checks(struct r600_common_screen *rscreen,
763 unsigned processor);
764 void r600_screen_clear_buffer(struct r600_common_screen *rscreen, struct pipe_resource *dst,
765 uint64_t offset, uint64_t size, unsigned value);
766 struct pipe_resource *r600_resource_create_common(struct pipe_screen *screen,
767 const struct pipe_resource *templ);
768 const char *r600_get_llvm_processor_name(enum radeon_family family);
769 void r600_need_dma_space(struct r600_common_context *ctx, unsigned num_dw,
770 struct r600_resource *dst, struct r600_resource *src);
771 void radeon_save_cs(struct radeon_winsys *ws, struct radeon_winsys_cs *cs,
772 struct radeon_saved_cs *saved);
773 void radeon_clear_saved_cs(struct radeon_saved_cs *saved);
774 bool r600_check_device_reset(struct r600_common_context *rctx);
775
776 /* r600_gpu_load.c */
777 void r600_gpu_load_kill_thread(struct r600_common_screen *rscreen);
778 uint64_t r600_begin_counter(struct r600_common_screen *rscreen, unsigned type);
779 unsigned r600_end_counter(struct r600_common_screen *rscreen, unsigned type,
780 uint64_t begin);
781
782 /* r600_perfcounters.c */
783 void r600_perfcounters_destroy(struct r600_common_screen *rscreen);
784
785 /* r600_query.c */
786 void r600_init_screen_query_functions(struct r600_common_screen *rscreen);
787 void r600_query_init(struct r600_common_context *rctx);
788 void r600_suspend_queries(struct r600_common_context *ctx);
789 void r600_resume_queries(struct r600_common_context *ctx);
790 void r600_query_fix_enabled_rb_mask(struct r600_common_screen *rscreen);
791
792 /* r600_streamout.c */
793 void r600_streamout_buffers_dirty(struct r600_common_context *rctx);
794 void r600_set_streamout_targets(struct pipe_context *ctx,
795 unsigned num_targets,
796 struct pipe_stream_output_target **targets,
797 const unsigned *offset);
798 void r600_emit_streamout_end(struct r600_common_context *rctx);
799 void r600_update_prims_generated_query_state(struct r600_common_context *rctx,
800 unsigned type, int diff);
801 void r600_streamout_init(struct r600_common_context *rctx);
802
803 /* r600_test_dma.c */
804 void r600_test_dma(struct r600_common_screen *rscreen);
805
806 /* r600_texture.c */
807 bool r600_prepare_for_dma_blit(struct r600_common_context *rctx,
808 struct r600_texture *rdst,
809 unsigned dst_level, unsigned dstx,
810 unsigned dsty, unsigned dstz,
811 struct r600_texture *rsrc,
812 unsigned src_level,
813 const struct pipe_box *src_box);
814 void r600_texture_get_fmask_info(struct r600_common_screen *rscreen,
815 struct r600_texture *rtex,
816 unsigned nr_samples,
817 struct r600_fmask_info *out);
818 void r600_texture_get_cmask_info(struct r600_common_screen *rscreen,
819 struct r600_texture *rtex,
820 struct r600_cmask_info *out);
821 bool r600_init_flushed_depth_texture(struct pipe_context *ctx,
822 struct pipe_resource *texture,
823 struct r600_texture **staging);
824 void r600_print_texture_info(struct r600_texture *rtex, FILE *f);
825 struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
826 const struct pipe_resource *templ);
827 bool vi_dcc_formats_compatible(enum pipe_format format1,
828 enum pipe_format format2);
829 void vi_dcc_disable_if_incompatible_format(struct r600_common_context *rctx,
830 struct pipe_resource *tex,
831 unsigned level,
832 enum pipe_format view_format);
833 struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
834 struct pipe_resource *texture,
835 const struct pipe_surface *templ,
836 unsigned width, unsigned height);
837 unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap);
838 void vi_separate_dcc_start_query(struct pipe_context *ctx,
839 struct r600_texture *tex);
840 void vi_separate_dcc_stop_query(struct pipe_context *ctx,
841 struct r600_texture *tex);
842 void vi_separate_dcc_process_and_reset_stats(struct pipe_context *ctx,
843 struct r600_texture *tex);
844 void vi_dcc_clear_level(struct r600_common_context *rctx,
845 struct r600_texture *rtex,
846 unsigned level, unsigned clear_value);
847 void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
848 struct pipe_framebuffer_state *fb,
849 struct r600_atom *fb_state,
850 unsigned *buffers, unsigned *dirty_cbufs,
851 const union pipe_color_union *color);
852 bool r600_texture_disable_dcc(struct r600_common_context *rctx,
853 struct r600_texture *rtex);
854 void r600_init_screen_texture_functions(struct r600_common_screen *rscreen);
855 void r600_init_context_texture_functions(struct r600_common_context *rctx);
856
857 /* r600_viewport.c */
858 void evergreen_apply_scissor_bug_workaround(struct r600_common_context *rctx,
859 struct pipe_scissor_state *scissor);
860 void r600_viewport_set_rast_deps(struct r600_common_context *rctx,
861 bool scissor_enable, bool clip_halfz);
862 void r600_update_vs_writes_viewport_index(struct r600_common_context *rctx,
863 struct tgsi_shader_info *info);
864 void r600_init_viewport_functions(struct r600_common_context *rctx);
865
866 /* cayman_msaa.c */
867 extern const uint32_t eg_sample_locs_2x[4];
868 extern const unsigned eg_max_dist_2x;
869 extern const uint32_t eg_sample_locs_4x[4];
870 extern const unsigned eg_max_dist_4x;
871 void cayman_get_sample_position(struct pipe_context *ctx, unsigned sample_count,
872 unsigned sample_index, float *out_value);
873 void cayman_init_msaa(struct pipe_context *ctx);
874 void cayman_emit_msaa_sample_locs(struct radeon_winsys_cs *cs, int nr_samples);
875 void cayman_emit_msaa_config(struct radeon_winsys_cs *cs, int nr_samples,
876 int ps_iter_samples, int overrast_samples,
877 unsigned sc_mode_cntl_1);
878
879
880 /* Inline helpers. */
881
882 static inline struct r600_resource *r600_resource(struct pipe_resource *r)
883 {
884 return (struct r600_resource*)r;
885 }
886
887 static inline void
888 r600_resource_reference(struct r600_resource **ptr, struct r600_resource *res)
889 {
890 pipe_resource_reference((struct pipe_resource **)ptr,
891 (struct pipe_resource *)res);
892 }
893
894 static inline void
895 r600_texture_reference(struct r600_texture **ptr, struct r600_texture *res)
896 {
897 pipe_resource_reference((struct pipe_resource **)ptr, &res->resource.b.b);
898 }
899
900 static inline void
901 r600_context_add_resource_size(struct pipe_context *ctx, struct pipe_resource *r)
902 {
903 struct r600_common_context *rctx = (struct r600_common_context *)ctx;
904 struct r600_resource *res = (struct r600_resource *)r;
905
906 if (res) {
907 /* Add memory usage for need_gfx_cs_space */
908 rctx->vram += res->vram_usage;
909 rctx->gtt += res->gart_usage;
910 }
911 }
912
913 static inline bool r600_get_strmout_en(struct r600_common_context *rctx)
914 {
915 return rctx->streamout.streamout_enabled ||
916 rctx->streamout.prims_gen_query_enabled;
917 }
918
919 #define SQ_TEX_XY_FILTER_POINT 0x00
920 #define SQ_TEX_XY_FILTER_BILINEAR 0x01
921 #define SQ_TEX_XY_FILTER_ANISO_POINT 0x02
922 #define SQ_TEX_XY_FILTER_ANISO_BILINEAR 0x03
923
924 static inline unsigned eg_tex_filter(unsigned filter, unsigned max_aniso)
925 {
926 if (filter == PIPE_TEX_FILTER_LINEAR)
927 return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_BILINEAR
928 : SQ_TEX_XY_FILTER_BILINEAR;
929 else
930 return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_POINT
931 : SQ_TEX_XY_FILTER_POINT;
932 }
933
934 static inline unsigned r600_tex_aniso_filter(unsigned filter)
935 {
936 if (filter < 2)
937 return 0;
938 if (filter < 4)
939 return 1;
940 if (filter < 8)
941 return 2;
942 if (filter < 16)
943 return 3;
944 return 4;
945 }
946
947 static inline unsigned r600_wavefront_size(enum radeon_family family)
948 {
949 switch (family) {
950 case CHIP_RV610:
951 case CHIP_RS780:
952 case CHIP_RV620:
953 case CHIP_RS880:
954 return 16;
955 case CHIP_RV630:
956 case CHIP_RV635:
957 case CHIP_RV730:
958 case CHIP_RV710:
959 case CHIP_PALM:
960 case CHIP_CEDAR:
961 return 32;
962 default:
963 return 64;
964 }
965 }
966
967 static inline enum radeon_bo_priority
968 r600_get_sampler_view_priority(struct r600_resource *res)
969 {
970 if (res->b.b.target == PIPE_BUFFER)
971 return RADEON_PRIO_SAMPLER_BUFFER;
972
973 if (res->b.b.nr_samples > 1)
974 return RADEON_PRIO_SAMPLER_TEXTURE_MSAA;
975
976 return RADEON_PRIO_SAMPLER_TEXTURE;
977 }
978
979 static inline bool
980 r600_can_sample_zs(struct r600_texture *tex, bool stencil_sampler)
981 {
982 return (stencil_sampler && tex->can_sample_s) ||
983 (!stencil_sampler && tex->can_sample_z);
984 }
985
986 #define COMPUTE_DBG(rscreen, fmt, args...) \
987 do { \
988 if ((rscreen->b.debug_flags & DBG_COMPUTE)) fprintf(stderr, fmt, ##args); \
989 } while (0);
990
991 #define R600_ERR(fmt, args...) \
992 fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args)
993
994 /* For MSAA sample positions. */
995 #define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y) \
996 (((s0x) & 0xf) | (((unsigned)(s0y) & 0xf) << 4) | \
997 (((unsigned)(s1x) & 0xf) << 8) | (((unsigned)(s1y) & 0xf) << 12) | \
998 (((unsigned)(s2x) & 0xf) << 16) | (((unsigned)(s2y) & 0xf) << 20) | \
999 (((unsigned)(s3x) & 0xf) << 24) | (((unsigned)(s3y) & 0xf) << 28))
1000
1001 #endif