Merge pull request 'Enhancements & Fixes' (#78) from enhancements into master

Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/78
This commit is contained in:
Georg Hagen
2024-07-24 16:06:01 +02:00
45 changed files with 442 additions and 110 deletions

View File

@@ -7,6 +7,7 @@
#pragma once
#include "Base/ICloseable.hpp"
#include "Scene/Camera.hpp"
#include "IRecordable.hpp"
#include "Vulkan/Resources/UniformBuffer.hpp"
@@ -39,5 +40,7 @@ namespace OpenVulkano::Vulkan
m_camera = nullptr;
delete m_buffer;
}
[[nodiscard]] Scene::Camera* GetCamera() const { return m_camera; }
};
}
}

View File

@@ -13,6 +13,7 @@
namespace OpenVulkano::Vulkan
{
static_assert(sizeof(vk::DescriptorSetLayoutBinding) == sizeof(DescriptorSetLayoutBinding));
static_assert(sizeof(vk::PushConstantRange) == sizeof(PushConstantRange));
VulkanShader::~VulkanShader()
{
@@ -79,7 +80,7 @@ namespace OpenVulkano::Vulkan
vk::PipelineRasterizationStateCreateInfo rasterizer = {};
rasterizer.cullMode = static_cast<vk::CullModeFlagBits>(shader->cullMode);
vk::PipelineMultisampleStateCreateInfo msaa = {};
vk::PipelineDepthStencilStateCreateInfo depth = { {}, 1, 1, vk::CompareOp::eLess };
vk::PipelineDepthStencilStateCreateInfo depth = { {}, shader->depthTest, shader->depthWrite, vk::CompareOp::eLess };
depth.maxDepthBounds = 1;
vk::PipelineColorBlendAttachmentState colorBlendAttachment = {};
colorBlendAttachment.colorWriteMask = vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eR;
@@ -148,9 +149,8 @@ namespace OpenVulkano::Vulkan
vk::DescriptorSetLayoutCreateInfo createInfo { {}, static_cast<uint32_t>(set.size()), reinterpret_cast<const vk::DescriptorSetLayoutBinding*>(set.data()) };
descriptorSetLayouts.push_back(device.createDescriptorSetLayout(createInfo));
}
vk::PipelineLayoutCreateInfo plci = { {}, static_cast<uint32_t>(descriptorSetLayouts.size()), descriptorSetLayouts.data(), 0, nullptr };
vk::PushConstantRange* pcRanges = reinterpret_cast<vk::PushConstantRange*>(shader->pushConstantRanges.data());
vk::PipelineLayoutCreateInfo plci = {{}, static_cast<uint32_t>(descriptorSetLayouts.size()), descriptorSetLayouts.data(), static_cast<uint32_t>(shader->pushConstantRanges.size()), pcRanges };
pipelineLayout = this->device.createPipelineLayout(plci);
}
}

View File

@@ -16,11 +16,10 @@
namespace OpenVulkano::Vulkan
{
class VulkanTexture : public IRecordable, public Image
class VulkanTexture : public Scene::RenderTexture, public IRecordable, public Image
{
public:
static inline vk::SamplerCreateInfo DEFAULT_SAMPLER_CONFIG {};
Scene::Texture* m_texture = nullptr;
vk::Sampler m_sampler;
vk::DescriptorSet m_descriptorSet;
@@ -37,9 +36,22 @@ namespace OpenVulkano::Vulkan
texture->renderTexture = this;
}
void InitSharedMem(ResourceManager* resManager, Scene::Texture* texture, vk::DescriptorSetLayout* descriptorSetLayout, const DescriptorSetLayoutBinding& binding)
{
m_texture = texture;
Image::Init(resManager->GetContext()->device.get(), texture->format, { texture->resolution.x, texture->resolution.y, texture->resolution.z }, vk::MemoryPropertyFlagBits::eDeviceLocal | vk::MemoryPropertyFlagBits::eHostVisible);
texture->updated = false;
texture->textureBuffer = Map();
m_sampler = resManager->CreateSampler(DEFAULT_SAMPLER_CONFIG);
SetDescriptorSet(resManager, descriptorSetLayout, binding);
texture->renderTexture = this;
}
virtual ~VulkanTexture() override
{
if (m_texture) Close();
if (m_sampler) Close();
}
void Close() override
@@ -125,4 +137,4 @@ namespace OpenVulkano::Vulkan
VulkanTexture::Record(context, setId);
}
};
}
}