Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/memory/LoadTile.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 LoadTile.cpp23*24* @brief Functionality for Load25*26******************************************************************************/27#include "LoadTile.h"2829// on demand buckets for load tiles30static std::vector<int> sBuckets(NUM_SWR_FORMATS, -1);31static std::mutex sBucketMutex;3233//////////////////////////////////////////////////////////////////////////34/// @brief Loads a full hottile from a render surface35/// @param hPrivateContext - Handle to private DC36/// @param dstFormat - Format for hot tile.37/// @param renderTargetIndex - Index to src render target38/// @param x, y - Coordinates to raster tile.39/// @param pDstHotTile - Pointer to Hot Tile40void SwrLoadHotTile(41HANDLE hWorkerPrivateData,42const SWR_SURFACE_STATE *pSrcSurface,43BucketManager* pBucketMgr,44SWR_FORMAT dstFormat,45SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,46uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,47uint8_t *pDstHotTile)48{49PFN_LOAD_TILES pfnLoadTiles = NULL;5051// don't need to load null surfaces52if (pSrcSurface->type == SURFACE_NULL)53{54return;55}5657// force 0 if requested renderTargetArrayIndex is OOB58if (renderTargetArrayIndex >= pSrcSurface->depth)59{60renderTargetArrayIndex = 0;61}6263if (renderTargetIndex < SWR_ATTACHMENT_DEPTH)64{65switch (pSrcSurface->tileMode)66{67case SWR_TILE_NONE:68pfnLoadTiles = sLoadTilesColorTable_SWR_TILE_NONE[pSrcSurface->format];69break;70case SWR_TILE_MODE_YMAJOR:71pfnLoadTiles = sLoadTilesColorTable_SWR_TILE_MODE_YMAJOR[pSrcSurface->format];72break;73case SWR_TILE_MODE_XMAJOR:74pfnLoadTiles = sLoadTilesColorTable_SWR_TILE_MODE_XMAJOR[pSrcSurface->format];75break;76case SWR_TILE_MODE_WMAJOR:77SWR_ASSERT(pSrcSurface->format == R8_UINT);78pfnLoadTiles = LoadMacroTile<TilingTraits<SWR_TILE_MODE_WMAJOR, 8>, R8_UINT, R8_UINT>::Load;79break;80default:81SWR_INVALID("Unsupported tiling mode");82break;83}84}85else if (renderTargetIndex == SWR_ATTACHMENT_DEPTH)86{87// Currently depth can map to linear and tile-y.88switch (pSrcSurface->tileMode)89{90case SWR_TILE_NONE:91pfnLoadTiles = sLoadTilesDepthTable_SWR_TILE_NONE[pSrcSurface->format];92break;93case SWR_TILE_MODE_YMAJOR:94pfnLoadTiles = sLoadTilesDepthTable_SWR_TILE_MODE_YMAJOR[pSrcSurface->format];95break;96default:97SWR_INVALID("Unsupported tiling mode");98break;99}100}101else102{103SWR_ASSERT(renderTargetIndex == SWR_ATTACHMENT_STENCIL);104SWR_ASSERT(pSrcSurface->format == R8_UINT);105switch (pSrcSurface->tileMode)106{107case SWR_TILE_NONE:108pfnLoadTiles = LoadMacroTile<TilingTraits<SWR_TILE_NONE, 8>, R8_UINT, R8_UINT>::Load;109break;110case SWR_TILE_MODE_WMAJOR:111pfnLoadTiles = LoadMacroTile<TilingTraits<SWR_TILE_MODE_WMAJOR, 8>, R8_UINT, R8_UINT>::Load;112break;113default:114SWR_INVALID("Unsupported tiling mode");115break;116}117}118119if (pfnLoadTiles == nullptr)120{121SWR_INVALID("Unsupported format for load tile");122return;123}124125// Load a macro tile.126#ifdef KNOB_ENABLE_RDTSC127if (sBuckets[pSrcSurface->format] == -1)128{129// guard sBuckets update since storetiles is called by multiple threads130sBucketMutex.lock();131if (sBuckets[pSrcSurface->format] == -1)132{133const SWR_FORMAT_INFO& info = GetFormatInfo(pSrcSurface->format);134BUCKET_DESC desc{ info.name, "", false, 0xffffffff };135sBuckets[pSrcSurface->format] = pBucketMgr->RegisterBucket(desc);136}137sBucketMutex.unlock();138}139#endif140141#ifdef KNOB_ENABLE_RDTSC142pBucketMgr->StartBucket(sBuckets[pSrcSurface->format]);143#endif144pfnLoadTiles(pSrcSurface, pDstHotTile, x, y, renderTargetArrayIndex);145#ifdef KNOB_ENABLE_RDTSC146pBucketMgr->StopBucket(sBuckets[pSrcSurface->format]);147#endif148}149150151void InitSimLoadTilesTable()152{153InitLoadTilesTable_Linear();154InitLoadTilesTable_XMajor();155InitLoadTilesTable_YMajor();156}157158159