1/**************************************************************************** 2 * Copyright (C) 2015 Intel Corporation. All Rights Reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 ***************************************************************************/ 23 24#include "swr_context.h" 25#include "swr_query.h" 26 27static void 28swr_clear(struct pipe_context *pipe, 29 unsigned buffers, 30 const struct pipe_scissor_state *scissor_state, 31 const union pipe_color_union *color, 32 double depth, 33 unsigned stencil) 34{ 35 struct swr_context *ctx = swr_context(pipe); 36 struct pipe_framebuffer_state *fb = &ctx->framebuffer; 37 38 UINT clearMask = 0; 39 unsigned layers = 0; 40 41 if (!swr_check_render_cond(pipe)) 42 return; 43 44 swr_update_derived(pipe); 45 46 if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) { 47 for (unsigned i = 0; i < fb->nr_cbufs; ++i) 48 if (fb->cbufs[i] && (buffers & (PIPE_CLEAR_COLOR0 << i))) { 49 clearMask |= (SWR_ATTACHMENT_COLOR0_BIT << i); 50 layers = std::max(layers, fb->cbufs[i]->u.tex.last_layer - 51 fb->cbufs[i]->u.tex.first_layer + 1u); 52 } 53 } 54 55 if (buffers & PIPE_CLEAR_DEPTH && fb->zsbuf) { 56 clearMask |= SWR_ATTACHMENT_DEPTH_BIT; 57 layers = std::max(layers, fb->zsbuf->u.tex.last_layer - 58 fb->zsbuf->u.tex.first_layer + 1u); 59 } 60 61 if (buffers & PIPE_CLEAR_STENCIL && fb->zsbuf) { 62 clearMask |= SWR_ATTACHMENT_STENCIL_BIT; 63 layers = std::max(layers, fb->zsbuf->u.tex.last_layer - 64 fb->zsbuf->u.tex.first_layer + 1u); 65 } 66 67#if 0 // XXX HACK, override clear color alpha. On ubuntu, clears are 68 // transparent. 69 ((union pipe_color_union *)color)->f[3] = 1.0; /* cast off your const'd-ness */ 70#endif 71 72 /* 73 * Always clear full surface. When GL_SCISSOR_TEST is enabled 74 * glClear is handled by state tracker and there is no need to do this here 75 */ 76 SWR_RECT clear_rect = {0, 0, (int32_t)fb->width, (int32_t)fb->height}; 77 78 for (unsigned i = 0; i < layers; ++i) { 79 swr_update_draw_context(ctx); 80 ctx->api.pfnSwrClearRenderTarget(ctx->swrContext, clearMask, i, 81 color->f, depth, stencil, 82 clear_rect); 83 84 // Mask out the attachments that are out of layers. 85 if (fb->zsbuf && 86 (fb->zsbuf->u.tex.last_layer <= fb->zsbuf->u.tex.first_layer + i)) 87 clearMask &= ~(SWR_ATTACHMENT_DEPTH_BIT | SWR_ATTACHMENT_STENCIL_BIT); 88 for (unsigned c = 0; c < fb->nr_cbufs; ++c) { 89 const struct pipe_surface *sf = fb->cbufs[c]; 90 if (sf && (sf->u.tex.last_layer <= sf->u.tex.first_layer + i)) 91 clearMask &= ~(SWR_ATTACHMENT_COLOR0_BIT << c); 92 } 93 } 94} 95 96void 97swr_clear_init(struct pipe_context *pipe) 98{ 99 pipe->clear = swr_clear; 100} 101