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