2525
2626namespace sw
2727{
28- Blitter::Blitter ()
28+ Blitter::Blitter () :
29+ blitMutex (),
30+ blitCache (1024 ),
31+ cornerUpdateMutex (),
32+ cornerUpdateCache (64 ) // We only need one of these per format
2933 {
30- blitCache = new RoutineCache<State>(1024 );
31- cornerUpdateCache = new RoutineCache<State>(64 ); // We only need one of these per format
3234 }
3335
3436 Blitter::~Blitter ()
3537 {
36- delete blitCache;
37- delete cornerUpdateCache;
3838 }
3939
4040 void Blitter::clear (void *pixel, vk::Format format, vk::Image *dest, const vk::Format& viewFormat, const VkImageSubresourceRange& subresourceRange, const VkRect2D* renderArea)
@@ -52,7 +52,7 @@ namespace sw
5252 }
5353
5454 State state (format, dstFormat, 1 , dest->getSampleCountFlagBits (), { 0xF });
55- Routine *blitRoutine = getRoutine (state);
55+ Routine *blitRoutine = getBlitRoutine (state);
5656 if (!blitRoutine)
5757 {
5858 return ;
@@ -1531,38 +1531,56 @@ namespace sw
15311531 return function (" BlitRoutine" );
15321532 }
15331533
1534- Routine *Blitter::getRoutine (const State &state)
1534+ Routine *Blitter::getBlitRoutine (const State &state)
15351535 {
1536- criticalSection. lock ();
1537- Routine *blitRoutine = blitCache-> query (state);
1536+ std::unique_lock<std::mutex> lock (blitMutex );
1537+ Routine *blitRoutine = blitCache. query (state);
15381538
15391539 if (!blitRoutine)
15401540 {
15411541 blitRoutine = generate (state);
15421542
15431543 if (!blitRoutine)
15441544 {
1545- criticalSection.unlock ();
15461545 UNIMPLEMENTED (" blitRoutine" );
15471546 return nullptr ;
15481547 }
15491548
1550- blitCache-> add (state, blitRoutine);
1549+ blitCache. add (state, blitRoutine);
15511550 }
15521551
1553- criticalSection.unlock ();
1554-
15551552 return blitRoutine;
15561553 }
15571554
1555+ Routine *Blitter::getCornerUpdateRoutine (const State &state)
1556+ {
1557+ std::unique_lock<std::mutex> lock (cornerUpdateMutex);
1558+ Routine *cornerUpdateRoutine = cornerUpdateCache.query (state);
1559+
1560+ if (!cornerUpdateRoutine)
1561+ {
1562+ cornerUpdateRoutine = generateCornerUpdate (state);
1563+
1564+ if (!cornerUpdateRoutine)
1565+ {
1566+ UNIMPLEMENTED (" cornerUpdateRoutine" );
1567+ return nullptr ;
1568+ }
1569+
1570+ cornerUpdateCache.add (state, cornerUpdateRoutine);
1571+ }
1572+
1573+ return cornerUpdateRoutine;
1574+ }
1575+
15581576 void Blitter::blitToBuffer (const vk::Image *src, VkImageSubresourceLayers subresource, VkOffset3D offset, VkExtent3D extent, uint8_t *dst, int bufferRowPitch, int bufferSlicePitch)
15591577 {
15601578 auto aspect = static_cast <VkImageAspectFlagBits>(subresource.aspectMask );
15611579 auto format = src->getFormat (aspect);
15621580 State state (format, format.getNonQuadLayoutFormat (), VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT,
15631581 {false , false });
15641582
1565- Routine *blitRoutine = getRoutine (state);
1583+ Routine *blitRoutine = getBlitRoutine (state);
15661584 if (!blitRoutine)
15671585 {
15681586 return ;
@@ -1628,7 +1646,7 @@ namespace sw
16281646 State state (format.getNonQuadLayoutFormat (), format, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT,
16291647 {false , false });
16301648
1631- Routine *blitRoutine = getRoutine (state);
1649+ Routine *blitRoutine = getBlitRoutine (state);
16321650 if (!blitRoutine)
16331651 {
16341652 return ;
@@ -1735,7 +1753,7 @@ namespace sw
17351753 (static_cast <uint32_t >(region.srcOffsets [1 ].y ) > srcExtent.height ) ||
17361754 (doFilter && ((x0 < 0 .5f ) || (y0 < 0 .5f )));
17371755
1738- Routine *blitRoutine = getRoutine (state);
1756+ Routine *blitRoutine = getBlitRoutine (state);
17391757 if (!blitRoutine)
17401758 {
17411759 return ;
@@ -1933,25 +1951,12 @@ namespace sw
19331951 UNIMPLEMENTED (" Multi-sampled cube: %d samples" , static_cast <int >(samples));
19341952 }
19351953
1936- criticalSection.lock ();
1937- Routine *cornerUpdateRoutine = cornerUpdateCache->query (state);
1938-
1954+ Routine *cornerUpdateRoutine = getCornerUpdateRoutine (state);
19391955 if (!cornerUpdateRoutine)
19401956 {
1941- cornerUpdateRoutine = generateCornerUpdate (state);
1942-
1943- if (!cornerUpdateRoutine)
1944- {
1945- criticalSection.unlock ();
1946- UNIMPLEMENTED (" cornerUpdateRoutine" );
1947- return ;
1948- }
1949-
1950- cornerUpdateCache->add (state, cornerUpdateRoutine);
1957+ return ;
19511958 }
19521959
1953- criticalSection.unlock ();
1954-
19551960 void (*cornerUpdateFunction)(const CubeBorderData *data) = (void (*)(const CubeBorderData*))cornerUpdateRoutine->getEntry ();
19561961
19571962 VkExtent3D extent = image->getMipLevelExtent (aspect, subresourceLayers.mipLevel );
0 commit comments