Path: blob/21.2-virgl/src/gallium/drivers/r300/r300_flush.c
4570 views
/*1* Copyright 2008 Corbin Simpson <[email protected]>2* Copyright 2010 Marek Olšák <[email protected]>3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE. */2223#include "draw/draw_context.h"24#include "draw/draw_private.h"2526#include "util/simple_list.h"27#include "util/u_upload_mgr.h"2829#include "util/os_time.h"3031#include "r300_context.h"32#include "r300_cs.h"33#include "r300_emit.h"343536static void r300_flush_and_cleanup(struct r300_context *r300, unsigned flags,37struct pipe_fence_handle **fence)38{39struct r300_atom *atom;4041r300_emit_hyperz_end(r300);42r300_emit_query_end(r300);43if (r300->screen->caps.is_r500)44r500_emit_index_bias(r300, 0);4546/* The DDX doesn't set these regs. */47{48CS_LOCALS(r300);49OUT_CS_REG_SEQ(R300_GB_MSPOS0, 2);50OUT_CS(0x66666666);51OUT_CS(0x6666666);52}5354r300->flush_counter++;55r300->rws->cs_flush(&r300->cs, flags, fence);56r300->dirty_hw = 0;5758/* New kitchen sink, baby. */59foreach_atom(r300, atom) {60if (atom->state || atom->allow_null_state) {61r300_mark_atom_dirty(r300, atom);62}63}64r300->vertex_arrays_dirty = TRUE;6566/* Unmark HWTCL state for SWTCL. */67if (!r300->screen->caps.has_tcl) {68r300->vs_state.dirty = FALSE;69r300->vs_constants.dirty = FALSE;70r300->clip_state.dirty = FALSE;71}72}7374void r300_flush(struct pipe_context *pipe,75unsigned flags,76struct pipe_fence_handle **fence)77{78struct r300_context *r300 = r300_context(pipe);7980if (r300->dirty_hw) {81r300_flush_and_cleanup(r300, flags, fence);82} else {83if (fence) {84/* We have to create a fence object, but the command stream is empty85* and we cannot emit an empty CS. Let's write to some reg. */86CS_LOCALS(r300);87OUT_CS_REG(RB3D_COLOR_CHANNEL_MASK, 0);88r300->rws->cs_flush(&r300->cs, flags, fence);89} else {90/* Even if hw is not dirty, we should at least reset the CS in case91* the space checking failed for the first draw operation. */92r300->rws->cs_flush(&r300->cs, flags, NULL);93}94}9596/* Update Hyper-Z status. */97if (r300->hyperz_enabled) {98/* If there was a Z clear, keep Hyper-Z access. */99if (r300->num_z_clears) {100r300->hyperz_time_of_last_flush = os_time_get();101r300->num_z_clears = 0;102} else if (r300->hyperz_time_of_last_flush - os_time_get() > 2000000) {103/* If there hasn't been a Z clear for 2 seconds, revoke Hyper-Z access. */104r300->hiz_in_use = FALSE;105106/* Decompress the Z buffer. */107if (r300->zmask_in_use) {108if (r300->locked_zbuffer) {109r300_decompress_zmask_locked(r300);110} else {111r300_decompress_zmask(r300);112}113114if (fence && *fence)115r300->rws->fence_reference(fence, NULL);116r300_flush_and_cleanup(r300, flags, fence);117}118119/* Revoke Hyper-Z access, so that some other process can take it. */120r300->rws->cs_request_feature(&r300->cs, RADEON_FID_R300_HYPERZ_ACCESS,121FALSE);122r300->hyperz_enabled = FALSE;123}124}125}126127static void r300_flush_wrapped(struct pipe_context *pipe,128struct pipe_fence_handle **fence,129unsigned flags)130{131if (flags & PIPE_FLUSH_HINT_FINISH)132flags &= ~PIPE_FLUSH_ASYNC;133134r300_flush(pipe, flags, fence);135}136137void r300_init_flush_functions(struct r300_context* r300)138{139r300->context.flush = r300_flush_wrapped;140}141142143