Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f60a2d5

Browse files
committed
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>
1 parent 7b4fc28 commit f60a2d5

File tree

8 files changed

+50
-52
lines changed

8 files changed

+50
-52
lines changed

src/Device/Blitter.cpp

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525

2626
namespace 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);

src/Device/Blitter.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,20 @@ namespace sw
133133
static Int ComputeOffset(Int &x, Int &y, Int &pitchB, int bytes, bool quadLayout);
134134
static Float4 LinearToSRGB(Float4 &color);
135135
static Float4 sRGBtoLinear(Float4 &color);
136-
Routine *getRoutine(const State &state);
136+
Routine *getBlitRoutine(const State &state);
137137
Routine *generate(const State &state);
138+
Routine *getCornerUpdateRoutine(const State &state);
138139
Routine *generateCornerUpdate(const State& state);
139140
void computeCubeCorner(Pointer<Byte>& layer, Int& x0, Int& x1, Int& y0, Int& y1, Int& pitchB, const State& state);
140141

141142
void copyCubeEdge(vk::Image* image,
142143
const VkImageSubresourceLayers& dstSubresourceLayers, Edge dstEdge,
143144
const VkImageSubresourceLayers& srcSubresourceLayers, Edge srcEdge);
144145

145-
RoutineCache<State> *blitCache;
146-
RoutineCache<State> *cornerUpdateCache;
147-
std::mutex criticalSection;
146+
std::mutex blitMutex;
147+
RoutineCache<State> blitCache; // guarded by blitMutex
148+
std::mutex cornerUpdateMutex;
149+
RoutineCache<State> cornerUpdateCache; // guarded by cornerUpdateMutex
148150
};
149151
}
150152

src/Device/Config.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "Config.hpp"
1616

17-
#include "System/Thread.hpp"
1817
#include "System/Timer.hpp"
1918

2019
namespace sw

src/Device/Context.hpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717

1818
#include "Vulkan/VkConfig.h"
1919
#include "Vulkan/VkDescriptorSet.hpp"
20-
#include "Sampler.hpp"
20+
#include "Config.hpp"
2121
#include "Stream.hpp"
22-
#include "Point.hpp"
23-
#include "Vertex.hpp"
2422
#include "System/Types.hpp"
2523

26-
#include <Vulkan/VkConfig.h>
27-
2824
namespace vk
2925
{
3026
class DescriptorSet;
@@ -34,14 +30,7 @@ namespace vk
3430

3531
namespace sw
3632
{
37-
struct Sampler;
38-
class PixelShader;
39-
class VertexShader;
4033
class SpirvShader;
41-
struct Triangle;
42-
struct Primitive;
43-
struct Vertex;
44-
class Resource;
4534

4635
enum In // Default input stream semantic
4736
{

src/Device/PixelProcessor.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef sw_PixelProcessor_hpp
1616
#define sw_PixelProcessor_hpp
1717

18+
#include "Color.hpp"
1819
#include "Context.hpp"
1920
#include "RoutineCache.hpp"
2021

@@ -24,6 +25,7 @@ namespace sw
2425
class Rasterizer;
2526
struct Texture;
2627
struct DrawData;
28+
struct Primitive;
2729

2830
class PixelProcessor
2931
{

src/Device/SwiftConfig.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ namespace sw
111111

112112
void SwiftConfig::getConfiguration(Configuration &configuration)
113113
{
114-
criticalSection.lock();
114+
std::unique_lock<std::mutex> lock(criticalSection);
115115
configuration = config;
116-
criticalSection.unlock();
117116
}
118117

119118
void SwiftConfig::serverRoutine(void *parameters)
@@ -186,7 +185,7 @@ namespace sw
186185
{
187186
if(match(&request, " ") || match(&request, "/ "))
188187
{
189-
criticalSection.lock();
188+
std::unique_lock<std::mutex> lock(criticalSection);
190189

191190
const char *postData = strstr(request, "\r\n\r\n");
192191
postData = postData ? postData + 4 : 0;
@@ -214,7 +213,7 @@ namespace sw
214213
destroyServer();
215214
}
216215

217-
criticalSection.unlock();
216+
lock.unlock();
218217

219218
return send(clientSocket, OK, page());
220219
}

src/Device/VertexProcessor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "Matrix.hpp"
1919
#include "Context.hpp"
2020
#include "RoutineCache.hpp"
21+
#include "Vertex.hpp"
2122
#include "Pipeline/SpirvShader.hpp"
2223

2324
namespace sw

src/Vulkan/VkCommandBuffer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "VkConfig.h"
1919
#include "VkObject.hpp"
2020
#include "VkDescriptorSet.hpp"
21+
#include "Device/Color.hpp"
2122
#include "Device/Context.hpp"
2223
#include <memory>
2324
#include <vector>

0 commit comments

Comments
 (0)