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