Commit 463fab94 by Alexis Hetu Committed by Alexis Hétu

Removed the AtomicInt class

Deleted Thread.hpp and replaced AtomicInt with std::atomic<int>. Should be noop. Note: AtomicInt's operator++(int) and operator--(int) were Post-increment operators implemented as Pre-increment operators, so expressions <AtomicInt object>++ have been replaced with ++<std::atomic object> (same for decrement operators). Bug b/129403963 Change-Id: I907b8c91581fed4b76647327f316b87369c6c82f Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33668Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent a29aa771
...@@ -1749,7 +1749,6 @@ file(GLOB_RECURSE VULKAN_LIST ...@@ -1749,7 +1749,6 @@ file(GLOB_RECURSE VULKAN_LIST
${SOURCE_DIR}/System/Socket.cpp ${SOURCE_DIR}/System/Socket.cpp
${SOURCE_DIR}/System/Socket.hpp ${SOURCE_DIR}/System/Socket.hpp
${SOURCE_DIR}/System/Synchronization.hpp ${SOURCE_DIR}/System/Synchronization.hpp
${SOURCE_DIR}/System/Thread.hpp
${SOURCE_DIR}/System/Timer.cpp ${SOURCE_DIR}/System/Timer.cpp
${SOURCE_DIR}/System/Timer.hpp ${SOURCE_DIR}/System/Timer.hpp
${SOURCE_DIR}/Device/*.cpp ${SOURCE_DIR}/Device/*.cpp
......
...@@ -42,9 +42,9 @@ unsigned int maxPrimitives = 1 << 21; ...@@ -42,9 +42,9 @@ unsigned int maxPrimitives = 1 << 21;
namespace sw namespace sw
{ {
static const int batchSize = 128; static const int batchSize = 128;
AtomicInt threadCount(1); std::atomic<int> threadCount(1);
AtomicInt Renderer::unitCount(1); std::atomic<int> Renderer::unitCount(1);
AtomicInt Renderer::clusterCount(1); std::atomic<int> Renderer::clusterCount(1);
template<typename T> template<typename T>
inline bool setBatchIndices(unsigned int batch[128][3], VkPrimitiveTopology topology, T indices, unsigned int start, unsigned int triangleCount) inline bool setBatchIndices(unsigned int batch[128][3], VkPrimitiveTopology topology, T indices, unsigned int start, unsigned int triangleCount)
...@@ -572,7 +572,7 @@ namespace sw ...@@ -572,7 +572,7 @@ namespace sw
// Commit to the task queue // Commit to the task queue
qHead = (qHead + 1) & TASK_COUNT_BITS; qHead = (qHead + 1) & TASK_COUNT_BITS;
qSize++; ++qSize; // Atomic
break; break;
} }
...@@ -613,7 +613,7 @@ namespace sw ...@@ -613,7 +613,7 @@ namespace sw
count = draw->count; count = draw->count;
int batch = draw->batchSize; int batch = draw->batchSize;
primitiveProgress[unit].drawCall = currentDraw; primitiveProgress[unit].drawCall = currentDraw.load();
primitiveProgress[unit].firstPrimitive = primitive; primitiveProgress[unit].firstPrimitive = primitive;
primitiveProgress[unit].primitiveCount = count - primitive >= batch ? batch : count - primitive; primitiveProgress[unit].primitiveCount = count - primitive >= batch ? batch : count - primitive;
...@@ -627,7 +627,7 @@ namespace sw ...@@ -627,7 +627,7 @@ namespace sw
// Commit to the task queue // Commit to the task queue
qHead = (qHead + 1) & TASK_COUNT_BITS; qHead = (qHead + 1) & TASK_COUNT_BITS;
qSize++; ++qSize; // Atomic
} }
} }
} }
...@@ -646,7 +646,7 @@ namespace sw ...@@ -646,7 +646,7 @@ namespace sw
if(qSize != 0) if(qSize != 0)
{ {
task[threadIndex] = taskQueue[(qHead - qSize) & TASK_COUNT_BITS]; task[threadIndex] = taskQueue[(qHead - qSize) & TASK_COUNT_BITS];
qSize--; --qSize; // Atomic
if(curThreadsAwake != threadCount) if(curThreadsAwake != threadCount)
{ {
...@@ -678,7 +678,7 @@ namespace sw ...@@ -678,7 +678,7 @@ namespace sw
void Renderer::executeTask(int threadIndex) void Renderer::executeTask(int threadIndex)
{ {
switch(task[threadIndex].type) switch(task[threadIndex].type.load())
{ {
case Task::PRIMITIVES: case Task::PRIMITIVES:
{ {
...@@ -699,7 +699,7 @@ namespace sw ...@@ -699,7 +699,7 @@ namespace sw
} }
primitiveProgress[unit].visible = visible; primitiveProgress[unit].visible = visible;
primitiveProgress[unit].references = clusterCount; primitiveProgress[unit].references = clusterCount.load();
} }
break; break;
case Task::PIXELS: case Task::PIXELS:
...@@ -754,11 +754,11 @@ namespace sw ...@@ -754,11 +754,11 @@ namespace sw
pixelProgress[cluster].processedPrimitives = 0; pixelProgress[cluster].processedPrimitives = 0;
} }
int ref = primitiveProgress[unit].references--; // Atomic int ref = --primitiveProgress[unit].references; // Atomic
if(ref == 0) if(ref == 0)
{ {
ref = draw.references--; // Atomic ref = --draw.references; // Atomic
if(ref == 0) if(ref == 0)
{ {
...@@ -839,7 +839,7 @@ namespace sw ...@@ -839,7 +839,7 @@ namespace sw
} }
else else
{ {
switch(draw->indexType) switch(draw->indexType.load())
{ {
case VK_INDEX_TYPE_UINT16: case VK_INDEX_TYPE_UINT16:
if(!setBatchIndices(batch, topology, static_cast<const uint16_t*>(indices), start, triangleCount)) if(!setBatchIndices(batch, topology, static_cast<const uint16_t*>(indices), start, triangleCount))
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
#include "Blitter.hpp" #include "Blitter.hpp"
#include "Device/Config.hpp" #include "Device/Config.hpp"
#include "System/Synchronization.hpp" #include "System/Synchronization.hpp"
#include "System/Thread.hpp"
#include "Vulkan/VkDescriptorSet.hpp" #include "Vulkan/VkDescriptorSet.hpp"
#include <atomic>
#include <list> #include <list>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
...@@ -111,9 +111,16 @@ namespace sw ...@@ -111,9 +111,16 @@ namespace sw
SUSPEND SUSPEND
}; };
AtomicInt type; void operator=(const Task& task)
AtomicInt primitiveUnit; {
AtomicInt pixelCluster; type = task.type.load();
primitiveUnit = task.primitiveUnit.load();
pixelCluster = task.pixelCluster.load();
}
std::atomic<int> type;
std::atomic<int> primitiveUnit;
std::atomic<int> pixelCluster;
}; };
struct PrimitiveProgress struct PrimitiveProgress
...@@ -127,11 +134,11 @@ namespace sw ...@@ -127,11 +134,11 @@ namespace sw
references = 0; references = 0;
} }
AtomicInt drawCall; std::atomic<int> drawCall;
AtomicInt firstPrimitive; std::atomic<int> firstPrimitive;
AtomicInt primitiveCount; std::atomic<int> primitiveCount;
AtomicInt visible; std::atomic<int> visible;
AtomicInt references; std::atomic<int> references;
}; };
struct PixelProgress struct PixelProgress
...@@ -143,9 +150,9 @@ namespace sw ...@@ -143,9 +150,9 @@ namespace sw
executing = false; executing = false;
} }
AtomicInt drawCall; std::atomic<int> drawCall;
AtomicInt processedPrimitives; std::atomic<int> processedPrimitives;
AtomicInt executing; std::atomic<int> executing;
}; };
public: public:
...@@ -201,8 +208,8 @@ namespace sw ...@@ -201,8 +208,8 @@ namespace sw
Triangle *triangleBatch[16]; Triangle *triangleBatch[16];
Primitive *primitiveBatch[16]; Primitive *primitiveBatch[16];
AtomicInt exitThreads; std::atomic<int> exitThreads;
AtomicInt threadsAwake; std::atomic<int> threadsAwake;
std::thread *worker[16]; std::thread *worker[16];
Event *resume[16]; // Events for resuming threads Event *resume[16]; // Events for resuming threads
Event *suspend[16]; // Events for suspending threads Event *suspend[16]; // Events for suspending threads
...@@ -219,19 +226,19 @@ namespace sw ...@@ -219,19 +226,19 @@ namespace sw
DrawCall *drawCall[DRAW_COUNT]; DrawCall *drawCall[DRAW_COUNT];
DrawCall *drawList[DRAW_COUNT]; DrawCall *drawList[DRAW_COUNT];
AtomicInt currentDraw; std::atomic<int> currentDraw;
AtomicInt nextDraw; std::atomic<int> nextDraw;
enum { enum {
TASK_COUNT = 32, // Size of the task queue (must be power of 2) TASK_COUNT = 32, // Size of the task queue (must be power of 2)
TASK_COUNT_BITS = TASK_COUNT - 1, TASK_COUNT_BITS = TASK_COUNT - 1,
}; };
Task taskQueue[TASK_COUNT]; Task taskQueue[TASK_COUNT];
AtomicInt qHead; std::atomic<int> qHead;
AtomicInt qSize; std::atomic<int> qSize;
static AtomicInt unitCount; static std::atomic<int> unitCount;
static AtomicInt clusterCount; static std::atomic<int> clusterCount;
std::mutex schedulerMutex; std::mutex schedulerMutex;
...@@ -255,9 +262,9 @@ namespace sw ...@@ -255,9 +262,9 @@ namespace sw
~DrawCall(); ~DrawCall();
AtomicInt topology; std::atomic<int> topology;
AtomicInt indexType; std::atomic<int> indexType;
AtomicInt batchSize; std::atomic<int> batchSize;
Routine *vertexRoutine; Routine *vertexRoutine;
Routine *setupRoutine; Routine *setupRoutine;
...@@ -277,9 +284,9 @@ namespace sw ...@@ -277,9 +284,9 @@ namespace sw
std::list<vk::Query*> *queries; std::list<vk::Query*> *queries;
AtomicInt primitive; // Current primitive to enter pipeline std::atomic<int> primitive; // Current primitive to enter pipeline
AtomicInt count; // Number of primitives to render std::atomic<int> count; // Number of primitives to render
AtomicInt references; // Remaining references to this draw call, 0 when done drawing, -1 when resources unlocked and slot is free std::atomic<int> references; // Remaining references to this draw call, 0 when done drawing, -1 when resources unlocked and slot is free
DrawData *data; DrawData *data;
}; };
......
...@@ -30,7 +30,6 @@ swiftshader_source_set("System") { ...@@ -30,7 +30,6 @@ swiftshader_source_set("System") {
"Memory.hpp", "Memory.hpp",
"Socket.cpp", "Socket.cpp",
"Socket.hpp", "Socket.hpp",
"Thread.hpp",
"Timer.cpp", "Timer.cpp",
"Timer.hpp", "Timer.hpp",
] ]
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_Thread_hpp
#define sw_Thread_hpp
#include <atomic>
namespace sw
{
class AtomicInt
{
public:
AtomicInt() : ai() {}
AtomicInt(int i) : ai(i) {}
inline operator int() const { return ai.load(std::memory_order_acquire); }
inline void operator=(const AtomicInt& i) { ai.store(i.ai.load(std::memory_order_acquire), std::memory_order_release); }
inline void operator=(int i) { ai.store(i, std::memory_order_release); }
inline void operator--() { ai.fetch_sub(1, std::memory_order_acq_rel); }
inline void operator++() { ai.fetch_add(1, std::memory_order_acq_rel); }
inline int operator--(int) { return ai.fetch_sub(1, std::memory_order_acq_rel) - 1; }
inline int operator++(int) { return ai.fetch_add(1, std::memory_order_acq_rel) + 1; }
inline void operator-=(int i) { ai.fetch_sub(i, std::memory_order_acq_rel); }
inline void operator+=(int i) { ai.fetch_add(i, std::memory_order_acq_rel); }
private:
std::atomic<int> ai;
};
}
#endif // sw_Thread_hpp
...@@ -274,7 +274,6 @@ IF EXIST "$(SolutionDir)..\deqp\build\external\vulkancts\modules\vulkan\" (copy ...@@ -274,7 +274,6 @@ IF EXIST "$(SolutionDir)..\deqp\build\external\vulkancts\modules\vulkan\" (copy
<ClInclude Include="..\System\SharedLibrary.hpp" /> <ClInclude Include="..\System\SharedLibrary.hpp" />
<ClInclude Include="..\System\Socket.hpp" /> <ClInclude Include="..\System\Socket.hpp" />
<ClInclude Include="..\System\Synchronization.hpp" /> <ClInclude Include="..\System\Synchronization.hpp" />
<ClInclude Include="..\System\Thread.hpp" />
<ClInclude Include="..\System\Timer.hpp" /> <ClInclude Include="..\System\Timer.hpp" />
<ClInclude Include="..\System\Types.hpp" /> <ClInclude Include="..\System\Types.hpp" />
<ClInclude Include="..\WSI\VkSurfaceKHR.hpp" /> <ClInclude Include="..\WSI\VkSurfaceKHR.hpp" />
......
...@@ -488,9 +488,6 @@ ...@@ -488,9 +488,6 @@
<ClInclude Include="..\System\Synchronization.hpp"> <ClInclude Include="..\System\Synchronization.hpp">
<Filter>Header Files\System</Filter> <Filter>Header Files\System</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\System\Thread.hpp">
<Filter>Header Files\System</Filter>
</ClInclude>
<ClInclude Include="..\System\Timer.hpp"> <ClInclude Include="..\System\Timer.hpp">
<Filter>Header Files\System</Filter> <Filter>Header Files\System</Filter>
</ClInclude> </ClInclude>
......
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