Skip to content

Commit

Permalink
todo: update dynamic buffers right before draw
Browse files Browse the repository at this point in the history
  • Loading branch information
PazerOP committed Jun 13, 2019
1 parent 2b6b1a3 commit 0d2d5db
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 345 deletions.
1 change: 1 addition & 0 deletions TF2VulkanUtil/TF2VulkanUtil.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<ClInclude Include="include\TF2Vulkan\Util\interface.h" />
<ClInclude Include="include\TF2Vulkan\Util\KeyValues.h" />
<ClInclude Include="include\TF2Vulkan\Util\MemoryPool.h" />
<ClInclude Include="include\TF2Vulkan\Util\Misc.h" />
<ClInclude Include="include\TF2Vulkan\Util\MutexWrapper.h" />
<ClInclude Include="include\TF2Vulkan\Util\platform.h" />
<ClInclude Include="include\TF2Vulkan\Util\SafeConvert.h" />
Expand Down
17 changes: 17 additions & 0 deletions TF2VulkanUtil/include/TF2Vulkan/Util/Misc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <cstddef>
#include <type_traits>

namespace Util
{
template<typename T, typename TOffset, typename = std::enable_if_t<std::is_integral_v<TOffset>>>
__forceinline T* OffsetPtr(T* base, TOffset offset)
{
if (!base)
return base;

using byteType = std::conditional_t<std::is_const_v<T>, const std::byte*, std::byte*>;
return reinterpret_cast<T*>(reinterpret_cast<byteType>(base) + offset);
}
}
4 changes: 3 additions & 1 deletion TF2VulkanUtil/include/TF2Vulkan/Util/Threads.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Threads.h"

#include <tier0/threadtools.h>
#include <thread>

static const auto& GetMainThreadID()
Expand All @@ -10,5 +11,6 @@ static const auto& GetMainThreadID()

bool Util::IsMainThread()
{
return std::this_thread::get_id() == GetMainThreadID();
return ThreadInMainThread();
//return std::this_thread::get_id() == GetMainThreadID();
}
4 changes: 2 additions & 2 deletions TF2VulkanUtil/include/TF2Vulkan/Util/std_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ namespace Util{ namespace algorithm
inline constexpr auto max(const T1& t1, const T2& t2)
{
using CT = std::common_type_t<T1, T2>;
return std::max<CT>(CT(t1), CT(t2));
return std::max<CT>(Util::SafeConvert<CT>(t1), Util::SafeConvert<CT>(t2));
}
template<typename T1, typename T2>
inline constexpr auto min(const T1& t1, const T2& t2)
{
using CT = std::common_type_t<T1, T2>;
return std::min<CT>(CT(t1), CT(t2));
return std::min<CT>(Util::SafeConvert<CT>(t1), Util::SafeConvert<CT>(t2));
}
} }
11 changes: 10 additions & 1 deletion shaderapivulkan/include/TF2Vulkan/IBufferPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace TF2Vulkan
size_t GetOffset() const { assert(m_Pool); return m_Offset; }

template<typename T> BufferPoolEntry& Update(const T& data);
BufferPoolEntry& Update(const void* data, size_t size);

operator bool() const { return !!m_Pool; }

Expand Down Expand Up @@ -63,10 +64,18 @@ namespace TF2Vulkan
}
};

inline BufferPoolEntry& BufferPoolEntry::Update(const void* data, size_t size)
{
assert(size <= m_Size);
GetPool().Update(data, size, m_Offset);
return *this;
}

template<typename T>
inline BufferPoolEntry& BufferPoolEntry::Update(const T& data)
{
GetPool().Update(*this, data);
static_assert(!std::is_pointer_v<T>);
Update(&data, sizeof(data));
return *this;
}
}
1 change: 1 addition & 0 deletions shaderapivulkan/src/TF2Vulkan/BufferPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ vma::AllocatedBuffer BufferPoolContiguous::CreateBackingBuffer(vk::BufferUsageFl
.SetSize(m_BackingBufferSize)
.SetMemoryRequiredFlags(vk::MemoryPropertyFlagBits::eHostCoherent | vk::MemoryPropertyFlagBits::eHostVisible)
.SetAllowMapping()
.SetDebugName("BufferPoolContiguous "s + vk::to_string(usage))
.Create();
}

Expand Down
Loading

0 comments on commit 0d2d5db

Please sign in to comment.