Commit fb05bcba by Jamie Madill Committed by Commit Bot

Move the vk Serial class to renderer_utils.

This can be useful for other back-ends, for various types of state management. Also redesign the class to use an opaque factory instead of an increment operator. The class maintains the property of being ordered. Also assume we don't overflow with 64-bit serials. We could maybe redesign this to use 32-bit serials for memory constrained situations, and handle overflow more gracefully. I plan to use the serials to track state revisions for the vertex array class, to avoid doing redundant work. BUG=angleproject:1156 Change-Id: I02c78b228bc6e2fb3ee786fe67a4e607baaca18e Reviewed-on: https://chromium-review.googlesource.com/529704Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent c174db3a
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
#include <array> #include <array>
#include "common/debug.h"
#include "common/MemoryBuffer.h" #include "common/MemoryBuffer.h"
#include "common/debug.h"
#include "libANGLE/ContextState.h" #include "libANGLE/ContextState.h"
#include "libANGLE/Device.h" #include "libANGLE/Device.h"
#include "libANGLE/Version.h"
#include "libANGLE/WorkerThread.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/VertexDataManager.h" #include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h" #include "libANGLE/renderer/d3d/formatutilsD3D.h"
#include "libANGLE/Version.h"
#include "libANGLE/WorkerThread.h"
#include "platform/WorkaroundsD3D.h" #include "platform/WorkaroundsD3D.h"
namespace egl namespace egl
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "common/bitset_utils.h" #include "common/bitset_utils.h"
#include "libANGLE/renderer/d3d/d3d11/Buffer11.h" #include "libANGLE/renderer/d3d/d3d11/Buffer11.h"
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
using namespace angle; using namespace angle;
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <limits> #include <limits>
#include <map> #include <map>
#include "common/angleutils.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
namespace angle namespace angle
...@@ -47,6 +48,43 @@ class ResourceSerial ...@@ -47,6 +48,43 @@ class ResourceSerial
uintptr_t mValue; uintptr_t mValue;
}; };
class SerialFactory;
class Serial final
{
public:
constexpr Serial() : mValue(0) {}
constexpr Serial(const Serial &other) = default;
Serial &operator=(const Serial &other) = default;
constexpr bool operator==(const Serial &other) const { return mValue == other.mValue; }
constexpr bool operator!=(const Serial &other) const { return mValue != other.mValue; }
constexpr bool operator>(const Serial &other) const { return mValue > other.mValue; }
constexpr bool operator>=(const Serial &other) const { return mValue >= other.mValue; }
constexpr bool operator<(const Serial &other) const { return mValue < other.mValue; }
constexpr bool operator<=(const Serial &other) const { return mValue <= other.mValue; }
private:
friend class SerialFactory;
constexpr explicit Serial(uint64_t value) : mValue(value) {}
uint64_t mValue;
};
class SerialFactory final : angle::NonCopyable
{
public:
SerialFactory() : mSerial(1) {}
Serial generate()
{
ASSERT(mSerial != std::numeric_limits<uint64_t>::max());
return Serial(mSerial++);
}
private:
uint64_t mSerial;
};
using MipGenerationFunction = void (*)(size_t sourceWidth, using MipGenerationFunction = void (*)(size_t sourceWidth,
size_t sourceHeight, size_t sourceHeight,
size_t sourceDepth, size_t sourceDepth,
......
...@@ -95,11 +95,10 @@ RendererVk::RendererVk() ...@@ -95,11 +95,10 @@ RendererVk::RendererVk()
mDevice(VK_NULL_HANDLE), mDevice(VK_NULL_HANDLE),
mHostVisibleMemoryIndex(std::numeric_limits<uint32_t>::max()), mHostVisibleMemoryIndex(std::numeric_limits<uint32_t>::max()),
mGlslangWrapper(nullptr), mGlslangWrapper(nullptr),
mCurrentQueueSerial(), mLastCompletedQueueSerial(mQueueSerialFactory.generate()),
mLastCompletedQueueSerial(), mCurrentQueueSerial(mQueueSerialFactory.generate()),
mInFlightCommands() mInFlightCommands()
{ {
++mCurrentQueueSerial;
} }
RendererVk::~RendererVk() RendererVk::~RendererVk()
...@@ -732,7 +731,8 @@ vk::Error RendererVk::submit(const VkSubmitInfo &submitInfo) ...@@ -732,7 +731,8 @@ vk::Error RendererVk::submit(const VkSubmitInfo &submitInfo)
ASSERT(mInFlightCommands.size() < 1000u); ASSERT(mInFlightCommands.size() < 1000u);
// Increment the queue serial. If this fails, we should restart ANGLE. // Increment the queue serial. If this fails, we should restart ANGLE.
ANGLE_VK_CHECK(++mCurrentQueueSerial, VK_ERROR_OUT_OF_HOST_MEMORY); // TODO(jmadill): Overflow check.
mCurrentQueueSerial = mQueueSerialFactory.generate();
return vk::NoError(); return vk::NoError();
} }
...@@ -757,7 +757,8 @@ vk::Error RendererVk::submitFrame(const VkSubmitInfo &submitInfo) ...@@ -757,7 +757,8 @@ vk::Error RendererVk::submitFrame(const VkSubmitInfo &submitInfo)
ASSERT(mInFlightCommands.size() < 1000u); ASSERT(mInFlightCommands.size() < 1000u);
// Increment the queue serial. If this fails, we should restart ANGLE. // Increment the queue serial. If this fails, we should restart ANGLE.
ANGLE_VK_CHECK(++mCurrentQueueSerial, VK_ERROR_OUT_OF_HOST_MEMORY); // TODO(jmadill): Overflow check.
mCurrentQueueSerial = mQueueSerialFactory.generate();
ANGLE_TRY(checkInFlightCommands()); ANGLE_TRY(checkInFlightCommands());
......
...@@ -124,8 +124,9 @@ class RendererVk : angle::NonCopyable ...@@ -124,8 +124,9 @@ class RendererVk : angle::NonCopyable
vk::CommandBuffer mCommandBuffer; vk::CommandBuffer mCommandBuffer;
uint32_t mHostVisibleMemoryIndex; uint32_t mHostVisibleMemoryIndex;
GlslangWrapper *mGlslangWrapper; GlslangWrapper *mGlslangWrapper;
Serial mCurrentQueueSerial; SerialFactory mQueueSerialFactory;
Serial mLastCompletedQueueSerial; Serial mLastCompletedQueueSerial;
Serial mCurrentQueueSerial;
std::vector<vk::CommandBufferAndSerial> mInFlightCommands; std::vector<vk::CommandBufferAndSerial> mInFlightCommands;
std::vector<vk::FenceAndSerial> mInFlightFences; std::vector<vk::FenceAndSerial> mInFlightFences;
std::vector<std::unique_ptr<vk::IGarbageObject>> mGarbage; std::vector<std::unique_ptr<vk::IGarbageObject>> mGarbage;
......
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "common/debug.h"
#include "common/Optional.h" #include "common/Optional.h"
#include "common/debug.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/renderer/renderer_utils.h"
namespace gl namespace gl
{ {
...@@ -47,35 +48,6 @@ enum DeleteSchedule ...@@ -47,35 +48,6 @@ enum DeleteSchedule
LATER, LATER,
}; };
// A serial supports a few operations - comparison, increment, and assignment.
// TODO(jmadill): Verify it's not easy to overflow the queue serial.
class Serial final
{
public:
Serial() : mValue(0) {}
Serial(const Serial &other) : mValue(other.mValue) {}
Serial(Serial &&other) : mValue(other.mValue) { other.mValue = 0; }
Serial &operator=(const Serial &other)
{
mValue = other.mValue;
return *this;
}
bool operator>=(Serial other) const { return mValue >= other.mValue; }
bool operator>(Serial other) const { return mValue > other.mValue; }
// This function fails if we're at the limits of our counting.
bool operator++()
{
if (mValue == std::numeric_limits<uint32_t>::max())
return false;
mValue++;
return true;
}
private:
uint32_t mValue;
};
// This is a small helper mixin for any GL object used in Vk command buffers. It records a serial // This is a small helper mixin for any GL object used in Vk command buffers. It records a serial
// at command submission times indicating it's order in the queue. We will use Fences to detect // at command submission times indicating it's order in the queue. We will use Fences to detect
// when commands are finished, and then handle lifetime management for the resources. // when commands are finished, and then handle lifetime management for the resources.
......
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