Graphics: Improve TextureSampler handling

This commit is contained in:
Jérôme Leclercq
2021-01-27 18:50:49 +01:00
parent 78c3f57333
commit b9151d8a7a
15 changed files with 181 additions and 27 deletions

View File

@@ -39,6 +39,8 @@ namespace Nz
if (!m_renderDevice)
throw std::runtime_error("failed to instantiate render device");
m_samplerCache.emplace(m_renderDevice);
MaterialPipeline::Initialize();
Nz::PredefinedViewerData viewerUboOffsets = Nz::PredefinedViewerData::GetOffsets();

View File

@@ -63,7 +63,14 @@ namespace Nz
for (const auto& textureSlot : m_textures)
{
if (textureSlot.texture && textureSlot.sampler)
if (!textureSlot.sampler)
{
TextureSamplerCache& samplerCache = Graphics::Instance()->GetSamplerCache();
textureSlot.sampler = samplerCache.Get(textureSlot.samplerInfo);
}
//TODO: Use "missing" texture
if (textureSlot.texture)
{
bindings.push_back({
bindingIndex,

View File

@@ -0,0 +1,19 @@
// Copyright (C) 2017 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/TextureSamplerCache.hpp>
#include <Nazara/Renderer/RenderDevice.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
const std::shared_ptr<TextureSampler>& TextureSamplerCache::Get(const TextureSamplerInfo& info)
{
auto it = m_samplers.find(info);
if (it == m_samplers.end())
it = m_samplers.emplace(info, m_device->InstantiateTextureSampler(info)).first;
return it->second;
}
}

View File

@@ -55,13 +55,13 @@ namespace Nz
VkMemoryRequirements requirement = newBlock.buffer.GetMemoryRequirements();
if (!newBlock.blockMemory.Create(m_device, requirement.size, requirement.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT))
throw std::runtime_error("Failed to allocate block memory: " + TranslateVulkanError(newBlock.blockMemory.GetLastErrorCode()));
throw std::runtime_error("failed to allocate block memory: " + TranslateVulkanError(newBlock.blockMemory.GetLastErrorCode()));
if (!newBlock.buffer.BindBufferMemory(newBlock.blockMemory))
throw std::runtime_error("Failed to bind buffer memory: " + TranslateVulkanError(newBlock.buffer.GetLastErrorCode()));
throw std::runtime_error("failed to bind buffer memory: " + TranslateVulkanError(newBlock.buffer.GetLastErrorCode()));
if (!newBlock.blockMemory.Map())
throw std::runtime_error("Failed to map buffer memory: " + TranslateVulkanError(newBlock.buffer.GetLastErrorCode()));
throw std::runtime_error("failed to map buffer memory: " + TranslateVulkanError(newBlock.buffer.GetLastErrorCode()));
bestBlock.block = &m_blocks.emplace_back(std::move(newBlock));
bestBlock.alignedOffset = 0;