Path: blob/21.2-virgl/src/gallium/drivers/r600/r600_pipe_common.c
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#include "r600_pipe_common.h"27#include "r600_cs.h"28#include "evergreen_compute.h"29#include "tgsi/tgsi_parse.h"30#include "util/list.h"31#include "util/u_draw_quad.h"32#include "util/u_memory.h"33#include "util/format/u_format_s3tc.h"34#include "util/u_upload_mgr.h"35#include "util/os_time.h"36#include "vl/vl_decoder.h"37#include "vl/vl_video_buffer.h"38#include "radeon_video.h"39#include <inttypes.h>40#include <sys/utsname.h>41#include <stdlib.h>4243#ifdef LLVM_AVAILABLE44#include <llvm-c/TargetMachine.h>45#endif4647struct r600_multi_fence {48struct pipe_reference reference;49struct pipe_fence_handle *gfx;50struct pipe_fence_handle *sdma;5152/* If the context wasn't flushed at fence creation, this is non-NULL. */53struct {54struct r600_common_context *ctx;55unsigned ib_index;56} gfx_unflushed;57};5859/*60* pipe_context61*/6263/**64* Write an EOP event.65*66* \param event EVENT_TYPE_*67* \param event_flags Optional cache flush flags (TC)68* \param data_sel 1 = fence, 3 = timestamp69* \param buf Buffer70* \param va GPU address71* \param old_value Previous fence value (for a bug workaround)72* \param new_value Fence value to write for this event.73*/74void r600_gfx_write_event_eop(struct r600_common_context *ctx,75unsigned event, unsigned event_flags,76unsigned data_sel,77struct r600_resource *buf, uint64_t va,78uint32_t new_fence, unsigned query_type)79{80struct radeon_cmdbuf *cs = &ctx->gfx.cs;81unsigned op = EVENT_TYPE(event) |82EVENT_INDEX(5) |83event_flags;84unsigned sel = EOP_DATA_SEL(data_sel);8586radeon_emit(cs, PKT3(PKT3_EVENT_WRITE_EOP, 4, 0));87radeon_emit(cs, op);88radeon_emit(cs, va);89radeon_emit(cs, ((va >> 32) & 0xffff) | sel);90radeon_emit(cs, new_fence); /* immediate data */91radeon_emit(cs, 0); /* unused */9293if (buf)94r600_emit_reloc(ctx, &ctx->gfx, buf, RADEON_USAGE_WRITE,95RADEON_PRIO_QUERY);96}9798unsigned r600_gfx_write_fence_dwords(struct r600_common_screen *screen)99{100unsigned dwords = 6;101102if (!screen->info.r600_has_virtual_memory)103dwords += 2;104105return dwords;106}107108void r600_gfx_wait_fence(struct r600_common_context *ctx,109struct r600_resource *buf,110uint64_t va, uint32_t ref, uint32_t mask)111{112struct radeon_cmdbuf *cs = &ctx->gfx.cs;113114radeon_emit(cs, PKT3(PKT3_WAIT_REG_MEM, 5, 0));115radeon_emit(cs, WAIT_REG_MEM_EQUAL | WAIT_REG_MEM_MEM_SPACE(1));116radeon_emit(cs, va);117radeon_emit(cs, va >> 32);118radeon_emit(cs, ref); /* reference value */119radeon_emit(cs, mask); /* mask */120radeon_emit(cs, 4); /* poll interval */121122if (buf)123r600_emit_reloc(ctx, &ctx->gfx, buf, RADEON_USAGE_READ,124RADEON_PRIO_QUERY);125}126127void r600_draw_rectangle(struct blitter_context *blitter,128void *vertex_elements_cso,129blitter_get_vs_func get_vs,130int x1, int y1, int x2, int y2,131float depth, unsigned num_instances,132enum blitter_attrib_type type,133const union blitter_attrib *attrib)134{135struct r600_common_context *rctx =136(struct r600_common_context*)util_blitter_get_pipe(blitter);137struct pipe_viewport_state viewport;138struct pipe_resource *buf = NULL;139unsigned offset = 0;140float *vb;141142rctx->b.bind_vertex_elements_state(&rctx->b, vertex_elements_cso);143rctx->b.bind_vs_state(&rctx->b, get_vs(blitter));144145/* Some operations (like color resolve on r6xx) don't work146* with the conventional primitive types.147* One that works is PT_RECTLIST, which we use here. */148149/* setup viewport */150viewport.scale[0] = 1.0f;151viewport.scale[1] = 1.0f;152viewport.scale[2] = 1.0f;153viewport.translate[0] = 0.0f;154viewport.translate[1] = 0.0f;155viewport.translate[2] = 0.0f;156rctx->b.set_viewport_states(&rctx->b, 0, 1, &viewport);157158/* Upload vertices. The hw rectangle has only 3 vertices,159* The 4th one is derived from the first 3.160* The vertex specification should match u_blitter's vertex element state. */161u_upload_alloc(rctx->b.stream_uploader, 0, sizeof(float) * 24,162rctx->screen->info.tcc_cache_line_size,163&offset, &buf, (void**)&vb);164if (!buf)165return;166167vb[0] = x1;168vb[1] = y1;169vb[2] = depth;170vb[3] = 1;171172vb[8] = x1;173vb[9] = y2;174vb[10] = depth;175vb[11] = 1;176177vb[16] = x2;178vb[17] = y1;179vb[18] = depth;180vb[19] = 1;181182switch (type) {183case UTIL_BLITTER_ATTRIB_COLOR:184memcpy(vb+4, attrib->color, sizeof(float)*4);185memcpy(vb+12, attrib->color, sizeof(float)*4);186memcpy(vb+20, attrib->color, sizeof(float)*4);187break;188case UTIL_BLITTER_ATTRIB_TEXCOORD_XYZW:189case UTIL_BLITTER_ATTRIB_TEXCOORD_XY:190vb[6] = vb[14] = vb[22] = attrib->texcoord.z;191vb[7] = vb[15] = vb[23] = attrib->texcoord.w;192/* fall through */193vb[4] = attrib->texcoord.x1;194vb[5] = attrib->texcoord.y1;195vb[12] = attrib->texcoord.x1;196vb[13] = attrib->texcoord.y2;197vb[20] = attrib->texcoord.x2;198vb[21] = attrib->texcoord.y1;199break;200default:; /* Nothing to do. */201}202203/* draw */204struct pipe_vertex_buffer vbuffer = {};205vbuffer.buffer.resource = buf;206vbuffer.stride = 2 * 4 * sizeof(float); /* vertex size */207vbuffer.buffer_offset = offset;208209rctx->b.set_vertex_buffers(&rctx->b, blitter->vb_slot, 1, 0, false, &vbuffer);210util_draw_arrays_instanced(&rctx->b, R600_PRIM_RECTANGLE_LIST, 0, 3,2110, num_instances);212pipe_resource_reference(&buf, NULL);213}214215static void r600_dma_emit_wait_idle(struct r600_common_context *rctx)216{217struct radeon_cmdbuf *cs = &rctx->dma.cs;218219if (rctx->chip_class >= EVERGREEN)220radeon_emit(cs, 0xf0000000); /* NOP */221else {222/* TODO: R600-R700 should use the FENCE packet.223* CS checker support is required. */224}225}226227void r600_need_dma_space(struct r600_common_context *ctx, unsigned num_dw,228struct r600_resource *dst, struct r600_resource *src)229{230uint64_t vram = (uint64_t)ctx->dma.cs.used_vram_kb * 1024;231uint64_t gtt = (uint64_t)ctx->dma.cs.used_gart_kb * 1024;232233if (dst) {234vram += dst->vram_usage;235gtt += dst->gart_usage;236}237if (src) {238vram += src->vram_usage;239gtt += src->gart_usage;240}241242/* Flush the GFX IB if DMA depends on it. */243if (radeon_emitted(&ctx->gfx.cs, ctx->initial_gfx_cs_size) &&244((dst &&245ctx->ws->cs_is_buffer_referenced(&ctx->gfx.cs, dst->buf,246RADEON_USAGE_READWRITE)) ||247(src &&248ctx->ws->cs_is_buffer_referenced(&ctx->gfx.cs, src->buf,249RADEON_USAGE_WRITE))))250ctx->gfx.flush(ctx, PIPE_FLUSH_ASYNC, NULL);251252/* Flush if there's not enough space, or if the memory usage per IB253* is too large.254*255* IBs using too little memory are limited by the IB submission overhead.256* IBs using too much memory are limited by the kernel/TTM overhead.257* Too long IBs create CPU-GPU pipeline bubbles and add latency.258*259* This heuristic makes sure that DMA requests are executed260* very soon after the call is made and lowers memory usage.261* It improves texture upload performance by keeping the DMA262* engine busy while uploads are being submitted.263*/264num_dw++; /* for emit_wait_idle below */265if (!ctx->ws->cs_check_space(&ctx->dma.cs, num_dw, false) ||266ctx->dma.cs.used_vram_kb + ctx->dma.cs.used_gart_kb > 64 * 1024 ||267!radeon_cs_memory_below_limit(ctx->screen, &ctx->dma.cs, vram, gtt)) {268ctx->dma.flush(ctx, PIPE_FLUSH_ASYNC, NULL);269assert((num_dw + ctx->dma.cs.current.cdw) <= ctx->dma.cs.current.max_dw);270}271272/* Wait for idle if either buffer has been used in the IB before to273* prevent read-after-write hazards.274*/275if ((dst &&276ctx->ws->cs_is_buffer_referenced(&ctx->dma.cs, dst->buf,277RADEON_USAGE_READWRITE)) ||278(src &&279ctx->ws->cs_is_buffer_referenced(&ctx->dma.cs, src->buf,280RADEON_USAGE_WRITE)))281r600_dma_emit_wait_idle(ctx);282283/* If GPUVM is not supported, the CS checker needs 2 entries284* in the buffer list per packet, which has to be done manually.285*/286if (ctx->screen->info.r600_has_virtual_memory) {287if (dst)288radeon_add_to_buffer_list(ctx, &ctx->dma, dst,289RADEON_USAGE_WRITE, 0);290if (src)291radeon_add_to_buffer_list(ctx, &ctx->dma, src,292RADEON_USAGE_READ, 0);293}294295/* this function is called before all DMA calls, so increment this. */296ctx->num_dma_calls++;297}298299void r600_preflush_suspend_features(struct r600_common_context *ctx)300{301/* suspend queries */302if (!list_is_empty(&ctx->active_queries))303r600_suspend_queries(ctx);304305ctx->streamout.suspended = false;306if (ctx->streamout.begin_emitted) {307r600_emit_streamout_end(ctx);308ctx->streamout.suspended = true;309}310}311312void r600_postflush_resume_features(struct r600_common_context *ctx)313{314if (ctx->streamout.suspended) {315ctx->streamout.append_bitmask = ctx->streamout.enabled_mask;316r600_streamout_buffers_dirty(ctx);317}318319/* resume queries */320if (!list_is_empty(&ctx->active_queries))321r600_resume_queries(ctx);322}323324static void r600_fence_server_sync(struct pipe_context *ctx,325struct pipe_fence_handle *fence)326{327/* radeon synchronizes all rings by default and will not implement328* fence imports.329*/330}331332static void r600_flush_from_st(struct pipe_context *ctx,333struct pipe_fence_handle **fence,334unsigned flags)335{336struct pipe_screen *screen = ctx->screen;337struct r600_common_context *rctx = (struct r600_common_context *)ctx;338struct radeon_winsys *ws = rctx->ws;339struct pipe_fence_handle *gfx_fence = NULL;340struct pipe_fence_handle *sdma_fence = NULL;341bool deferred_fence = false;342unsigned rflags = PIPE_FLUSH_ASYNC;343344if (flags & PIPE_FLUSH_END_OF_FRAME)345rflags |= PIPE_FLUSH_END_OF_FRAME;346347/* DMA IBs are preambles to gfx IBs, therefore must be flushed first. */348if (rctx->dma.cs.priv)349rctx->dma.flush(rctx, rflags, fence ? &sdma_fence : NULL);350351if (!radeon_emitted(&rctx->gfx.cs, rctx->initial_gfx_cs_size)) {352if (fence)353ws->fence_reference(&gfx_fence, rctx->last_gfx_fence);354if (!(flags & PIPE_FLUSH_DEFERRED))355ws->cs_sync_flush(&rctx->gfx.cs);356} else {357/* Instead of flushing, create a deferred fence. Constraints:358* - the gallium frontend must allow a deferred flush.359* - the gallium frontend must request a fence.360* Thread safety in fence_finish must be ensured by the gallium frontend.361*/362if (flags & PIPE_FLUSH_DEFERRED && fence) {363gfx_fence = rctx->ws->cs_get_next_fence(&rctx->gfx.cs);364deferred_fence = true;365} else {366rctx->gfx.flush(rctx, rflags, fence ? &gfx_fence : NULL);367}368}369370/* Both engines can signal out of order, so we need to keep both fences. */371if (fence) {372struct r600_multi_fence *multi_fence =373CALLOC_STRUCT(r600_multi_fence);374if (!multi_fence) {375ws->fence_reference(&sdma_fence, NULL);376ws->fence_reference(&gfx_fence, NULL);377goto finish;378}379380multi_fence->reference.count = 1;381/* If both fences are NULL, fence_finish will always return true. */382multi_fence->gfx = gfx_fence;383multi_fence->sdma = sdma_fence;384385if (deferred_fence) {386multi_fence->gfx_unflushed.ctx = rctx;387multi_fence->gfx_unflushed.ib_index = rctx->num_gfx_cs_flushes;388}389390screen->fence_reference(screen, fence, NULL);391*fence = (struct pipe_fence_handle*)multi_fence;392}393finish:394if (!(flags & PIPE_FLUSH_DEFERRED)) {395if (rctx->dma.cs.priv)396ws->cs_sync_flush(&rctx->dma.cs);397ws->cs_sync_flush(&rctx->gfx.cs);398}399}400401static void r600_flush_dma_ring(void *ctx, unsigned flags,402struct pipe_fence_handle **fence)403{404struct r600_common_context *rctx = (struct r600_common_context *)ctx;405struct radeon_cmdbuf *cs = &rctx->dma.cs;406struct radeon_saved_cs saved;407bool check_vm =408(rctx->screen->debug_flags & DBG_CHECK_VM) &&409rctx->check_vm_faults;410411if (!radeon_emitted(cs, 0)) {412if (fence)413rctx->ws->fence_reference(fence, rctx->last_sdma_fence);414return;415}416417if (check_vm)418radeon_save_cs(rctx->ws, cs, &saved, true);419420rctx->ws->cs_flush(cs, flags, &rctx->last_sdma_fence);421if (fence)422rctx->ws->fence_reference(fence, rctx->last_sdma_fence);423424if (check_vm) {425/* Use conservative timeout 800ms, after which we won't wait any426* longer and assume the GPU is hung.427*/428rctx->ws->fence_wait(rctx->ws, rctx->last_sdma_fence, 800*1000*1000);429430rctx->check_vm_faults(rctx, &saved, RING_DMA);431radeon_clear_saved_cs(&saved);432}433}434435/**436* Store a linearized copy of all chunks of \p cs together with the buffer437* list in \p saved.438*/439void radeon_save_cs(struct radeon_winsys *ws, struct radeon_cmdbuf *cs,440struct radeon_saved_cs *saved, bool get_buffer_list)441{442uint32_t *buf;443unsigned i;444445/* Save the IB chunks. */446saved->num_dw = cs->prev_dw + cs->current.cdw;447saved->ib = MALLOC(4 * saved->num_dw);448if (!saved->ib)449goto oom;450451buf = saved->ib;452for (i = 0; i < cs->num_prev; ++i) {453memcpy(buf, cs->prev[i].buf, cs->prev[i].cdw * 4);454buf += cs->prev[i].cdw;455}456memcpy(buf, cs->current.buf, cs->current.cdw * 4);457458if (!get_buffer_list)459return;460461/* Save the buffer list. */462saved->bo_count = ws->cs_get_buffer_list(cs, NULL);463saved->bo_list = CALLOC(saved->bo_count,464sizeof(saved->bo_list[0]));465if (!saved->bo_list) {466FREE(saved->ib);467goto oom;468}469ws->cs_get_buffer_list(cs, saved->bo_list);470471return;472473oom:474fprintf(stderr, "%s: out of memory\n", __func__);475memset(saved, 0, sizeof(*saved));476}477478void radeon_clear_saved_cs(struct radeon_saved_cs *saved)479{480FREE(saved->ib);481FREE(saved->bo_list);482483memset(saved, 0, sizeof(*saved));484}485486static enum pipe_reset_status r600_get_reset_status(struct pipe_context *ctx)487{488struct r600_common_context *rctx = (struct r600_common_context *)ctx;489490return rctx->ws->ctx_query_reset_status(rctx->ctx, false, NULL);491}492493static void r600_set_debug_callback(struct pipe_context *ctx,494const struct pipe_debug_callback *cb)495{496struct r600_common_context *rctx = (struct r600_common_context *)ctx;497498if (cb)499rctx->debug = *cb;500else501memset(&rctx->debug, 0, sizeof(rctx->debug));502}503504static void r600_set_device_reset_callback(struct pipe_context *ctx,505const struct pipe_device_reset_callback *cb)506{507struct r600_common_context *rctx = (struct r600_common_context *)ctx;508509if (cb)510rctx->device_reset_callback = *cb;511else512memset(&rctx->device_reset_callback, 0,513sizeof(rctx->device_reset_callback));514}515516bool r600_check_device_reset(struct r600_common_context *rctx)517{518enum pipe_reset_status status;519520if (!rctx->device_reset_callback.reset)521return false;522523if (!rctx->b.get_device_reset_status)524return false;525526status = rctx->b.get_device_reset_status(&rctx->b);527if (status == PIPE_NO_RESET)528return false;529530rctx->device_reset_callback.reset(rctx->device_reset_callback.data, status);531return true;532}533534static void r600_dma_clear_buffer_fallback(struct pipe_context *ctx,535struct pipe_resource *dst,536uint64_t offset, uint64_t size,537unsigned value)538{539struct r600_common_context *rctx = (struct r600_common_context *)ctx;540541rctx->clear_buffer(ctx, dst, offset, size, value, R600_COHERENCY_NONE);542}543544static bool r600_resource_commit(struct pipe_context *pctx,545struct pipe_resource *resource,546unsigned level, struct pipe_box *box,547bool commit)548{549struct r600_common_context *ctx = (struct r600_common_context *)pctx;550struct r600_resource *res = r600_resource(resource);551552/*553* Since buffer commitment changes cannot be pipelined, we need to554* (a) flush any pending commands that refer to the buffer we're about555* to change, and556* (b) wait for threaded submit to finish, including those that were557* triggered by some other, earlier operation.558*/559if (radeon_emitted(&ctx->gfx.cs, ctx->initial_gfx_cs_size) &&560ctx->ws->cs_is_buffer_referenced(&ctx->gfx.cs,561res->buf, RADEON_USAGE_READWRITE)) {562ctx->gfx.flush(ctx, PIPE_FLUSH_ASYNC, NULL);563}564if (radeon_emitted(&ctx->dma.cs, 0) &&565ctx->ws->cs_is_buffer_referenced(&ctx->dma.cs,566res->buf, RADEON_USAGE_READWRITE)) {567ctx->dma.flush(ctx, PIPE_FLUSH_ASYNC, NULL);568}569570ctx->ws->cs_sync_flush(&ctx->dma.cs);571ctx->ws->cs_sync_flush(&ctx->gfx.cs);572573assert(resource->target == PIPE_BUFFER);574575return ctx->ws->buffer_commit(ctx->ws, res->buf, box->x, box->width, commit);576}577578bool r600_common_context_init(struct r600_common_context *rctx,579struct r600_common_screen *rscreen,580unsigned context_flags)581{582slab_create_child(&rctx->pool_transfers, &rscreen->pool_transfers);583slab_create_child(&rctx->pool_transfers_unsync, &rscreen->pool_transfers);584585rctx->screen = rscreen;586rctx->ws = rscreen->ws;587rctx->family = rscreen->family;588rctx->chip_class = rscreen->chip_class;589590rctx->b.invalidate_resource = r600_invalidate_resource;591rctx->b.resource_commit = r600_resource_commit;592rctx->b.buffer_map = r600_buffer_transfer_map;593rctx->b.texture_map = r600_texture_transfer_map;594rctx->b.transfer_flush_region = r600_buffer_flush_region;595rctx->b.buffer_unmap = r600_buffer_transfer_unmap;596rctx->b.texture_unmap = r600_texture_transfer_unmap;597rctx->b.texture_subdata = u_default_texture_subdata;598rctx->b.flush = r600_flush_from_st;599rctx->b.set_debug_callback = r600_set_debug_callback;600rctx->b.fence_server_sync = r600_fence_server_sync;601rctx->dma_clear_buffer = r600_dma_clear_buffer_fallback;602603/* evergreen_compute.c has a special codepath for global buffers.604* Everything else can use the direct path.605*/606if ((rscreen->chip_class == EVERGREEN || rscreen->chip_class == CAYMAN) &&607(context_flags & PIPE_CONTEXT_COMPUTE_ONLY))608rctx->b.buffer_subdata = u_default_buffer_subdata;609else610rctx->b.buffer_subdata = r600_buffer_subdata;611612rctx->b.get_device_reset_status = r600_get_reset_status;613rctx->b.set_device_reset_callback = r600_set_device_reset_callback;614615r600_init_context_texture_functions(rctx);616r600_init_viewport_functions(rctx);617r600_streamout_init(rctx);618r600_query_init(rctx);619cayman_init_msaa(&rctx->b);620621u_suballocator_init(&rctx->allocator_zeroed_memory, &rctx->b, rscreen->info.gart_page_size,6220, PIPE_USAGE_DEFAULT, 0, true);623624rctx->b.stream_uploader = u_upload_create(&rctx->b, 1024 * 1024,6250, PIPE_USAGE_STREAM, 0);626if (!rctx->b.stream_uploader)627return false;628629rctx->b.const_uploader = u_upload_create(&rctx->b, 128 * 1024,6300, PIPE_USAGE_DEFAULT, 0);631if (!rctx->b.const_uploader)632return false;633634rctx->ctx = rctx->ws->ctx_create(rctx->ws);635if (!rctx->ctx)636return false;637638if (rscreen->info.num_rings[RING_DMA] && !(rscreen->debug_flags & DBG_NO_ASYNC_DMA)) {639rctx->ws->cs_create(&rctx->dma.cs, rctx->ctx, RING_DMA,640r600_flush_dma_ring, rctx, false);641rctx->dma.flush = r600_flush_dma_ring;642}643644return true;645}646647void r600_common_context_cleanup(struct r600_common_context *rctx)648{649if (rctx->query_result_shader)650rctx->b.delete_compute_state(&rctx->b, rctx->query_result_shader);651652rctx->ws->cs_destroy(&rctx->gfx.cs);653rctx->ws->cs_destroy(&rctx->dma.cs);654if (rctx->ctx)655rctx->ws->ctx_destroy(rctx->ctx);656657if (rctx->b.stream_uploader)658u_upload_destroy(rctx->b.stream_uploader);659if (rctx->b.const_uploader)660u_upload_destroy(rctx->b.const_uploader);661662slab_destroy_child(&rctx->pool_transfers);663slab_destroy_child(&rctx->pool_transfers_unsync);664665u_suballocator_destroy(&rctx->allocator_zeroed_memory);666rctx->ws->fence_reference(&rctx->last_gfx_fence, NULL);667rctx->ws->fence_reference(&rctx->last_sdma_fence, NULL);668r600_resource_reference(&rctx->eop_bug_scratch, NULL);669}670671/*672* pipe_screen673*/674675static const struct debug_named_value common_debug_options[] = {676/* logging */677{ "tex", DBG_TEX, "Print texture info" },678{ "nir", DBG_NIR, "Enable experimental NIR shaders" },679{ "compute", DBG_COMPUTE, "Print compute info" },680{ "vm", DBG_VM, "Print virtual addresses when creating resources" },681{ "info", DBG_INFO, "Print driver information" },682683/* shaders */684{ "fs", DBG_FS, "Print fetch shaders" },685{ "vs", DBG_VS, "Print vertex shaders" },686{ "gs", DBG_GS, "Print geometry shaders" },687{ "ps", DBG_PS, "Print pixel shaders" },688{ "cs", DBG_CS, "Print compute shaders" },689{ "tcs", DBG_TCS, "Print tessellation control shaders" },690{ "tes", DBG_TES, "Print tessellation evaluation shaders" },691{ "noir", DBG_NO_IR, "Don't print the LLVM IR"},692{ "notgsi", DBG_NO_TGSI, "Don't print the TGSI"},693{ "noasm", DBG_NO_ASM, "Don't print disassembled shaders"},694{ "preoptir", DBG_PREOPT_IR, "Print the LLVM IR before initial optimizations" },695{ "checkir", DBG_CHECK_IR, "Enable additional sanity checks on shader IR" },696{ "nooptvariant", DBG_NO_OPT_VARIANT, "Disable compiling optimized shader variants." },697698{ "testdma", DBG_TEST_DMA, "Invoke SDMA tests and exit." },699{ "testvmfaultcp", DBG_TEST_VMFAULT_CP, "Invoke a CP VM fault test and exit." },700{ "testvmfaultsdma", DBG_TEST_VMFAULT_SDMA, "Invoke a SDMA VM fault test and exit." },701{ "testvmfaultshader", DBG_TEST_VMFAULT_SHADER, "Invoke a shader VM fault test and exit." },702703/* features */704{ "nodma", DBG_NO_ASYNC_DMA, "Disable asynchronous DMA" },705{ "nohyperz", DBG_NO_HYPERZ, "Disable Hyper-Z" },706/* GL uses the word INVALIDATE, gallium uses the word DISCARD */707{ "noinvalrange", DBG_NO_DISCARD_RANGE, "Disable handling of INVALIDATE_RANGE map flags" },708{ "no2d", DBG_NO_2D_TILING, "Disable 2D tiling" },709{ "notiling", DBG_NO_TILING, "Disable tiling" },710{ "switch_on_eop", DBG_SWITCH_ON_EOP, "Program WD/IA to switch on end-of-packet." },711{ "forcedma", DBG_FORCE_DMA, "Use asynchronous DMA for all operations when possible." },712{ "precompile", DBG_PRECOMPILE, "Compile one shader variant at shader creation." },713{ "nowc", DBG_NO_WC, "Disable GTT write combining" },714{ "check_vm", DBG_CHECK_VM, "Check VM faults and dump debug info." },715{ "unsafemath", DBG_UNSAFE_MATH, "Enable unsafe math shader optimizations" },716717DEBUG_NAMED_VALUE_END /* must be last */718};719720static const char* r600_get_vendor(struct pipe_screen* pscreen)721{722return "X.Org";723}724725static const char* r600_get_device_vendor(struct pipe_screen* pscreen)726{727return "AMD";728}729730static const char *r600_get_family_name(const struct r600_common_screen *rscreen)731{732switch (rscreen->info.family) {733case CHIP_R600: return "AMD R600";734case CHIP_RV610: return "AMD RV610";735case CHIP_RV630: return "AMD RV630";736case CHIP_RV670: return "AMD RV670";737case CHIP_RV620: return "AMD RV620";738case CHIP_RV635: return "AMD RV635";739case CHIP_RS780: return "AMD RS780";740case CHIP_RS880: return "AMD RS880";741case CHIP_RV770: return "AMD RV770";742case CHIP_RV730: return "AMD RV730";743case CHIP_RV710: return "AMD RV710";744case CHIP_RV740: return "AMD RV740";745case CHIP_CEDAR: return "AMD CEDAR";746case CHIP_REDWOOD: return "AMD REDWOOD";747case CHIP_JUNIPER: return "AMD JUNIPER";748case CHIP_CYPRESS: return "AMD CYPRESS";749case CHIP_HEMLOCK: return "AMD HEMLOCK";750case CHIP_PALM: return "AMD PALM";751case CHIP_SUMO: return "AMD SUMO";752case CHIP_SUMO2: return "AMD SUMO2";753case CHIP_BARTS: return "AMD BARTS";754case CHIP_TURKS: return "AMD TURKS";755case CHIP_CAICOS: return "AMD CAICOS";756case CHIP_CAYMAN: return "AMD CAYMAN";757case CHIP_ARUBA: return "AMD ARUBA";758default: return "AMD unknown";759}760}761762static void r600_disk_cache_create(struct r600_common_screen *rscreen)763{764/* Don't use the cache if shader dumping is enabled. */765if (rscreen->debug_flags & DBG_ALL_SHADERS)766return;767768struct mesa_sha1 ctx;769unsigned char sha1[20];770char cache_id[20 * 2 + 1];771772_mesa_sha1_init(&ctx);773if (!disk_cache_get_function_identifier(r600_disk_cache_create,774&ctx))775return;776777_mesa_sha1_final(&ctx, sha1);778disk_cache_format_hex_id(cache_id, sha1, 20 * 2);779780/* These flags affect shader compilation. */781uint64_t shader_debug_flags =782rscreen->debug_flags &783(DBG_FS_CORRECT_DERIVS_AFTER_KILL |784DBG_UNSAFE_MATH);785786rscreen->disk_shader_cache =787disk_cache_create(r600_get_family_name(rscreen),788cache_id,789shader_debug_flags);790}791792static struct disk_cache *r600_get_disk_shader_cache(struct pipe_screen *pscreen)793{794struct r600_common_screen *rscreen = (struct r600_common_screen*)pscreen;795return rscreen->disk_shader_cache;796}797798static const char* r600_get_name(struct pipe_screen* pscreen)799{800struct r600_common_screen *rscreen = (struct r600_common_screen*)pscreen;801802return rscreen->renderer_string;803}804805static float r600_get_paramf(struct pipe_screen* pscreen,806enum pipe_capf param)807{808switch (param) {809case PIPE_CAPF_MAX_LINE_WIDTH:810case PIPE_CAPF_MAX_LINE_WIDTH_AA:811case PIPE_CAPF_MAX_POINT_WIDTH:812case PIPE_CAPF_MAX_POINT_WIDTH_AA:813return 8191.0f;814case PIPE_CAPF_MAX_TEXTURE_ANISOTROPY:815return 16.0f;816case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:817return 16.0f;818case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:819case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:820case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:821return 0.0f;822}823return 0.0f;824}825826static int r600_get_video_param(struct pipe_screen *screen,827enum pipe_video_profile profile,828enum pipe_video_entrypoint entrypoint,829enum pipe_video_cap param)830{831switch (param) {832case PIPE_VIDEO_CAP_SUPPORTED:833return vl_profile_supported(screen, profile, entrypoint);834case PIPE_VIDEO_CAP_NPOT_TEXTURES:835return 1;836case PIPE_VIDEO_CAP_MAX_WIDTH:837case PIPE_VIDEO_CAP_MAX_HEIGHT:838return vl_video_buffer_max_size(screen);839case PIPE_VIDEO_CAP_PREFERED_FORMAT:840return PIPE_FORMAT_NV12;841case PIPE_VIDEO_CAP_PREFERS_INTERLACED:842return false;843case PIPE_VIDEO_CAP_SUPPORTS_INTERLACED:844return false;845case PIPE_VIDEO_CAP_SUPPORTS_PROGRESSIVE:846return true;847case PIPE_VIDEO_CAP_MAX_LEVEL:848return vl_level_supported(screen, profile);849default:850return 0;851}852}853854const char *r600_get_llvm_processor_name(enum radeon_family family)855{856switch (family) {857case CHIP_R600:858case CHIP_RV630:859case CHIP_RV635:860case CHIP_RV670:861return "r600";862case CHIP_RV610:863case CHIP_RV620:864case CHIP_RS780:865case CHIP_RS880:866return "rs880";867case CHIP_RV710:868return "rv710";869case CHIP_RV730:870return "rv730";871case CHIP_RV740:872case CHIP_RV770:873return "rv770";874case CHIP_PALM:875case CHIP_CEDAR:876return "cedar";877case CHIP_SUMO:878case CHIP_SUMO2:879return "sumo";880case CHIP_REDWOOD:881return "redwood";882case CHIP_JUNIPER:883return "juniper";884case CHIP_HEMLOCK:885case CHIP_CYPRESS:886return "cypress";887case CHIP_BARTS:888return "barts";889case CHIP_TURKS:890return "turks";891case CHIP_CAICOS:892return "caicos";893case CHIP_CAYMAN:894case CHIP_ARUBA:895return "cayman";896897default:898return "";899}900}901902static unsigned get_max_threads_per_block(struct r600_common_screen *screen,903enum pipe_shader_ir ir_type)904{905if (ir_type != PIPE_SHADER_IR_TGSI &&906ir_type != PIPE_SHADER_IR_NIR)907return 256;908if (screen->chip_class >= EVERGREEN)909return 1024;910return 256;911}912913static int r600_get_compute_param(struct pipe_screen *screen,914enum pipe_shader_ir ir_type,915enum pipe_compute_cap param,916void *ret)917{918struct r600_common_screen *rscreen = (struct r600_common_screen *)screen;919920//TODO: select these params by asic921switch (param) {922case PIPE_COMPUTE_CAP_IR_TARGET: {923const char *gpu;924const char *triple = "r600--";925gpu = r600_get_llvm_processor_name(rscreen->family);926if (ret) {927sprintf(ret, "%s-%s", gpu, triple);928}929/* +2 for dash and terminating NIL byte */930return (strlen(triple) + strlen(gpu) + 2) * sizeof(char);931}932case PIPE_COMPUTE_CAP_GRID_DIMENSION:933if (ret) {934uint64_t *grid_dimension = ret;935grid_dimension[0] = 3;936}937return 1 * sizeof(uint64_t);938939case PIPE_COMPUTE_CAP_MAX_GRID_SIZE:940if (ret) {941uint64_t *grid_size = ret;942grid_size[0] = 65535;943grid_size[1] = 65535;944grid_size[2] = 65535;945}946return 3 * sizeof(uint64_t) ;947948case PIPE_COMPUTE_CAP_MAX_BLOCK_SIZE:949if (ret) {950uint64_t *block_size = ret;951unsigned threads_per_block = get_max_threads_per_block(rscreen, ir_type);952block_size[0] = threads_per_block;953block_size[1] = threads_per_block;954block_size[2] = threads_per_block;955}956return 3 * sizeof(uint64_t);957958case PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK:959if (ret) {960uint64_t *max_threads_per_block = ret;961*max_threads_per_block = get_max_threads_per_block(rscreen, ir_type);962}963return sizeof(uint64_t);964case PIPE_COMPUTE_CAP_ADDRESS_BITS:965if (ret) {966uint32_t *address_bits = ret;967address_bits[0] = 32;968}969return 1 * sizeof(uint32_t);970971case PIPE_COMPUTE_CAP_MAX_GLOBAL_SIZE:972if (ret) {973uint64_t *max_global_size = ret;974uint64_t max_mem_alloc_size;975976r600_get_compute_param(screen, ir_type,977PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE,978&max_mem_alloc_size);979980/* In OpenCL, the MAX_MEM_ALLOC_SIZE must be at least981* 1/4 of the MAX_GLOBAL_SIZE. Since the982* MAX_MEM_ALLOC_SIZE is fixed for older kernels,983* make sure we never report more than984* 4 * MAX_MEM_ALLOC_SIZE.985*/986*max_global_size = MIN2(4 * max_mem_alloc_size,987MAX2(rscreen->info.gart_size,988rscreen->info.vram_size));989}990return sizeof(uint64_t);991992case PIPE_COMPUTE_CAP_MAX_LOCAL_SIZE:993if (ret) {994uint64_t *max_local_size = ret;995/* Value reported by the closed source driver. */996*max_local_size = 32768;997}998return sizeof(uint64_t);9991000case PIPE_COMPUTE_CAP_MAX_INPUT_SIZE:1001if (ret) {1002uint64_t *max_input_size = ret;1003/* Value reported by the closed source driver. */1004*max_input_size = 1024;1005}1006return sizeof(uint64_t);10071008case PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE:1009if (ret) {1010uint64_t *max_mem_alloc_size = ret;10111012*max_mem_alloc_size = rscreen->info.max_alloc_size;1013}1014return sizeof(uint64_t);10151016case PIPE_COMPUTE_CAP_MAX_CLOCK_FREQUENCY:1017if (ret) {1018uint32_t *max_clock_frequency = ret;1019*max_clock_frequency = rscreen->info.max_shader_clock;1020}1021return sizeof(uint32_t);10221023case PIPE_COMPUTE_CAP_MAX_COMPUTE_UNITS:1024if (ret) {1025uint32_t *max_compute_units = ret;1026*max_compute_units = rscreen->info.num_good_compute_units;1027}1028return sizeof(uint32_t);10291030case PIPE_COMPUTE_CAP_IMAGES_SUPPORTED:1031if (ret) {1032uint32_t *images_supported = ret;1033*images_supported = 0;1034}1035return sizeof(uint32_t);1036case PIPE_COMPUTE_CAP_MAX_PRIVATE_SIZE:1037break; /* unused */1038case PIPE_COMPUTE_CAP_SUBGROUP_SIZE:1039if (ret) {1040uint32_t *subgroup_size = ret;1041*subgroup_size = r600_wavefront_size(rscreen->family);1042}1043return sizeof(uint32_t);1044case PIPE_COMPUTE_CAP_MAX_VARIABLE_THREADS_PER_BLOCK:1045if (ret) {1046uint64_t *max_variable_threads_per_block = ret;1047*max_variable_threads_per_block = 0;1048}1049return sizeof(uint64_t);1050}10511052fprintf(stderr, "unknown PIPE_COMPUTE_CAP %d\n", param);1053return 0;1054}10551056static uint64_t r600_get_timestamp(struct pipe_screen *screen)1057{1058struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;10591060return 1000000 * rscreen->ws->query_value(rscreen->ws, RADEON_TIMESTAMP) /1061rscreen->info.clock_crystal_freq;1062}10631064static void r600_fence_reference(struct pipe_screen *screen,1065struct pipe_fence_handle **dst,1066struct pipe_fence_handle *src)1067{1068struct radeon_winsys *ws = ((struct r600_common_screen*)screen)->ws;1069struct r600_multi_fence **rdst = (struct r600_multi_fence **)dst;1070struct r600_multi_fence *rsrc = (struct r600_multi_fence *)src;10711072if (pipe_reference(&(*rdst)->reference, &rsrc->reference)) {1073ws->fence_reference(&(*rdst)->gfx, NULL);1074ws->fence_reference(&(*rdst)->sdma, NULL);1075FREE(*rdst);1076}1077*rdst = rsrc;1078}10791080static bool r600_fence_finish(struct pipe_screen *screen,1081struct pipe_context *ctx,1082struct pipe_fence_handle *fence,1083uint64_t timeout)1084{1085struct radeon_winsys *rws = ((struct r600_common_screen*)screen)->ws;1086struct r600_multi_fence *rfence = (struct r600_multi_fence *)fence;1087struct r600_common_context *rctx;1088int64_t abs_timeout = os_time_get_absolute_timeout(timeout);10891090ctx = threaded_context_unwrap_sync(ctx);1091rctx = ctx ? (struct r600_common_context*)ctx : NULL;10921093if (rfence->sdma) {1094if (!rws->fence_wait(rws, rfence->sdma, timeout))1095return false;10961097/* Recompute the timeout after waiting. */1098if (timeout && timeout != PIPE_TIMEOUT_INFINITE) {1099int64_t time = os_time_get_nano();1100timeout = abs_timeout > time ? abs_timeout - time : 0;1101}1102}11031104if (!rfence->gfx)1105return true;11061107/* Flush the gfx IB if it hasn't been flushed yet. */1108if (rctx &&1109rfence->gfx_unflushed.ctx == rctx &&1110rfence->gfx_unflushed.ib_index == rctx->num_gfx_cs_flushes) {1111rctx->gfx.flush(rctx, timeout ? 0 : PIPE_FLUSH_ASYNC, NULL);1112rfence->gfx_unflushed.ctx = NULL;11131114if (!timeout)1115return false;11161117/* Recompute the timeout after all that. */1118if (timeout && timeout != PIPE_TIMEOUT_INFINITE) {1119int64_t time = os_time_get_nano();1120timeout = abs_timeout > time ? abs_timeout - time : 0;1121}1122}11231124return rws->fence_wait(rws, rfence->gfx, timeout);1125}11261127static void r600_query_memory_info(struct pipe_screen *screen,1128struct pipe_memory_info *info)1129{1130struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;1131struct radeon_winsys *ws = rscreen->ws;1132unsigned vram_usage, gtt_usage;11331134info->total_device_memory = rscreen->info.vram_size / 1024;1135info->total_staging_memory = rscreen->info.gart_size / 1024;11361137/* The real TTM memory usage is somewhat random, because:1138*1139* 1) TTM delays freeing memory, because it can only free it after1140* fences expire.1141*1142* 2) The memory usage can be really low if big VRAM evictions are1143* taking place, but the real usage is well above the size of VRAM.1144*1145* Instead, return statistics of this process.1146*/1147vram_usage = ws->query_value(ws, RADEON_REQUESTED_VRAM_MEMORY) / 1024;1148gtt_usage = ws->query_value(ws, RADEON_REQUESTED_GTT_MEMORY) / 1024;11491150info->avail_device_memory =1151vram_usage <= info->total_device_memory ?1152info->total_device_memory - vram_usage : 0;1153info->avail_staging_memory =1154gtt_usage <= info->total_staging_memory ?1155info->total_staging_memory - gtt_usage : 0;11561157info->device_memory_evicted =1158ws->query_value(ws, RADEON_NUM_BYTES_MOVED) / 1024;11591160/* Just return the number of evicted 64KB pages. */1161info->nr_device_memory_evictions = info->device_memory_evicted / 64;1162}11631164struct pipe_resource *r600_resource_create_common(struct pipe_screen *screen,1165const struct pipe_resource *templ)1166{1167if (templ->target == PIPE_BUFFER) {1168return r600_buffer_create(screen, templ, 256);1169} else {1170return r600_texture_create(screen, templ);1171}1172}11731174static const void *1175r600_get_compiler_options(struct pipe_screen *screen,1176enum pipe_shader_ir ir,1177enum pipe_shader_type shader)1178{1179assert(ir == PIPE_SHADER_IR_NIR);11801181struct r600_common_screen *rscreen = (struct r600_common_screen *)screen;11821183return &rscreen->nir_options;1184}11851186extern bool r600_lower_to_scalar_instr_filter(const nir_instr *instr, const void *);11871188static void r600_resource_destroy(struct pipe_screen *screen,1189struct pipe_resource *res)1190{1191if (res->target == PIPE_BUFFER) {1192if (r600_resource(res)->compute_global_bo)1193r600_compute_global_buffer_destroy(screen, res);1194else1195r600_buffer_destroy(screen, res);1196} else {1197r600_texture_destroy(screen, res);1198}1199}12001201bool r600_common_screen_init(struct r600_common_screen *rscreen,1202struct radeon_winsys *ws)1203{1204char family_name[32] = {}, kernel_version[128] = {};1205struct utsname uname_data;1206const char *chip_name;12071208ws->query_info(ws, &rscreen->info, false, false);1209rscreen->ws = ws;12101211chip_name = r600_get_family_name(rscreen);12121213if (uname(&uname_data) == 0)1214snprintf(kernel_version, sizeof(kernel_version),1215" / %s", uname_data.release);12161217snprintf(rscreen->renderer_string, sizeof(rscreen->renderer_string),1218"%s (%sDRM %i.%i.%i%s"1219#ifdef LLVM_AVAILABLE1220", LLVM " MESA_LLVM_VERSION_STRING1221#endif1222")",1223chip_name, family_name, rscreen->info.drm_major,1224rscreen->info.drm_minor, rscreen->info.drm_patchlevel,1225kernel_version);12261227rscreen->b.get_name = r600_get_name;1228rscreen->b.get_vendor = r600_get_vendor;1229rscreen->b.get_device_vendor = r600_get_device_vendor;1230rscreen->b.get_disk_shader_cache = r600_get_disk_shader_cache;1231rscreen->b.get_compute_param = r600_get_compute_param;1232rscreen->b.get_paramf = r600_get_paramf;1233rscreen->b.get_timestamp = r600_get_timestamp;1234rscreen->b.get_compiler_options = r600_get_compiler_options;1235rscreen->b.fence_finish = r600_fence_finish;1236rscreen->b.fence_reference = r600_fence_reference;1237rscreen->b.resource_destroy = r600_resource_destroy;1238rscreen->b.resource_from_user_memory = r600_buffer_from_user_memory;1239rscreen->b.query_memory_info = r600_query_memory_info;12401241if (rscreen->info.has_video_hw.uvd_decode) {1242rscreen->b.get_video_param = rvid_get_video_param;1243rscreen->b.is_video_format_supported = rvid_is_format_supported;1244} else {1245rscreen->b.get_video_param = r600_get_video_param;1246rscreen->b.is_video_format_supported = vl_video_buffer_is_format_supported;1247}12481249r600_init_screen_texture_functions(rscreen);1250r600_init_screen_query_functions(rscreen);12511252rscreen->family = rscreen->info.family;1253rscreen->chip_class = rscreen->info.chip_class;1254rscreen->debug_flags |= debug_get_flags_option("R600_DEBUG", common_debug_options, 0);12551256r600_disk_cache_create(rscreen);12571258slab_create_parent(&rscreen->pool_transfers, sizeof(struct r600_transfer), 64);12591260rscreen->force_aniso = MIN2(16, debug_get_num_option("R600_TEX_ANISO", -1));1261if (rscreen->force_aniso >= 0) {1262printf("radeon: Forcing anisotropy filter to %ix\n",1263/* round down to a power of two */12641 << util_logbase2(rscreen->force_aniso));1265}12661267(void) mtx_init(&rscreen->aux_context_lock, mtx_plain);1268(void) mtx_init(&rscreen->gpu_load_mutex, mtx_plain);12691270if (rscreen->debug_flags & DBG_INFO) {1271printf("pci (domain:bus:dev.func): %04x:%02x:%02x.%x\n",1272rscreen->info.pci_domain, rscreen->info.pci_bus,1273rscreen->info.pci_dev, rscreen->info.pci_func);1274printf("pci_id = 0x%x\n", rscreen->info.pci_id);1275printf("family = %i (%s)\n", rscreen->info.family,1276r600_get_family_name(rscreen));1277printf("chip_class = %i\n", rscreen->info.chip_class);1278printf("pte_fragment_size = %u\n", rscreen->info.pte_fragment_size);1279printf("gart_page_size = %u\n", rscreen->info.gart_page_size);1280printf("gart_size = %i MB\n", (int)DIV_ROUND_UP(rscreen->info.gart_size, 1024*1024));1281printf("vram_size = %i MB\n", (int)DIV_ROUND_UP(rscreen->info.vram_size, 1024*1024));1282printf("vram_vis_size = %i MB\n", (int)DIV_ROUND_UP(rscreen->info.vram_vis_size, 1024*1024));1283printf("max_alloc_size = %i MB\n",1284(int)DIV_ROUND_UP(rscreen->info.max_alloc_size, 1024*1024));1285printf("min_alloc_size = %u\n", rscreen->info.min_alloc_size);1286printf("has_dedicated_vram = %u\n", rscreen->info.has_dedicated_vram);1287printf("r600_has_virtual_memory = %i\n", rscreen->info.r600_has_virtual_memory);1288printf("gfx_ib_pad_with_type2 = %i\n", rscreen->info.gfx_ib_pad_with_type2);1289printf("uvd_decode = %u\n", rscreen->info.has_video_hw.uvd_decode);1290printf("num_rings[RING_DMA] = %i\n", rscreen->info.num_rings[RING_DMA]);1291printf("num_rings[RING_COMPUTE] = %u\n", rscreen->info.num_rings[RING_COMPUTE]);1292printf("uvd_fw_version = %u\n", rscreen->info.uvd_fw_version);1293printf("vce_fw_version = %u\n", rscreen->info.vce_fw_version);1294printf("me_fw_version = %i\n", rscreen->info.me_fw_version);1295printf("pfp_fw_version = %i\n", rscreen->info.pfp_fw_version);1296printf("ce_fw_version = %i\n", rscreen->info.ce_fw_version);1297printf("vce_harvest_config = %i\n", rscreen->info.vce_harvest_config);1298printf("clock_crystal_freq = %i\n", rscreen->info.clock_crystal_freq);1299printf("tcc_cache_line_size = %u\n", rscreen->info.tcc_cache_line_size);1300printf("drm = %i.%i.%i\n", rscreen->info.drm_major,1301rscreen->info.drm_minor, rscreen->info.drm_patchlevel);1302printf("has_userptr = %i\n", rscreen->info.has_userptr);1303printf("has_syncobj = %u\n", rscreen->info.has_syncobj);13041305printf("r600_max_quad_pipes = %i\n", rscreen->info.r600_max_quad_pipes);1306printf("max_shader_clock = %i\n", rscreen->info.max_shader_clock);1307printf("num_good_compute_units = %i\n", rscreen->info.num_good_compute_units);1308printf("max_se = %i\n", rscreen->info.max_se);1309printf("max_sh_per_se = %i\n", rscreen->info.max_sa_per_se);13101311printf("r600_gb_backend_map = %i\n", rscreen->info.r600_gb_backend_map);1312printf("r600_gb_backend_map_valid = %i\n", rscreen->info.r600_gb_backend_map_valid);1313printf("r600_num_banks = %i\n", rscreen->info.r600_num_banks);1314printf("num_render_backends = %i\n", rscreen->info.max_render_backends);1315printf("num_tile_pipes = %i\n", rscreen->info.num_tile_pipes);1316printf("pipe_interleave_bytes = %i\n", rscreen->info.pipe_interleave_bytes);1317printf("enabled_rb_mask = 0x%x\n", rscreen->info.enabled_rb_mask);1318printf("max_alignment = %u\n", (unsigned)rscreen->info.max_alignment);1319}13201321const struct nir_shader_compiler_options nir_options = {1322.fuse_ffma16 = true,1323.fuse_ffma32 = true,1324.fuse_ffma64 = true,1325.lower_flrp32 = true,1326.lower_flrp64 = true,1327.lower_fpow = true,1328.lower_fdiv = true,1329.lower_isign = true,1330.lower_fsign = true,1331.lower_fmod = true,1332.lower_doubles_options = nir_lower_fp64_full_software,1333.lower_int64_options = ~0,1334.lower_extract_byte = true,1335.lower_extract_word = true,1336.lower_insert_byte = true,1337.lower_insert_word = true,1338.lower_rotate = true,1339.max_unroll_iterations = 32,1340.lower_interpolate_at = true,1341.vectorize_io = true,1342.has_umad24 = true,1343.has_umul24 = true,1344.use_interpolated_input_intrinsics = true,1345.has_fsub = true,1346.has_isub = true,1347.lower_iabs = true,1348.lower_bitfield_extract = true,1349.lower_bitfield_insert_to_bitfield_select = true,1350.has_fused_comp_and_csel = true,1351.lower_find_msb_to_reverse = true,1352.lower_to_scalar = true,1353.lower_to_scalar_filter = r600_lower_to_scalar_instr_filter,1354.linker_ignore_precision = true,1355};13561357rscreen->nir_options = nir_options;13581359return true;1360}13611362void r600_destroy_common_screen(struct r600_common_screen *rscreen)1363{1364r600_perfcounters_destroy(rscreen);1365r600_gpu_load_kill_thread(rscreen);13661367mtx_destroy(&rscreen->gpu_load_mutex);1368mtx_destroy(&rscreen->aux_context_lock);1369rscreen->aux_context->destroy(rscreen->aux_context);13701371slab_destroy_parent(&rscreen->pool_transfers);13721373disk_cache_destroy(rscreen->disk_shader_cache);1374rscreen->ws->destroy(rscreen->ws);1375FREE(rscreen);1376}13771378bool r600_can_dump_shader(struct r600_common_screen *rscreen,1379unsigned processor)1380{1381return rscreen->debug_flags & (1 << processor);1382}13831384bool r600_extra_shader_checks(struct r600_common_screen *rscreen, unsigned processor)1385{1386return (rscreen->debug_flags & DBG_CHECK_IR) ||1387r600_can_dump_shader(rscreen, processor);1388}13891390void r600_screen_clear_buffer(struct r600_common_screen *rscreen, struct pipe_resource *dst,1391uint64_t offset, uint64_t size, unsigned value)1392{1393struct r600_common_context *rctx = (struct r600_common_context*)rscreen->aux_context;13941395mtx_lock(&rscreen->aux_context_lock);1396rctx->dma_clear_buffer(&rctx->b, dst, offset, size, value);1397rscreen->aux_context->flush(rscreen->aux_context, NULL, 0);1398mtx_unlock(&rscreen->aux_context_lock);1399}140014011402