Path: blob/21.2-virgl/src/gallium/drivers/r600/r600_pipe_common.h
4570 views
/*1* Copyright 2013 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors: Marek Olšák <[email protected]>23*24*/2526/**27* This file contains common screen and context structures and functions28* for r600g and radeonsi.29*/3031#ifndef R600_PIPE_COMMON_H32#define R600_PIPE_COMMON_H3334#include <stdio.h>3536#include "radeon/radeon_winsys.h"3738#include "util/disk_cache.h"39#include "util/u_blitter.h"40#include "util/list.h"41#include "util/u_range.h"42#include "util/slab.h"43#include "util/u_suballoc.h"44#include "util/u_transfer.h"45#include "util/u_threaded_context.h"4647#include "compiler/nir/nir.h"4849struct u_log_context;50#define ATI_VENDOR_ID 0x10025152#define R600_RESOURCE_FLAG_TRANSFER (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)53#define R600_RESOURCE_FLAG_FLUSHED_DEPTH (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)54#define R600_RESOURCE_FLAG_FORCE_TILING (PIPE_RESOURCE_FLAG_DRV_PRIV << 2)55#define R600_RESOURCE_FLAG_UNMAPPABLE (PIPE_RESOURCE_FLAG_DRV_PRIV << 4)5657#define R600_CONTEXT_STREAMOUT_FLUSH (1u << 0)58/* Pipeline & streamout query controls. */59#define R600_CONTEXT_START_PIPELINE_STATS (1u << 1)60#define R600_CONTEXT_STOP_PIPELINE_STATS (1u << 2)61#define R600_CONTEXT_FLUSH_FOR_RENDER_COND (1u << 3)62#define R600_CONTEXT_PRIVATE_FLAG (1u << 4)6364/* special primitive types */65#define R600_PRIM_RECTANGLE_LIST PIPE_PRIM_MAX6667#define R600_NOT_QUERY 0xffffffff6869/* Debug flags. */70#define DBG_VS (1 << PIPE_SHADER_VERTEX)71#define DBG_PS (1 << PIPE_SHADER_FRAGMENT)72#define DBG_GS (1 << PIPE_SHADER_GEOMETRY)73#define DBG_TCS (1 << PIPE_SHADER_TESS_CTRL)74#define DBG_TES (1 << PIPE_SHADER_TESS_EVAL)75#define DBG_CS (1 << PIPE_SHADER_COMPUTE)76#define DBG_ALL_SHADERS (DBG_FS - 1)77#define DBG_FS (1 << 6) /* fetch shader */78#define DBG_TEX (1 << 7)79#define DBG_NIR (1 << 8)80#define DBG_COMPUTE (1 << 9)81/* gap */82#define DBG_VM (1 << 11)83#define DBG_NO_IR (1 << 12)84#define DBG_NO_TGSI (1 << 13)85#define DBG_NO_ASM (1 << 14)86#define DBG_PREOPT_IR (1 << 15)87#define DBG_CHECK_IR (1 << 16)88#define DBG_NO_OPT_VARIANT (1 << 17)89#define DBG_FS_CORRECT_DERIVS_AFTER_KILL (1 << 18)90/* gaps */91#define DBG_TEST_DMA (1 << 20)92/* Bits 21-31 are reserved for the r600g driver. */93/* features */94#define DBG_NO_ASYNC_DMA (1ull << 32)95#define DBG_NO_HYPERZ (1ull << 33)96#define DBG_NO_DISCARD_RANGE (1ull << 34)97#define DBG_NO_2D_TILING (1ull << 35)98#define DBG_NO_TILING (1ull << 36)99#define DBG_SWITCH_ON_EOP (1ull << 37)100#define DBG_FORCE_DMA (1ull << 38)101#define DBG_PRECOMPILE (1ull << 39)102#define DBG_INFO (1ull << 40)103#define DBG_NO_WC (1ull << 41)104#define DBG_CHECK_VM (1ull << 42)105/* gap */106#define DBG_UNSAFE_MATH (1ull << 49)107#define DBG_TEST_VMFAULT_CP (1ull << 51)108#define DBG_TEST_VMFAULT_SDMA (1ull << 52)109#define DBG_TEST_VMFAULT_SHADER (1ull << 53)110111#define R600_MAP_BUFFER_ALIGNMENT 64112#define R600_MAX_VIEWPORTS 16113114#define SI_MAX_VARIABLE_THREADS_PER_BLOCK 1024115116enum r600_coherency {117R600_COHERENCY_NONE, /* no cache flushes needed */118R600_COHERENCY_SHADER,119R600_COHERENCY_CB_META,120};121122#if UTIL_ARCH_BIG_ENDIAN123#define R600_BIG_ENDIAN 1124#else125#define R600_BIG_ENDIAN 0126#endif127128struct r600_common_context;129struct r600_perfcounters;130struct tgsi_shader_info;131struct r600_qbo_state;132133/* Only 32-bit buffer allocations are supported, gallium doesn't support more134* at the moment.135*/136struct r600_resource {137struct threaded_resource b;138139/* Winsys objects. */140struct pb_buffer *buf;141uint64_t gpu_address;142/* Memory usage if the buffer placement is optimal. */143uint64_t vram_usage;144uint64_t gart_usage;145146/* Resource properties. */147uint64_t bo_size;148unsigned bo_alignment;149enum radeon_bo_domain domains;150enum radeon_bo_flag flags;151unsigned bind_history;152153/* The buffer range which is initialized (with a write transfer,154* streamout, DMA, or as a random access target). The rest of155* the buffer is considered invalid and can be mapped unsynchronized.156*157* This allows unsychronized mapping of a buffer range which hasn't158* been used yet. It's for applications which forget to use159* the unsynchronized map flag and expect the driver to figure it out.160*/161struct util_range valid_buffer_range;162163/* Whether the resource has been exported via resource_get_handle. */164unsigned external_usage; /* PIPE_HANDLE_USAGE_* */165166/* Whether this resource is referenced by bindless handles. */167bool texture_handle_allocated;168bool image_handle_allocated;169bool compute_global_bo;170171/*172* EG/Cayman only - for RAT operations hw need an immediate buffer173* to store results in.174*/175struct r600_resource *immed_buffer;176};177178struct r600_transfer {179struct threaded_transfer b;180struct r600_resource *staging;181};182183struct r600_fmask_info {184uint64_t offset;185uint64_t size;186unsigned alignment;187unsigned pitch_in_pixels;188unsigned bank_height;189unsigned slice_tile_max;190unsigned tile_mode_index;191unsigned tile_swizzle;192};193194struct r600_cmask_info {195uint64_t offset;196uint64_t size;197unsigned alignment;198unsigned slice_tile_max;199uint64_t base_address_reg;200};201202struct r600_texture {203struct r600_resource resource;204205uint64_t size;206unsigned num_level0_transfers;207enum pipe_format db_render_format;208bool is_depth;209bool db_compatible;210bool can_sample_z;211bool can_sample_s;212unsigned dirty_level_mask; /* each bit says if that mipmap is compressed */213unsigned stencil_dirty_level_mask; /* each bit says if that mipmap is compressed */214struct r600_texture *flushed_depth_texture;215struct radeon_surf surface;216217/* Colorbuffer compression and fast clear. */218struct r600_fmask_info fmask;219struct r600_cmask_info cmask;220struct r600_resource *cmask_buffer;221unsigned cb_color_info; /* fast clear enable bit */222unsigned color_clear_value[2];223unsigned last_msaa_resolve_target_micro_mode;224225/* Depth buffer compression and fast clear. */226uint64_t htile_offset;227bool depth_cleared; /* if it was cleared at least once */228float depth_clear_value;229bool stencil_cleared; /* if it was cleared at least once */230uint8_t stencil_clear_value;231232bool non_disp_tiling; /* R600-Cayman only */233234/* Counter that should be non-zero if the texture is bound to a235* framebuffer. Implemented in radeonsi only.236*/237uint32_t framebuffers_bound;238};239240struct r600_surface {241struct pipe_surface base;242243/* These can vary with block-compressed textures. */244unsigned width0;245unsigned height0;246247bool color_initialized;248bool depth_initialized;249250/* Misc. color flags. */251bool alphatest_bypass;252bool export_16bpc;253bool color_is_int8;254bool color_is_int10;255256/* Color registers. */257unsigned cb_color_info;258unsigned cb_color_base;259unsigned cb_color_view;260unsigned cb_color_size; /* R600 only */261unsigned cb_color_dim; /* EG only */262unsigned cb_color_pitch; /* EG and later */263unsigned cb_color_slice; /* EG and later */264unsigned cb_color_attrib; /* EG and later */265unsigned cb_color_fmask; /* CB_COLORn_FMASK (EG and later) or CB_COLORn_FRAG (r600) */266unsigned cb_color_fmask_slice; /* EG and later */267unsigned cb_color_cmask; /* CB_COLORn_TILE (r600 only) */268unsigned cb_color_mask; /* R600 only */269struct r600_resource *cb_buffer_fmask; /* Used for FMASK relocations. R600 only */270struct r600_resource *cb_buffer_cmask; /* Used for CMASK relocations. R600 only */271272/* DB registers. */273uint64_t db_depth_base; /* DB_Z_READ/WRITE_BASE (EG and later) or DB_DEPTH_BASE (r600) */274uint64_t db_stencil_base; /* EG and later */275uint64_t db_htile_data_base;276unsigned db_depth_info; /* R600 only, then SI and later */277unsigned db_z_info; /* EG and later */278unsigned db_depth_view;279unsigned db_depth_size;280unsigned db_depth_slice; /* EG and later */281unsigned db_stencil_info; /* EG and later */282unsigned db_prefetch_limit; /* R600 only */283unsigned db_htile_surface;284unsigned db_preload_control; /* EG and later */285};286287struct r600_mmio_counter {288unsigned busy;289unsigned idle;290};291292union r600_mmio_counters {293struct r600_mmio_counters_named {294/* For global GPU load including SDMA. */295struct r600_mmio_counter gpu;296297/* GRBM_STATUS */298struct r600_mmio_counter spi;299struct r600_mmio_counter gui;300struct r600_mmio_counter ta;301struct r600_mmio_counter gds;302struct r600_mmio_counter vgt;303struct r600_mmio_counter ia;304struct r600_mmio_counter sx;305struct r600_mmio_counter wd;306struct r600_mmio_counter bci;307struct r600_mmio_counter sc;308struct r600_mmio_counter pa;309struct r600_mmio_counter db;310struct r600_mmio_counter cp;311struct r600_mmio_counter cb;312313/* SRBM_STATUS2 */314struct r600_mmio_counter sdma;315316/* CP_STAT */317struct r600_mmio_counter pfp;318struct r600_mmio_counter meq;319struct r600_mmio_counter me;320struct r600_mmio_counter surf_sync;321struct r600_mmio_counter cp_dma;322struct r600_mmio_counter scratch_ram;323} named;324unsigned array[sizeof(struct r600_mmio_counters_named) / sizeof(unsigned)];325};326327struct r600_memory_object {328struct pipe_memory_object b;329struct pb_buffer *buf;330uint32_t stride;331uint32_t offset;332};333334struct r600_common_screen {335struct pipe_screen b;336struct radeon_winsys *ws;337enum radeon_family family;338enum chip_class chip_class;339struct radeon_info info;340uint64_t debug_flags;341bool has_cp_dma;342bool has_streamout;343344struct disk_cache *disk_shader_cache;345346struct slab_parent_pool pool_transfers;347348/* Texture filter settings. */349int force_aniso; /* -1 = disabled */350351/* Auxiliary context. Mainly used to initialize resources.352* It must be locked prior to using and flushed before unlocking. */353struct pipe_context *aux_context;354mtx_t aux_context_lock;355356/* This must be in the screen, because UE4 uses one context for357* compilation and another one for rendering.358*/359unsigned num_compilations;360/* Along with ST_DEBUG=precompile, this should show if applications361* are loading shaders on demand. This is a monotonic counter.362*/363unsigned num_shaders_created;364unsigned num_shader_cache_hits;365366/* GPU load thread. */367mtx_t gpu_load_mutex;368thrd_t gpu_load_thread;369union r600_mmio_counters mmio_counters;370volatile unsigned gpu_load_stop_thread; /* bool */371372char renderer_string[100];373374/* Performance counters. */375struct r600_perfcounters *perfcounters;376377/* If pipe_screen wants to recompute and re-emit the framebuffer,378* sampler, and image states of all contexts, it should atomically379* increment this.380*381* Each context will compare this with its own last known value of382* the counter before drawing and re-emit the states accordingly.383*/384unsigned dirty_tex_counter;385386/* Atomically increment this counter when an existing texture's387* metadata is enabled or disabled in a way that requires changing388* contexts' compressed texture binding masks.389*/390unsigned compressed_colortex_counter;391392struct {393/* Context flags to set so that all writes from earlier jobs394* in the CP are seen by L2 clients.395*/396unsigned cp_to_L2;397398/* Context flags to set so that all writes from earlier jobs399* that end in L2 are seen by CP.400*/401unsigned L2_to_cp;402403/* Context flags to set so that all writes from earlier404* compute jobs are seen by L2 clients.405*/406unsigned compute_to_L2;407} barrier_flags;408409struct nir_shader_compiler_options nir_options;410};411412/* This encapsulates a state or an operation which can emitted into the GPU413* command stream. */414struct r600_atom {415void (*emit)(struct r600_common_context *ctx, struct r600_atom *state);416unsigned num_dw;417unsigned short id;418};419420struct r600_so_target {421struct pipe_stream_output_target b;422423/* The buffer where BUFFER_FILLED_SIZE is stored. */424struct r600_resource *buf_filled_size;425unsigned buf_filled_size_offset;426bool buf_filled_size_valid;427428unsigned stride_in_dw;429};430431struct r600_streamout {432struct r600_atom begin_atom;433bool begin_emitted;434unsigned num_dw_for_end;435436unsigned enabled_mask;437unsigned num_targets;438struct r600_so_target *targets[PIPE_MAX_SO_BUFFERS];439440unsigned append_bitmask;441bool suspended;442443/* External state which comes from the vertex shader,444* it must be set explicitly when binding a shader. */445uint16_t *stride_in_dw;446unsigned enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */447448/* The state of VGT_STRMOUT_BUFFER_(CONFIG|EN). */449unsigned hw_enabled_mask;450451/* The state of VGT_STRMOUT_(CONFIG|EN). */452struct r600_atom enable_atom;453bool streamout_enabled;454bool prims_gen_query_enabled;455int num_prims_gen_queries;456};457458struct r600_signed_scissor {459int minx;460int miny;461int maxx;462int maxy;463};464465struct r600_scissors {466struct r600_atom atom;467unsigned dirty_mask;468struct pipe_scissor_state states[R600_MAX_VIEWPORTS];469};470471struct r600_viewports {472struct r600_atom atom;473unsigned dirty_mask;474unsigned depth_range_dirty_mask;475struct pipe_viewport_state states[R600_MAX_VIEWPORTS];476struct r600_signed_scissor as_scissor[R600_MAX_VIEWPORTS];477};478479struct r600_ring {480struct radeon_cmdbuf cs;481void (*flush)(void *ctx, unsigned flags,482struct pipe_fence_handle **fence);483};484485/* Saved CS data for debugging features. */486struct radeon_saved_cs {487uint32_t *ib;488unsigned num_dw;489490struct radeon_bo_list_item *bo_list;491unsigned bo_count;492};493494struct r600_common_context {495struct pipe_context b; /* base class */496497struct r600_common_screen *screen;498struct radeon_winsys *ws;499struct radeon_winsys_ctx *ctx;500enum radeon_family family;501enum chip_class chip_class;502struct r600_ring gfx;503struct r600_ring dma;504struct pipe_fence_handle *last_gfx_fence;505struct pipe_fence_handle *last_sdma_fence;506struct r600_resource *eop_bug_scratch;507unsigned num_gfx_cs_flushes;508unsigned initial_gfx_cs_size;509unsigned last_dirty_tex_counter;510unsigned last_compressed_colortex_counter;511unsigned last_num_draw_calls;512513struct threaded_context *tc;514struct u_suballocator allocator_zeroed_memory;515struct slab_child_pool pool_transfers;516struct slab_child_pool pool_transfers_unsync; /* for threaded_context */517518/* Current unaccounted memory usage. */519uint64_t vram;520uint64_t gtt;521522/* States. */523struct r600_streamout streamout;524struct r600_scissors scissors;525struct r600_viewports viewports;526bool scissor_enabled;527bool clip_halfz;528bool vs_writes_viewport_index;529bool vs_disables_clipping_viewport;530531/* Additional context states. */532unsigned flags; /* flush flags */533534/* Queries. */535/* Maintain the list of active queries for pausing between IBs. */536int num_occlusion_queries;537int num_perfect_occlusion_queries;538struct list_head active_queries;539unsigned num_cs_dw_queries_suspend;540/* Misc stats. */541unsigned num_draw_calls;542unsigned num_decompress_calls;543unsigned num_mrt_draw_calls;544unsigned num_prim_restart_calls;545unsigned num_spill_draw_calls;546unsigned num_compute_calls;547unsigned num_spill_compute_calls;548unsigned num_dma_calls;549unsigned num_cp_dma_calls;550unsigned num_vs_flushes;551unsigned num_ps_flushes;552unsigned num_cs_flushes;553unsigned num_cb_cache_flushes;554unsigned num_db_cache_flushes;555unsigned num_resident_handles;556uint64_t num_alloc_tex_transfer_bytes;557558/* Render condition. */559struct r600_atom render_cond_atom;560struct pipe_query *render_cond;561unsigned render_cond_mode;562bool render_cond_invert;563bool render_cond_force_off; /* for u_blitter */564565/* MSAA sample locations.566* The first index is the sample index.567* The second index is the coordinate: X, Y. */568float sample_locations_1x[1][2];569float sample_locations_2x[2][2];570float sample_locations_4x[4][2];571float sample_locations_8x[8][2];572float sample_locations_16x[16][2];573574struct pipe_debug_callback debug;575struct pipe_device_reset_callback device_reset_callback;576struct u_log_context *log;577578void *query_result_shader;579580/* Copy one resource to another using async DMA. */581void (*dma_copy)(struct pipe_context *ctx,582struct pipe_resource *dst,583unsigned dst_level,584unsigned dst_x, unsigned dst_y, unsigned dst_z,585struct pipe_resource *src,586unsigned src_level,587const struct pipe_box *src_box);588589void (*dma_clear_buffer)(struct pipe_context *ctx, struct pipe_resource *dst,590uint64_t offset, uint64_t size, unsigned value);591592void (*clear_buffer)(struct pipe_context *ctx, struct pipe_resource *dst,593uint64_t offset, uint64_t size, unsigned value,594enum r600_coherency coher);595596void (*blit_decompress_depth)(struct pipe_context *ctx,597struct r600_texture *texture,598struct r600_texture *staging,599unsigned first_level, unsigned last_level,600unsigned first_layer, unsigned last_layer,601unsigned first_sample, unsigned last_sample);602603/* Reallocate the buffer and update all resource bindings where604* the buffer is bound, including all resource descriptors. */605void (*invalidate_buffer)(struct pipe_context *ctx, struct pipe_resource *buf);606607/* Update all resource bindings where the buffer is bound, including608* all resource descriptors. This is invalidate_buffer without609* the invalidation. */610void (*rebind_buffer)(struct pipe_context *ctx, struct pipe_resource *buf,611uint64_t old_gpu_address);612613void (*save_qbo_state)(struct pipe_context *ctx, struct r600_qbo_state *st);614615/* This ensures there is enough space in the command stream. */616void (*need_gfx_cs_space)(struct pipe_context *ctx, unsigned num_dw,617bool include_draw_vbo);618619void (*set_atom_dirty)(struct r600_common_context *ctx,620struct r600_atom *atom, bool dirty);621622void (*check_vm_faults)(struct r600_common_context *ctx,623struct radeon_saved_cs *saved,624enum ring_type ring);625};626627/* r600_buffer_common.c */628bool r600_rings_is_buffer_referenced(struct r600_common_context *ctx,629struct pb_buffer *buf,630enum radeon_bo_usage usage);631void *r600_buffer_map_sync_with_rings(struct r600_common_context *ctx,632struct r600_resource *resource,633unsigned usage);634void r600_buffer_subdata(struct pipe_context *ctx,635struct pipe_resource *buffer,636unsigned usage, unsigned offset,637unsigned size, const void *data);638void r600_init_resource_fields(struct r600_common_screen *rscreen,639struct r600_resource *res,640uint64_t size, unsigned alignment);641bool r600_alloc_resource(struct r600_common_screen *rscreen,642struct r600_resource *res);643void r600_buffer_destroy(struct pipe_screen *screen, struct pipe_resource *buf);644void r600_buffer_flush_region(struct pipe_context *ctx,645struct pipe_transfer *transfer,646const struct pipe_box *rel_box);647struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,648const struct pipe_resource *templ,649unsigned alignment);650struct pipe_resource * r600_aligned_buffer_create(struct pipe_screen *screen,651unsigned flags,652unsigned usage,653unsigned size,654unsigned alignment);655struct pipe_resource *656r600_buffer_from_user_memory(struct pipe_screen *screen,657const struct pipe_resource *templ,658void *user_memory);659void660r600_invalidate_resource(struct pipe_context *ctx,661struct pipe_resource *resource);662void r600_replace_buffer_storage(struct pipe_context *ctx,663struct pipe_resource *dst,664struct pipe_resource *src);665void *r600_buffer_transfer_map(struct pipe_context *ctx,666struct pipe_resource *resource,667unsigned level,668unsigned usage,669const struct pipe_box *box,670struct pipe_transfer **ptransfer);671void r600_buffer_transfer_unmap(struct pipe_context *ctx,672struct pipe_transfer *transfer);673674/* r600_common_pipe.c */675void r600_gfx_write_event_eop(struct r600_common_context *ctx,676unsigned event, unsigned event_flags,677unsigned data_sel,678struct r600_resource *buf, uint64_t va,679uint32_t new_fence, unsigned query_type);680unsigned r600_gfx_write_fence_dwords(struct r600_common_screen *screen);681void r600_gfx_wait_fence(struct r600_common_context *ctx,682struct r600_resource *buf,683uint64_t va, uint32_t ref, uint32_t mask);684void r600_draw_rectangle(struct blitter_context *blitter,685void *vertex_elements_cso,686blitter_get_vs_func get_vs,687int x1, int y1, int x2, int y2,688float depth, unsigned num_instances,689enum blitter_attrib_type type,690const union blitter_attrib *attrib);691bool r600_common_screen_init(struct r600_common_screen *rscreen,692struct radeon_winsys *ws);693void r600_destroy_common_screen(struct r600_common_screen *rscreen);694void r600_preflush_suspend_features(struct r600_common_context *ctx);695void r600_postflush_resume_features(struct r600_common_context *ctx);696bool r600_common_context_init(struct r600_common_context *rctx,697struct r600_common_screen *rscreen,698unsigned context_flags);699void r600_common_context_cleanup(struct r600_common_context *rctx);700bool r600_can_dump_shader(struct r600_common_screen *rscreen,701unsigned processor);702bool r600_extra_shader_checks(struct r600_common_screen *rscreen,703unsigned processor);704void r600_screen_clear_buffer(struct r600_common_screen *rscreen, struct pipe_resource *dst,705uint64_t offset, uint64_t size, unsigned value);706struct pipe_resource *r600_resource_create_common(struct pipe_screen *screen,707const struct pipe_resource *templ);708const char *r600_get_llvm_processor_name(enum radeon_family family);709void r600_need_dma_space(struct r600_common_context *ctx, unsigned num_dw,710struct r600_resource *dst, struct r600_resource *src);711void radeon_save_cs(struct radeon_winsys *ws, struct radeon_cmdbuf *cs,712struct radeon_saved_cs *saved, bool get_buffer_list);713void radeon_clear_saved_cs(struct radeon_saved_cs *saved);714bool r600_check_device_reset(struct r600_common_context *rctx);715716/* r600_gpu_load.c */717void r600_gpu_load_kill_thread(struct r600_common_screen *rscreen);718uint64_t r600_begin_counter(struct r600_common_screen *rscreen, unsigned type);719unsigned r600_end_counter(struct r600_common_screen *rscreen, unsigned type,720uint64_t begin);721722/* r600_perfcounters.c */723void r600_perfcounters_destroy(struct r600_common_screen *rscreen);724725/* r600_query.c */726void r600_init_screen_query_functions(struct r600_common_screen *rscreen);727void r600_query_init(struct r600_common_context *rctx);728void r600_suspend_queries(struct r600_common_context *ctx);729void r600_resume_queries(struct r600_common_context *ctx);730void r600_query_fix_enabled_rb_mask(struct r600_common_screen *rscreen);731732/* r600_streamout.c */733void r600_streamout_buffers_dirty(struct r600_common_context *rctx);734void r600_set_streamout_targets(struct pipe_context *ctx,735unsigned num_targets,736struct pipe_stream_output_target **targets,737const unsigned *offset);738void r600_emit_streamout_end(struct r600_common_context *rctx);739void r600_update_prims_generated_query_state(struct r600_common_context *rctx,740unsigned type, int diff);741void r600_streamout_init(struct r600_common_context *rctx);742743/* r600_test_dma.c */744void r600_test_dma(struct r600_common_screen *rscreen);745746/* r600_texture.c */747bool r600_prepare_for_dma_blit(struct r600_common_context *rctx,748struct r600_texture *rdst,749unsigned dst_level, unsigned dstx,750unsigned dsty, unsigned dstz,751struct r600_texture *rsrc,752unsigned src_level,753const struct pipe_box *src_box);754void r600_texture_destroy(struct pipe_screen *screen, struct pipe_resource *ptex);755void r600_texture_get_fmask_info(struct r600_common_screen *rscreen,756struct r600_texture *rtex,757unsigned nr_samples,758struct r600_fmask_info *out);759void r600_texture_get_cmask_info(struct r600_common_screen *rscreen,760struct r600_texture *rtex,761struct r600_cmask_info *out);762bool r600_init_flushed_depth_texture(struct pipe_context *ctx,763struct pipe_resource *texture,764struct r600_texture **staging);765void r600_print_texture_info(struct r600_common_screen *rscreen,766struct r600_texture *rtex, struct u_log_context *log);767struct pipe_resource *r600_texture_create(struct pipe_screen *screen,768const struct pipe_resource *templ);769struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,770struct pipe_resource *texture,771const struct pipe_surface *templ,772unsigned width0, unsigned height0,773unsigned width, unsigned height);774unsigned r600_translate_colorswap(enum pipe_format format, bool do_endian_swap);775void evergreen_do_fast_color_clear(struct r600_common_context *rctx,776struct pipe_framebuffer_state *fb,777struct r600_atom *fb_state,778unsigned *buffers, ubyte *dirty_cbufs,779const union pipe_color_union *color);780void r600_init_screen_texture_functions(struct r600_common_screen *rscreen);781void r600_init_context_texture_functions(struct r600_common_context *rctx);782void eg_resource_alloc_immed(struct r600_common_screen *rscreen,783struct r600_resource *res,784unsigned immed_size);785void *r600_texture_transfer_map(struct pipe_context *ctx,786struct pipe_resource *texture,787unsigned level,788unsigned usage,789const struct pipe_box *box,790struct pipe_transfer **ptransfer);791void r600_texture_transfer_unmap(struct pipe_context *ctx,792struct pipe_transfer* transfer);793794/* r600_viewport.c */795void evergreen_apply_scissor_bug_workaround(struct r600_common_context *rctx,796struct pipe_scissor_state *scissor);797void r600_viewport_set_rast_deps(struct r600_common_context *rctx,798bool scissor_enable, bool clip_halfz);799void r600_update_vs_writes_viewport_index(struct r600_common_context *rctx,800struct tgsi_shader_info *info);801void r600_init_viewport_functions(struct r600_common_context *rctx);802803/* cayman_msaa.c */804extern const uint32_t eg_sample_locs_2x[4];805extern const unsigned eg_max_dist_2x;806extern const uint32_t eg_sample_locs_4x[4];807extern const unsigned eg_max_dist_4x;808void cayman_get_sample_position(struct pipe_context *ctx, unsigned sample_count,809unsigned sample_index, float *out_value);810void cayman_init_msaa(struct pipe_context *ctx);811void cayman_emit_msaa_state(struct radeon_cmdbuf *cs, int nr_samples,812int ps_iter_samples, int overrast_samples);813814815/* Inline helpers. */816817static inline struct r600_resource *r600_resource(struct pipe_resource *r)818{819return (struct r600_resource*)r;820}821822static inline void823r600_resource_reference(struct r600_resource **ptr, struct r600_resource *res)824{825pipe_resource_reference((struct pipe_resource **)ptr,826(struct pipe_resource *)res);827}828829static inline void830r600_texture_reference(struct r600_texture **ptr, struct r600_texture *res)831{832pipe_resource_reference((struct pipe_resource **)ptr, &res->resource.b.b);833}834835static inline void836r600_context_add_resource_size(struct pipe_context *ctx, struct pipe_resource *r)837{838struct r600_common_context *rctx = (struct r600_common_context *)ctx;839struct r600_resource *res = (struct r600_resource *)r;840841if (res) {842/* Add memory usage for need_gfx_cs_space */843rctx->vram += res->vram_usage;844rctx->gtt += res->gart_usage;845}846}847848static inline bool r600_get_strmout_en(struct r600_common_context *rctx)849{850return rctx->streamout.streamout_enabled ||851rctx->streamout.prims_gen_query_enabled;852}853854#define SQ_TEX_XY_FILTER_POINT 0x00855#define SQ_TEX_XY_FILTER_BILINEAR 0x01856#define SQ_TEX_XY_FILTER_ANISO_POINT 0x02857#define SQ_TEX_XY_FILTER_ANISO_BILINEAR 0x03858859static inline unsigned eg_tex_filter(unsigned filter, unsigned max_aniso)860{861if (filter == PIPE_TEX_FILTER_LINEAR)862return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_BILINEAR863: SQ_TEX_XY_FILTER_BILINEAR;864else865return max_aniso > 1 ? SQ_TEX_XY_FILTER_ANISO_POINT866: SQ_TEX_XY_FILTER_POINT;867}868869static inline unsigned r600_tex_aniso_filter(unsigned filter)870{871if (filter < 2)872return 0;873if (filter < 4)874return 1;875if (filter < 8)876return 2;877if (filter < 16)878return 3;879return 4;880}881882static inline unsigned r600_wavefront_size(enum radeon_family family)883{884switch (family) {885case CHIP_RV610:886case CHIP_RS780:887case CHIP_RV620:888case CHIP_RS880:889return 16;890case CHIP_RV630:891case CHIP_RV635:892case CHIP_RV730:893case CHIP_RV710:894case CHIP_PALM:895case CHIP_CEDAR:896return 32;897default:898return 64;899}900}901902static inline enum radeon_bo_priority903r600_get_sampler_view_priority(struct r600_resource *res)904{905if (res->b.b.target == PIPE_BUFFER)906return RADEON_PRIO_SAMPLER_BUFFER;907908if (res->b.b.nr_samples > 1)909return RADEON_PRIO_SAMPLER_TEXTURE_MSAA;910911return RADEON_PRIO_SAMPLER_TEXTURE;912}913914static inline bool915r600_can_sample_zs(struct r600_texture *tex, bool stencil_sampler)916{917return (stencil_sampler && tex->can_sample_s) ||918(!stencil_sampler && tex->can_sample_z);919}920921static inline bool922r600_htile_enabled(struct r600_texture *tex, unsigned level)923{924return tex->htile_offset && level == 0;925}926927#define COMPUTE_DBG(rscreen, fmt, args...) \928do { \929if ((rscreen->b.debug_flags & DBG_COMPUTE)) fprintf(stderr, fmt, ##args); \930} while (0);931932#define R600_ERR(fmt, args...) \933fprintf(stderr, "EE %s:%d %s - " fmt, __FILE__, __LINE__, __func__, ##args)934935/* For MSAA sample positions. */936#define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y) \937(((s0x) & 0xf) | (((unsigned)(s0y) & 0xf) << 4) | \938(((unsigned)(s1x) & 0xf) << 8) | (((unsigned)(s1y) & 0xf) << 12) | \939(((unsigned)(s2x) & 0xf) << 16) | (((unsigned)(s2y) & 0xf) << 20) | \940(((unsigned)(s3x) & 0xf) << 24) | (((unsigned)(s3y) & 0xf) << 28))941942static inline int S_FIXED(float value, unsigned frac_bits)943{944return value * (1 << frac_bits);945}946947#endif948949950