Merge pull request 'Fix issues with rendering' (#22) from render_fixes into master
Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/22
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <memory>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#include <functional>
|
||||
#include "Base/Utils.hpp"
|
||||
|
||||
namespace OpenVulkano::Vulkan
|
||||
{
|
||||
@@ -44,6 +45,11 @@ namespace OpenVulkano::Vulkan
|
||||
return size - used;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t FreeSpace(size_t alignment) const
|
||||
{
|
||||
return size - Utils::Align(used, alignment);
|
||||
}
|
||||
|
||||
void HandleChildMappingValidation() const;
|
||||
|
||||
void* Map()
|
||||
|
||||
@@ -309,11 +309,11 @@ namespace OpenVulkano::Vulkan
|
||||
vk::Buffer buffer = device.createBuffer(bufferCreateInfo);
|
||||
const vk::MemoryRequirements memoryRequirements = device.getBufferMemoryRequirements(buffer);
|
||||
uint32_t memtype = context->device->GetMemoryType(memoryRequirements.memoryTypeBits, properties);
|
||||
if (memoryRequirements.size != size) Logger::DATA->warn("Memory Requirement Size ({0}) != Size ({1})", memoryRequirements.size, size);
|
||||
MemoryAllocation* allocation = GetFreeMemoryAllocation(memoryRequirements.size, memtype);
|
||||
uint32_t offset = allocation->used;
|
||||
if (memoryRequirements.size != size) Logger::DATA->debug("Memory Requirement Size ({0}) != Size ({1})", memoryRequirements.size, size);
|
||||
MemoryAllocation* allocation = GetFreeMemoryAllocation(memoryRequirements.size, memoryRequirements.alignment, memtype);
|
||||
uint32_t offset = Utils::Align(allocation->used, memoryRequirements.alignment);
|
||||
device.bindBufferMemory(buffer, allocation->memory, offset);
|
||||
allocation->used += memoryRequirements.size;
|
||||
allocation->used += memoryRequirements.size + (offset - allocation->used);
|
||||
return new ManagedBuffer{ allocation, offset, size, buffer, usage, properties, nullptr };
|
||||
}
|
||||
|
||||
@@ -326,12 +326,12 @@ namespace OpenVulkano::Vulkan
|
||||
return alloc;
|
||||
}
|
||||
|
||||
MemoryAllocation* ResourceManager::GetFreeMemoryAllocation(size_t size, uint32_t type, bool createIfAllFull)
|
||||
MemoryAllocation* ResourceManager::GetFreeMemoryAllocation(size_t size, vk::DeviceSize alignment, uint32_t type, bool createIfAllFull)
|
||||
{
|
||||
MemoryAllocation* alloc = nullptr;
|
||||
for (auto& allocation : allocations)
|
||||
{
|
||||
if (allocation->type == type && allocation->FreeSpace() >= size)
|
||||
if (allocation->type == type && allocation->FreeSpace(alignment) >= size)
|
||||
{
|
||||
alloc = allocation.get();
|
||||
break;
|
||||
@@ -345,6 +345,7 @@ namespace OpenVulkano::Vulkan
|
||||
VulkanShader* ResourceManager::CreateShader(Scene::Shader* shader)
|
||||
{
|
||||
const std::unique_lock lock(mutex);
|
||||
if (shader->renderShader) return static_cast<VulkanShader*>(shader->renderShader);
|
||||
VulkanShader* vkShader = new VulkanShader();
|
||||
vkShader->Init(context, shader, this);
|
||||
shaders.emplace_back(vkShader);
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace OpenVulkano
|
||||
|
||||
MemoryAllocation* CreateMemoryAllocation(size_t size, uint32_t type, bool addToCache = true);
|
||||
|
||||
MemoryAllocation* GetFreeMemoryAllocation(size_t size, uint32_t type, bool createIfAllFull = true);
|
||||
MemoryAllocation* GetFreeMemoryAllocation(size_t size, size_t alignment, uint32_t type, bool createIfAllFull = true);
|
||||
|
||||
vk::DescriptorSetLayout* GetDescriptorLayoutSet(const DescriptorSetLayoutBinding& descriptorSetLayoutBinding);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace OpenVulkano::Vulkan
|
||||
writeDescriptorSet.pBufferInfo = &bufferInfo;
|
||||
buffer->allocation->device.updateDescriptorSets(1, &writeDescriptorSet, 0, nullptr);
|
||||
m_setOffset = setId;
|
||||
m_dynamic = binding.descriptorType == DescriptorSetLayoutBinding::TYPE_UNIFORM_BUFFER_DYNAMIC || binding.descriptorType == DescriptorSetLayoutBinding::TYPE_STORAGE_BUFFER_DYNAMIC;
|
||||
}
|
||||
|
||||
void UniformBuffer::Close()
|
||||
@@ -36,7 +37,7 @@ namespace OpenVulkano::Vulkan
|
||||
void UniformBuffer::Record(VulkanDrawContext* drawContext)
|
||||
{
|
||||
uint32_t frameOffset = m_frameOffset * drawContext->currentImageId;
|
||||
drawContext->commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, drawContext->GetShader()->pipelineLayout, m_setOffset, m_setCount, &m_descriptorSet, (m_frameOffset) ? 1 : 0, &frameOffset);
|
||||
drawContext->commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, drawContext->GetShader()->pipelineLayout, m_setOffset, m_setCount, &m_descriptorSet, (m_dynamic) ? 1 : 0, &frameOffset);
|
||||
}
|
||||
|
||||
void UniformBuffer::Update(void* data, uint32_t size, uint32_t bufferId) const
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace OpenVulkano::Vulkan
|
||||
vk::DescriptorSet m_descriptorSet;
|
||||
uint32_t m_frameOffset;
|
||||
uint32_t m_setOffset, m_setCount = 1;
|
||||
bool m_dynamic;
|
||||
|
||||
public:
|
||||
~UniformBuffer() override
|
||||
|
||||
@@ -33,7 +33,6 @@ namespace OpenVulkano::Vulkan
|
||||
this->shader = shader;
|
||||
this->owner = owner;
|
||||
this->context = context;
|
||||
shader->renderShader = this;
|
||||
shaderModules.reserve(shader->shaderPrograms.size());
|
||||
shaderStageCreateInfo.resize(shader->shaderPrograms.size());
|
||||
int i = 0;
|
||||
@@ -45,6 +44,7 @@ namespace OpenVulkano::Vulkan
|
||||
i++;
|
||||
}
|
||||
BuildPipeline();
|
||||
shader->renderShader = this;
|
||||
}
|
||||
|
||||
void VulkanShader::BuildPipeline()
|
||||
|
||||
Reference in New Issue
Block a user