Commit f60a2d59 by Alexis Hetu Committed by Alexis Hétu

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/+/31031Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 7b4fc281
......@@ -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 @@ namespace sw
}
State state(format, dstFormat, 1, dest->getSampleCountFlagBits(), { 0xF });
Routine *blitRoutine = getRoutine(state);
Routine *blitRoutine = getBlitRoutine(state);
if(!blitRoutine)
{
return;
......@@ -1531,10 +1531,10 @@ namespace sw
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 @@ namespace sw
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 @@ namespace sw
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 @@ namespace sw
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 @@ namespace sw
(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 @@ namespace sw
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);
......
......@@ -133,8 +133,9 @@ namespace sw
static Int ComputeOffset(Int &x, Int &y, Int &pitchB, int bytes, bool quadLayout);
static Float4 LinearToSRGB(Float4 &color);
static Float4 sRGBtoLinear(Float4 &color);
Routine *getRoutine(const State &state);
Routine *getBlitRoutine(const State &state);
Routine *generate(const State &state);
Routine *getCornerUpdateRoutine(const State &state);
Routine *generateCornerUpdate(const State& state);
void computeCubeCorner(Pointer<Byte>& layer, Int& x0, Int& x1, Int& y0, Int& y1, Int& pitchB, const State& state);
......@@ -142,9 +143,10 @@ namespace sw
const VkImageSubresourceLayers& dstSubresourceLayers, Edge dstEdge,
const VkImageSubresourceLayers& srcSubresourceLayers, Edge srcEdge);
RoutineCache<State> *blitCache;
RoutineCache<State> *cornerUpdateCache;
std::mutex criticalSection;
std::mutex blitMutex;
RoutineCache<State> blitCache; // guarded by blitMutex
std::mutex cornerUpdateMutex;
RoutineCache<State> cornerUpdateCache; // guarded by cornerUpdateMutex
};
}
......
......@@ -14,7 +14,6 @@
#include "Config.hpp"
#include "System/Thread.hpp"
#include "System/Timer.hpp"
namespace sw
......
......@@ -17,14 +17,10 @@
#include "Vulkan/VkConfig.h"
#include "Vulkan/VkDescriptorSet.hpp"
#include "Sampler.hpp"
#include "Config.hpp"
#include "Stream.hpp"
#include "Point.hpp"
#include "Vertex.hpp"
#include "System/Types.hpp"
#include <Vulkan/VkConfig.h>
namespace vk
{
class DescriptorSet;
......@@ -34,14 +30,7 @@ namespace vk
namespace sw
{
struct Sampler;
class PixelShader;
class VertexShader;
class SpirvShader;
struct Triangle;
struct Primitive;
struct Vertex;
class Resource;
enum In // Default input stream semantic
{
......
......@@ -15,6 +15,7 @@
#ifndef sw_PixelProcessor_hpp
#define sw_PixelProcessor_hpp
#include "Color.hpp"
#include "Context.hpp"
#include "RoutineCache.hpp"
......@@ -24,6 +25,7 @@ namespace sw
class Rasterizer;
struct Texture;
struct DrawData;
struct Primitive;
class PixelProcessor
{
......
......@@ -111,9 +111,8 @@ namespace sw
void SwiftConfig::getConfiguration(Configuration &configuration)
{
criticalSection.lock();
std::unique_lock<std::mutex> lock(criticalSection);
configuration = config;
criticalSection.unlock();
}
void SwiftConfig::serverRoutine(void *parameters)
......@@ -186,7 +185,7 @@ namespace sw
{
if(match(&request, " ") || match(&request, "/ "))
{
criticalSection.lock();
std::unique_lock<std::mutex> lock(criticalSection);
const char *postData = strstr(request, "\r\n\r\n");
postData = postData ? postData + 4 : 0;
......@@ -214,7 +213,7 @@ namespace sw
destroyServer();
}
criticalSection.unlock();
lock.unlock();
return send(clientSocket, OK, page());
}
......
......@@ -18,6 +18,7 @@
#include "Matrix.hpp"
#include "Context.hpp"
#include "RoutineCache.hpp"
#include "Vertex.hpp"
#include "Pipeline/SpirvShader.hpp"
namespace sw
......
......@@ -18,6 +18,7 @@
#include "VkConfig.h"
#include "VkObject.hpp"
#include "VkDescriptorSet.hpp"
#include "Device/Color.hpp"
#include "Device/Context.hpp"
#include <memory>
#include <vector>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment