summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2016-11-27 11:56:22 +0100
committerLéo Lam <leo@innovatetechnologi.es>2016-12-06 20:33:53 +0100
commit31ccfffd386cdf7bfafdccda240a179431ecc98c (patch)
tree820bdb640091e5726e4c52d42f819956f82bfd28 /Source/Core/VideoBackends/Vulkan
parent7192789c1162e2deb5923151d05158f459448ab9 (diff)
Common: Add alignment header
Gets rid of duplicated alignment code.
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan')
-rw-r--r--Source/Core/VideoBackends/Vulkan/StateTracker.cpp13
-rw-r--r--Source/Core/VideoBackends/Vulkan/Util.cpp12
-rw-r--r--Source/Core/VideoBackends/Vulkan/Util.h1
3 files changed, 9 insertions, 17 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
index 34ea98f41b..e9bbb980b0 100644
--- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
+++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp
@@ -6,6 +6,7 @@
#include <cstring>
+#include "Common/Align.h"
#include "Common/Assert.h"
#include "VideoBackends/Vulkan/CommandBufferManager.h"
@@ -101,11 +102,11 @@ bool StateTracker::Initialize()
// To work around this we reserve the maximum buffer size at all times, but only commit
// as many bytes as we use.
m_uniform_buffer_reserve_size = sizeof(PixelShaderConstants);
- m_uniform_buffer_reserve_size = Util::AlignValue(m_uniform_buffer_reserve_size,
- g_vulkan_context->GetUniformBufferAlignment()) +
+ m_uniform_buffer_reserve_size = Common::AlignUp(m_uniform_buffer_reserve_size,
+ g_vulkan_context->GetUniformBufferAlignment()) +
sizeof(VertexShaderConstants);
- m_uniform_buffer_reserve_size = Util::AlignValue(m_uniform_buffer_reserve_size,
- g_vulkan_context->GetUniformBufferAlignment()) +
+ m_uniform_buffer_reserve_size = Common::AlignUp(m_uniform_buffer_reserve_size,
+ g_vulkan_context->GetUniformBufferAlignment()) +
sizeof(GeometryShaderConstants);
// Default dirty flags include all descriptors
@@ -461,9 +462,9 @@ void StateTracker::UploadAllConstants()
size_t ub_alignment = g_vulkan_context->GetUniformBufferAlignment();
size_t pixel_constants_offset = 0;
size_t vertex_constants_offset =
- Util::AlignValue(pixel_constants_offset + sizeof(PixelShaderConstants), ub_alignment);
+ Common::AlignUp(pixel_constants_offset + sizeof(PixelShaderConstants), ub_alignment);
size_t geometry_constants_offset =
- Util::AlignValue(vertex_constants_offset + sizeof(VertexShaderConstants), ub_alignment);
+ Common::AlignUp(vertex_constants_offset + sizeof(VertexShaderConstants), ub_alignment);
size_t allocation_size = geometry_constants_offset + sizeof(GeometryShaderConstants);
// Allocate everything at once.
diff --git a/Source/Core/VideoBackends/Vulkan/Util.cpp b/Source/Core/VideoBackends/Vulkan/Util.cpp
index f85321bac5..f49ca90580 100644
--- a/Source/Core/VideoBackends/Vulkan/Util.cpp
+++ b/Source/Core/VideoBackends/Vulkan/Util.cpp
@@ -4,6 +4,7 @@
#include "VideoBackends/Vulkan/Util.h"
+#include "Common/Align.h"
#include "Common/Assert.h"
#include "Common/CommonFuncs.h"
#include "Common/MathUtil.h"
@@ -20,22 +21,13 @@ namespace Vulkan
{
namespace Util
{
-size_t AlignValue(size_t value, size_t alignment)
-{
- // Have to use mod rather than masking bits in case alignment is not a power of two.
- size_t offset = value % alignment;
- if (offset != 0)
- value += (alignment - offset);
- return value;
-}
-
size_t AlignBufferOffset(size_t offset, size_t alignment)
{
// Assume an offset of zero is already aligned to a value larger than alignment.
if (offset == 0)
return 0;
- return AlignValue(offset, alignment);
+ return Common::AlignUp(offset, alignment);
}
u32 MakeRGBA8Color(float r, float g, float b, float a)
diff --git a/Source/Core/VideoBackends/Vulkan/Util.h b/Source/Core/VideoBackends/Vulkan/Util.h
index bb701716c2..7ee8e82356 100644
--- a/Source/Core/VideoBackends/Vulkan/Util.h
+++ b/Source/Core/VideoBackends/Vulkan/Util.h
@@ -19,7 +19,6 @@ class StateTracker;
namespace Util
{
-size_t AlignValue(size_t value, size_t alignment);
size_t AlignBufferOffset(size_t offset, size_t alignment);
u32 MakeRGBA8Color(float r, float g, float b, float a);