Minor fixes
This commit is contained in:
parent
f45c2c5008
commit
5c7059c8fc
|
|
@ -25,7 +25,7 @@ namespace Nz
|
|||
OpenGLCommandPool(OpenGLCommandPool&&) noexcept = default;
|
||||
~OpenGLCommandPool() = default;
|
||||
|
||||
CommandBufferPtr BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
|
||||
CommandBufferPtr BuildCommandBuffer(const FunctionRef<void(CommandBufferBuilder& builder)>& callback) override;
|
||||
|
||||
void UpdateDebugName(std::string_view name) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ namespace Nz::GL
|
|||
EnsureContext();
|
||||
|
||||
if (m_context->glObjectLabel)
|
||||
m_context->glObjectLabel(ObjectType, m_objectId, SafeCast<GLsizei>(name.size()), name.data());
|
||||
m_context->glObjectLabel(ObjectType, m_objectId, SafeCaster(name.size()), name.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ namespace Nz::GL
|
|||
const Context& context = EnsureDeviceContext();
|
||||
|
||||
if (context.glObjectLabel)
|
||||
context.glObjectLabel(ObjectType, m_objectId, SafeCast<GLsizei>(name.size()), name.data());
|
||||
context.glObjectLabel(ObjectType, m_objectId, SafeCaster(name.size()), name.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace Nz::GL
|
|||
|
||||
if (activeUniformCount > 0)
|
||||
{
|
||||
uniformIndices.resize(static_cast<std::size_t>(activeUniformCount));
|
||||
uniformIndices.resize(SafeCaster(activeUniformCount));
|
||||
context.glGetActiveUniformBlockiv(m_objectId, uniformBlockIndex, GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES, uniformIndices.data());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#include <NazaraUtils/Prerequisites.hpp>
|
||||
#include <Nazara/Renderer/CommandBuffer.hpp>
|
||||
#include <Nazara/Renderer/Config.hpp>
|
||||
#include <functional>
|
||||
#include <NazaraUtils/FunctionRef.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -24,7 +24,7 @@ namespace Nz
|
|||
CommandPool(CommandPool&&) = default;
|
||||
virtual ~CommandPool();
|
||||
|
||||
virtual CommandBufferPtr BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) = 0;
|
||||
virtual CommandBufferPtr BuildCommandBuffer(const FunctionRef<void(CommandBufferBuilder& builder)>& callback) = 0;
|
||||
|
||||
virtual void UpdateDebugName(std::string_view name) = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
|||
VulkanCommandPool(VulkanCommandPool&&) noexcept = default;
|
||||
~VulkanCommandPool() = default;
|
||||
|
||||
CommandBufferPtr BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback) override;
|
||||
CommandBufferPtr BuildCommandBuffer(const FunctionRef<void(CommandBufferBuilder& builder)>& callback) override;
|
||||
|
||||
void UpdateDebugName(std::string_view name) override;
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ namespace Nz
|
|||
{
|
||||
auto& libcurl = m_webService.GetCurlLibrary();
|
||||
|
||||
curl_off_t maxSize = SafeCast<curl_off_t>(maxFileSize);
|
||||
curl_off_t maxSize = SafeCaster(maxFileSize);
|
||||
libcurl.easy_setopt(m_curlHandle, CURLOPT_MAXFILESIZE_LARGE, maxSize);
|
||||
}
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ namespace Nz
|
|||
inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const InsertDebugLabelCommand& command)
|
||||
{
|
||||
if (context->glDebugMessageInsert)
|
||||
context->glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, SafeCast<GLsizei>(command.label.size()), command.label.data());
|
||||
context->glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0, GL_DEBUG_SEVERITY_NOTIFICATION, SafeCaster(command.label.size()), command.label.data());
|
||||
}
|
||||
|
||||
inline void OpenGLCommandBuffer::Execute(const GL::Context* context, const MemoryBarrier& command)
|
||||
|
|
@ -277,7 +277,7 @@ namespace Nz
|
|||
|
||||
if (command.framebuffer->GetType() == FramebufferType::Texture)
|
||||
{
|
||||
const OpenGLFboFramebuffer& fboFramebuffer = static_cast<const OpenGLFboFramebuffer&>(*command.framebuffer);
|
||||
const OpenGLFboFramebuffer& fboFramebuffer = SafeCast<const OpenGLFboFramebuffer&>(*command.framebuffer);
|
||||
|
||||
invalidateAttachments = NazaraStackVector(GLenum, colorBufferCount + 1);
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
CommandBufferPtr OpenGLCommandPool::BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback)
|
||||
CommandBufferPtr OpenGLCommandPool::BuildCommandBuffer(const FunctionRef<void(CommandBufferBuilder& builder)>& callback)
|
||||
{
|
||||
CommandBufferPtr commandBuffer;
|
||||
for (std::size_t i = 0; i < m_commandPools.size(); ++i)
|
||||
|
|
@ -30,7 +30,7 @@ namespace Nz
|
|||
assert(commandBuffer);
|
||||
}
|
||||
|
||||
OpenGLCommandBufferBuilder builder(static_cast<OpenGLCommandBuffer&>(*commandBuffer.get()));
|
||||
OpenGLCommandBufferBuilder builder(SafeCast<OpenGLCommandBuffer&>(*commandBuffer.get()));
|
||||
callback(builder);
|
||||
|
||||
return commandBuffer;
|
||||
|
|
@ -68,7 +68,7 @@ namespace Nz
|
|||
|
||||
void OpenGLCommandPool::Release(CommandBuffer& binding)
|
||||
{
|
||||
OpenGLCommandBuffer& openglBinding = static_cast<OpenGLCommandBuffer&>(binding);
|
||||
OpenGLCommandBuffer& openglBinding = SafeCast<OpenGLCommandBuffer&>(binding);
|
||||
|
||||
std::size_t poolIndex = openglBinding.GetPoolIndex();
|
||||
std::size_t bindingIndex = openglBinding.GetBindingIndex();
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ namespace Nz
|
|||
if (!device.GetEnabledFeatures().computeShaders)
|
||||
throw std::runtime_error("compute shaders are not enabled on the device");
|
||||
|
||||
OpenGLRenderPipelineLayout& pipelineLayout = static_cast<OpenGLRenderPipelineLayout&>(*m_pipelineInfo.pipelineLayout);
|
||||
OpenGLRenderPipelineLayout& pipelineLayout = SafeCast<OpenGLRenderPipelineLayout&>(*m_pipelineInfo.pipelineLayout);
|
||||
|
||||
if (!m_program.Create(device))
|
||||
throw std::runtime_error("failed to create program");
|
||||
|
||||
NazaraAssert(m_pipelineInfo.shaderModule, "invalid shader module");
|
||||
|
||||
OpenGLShaderModule& shaderModule = static_cast<OpenGLShaderModule&>(*m_pipelineInfo.shaderModule);
|
||||
OpenGLShaderModule& shaderModule = SafeCast<OpenGLShaderModule&>(*m_pipelineInfo.shaderModule);
|
||||
|
||||
std::vector<OpenGLShaderModule::ExplicitBinding> explicitBindings;
|
||||
nzsl::ShaderStageTypeFlags stageFlags = shaderModule.Attach(m_program, pipelineLayout.GetBindingMapping(), &explicitBindings);
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace Nz
|
|||
for (std::size_t i = 0; i < m_attachments.size(); ++i)
|
||||
{
|
||||
assert(m_attachments[i]);
|
||||
const OpenGLTexture& glTexture = static_cast<const OpenGLTexture&>(*m_attachments[i]);
|
||||
const OpenGLTexture& glTexture = SafeCast<const OpenGLTexture&>(*m_attachments[i]);
|
||||
|
||||
PixelFormat textureFormat = glTexture.GetFormat();
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ namespace Nz
|
|||
for (std::size_t i = 0; i < m_colorAttachmentCount; ++i)
|
||||
fboDrawBuffers[i] = GLenum(GL_COLOR_ATTACHMENT0 + i);
|
||||
|
||||
framebuffer.DrawBuffers(SafeCast<GLsizei>(m_colorAttachmentCount), fboDrawBuffers.data());
|
||||
framebuffer.DrawBuffers(SafeCaster(m_colorAttachmentCount), fboDrawBuffers.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Nz
|
|||
|
||||
void OpenGLRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags /*queueTypeFlags*/)
|
||||
{
|
||||
OpenGLCommandBuffer* oglCommandBuffer = static_cast<OpenGLCommandBuffer*>(commandBuffer);
|
||||
OpenGLCommandBuffer* oglCommandBuffer = SafeCast<OpenGLCommandBuffer*>(commandBuffer);
|
||||
oglCommandBuffer->Execute();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Nz
|
|||
{
|
||||
ValidatePipelineInfo(device, m_pipelineInfo);
|
||||
|
||||
OpenGLRenderPipelineLayout& pipelineLayout = static_cast<OpenGLRenderPipelineLayout&>(*m_pipelineInfo.pipelineLayout);
|
||||
OpenGLRenderPipelineLayout& pipelineLayout = SafeCast<OpenGLRenderPipelineLayout&>(*m_pipelineInfo.pipelineLayout);
|
||||
|
||||
if (!m_program.Create(device))
|
||||
throw std::runtime_error("failed to create program");
|
||||
|
|
@ -38,7 +38,7 @@ namespace Nz
|
|||
|
||||
for (const auto& shaderModulePtr : m_pipelineInfo.shaderModules)
|
||||
{
|
||||
OpenGLShaderModule& shaderModule = static_cast<OpenGLShaderModule&>(*shaderModulePtr);
|
||||
OpenGLShaderModule& shaderModule = SafeCast<OpenGLShaderModule&>(*shaderModulePtr);
|
||||
stageFlags |= shaderModule.Attach(m_program, pipelineLayout.GetBindingMapping(), &explicitBindings);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ namespace Nz
|
|||
|
||||
void OpenGLRenderPipelineLayout::Release(ShaderBinding& binding)
|
||||
{
|
||||
OpenGLShaderBinding& vulkanBinding = static_cast<OpenGLShaderBinding&>(binding);
|
||||
OpenGLShaderBinding& vulkanBinding = SafeCast<OpenGLShaderBinding&>(binding);
|
||||
|
||||
std::size_t poolIndex = vulkanBinding.GetPoolIndex();
|
||||
std::size_t bindingIndex = vulkanBinding.GetBindingIndex();
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ namespace Nz
|
|||
storageDescriptor.offset = arg.offset;
|
||||
storageDescriptor.size = arg.range;
|
||||
|
||||
if (OpenGLBuffer* glBuffer = static_cast<OpenGLBuffer*>(arg.buffer))
|
||||
if (OpenGLBuffer* glBuffer = SafeCast<OpenGLBuffer*>(arg.buffer))
|
||||
{
|
||||
if (glBuffer->GetType() != BufferType::Storage)
|
||||
throw std::runtime_error("expected storage buffer");
|
||||
|
|
@ -115,7 +115,7 @@ namespace Nz
|
|||
else if constexpr (std::is_same_v<T, TextureBinding>)
|
||||
{
|
||||
auto& textureDescriptor = m_owner.GetTextureDescriptor(m_poolIndex, m_bindingIndex, binding.bindingIndex);
|
||||
if (const OpenGLTexture* glTexture = static_cast<const OpenGLTexture*>(arg.texture))
|
||||
if (const OpenGLTexture* glTexture = SafeCast<const OpenGLTexture*>(arg.texture))
|
||||
{
|
||||
std::optional<GLTextureFormat> format = DescribeTextureFormat(glTexture->GetFormat());
|
||||
if (!format)
|
||||
|
|
@ -151,7 +151,7 @@ namespace Nz
|
|||
uboDescriptor.offset = arg.offset;
|
||||
uboDescriptor.size = arg.range;
|
||||
|
||||
if (OpenGLBuffer* glBuffer = static_cast<OpenGLBuffer*>(arg.buffer))
|
||||
if (OpenGLBuffer* glBuffer = SafeCast<OpenGLBuffer*>(arg.buffer))
|
||||
{
|
||||
if (glBuffer->GetType() != BufferType::Uniform)
|
||||
throw std::runtime_error("expected uniform buffer");
|
||||
|
|
@ -177,13 +177,13 @@ namespace Nz
|
|||
{
|
||||
auto& textureDescriptor = m_owner.GetSampledTextureDescriptor(m_poolIndex, m_bindingIndex, bindingIndex);
|
||||
|
||||
if (const OpenGLTexture* glTexture = static_cast<const OpenGLTexture*>(textureBinding.texture))
|
||||
if (const OpenGLTexture* glTexture = SafeCast<const OpenGLTexture*>(textureBinding.texture))
|
||||
{
|
||||
// TODO: Add texture view emulation
|
||||
|
||||
textureDescriptor.texture = glTexture->GetTexture().GetObjectId();
|
||||
|
||||
if (const OpenGLTextureSampler* glSampler = static_cast<const OpenGLTextureSampler*>(textureBinding.sampler))
|
||||
if (const OpenGLTextureSampler* glSampler = SafeCast<const OpenGLTextureSampler*>(textureBinding.sampler))
|
||||
textureDescriptor.sampler = glSampler->GetSampler(glTexture->GetLevelCount() > 1).GetObjectId();
|
||||
else
|
||||
textureDescriptor.sampler = 0;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace Nz
|
|||
|
||||
bool OpenGLTexture::Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos)
|
||||
{
|
||||
const OpenGLTexture& glTexture = static_cast<const OpenGLTexture&>(source);
|
||||
const OpenGLTexture& glTexture = SafeCast<const OpenGLTexture&>(source);
|
||||
|
||||
const GL::Context& context = m_texture.EnsureDeviceContext();
|
||||
return context.CopyTexture(glTexture, *this, srcBox, dstPos);
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ namespace Nz::GL
|
|||
|
||||
glClearDepthf = [](GLfloat depth)
|
||||
{
|
||||
const EGLContextBase* context = static_cast<const EGLContextBase*>(GetCurrentContext());
|
||||
const EGLContextBase* context = SafeCast<const EGLContextBase*>(GetCurrentContext());
|
||||
assert(context);
|
||||
context->fallbacks.glClearDepth(depth);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ namespace Nz::GL
|
|||
context = std::make_shared<EGLContextBase>(device, *this);
|
||||
#endif
|
||||
|
||||
if (!context->Create(params, static_cast<EGLContextBase*>(shareContext)))
|
||||
if (!context->Create(params, SafeCast<EGLContextBase*>(shareContext)))
|
||||
{
|
||||
NazaraError("failed to create context");
|
||||
return {};
|
||||
|
|
@ -193,7 +193,7 @@ namespace Nz::GL
|
|||
return {};
|
||||
}
|
||||
|
||||
if (!context->Create(params, handle, static_cast<EGLContextBase*>(shareContext)))
|
||||
if (!context->Create(params, handle, SafeCast<EGLContextBase*>(shareContext)))
|
||||
{
|
||||
NazaraError("failed to create context");
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ namespace Nz::GL
|
|||
|
||||
glClearDepthf = [](GLfloat depth)
|
||||
{
|
||||
const WGLContext* context = static_cast<const WGLContext*>(GetCurrentContext());
|
||||
const WGLContext* context = SafeCast<const WGLContext*>(GetCurrentContext());
|
||||
assert(context);
|
||||
context->fallbacks.glClearDepth(depth);
|
||||
};
|
||||
|
|
@ -328,7 +328,7 @@ namespace Nz::GL
|
|||
int pixelFormat = 0;
|
||||
if (m_params.sampleCount > 1)
|
||||
{
|
||||
const WGLContext* currentContext = static_cast<const WGLContext*>(GetCurrentContext()); //< Pay TLS cost only once
|
||||
const WGLContext* currentContext = SafeCast<const WGLContext*>(GetCurrentContext()); //< Pay TLS cost only once
|
||||
if (currentContext)
|
||||
{
|
||||
// WGL_ARB_pixel_format and WGL_EXT_pixel_format are the same, except for the symbol
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ namespace Nz::GL
|
|||
std::shared_ptr<Context> WGLLoader::CreateContext(const OpenGLDevice* device, const ContextParams& params, Context* shareContext) const
|
||||
{
|
||||
auto context = std::make_shared<WGLContext>(device, *this);
|
||||
if (!context->Create(&m_baseContext, params, static_cast<WGLContext*>(shareContext)))
|
||||
if (!context->Create(&m_baseContext, params, SafeCast<WGLContext*>(shareContext)))
|
||||
{
|
||||
NazaraError("failed to create context");
|
||||
return {};
|
||||
|
|
@ -114,7 +114,7 @@ namespace Nz::GL
|
|||
std::shared_ptr<Context> WGLLoader::CreateContext(const OpenGLDevice* device, const ContextParams& params, WindowHandle handle, Context* shareContext) const
|
||||
{
|
||||
auto context = std::make_shared<WGLContext>(device, *this);
|
||||
if (!context->Create(&m_baseContext, params, handle, static_cast<WGLContext*>(shareContext)))
|
||||
if (!context->Create(&m_baseContext, params, handle, SafeCast<WGLContext*>(shareContext)))
|
||||
{
|
||||
NazaraError("failed to create context");
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ namespace Nz
|
|||
for (auto& drawCall : m_drawCalls)
|
||||
{
|
||||
builder.BindVertexBuffer(0, *drawCall.vertexBuffer);
|
||||
builder.Draw(SafeCast<UInt32>(drawCall.vertexCount));
|
||||
builder.Draw(SafeCaster(drawCall.vertexCount));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Renderer/RendererImpl.hpp>
|
||||
#include <NazaraUtils/EnumArray.hpp>
|
||||
#include <NazaraUtils/TypeTraits.hpp>
|
||||
#include <frozen/string.h>
|
||||
#include <frozen/unordered_map.h>
|
||||
#include <filesystem>
|
||||
|
|
@ -80,10 +81,12 @@ namespace Nz
|
|||
|
||||
void Renderer::LoadBackend(const Config& config)
|
||||
{
|
||||
using FactoryFunc = FunctionPtr<std::unique_ptr<RendererImpl>()>;
|
||||
|
||||
struct RendererImplementations
|
||||
{
|
||||
#ifdef NAZARA_RENDERER_EMBEDDEDBACKENDS
|
||||
std::function<std::unique_ptr<RendererImpl>()> factory;
|
||||
FactoryFunc factory;
|
||||
#else
|
||||
std::filesystem::path fileName;
|
||||
#endif
|
||||
|
|
@ -97,20 +100,20 @@ namespace Nz
|
|||
preferredAPI = RenderAPI::OpenGL;
|
||||
|
||||
#ifdef NAZARA_RENDERER_EMBEDDEDBACKENDS
|
||||
auto RegisterImpl = [&](RenderAPI api, auto ComputeScore, std::function<std::unique_ptr<RendererImpl>()> factory)
|
||||
auto RegisterImpl = [&]<typename T>(RenderAPI api, auto ComputeScore, TypeTag<T> RendererTag)
|
||||
{
|
||||
int score = ComputeScore();
|
||||
if (score >= 0)
|
||||
{
|
||||
auto& impl = implementations.emplace_back();
|
||||
impl.factory = std::move(factory);
|
||||
impl.factory = []() -> std::unique_ptr<RendererImpl> { return std::make_unique<T>(); };
|
||||
impl.score = (preferredAPI == api) ? std::numeric_limits<int>::max() : score;
|
||||
}
|
||||
};
|
||||
|
||||
RegisterImpl(RenderAPI::OpenGL, [] { return 50; }, [] { return std::make_unique<OpenGLRenderer>(); });
|
||||
RegisterImpl(RenderAPI::OpenGL, [] { return 50; }, TypeTag<OpenGLRenderer>{});
|
||||
#ifndef NAZARA_PLATFORM_WEB
|
||||
RegisterImpl(RenderAPI::Vulkan, [] { return 100; }, [] { return std::make_unique<VulkanRenderer>(); });
|
||||
RegisterImpl(RenderAPI::Vulkan, [] { return 100; }, TypeTag<VulkanRenderer>{});
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
|
@ -202,7 +205,7 @@ namespace Nz
|
|||
m_rendererLib = std::move(chosenLib);
|
||||
#endif
|
||||
|
||||
NazaraDebug("Using " + m_rendererImpl->QueryAPIString() + " as renderer");
|
||||
NazaraDebug("Using {0} as renderer", m_rendererImpl->QueryAPIString());
|
||||
}
|
||||
|
||||
Renderer* Renderer::s_instance = nullptr;
|
||||
|
|
|
|||
|
|
@ -144,11 +144,11 @@ namespace Nz
|
|||
std::string appName = parameters.GetStringParameter("VkAppInfo_OverrideApplicationName").GetValueOr("Another application made with Nazara Engine");
|
||||
std::string engineName = parameters.GetStringParameter("VkAppInfo_OverrideEngineName").GetValueOr("Nazara Engine - Vulkan Renderer");
|
||||
|
||||
UInt32 appVersion = SafeCast<UInt32>(parameters.GetIntegerParameter("VkAppInfo_OverrideApplicationVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0)));
|
||||
UInt32 engineVersion = SafeCast<UInt32>(parameters.GetIntegerParameter("VkAppInfo_OverrideEngineVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0)));
|
||||
UInt32 appVersion = SafeCaster(parameters.GetIntegerParameter("VkAppInfo_OverrideApplicationVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0)));
|
||||
UInt32 engineVersion = SafeCaster(parameters.GetIntegerParameter("VkAppInfo_OverrideEngineVersion").GetValueOr(VK_MAKE_API_VERSION(0, 1, 0, 0)));
|
||||
|
||||
if (auto result = parameters.GetIntegerParameter("VkAppInfo_OverrideAPIVersion"))
|
||||
targetApiVersion = SafeCast<UInt32>(result.GetValue());
|
||||
targetApiVersion = SafeCaster(result.GetValue());
|
||||
|
||||
if (Vk::Loader::vkEnumerateInstanceVersion)
|
||||
{
|
||||
|
|
@ -171,7 +171,7 @@ namespace Nz
|
|||
targetApiVersion
|
||||
};
|
||||
|
||||
VkInstanceCreateFlags createFlags = SafeCast<VkInstanceCreateFlags>(parameters.GetIntegerParameter("VkInstanceInfo_OverrideCreateFlags").GetValueOr(0));
|
||||
VkInstanceCreateFlags createFlags = SafeCaster(parameters.GetIntegerParameter("VkInstanceInfo_OverrideCreateFlags").GetValueOr(0));
|
||||
|
||||
std::vector<const char*> enabledLayers;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
CommandBufferPtr VulkanCommandPool::BuildCommandBuffer(const std::function<void(CommandBufferBuilder& builder)>& callback)
|
||||
CommandBufferPtr VulkanCommandPool::BuildCommandBuffer(const FunctionRef<void(CommandBufferBuilder& builder)>& callback)
|
||||
{
|
||||
Vk::AutoCommandBuffer commandBuffer = m_commandPool.AllocateCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY);
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ namespace Nz
|
|||
|
||||
void VulkanCommandPool::Release(CommandBuffer& binding)
|
||||
{
|
||||
VulkanCommandBuffer& vulkanBinding = static_cast<VulkanCommandBuffer&>(binding);
|
||||
VulkanCommandBuffer& vulkanBinding = SafeCast<VulkanCommandBuffer&>(binding);
|
||||
|
||||
std::size_t poolIndex = vulkanBinding.GetPoolIndex();
|
||||
std::size_t bindingIndex = vulkanBinding.GetBindingIndex();
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace Nz
|
|||
if (!device.GetEnabledFeatures().computeShaders)
|
||||
throw std::runtime_error("compute shaders are not enabled on the device");
|
||||
|
||||
VulkanShaderModule& vulkanModule = static_cast<VulkanShaderModule&>(*m_pipelineInfo.shaderModule);
|
||||
VulkanShaderModule& vulkanModule = SafeCast<VulkanShaderModule&>(*m_pipelineInfo.shaderModule);
|
||||
const VulkanShaderModule::Stage* computeStage = nullptr;
|
||||
for (const auto& stage : vulkanModule.GetStages())
|
||||
{
|
||||
|
|
@ -42,7 +42,7 @@ namespace Nz
|
|||
createInfo.stage.pName = computeStage->name.data();
|
||||
createInfo.stage.stage = ToVulkan(computeStage->stage);
|
||||
|
||||
VulkanRenderPipelineLayout& pipelineLayout = *static_cast<VulkanRenderPipelineLayout*>(m_pipelineInfo.pipelineLayout.get());
|
||||
VulkanRenderPipelineLayout& pipelineLayout = *SafeCast<VulkanRenderPipelineLayout*>(m_pipelineInfo.pipelineLayout.get());
|
||||
createInfo.layout = pipelineLayout.GetPipelineLayout();
|
||||
|
||||
if (!m_pipeline.CreateCompute(device, createInfo))
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ namespace Nz
|
|||
|
||||
void VulkanRenderImage::SubmitCommandBuffer(CommandBuffer* commandBuffer, QueueTypeFlags queueTypeFlags)
|
||||
{
|
||||
VulkanCommandBuffer& vkCommandBuffer = *static_cast<VulkanCommandBuffer*>(commandBuffer);
|
||||
VulkanCommandBuffer& vkCommandBuffer = *SafeCast<VulkanCommandBuffer*>(commandBuffer);
|
||||
|
||||
return SubmitCommandBuffer(vkCommandBuffer.GetCommandBuffer(), queueTypeFlags);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ namespace Nz
|
|||
{
|
||||
assert(stagePtr);
|
||||
|
||||
VulkanShaderModule& vulkanModule = static_cast<VulkanShaderModule&>(*stagePtr);
|
||||
VulkanShaderModule& vulkanModule = SafeCast<VulkanShaderModule&>(*stagePtr);
|
||||
for (auto& stage : vulkanModule.GetStages())
|
||||
{
|
||||
VkPipelineShaderStageCreateInfo& createInfo = shaderStageCreateInfos.emplace_back();
|
||||
|
|
@ -227,7 +227,7 @@ namespace Nz
|
|||
|
||||
for (const auto& bufferData : pipelineInfo.vertexBuffers)
|
||||
{
|
||||
std::uint32_t binding = std::uint32_t(bufferData.binding);
|
||||
std::uint32_t binding = SafeCaster(bufferData.binding);
|
||||
|
||||
for (const auto& componentInfo : bufferData.declaration->GetComponents())
|
||||
{
|
||||
|
|
@ -237,7 +237,7 @@ namespace Nz
|
|||
auto& bufferAttribute = vertexAttributes.emplace_back();
|
||||
bufferAttribute.binding = binding;
|
||||
bufferAttribute.location = locationIndex++;
|
||||
bufferAttribute.offset = std::uint32_t(componentInfo.offset);
|
||||
bufferAttribute.offset = SafeCaster(componentInfo.offset);
|
||||
bufferAttribute.format = ToVulkan(componentInfo.type);
|
||||
}
|
||||
}
|
||||
|
|
@ -252,8 +252,8 @@ namespace Nz
|
|||
for (const auto& bufferData : pipelineInfo.vertexBuffers)
|
||||
{
|
||||
auto& bufferBinding = vertexBindings.emplace_back();
|
||||
bufferBinding.binding = std::uint32_t(bufferData.binding);
|
||||
bufferBinding.stride = std::uint32_t(bufferData.declaration->GetStride());
|
||||
bufferBinding.binding = SafeCaster(bufferData.binding);
|
||||
bufferBinding.stride = SafeCaster(bufferData.declaration->GetStride());
|
||||
bufferBinding.inputRate = ToVulkan(bufferData.declaration->GetInputRate());
|
||||
}
|
||||
|
||||
|
|
@ -265,10 +265,10 @@ namespace Nz
|
|||
VkPipelineVertexInputStateCreateInfo createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
||||
|
||||
createInfo.vertexAttributeDescriptionCount = std::uint32_t(vertexAttributes.size());
|
||||
createInfo.vertexAttributeDescriptionCount = SafeCaster(vertexAttributes.size());
|
||||
createInfo.pVertexAttributeDescriptions = vertexAttributes.data();
|
||||
|
||||
createInfo.vertexBindingDescriptionCount = std::uint32_t(bindingDescriptions.size());
|
||||
createInfo.vertexBindingDescriptionCount = SafeCaster(bindingDescriptions.size());
|
||||
createInfo.pVertexBindingDescriptions = bindingDescriptions.data();
|
||||
|
||||
return createInfo;
|
||||
|
|
@ -295,7 +295,7 @@ namespace Nz
|
|||
createInfo.stateData->vertexInputState = BuildVertexInputInfo(pipelineInfo, createInfo.vertexAttributesDescription, createInfo.vertexBindingDescription);
|
||||
|
||||
createInfo.pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
||||
createInfo.pipelineInfo.stageCount = std::uint32_t(createInfo.shaderStages.size());
|
||||
createInfo.pipelineInfo.stageCount = SafeCaster(createInfo.shaderStages.size());
|
||||
createInfo.pipelineInfo.pStages = createInfo.shaderStages.data();
|
||||
createInfo.pipelineInfo.pColorBlendState = &createInfo.stateData->colorBlendState;
|
||||
createInfo.pipelineInfo.pDepthStencilState = &createInfo.stateData->depthStencilState;
|
||||
|
|
@ -306,7 +306,7 @@ namespace Nz
|
|||
createInfo.pipelineInfo.pVertexInputState = &createInfo.stateData->vertexInputState;
|
||||
createInfo.pipelineInfo.pViewportState = &createInfo.stateData->viewportState;
|
||||
|
||||
VulkanRenderPipelineLayout& pipelineLayout = *static_cast<VulkanRenderPipelineLayout*>(pipelineInfo.pipelineLayout.get());
|
||||
VulkanRenderPipelineLayout& pipelineLayout = *SafeCast<VulkanRenderPipelineLayout*>(pipelineInfo.pipelineLayout.get());
|
||||
createInfo.pipelineInfo.layout = pipelineLayout.GetPipelineLayout();
|
||||
|
||||
return createInfo;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace Nz
|
|||
for (auto& pool : m_descriptorPools)
|
||||
{
|
||||
if (!pool.freeBindings.TestAll())
|
||||
NazaraWarning("Not all ShaderBinding have been released!");
|
||||
NazaraWarning("not all ShaderBinding have been released!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ namespace Nz
|
|||
|
||||
ShaderBindingPtr bindingPtr = AllocateFromPool(newPoolIndex, setIndex);
|
||||
if (!bindingPtr)
|
||||
throw std::runtime_error("Failed to allocate shader binding");
|
||||
throw std::runtime_error("failed to allocate shader binding");
|
||||
|
||||
return bindingPtr;
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ namespace Nz
|
|||
setLayouts[i] = *m_descriptorSetLayouts[i];
|
||||
}
|
||||
|
||||
if (!m_pipelineLayout.Create(*m_device, UInt32(setLayouts.size()), setLayouts.data()))
|
||||
if (!m_pipelineLayout.Create(*m_device, SafeCaster(setLayouts.size()), setLayouts.data()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -108,7 +108,7 @@ namespace Nz
|
|||
DescriptorPool pool;
|
||||
pool.descriptorPool = std::make_unique<Vk::DescriptorPool>();
|
||||
|
||||
if (!pool.descriptorPool->Create(*m_device, MaxSet, UInt32(poolSizes.size()), poolSizes.data(), VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT))
|
||||
if (!pool.descriptorPool->Create(*m_device, MaxSet, SafeCaster(poolSizes.size()), poolSizes.data(), VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT))
|
||||
throw std::runtime_error("failed to allocate new descriptor pool: " + TranslateVulkanError(pool.descriptorPool->GetLastErrorCode()));
|
||||
|
||||
pool.freeBindings.Resize(MaxSet, true);
|
||||
|
|
@ -128,7 +128,7 @@ namespace Nz
|
|||
Vk::DescriptorSet descriptorSet = pool.descriptorPool->AllocateDescriptorSet(*m_descriptorSetLayouts[setIndex]);
|
||||
if (!descriptorSet)
|
||||
{
|
||||
NazaraWarning("Failed to allocate descriptor set: " + TranslateVulkanError(pool.descriptorPool->GetLastErrorCode()));
|
||||
NazaraWarningFmt("failed to allocate descriptor set: {}", TranslateVulkanError(pool.descriptorPool->GetLastErrorCode()));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ namespace Nz
|
|||
|
||||
void VulkanRenderPipelineLayout::Release(ShaderBinding& binding)
|
||||
{
|
||||
VulkanShaderBinding& vulkanBinding = static_cast<VulkanShaderBinding&>(binding);
|
||||
VulkanShaderBinding& vulkanBinding = SafeCast<VulkanShaderBinding&>(binding);
|
||||
|
||||
std::size_t poolIndex = vulkanBinding.GetPoolIndex();
|
||||
std::size_t bindingIndex = vulkanBinding.GetBindingIndex();
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ namespace Nz
|
|||
}
|
||||
else if constexpr (std::is_same_v<T, UniformBufferBinding>)
|
||||
{
|
||||
VulkanBuffer* vkBuffer = static_cast<VulkanBuffer*>(arg.buffer);
|
||||
VulkanBuffer* vkBuffer = SafeCast<VulkanBuffer*>(arg.buffer);
|
||||
|
||||
VkDescriptorBufferInfo& bufferInfo = bufferBinding.emplace_back();
|
||||
bufferInfo.buffer = (vkBuffer) ? vkBuffer->GetBuffer() : VK_NULL_HANDLE;
|
||||
|
|
|
|||
|
|
@ -304,42 +304,32 @@ namespace Nz
|
|||
|
||||
bool VulkanTexture::Copy(const Texture& source, const Boxui& srcBox, const Vector3ui& dstPos)
|
||||
{
|
||||
const VulkanTexture& sourceTexture = static_cast<const VulkanTexture&>(source);
|
||||
const VulkanTexture& sourceTexture = SafeCast<const VulkanTexture&>(source);
|
||||
|
||||
Vk::AutoCommandBuffer copyCommandBuffer = m_device.AllocateCommandBuffer(QueueType::Graphics);
|
||||
if (!copyCommandBuffer->Begin(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT))
|
||||
return false;
|
||||
|
||||
VkImageSubresourceLayers subresourceLayers = { //< FIXME
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
0, //< mipLevel
|
||||
0, //< baseArrayLayer
|
||||
1 //< layerCount
|
||||
};
|
||||
|
||||
VkImageSubresourceRange subresourceRange = { //< FIXME
|
||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
0, //< baseMipLevel
|
||||
1, //< levelCount
|
||||
subresourceLayers.baseArrayLayer, //< baseArrayLayer
|
||||
subresourceLayers.layerCount //< layerCount
|
||||
};
|
||||
VkImageSubresourceLayers srcSubresourceLayers = sourceTexture.BuildSubresourceLayers(0);
|
||||
VkImageSubresourceRange srcSubresourceRange = sourceTexture.BuildSubresourceRange(0, 1);
|
||||
VkImageSubresourceLayers dstSubresourceLayers = BuildSubresourceLayers(0);
|
||||
VkImageSubresourceRange dstSubresourceRange = BuildSubresourceRange(0, 1);
|
||||
|
||||
VkImageCopy region = {
|
||||
subresourceLayers,
|
||||
VkOffset3D { static_cast<Int32>(srcBox.x), static_cast<Int32>(srcBox.y), static_cast<Int32>(srcBox.z) },
|
||||
subresourceLayers,
|
||||
VkOffset3D { static_cast<Int32>(dstPos.x), static_cast<Int32>(dstPos.y), static_cast<Int32>(dstPos.z) },
|
||||
VkExtent3D { static_cast<UInt32>(srcBox.width), static_cast<UInt32>(srcBox.height), static_cast<UInt32>(srcBox.depth) }
|
||||
.srcSubresource = srcSubresourceLayers,
|
||||
.srcOffset = VkOffset3D { SafeCast<Int32>(srcBox.x), SafeCast<Int32>(srcBox.y), SafeCast<Int32>(srcBox.z) },
|
||||
.dstSubresource = dstSubresourceLayers,
|
||||
.dstOffset = VkOffset3D { SafeCast<Int32>(dstPos.x), SafeCast<Int32>(dstPos.y), SafeCast<Int32>(dstPos.z) },
|
||||
.extent = VkExtent3D { SafeCast<UInt32>(srcBox.width), SafeCast<UInt32>(srcBox.height), SafeCast<UInt32>(srcBox.depth) }
|
||||
};
|
||||
|
||||
copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, subresourceRange);
|
||||
copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, subresourceRange);
|
||||
copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, srcSubresourceRange);
|
||||
copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, dstSubresourceRange);
|
||||
|
||||
copyCommandBuffer->CopyImage(sourceTexture.GetImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, region);
|
||||
|
||||
copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, subresourceRange);
|
||||
copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, subresourceRange);
|
||||
copyCommandBuffer->SetImageLayout(sourceTexture.GetImage(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, srcSubresourceRange);
|
||||
copyCommandBuffer->SetImageLayout(m_image, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, dstSubresourceRange);
|
||||
|
||||
if (!copyCommandBuffer->End())
|
||||
return false;
|
||||
|
|
@ -455,14 +445,14 @@ namespace Nz
|
|||
VkImageSubresourceLayers subresourceLayers = BuildSubresourceLayers(level, baseLayer, layerCount);
|
||||
|
||||
VkBufferImageCopy region = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
subresourceLayers,
|
||||
{ // imageOffset
|
||||
.bufferOffset = 0,
|
||||
.bufferRowLength = 0,
|
||||
.bufferImageHeight = 0,
|
||||
.imageSubresource = subresourceLayers,
|
||||
.imageOffset = {
|
||||
SafeCast<Int32>(copyBox.x), SafeCast<Int32>(copyBox.y), SafeCast<Int32>(copyBox.z)
|
||||
},
|
||||
{ // imageExtent
|
||||
.imageExtent = {
|
||||
copyBox.width, copyBox.height, copyBox.depth
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,27 +15,27 @@ namespace Nz
|
|||
VulkanFramebuffer(FramebufferType::Texture)
|
||||
{
|
||||
assert(renderPass);
|
||||
const VulkanRenderPass& vkRenderPass = static_cast<const VulkanRenderPass&>(*renderPass);
|
||||
const VulkanRenderPass& vkRenderPass = SafeCast<const VulkanRenderPass&>(*renderPass);
|
||||
|
||||
StackArray<VkImageView> imageViews = NazaraStackArrayNoInit(VkImageView, attachments.size());
|
||||
for (std::size_t i = 0; i < attachments.size(); ++i)
|
||||
{
|
||||
assert(attachments[i]);
|
||||
|
||||
const VulkanTexture& vkTexture = static_cast<const VulkanTexture&>(*attachments[i]);
|
||||
const VulkanTexture& vkTexture = SafeCast<const VulkanTexture&>(*attachments[i]);
|
||||
imageViews[i] = vkTexture.GetImageView();
|
||||
}
|
||||
|
||||
VkFramebufferCreateInfo createInfo = {
|
||||
VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
||||
nullptr,
|
||||
0,
|
||||
vkRenderPass.GetRenderPass(),
|
||||
UInt32(imageViews.size()),
|
||||
imageViews.data(),
|
||||
UInt32(width),
|
||||
UInt32(height),
|
||||
1
|
||||
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.renderPass = vkRenderPass.GetRenderPass(),
|
||||
.attachmentCount = UInt32(imageViews.size()),
|
||||
.pAttachments = imageViews.data(),
|
||||
.width = UInt32(width),
|
||||
.height = UInt32(height),
|
||||
.layers = 1
|
||||
};
|
||||
|
||||
if (!m_framebuffer.Create(device, createInfo))
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ end
|
|||
|
||||
add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo")
|
||||
|
||||
add_requires("entt 3.12.2", "fmt", "frozen", "nazarautils >=2024.01.02")
|
||||
add_requires("entt 3.12.2", "fmt", "frozen", "nazarautils >=2024.01.13")
|
||||
|
||||
-- Module dependencies
|
||||
if has_config("audio") then
|
||||
|
|
|
|||
Loading…
Reference in New Issue