// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Vulkan renderer" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include #include #include #include #include #include #include namespace Nz { VulkanDevice::~VulkanDevice() = default; const RenderDeviceInfo& VulkanDevice::GetDeviceInfo() const { return m_renderDeviceInfo; } const RenderDeviceFeatures& VulkanDevice::GetEnabledFeatures() const { return m_enabledFeatures; } std::shared_ptr VulkanDevice::InstantiateBuffer(BufferType type, UInt64 size, BufferUsageFlags usageFlags, const void* initialData) { return std::make_shared(*this, type, size, usageFlags, initialData); } std::shared_ptr VulkanDevice::InstantiateCommandPool(QueueType queueType) { return std::make_shared(*this, queueType); } std::shared_ptr VulkanDevice::InstantiateFramebuffer(unsigned int width, unsigned int height, const std::shared_ptr& renderPass, const std::vector>& attachments) { return std::make_shared(*this, width, height, renderPass, attachments); } std::shared_ptr VulkanDevice::InstantiateRenderPass(std::vector attachments, std::vector subpassDescriptions, std::vector subpassDependencies) { return std::make_shared(*this, std::move(attachments), std::move(subpassDescriptions), std::move(subpassDependencies)); } std::shared_ptr VulkanDevice::InstantiateRenderPipeline(RenderPipelineInfo pipelineInfo) { return std::make_shared(*this, std::move(pipelineInfo)); } std::shared_ptr VulkanDevice::InstantiateRenderPipelineLayout(RenderPipelineLayoutInfo pipelineLayoutInfo) { auto pipelineLayout = std::make_shared(); if (!pipelineLayout->Create(*this, std::move(pipelineLayoutInfo))) throw std::runtime_error("failed to instantiate vulkan render pipeline layout"); return pipelineLayout; } std::shared_ptr VulkanDevice::InstantiateShaderModule(ShaderStageTypeFlags stages, ShaderAst::Statement& shaderAst, const ShaderWriter::States& states) { auto stage = std::make_shared(); if (!stage->Create(*this, stages, shaderAst, states)) throw std::runtime_error("failed to instantiate vulkan shader module"); return stage; } std::shared_ptr VulkanDevice::InstantiateShaderModule(ShaderStageTypeFlags stages, ShaderLanguage lang, const void* source, std::size_t sourceSize, const ShaderWriter::States& states) { auto stage = std::make_shared(); if (!stage->Create(*this, stages, lang, source, sourceSize, states)) throw std::runtime_error("failed to instantiate vulkan shader module"); return stage; } std::shared_ptr VulkanDevice::InstantiateTexture(const TextureInfo& params) { return std::make_shared(*this, params); } std::shared_ptr VulkanDevice::InstantiateTextureSampler(const TextureSamplerInfo& params) { return std::make_shared(*this, params); } bool VulkanDevice::IsTextureFormatSupported(PixelFormat format, TextureUsage usage) const { VkFormatFeatureFlags flags = 0; switch (usage) { case TextureUsage::ColorAttachment: flags = VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT; break; case TextureUsage::DepthStencilAttachment: flags = VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; break; case TextureUsage::InputAttachment: case TextureUsage::ShaderSampling: flags = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT; break; case TextureUsage::TransferSource: flags = VK_FORMAT_FEATURE_TRANSFER_SRC_BIT; break; case TextureUsage::TransferDestination: flags = VK_FORMAT_FEATURE_TRANSFER_DST_BIT; break; } VkFormatProperties formatProperties = GetInstance().GetPhysicalDeviceFormatProperties(GetPhysicalDevice(), ToVulkan(format)); return formatProperties.optimalTilingFeatures & flags; //< Assume optimal tiling } }