Add and make use of Vulkan Memory Allocator

This commit is contained in:
Lynix
2020-03-26 21:15:49 +01:00
parent 509c392e05
commit b73d3e8f04
13 changed files with 18536 additions and 119 deletions

View File

@@ -1,44 +0,0 @@
// Copyright (C) 2020 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HARDWAREBUFFER_HPP
#define NAZARA_HARDWAREBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Utility/AbstractBuffer.hpp>
namespace Nz
{
class Buffer;
class HardwareBuffer : public AbstractBuffer
{
public:
HardwareBuffer(Buffer* parent, BufferType type);
~HardwareBuffer();
bool Fill(const void* data, UInt32 offset, UInt32 size) override;
bool Initialize(unsigned int size, BufferUsageFlags usage) override;
DataStorage GetStorage() const override;
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) override;
bool Unmap() override;
// Fonctions OpenGL
void Bind() const;
GLuint GetOpenGLID() const;
private:
GLuint m_buffer;
BufferType m_type;
Buffer* m_parent;
};
}
#endif // NAZARA_HARDWAREBUFFER_HPP

View File

@@ -31,11 +31,10 @@ namespace Nz
AbstractBuffer* RenderBuffer::GetHardwareBuffer(RenderDevice* device)
{
auto it = m_hardwareBuffers.find(device);
if (it == m_hardwareBuffers.end())
return nullptr;
if (HardwareBuffer* hwBuffer = GetHardwareBufferData(device))
return hwBuffer->buffer.get();
return it->second.buffer.get();
return nullptr;
}
DataStorage RenderBuffer::GetStorage() const
@@ -65,6 +64,18 @@ namespace Nz
}
bool RenderBuffer::Synchronize(RenderDevice* device)
{
HardwareBuffer* hwBuffer = GetHardwareBufferData(device);
if (!hwBuffer)
return false;
if (hwBuffer->synchronized)
return true;
return hwBuffer->buffer->Fill(m_softwareBuffer.GetData(), 0, m_size);
}
auto RenderBuffer::GetHardwareBufferData(RenderDevice* device) -> HardwareBuffer*
{
auto it = m_hardwareBuffers.find(device);
if (it == m_hardwareBuffers.end())
@@ -74,16 +85,13 @@ namespace Nz
if (!hwBuffer.buffer->Initialize(m_size, m_usage))
{
NazaraError("Failed to initialize hardware buffer");
return false;
return nullptr;
}
it = m_hardwareBuffers.emplace(device, std::move(hwBuffer)).first;
}
HardwareBuffer& hwBuffer = it->second;
if (hwBuffer.synchronized)
return true;
return hwBuffer.buffer->Fill(m_softwareBuffer.GetData(), 0, m_size);
return &it->second;
}
}