Path: blob/21.2-virgl/src/gallium/drivers/softpipe/sp_flush.c
4570 views
/**************************************************************************1*2* Copyright 2007 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/* Author:28* Keith Whitwell <[email protected]>29*/303132#include "pipe/p_defines.h"33#include "pipe/p_screen.h"34#include "draw/draw_context.h"35#include "sp_flush.h"36#include "sp_context.h"37#include "sp_state.h"38#include "sp_tile_cache.h"39#include "sp_tex_tile_cache.h"40#include "util/u_debug_image.h"41#include "util/u_memory.h"42#include "util/u_string.h"434445void46softpipe_flush( struct pipe_context *pipe,47unsigned flags,48struct pipe_fence_handle **fence )49{50struct softpipe_context *softpipe = softpipe_context(pipe);51uint i;5253draw_flush(softpipe->draw);5455if (flags & SP_FLUSH_TEXTURE_CACHE) {56unsigned sh;5758for (sh = 0; sh < ARRAY_SIZE(softpipe->tex_cache); sh++) {59for (i = 0; i < softpipe->num_sampler_views[sh]; i++) {60sp_flush_tex_tile_cache(softpipe->tex_cache[sh][i]);61}62}63}6465/* If this is a swapbuffers, just flush color buffers.66*67* The zbuffer changes are not discarded, but held in the cache68* in the hope that a later clear will wipe them out.69*/70for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++)71if (softpipe->cbuf_cache[i])72sp_flush_tile_cache(softpipe->cbuf_cache[i]);7374if (softpipe->zsbuf_cache)75sp_flush_tile_cache(softpipe->zsbuf_cache);7677softpipe->dirty_render_cache = FALSE;7879/* Enable to dump BMPs of the color/depth buffers each frame */80#if 081if (flags & PIPE_FLUSH_END_OF_FRAME) {82static unsigned frame_no = 1;83static char filename[256];84snprintf(filename, sizeof(filename), "cbuf_%u.bmp", frame_no);85debug_dump_surface_bmp(pipe, filename, softpipe->framebuffer.cbufs[0]);86snprintf(filename, sizeof(filename), "zsbuf_%u.bmp", frame_no);87debug_dump_surface_bmp(pipe, filename, softpipe->framebuffer.zsbuf);88++frame_no;89}90#endif9192if (fence)93*fence = (void*)(intptr_t)1;94}9596void97softpipe_flush_wrapped(struct pipe_context *pipe,98struct pipe_fence_handle **fence,99unsigned flags)100{101softpipe_flush(pipe, SP_FLUSH_TEXTURE_CACHE, fence);102}103104105/**106* Flush context if necessary.107*108* Returns FALSE if it would have block, but do_not_block was set, TRUE109* otherwise.110*111* TODO: move this logic to an auxiliary library?112*/113boolean114softpipe_flush_resource(struct pipe_context *pipe,115struct pipe_resource *texture,116unsigned level,117int layer,118unsigned flush_flags,119boolean read_only,120boolean cpu_access,121boolean do_not_block)122{123unsigned referenced;124125referenced = softpipe_is_resource_referenced(pipe, texture, level, layer);126127if ((referenced & SP_REFERENCED_FOR_WRITE) ||128((referenced & SP_REFERENCED_FOR_READ) && !read_only)) {129130/*131* TODO: The semantics of these flush flags are too obtuse. They should132* disappear and the pipe driver should just ensure that all visible133* side-effects happen when they need to happen.134*/135if (referenced & SP_REFERENCED_FOR_READ)136flush_flags |= SP_FLUSH_TEXTURE_CACHE;137138if (cpu_access) {139/*140* Flush and wait.141*/142143struct pipe_fence_handle *fence = NULL;144145if (do_not_block)146return FALSE;147148softpipe_flush(pipe, flush_flags, &fence);149150if (fence) {151/*152* This is for illustrative purposes only, as softpipe does not153* have fences.154*/155pipe->screen->fence_finish(pipe->screen, NULL, fence,156PIPE_TIMEOUT_INFINITE);157pipe->screen->fence_reference(pipe->screen, &fence, NULL);158}159} else {160/*161* Just flush.162*/163164softpipe_flush(pipe, flush_flags, NULL);165}166}167168return TRUE;169}170171void softpipe_texture_barrier(struct pipe_context *pipe, unsigned flags)172{173struct softpipe_context *softpipe = softpipe_context(pipe);174uint i, sh;175176for (sh = 0; sh < ARRAY_SIZE(softpipe->tex_cache); sh++) {177for (i = 0; i < softpipe->num_sampler_views[sh]; i++) {178sp_flush_tex_tile_cache(softpipe->tex_cache[sh][i]);179}180}181182for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++)183if (softpipe->cbuf_cache[i])184sp_flush_tile_cache(softpipe->cbuf_cache[i]);185186if (softpipe->zsbuf_cache)187sp_flush_tile_cache(softpipe->zsbuf_cache);188189softpipe->dirty_render_cache = FALSE;190}191192void softpipe_memory_barrier(struct pipe_context *pipe, unsigned flags)193{194if (!(flags & ~PIPE_BARRIER_UPDATE))195return;196197softpipe_texture_barrier(pipe, 0);198}199200201