Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/swr/rasterizer/memory/StoreTile.cpp
4574 views
1
/****************************************************************************
2
* Copyright (C) 2014-2016 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
* @file StoreTile.cpp
24
*
25
* @brief Functionality for Store.
26
*
27
******************************************************************************/
28
#include "StoreTile.h"
29
//////////////////////////////////////////////////////////////////////////
30
/// Store Raster Tile Function Tables.
31
//////////////////////////////////////////////////////////////////////////
32
PFN_STORE_TILES sStoreTilesTableColor[SWR_TILE_MODE_COUNT][NUM_SWR_FORMATS] = {};
33
PFN_STORE_TILES sStoreTilesTableDepth[SWR_TILE_MODE_COUNT][NUM_SWR_FORMATS] = {};
34
PFN_STORE_TILES sStoreTilesTableStencil[SWR_TILE_MODE_COUNT][NUM_SWR_FORMATS] = {};
35
36
// on demand buckets for store tiles
37
static std::mutex sBucketMutex;
38
static std::vector<int32_t> sBuckets(NUM_SWR_FORMATS, -1);
39
40
//////////////////////////////////////////////////////////////////////////
41
/// @brief Deswizzles and stores a full hottile to a render surface
42
/// @param hPrivateContext - Handle to private DC
43
/// @param srcFormat - Format for hot tile.
44
/// @param renderTargetIndex - Index to destination render target
45
/// @param x, y - Coordinates to raster tile.
46
/// @param pSrcHotTile - Pointer to Hot Tile
47
void SwrStoreHotTileToSurface(
48
HANDLE hWorkerPrivateData,
49
SWR_SURFACE_STATE *pDstSurface,
50
BucketManager* pBucketMgr,
51
SWR_FORMAT srcFormat,
52
SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
53
uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,
54
uint8_t *pSrcHotTile)
55
{
56
if (pDstSurface->type == SURFACE_NULL)
57
{
58
return;
59
}
60
61
// force 0 if requested renderTargetArrayIndex is OOB
62
if (renderTargetArrayIndex >= pDstSurface->depth)
63
{
64
renderTargetArrayIndex = 0;
65
}
66
67
PFN_STORE_TILES pfnStoreTiles = nullptr;
68
69
if (renderTargetIndex <= SWR_ATTACHMENT_COLOR7)
70
{
71
pfnStoreTiles = sStoreTilesTableColor[pDstSurface->tileMode][pDstSurface->format];
72
}
73
else if (renderTargetIndex == SWR_ATTACHMENT_DEPTH)
74
{
75
pfnStoreTiles = sStoreTilesTableDepth[pDstSurface->tileMode][pDstSurface->format];
76
}
77
else
78
{
79
pfnStoreTiles = sStoreTilesTableStencil[pDstSurface->tileMode][pDstSurface->format];
80
}
81
82
if(nullptr == pfnStoreTiles)
83
{
84
SWR_INVALID("Invalid pixel format / tile mode for store tiles");
85
return;
86
}
87
88
// Store a macro tile
89
#ifdef KNOB_ENABLE_RDTSC
90
if (sBuckets[pDstSurface->format] == -1)
91
{
92
// guard sBuckets update since storetiles is called by multiple threads
93
sBucketMutex.lock();
94
if (sBuckets[pDstSurface->format] == -1)
95
{
96
const SWR_FORMAT_INFO& info = GetFormatInfo(pDstSurface->format);
97
BUCKET_DESC desc{info.name, "", false, 0xffffffff};
98
sBuckets[pDstSurface->format] = pBucketMgr->RegisterBucket(desc);
99
}
100
sBucketMutex.unlock();
101
}
102
#endif
103
104
#ifdef KNOB_ENABLE_RDTSC
105
pBucketMgr->StartBucket(sBuckets[pDstSurface->format]);
106
#endif
107
pfnStoreTiles(pSrcHotTile, pDstSurface, x, y, renderTargetArrayIndex);
108
#ifdef KNOB_ENABLE_RDTSC
109
pBucketMgr->StopBucket(sBuckets[pDstSurface->format]);
110
#endif
111
112
}
113
114
115
//////////////////////////////////////////////////////////////////////////
116
/// @brief Sets up tables for StoreTile
117
void InitSimStoreTilesTable()
118
{
119
memset(sStoreTilesTableColor, 0, sizeof(sStoreTilesTableColor));
120
memset(sStoreTilesTableDepth, 0, sizeof(sStoreTilesTableDepth));
121
122
InitStoreTilesTable_Linear_1();
123
InitStoreTilesTable_Linear_2();
124
InitStoreTilesTable_TileX_1();
125
InitStoreTilesTable_TileX_2();
126
InitStoreTilesTable_TileY_1();
127
InitStoreTilesTable_TileY_2();
128
InitStoreTilesTable_TileW();
129
}
130
131