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 Load
27 ******************************************************************************/
31 static void BUCKETS_START(UINT id
)
33 #ifdef KNOB_ENABLE_RDTSC
34 gBucketMgr
.StartBucket(id
);
38 static void BUCKETS_STOP(UINT id
)
40 #ifdef KNOB_ENABLE_RDTSC
41 gBucketMgr
.StopBucket(id
);
45 // on demand buckets for load tiles
46 static std::vector
<int> sBuckets(NUM_SWR_FORMATS
, -1);
47 static std::mutex sBucketMutex
;
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
57 const SWR_SURFACE_STATE
*pSrcSurface
,
59 SWR_RENDERTARGET_ATTACHMENT renderTargetIndex
,
60 uint32_t x
, uint32_t y
, uint32_t renderTargetArrayIndex
,
63 PFN_LOAD_TILES pfnLoadTiles
= NULL
;
65 // don't need to load null surfaces
66 if (pSrcSurface
->type
== SURFACE_NULL
)
71 // force 0 if requested renderTargetArrayIndex is OOB
72 if (renderTargetArrayIndex
>= pSrcSurface
->depth
)
74 renderTargetArrayIndex
= 0;
77 if (renderTargetIndex
< SWR_ATTACHMENT_DEPTH
)
79 switch (pSrcSurface
->tileMode
)
82 pfnLoadTiles
= sLoadTilesColorTable_SWR_TILE_NONE
[pSrcSurface
->format
];
84 case SWR_TILE_MODE_YMAJOR
:
85 pfnLoadTiles
= sLoadTilesColorTable_SWR_TILE_MODE_YMAJOR
[pSrcSurface
->format
];
87 case SWR_TILE_MODE_XMAJOR
:
88 pfnLoadTiles
= sLoadTilesColorTable_SWR_TILE_MODE_XMAJOR
[pSrcSurface
->format
];
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
;
95 SWR_INVALID("Unsupported tiling mode");
99 else if (renderTargetIndex
== SWR_ATTACHMENT_DEPTH
)
101 // Currently depth can map to linear and tile-y.
102 switch (pSrcSurface
->tileMode
)
105 pfnLoadTiles
= sLoadTilesDepthTable_SWR_TILE_NONE
[pSrcSurface
->format
];
107 case SWR_TILE_MODE_YMAJOR
:
108 pfnLoadTiles
= sLoadTilesDepthTable_SWR_TILE_MODE_YMAJOR
[pSrcSurface
->format
];
111 SWR_INVALID("Unsupported tiling mode");
117 SWR_ASSERT(renderTargetIndex
== SWR_ATTACHMENT_STENCIL
);
118 SWR_ASSERT(pSrcSurface
->format
== R8_UINT
);
119 switch (pSrcSurface
->tileMode
)
122 pfnLoadTiles
= LoadMacroTile
<TilingTraits
<SWR_TILE_NONE
, 8>, R8_UINT
, R8_UINT
>::Load
;
124 case SWR_TILE_MODE_WMAJOR
:
125 pfnLoadTiles
= LoadMacroTile
<TilingTraits
<SWR_TILE_MODE_WMAJOR
, 8>, R8_UINT
, R8_UINT
>::Load
;
128 SWR_INVALID("Unsupported tiling mode");
133 if (pfnLoadTiles
== nullptr)
135 SWR_INVALID("Unsupported format for load tile");
139 // Load a macro tile.
140 #ifdef KNOB_ENABLE_RDTSC
141 if (sBuckets
[pSrcSurface
->format
] == -1)
143 // guard sBuckets update since storetiles is called by multiple threads
145 if (sBuckets
[pSrcSurface
->format
] == -1)
147 const SWR_FORMAT_INFO
& info
= GetFormatInfo(pSrcSurface
->format
);
148 BUCKET_DESC desc
{ info
.name
, "", false, 0xffffffff };
149 sBuckets
[pSrcSurface
->format
] = gBucketMgr
.RegisterBucket(desc
);
151 sBucketMutex
.unlock();
155 BUCKETS_START(sBuckets
[pSrcSurface
->format
]);
156 pfnLoadTiles(pSrcSurface
, pDstHotTile
, x
, y
, renderTargetArrayIndex
);
157 BUCKETS_STOP(sBuckets
[pSrcSurface
->format
]);
161 void InitSimLoadTilesTable()
163 InitLoadTilesTable_Linear();
164 InitLoadTilesTable_XMajor();
165 InitLoadTilesTable_YMajor();