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 LoadTile.cpp
24 *
25 * @brief Functionality for Load
26 *
27 ******************************************************************************/
28 #include "LoadTile.h"
29
30 // on demand buckets for load tiles
31 static std::vector<int> sBuckets(NUM_SWR_FORMATS, -1);
32 static std::mutex sBucketMutex;
33
34 //////////////////////////////////////////////////////////////////////////
35 /// @brief Loads a full hottile from a render surface
36 /// @param hPrivateContext - Handle to private DC
37 /// @param dstFormat - Format for hot tile.
38 /// @param renderTargetIndex - Index to src render target
39 /// @param x, y - Coordinates to raster tile.
40 /// @param pDstHotTile - Pointer to Hot Tile
SwrLoadHotTile(HANDLE hWorkerPrivateData,const SWR_SURFACE_STATE * pSrcSurface,BucketManager * pBucketMgr,SWR_FORMAT dstFormat,SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,uint32_t x,uint32_t y,uint32_t renderTargetArrayIndex,uint8_t * pDstHotTile)41 void SwrLoadHotTile(
42 HANDLE hWorkerPrivateData,
43 const SWR_SURFACE_STATE *pSrcSurface,
44 BucketManager* pBucketMgr,
45 SWR_FORMAT dstFormat,
46 SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
47 uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,
48 uint8_t *pDstHotTile)
49 {
50 PFN_LOAD_TILES pfnLoadTiles = NULL;
51
52 // don't need to load null surfaces
53 if (pSrcSurface->type == SURFACE_NULL)
54 {
55 return;
56 }
57
58 // force 0 if requested renderTargetArrayIndex is OOB
59 if (renderTargetArrayIndex >= pSrcSurface->depth)
60 {
61 renderTargetArrayIndex = 0;
62 }
63
64 if (renderTargetIndex < SWR_ATTACHMENT_DEPTH)
65 {
66 switch (pSrcSurface->tileMode)
67 {
68 case SWR_TILE_NONE:
69 pfnLoadTiles = sLoadTilesColorTable_SWR_TILE_NONE[pSrcSurface->format];
70 break;
71 case SWR_TILE_MODE_YMAJOR:
72 pfnLoadTiles = sLoadTilesColorTable_SWR_TILE_MODE_YMAJOR[pSrcSurface->format];
73 break;
74 case SWR_TILE_MODE_XMAJOR:
75 pfnLoadTiles = sLoadTilesColorTable_SWR_TILE_MODE_XMAJOR[pSrcSurface->format];
76 break;
77 case SWR_TILE_MODE_WMAJOR:
78 SWR_ASSERT(pSrcSurface->format == R8_UINT);
79 pfnLoadTiles = LoadMacroTile<TilingTraits<SWR_TILE_MODE_WMAJOR, 8>, R8_UINT, R8_UINT>::Load;
80 break;
81 default:
82 SWR_INVALID("Unsupported tiling mode");
83 break;
84 }
85 }
86 else if (renderTargetIndex == SWR_ATTACHMENT_DEPTH)
87 {
88 // Currently depth can map to linear and tile-y.
89 switch (pSrcSurface->tileMode)
90 {
91 case SWR_TILE_NONE:
92 pfnLoadTiles = sLoadTilesDepthTable_SWR_TILE_NONE[pSrcSurface->format];
93 break;
94 case SWR_TILE_MODE_YMAJOR:
95 pfnLoadTiles = sLoadTilesDepthTable_SWR_TILE_MODE_YMAJOR[pSrcSurface->format];
96 break;
97 default:
98 SWR_INVALID("Unsupported tiling mode");
99 break;
100 }
101 }
102 else
103 {
104 SWR_ASSERT(renderTargetIndex == SWR_ATTACHMENT_STENCIL);
105 SWR_ASSERT(pSrcSurface->format == R8_UINT);
106 switch (pSrcSurface->tileMode)
107 {
108 case SWR_TILE_NONE:
109 pfnLoadTiles = LoadMacroTile<TilingTraits<SWR_TILE_NONE, 8>, R8_UINT, R8_UINT>::Load;
110 break;
111 case SWR_TILE_MODE_WMAJOR:
112 pfnLoadTiles = LoadMacroTile<TilingTraits<SWR_TILE_MODE_WMAJOR, 8>, R8_UINT, R8_UINT>::Load;
113 break;
114 default:
115 SWR_INVALID("Unsupported tiling mode");
116 break;
117 }
118 }
119
120 if (pfnLoadTiles == nullptr)
121 {
122 SWR_INVALID("Unsupported format for load tile");
123 return;
124 }
125
126 // Load a macro tile.
127 #ifdef KNOB_ENABLE_RDTSC
128 if (sBuckets[pSrcSurface->format] == -1)
129 {
130 // guard sBuckets update since storetiles is called by multiple threads
131 sBucketMutex.lock();
132 if (sBuckets[pSrcSurface->format] == -1)
133 {
134 const SWR_FORMAT_INFO& info = GetFormatInfo(pSrcSurface->format);
135 BUCKET_DESC desc{ info.name, "", false, 0xffffffff };
136 sBuckets[pSrcSurface->format] = pBucketMgr->RegisterBucket(desc);
137 }
138 sBucketMutex.unlock();
139 }
140 #endif
141
142 #ifdef KNOB_ENABLE_RDTSC
143 pBucketMgr->StartBucket(sBuckets[pSrcSurface->format]);
144 #endif
145 pfnLoadTiles(pSrcSurface, pDstHotTile, x, y, renderTargetArrayIndex);
146 #ifdef KNOB_ENABLE_RDTSC
147 pBucketMgr->StopBucket(sBuckets[pSrcSurface->format]);
148 #endif
149 }
150
151
InitSimLoadTilesTable()152 void InitSimLoadTilesTable()
153 {
154 InitLoadTilesTable_Linear();
155 InitLoadTilesTable_XMajor();
156 InitLoadTilesTable_YMajor();
157 }
158