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
${SOURCE_DIR}/System/Socket.cpp
${SOURCE_DIR}/System/Socket.hpp
${SOURCE_DIR}/System/Synchronization.hpp
${SOURCE_DIR}/System/Thread.hpp
${SOURCE_DIR}/System/Timer.cpp
${SOURCE_DIR}/System/Timer.hpp
${SOURCE_DIR}/Device/*.cpp
......
......@@ -42,9 +42,9 @@ unsigned int maxPrimitives = 1 << 21;
namespace sw
{
static const int batchSize = 128;
AtomicInt threadCount(1);
AtomicInt Renderer::unitCount(1);
AtomicInt Renderer::clusterCount(1);
std::atomic<int> threadCount(1);
std::atomic<int> Renderer::unitCount(1);
std::atomic<int> Renderer::clusterCount(1);
template<typename T>
inline bool setBatchIndices(unsigned int batch[128][3], VkPrimitiveTopology topology, T indices, unsigned int start, unsigned int triangleCount)
......@@ -572,7 +572,7 @@ namespace sw
// Commit to the task queue
qHead = (qHead + 1) & TASK_COUNT_BITS;
qSize++;
++qSize; // Atomic
break;
}
......@@ -613,7 +613,7 @@ namespace sw
count = draw->count;
int batch = draw->batchSize;
primitiveProgress[unit].drawCall = currentDraw;
primitiveProgress[unit].drawCall = currentDraw.load();
primitiveProgress[unit].firstPrimitive = primitive;
primitiveProgress[unit].primitiveCount = count - primitive >= batch ? batch : count - primitive;
......@@ -627,7 +627,7 @@ namespace sw
// Commit to the task queue
qHead = (qHead + 1) & TASK_COUNT_BITS;
qSize++;
++qSize; // Atomic
}
}
}
......@@ -646,7 +646,7 @@ namespace sw
if(qSize != 0)
{
task[threadIndex] = taskQueue[(qHead - qSize) & TASK_COUNT_BITS];
qSize--;
--qSize; // Atomic
if(curThreadsAwake != threadCount)
{
......@@ -678,7 +678,7 @@ namespace sw
void Renderer::executeTask(int threadIndex)
{
switch(task[threadIndex].type)
switch(task[threadIndex].type.load())
{
case Task::PRIMITIVES:
{
......@@ -699,7 +699,7 @@ namespace sw
}
primitiveProgress[unit].visible = visible;
primitiveProgress[unit].references = clusterCount;
primitiveProgress[unit].references = clusterCount.load();
}
break;
case Task::PIXELS:
......@@ -754,11 +754,11 @@ namespace sw
pixelProgress[cluster].processedPrimitives = 0;
}
int ref = primitiveProgress[unit].references--; // Atomic
int ref = --primitiveProgress[unit].references; // Atomic
if(ref == 0)
{
ref = draw.references--; // Atomic
ref = --draw.references; // Atomic
if(ref == 0)
{
......@@ -839,7 +839,7 @@ namespace sw
}
else
{
switch(draw->indexType)
switch(draw->indexType.load())
{
case VK_INDEX_TYPE_UINT16:
if(!setBatchIndices(batch, topology, static_cast<const uint16_t*>(indices), start, triangleCount))
......
......@@ -22,9 +22,9 @@
#include "Blitter.hpp"
#include "Device/Config.hpp"
#include "System/Synchronization.hpp"
#include "System/Thread.hpp"
#include "Vulkan/VkDescriptorSet.hpp"
#include <atomic>
#include <list>
#include <mutex>
#include <thread>
......@@ -111,9 +111,16 @@ namespace sw
SUSPEND
};
AtomicInt type;
AtomicInt primitiveUnit;
AtomicInt pixelCluster;
void operator=(const Task& task)
{
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
......@@ -127,11 +134,11 @@ namespace sw
references = 0;
}
AtomicInt drawCall;
AtomicInt firstPrimitive;
AtomicInt primitiveCount;
AtomicInt visible;
AtomicInt references;
std::atomic<int> drawCall;
std::atomic<int> firstPrimitive;
std::atomic<int> primitiveCount;
std::atomic<int> visible;
std::atomic<int> references;
};
struct PixelProgress
......@@ -143,9 +150,9 @@ namespace sw
executing = false;
}
AtomicInt drawCall;
AtomicInt processedPrimitives;
AtomicInt executing;
std::atomic<int> drawCall;
std::atomic<int> processedPrimitives;
std::atomic<int> executing;
};
public:
......@@ -201,8 +208,8 @@ namespace sw
Triangle *triangleBatch[16];
Primitive *primitiveBatch[16];
AtomicInt exitThreads;
AtomicInt threadsAwake;
std::atomic<int> exitThreads;
std::atomic<int> threadsAwake;
std::thread *worker[16];
Event *resume[16]; // Events for resuming threads
Event *suspend[16]; // Events for suspending threads
......@@ -219,19 +226,19 @@ namespace sw
DrawCall *drawCall[DRAW_COUNT];
DrawCall *drawList[DRAW_COUNT];
AtomicInt currentDraw;
AtomicInt nextDraw;
std::atomic<int> currentDraw;
std::atomic<int> nextDraw;
enum {
TASK_COUNT = 32, // Size of the task queue (must be power of 2)
TASK_COUNT_BITS = TASK_COUNT - 1,
};
Task taskQueue[TASK_COUNT];
AtomicInt qHead;
AtomicInt qSize;
std::atomic<int> qHead;
std::atomic<int> qSize;
static AtomicInt unitCount;
static AtomicInt clusterCount;
static std::atomic<int> unitCount;
static std::atomic<int> clusterCount;
std::mutex schedulerMutex;
......@@ -255,9 +262,9 @@ namespace sw
~DrawCall();
AtomicInt topology;
AtomicInt indexType;
AtomicInt batchSize;
std::atomic<int> topology;
std::atomic<int> indexType;
std::atomic<int> batchSize;
Routine *vertexRoutine;
Routine *setupRoutine;
......@@ -277,9 +284,9 @@ namespace sw
std::list<vk::Query*> *queries;
AtomicInt primitive; // Current primitive to enter pipeline
AtomicInt 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> primitive; // Current primitive to enter pipeline
std::atomic<int> count; // Number of primitives to render
std::atomic<int> references; // Remaining references to this draw call, 0 when done drawing, -1 when resources unlocked and slot is free
DrawData *data;
};
......
......@@ -30,7 +30,6 @@ swiftshader_source_set("System") {
"Memory.hpp",
"Socket.cpp",
"Socket.hpp",
"Thread.hpp",
"Timer.cpp",
"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
<ClInclude Include="..\System\SharedLibrary.hpp" />
<ClInclude Include="..\System\Socket.hpp" />
<ClInclude Include="..\System\Synchronization.hpp" />
<ClInclude Include="..\System\Thread.hpp" />
<ClInclude Include="..\System\Timer.hpp" />
<ClInclude Include="..\System\Types.hpp" />
<ClInclude Include="..\WSI\VkSurfaceKHR.hpp" />
......
......@@ -488,9 +488,6 @@
<ClInclude Include="..\System\Synchronization.hpp">
<Filter>Header Files\System</Filter>
</ClInclude>
<ClInclude Include="..\System\Thread.hpp">
<Filter>Header Files\System</Filter>
</ClInclude>
<ClInclude Include="..\System\Timer.hpp">
<Filter>Header Files\System</Filter>
</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