Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/memory/StoreTile.cpp
4574 views
/****************************************************************************1* Copyright (C) 2014-2016 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*22* @file StoreTile.cpp23*24* @brief Functionality for Store.25*26******************************************************************************/27#include "StoreTile.h"28//////////////////////////////////////////////////////////////////////////29/// Store Raster Tile Function Tables.30//////////////////////////////////////////////////////////////////////////31PFN_STORE_TILES sStoreTilesTableColor[SWR_TILE_MODE_COUNT][NUM_SWR_FORMATS] = {};32PFN_STORE_TILES sStoreTilesTableDepth[SWR_TILE_MODE_COUNT][NUM_SWR_FORMATS] = {};33PFN_STORE_TILES sStoreTilesTableStencil[SWR_TILE_MODE_COUNT][NUM_SWR_FORMATS] = {};3435// on demand buckets for store tiles36static std::mutex sBucketMutex;37static std::vector<int32_t> sBuckets(NUM_SWR_FORMATS, -1);3839//////////////////////////////////////////////////////////////////////////40/// @brief Deswizzles and stores a full hottile to a render surface41/// @param hPrivateContext - Handle to private DC42/// @param srcFormat - Format for hot tile.43/// @param renderTargetIndex - Index to destination render target44/// @param x, y - Coordinates to raster tile.45/// @param pSrcHotTile - Pointer to Hot Tile46void SwrStoreHotTileToSurface(47HANDLE hWorkerPrivateData,48SWR_SURFACE_STATE *pDstSurface,49BucketManager* pBucketMgr,50SWR_FORMAT srcFormat,51SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,52uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,53uint8_t *pSrcHotTile)54{55if (pDstSurface->type == SURFACE_NULL)56{57return;58}5960// force 0 if requested renderTargetArrayIndex is OOB61if (renderTargetArrayIndex >= pDstSurface->depth)62{63renderTargetArrayIndex = 0;64}6566PFN_STORE_TILES pfnStoreTiles = nullptr;6768if (renderTargetIndex <= SWR_ATTACHMENT_COLOR7)69{70pfnStoreTiles = sStoreTilesTableColor[pDstSurface->tileMode][pDstSurface->format];71}72else if (renderTargetIndex == SWR_ATTACHMENT_DEPTH)73{74pfnStoreTiles = sStoreTilesTableDepth[pDstSurface->tileMode][pDstSurface->format];75}76else77{78pfnStoreTiles = sStoreTilesTableStencil[pDstSurface->tileMode][pDstSurface->format];79}8081if(nullptr == pfnStoreTiles)82{83SWR_INVALID("Invalid pixel format / tile mode for store tiles");84return;85}8687// Store a macro tile88#ifdef KNOB_ENABLE_RDTSC89if (sBuckets[pDstSurface->format] == -1)90{91// guard sBuckets update since storetiles is called by multiple threads92sBucketMutex.lock();93if (sBuckets[pDstSurface->format] == -1)94{95const SWR_FORMAT_INFO& info = GetFormatInfo(pDstSurface->format);96BUCKET_DESC desc{info.name, "", false, 0xffffffff};97sBuckets[pDstSurface->format] = pBucketMgr->RegisterBucket(desc);98}99sBucketMutex.unlock();100}101#endif102103#ifdef KNOB_ENABLE_RDTSC104pBucketMgr->StartBucket(sBuckets[pDstSurface->format]);105#endif106pfnStoreTiles(pSrcHotTile, pDstSurface, x, y, renderTargetArrayIndex);107#ifdef KNOB_ENABLE_RDTSC108pBucketMgr->StopBucket(sBuckets[pDstSurface->format]);109#endif110111}112113114//////////////////////////////////////////////////////////////////////////115/// @brief Sets up tables for StoreTile116void InitSimStoreTilesTable()117{118memset(sStoreTilesTableColor, 0, sizeof(sStoreTilesTableColor));119memset(sStoreTilesTableDepth, 0, sizeof(sStoreTilesTableDepth));120121InitStoreTilesTable_Linear_1();122InitStoreTilesTable_Linear_2();123InitStoreTilesTable_TileX_1();124InitStoreTilesTable_TileX_2();125InitStoreTilesTable_TileY_1();126InitStoreTilesTable_TileY_2();127InitStoreTilesTable_TileW();128}129130131