Path: blob/21.2-virgl/src/gallium/drivers/swr/swr_clear.cpp
4570 views
/****************************************************************************1* Copyright (C) 2015 Intel Corporation. All Rights Reserved.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, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21***************************************************************************/2223#include "swr_context.h"24#include "swr_query.h"2526static void27swr_clear(struct pipe_context *pipe,28unsigned buffers,29const struct pipe_scissor_state *scissor_state,30const union pipe_color_union *color,31double depth,32unsigned stencil)33{34struct swr_context *ctx = swr_context(pipe);35struct pipe_framebuffer_state *fb = &ctx->framebuffer;3637UINT clearMask = 0;38unsigned layers = 0;3940if (!swr_check_render_cond(pipe))41return;4243swr_update_derived(pipe);4445if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {46for (unsigned i = 0; i < fb->nr_cbufs; ++i)47if (fb->cbufs[i] && (buffers & (PIPE_CLEAR_COLOR0 << i))) {48clearMask |= (SWR_ATTACHMENT_COLOR0_BIT << i);49layers = std::max(layers, fb->cbufs[i]->u.tex.last_layer -50fb->cbufs[i]->u.tex.first_layer + 1u);51}52}5354if (buffers & PIPE_CLEAR_DEPTH && fb->zsbuf) {55clearMask |= SWR_ATTACHMENT_DEPTH_BIT;56layers = std::max(layers, fb->zsbuf->u.tex.last_layer -57fb->zsbuf->u.tex.first_layer + 1u);58}5960if (buffers & PIPE_CLEAR_STENCIL && fb->zsbuf) {61clearMask |= SWR_ATTACHMENT_STENCIL_BIT;62layers = std::max(layers, fb->zsbuf->u.tex.last_layer -63fb->zsbuf->u.tex.first_layer + 1u);64}6566#if 0 // XXX HACK, override clear color alpha. On ubuntu, clears are67// transparent.68((union pipe_color_union *)color)->f[3] = 1.0; /* cast off your const'd-ness */69#endif7071/*72* Always clear full surface. When GL_SCISSOR_TEST is enabled73* glClear is handled by state tracker and there is no need to do this here74*/75SWR_RECT clear_rect = {0, 0, (int32_t)fb->width, (int32_t)fb->height};7677for (unsigned i = 0; i < layers; ++i) {78swr_update_draw_context(ctx);79ctx->api.pfnSwrClearRenderTarget(ctx->swrContext, clearMask, i,80color->f, depth, stencil,81clear_rect);8283// Mask out the attachments that are out of layers.84if (fb->zsbuf &&85(fb->zsbuf->u.tex.last_layer <= fb->zsbuf->u.tex.first_layer + i))86clearMask &= ~(SWR_ATTACHMENT_DEPTH_BIT | SWR_ATTACHMENT_STENCIL_BIT);87for (unsigned c = 0; c < fb->nr_cbufs; ++c) {88const struct pipe_surface *sf = fb->cbufs[c];89if (sf && (sf->u.tex.last_layer <= sf->u.tex.first_layer + i))90clearMask &= ~(SWR_ATTACHMENT_COLOR0_BIT << c);91}92}93}9495void96swr_clear_init(struct pipe_context *pipe)97{98pipe->clear = swr_clear;99}100101102