2 * Copyright 2013 Advanced Micro Devices, Inc.
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:
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
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
23 * Authors: Marek Olšák <maraeo@gmail.com>
28 * This file contains common screen and context structures and functions
29 * for r600g and radeonsi.
32 #ifndef R600_PIPE_COMMON_H
33 #define R600_PIPE_COMMON_H
37 #include "amd/common/ac_binary.h"
39 #include "radeon/radeon_winsys.h"
41 #include "util/disk_cache.h"
42 #include "util/u_blitter.h"
43 #include "util/list.h"
44 #include "util/u_range.h"
45 #include "util/slab.h"
46 #include "util/u_suballoc.h"
47 #include "util/u_transfer.h"
48 #include "util/u_threaded_context.h"
52 #define ATI_VENDOR_ID 0x1002
54 #define R600_RESOURCE_FLAG_TRANSFER (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
55 #define R600_RESOURCE_FLAG_FLUSHED_DEPTH (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
56 #define R600_RESOURCE_FLAG_FORCE_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)
57 #define R600_RESOURCE_FLAG_DISABLE_DCC (PIPE_RESOURCE_FLAG_DRV_PRIV << 3)
58 #define R600_RESOURCE_FLAG_UNMAPPABLE (PIPE_RESOURCE_FLAG_DRV_PRIV << 4)
60 #define R600_CONTEXT_STREAMOUT_FLUSH (1u << 0)
61 /* Pipeline & streamout query controls. */
62 #define R600_CONTEXT_START_PIPELINE_STATS (1u << 1)
63 #define R600_CONTEXT_STOP_PIPELINE_STATS (1u << 2)
64 #define R600_CONTEXT_FLUSH_FOR_RENDER_COND (1u << 3)
65 #define R600_CONTEXT_PRIVATE_FLAG (1u << 4)
67 /* special primitive types */
68 #define R600_PRIM_RECTANGLE_LIST PIPE_PRIM_MAX
70 #define R600_NOT_QUERY 0xffffffff
74 /* Shader logging options: */
75 DBG_VS
= PIPE_SHADER_VERTEX
,
76 DBG_PS
= PIPE_SHADER_FRAGMENT
,
77 DBG_GS
= PIPE_SHADER_GEOMETRY
,
78 DBG_TCS
= PIPE_SHADER_TESS_CTRL
,
79 DBG_TES
= PIPE_SHADER_TESS_EVAL
,
80 DBG_CS
= PIPE_SHADER_COMPUTE
,
86 /* Shader compiler options the shader cache should be aware of: */
87 DBG_FS_CORRECT_DERIVS_AFTER_KILL
,
91 /* Shader compiler options (with no effect on the shader cache): */
95 DBG_MONOLITHIC_SHADERS
,
98 /* Information logging options: */
104 /* Driver options: */
107 DBG_NO_DISCARD_RANGE
,
111 /* 3D engine options: */
129 DBG_TEST_VMFAULT_SDMA
,
130 DBG_TEST_VMFAULT_SHADER
,
133 #define DBG_ALL_SHADERS (((1 << (DBG_CS + 1)) - 1))
134 #define DBG(name) (1ull << DBG_##name)
136 #define R600_MAP_BUFFER_ALIGNMENT 64
138 #define SI_MAX_VARIABLE_THREADS_PER_BLOCK 1024
140 enum r600_coherency
{
141 R600_COHERENCY_NONE
, /* no cache flushes needed */
142 R600_COHERENCY_SHADER
,
143 R600_COHERENCY_CB_META
,
146 #ifdef PIPE_ARCH_BIG_ENDIAN
147 #define R600_BIG_ENDIAN 1
149 #define R600_BIG_ENDIAN 0
152 struct r600_common_context
;
153 struct r600_perfcounters
;
154 struct tgsi_shader_info
;
155 struct r600_qbo_state
;
157 void si_radeon_shader_binary_init(struct ac_shader_binary
*b
);
158 void si_radeon_shader_binary_clean(struct ac_shader_binary
*b
);
160 /* Only 32-bit buffer allocations are supported, gallium doesn't support more
163 struct r600_resource
{
164 struct threaded_resource b
;
166 /* Winsys objects. */
167 struct pb_buffer
*buf
;
168 uint64_t gpu_address
;
169 /* Memory usage if the buffer placement is optimal. */
173 /* Resource properties. */
175 unsigned bo_alignment
;
176 enum radeon_bo_domain domains
;
177 enum radeon_bo_flag flags
;
178 unsigned bind_history
;
180 /* The buffer range which is initialized (with a write transfer,
181 * streamout, DMA, or as a random access target). The rest of
182 * the buffer is considered invalid and can be mapped unsynchronized.
184 * This allows unsychronized mapping of a buffer range which hasn't
185 * been used yet. It's for applications which forget to use
186 * the unsynchronized map flag and expect the driver to figure it out.
188 struct util_range valid_buffer_range
;
190 /* For buffers only. This indicates that a write operation has been
191 * performed by TC L2, but the cache hasn't been flushed.
192 * Any hw block which doesn't use or bypasses TC L2 should check this
193 * flag and flush the cache before using the buffer.
195 * For example, TC L2 must be flushed if a buffer which has been
196 * modified by a shader store instruction is about to be used as
197 * an index buffer. The reason is that VGT DMA index fetching doesn't
202 /* Whether the resource has been exported via resource_get_handle. */
203 unsigned external_usage
; /* PIPE_HANDLE_USAGE_* */
205 /* Whether this resource is referenced by bindless handles. */
206 bool texture_handle_allocated
;
207 bool image_handle_allocated
;
210 struct r600_transfer
{
211 struct threaded_transfer b
;
212 struct r600_resource
*staging
;
216 struct r600_fmask_info
{
220 unsigned pitch_in_pixels
;
221 unsigned bank_height
;
222 unsigned slice_tile_max
;
223 unsigned tile_mode_index
;
224 unsigned tile_swizzle
;
227 struct r600_cmask_info
{
231 unsigned slice_tile_max
;
232 uint64_t base_address_reg
;
235 struct r600_texture
{
236 struct r600_resource resource
;
239 unsigned num_level0_transfers
;
240 enum pipe_format db_render_format
;
245 unsigned dirty_level_mask
; /* each bit says if that mipmap is compressed */
246 unsigned stencil_dirty_level_mask
; /* each bit says if that mipmap is compressed */
247 struct r600_texture
*flushed_depth_texture
;
248 struct radeon_surf surface
;
250 /* Colorbuffer compression and fast clear. */
251 struct r600_fmask_info fmask
;
252 struct r600_cmask_info cmask
;
253 struct r600_resource
*cmask_buffer
;
254 uint64_t dcc_offset
; /* 0 = disabled */
255 unsigned cb_color_info
; /* fast clear enable bit */
256 unsigned color_clear_value
[2];
257 unsigned last_msaa_resolve_target_micro_mode
;
259 /* Depth buffer compression and fast clear. */
260 uint64_t htile_offset
;
261 bool tc_compatible_htile
;
262 bool depth_cleared
; /* if it was cleared at least once */
263 float depth_clear_value
;
264 bool stencil_cleared
; /* if it was cleared at least once */
265 uint8_t stencil_clear_value
;
266 bool upgraded_depth
; /* upgraded from unorm to Z32_FLOAT */
268 bool non_disp_tiling
; /* R600-Cayman only */
270 /* Whether the texture is a displayable back buffer and needs DCC
271 * decompression, which is expensive. Therefore, it's enabled only
272 * if statistics suggest that it will pay off and it's allocated
273 * separately. It can't be bound as a sampler by apps. Limited to
274 * target == 2D and last_level == 0. If enabled, dcc_offset contains
275 * the absolute GPUVM address, not the relative one.
277 struct r600_resource
*dcc_separate_buffer
;
278 /* When DCC is temporarily disabled, the separate buffer is here. */
279 struct r600_resource
*last_dcc_separate_buffer
;
280 /* We need to track DCC dirtiness, because st/dri usually calls
281 * flush_resource twice per frame (not a bug) and we don't wanna
282 * decompress DCC twice. Also, the dirty tracking must be done even
283 * if DCC isn't used, because it's required by the DCC usage analysis
284 * for a possible future enablement.
286 bool separate_dcc_dirty
;
287 /* Statistics gathering for the DCC enablement heuristic. */
288 bool dcc_gather_statistics
;
289 /* Estimate of how much this color buffer is written to in units of
290 * full-screen draws: ps_invocations / (width * height)
291 * Shader kills, late Z, and blending with trivial discards make it
292 * inaccurate (we need to count CB updates, not PS invocations).
294 unsigned ps_draw_ratio
;
295 /* The number of clears since the last DCC usage analysis. */
296 unsigned num_slow_clears
;
298 /* Counter that should be non-zero if the texture is bound to a
299 * framebuffer. Implemented in radeonsi only.
301 uint32_t framebuffers_bound
;
304 struct r600_surface
{
305 struct pipe_surface base
;
307 /* These can vary with block-compressed textures. */
311 bool color_initialized
;
312 bool depth_initialized
;
314 /* Misc. color flags. */
315 bool alphatest_bypass
;
319 bool dcc_incompatible
;
321 /* Color registers. */
322 unsigned cb_color_info
;
323 unsigned cb_color_base
;
324 unsigned cb_color_view
;
325 unsigned cb_color_size
; /* R600 only */
326 unsigned cb_color_dim
; /* EG only */
327 unsigned cb_color_pitch
; /* EG and later */
328 unsigned cb_color_slice
; /* EG and later */
329 unsigned cb_color_attrib
; /* EG and later */
330 unsigned cb_color_attrib2
; /* GFX9 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 */
344 uint64_t db_depth_base
; /* DB_Z_READ/WRITE_BASE (EG and later) or DB_DEPTH_BASE (r600) */
345 uint64_t db_stencil_base
; /* EG and later */
346 uint64_t db_htile_data_base
;
347 unsigned db_depth_info
; /* R600 only, then SI and later */
348 unsigned db_z_info
; /* EG and later */
349 unsigned db_z_info2
; /* GFX9+ */
350 unsigned db_depth_view
;
351 unsigned db_depth_size
;
352 unsigned db_depth_slice
; /* EG and later */
353 unsigned db_stencil_info
; /* EG and later */
354 unsigned db_stencil_info2
; /* GFX9+ */
355 unsigned db_prefetch_limit
; /* R600 only */
356 unsigned db_htile_surface
;
357 unsigned db_preload_control
; /* EG and later */
360 struct r600_mmio_counter
{
365 union r600_mmio_counters
{
367 /* For global GPU load including SDMA. */
368 struct r600_mmio_counter gpu
;
371 struct r600_mmio_counter spi
;
372 struct r600_mmio_counter gui
;
373 struct r600_mmio_counter ta
;
374 struct r600_mmio_counter gds
;
375 struct r600_mmio_counter vgt
;
376 struct r600_mmio_counter ia
;
377 struct r600_mmio_counter sx
;
378 struct r600_mmio_counter wd
;
379 struct r600_mmio_counter bci
;
380 struct r600_mmio_counter sc
;
381 struct r600_mmio_counter pa
;
382 struct r600_mmio_counter db
;
383 struct r600_mmio_counter cp
;
384 struct r600_mmio_counter cb
;
387 struct r600_mmio_counter sdma
;
390 struct r600_mmio_counter pfp
;
391 struct r600_mmio_counter meq
;
392 struct r600_mmio_counter me
;
393 struct r600_mmio_counter surf_sync
;
394 struct r600_mmio_counter cp_dma
;
395 struct r600_mmio_counter scratch_ram
;
400 struct r600_memory_object
{
401 struct pipe_memory_object b
;
402 struct pb_buffer
*buf
;
407 struct r600_common_screen
{
408 struct pipe_screen b
;
409 struct radeon_winsys
*ws
;
410 enum radeon_family family
;
411 enum chip_class chip_class
;
412 struct radeon_info info
;
413 uint64_t debug_flags
;
416 bool has_rbplus
; /* if RB+ registers exist */
417 bool rbplus_allowed
; /* if RB+ is allowed */
419 struct disk_cache
*disk_shader_cache
;
421 struct slab_parent_pool pool_transfers
;
423 /* Texture filter settings. */
424 int force_aniso
; /* -1 = disabled */
426 /* Auxiliary context. Mainly used to initialize resources.
427 * It must be locked prior to using and flushed before unlocking. */
428 struct pipe_context
*aux_context
;
429 mtx_t aux_context_lock
;
431 /* This must be in the screen, because UE4 uses one context for
432 * compilation and another one for rendering.
434 unsigned num_compilations
;
435 /* Along with ST_DEBUG=precompile, this should show if applications
436 * are loading shaders on demand. This is a monotonic counter.
438 unsigned num_shaders_created
;
439 unsigned num_shader_cache_hits
;
441 /* GPU load thread. */
442 mtx_t gpu_load_mutex
;
443 thrd_t gpu_load_thread
;
444 union r600_mmio_counters mmio_counters
;
445 volatile unsigned gpu_load_stop_thread
; /* bool */
447 char renderer_string
[100];
449 /* Performance counters. */
450 struct r600_perfcounters
*perfcounters
;
452 /* If pipe_screen wants to recompute and re-emit the framebuffer,
453 * sampler, and image states of all contexts, it should atomically
456 * Each context will compare this with its own last known value of
457 * the counter before drawing and re-emit the states accordingly.
459 unsigned dirty_tex_counter
;
461 /* Atomically increment this counter when an existing texture's
462 * metadata is enabled or disabled in a way that requires changing
463 * contexts' compressed texture binding masks.
465 unsigned compressed_colortex_counter
;
468 /* Context flags to set so that all writes from earlier jobs
469 * in the CP are seen by L2 clients.
473 /* Context flags to set so that all writes from earlier jobs
474 * that end in L2 are seen by CP.
478 /* Context flags to set so that all writes from earlier
479 * compute jobs are seen by L2 clients.
481 unsigned compute_to_L2
;
484 void (*query_opaque_metadata
)(struct r600_common_screen
*rscreen
,
485 struct r600_texture
*rtex
,
486 struct radeon_bo_metadata
*md
);
488 void (*apply_opaque_metadata
)(struct r600_common_screen
*rscreen
,
489 struct r600_texture
*rtex
,
490 struct radeon_bo_metadata
*md
);
493 /* This encapsulates a state or an operation which can emitted into the GPU
496 void (*emit
)(struct r600_common_context
*ctx
, struct r600_atom
*state
);
500 struct r600_so_target
{
501 struct pipe_stream_output_target b
;
503 /* The buffer where BUFFER_FILLED_SIZE is stored. */
504 struct r600_resource
*buf_filled_size
;
505 unsigned buf_filled_size_offset
;
506 bool buf_filled_size_valid
;
508 unsigned stride_in_dw
;
511 struct r600_streamout
{
512 struct r600_atom begin_atom
;
515 unsigned enabled_mask
;
516 unsigned num_targets
;
517 struct r600_so_target
*targets
[PIPE_MAX_SO_BUFFERS
];
519 unsigned append_bitmask
;
522 /* External state which comes from the vertex shader,
523 * it must be set explicitly when binding a shader. */
524 uint16_t *stride_in_dw
;
525 unsigned enabled_stream_buffers_mask
; /* stream0 buffers0-3 in 4 LSB */
527 /* The state of VGT_STRMOUT_BUFFER_(CONFIG|EN). */
528 unsigned hw_enabled_mask
;
530 /* The state of VGT_STRMOUT_(CONFIG|EN). */
531 struct r600_atom enable_atom
;
532 bool streamout_enabled
;
533 bool prims_gen_query_enabled
;
534 int num_prims_gen_queries
;
538 struct radeon_winsys_cs
*cs
;
539 void (*flush
)(void *ctx
, unsigned flags
,
540 struct pipe_fence_handle
**fence
);
543 /* Saved CS data for debugging features. */
544 struct radeon_saved_cs
{
548 struct radeon_bo_list_item
*bo_list
;
552 struct r600_common_context
{
553 struct pipe_context b
; /* base class */
555 struct r600_common_screen
*screen
;
556 struct radeon_winsys
*ws
;
557 struct radeon_winsys_ctx
*ctx
;
558 enum radeon_family family
;
559 enum chip_class chip_class
;
560 struct r600_ring gfx
;
561 struct r600_ring dma
;
562 struct pipe_fence_handle
*last_gfx_fence
;
563 struct pipe_fence_handle
*last_sdma_fence
;
564 struct r600_resource
*eop_bug_scratch
;
565 unsigned num_gfx_cs_flushes
;
566 unsigned initial_gfx_cs_size
;
567 unsigned gpu_reset_counter
;
568 unsigned last_dirty_tex_counter
;
569 unsigned last_compressed_colortex_counter
;
570 unsigned last_num_draw_calls
;
572 struct threaded_context
*tc
;
573 struct u_suballocator
*allocator_zeroed_memory
;
574 struct slab_child_pool pool_transfers
;
575 struct slab_child_pool pool_transfers_unsync
; /* for threaded_context */
577 /* Current unaccounted memory usage. */
582 struct r600_streamout streamout
;
584 /* Additional context states. */
585 unsigned flags
; /* flush flags */
588 /* Maintain the list of active queries for pausing between IBs. */
589 int num_occlusion_queries
;
590 int num_perfect_occlusion_queries
;
591 struct list_head active_queries
;
592 unsigned num_cs_dw_queries_suspend
;
594 unsigned num_draw_calls
;
595 unsigned num_decompress_calls
;
596 unsigned num_mrt_draw_calls
;
597 unsigned num_prim_restart_calls
;
598 unsigned num_spill_draw_calls
;
599 unsigned num_compute_calls
;
600 unsigned num_spill_compute_calls
;
601 unsigned num_dma_calls
;
602 unsigned num_cp_dma_calls
;
603 unsigned num_vs_flushes
;
604 unsigned num_ps_flushes
;
605 unsigned num_cs_flushes
;
606 unsigned num_cb_cache_flushes
;
607 unsigned num_db_cache_flushes
;
608 unsigned num_L2_invalidates
;
609 unsigned num_L2_writebacks
;
610 unsigned num_resident_handles
;
611 uint64_t num_alloc_tex_transfer_bytes
;
612 unsigned last_tex_ps_draw_ratio
; /* for query */
614 /* Render condition. */
615 struct r600_atom render_cond_atom
;
616 struct pipe_query
*render_cond
;
617 unsigned render_cond_mode
;
618 bool render_cond_invert
;
619 bool render_cond_force_off
; /* for u_blitter */
621 /* MSAA sample locations.
622 * The first index is the sample index.
623 * The second index is the coordinate: X, Y. */
624 float sample_locations_1x
[1][2];
625 float sample_locations_2x
[2][2];
626 float sample_locations_4x
[4][2];
627 float sample_locations_8x
[8][2];
628 float sample_locations_16x
[16][2];
630 /* Statistics gathering for the DCC enablement heuristic. It can't be
631 * in r600_texture because r600_texture can be shared by multiple
632 * contexts. This is for back buffers only. We shouldn't get too many
635 * X11 DRI3 rotates among a finite set of back buffers. They should
636 * all fit in this array. If they don't, separate DCC might never be
637 * enabled by DCC stat gathering.
640 struct r600_texture
*tex
;
641 /* Query queue: 0 = usually active, 1 = waiting, 2 = readback. */
642 struct pipe_query
*ps_stats
[3];
643 /* If all slots are used and another slot is needed,
644 * the least recently used slot is evicted based on this. */
645 int64_t last_use_timestamp
;
649 struct pipe_debug_callback debug
;
650 struct pipe_device_reset_callback device_reset_callback
;
651 struct u_log_context
*log
;
653 void *query_result_shader
;
655 /* Copy one resource to another using async DMA. */
656 void (*dma_copy
)(struct pipe_context
*ctx
,
657 struct pipe_resource
*dst
,
659 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
660 struct pipe_resource
*src
,
662 const struct pipe_box
*src_box
);
664 void (*dma_clear_buffer
)(struct pipe_context
*ctx
, struct pipe_resource
*dst
,
665 uint64_t offset
, uint64_t size
, unsigned value
);
667 void (*clear_buffer
)(struct pipe_context
*ctx
, struct pipe_resource
*dst
,
668 uint64_t offset
, uint64_t size
, unsigned value
,
669 enum r600_coherency coher
);
671 void (*blit_decompress_depth
)(struct pipe_context
*ctx
,
672 struct r600_texture
*texture
,
673 struct r600_texture
*staging
,
674 unsigned first_level
, unsigned last_level
,
675 unsigned first_layer
, unsigned last_layer
,
676 unsigned first_sample
, unsigned last_sample
);
678 void (*decompress_dcc
)(struct pipe_context
*ctx
,
679 struct r600_texture
*rtex
);
681 /* Reallocate the buffer and update all resource bindings where
682 * the buffer is bound, including all resource descriptors. */
683 void (*invalidate_buffer
)(struct pipe_context
*ctx
, struct pipe_resource
*buf
);
685 /* Update all resource bindings where the buffer is bound, including
686 * all resource descriptors. This is invalidate_buffer without
687 * the invalidation. */
688 void (*rebind_buffer
)(struct pipe_context
*ctx
, struct pipe_resource
*buf
,
689 uint64_t old_gpu_address
);
691 /* Enable or disable occlusion queries. */
692 void (*set_occlusion_query_state
)(struct pipe_context
*ctx
,
694 bool old_perfect_enable
);
696 void (*save_qbo_state
)(struct pipe_context
*ctx
, struct r600_qbo_state
*st
);
698 /* This ensures there is enough space in the command stream. */
699 void (*need_gfx_cs_space
)(struct pipe_context
*ctx
, unsigned num_dw
,
700 bool include_draw_vbo
);
702 void (*set_atom_dirty
)(struct r600_common_context
*ctx
,
703 struct r600_atom
*atom
, bool dirty
);
705 void (*check_vm_faults
)(struct r600_common_context
*ctx
,
706 struct radeon_saved_cs
*saved
,
707 enum ring_type ring
);
710 /* r600_buffer_common.c */
711 bool si_rings_is_buffer_referenced(struct r600_common_context
*ctx
,
712 struct pb_buffer
*buf
,
713 enum radeon_bo_usage usage
);
714 void *si_buffer_map_sync_with_rings(struct r600_common_context
*ctx
,
715 struct r600_resource
*resource
,
717 void si_buffer_subdata(struct pipe_context
*ctx
,
718 struct pipe_resource
*buffer
,
719 unsigned usage
, unsigned offset
,
720 unsigned size
, const void *data
);
721 void si_init_resource_fields(struct r600_common_screen
*rscreen
,
722 struct r600_resource
*res
,
723 uint64_t size
, unsigned alignment
);
724 bool si_alloc_resource(struct r600_common_screen
*rscreen
,
725 struct r600_resource
*res
);
726 struct pipe_resource
*si_buffer_create(struct pipe_screen
*screen
,
727 const struct pipe_resource
*templ
,
729 struct pipe_resource
*si_aligned_buffer_create(struct pipe_screen
*screen
,
734 struct pipe_resource
*
735 si_buffer_from_user_memory(struct pipe_screen
*screen
,
736 const struct pipe_resource
*templ
,
738 void si_invalidate_resource(struct pipe_context
*ctx
,
739 struct pipe_resource
*resource
);
740 void si_replace_buffer_storage(struct pipe_context
*ctx
,
741 struct pipe_resource
*dst
,
742 struct pipe_resource
*src
);
744 /* r600_common_pipe.c */
745 void si_gfx_write_event_eop(struct r600_common_context
*ctx
,
746 unsigned event
, unsigned event_flags
,
748 struct r600_resource
*buf
, uint64_t va
,
749 uint32_t new_fence
, unsigned query_type
);
750 unsigned si_gfx_write_fence_dwords(struct r600_common_screen
*screen
);
751 void si_gfx_wait_fence(struct r600_common_context
*ctx
,
752 uint64_t va
, uint32_t ref
, uint32_t mask
);
753 bool si_common_screen_init(struct r600_common_screen
*rscreen
,
754 struct radeon_winsys
*ws
);
755 void si_destroy_common_screen(struct r600_common_screen
*rscreen
);
756 void si_preflush_suspend_features(struct r600_common_context
*ctx
);
757 void si_postflush_resume_features(struct r600_common_context
*ctx
);
758 bool si_common_context_init(struct r600_common_context
*rctx
,
759 struct r600_common_screen
*rscreen
,
760 unsigned context_flags
);
761 void si_common_context_cleanup(struct r600_common_context
*rctx
);
762 bool si_can_dump_shader(struct r600_common_screen
*rscreen
,
764 bool si_extra_shader_checks(struct r600_common_screen
*rscreen
,
766 void si_screen_clear_buffer(struct r600_common_screen
*rscreen
, struct pipe_resource
*dst
,
767 uint64_t offset
, uint64_t size
, unsigned value
);
768 struct pipe_resource
*si_resource_create_common(struct pipe_screen
*screen
,
769 const struct pipe_resource
*templ
);
770 const char *si_get_llvm_processor_name(enum radeon_family family
);
771 void si_need_dma_space(struct r600_common_context
*ctx
, unsigned num_dw
,
772 struct r600_resource
*dst
, struct r600_resource
*src
);
773 void si_save_cs(struct radeon_winsys
*ws
, struct radeon_winsys_cs
*cs
,
774 struct radeon_saved_cs
*saved
, bool get_buffer_list
);
775 void si_clear_saved_cs(struct radeon_saved_cs
*saved
);
776 bool si_check_device_reset(struct r600_common_context
*rctx
);
778 /* r600_gpu_load.c */
779 void si_gpu_load_kill_thread(struct r600_common_screen
*rscreen
);
780 uint64_t si_begin_counter(struct r600_common_screen
*rscreen
, unsigned type
);
781 unsigned si_end_counter(struct r600_common_screen
*rscreen
, unsigned type
,
784 /* r600_perfcounters.c */
785 void si_perfcounters_destroy(struct r600_common_screen
*rscreen
);
788 void si_init_screen_query_functions(struct r600_common_screen
*rscreen
);
789 void si_init_query_functions(struct r600_common_context
*rctx
);
790 void si_suspend_queries(struct r600_common_context
*ctx
);
791 void si_resume_queries(struct r600_common_context
*ctx
);
793 /* r600_streamout.c */
794 void si_streamout_buffers_dirty(struct r600_common_context
*rctx
);
795 void si_common_set_streamout_targets(struct pipe_context
*ctx
,
796 unsigned num_targets
,
797 struct pipe_stream_output_target
**targets
,
798 const unsigned *offset
);
799 void si_emit_streamout_end(struct r600_common_context
*rctx
);
800 void si_update_prims_generated_query_state(struct r600_common_context
*rctx
,
801 unsigned type
, int diff
);
802 void si_streamout_init(struct r600_common_context
*rctx
);
804 /* r600_test_dma.c */
805 void si_test_dma(struct r600_common_screen
*rscreen
);
808 bool si_prepare_for_dma_blit(struct r600_common_context
*rctx
,
809 struct r600_texture
*rdst
,
810 unsigned dst_level
, unsigned dstx
,
811 unsigned dsty
, unsigned dstz
,
812 struct r600_texture
*rsrc
,
814 const struct pipe_box
*src_box
);
815 void si_texture_get_fmask_info(struct r600_common_screen
*rscreen
,
816 struct r600_texture
*rtex
,
818 struct r600_fmask_info
*out
);
819 bool si_init_flushed_depth_texture(struct pipe_context
*ctx
,
820 struct pipe_resource
*texture
,
821 struct r600_texture
**staging
);
822 void si_print_texture_info(struct r600_common_screen
*rscreen
,
823 struct r600_texture
*rtex
, struct u_log_context
*log
);
824 struct pipe_resource
*si_texture_create(struct pipe_screen
*screen
,
825 const struct pipe_resource
*templ
);
826 bool vi_dcc_formats_compatible(enum pipe_format format1
,
827 enum pipe_format format2
);
828 bool vi_dcc_formats_are_incompatible(struct pipe_resource
*tex
,
830 enum pipe_format view_format
);
831 void vi_disable_dcc_if_incompatible_format(struct r600_common_context
*rctx
,
832 struct pipe_resource
*tex
,
834 enum pipe_format view_format
);
835 struct pipe_surface
*si_create_surface_custom(struct pipe_context
*pipe
,
836 struct pipe_resource
*texture
,
837 const struct pipe_surface
*templ
,
838 unsigned width0
, unsigned height0
,
839 unsigned width
, unsigned height
);
840 unsigned si_translate_colorswap(enum pipe_format format
, bool do_endian_swap
);
841 void vi_separate_dcc_start_query(struct pipe_context
*ctx
,
842 struct r600_texture
*tex
);
843 void vi_separate_dcc_stop_query(struct pipe_context
*ctx
,
844 struct r600_texture
*tex
);
845 void vi_separate_dcc_process_and_reset_stats(struct pipe_context
*ctx
,
846 struct r600_texture
*tex
);
847 void vi_dcc_clear_level(struct r600_common_context
*rctx
,
848 struct r600_texture
*rtex
,
849 unsigned level
, unsigned clear_value
);
850 void si_do_fast_color_clear(struct r600_common_context
*rctx
,
851 struct pipe_framebuffer_state
*fb
,
852 struct r600_atom
*fb_state
,
853 unsigned *buffers
, ubyte
*dirty_cbufs
,
854 const union pipe_color_union
*color
);
855 bool si_texture_disable_dcc(struct r600_common_context
*rctx
,
856 struct r600_texture
*rtex
);
857 void si_init_screen_texture_functions(struct r600_common_screen
*rscreen
);
858 void si_init_context_texture_functions(struct r600_common_context
*rctx
);
861 void si_get_sample_position(struct pipe_context
*ctx
, unsigned sample_count
,
862 unsigned sample_index
, float *out_value
);
863 void si_init_msaa(struct pipe_context
*ctx
);
864 void si_common_emit_msaa_sample_locs(struct radeon_winsys_cs
*cs
, int nr_samples
);
865 void si_common_emit_msaa_config(struct radeon_winsys_cs
*cs
, int nr_samples
,
866 int ps_iter_samples
, int overrast_samples
,
867 unsigned sc_mode_cntl_1
);
870 /* Inline helpers. */
872 static inline struct r600_resource
*r600_resource(struct pipe_resource
*r
)
874 return (struct r600_resource
*)r
;
878 r600_resource_reference(struct r600_resource
**ptr
, struct r600_resource
*res
)
880 pipe_resource_reference((struct pipe_resource
**)ptr
,
881 (struct pipe_resource
*)res
);
885 r600_texture_reference(struct r600_texture
**ptr
, struct r600_texture
*res
)
887 pipe_resource_reference((struct pipe_resource
**)ptr
, &res
->resource
.b
.b
);
891 r600_context_add_resource_size(struct pipe_context
*ctx
, struct pipe_resource
*r
)
893 struct r600_common_context
*rctx
= (struct r600_common_context
*)ctx
;
894 struct r600_resource
*res
= (struct r600_resource
*)r
;
897 /* Add memory usage for need_gfx_cs_space */
898 rctx
->vram
+= res
->vram_usage
;
899 rctx
->gtt
+= res
->gart_usage
;
903 static inline bool r600_get_strmout_en(struct r600_common_context
*rctx
)
905 return rctx
->streamout
.streamout_enabled
||
906 rctx
->streamout
.prims_gen_query_enabled
;
909 #define SQ_TEX_XY_FILTER_POINT 0x00
910 #define SQ_TEX_XY_FILTER_BILINEAR 0x01
911 #define SQ_TEX_XY_FILTER_ANISO_POINT 0x02
912 #define SQ_TEX_XY_FILTER_ANISO_BILINEAR 0x03
914 static inline unsigned eg_tex_filter(unsigned filter
, unsigned max_aniso
)
916 if (filter
== PIPE_TEX_FILTER_LINEAR
)
917 return max_aniso
> 1 ? SQ_TEX_XY_FILTER_ANISO_BILINEAR
918 : SQ_TEX_XY_FILTER_BILINEAR
;
920 return max_aniso
> 1 ? SQ_TEX_XY_FILTER_ANISO_POINT
921 : SQ_TEX_XY_FILTER_POINT
;
924 static inline unsigned r600_tex_aniso_filter(unsigned filter
)
937 static inline enum radeon_bo_priority
938 r600_get_sampler_view_priority(struct r600_resource
*res
)
940 if (res
->b
.b
.target
== PIPE_BUFFER
)
941 return RADEON_PRIO_SAMPLER_BUFFER
;
943 if (res
->b
.b
.nr_samples
> 1)
944 return RADEON_PRIO_SAMPLER_TEXTURE_MSAA
;
946 return RADEON_PRIO_SAMPLER_TEXTURE
;
950 r600_can_sample_zs(struct r600_texture
*tex
, bool stencil_sampler
)
952 return (stencil_sampler
&& tex
->can_sample_s
) ||
953 (!stencil_sampler
&& tex
->can_sample_z
);
957 vi_dcc_enabled(struct r600_texture
*tex
, unsigned level
)
959 return tex
->dcc_offset
&& level
< tex
->surface
.num_dcc_levels
;
963 r600_htile_enabled(struct r600_texture
*tex
, unsigned level
)
965 return tex
->htile_offset
&& level
== 0;
969 vi_tc_compat_htile_enabled(struct r600_texture
*tex
, unsigned level
)
971 assert(!tex
->tc_compatible_htile
|| tex
->htile_offset
);
972 return tex
->tc_compatible_htile
&& level
== 0;
975 #define COMPUTE_DBG(rscreen, fmt, args...) \
977 if ((rscreen->b.debug_flags & DBG(COMPUTE))) fprintf(stderr, fmt, ##args); \
980 #define R600_ERR(fmt, args...) \
981 fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args)
983 /* For MSAA sample positions. */
984 #define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y) \
985 (((s0x) & 0xf) | (((unsigned)(s0y) & 0xf) << 4) | \
986 (((unsigned)(s1x) & 0xf) << 8) | (((unsigned)(s1y) & 0xf) << 12) | \
987 (((unsigned)(s2x) & 0xf) << 16) | (((unsigned)(s2y) & 0xf) << 20) | \
988 (((unsigned)(s3x) & 0xf) << 24) | (((unsigned)(s3y) & 0xf) << 28))
990 static inline int S_FIXED(float value
, unsigned frac_bits
)
992 return value
* (1 << frac_bits
);