Removed some dependencies on old threading class
- Added separate mutexes for both caches in the Blitter and used
std::mutex instead of MutexLock.
- Removed some now unused inclusions/forward declaration from the
Context class and fixed the fallout of doing that in other files.
- Also moved SwiftConfig to std::thread/std::mutex
- Removed unused inclusions of System/Thread.hpp where possible.
Bug b/132280877
Change-Id: Ic1a992ee3161c141ec1a16471420955c6309f58f
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31031
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index 957f819..ce4a2b0 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -25,16 +25,16 @@
namespace sw
{
- Blitter::Blitter()
+ Blitter::Blitter() :
+ blitMutex(),
+ blitCache(1024),
+ cornerUpdateMutex(),
+ cornerUpdateCache(64) // We only need one of these per format
{
- blitCache = new RoutineCache<State>(1024);
- cornerUpdateCache = new RoutineCache<State>(64); // We only need one of these per format
}
Blitter::~Blitter()
{
- delete blitCache;
- delete cornerUpdateCache;
}
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 @@
}
State state(format, dstFormat, 1, dest->getSampleCountFlagBits(), { 0xF });
- Routine *blitRoutine = getRoutine(state);
+ Routine *blitRoutine = getBlitRoutine(state);
if(!blitRoutine)
{
return;
@@ -1531,10 +1531,10 @@
return function("BlitRoutine");
}
- Routine *Blitter::getRoutine(const State &state)
+ Routine *Blitter::getBlitRoutine(const State &state)
{
- criticalSection.lock();
- Routine *blitRoutine = blitCache->query(state);
+ std::unique_lock<std::mutex> lock(blitMutex);
+ Routine *blitRoutine = blitCache.query(state);
if(!blitRoutine)
{
@@ -1542,19 +1542,37 @@
if(!blitRoutine)
{
- criticalSection.unlock();
UNIMPLEMENTED("blitRoutine");
return nullptr;
}
- blitCache->add(state, blitRoutine);
+ blitCache.add(state, blitRoutine);
}
- criticalSection.unlock();
-
return blitRoutine;
}
+ Routine *Blitter::getCornerUpdateRoutine(const State &state)
+ {
+ std::unique_lock<std::mutex> lock(cornerUpdateMutex);
+ Routine *cornerUpdateRoutine = cornerUpdateCache.query(state);
+
+ if(!cornerUpdateRoutine)
+ {
+ cornerUpdateRoutine = generateCornerUpdate(state);
+
+ if(!cornerUpdateRoutine)
+ {
+ UNIMPLEMENTED("cornerUpdateRoutine");
+ return nullptr;
+ }
+
+ cornerUpdateCache.add(state, cornerUpdateRoutine);
+ }
+
+ return cornerUpdateRoutine;
+ }
+
void Blitter::blitToBuffer(const vk::Image *src, VkImageSubresourceLayers subresource, VkOffset3D offset, VkExtent3D extent, uint8_t *dst, int bufferRowPitch, int bufferSlicePitch)
{
auto aspect = static_cast<VkImageAspectFlagBits>(subresource.aspectMask);
@@ -1562,7 +1580,7 @@
State state(format, format.getNonQuadLayoutFormat(), VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT,
{false, false});
- Routine *blitRoutine = getRoutine(state);
+ Routine *blitRoutine = getBlitRoutine(state);
if(!blitRoutine)
{
return;
@@ -1628,7 +1646,7 @@
State state(format.getNonQuadLayoutFormat(), format, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT,
{false, false});
- Routine *blitRoutine = getRoutine(state);
+ Routine *blitRoutine = getBlitRoutine(state);
if(!blitRoutine)
{
return;
@@ -1735,7 +1753,7 @@
(static_cast<uint32_t>(region.srcOffsets[1].y) > srcExtent.height) ||
(doFilter && ((x0 < 0.5f) || (y0 < 0.5f)));
- Routine *blitRoutine = getRoutine(state);
+ Routine *blitRoutine = getBlitRoutine(state);
if(!blitRoutine)
{
return;
@@ -1933,25 +1951,12 @@
UNIMPLEMENTED("Multi-sampled cube: %d samples", static_cast<int>(samples));
}
- criticalSection.lock();
- Routine *cornerUpdateRoutine = cornerUpdateCache->query(state);
-
+ Routine *cornerUpdateRoutine = getCornerUpdateRoutine(state);
if(!cornerUpdateRoutine)
{
- cornerUpdateRoutine = generateCornerUpdate(state);
-
- if(!cornerUpdateRoutine)
- {
- criticalSection.unlock();
- UNIMPLEMENTED("cornerUpdateRoutine");
- return;
- }
-
- cornerUpdateCache->add(state, cornerUpdateRoutine);
+ return;
}
- criticalSection.unlock();
-
void(*cornerUpdateFunction)(const CubeBorderData *data) = (void(*)(const CubeBorderData*))cornerUpdateRoutine->getEntry();
VkExtent3D extent = image->getMipLevelExtent(aspect, subresourceLayers.mipLevel);