1 /****************************************************************************
2 * Copyright (C) 2014-2016 Intel Corporation. All Rights Reserved.
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:
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
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
25 * @brief Functionality for Store.
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
] = {};
36 static void BUCKETS_START(UINT id
)
38 #ifdef KNOB_ENABLE_RDTSC
39 gBucketMgr
.StartBucket(id
);
43 static void BUCKETS_STOP(UINT id
)
45 #ifdef KNOB_ENABLE_RDTSC
46 gBucketMgr
.StopBucket(id
);
50 // on demand buckets for store tiles
51 static std::mutex sBucketMutex
;
52 static std::vector
<int32_t> sBuckets(NUM_SWR_FORMATS
, -1);
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
,
64 SWR_RENDERTARGET_ATTACHMENT renderTargetIndex
,
65 uint32_t x
, uint32_t y
, uint32_t renderTargetArrayIndex
,
68 if (pDstSurface
->type
== SURFACE_NULL
)
73 // force 0 if requested renderTargetArrayIndex is OOB
74 if (renderTargetArrayIndex
>= pDstSurface
->depth
)
76 renderTargetArrayIndex
= 0;
79 PFN_STORE_TILES pfnStoreTiles
= nullptr;
81 if (renderTargetIndex
<= SWR_ATTACHMENT_COLOR7
)
83 pfnStoreTiles
= sStoreTilesTableColor
[pDstSurface
->tileMode
][pDstSurface
->format
];
85 else if (renderTargetIndex
== SWR_ATTACHMENT_DEPTH
)
87 pfnStoreTiles
= sStoreTilesTableDepth
[pDstSurface
->tileMode
][pDstSurface
->format
];
91 pfnStoreTiles
= sStoreTilesTableStencil
[pDstSurface
->tileMode
][pDstSurface
->format
];
94 if(nullptr == pfnStoreTiles
)
96 SWR_INVALID("Invalid pixel format / tile mode for store tiles");
100 // Store a macro tile
101 #ifdef KNOB_ENABLE_RDTSC
102 if (sBuckets
[pDstSurface
->format
] == -1)
104 // guard sBuckets update since storetiles is called by multiple threads
106 if (sBuckets
[pDstSurface
->format
] == -1)
108 const SWR_FORMAT_INFO
& info
= GetFormatInfo(pDstSurface
->format
);
109 BUCKET_DESC desc
{info
.name
, "", false, 0xffffffff};
110 sBuckets
[pDstSurface
->format
] = gBucketMgr
.RegisterBucket(desc
);
112 sBucketMutex
.unlock();
116 BUCKETS_START(sBuckets
[pDstSurface
->format
]);
117 pfnStoreTiles(pSrcHotTile
, pDstSurface
, x
, y
, renderTargetArrayIndex
);
118 BUCKETS_STOP(sBuckets
[pDstSurface
->format
]);
122 //////////////////////////////////////////////////////////////////////////
123 /// @brief Sets up tables for StoreTile
124 void InitSimStoreTilesTable()
126 memset(sStoreTilesTableColor
, 0, sizeof(sStoreTilesTableColor
));
127 memset(sStoreTilesTableDepth
, 0, sizeof(sStoreTilesTableDepth
));
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();