Path: blob/21.2-virgl/src/gallium/drivers/softpipe/sp_quad_depth_test_tmp.h
4570 views
/**************************************************************************1*2* Copyright 2010 VMware, Inc. All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the6* "Software"), to deal in the Software without restriction, including7* without limitation the rights to use, copy, modify, merge, publish,8* distribute, sub license, and/or sell copies of the Software, and to9* permit persons to whom the Software is furnished to do so, subject to10* the following conditions:11*12* The above copyright notice and this permission notice (including the13* next paragraph) shall be included in all copies or substantial portions14* of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS17* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.19* IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR20* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,21* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE22* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*24**************************************************************************/252627/*28* Template for generating Z test functions29* Only PIPE_FORMAT_Z16_UNORM supported at this time.30*/313233#ifndef NAME34#error "NAME is not defined!"35#endif3637#if !defined(OPERATOR) && !defined(ALWAYS)38#error "neither OPERATOR nor ALWAYS is defined!"39#endif404142/*43* NOTE: there's no guarantee that the quads are sequentially side by44* side. The fragment shader may have culled some quads, etc. Sliver45* triangles may generate non-sequential quads.46*/47static void48NAME(struct quad_stage *qs,49struct quad_header *quads[],50unsigned nr)51{52unsigned i, pass = 0;53const unsigned ix = quads[0]->input.x0;54const unsigned iy = quads[0]->input.y0;55const float fx = (float) ix;56const float fy = (float) iy;57const float dzdx = quads[0]->posCoef->dadx[2];58const float dzdy = quads[0]->posCoef->dady[2];59const float z0 = quads[0]->posCoef->a0[2] + dzdx * fx + dzdy * fy;60struct softpipe_cached_tile *tile;61ushort (*depth16)[TILE_SIZE];62ushort init_idepth[4], idepth[4], depth_step;63const float scale = 65535.0;6465/* compute scaled depth of the four pixels in first quad */66init_idepth[0] = (ushort)((z0) * scale);67init_idepth[1] = (ushort)((z0 + dzdx) * scale);68init_idepth[2] = (ushort)((z0 + dzdy) * scale);69init_idepth[3] = (ushort)((z0 + dzdx + dzdy) * scale);7071depth_step = (ushort)(dzdx * scale);7273tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy, quads[0]->input.layer);7475for (i = 0; i < nr; i++) {76const unsigned outmask = quads[i]->inout.mask;77const int dx = quads[i]->input.x0 - ix;78unsigned mask = 0;7980/* compute depth for this quad */81idepth[0] = init_idepth[0] + dx * depth_step;82idepth[1] = init_idepth[1] + dx * depth_step;83idepth[2] = init_idepth[2] + dx * depth_step;84idepth[3] = init_idepth[3] + dx * depth_step;8586depth16 = (ushort (*)[TILE_SIZE])87&tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE];8889#ifdef ALWAYS90if (outmask & 1) {91depth16[0][0] = idepth[0];92mask |= (1 << 0);93}9495if (outmask & 2) {96depth16[0][1] = idepth[1];97mask |= (1 << 1);98}99100if (outmask & 4) {101depth16[1][0] = idepth[2];102mask |= (1 << 2);103}104105if (outmask & 8) {106depth16[1][1] = idepth[3];107mask |= (1 << 3);108}109#else110/* Note: OPERATOR appears here: */111if ((outmask & 1) && (idepth[0] OPERATOR depth16[0][0])) {112depth16[0][0] = idepth[0];113mask |= (1 << 0);114}115116if ((outmask & 2) && (idepth[1] OPERATOR depth16[0][1])) {117depth16[0][1] = idepth[1];118mask |= (1 << 1);119}120121if ((outmask & 4) && (idepth[2] OPERATOR depth16[1][0])) {122depth16[1][0] = idepth[2];123mask |= (1 << 2);124}125126if ((outmask & 8) && (idepth[3] OPERATOR depth16[1][1])) {127depth16[1][1] = idepth[3];128mask |= (1 << 3);129}130#endif131132depth16 = (ushort (*)[TILE_SIZE]) &depth16[0][2];133134quads[i]->inout.mask = mask;135if (quads[i]->inout.mask)136quads[pass++] = quads[i];137}138139if (pass)140qs->next->run(qs->next, quads, pass);141}142143144#undef NAME145#undef OPERATOR146#undef ALWAYS147148149