Rework buffers synchronization
This commit is contained in:
@@ -51,6 +51,8 @@ namespace Nz
|
||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, const VkImageSubresourceRange& range);
|
||||
inline void ClearDepthStencilImage(VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue& depthStencil, UInt32 rangeCount, const VkImageSubresourceRange* ranges);
|
||||
|
||||
inline void CopyBuffer(VkBuffer source, VkBuffer target, UInt32 size, UInt32 sourceOffset = 0, UInt32 targetOffset = 0);
|
||||
|
||||
inline void Draw(UInt32 vertexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0);
|
||||
inline void DrawIndexed(UInt32 indexCount, UInt32 instanceCount = 1, UInt32 firstVertex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0);
|
||||
|
||||
|
||||
@@ -194,6 +194,16 @@ namespace Nz
|
||||
return m_pool->GetDevice()->vkCmdClearDepthStencilImage(m_handle, image, imageLayout, &depthStencil, rangeCount, ranges);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::CopyBuffer(VkBuffer source, VkBuffer target, UInt32 size, UInt32 sourceOffset, UInt32 targetOffset)
|
||||
{
|
||||
VkBufferCopy region;
|
||||
region.dstOffset = targetOffset;
|
||||
region.size = size;
|
||||
region.srcOffset = sourceOffset;
|
||||
|
||||
return m_pool->GetDevice()->vkCmdCopyBuffer(m_handle, source, target, 1, ®ion);
|
||||
}
|
||||
|
||||
inline void CommandBuffer::Draw(UInt32 vertexCount, UInt32 instanceCount, UInt32 firstVertex, UInt32 firstInstance)
|
||||
{
|
||||
return m_pool->GetDevice()->vkCmdDraw(m_handle, vertexCount, instanceCount, firstVertex, firstInstance);
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class CommandBuffer;
|
||||
class Instance;
|
||||
class Queue;
|
||||
|
||||
@@ -34,6 +35,8 @@ namespace Nz
|
||||
Device(Device&&) = delete;
|
||||
~Device();
|
||||
|
||||
CommandBuffer AllocateTransferCommandBuffer();
|
||||
|
||||
bool Create(const Vk::PhysicalDevice& deviceInfo, const VkDeviceCreateInfo& createInfo, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline void Destroy();
|
||||
|
||||
@@ -47,6 +50,8 @@ namespace Nz
|
||||
inline VkPhysicalDevice GetPhysicalDevice() const;
|
||||
inline const Vk::PhysicalDevice& GetPhysicalDeviceInfo() const;
|
||||
|
||||
inline UInt32 GetTransferQueueFamilyIndex() const;
|
||||
|
||||
inline bool IsExtensionLoaded(const std::string& extensionName);
|
||||
inline bool IsLayerLoaded(const std::string& layerName);
|
||||
|
||||
@@ -90,11 +95,15 @@ namespace Nz
|
||||
|
||||
inline PFN_vkVoidFunction GetProcAddr(const char* name);
|
||||
|
||||
struct InternalData;
|
||||
|
||||
std::unique_ptr<InternalData> m_internalData;
|
||||
Instance& m_instance;
|
||||
const Vk::PhysicalDevice* m_physicalDevice;
|
||||
VkAllocationCallbacks m_allocator;
|
||||
VkDevice m_device;
|
||||
VkResult m_lastErrorCode;
|
||||
UInt32 m_transferQueueFamilyIndex;
|
||||
std::unordered_set<std::string> m_loadedExtensions;
|
||||
std::unordered_set<std::string> m_loadedLayers;
|
||||
std::vector<QueueFamilyInfo> m_enabledQueuesInfos;
|
||||
|
||||
@@ -49,6 +49,11 @@ namespace Nz
|
||||
return *m_physicalDevice;
|
||||
}
|
||||
|
||||
inline UInt32 Device::GetTransferQueueFamilyIndex() const
|
||||
{
|
||||
return m_transferQueueFamilyIndex;
|
||||
}
|
||||
|
||||
inline bool Device::IsExtensionLoaded(const std::string& extensionName)
|
||||
{
|
||||
return m_loadedExtensions.count(extensionName) > 0;
|
||||
|
||||
@@ -28,6 +28,9 @@ namespace Nz
|
||||
inline bool Create(Device& device, VkDeviceSize size, UInt32 memoryType, const VkAllocationCallbacks* allocator = nullptr);
|
||||
inline bool Create(Device& device, VkDeviceSize size, UInt32 typeBits, VkFlags properties, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline bool FlushMemory();
|
||||
inline bool FlushMemory(UInt64 offset, UInt64 size);
|
||||
|
||||
inline void* GetMappedPointer();
|
||||
|
||||
inline bool Map(VkDeviceSize offset, VkDeviceSize size, VkMemoryMapFlags flags = 0);
|
||||
|
||||
@@ -57,6 +57,31 @@ namespace Nz
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::FlushMemory()
|
||||
{
|
||||
return FlushMemory(0, VK_WHOLE_SIZE);
|
||||
}
|
||||
|
||||
inline bool DeviceMemory::FlushMemory(UInt64 offset, UInt64 size)
|
||||
{
|
||||
VkMappedMemoryRange memoryRange = {
|
||||
VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
|
||||
nullptr,
|
||||
m_handle,
|
||||
offset,
|
||||
size
|
||||
};
|
||||
|
||||
m_lastErrorCode = m_device->vkFlushMappedMemoryRanges(*m_device, 1, &memoryRange);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to flush memory: " + TranslateVulkanError(m_lastErrorCode));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void* DeviceMemory::GetMappedPointer()
|
||||
{
|
||||
return m_mappedPtr;
|
||||
|
||||
Reference in New Issue
Block a user