From b657ad88846b228ec14149278bfb12fc90383bea Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 1 Oct 2022 16:33:16 +0800 Subject: [PATCH 01/14] Handled resizing for the render graph resource (not tested) --- .../Graphics/Devices/SHVkLogicalDevice.cpp | 2 + .../src/Graphics/Images/SHVkImage.cpp | 74 ++++++---- SHADE_Engine/src/Graphics/Images/SHVkImage.h | 5 +- .../src/Graphics/Images/SHVkImageView.cpp | 136 ++++++++++-------- .../src/Graphics/Images/SHVkImageView.h | 5 + .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 19 ++- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 + .../Graphics/RenderGraph/SHRenderGraph.cpp | 9 ++ .../src/Graphics/RenderGraph/SHRenderGraph.h | 1 + .../RenderGraph/SHRenderGraphResource.cpp | 56 +++++++- .../RenderGraph/SHRenderGraphResource.h | 16 +++ 11 files changed, 220 insertions(+), 105 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 3fa797bf..766a27c6 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -195,6 +195,8 @@ namespace SHADE vk::PhysicalDeviceDescriptorIndexingFeatures descIndexingFeature{}; descIndexingFeature.descriptorBindingVariableDescriptorCount = true; + descIndexingFeature.shaderSampledImageArrayNonUniformIndexing = true; + descIndexingFeature.runtimeDescriptorArray = true; // Prepare to create the device vk::DeviceCreateInfo deviceCreateInfo diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp index b6f20af4..ed539a6c 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp @@ -79,6 +79,41 @@ namespace SHADE vmaUnmapMemory(*vmaAllocator, stagingAlloc); } + void SHVkImage::CreateFramebufferImage(void) noexcept + { + vk::ImageCreateInfo imageCreateInfo{}; + imageCreateInfo.imageType = vk::ImageType::e2D; + imageCreateInfo.extent.width = width; + imageCreateInfo.extent.height = height; + imageCreateInfo.extent.depth = depth; + imageCreateInfo.mipLevels = mipLevelCount; + imageCreateInfo.arrayLayers = layerCount; + imageCreateInfo.format = imageFormat; + imageCreateInfo.tiling = vk::ImageTiling::eOptimal; + imageCreateInfo.initialLayout = vk::ImageLayout::eUndefined; + imageCreateInfo.usage = usageFlags; + imageCreateInfo.sharingMode = vk::SharingMode::eExclusive; + imageCreateInfo.samples = vk::SampleCountFlagBits::e1; + imageCreateInfo.flags = createFlags; + + + // Prepare allocation parameters for call to create images later + VmaAllocationCreateInfo allocCreateInfo{}; + allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO; + allocCreateInfo.flags = {}; // TODO: Make sure the vk::MemoryPropertyFlags returned from vmaGetAllocationMemoryProperties has the device local bit set + + VmaAllocationInfo allocInfo{}; + + VkImage tempImage; + auto result = vmaCreateImage(*vmaAllocator, &imageCreateInfo.operator VkImageCreateInfo & (), &allocCreateInfo, &tempImage, &alloc, &allocInfo); + vkImage = tempImage; + + if (result != VK_SUCCESS) + SHVulkanDebugUtil::ReportVkError(vk::Result(result), "Failed to create vulkan image. "); + else + SHVulkanDebugUtil::ReportVkSuccess("Successfully created image. "); + } + SHVkImage::SHVkImage( VmaAllocator const* allocator, SHImageCreateParams const& imageDetails, @@ -196,37 +231,7 @@ namespace SHADE , createFlags {create} , vmaAllocator {allocator} { - vk::ImageCreateInfo imageCreateInfo{}; - imageCreateInfo.imageType = vk::ImageType::e2D; - imageCreateInfo.extent.width = width; - imageCreateInfo.extent.height = height; - imageCreateInfo.extent.depth = depth; - imageCreateInfo.mipLevels = mipLevelCount; - imageCreateInfo.arrayLayers = layerCount; - imageCreateInfo.format = imageFormat; - imageCreateInfo.tiling = vk::ImageTiling::eOptimal; - imageCreateInfo.initialLayout = vk::ImageLayout::eUndefined; - imageCreateInfo.usage = usageFlags; - imageCreateInfo.sharingMode = vk::SharingMode::eExclusive; - imageCreateInfo.samples = vk::SampleCountFlagBits::e1; - imageCreateInfo.flags = createFlags; - - - // Prepare allocation parameters for call to create images later - VmaAllocationCreateInfo allocCreateInfo{}; - allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO; - allocCreateInfo.flags = {}; // TODO: Make sure the vk::MemoryPropertyFlags returned from vmaGetAllocationMemoryProperties has the device local bit set - - VmaAllocationInfo allocInfo{}; - - VkImage tempImage; - auto result = vmaCreateImage(*vmaAllocator, &imageCreateInfo.operator VkImageCreateInfo & (), &allocCreateInfo, &tempImage, &alloc, &allocInfo); - vkImage = tempImage; - - if (result != VK_SUCCESS) - SHVulkanDebugUtil::ReportVkError(vk::Result(result), "Failed to create vulkan image. "); - else - SHVulkanDebugUtil::ReportVkSuccess("Successfully created image. "); + CreateFramebufferImage(); } Handle SHVkImage::CreateImageView(Handle const& inLogicalDeviceHdl, Handle const& parent, SHImageViewDetails const& createParams) const noexcept @@ -288,6 +293,13 @@ namespace SHADE barrier.subresourceRange.layerCount = layerCount; } + void SHVkImage::HandleResizeFramebufferImage(void) noexcept + { + vmaDestroyImage(*vmaAllocator, vkImage, alloc); + + CreateFramebufferImage(); + } + void SHVkImage::LinkWithExteriorImage(vk::Image inVkImage, vk::ImageType type, uint32_t inWidth, uint32_t inHeight, uint32_t inDepth, uint32_t layers, uint8_t levels, vk::Format format, vk::ImageUsageFlags flags) noexcept { vkImage = inVkImage; diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImage.h b/SHADE_Engine/src/Graphics/Images/SHVkImage.h index 39e695a5..b23d7bd4 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.h +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.h @@ -108,7 +108,7 @@ namespace SHADE /* PRIVATE MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ void PrepStagingBuffer(const void* data, uint32_t srcSize) noexcept; - + void CreateFramebufferImage (void) noexcept; public: /*-----------------------------------------------------------------------*/ @@ -137,7 +137,8 @@ namespace SHADE Handle CreateImageView (Handle const& inLogicalDeviceHdl, Handle const& parent, SHImageViewDetails const& createParams) const noexcept; void TransferToDeviceResource (Handle cmdBufferHdl) noexcept; void PrepareImageTransitionInfo (vk::ImageLayout oldLayout, vk::ImageLayout newLayout, vk::ImageMemoryBarrier& barrier) noexcept; - + void HandleResizeFramebufferImage(void) noexcept; + /*-----------------------------------------------------------------------*/ /* GETTERS AND SETTERS */ /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImageView.cpp b/SHADE_Engine/src/Graphics/Images/SHVkImageView.cpp index 9d12d7cd..44b5718c 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImageView.cpp +++ b/SHADE_Engine/src/Graphics/Images/SHVkImageView.cpp @@ -6,6 +6,67 @@ namespace SHADE { + + void SHVkImageView::Create(void) noexcept + { + auto parentImageCreateFlags = parentImage->GetImageeCreateFlags(); + + // 2D array image type means parent image must be 2D array compatible + if (imageViewDetails.viewType == vk::ImageViewType::e2DArray) + { + if (!(parentImageCreateFlags & vk::ImageCreateFlagBits::e2DArrayCompatible)) + { + SHLOG_ERROR("Failed to create image view. Parent image not 2D array compatible. "); + return; + } + } + + // Check if its possible for the image view to have different format than parent image + if (imageViewDetails.format != parentImage->GetImageFormat()) + { + if (!(parentImageCreateFlags & vk::ImageCreateFlagBits::eMutableFormat)) + { + SHLOG_ERROR("Failed to create image view. Format for image view not same as image but image not initialized with mutable format bit. "); + return; + } + } + + + vk::ImageViewCreateInfo viewCreateInfo + { + .pNext = nullptr, // Can be used to override with a VkImageViewUsageCreateInfo to override usage. See Vulkan spec page 877 for more information + .image = parentImage->GetVkImage(), + .viewType = imageViewDetails.viewType, + .format = imageViewDetails.format, + .components + { + .r = vk::ComponentSwizzle::eR, + .g = vk::ComponentSwizzle::eG, + .b = vk::ComponentSwizzle::eB, + .a = vk::ComponentSwizzle::eA, + }, + .subresourceRange + { + .aspectMask = imageViewDetails.imageAspectFlags, + .baseMipLevel = imageViewDetails.baseMipLevel, + .levelCount = imageViewDetails.mipLevelCount, + .baseArrayLayer = imageViewDetails.baseArrayLayer, + .layerCount = imageViewDetails.layerCount, + }, + }; + + if (auto result = logicalDeviceHdl->GetVkLogicalDevice().createImageView(&viewCreateInfo, nullptr, &vkImageView); result != vk::Result::eSuccess) + { + SHVulkanDebugUtil::ReportVkError(result, "Failed to create image view! "); + return; + } + else + { + SHVulkanDebugUtil::ReportVkSuccess("Successfully created image view. "); + } + + } + /***************************************************************************/ /*! @@ -18,70 +79,12 @@ namespace SHADE */ /***************************************************************************/ SHVkImageView::SHVkImageView(Handle const& inLogicalDeviceHdl, Handle const& parent, SHImageViewDetails const& createParams) noexcept - : parentImage{ } + : parentImage{ parent } , vkImageView{} - , imageViewDetails{} + , imageViewDetails{createParams} , logicalDeviceHdl {inLogicalDeviceHdl} { - auto parentImageCreateFlags = parent->GetImageeCreateFlags(); - - // 2D array image type means parent image must be 2D array compatible - if (createParams.viewType == vk::ImageViewType::e2DArray) - { - if (!(parentImageCreateFlags & vk::ImageCreateFlagBits::e2DArrayCompatible)) - { - SHLOG_ERROR("Failed to create image view. Parent image not 2D array compatible. "); - return; - } - } - - // Check if its possible for the image view to have different format than parent image - if (createParams.format != parent->GetImageFormat()) - { - if (!(parentImageCreateFlags & vk::ImageCreateFlagBits::eMutableFormat)) - { - SHLOG_ERROR("Failed to create image view. Format for image view not same as image but image not initialized with mutable format bit. "); - return; - } - } - - - vk::ImageViewCreateInfo viewCreateInfo - { - .pNext = nullptr, // Can be used to override with a VkImageViewUsageCreateInfo to override usage. See Vulkan spec page 877 for more information - .image = parent->GetVkImage(), - .viewType = createParams.viewType, - .format = createParams.format, - .components - { - .r = vk::ComponentSwizzle::eR, - .g = vk::ComponentSwizzle::eG, - .b = vk::ComponentSwizzle::eB, - .a = vk::ComponentSwizzle::eA, - }, - .subresourceRange - { - .aspectMask = createParams.imageAspectFlags, - .baseMipLevel = createParams.baseMipLevel, - .levelCount = createParams.mipLevelCount, - .baseArrayLayer = createParams.baseArrayLayer, - .layerCount = createParams.layerCount, - }, - }; - - if (auto result = inLogicalDeviceHdl->GetVkLogicalDevice().createImageView(&viewCreateInfo, nullptr, &vkImageView); result != vk::Result::eSuccess) - { - SHVulkanDebugUtil::ReportVkError(result, "Failed to create image view! "); - return; - } - else - { - SHVulkanDebugUtil::ReportVkSuccess("Successfully created image view. "); - } - - // After success, THEN assign variables - parentImage = parent; - imageViewDetails = createParams; + Create(); } SHVkImageView::SHVkImageView(SHVkImageView&& rhs) noexcept @@ -94,6 +97,17 @@ namespace SHADE } + void SHVkImageView::ViewNewImage(Handle const& parent, SHImageViewDetails const& createParams) noexcept + { + imageViewDetails = createParams; + parentImage = parent; + + if (vkImageView) + logicalDeviceHdl->GetVkLogicalDevice().destroyImageView(vkImageView, nullptr); + + Create(); + } + Handle const& SHVkImageView::GetParentImage(void) const noexcept { return parentImage; diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImageView.h b/SHADE_Engine/src/Graphics/Images/SHVkImageView.h index afa357ef..ae23d7a7 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImageView.h +++ b/SHADE_Engine/src/Graphics/Images/SHVkImageView.h @@ -25,12 +25,17 @@ namespace SHADE //! Logical Device needed for creation and destruction Handle logicalDeviceHdl; + //! Create new image view + void Create (void) noexcept; + public: SHVkImageView(Handle const& inLogicalDeviceHdl, Handle const& parent, SHImageViewDetails const& createParams) noexcept; ~SHVkImageView(void) noexcept; SHVkImageView(SHVkImageView&& rhs) noexcept; SHVkImageView& operator=(SHVkImageView&& rhs) noexcept; + void ViewNewImage (Handle const& parent, SHImageViewDetails const& createParams) noexcept; + /*-----------------------------------------------------------------------*/ /* GETTERS AND SETTERS */ /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 40e24979..e4207c20 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -341,10 +341,7 @@ namespace SHADE { device->WaitIdle(); - // Resize the swapchain - swapchain->Resize(surface, windowDims.first, windowDims.second); - - renderContext.HandleResize(); + HandleResize(); } const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame(); @@ -387,10 +384,8 @@ namespace SHADE // If swapchain is incompatible/outdated if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR) { - auto windowDims = window->GetWindowSize(); - swapchain->Resize(surface, windowDims.first, windowDims.second); - renderContext.HandleResize(); + HandleResize(); } } @@ -509,6 +504,16 @@ namespace SHADE ); } + void SHGraphicsSystem::HandleResize(void) noexcept + { + auto windowDims = window->GetWindowSize(); + + // Resize the swapchain + swapchain->Resize(surface, windowDims.first, windowDims.second); + + renderContext.HandleResize(); + } + void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept { window = wind; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 84dc39cd..10df44a5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -246,6 +246,8 @@ namespace SHADE /***************************************************************************/ void BuildTextures(); + void HandleResize(void) noexcept; + /*-----------------------------------------------------------------------------*/ /* Setters */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 828a83f1..27a1d604 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -480,6 +480,15 @@ namespace SHADE } } + void SHRenderGraph::HandleResize(void) noexcept + { + // resize resources + for (auto& [name, resource]: graphResources) + resource->HandleResize(); + + + } + Handle SHRenderGraph::GetNode(std::string const& nodeName) const noexcept { if (nodeIndexing.contains(nodeName)) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 8b5b2212..83aeeb2c 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -80,6 +80,7 @@ namespace SHADE void Generate (void) noexcept; void Execute (uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept; void FinaliseBatch(uint32_t frameIndex, Handle descPool); + void HandleResize (void) noexcept; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index eb873b16..72dd557f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -2,9 +2,11 @@ #include "SHRenderGraphResource.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Swapchain/SHVkSwapchain.h" +#include "Graphics/Images/SHVkImageView.h" namespace SHADE { + /***************************************************************************/ /*! @@ -42,7 +44,9 @@ namespace SHADE */ /***************************************************************************/ SHRenderGraphResource::SHRenderGraphResource(Handle const& logicalDevice, Handle const& swapchain, std::string const& name, SH_ATT_DESC_TYPE type, vk::Format format, uint32_t w, uint32_t h, uint8_t levels, vk::ImageCreateFlagBits createFlags) noexcept - : resourceType{ type } + : logicalDevice {logicalDevice} + , swapchain{ swapchain } + , resourceType{ type } , resourceFormat{ format } , images{} , imageViews{} @@ -52,10 +56,10 @@ namespace SHADE , resourceName{ name } { // If the resource type is an arbitrary image and not swapchain image - if (type != SH_ATT_DESC_TYPE::COLOR_PRESENT) + if (resourceType != SH_ATT_DESC_TYPE::COLOR_PRESENT) { - vk::ImageAspectFlags imageAspectFlags; - vk::ImageUsageFlags usage = {}; + imageAspectFlags = vk::ImageAspectFlags{}; + usage = {}; // Check the resource type and set image usage flags and image aspect flags accordingly switch (resourceType) @@ -189,4 +193,48 @@ namespace SHADE } + void SHRenderGraphResource::HandleResize(void) noexcept + { + if (resourceType != SH_ATT_DESC_TYPE::COLOR_PRESENT) + { + // prepare image view details + SHImageViewDetails viewDetails + { + .viewType = vk::ImageViewType::e2D, + .format = images[0]->GetImageFormat(), + .imageAspectFlags = imageAspectFlags, + .baseMipLevel = 0, + .mipLevelCount = mipLevels, + .baseArrayLayer = 0, + .layerCount = 1, + }; + + for (uint32_t i = 0; i < images.size(); ++i) + { + images[i]->HandleResizeFramebufferImage(); + imageViews[i]->ViewNewImage(images[i], viewDetails); + } + } + else + { + // Prepare image view details + SHImageViewDetails viewDetails + { + .viewType = vk::ImageViewType::e2D, + .format = swapchain->GetSurfaceFormatKHR().format, + .imageAspectFlags = vk::ImageAspectFlagBits::eColor, + .baseMipLevel = 0, + .mipLevelCount = 1, + .baseArrayLayer = 0, + .layerCount = 1, + }; + + for (uint32_t i = 0; i < swapchain->GetNumImages(); ++i) + { + images[i] = swapchain->GetSwapchainImage(i); + imageViews[i]->ViewNewImage(images[i], viewDetails); + } + } + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h index fcb16601..741acdc0 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -20,6 +20,12 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PRIVATE MEMBER VARIABLES */ /*-----------------------------------------------------------------------*/ + // for creation/recreation + Handle logicalDevice; + + // for creation/recreation + Handle swapchain; + //! Name of the resource std::string resourceName; @@ -47,6 +53,14 @@ namespace SHADE //! Number of mipmap levels uint8_t mipLevels; + + //! image aspect flags + vk::ImageAspectFlags imageAspectFlags; + + //! usage flags + vk::ImageUsageFlags usage = {}; + + public: /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ @@ -56,6 +70,8 @@ namespace SHADE SHRenderGraphResource& operator=(SHRenderGraphResource&& rhs) noexcept; ~SHRenderGraphResource(void) noexcept; + void HandleResize (void) noexcept; + friend class SHRenderGraphNode; friend class SHRenderGraph; }; From 1a725c24e26d0feb7a3d7cb726ab93cd61755291 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 1 Oct 2022 21:25:22 +0800 Subject: [PATCH 02/14] Stored renderpass attachement information in SHVkRenderpass --- .../RenderGraph/SHRenderGraphNode.cpp | 5 ++ .../Graphics/RenderGraph/SHRenderGraphNode.h | 1 + .../Graphics/Renderpass/SHVkRenderpass.cpp | 57 ++++++++++++------- .../src/Graphics/Renderpass/SHVkRenderpass.h | 8 ++- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index b981225a..551e90fc 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -56,6 +56,11 @@ namespace SHADE } } + void SHRenderGraphNode::HandleResize(void) noexcept + { + + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index 59b20271..c713f402 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -81,6 +81,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ void CreateRenderpass(void) noexcept; void CreateFramebuffer(void) noexcept; + void HandleResize (void) noexcept; public: /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp index 29de5954..349c507e 100644 --- a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp +++ b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp @@ -30,7 +30,10 @@ namespace SHADE SHVkRenderpass::SHVkRenderpass(Handle const& inLogicalDeviceHdl, std::span const vkDescriptions, std::vector const& subpasses) noexcept : logicalDeviceHdl {inLogicalDeviceHdl} , numAttDescs {static_cast(vkDescriptions.size())} + , vkSubpassDescriptions{} + , vkSubpassDeps{} , clearColors{} + , vkAttachmentDescriptions{} { for (uint32_t i = 0; i < vkDescriptions.size(); ++i) { @@ -42,7 +45,6 @@ namespace SHADE vk::RenderPassCreateInfo renderPassCreateInfo{}; - std::vector subpassDeps; // For validating the depth ref auto isValidDepthRef = [&](vk::AttachmentReference const& depthRef) -> bool @@ -50,13 +52,16 @@ namespace SHADE return !(depthRef.attachment == static_cast (-1) && depthRef.layout == vk::ImageLayout::eUndefined); }; + for (uint32_t i = 0; i < vkDescriptions.size(); ++i) + vkAttachmentDescriptions[i] = vkDescriptions[i]; + uint32_t subpassIndex = 0; if (!subpasses.empty()) { for (auto& subpass : subpasses) { - subpassDescriptions.emplace_back(); - auto& spDesc = subpassDescriptions.back(); + vkSubpassDescriptions.emplace_back(); + auto& spDesc = vkSubpassDescriptions.back(); spDesc.pColorAttachments = subpass.colorRefs.data(); spDesc.colorAttachmentCount = static_cast(subpass.colorRefs.size()); @@ -88,18 +93,18 @@ namespace SHADE }; // Push a new dependency - subpassDeps.push_back(dependency); + vkSubpassDeps.push_back(dependency); ++subpassIndex; } // Renderpass create info for render pass creation - renderPassCreateInfo.attachmentCount = static_cast(vkDescriptions.size()); - renderPassCreateInfo.pAttachments = vkDescriptions.data(); - renderPassCreateInfo.subpassCount = static_cast(subpassDescriptions.size()); - renderPassCreateInfo.pSubpasses = subpassDescriptions.data(); - renderPassCreateInfo.dependencyCount = static_cast(subpassDeps.size()); - renderPassCreateInfo.pDependencies = subpassDeps.data(); + renderPassCreateInfo.attachmentCount = static_cast(vkAttachmentDescriptions.size()); + renderPassCreateInfo.pAttachments = vkAttachmentDescriptions.data(); + renderPassCreateInfo.subpassCount = static_cast(vkSubpassDescriptions.size()); + renderPassCreateInfo.pSubpasses = vkSubpassDescriptions.data(); + renderPassCreateInfo.dependencyCount = static_cast(vkSubpassDeps.size()); + renderPassCreateInfo.pDependencies = vkSubpassDeps.data(); } // No subpasses passed in, create a default one. @@ -172,6 +177,8 @@ namespace SHADE : logicalDeviceHdl{ inLogicalDeviceHdl } , numAttDescs{ static_cast(vkDescriptions.size()) } , clearColors{} + , vkSubpassDescriptions{ } + , vkSubpassDeps{ } { for (uint32_t i = 0; i < vkDescriptions.size(); ++i) { @@ -181,18 +188,24 @@ namespace SHADE clearColors[i].color = { {{0.0f, 0.0f, 0.0f, 1.0f}} }; } - subpassDescriptions.resize (spDescs.size()); - for (uint32_t i = 0; i < subpassDescriptions.size(); ++i) - { - subpassDescriptions[i] = spDescs[i]; - } + vkAttachmentDescriptions.resize(vkDescriptions.size()); + for (uint32_t i = 0; i < vkDescriptions.size(); ++i) + vkAttachmentDescriptions[i] = vkDescriptions[i]; + + vkSubpassDescriptions.resize (spDescs.size()); + for (uint32_t i = 0; i < vkSubpassDescriptions.size(); ++i) + vkSubpassDescriptions[i] = spDescs[i]; + + vkSubpassDeps.resize(spDeps.size()); + for (uint32_t i = 0; i < vkSubpassDeps.size(); ++i) + vkSubpassDeps[i] = spDeps[i]; vk::RenderPassCreateInfo renderPassCreateInfo{}; renderPassCreateInfo.attachmentCount = static_cast(vkDescriptions.size()); renderPassCreateInfo.pAttachments = vkDescriptions.data(); - renderPassCreateInfo.subpassCount = static_cast(subpassDescriptions.size()); - renderPassCreateInfo.pSubpasses = subpassDescriptions.data(); + renderPassCreateInfo.subpassCount = static_cast(vkSubpassDescriptions.size()); + renderPassCreateInfo.pSubpasses = vkSubpassDescriptions.data(); renderPassCreateInfo.dependencyCount = static_cast(spDeps.size()); renderPassCreateInfo.pDependencies = spDeps.data(); @@ -210,8 +223,10 @@ namespace SHADE SHVkRenderpass::SHVkRenderpass(SHVkRenderpass&& rhs) noexcept : vkRenderpass {rhs.vkRenderpass} , logicalDeviceHdl {rhs.logicalDeviceHdl} - , subpassDescriptions {std::move (rhs.subpassDescriptions)} - , clearColors {std::move (rhs.clearColors)} + , vkSubpassDescriptions{ std::move(rhs.vkSubpassDescriptions) } + , vkSubpassDeps{ std::move(rhs.vkSubpassDeps) } + , clearColors{ std::move(rhs.clearColors) } + , vkAttachmentDescriptions{ std::move(rhs.vkAttachmentDescriptions) } { rhs.vkRenderpass = VK_NULL_HANDLE; } @@ -224,8 +239,10 @@ namespace SHADE vkRenderpass = rhs.vkRenderpass; logicalDeviceHdl = rhs.logicalDeviceHdl; - subpassDescriptions = std::move(rhs.subpassDescriptions); + vkSubpassDescriptions = std::move(rhs.vkSubpassDescriptions); + vkSubpassDeps = std::move(rhs.vkSubpassDeps); clearColors = std::move(rhs.clearColors); + vkAttachmentDescriptions = std::move(rhs.vkAttachmentDescriptions); rhs.vkRenderpass = VK_NULL_HANDLE; diff --git a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h index b0ae7445..a2799eb7 100644 --- a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h +++ b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h @@ -29,7 +29,13 @@ namespace SHADE Handle logicalDeviceHdl; //! Container of subpass information used to construct subpasses - std::vector subpassDescriptions; + std::vector vkSubpassDescriptions; + + //! Container of subpass dependencies used to create renderpass + std::vector vkSubpassDeps; + + //! Attachment descriptions + std::vector vkAttachmentDescriptions; //! Clear colors for the color and depth std::array clearColors; From 1a14e5241b1fa12325aa45e4f4f6ce4f222dee9d Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sat, 1 Oct 2022 23:14:42 +0800 Subject: [PATCH 03/14] Added names for SHGraphicsSystem Routines --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 29 +++++++++++++++++++ .../MiddleEnd/Interface/SHGraphicsSystem.h | 4 +++ 2 files changed, 33 insertions(+) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index e4207c20..8e3c599b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -518,21 +518,50 @@ namespace SHADE { window = wind; } + + /*-----------------------------------------------------------------------------------*/ + /* System Routine Functions - BeginRoutine */ + /*-----------------------------------------------------------------------------------*/ + SHGraphicsSystem::BeginRoutine::BeginRoutine() + : SHSystemRoutine("Graphics System Frame Set Up", false) + {} void SHGraphicsSystem::BeginRoutine::Execute(double) noexcept { reinterpret_cast(system)->BeginRender(); } + + /*-----------------------------------------------------------------------------------*/ + /* System Routine Functions - RenderRoutine */ + /*-----------------------------------------------------------------------------------*/ + SHGraphicsSystem::RenderRoutine::RenderRoutine() + : SHSystemRoutine("Graphics System Render", false) + {} void SHGraphicsSystem::RenderRoutine::Execute(double dt) noexcept { reinterpret_cast(system)->Run(dt); } + /*-----------------------------------------------------------------------------------*/ + /* System Routine Functions - EndRoutine */ + /*-----------------------------------------------------------------------------------*/ + SHGraphicsSystem::EndRoutine::EndRoutine() + : SHSystemRoutine("Graphics System Frame Clean Up", false) + {} + void SHGraphicsSystem::EndRoutine::Execute(double) noexcept { reinterpret_cast(system)->EndRender(); } + + /*-----------------------------------------------------------------------------------*/ + /* System Routine Functions - BatcherDispatcherRoutine */ + /*-----------------------------------------------------------------------------------*/ + SHGraphicsSystem::BatcherDispatcherRoutine::BatcherDispatcherRoutine() + : SHSystemRoutine("Graphics System Batcher Dispatcher", false) + {} + void SHGraphicsSystem::BatcherDispatcherRoutine::Execute(double) noexcept { auto& renderables = SHComponentManager::GetDense(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 10df44a5..3a392ac5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -69,21 +69,25 @@ namespace SHADE class SH_API BeginRoutine final : public SHSystemRoutine { public: + BeginRoutine(); virtual void Execute(double dt) noexcept override final; }; class SH_API RenderRoutine final : public SHSystemRoutine { public: + RenderRoutine(); virtual void Execute(double dt) noexcept override final; }; class SH_API EndRoutine final : public SHSystemRoutine { public: + EndRoutine(); virtual void Execute(double dt) noexcept override final; }; class SH_API BatcherDispatcherRoutine final : public SHSystemRoutine { public: + BatcherDispatcherRoutine(); virtual void Execute(double dt) noexcept override final; }; From 77653ebde5940ac0707adad35162349ad43e5450 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sat, 1 Oct 2022 23:56:45 +0800 Subject: [PATCH 04/14] add window isMinimized --- SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp | 6 ++++++ SHADE_Engine/src/Graphics/Windowing/SHWindow.h | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp index 4d8dae72..a4569c75 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp @@ -378,6 +378,12 @@ namespace SHADE { wndData.width = static_cast(size.cx); wndData.height = static_cast(size.cy); + + if (type == SIZE_MINIMIZED) + { + wndData.isMinimised = true; + } + for (auto const& entry : windowResizeCallbacks) { entry.second(static_cast(wndData.width), static_cast(wndData.height)); diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h index 1e08dcb0..8f15bb60 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h @@ -18,7 +18,7 @@ namespace SHADE }; struct WindowData - { + { unsigned x = 0; unsigned y = 0; @@ -42,7 +42,7 @@ namespace SHADE bool closable = true; bool minimizable = true; - + bool maximizable = true; //bool canFullscreen = true; @@ -56,11 +56,13 @@ namespace SHADE bool shadowEnabled = true; bool isVisible = true; - + bool isFullscreen = false; bool modal = false; + bool isMinimised = false; + std::wstring title = L"SHADE ENGINE"; std::wstring name = L"SHADEEngineApp"; @@ -103,7 +105,7 @@ namespace SHADE void SetMousePosition(unsigned x, unsigned y); //unsigned GetBGColor(); - + void SetBGColor(unsigned color); void Minimize(); @@ -163,6 +165,7 @@ namespace SHADE void OnSize(UINT msg, UINT type, SIZE size); void OnPosChange(LPWINDOWPOS pos); void OnPaint(HDC hdc, LPPAINTSTRUCT paint); + bool IsMinimized() const { return wndData.isMinimised; } }; static SHWindowMap windowMap; static SHWindow* windowBeingCreated = nullptr; From e2b86545bb8482c95d2f90f457e1a6d253bfbb14 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 1 Oct 2022 23:57:08 +0800 Subject: [PATCH 05/14] Window resize working --- SHADE_Application/src/Scenes/SBTestScene.cpp | 4 +- .../Graphics/Framebuffer/SHVkFramebuffer.cpp | 45 +++++++++++++++++++ .../Graphics/Framebuffer/SHVkFramebuffer.h | 2 + .../src/Graphics/Images/SHVkImage.cpp | 5 ++- SHADE_Engine/src/Graphics/Images/SHVkImage.h | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 18 +++++++- .../MiddleEnd/Interface/SHGraphicsSystem.h | 2 + .../MiddleEnd/Interface/SHViewport.cpp | 12 +++++ .../Graphics/MiddleEnd/Interface/SHViewport.h | 6 +++ .../Graphics/RenderGraph/SHRenderGraph.cpp | 14 +++--- .../src/Graphics/RenderGraph/SHRenderGraph.h | 2 +- .../RenderGraph/SHRenderGraphNode.cpp | 23 ++++++++++ .../RenderGraph/SHRenderGraphResource.cpp | 9 +++- .../RenderGraph/SHRenderGraphResource.h | 2 +- .../Graphics/Renderpass/SHVkRenderpass.cpp | 27 +++++++++++ .../src/Graphics/Renderpass/SHVkRenderpass.h | 2 + 16 files changed, 158 insertions(+), 17 deletions(-) diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index 6daa3645..5eee8cac 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -76,8 +76,8 @@ namespace Sandbox // Create Stress Test Objects static const SHVec3 TEST_OBJ_SCALE = { 0.05f, 0.05f, 0.05f }; - constexpr int NUM_ROWS = 100; - constexpr int NUM_COLS = 100; + constexpr int NUM_ROWS = 10; + constexpr int NUM_COLS = 10; static const SHVec3 TEST_OBJ_SPACING = { 0.05f, 0.05f, 0.05f }; static const SHVec3 TEST_OBJ_START_POS = { - (NUM_COLS / 2 * TEST_OBJ_SPACING.x ) + 1.0f, -2.0f, -1.0f }; diff --git a/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.cpp b/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.cpp index 1386134f..76e627d3 100644 --- a/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.cpp +++ b/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.cpp @@ -98,6 +98,51 @@ namespace SHADE return *this; } + void SHVkFramebuffer::HandleResize(Handle const& renderpassHdl, std::vector> const& attachments, uint32_t inWidth, uint32_t inHeight) noexcept + { + width = inWidth; + height = inHeight; + + for (auto& attachment : attachments) + { + // Not sure if its an error to pass in diff dimension images. + if (attachment->GetParentImage()->GetWidth() != (*attachments.begin())->GetParentImage()->GetWidth() || attachment->GetParentImage()->GetHeight() != (*attachments.begin())->GetParentImage()->GetHeight()) + { + SHLOG_ERROR("Dimensions of images not same as each other. Cannot create framebuffer."); + return; + } + } + + std::vector vkAttachments(attachments.size()); + + uint32_t i = 0; + for(auto const& attachment : attachments) + { + vkAttachments[i] = attachment->GetImageView(); + ++i; + } + + vk::FramebufferCreateInfo createInfo + { + .renderPass = renderpassHdl->GetVkRenderpass(), + .attachmentCount = static_cast(vkAttachments.size()), + .pAttachments = vkAttachments.data(), + .width = width, + .height = height, + .layers = 1 // TODO: Find out why this is 1 + }; + + if (auto result = logicalDeviceHdl->GetVkLogicalDevice().createFramebuffer(&createInfo, nullptr, &vkFramebuffer); result != vk::Result::eSuccess) + { + SHVulkanDebugUtil::ReportVkError(result, "Failed to create framebuffer. "); + return; + } + else + { + SHVulkanDebugUtil::ReportVkSuccess("Successfully created framebuffer. "); + } + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h b/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h index fa9161e8..47bfcf99 100644 --- a/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h +++ b/SHADE_Engine/src/Graphics/Framebuffer/SHVkFramebuffer.h @@ -37,6 +37,8 @@ namespace SHADE SHVkFramebuffer(SHVkFramebuffer&& rhs) noexcept; SHVkFramebuffer& operator=(SHVkFramebuffer&& rhs) noexcept; + void HandleResize (Handle const& renderpassHdl, std::vector> const& attachments, uint32_t inWidth, uint32_t inHeight) noexcept; + /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp index ed539a6c..00cc31bf 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp @@ -293,10 +293,13 @@ namespace SHADE barrier.subresourceRange.layerCount = layerCount; } - void SHVkImage::HandleResizeFramebufferImage(void) noexcept + void SHVkImage::HandleResizeFramebufferImage(uint32_t newWidth, uint32_t newHeight) noexcept { vmaDestroyImage(*vmaAllocator, vkImage, alloc); + width = newWidth; + height = newHeight; + CreateFramebufferImage(); } diff --git a/SHADE_Engine/src/Graphics/Images/SHVkImage.h b/SHADE_Engine/src/Graphics/Images/SHVkImage.h index b23d7bd4..51b71b26 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.h +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.h @@ -137,7 +137,7 @@ namespace SHADE Handle CreateImageView (Handle const& inLogicalDeviceHdl, Handle const& parent, SHImageViewDetails const& createParams) const noexcept; void TransferToDeviceResource (Handle cmdBufferHdl) noexcept; void PrepareImageTransitionInfo (vk::ImageLayout oldLayout, vk::ImageLayout newLayout, vk::ImageMemoryBarrier& barrier) noexcept; - void HandleResizeFramebufferImage(void) noexcept; + void HandleResizeFramebufferImage(uint32_t newWidth, uint32_t newHeight) noexcept; /*-----------------------------------------------------------------------*/ /* GETTERS AND SETTERS */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index e4207c20..979f8d40 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -67,6 +67,9 @@ namespace SHADE // Register callback to notify render context upon a window resize window->RegisterWindowSizeCallback([&]([[maybe_unused]] uint32_t width, [[maybe_unused]] uint32_t height) { + if (width == 0 || height == 0) + return; + renderContext.SetIsResized(true); }); @@ -116,8 +119,8 @@ namespace SHADE screenCamera = resourceManager.Create(); screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); screenCamera->SetOrthographic(static_cast(windowDims.first), static_cast(windowDims.second), 0.01f, 100.0f); + worldCamera = resourceManager.Create(); - //worldCamera->SetLookAt(SHVec3(1.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 2.0f), SHVec3(0.0f, 1.0f, 0.0f)); worldCamera->SetLookAt(SHVec3(0.0f, 0.0f, 0.0f), SHVec3(0.0f, 0.0f, -2.0f), SHVec3(0.0f, 1.0f, 0.0f)); worldCamera->SetPerspective(90.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); @@ -125,7 +128,7 @@ namespace SHADE defaultViewport = AddViewport(vk::Viewport(0.0f, 0.0f, static_cast(window->GetWindowSize().first), static_cast(window->GetWindowSize().second), 0.0f, 1.0f)); // Get render graph from default viewport world renderer - auto worldRenderGraph = resourceManager.Create(); + worldRenderGraph = resourceManager.Create(); std::vector> renderContextCmdPools{swapchain->GetNumImages()}; for (uint32_t i = 0; i < renderContextCmdPools.size(); ++i) @@ -249,6 +252,10 @@ namespace SHADE // Begin recording the command buffer currentCmdBuffer->BeginRecording(); + uint32_t w = viewports[vpIndex]->GetWidth(); + uint32_t h = viewports[vpIndex]->GetHeight(); + currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); + currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout()); // Bind all the buffers required for meshes @@ -512,6 +519,13 @@ namespace SHADE swapchain->Resize(surface, windowDims.first, windowDims.second); renderContext.HandleResize(); + + worldRenderGraph->HandleResize(windowDims.first, windowDims.second); + + defaultViewport->SetWidth(windowDims.first); + defaultViewport->SetHeight(windowDims.second); + + worldCamera->SetPerspective(90.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); } void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 10df44a5..1dddaeb1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -316,5 +316,7 @@ namespace SHADE // Temp Materials Handle defaultMaterial; + + Handle worldRenderGraph; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp index 25c5bca2..d6eea3d7 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp @@ -73,4 +73,16 @@ namespace SHADE iter->Free(); renderers.erase(iter); } + + void SHViewport::SetWidth(uint32_t w) noexcept + { + viewport.width = w; + } + + void SHViewport::SetHeight(uint32_t h) noexcept + { + viewport.height = h; + + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h index d97d62ce..ce992f77 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h @@ -62,6 +62,12 @@ namespace SHADE Handle AddRenderer(ResourceManager& resourceManager, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle renderGraph); void RemoveRenderer(Handle renderer); + /*-----------------------------------------------------------------------------*/ + /* Setters */ + /*-----------------------------------------------------------------------------*/ + void SetWidth(uint32_t w) noexcept; + void SetHeight (uint32_t h) noexcept; + /*-----------------------------------------------------------------------------*/ /* Getters */ /*-----------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 27a1d604..cad6a78e 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -46,7 +46,7 @@ namespace SHADE if (w == static_cast(-1) && h == static_cast(-1)) { w = swapchainHdl->GetSwapchainImage(0)->GetWidth(); - w = swapchainHdl->GetSwapchainImage(0)->GetHeight(); + h = swapchainHdl->GetSwapchainImage(0)->GetHeight(); format = swapchainHdl->GetSurfaceFormatKHR().format; } @@ -465,9 +465,6 @@ namespace SHADE // better way to manage these void SHRenderGraph::Execute(uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept { - // TODO: DON'T HARDCODE THIS - cmdBuffer->SetViewportScissor(1920.0f, 1080.0f, 1920, 1080); - for (auto& node : nodes) node->Execute(cmdBuffer, descPool, frameIndex); } @@ -480,13 +477,16 @@ namespace SHADE } } - void SHRenderGraph::HandleResize(void) noexcept + void SHRenderGraph::HandleResize(uint32_t newWidth, uint32_t newHeight) noexcept { // resize resources for (auto& [name, resource]: graphResources) - resource->HandleResize(); - + resource->HandleResize(newWidth, newHeight); + for (auto& node : nodes) + { + node->HandleResize(); + } } Handle SHRenderGraph::GetNode(std::string const& nodeName) const noexcept diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 83aeeb2c..a3140a4f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -80,7 +80,7 @@ namespace SHADE void Generate (void) noexcept; void Execute (uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept; void FinaliseBatch(uint32_t frameIndex, Handle descPool); - void HandleResize (void) noexcept; + void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 551e90fc..05232af3 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -3,6 +3,7 @@ #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Images/SHVkImageView.h" #include "Graphics/Swapchain/SHVkSwapchain.h" +#include "Graphics/Framebuffer/SHVkFramebuffer.h" #include "SHRenderGraphResource.h" #include "SHSubpass.h" @@ -58,7 +59,29 @@ namespace SHADE void SHRenderGraphNode::HandleResize(void) noexcept { + renderpass->HandleResize(); + for (uint32_t i = 0; i < framebuffers.size(); ++i) + { + std::vector> imageViews(attResources.size()); + uint32_t fbWidth = std::numeric_limits::max(); + uint32_t fbHeight = std::numeric_limits::max(); + + for (uint32_t j = 0; j < attResources.size(); ++j) + { + uint32_t imageViewIndex = (attResources[j]->resourceType == SH_ATT_DESC_TYPE::COLOR_PRESENT) ? i : 0; + imageViews[j] = attResources[j]->imageViews[imageViewIndex]; + + // We want the minimum dimensions for the framebuffer because the image attachments referenced cannot have dimensions smaller than the framebuffer's + if (fbWidth > attResources[j]->width) + fbWidth = attResources[j]->width; + if (fbHeight > attResources[j]->height) + fbHeight = attResources[j]->height; + } + + + framebuffers[i]->HandleResize(renderpass, imageViews, fbWidth, fbHeight); + } } /***************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index 72dd557f..cc881867 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -146,6 +146,7 @@ namespace SHADE , width{ rhs.width } , height{ rhs.height } , mipLevels{ rhs.mipLevels } + , imageAspectFlags{ rhs.imageAspectFlags } { } @@ -176,6 +177,7 @@ namespace SHADE width = rhs.width; height = rhs.height; mipLevels = rhs.mipLevels; + imageAspectFlags = rhs.imageAspectFlags; return *this; } @@ -193,8 +195,11 @@ namespace SHADE } - void SHRenderGraphResource::HandleResize(void) noexcept + void SHRenderGraphResource::HandleResize(uint32_t newWidth, uint32_t newHeight) noexcept { + width = newWidth; + height = newHeight; + if (resourceType != SH_ATT_DESC_TYPE::COLOR_PRESENT) { // prepare image view details @@ -211,7 +216,7 @@ namespace SHADE for (uint32_t i = 0; i < images.size(); ++i) { - images[i]->HandleResizeFramebufferImage(); + images[i]->HandleResizeFramebufferImage(width, height); imageViews[i]->ViewNewImage(images[i], viewDetails); } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h index 741acdc0..ebb699d8 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -70,7 +70,7 @@ namespace SHADE SHRenderGraphResource& operator=(SHRenderGraphResource&& rhs) noexcept; ~SHRenderGraphResource(void) noexcept; - void HandleResize (void) noexcept; + void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept; friend class SHRenderGraphNode; friend class SHRenderGraph; diff --git a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp index 349c507e..fee23f13 100644 --- a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp +++ b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.cpp @@ -227,6 +227,7 @@ namespace SHADE , vkSubpassDeps{ std::move(rhs.vkSubpassDeps) } , clearColors{ std::move(rhs.clearColors) } , vkAttachmentDescriptions{ std::move(rhs.vkAttachmentDescriptions) } + , numAttDescs{rhs.numAttDescs} { rhs.vkRenderpass = VK_NULL_HANDLE; } @@ -243,6 +244,7 @@ namespace SHADE vkSubpassDeps = std::move(rhs.vkSubpassDeps); clearColors = std::move(rhs.clearColors); vkAttachmentDescriptions = std::move(rhs.vkAttachmentDescriptions); + numAttDescs = std::move(rhs.numAttDescs); rhs.vkRenderpass = VK_NULL_HANDLE; @@ -255,6 +257,31 @@ namespace SHADE } + void SHVkRenderpass::HandleResize(void) noexcept + { + logicalDeviceHdl->GetVkLogicalDevice().destroyRenderPass(vkRenderpass, nullptr); + + vk::RenderPassCreateInfo renderPassCreateInfo{}; + + renderPassCreateInfo.attachmentCount = static_cast(vkAttachmentDescriptions.size()); + renderPassCreateInfo.pAttachments = vkAttachmentDescriptions.data(); + renderPassCreateInfo.subpassCount = static_cast(vkSubpassDescriptions.size()); + renderPassCreateInfo.pSubpasses = vkSubpassDescriptions.data(); + renderPassCreateInfo.dependencyCount = static_cast(vkSubpassDeps.size()); + renderPassCreateInfo.pDependencies = vkSubpassDeps.data(); + + + if (auto result = logicalDeviceHdl->GetVkLogicalDevice().createRenderPass(&renderPassCreateInfo, nullptr, &vkRenderpass); result != vk::Result::eSuccess) + { + SHVulkanDebugUtil::ReportVkError(result, "Failed to create Renderpass. "); + } + else + { + SHVulkanDebugUtil::ReportVkSuccess("Successfully created Renderpass. "); + } + + } + vk::RenderPass SHVkRenderpass::GetVkRenderpass(void) const noexcept { return vkRenderpass; diff --git a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h index a2799eb7..70a04bbf 100644 --- a/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h +++ b/SHADE_Engine/src/Graphics/Renderpass/SHVkRenderpass.h @@ -55,6 +55,8 @@ namespace SHADE SHVkRenderpass(SHVkRenderpass&& rhs) noexcept; SHVkRenderpass& operator=(SHVkRenderpass&& rhs) noexcept; + void HandleResize (void) noexcept; + /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ From 64d1c2ab2e0e07e27fd9bb129029dd1a23553b6d Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 2 Oct 2022 00:47:26 +0800 Subject: [PATCH 06/14] Minimize is now working --- SHADE_Engine/premake5.lua | 6 ++--- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 25 +++++++++++++++++++ .../MiddleEnd/PerFrame/SHRenderContext.cpp | 5 ++++ .../MiddleEnd/PerFrame/SHRenderContext.h | 1 + .../src/Graphics/Windowing/SHWindow.cpp | 2 ++ .../src/Graphics/Windowing/SHWindow.h | 2 +- SHADE_Managed/premake5.lua | 5 ++++ 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/SHADE_Engine/premake5.lua b/SHADE_Engine/premake5.lua index f11ccf79..d90d69e3 100644 --- a/SHADE_Engine/premake5.lua +++ b/SHADE_Engine/premake5.lua @@ -156,8 +156,8 @@ project "SHADE_Engine" links{"assimp-vc142-mt.lib", "librttr_core.lib", "spdlog.lib"} excludes { - "%{prj.location}/src/Editor/**.cpp", - "%{prj.location}/src/Editor/**.h", - "%{prj.location}/src/Editor/**.hpp", +-- "%{prj.location}/src/Editor/**.cpp", +-- "%{prj.location}/src/Editor/**.h", +-- "%{prj.location}/src/Editor/**.hpp", } links{"fmodstudio_vc.lib", "fmod_vc.lib"} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 7aad2206..5751e7b0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -213,6 +213,15 @@ namespace SHADE /***************************************************************************/ void SHGraphicsSystem::Run(double) noexcept { + if (window->IsMinimized()) + return; + + if (renderContext.GetResized()) + { + return; + } + + // Frame data for the current frame auto const& frameData = renderContext.GetCurrentFrameData(); uint32_t frameIndex = renderContext.GetCurrentFrame(); @@ -335,6 +344,9 @@ namespace SHADE /***************************************************************************/ void SHGraphicsSystem::BeginRender() { + if (window->IsMinimized()) + return; + // Finalise all batches for (auto vp : viewports) for (auto renderer : vp->GetRenderers()) @@ -381,6 +393,16 @@ namespace SHADE /***************************************************************************/ void SHGraphicsSystem::EndRender() { + if (window->IsMinimized()) + return; + + if (renderContext.GetResized()) + { + return; + } + + + const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame(); auto& currFrameData = renderContext.GetCurrentFrameData(); @@ -513,6 +535,9 @@ namespace SHADE void SHGraphicsSystem::HandleResize(void) noexcept { + if (window->IsMinimized()) + return; + auto windowDims = window->GetWindowSize(); // Resize the swapchain diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp index f31653a8..4953447b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp @@ -197,6 +197,11 @@ namespace SHADE return currentFrame; } + bool SHRenderContext::GetResized(void) noexcept + { + return isResized; + } + bool SHRenderContext::GetResizeAndReset(void) noexcept { bool b = isResized; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h index 04cea4e4..afdbef2d 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h @@ -56,6 +56,7 @@ namespace SHADE SHPerFrameData& GetCurrentFrameData(void) noexcept; SHPerFrameData& GetFrameData (uint32_t index) noexcept; uint32_t GetCurrentFrame (void) const noexcept; + bool GetResized(void) noexcept; bool GetResizeAndReset (void) noexcept; }; diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp index a4569c75..2477b111 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp @@ -383,6 +383,8 @@ namespace SHADE { wndData.isMinimised = true; } + else + wndData.isMinimised = false; for (auto const& entry : windowResizeCallbacks) { diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h index 8f15bb60..9dcaedd9 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h @@ -125,6 +125,7 @@ namespace SHADE CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn); void UnregisterWindowSizeCallback(CALLBACKID const& callbackid); + bool IsMinimized() const { return wndData.isMinimised; } protected: static LRESULT CALLBACK WndProcStatic(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); @@ -165,7 +166,6 @@ namespace SHADE void OnSize(UINT msg, UINT type, SIZE size); void OnPosChange(LPWINDOWPOS pos); void OnPaint(HDC hdc, LPPAINTSTRUCT paint); - bool IsMinimized() const { return wndData.isMinimised; } }; static SHWindowMap windowMap; static SHWindow* windowBeingCreated = nullptr; diff --git a/SHADE_Managed/premake5.lua b/SHADE_Managed/premake5.lua index a7b20144..d9a47975 100644 --- a/SHADE_Managed/premake5.lua +++ b/SHADE_Managed/premake5.lua @@ -79,3 +79,8 @@ project "SHADE_Managed" optimize "On" defines{"_RELEASE"} links{"librttr_core.lib"} + + filter "configurations:Publish" + optimize "On" + defines{"_RELEASE"} + links{"librttr_core.lib"} From 201ce17a407dd61a0bedc2eb3b24d183c6f39625 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 2 Oct 2022 00:56:12 +0800 Subject: [PATCH 07/14] Fixed validation errors when closing the app --- SHADE_Application/src/Application/SBApplication.cpp | 3 +++ .../src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp | 7 ++++++- .../src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 8abc341b..d0bf544d 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -136,6 +136,9 @@ namespace Sandbox SHADE::SHSystemManager::RunRoutines(false, 0.016f); } + + // Finish all graphics jobs first + graphicsSystem->AwaitGraphicsExecution(); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 5751e7b0..fc02b994 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -552,12 +552,17 @@ namespace SHADE worldCamera->SetPerspective(90.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); } + + void SHGraphicsSystem::AwaitGraphicsExecution() + { + device->WaitIdle(); + } void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept { window = wind; } - + /*-----------------------------------------------------------------------------------*/ /* System Routine Functions - BeginRoutine */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index a835b1bb..6ecb13f0 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -251,6 +251,7 @@ namespace SHADE void BuildTextures(); void HandleResize(void) noexcept; + void AwaitGraphicsExecution(); /*-----------------------------------------------------------------------------*/ /* Setters */ From 9e8b4414d10e1fd7fb2cd89524f35301db6752c5 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sun, 2 Oct 2022 01:00:07 +0800 Subject: [PATCH 08/14] add window close callback --- .../src/Graphics/Windowing/SHWindow.cpp | 21 +++++++++++++++++++ .../src/Graphics/Windowing/SHWindow.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp index 2477b111..1688d348 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp @@ -272,6 +272,17 @@ namespace SHADE windowResizeCallbacks.erase(callbackid); } + SHWindow::CALLBACKID SHWindow::RegisterWindowCloseCallback(WindowResizeCallbackFn windowCloseCallback) + { + windowCloseCallbacks.try_emplace(windowResizeCallbackCount, windowCloseCallback); + return windowCloseCallbackCount++; + } + + void SHWindow::UnregisterWindowCloseCallback(CALLBACKID const& callbackid) + { + windowCloseCallbacks.erase(callbackid); + } + LRESULT SHWindow::WndProcStatic(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { auto window = windowMap.GetWindow(hwnd); @@ -307,6 +318,8 @@ namespace SHADE case WM_CREATE: OnCreate(hwnd, reinterpret_cast(wparam)); break; + case WM_CLOSE: + case WM_DESTROY: OnDestroy(); return 0; @@ -365,6 +378,14 @@ namespace SHADE } + void SHADE::SHWindow::OnClose() + { + for (const auto& callbackFn : windowCloseCallbacks | std::views::values) + { + callbackFn(); + } + } + void SHWindow::OnDestroy() { this->Destroy(); diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h index 9dcaedd9..b1c1067d 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h @@ -75,6 +75,7 @@ namespace SHADE public: using SHVec2 = std::pair; typedef std::function WindowResizeCallbackFn; + typedef std::function WindowCloseCallbackFn; typedef uint16_t CALLBACKID; SHWindow(); @@ -125,6 +126,8 @@ namespace SHADE CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn); void UnregisterWindowSizeCallback(CALLBACKID const& callbackid); + CALLBACKID RegisterWindowCloseCallback(WindowResizeCallbackFn); + void UnregisterWindowCloseCallback(CALLBACKID const& callbackid); bool IsMinimized() const { return wndData.isMinimised; } protected: @@ -157,10 +160,13 @@ namespace SHADE HFONT font; std::unordered_map windowResizeCallbacks; + std::unordered_map windowCloseCallbacks; CALLBACKID windowResizeCallbackCount{}; + CALLBACKID windowCloseCallbackCount{}; //TODO: Shift to events abstraction void OnCreate(HWND hwnd, LPCREATESTRUCT create_struct); + void OnClose(); void OnDestroy(); //void OnFileDrop(HDROP drop); void OnSize(UINT msg, UINT type, SIZE size); From 9fabb7d672b95c75997fbb77d727c6dc39bf869a Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 2 Oct 2022 01:13:04 +0800 Subject: [PATCH 09/14] Window can close properly (with the exception of scene graph dtor crash) --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 13 +++++++++---- .../Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp | 10 ++++++++++ .../Graphics/MiddleEnd/PerFrame/SHRenderContext.h | 7 +++++-- SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp | 3 ++- SHADE_Engine/src/Graphics/Windowing/SHWindow.h | 2 +- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index fc02b994..8aec5a83 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -73,6 +73,11 @@ namespace SHADE renderContext.SetIsResized(true); }); + window->RegisterWindowCloseCallback([&](void) + { + renderContext.SetWindowIsDead(true); + } + ); // Create graphics queue graphicsQueue = device->GetQueue(SH_Q_FAM::GRAPHICS, 0); transferQueue = device->GetQueue(SH_Q_FAM::TRANSFER, 0); @@ -213,7 +218,7 @@ namespace SHADE /***************************************************************************/ void SHGraphicsSystem::Run(double) noexcept { - if (window->IsMinimized()) + if (window->IsMinimized() || renderContext.GetWindowIsDead()) return; if (renderContext.GetResized()) @@ -344,7 +349,7 @@ namespace SHADE /***************************************************************************/ void SHGraphicsSystem::BeginRender() { - if (window->IsMinimized()) + if (window->IsMinimized() || renderContext.GetWindowIsDead()) return; // Finalise all batches @@ -393,7 +398,7 @@ namespace SHADE /***************************************************************************/ void SHGraphicsSystem::EndRender() { - if (window->IsMinimized()) + if (window->IsMinimized() || renderContext.GetWindowIsDead()) return; if (renderContext.GetResized()) @@ -535,7 +540,7 @@ namespace SHADE void SHGraphicsSystem::HandleResize(void) noexcept { - if (window->IsMinimized()) + if (window->IsMinimized() || renderContext.GetWindowIsDead()) return; auto windowDims = window->GetWindowSize(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp index 4953447b..0ac7013a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.cpp @@ -168,6 +168,11 @@ namespace SHADE isResized = resized; } + void SHRenderContext::SetWindowIsDead(bool dead) noexcept + { + windowIsDead = dead; + } + /***************************************************************************/ /*! @@ -209,4 +214,9 @@ namespace SHADE return b; } + bool SHRenderContext::GetWindowIsDead(void) const noexcept + { + return windowIsDead; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h index afdbef2d..bf186922 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/PerFrame/SHRenderContext.h @@ -36,6 +36,7 @@ namespace SHADE uint32_t currentFrame; bool isResized{ false }; + bool windowIsDead {false}; public: SHRenderContext(void) noexcept; @@ -51,13 +52,15 @@ namespace SHADE bool WaitForFence (void) noexcept; void ResetFence (void) noexcept; - void SetIsResized (bool resized) noexcept; + void SetIsResized (bool resized) noexcept; + void SetWindowIsDead (bool dead) noexcept; SHPerFrameData& GetCurrentFrameData(void) noexcept; SHPerFrameData& GetFrameData (uint32_t index) noexcept; uint32_t GetCurrentFrame (void) const noexcept; - bool GetResized(void) noexcept; + bool GetResized (void) noexcept; bool GetResizeAndReset (void) noexcept; + bool GetWindowIsDead (void) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp index 1688d348..f4ae3d7e 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.cpp @@ -272,7 +272,7 @@ namespace SHADE windowResizeCallbacks.erase(callbackid); } - SHWindow::CALLBACKID SHWindow::RegisterWindowCloseCallback(WindowResizeCallbackFn windowCloseCallback) + SHWindow::CALLBACKID SHWindow::RegisterWindowCloseCallback(WindowCloseCallbackFn windowCloseCallback) { windowCloseCallbacks.try_emplace(windowResizeCallbackCount, windowCloseCallback); return windowCloseCallbackCount++; @@ -388,6 +388,7 @@ namespace SHADE void SHWindow::OnDestroy() { + OnClose(); this->Destroy(); } diff --git a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h index b1c1067d..0a180285 100644 --- a/SHADE_Engine/src/Graphics/Windowing/SHWindow.h +++ b/SHADE_Engine/src/Graphics/Windowing/SHWindow.h @@ -126,7 +126,7 @@ namespace SHADE CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn); void UnregisterWindowSizeCallback(CALLBACKID const& callbackid); - CALLBACKID RegisterWindowCloseCallback(WindowResizeCallbackFn); + CALLBACKID RegisterWindowCloseCallback(WindowCloseCallbackFn); void UnregisterWindowCloseCallback(CALLBACKID const& callbackid); bool IsMinimized() const { return wndData.isMinimised; } From cfa07e9b3b201238063fc5fb26e13793bb3e7a7e Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 2 Oct 2022 01:58:24 +0800 Subject: [PATCH 10/14] Temp fix for SceneGraph crash --- SHADE_Engine/src/Scene/SHSceneGraph.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index da2dcffd..3fe85809 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -90,10 +90,15 @@ namespace SHADE #endif // Go through the map and release all the nodes - for (auto* node : entityNodeMap | std::views::values) - ReleaseNode(node); + for (auto*& node : entityNodeMap | std::views::values) + { + delete node; + node = nullptr; + } - delete root; + entityNodeMap.clear(); + + //delete root; #ifdef _DEBUG SHLOG_INFO("Scene Graph Destroyed Successfully!") From e5df98aaa6341429bac49436278370308dfb64a4 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 2 Oct 2022 01:59:56 +0800 Subject: [PATCH 11/14] Added missing move assignment and extra check for command buffer destructor --- .../src/Graphics/Commands/SHVkCommandBuffer.cpp | 2 +- .../src/Graphics/Commands/SHVkCommandPool.cpp | 2 -- .../src/Graphics/Devices/SHVkLogicalDevice.cpp | 16 ++++++++++++++++ .../src/Graphics/Devices/SHVkLogicalDevice.h | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp index eb65598c..9ebbd227 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp @@ -24,7 +24,7 @@ namespace SHADE /***************************************************************************/ SHVkCommandBuffer::~SHVkCommandBuffer(void) noexcept { - if (vkCommandBuffer) + if (vkCommandBuffer && parentPool) parentPool->GetLogicalDevice()->GetVkLogicalDevice().freeCommandBuffers(parentPool->GetVkCommandPool(), commandBufferCount, &vkCommandBuffer); } diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp b/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp index 881ee998..e1470898 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandPool.cpp @@ -102,8 +102,6 @@ namespace SHADE logicalDeviceHdl = rhs.logicalDeviceHdl; transient = rhs.transient; - static_cast&>(*this) = static_cast&>(rhs); - rhs.vkCommandPool = VK_NULL_HANDLE; return *this; diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 766a27c6..3f8aa239 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -251,6 +251,22 @@ namespace SHADE vkLogicalDevice.destroy(nullptr); } + SHVkLogicalDevice& SHVkLogicalDevice::operator=(SHVkLogicalDevice&& rhs) noexcept + { + if (this == &rhs) + return *this; + + vkLogicalDevice = std::move (rhs.vkLogicalDevice); + queueFamilyIndices = std::move (rhs.queueFamilyIndices); + vmaAllocator = rhs.vmaAllocator; + nonDedicatedBestIndex = 0; + parentPhysicalDeviceHdl = rhs.parentPhysicalDeviceHdl; + + rhs.vkLogicalDevice = VK_NULL_HANDLE; + + return *this; + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h index 1272f68f..5c400e02 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.h @@ -115,7 +115,7 @@ namespace SHADE ~SHVkLogicalDevice (void) noexcept; SHVkLogicalDevice& operator= (SHVkLogicalDevice const& rhs) noexcept = default; - SHVkLogicalDevice& operator= (SHVkLogicalDevice&& rhs) noexcept = default; + SHVkLogicalDevice& operator= (SHVkLogicalDevice&& rhs) noexcept; /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER VARIABLES */ From 4771fbfb762f413a9b35934c3861c60b135d9c71 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 2 Oct 2022 02:28:50 +0800 Subject: [PATCH 12/14] WIP --- .../src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 ++ .../src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h | 1 - .../src/Graphics/MiddleEnd/Interface/SHRenderer.cpp | 8 ++++++++ .../src/Graphics/MiddleEnd/Interface/SHRenderer.h | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 8aec5a83..14768108 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -325,6 +325,8 @@ namespace SHADE void SHGraphicsSystem::Exit(void) { + //worldRenderer-> + graphicsCmdPool.Free(); renderContext.Destroy(); graphicsQueue.Free(); swapchain.Free(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 6ecb13f0..c89e6ebc 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -286,7 +286,6 @@ namespace SHADE Handle transferQueue; Handle descPool; Handle graphicsCmdPool; - Handle transferCmdPool; Handle transferCmdBuffer; Handle graphicsTexCmdBuffer; SHRenderContext renderContext; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index 84ac3ee2..14af56ee 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -49,6 +49,14 @@ namespace SHADE cameraDescriptorSet->UpdateDescriptorSetBuffer(SHGraphicsConstants::DescriptorSetIndex::HIGH_FREQUENCY_GLOBALS, SHGraphicsConstants::DescriptorSetBindings::CAMERA_DATA); } + SHRenderer::~SHRenderer(void) + { + //for (auto& cmdBuffer : commandBuffers) + //{ + // cmdBuffer.Free(); + //} + } + /*-----------------------------------------------------------------------------------*/ /* Camera Registration */ /*-----------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 5e72da85..0feea840 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -65,6 +65,7 @@ namespace SHADE /* Constructor/Destructors */ /*-----------------------------------------------------------------------------*/ SHRenderer(Handle logicalDevice, uint32_t numFrames, std::vector>& cmdPools, Handle descriptorPool, Handle cameraDescLayout, Handle viewport, Handle renderGraph); + ~SHRenderer(void); /*-----------------------------------------------------------------------------*/ /* Camera Registration */ From 45514ac77e2fb599f7e2bc940b6fbf819a1c5f2f Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 2 Oct 2022 03:06:13 +0800 Subject: [PATCH 13/14] Fixed warnings and errors --- .../src/Graphics/Devices/SHVkLogicalDevice.cpp | 2 +- .../src/Graphics/MiddleEnd/Batching/SHBatch.cpp | 4 ++-- .../src/Graphics/MiddleEnd/Interface/SHCamera.h | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 17 ++++------------- .../Graphics/MiddleEnd/Interface/SHMaterial.h | 2 +- .../Graphics/MiddleEnd/Interface/SHViewport.cpp | 4 ++-- .../Graphics/MiddleEnd/Interface/SHViewport.h | 4 ++-- .../MiddleEnd/Meshes/SHPrimitiveGenerator.cpp | 8 ++++---- .../MiddleEnd/Textures/SHTextureLibrary.cpp | 2 +- SHADE_Engine/src/Resource/ResourceLibrary.cpp | 4 ++-- SHADE_Engine/src/Resource/ResourceLibrary.h | 2 +- 11 files changed, 21 insertions(+), 30 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp index 3f8aa239..4f4f94a4 100644 --- a/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp +++ b/SHADE_Engine/src/Graphics/Devices/SHVkLogicalDevice.cpp @@ -92,7 +92,7 @@ namespace SHADE //uint32_t minBuffer if (alignmentSize > 0) { - alignedSize = (alignedSize + alignmentSize - 1) & ~(alignmentSize - 1); + alignedSize = (alignedSize + static_cast(alignmentSize) - 1) & ~(alignmentSize - 1); } return alignedSize; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index b1cd2cd3..181c1f22 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -249,7 +249,7 @@ namespace SHADE if (!EMPTY_MAT_PROPS) { singleMatPropSize = SHADER_INFO->GetBytesRequired(); - singleMatPropAlignedSize = device->PadSSBOSize(singleMatPropSize); + singleMatPropAlignedSize = device->PadSSBOSize(static_cast(singleMatPropSize)); matPropTotalBytes = numTotalElements * singleMatPropAlignedSize; if (matPropsDataSize < matPropTotalBytes) { @@ -386,7 +386,7 @@ namespace SHADE SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, bufferList, - 0, matPropsDataSize + 0, static_cast(matPropsDataSize) ); matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer ( diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHCamera.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHCamera.h index c54f29ed..3a945109 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHCamera.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHCamera.h @@ -69,7 +69,7 @@ namespace SHADE SHMatrix inverseViewMatrix; SHMatrix inverseProjMatrix; SHMatrix inverseVpMatrix; - bool isDirty; + bool isDirty = true; /*-----------------------------------------------------------------------------*/ /* Helper Functions */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 14768108..6957aa93 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -266,8 +266,8 @@ namespace SHADE // Begin recording the command buffer currentCmdBuffer->BeginRecording(); - uint32_t w = viewports[vpIndex]->GetWidth(); - uint32_t h = viewports[vpIndex]->GetHeight(); + uint32_t w = static_cast(viewports[vpIndex]->GetWidth()); + uint32_t h = static_cast(viewports[vpIndex]->GetHeight()); currentCmdBuffer->SetViewportScissor (static_cast(w), static_cast(h), w, h); currentCmdBuffer->ForceSetPipelineLayout(SHGraphicsGlobalData::GetDummyPipelineLayout()); @@ -325,15 +325,6 @@ namespace SHADE void SHGraphicsSystem::Exit(void) { - //worldRenderer-> - graphicsCmdPool.Free(); - renderContext.Destroy(); - graphicsQueue.Free(); - swapchain.Free(); - surface.Free(); - device.Free(); - - SHVkInstance::Destroy(); } /*---------------------------------------------------------------------------------*/ @@ -554,8 +545,8 @@ namespace SHADE worldRenderGraph->HandleResize(windowDims.first, windowDims.second); - defaultViewport->SetWidth(windowDims.first); - defaultViewport->SetHeight(windowDims.second); + defaultViewport->SetWidth(static_cast(windowDims.first)); + defaultViewport->SetHeight(static_cast(windowDims.second)); worldCamera->SetPerspective(90.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h index 692d857f..348efb07 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMaterial.h @@ -63,7 +63,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ Handle pipeline; std::unique_ptr propMemory; - Byte propMemorySize; + Byte propMemorySize = 0; /*-----------------------------------------------------------------------------*/ /* Helper Functions */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp index d6eea3d7..dc534a49 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.cpp @@ -74,12 +74,12 @@ namespace SHADE renderers.erase(iter); } - void SHViewport::SetWidth(uint32_t w) noexcept + void SHViewport::SetWidth(float w) noexcept { viewport.width = w; } - void SHViewport::SetHeight(uint32_t h) noexcept + void SHViewport::SetHeight(float h) noexcept { viewport.height = h; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h index ce992f77..221dbe7e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h @@ -65,8 +65,8 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Setters */ /*-----------------------------------------------------------------------------*/ - void SetWidth(uint32_t w) noexcept; - void SetHeight (uint32_t h) noexcept; + void SetWidth(float w) noexcept; + void SetHeight (float h) noexcept; /*-----------------------------------------------------------------------------*/ /* Getters */ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp index 2080265b..be181beb 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.cpp @@ -196,12 +196,12 @@ namespace SHADE static SHMeshData meshData = Cube(); return meshLibrary.AddMesh ( - meshData.VertexPositions.size(), + static_cast(meshData.VertexPositions.size()), meshData.VertexPositions.data(), meshData.VertexTexCoords.data(), meshData.VertexTangents.data(), meshData.VertexNormals.data(), - meshData.Indices.size(), + static_cast(meshData.Indices.size()), meshData.Indices.data() ); } @@ -211,12 +211,12 @@ namespace SHADE static SHMeshData meshData = Cube(); return gfxSystem.AddMesh ( - meshData.VertexPositions.size(), + static_cast(meshData.VertexPositions.size()), meshData.VertexPositions.data(), meshData.VertexTexCoords.data(), meshData.VertexTangents.data(), meshData.VertexNormals.data(), - meshData.Indices.size(), + static_cast(meshData.Indices.size()), meshData.Indices.data() ); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp index 6a7439e5..5c315ff6 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -149,7 +149,7 @@ namespace SHADE { texOrder.emplace_back(job.TextureHandle); combinedImageSamplers.emplace_back(std::make_tuple(job.TextureHandle->ImageView, job.Sampler, vk::ImageLayout::eShaderReadOnlyOptimal)); - job.TextureHandle->TextureArrayIndex = texOrder.size() - 1; + job.TextureHandle->TextureArrayIndex = static_cast(texOrder.size()) - 1U; } addJobs.clear(); diff --git a/SHADE_Engine/src/Resource/ResourceLibrary.cpp b/SHADE_Engine/src/Resource/ResourceLibrary.cpp index 5a3ad9fe..b215b591 100644 --- a/SHADE_Engine/src/Resource/ResourceLibrary.cpp +++ b/SHADE_Engine/src/Resource/ResourceLibrary.cpp @@ -8,9 +8,9 @@ namespace SHADE ResourceManager::~ResourceManager() { // Delete all resources libraries - for (const auto& deleter : deleters) + for (auto iter = deleters.rbegin(); iter != deleters.rend(); ++iter) { - deleter(); + (*iter)(); } deleters.clear(); } diff --git a/SHADE_Engine/src/Resource/ResourceLibrary.h b/SHADE_Engine/src/Resource/ResourceLibrary.h index 4588b9fe..a5bf0a67 100644 --- a/SHADE_Engine/src/Resource/ResourceLibrary.h +++ b/SHADE_Engine/src/Resource/ResourceLibrary.h @@ -118,7 +118,7 @@ namespace SHADE /// Handle to the resource object. /// Read-only reference to the resource object. template - const T& Get(Handle handle) const; + const T& Get(Handle handle) const; private: /*-----------------------------------------------------------------------------*/ From 0dba60f9f11aaf5c1553b8f175b3e734b2b31aab Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 2 Oct 2022 03:09:09 +0800 Subject: [PATCH 14/14] Small fix --- .../src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp index e50e717f..e842df47 100644 --- a/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp +++ b/SHADE_Engine/src/Graphics/Descriptors/SHVkDescriptorSetGroup.cpp @@ -208,7 +208,7 @@ namespace SHADE BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); // to index a set - uint32_t setIndex = setIndexing[bsHash]; + uint32_t setIndex = setIndexing[set]; // to index a write for a binding uint32_t writeInfoIndex = updater.writeHashMap[bsHash]; @@ -233,7 +233,7 @@ namespace SHADE BindingAndSetHash bsHash = SHVkUtil::GenBindingSetHash(set, binding); // to index a set - uint32_t setIndex = setIndexing[bsHash]; + uint32_t setIndex = setIndexing[set]; // to index a write for a binding uint32_t writeInfoIndex = updater.writeHashMap[bsHash];