From 0a3d211f027507ab99f6498c55bb479b739e0177 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Thu, 13 Oct 2022 16:57:08 +0800 Subject: [PATCH 1/4] Added a render target to store entity ID Pipelines created from pipeline library now checks if the resources pointed to by a subpass requires blending and adds a blend state accordingly. Fragment shader writes to this new render target for testing (works) --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 14 ++++----- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 27 ++++++++++++++++++ .../src/Graphics/Pipeline/SHPipelineState.h | 17 ++--------- .../RenderGraph/SHRenderGraphNode.cpp | 9 ++++++ .../Graphics/RenderGraph/SHRenderGraphNode.h | 1 + .../RenderGraph/SHRenderGraphResource.cpp | 5 ++++ .../RenderGraph/SHRenderGraphResource.h | 2 ++ .../src/Graphics/RenderGraph/SHSubpass.cpp | 13 +++++++++ .../src/Graphics/RenderGraph/SHSubpass.h | 3 +- SHADE_Engine/src/Graphics/SHVkUtil.cpp | 19 ++++++++++++ SHADE_Engine/src/Graphics/SHVkUtil.h | 1 + TempShaderFolder/TestCubeFs.glsl | 3 +- TempShaderFolder/TestCubeFs.spv | Bin 1984 -> 2100 bytes 13 files changed, 88 insertions(+), 26 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 6957aa93..09579f02 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -143,26 +143,22 @@ namespace SHADE // Initialize world render graph worldRenderGraph->Init(device, swapchain); + worldRenderGraph->AddResource("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second); worldRenderGraph->AddResource("Depth Buffer", SH_ATT_DESC_TYPE::DEPTH_STENCIL, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); + worldRenderGraph->AddResource("Entity ID", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR32Uint); + //worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Composite", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Scene", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eB8G8R8A8Unorm); - worldRenderGraph->AddResource("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second); - auto node = worldRenderGraph->AddNode("G-Buffer", { /*"Composite", "Position", */"Depth Buffer", "Present" }, {}); // no predecessors + auto node = worldRenderGraph->AddNode("G-Buffer", { "Entity ID", "Depth Buffer", "Present"}, {}); // no predecessors //First subpass to write to G-Buffer auto gBufferWriteSubpass = node->AddSubpass("G-Buffer Write"); - //gBufferWriteSubpass->AddColorOutput("Scene"); gBufferWriteSubpass->AddColorOutput("Present"); + gBufferWriteSubpass->AddColorOutput("Entity ID"); gBufferWriteSubpass->AddDepthOutput ("Depth Buffer", SH_ATT_DESC_TYPE::DEPTH_STENCIL); - //writeSubpass->AddColorOutput("Normals"); - // //Second subpass to read from G-Buffer - //auto compositeSubpass = node->AddSubpass("G-Buffer Composite"); - //compositeSubpass->AddColorOutput("Present"); // TODO: This should be "Composite" and then composite will write to swapchain image "Present" - //compositeSubpass->AddInput("Normals"); - //compositeSubpass->AddInput("Position"); // TODO: Use macro to add this node when SH_EDITOR is enabled auto imguiNode = worldRenderGraph->AddNode("ImGui Node", { "Present" }, {"G-Buffer"}); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 10b42a9e..682b549c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -2,6 +2,8 @@ #include "SHPipelineLibrary.h" #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" +#include "Graphics/RenderGraph/SHSubpass.h" +#include "Graphics/SHVkUtil.h" namespace SHADE { @@ -20,6 +22,31 @@ namespace SHADE // Create the pipeline and configure the default vertex input state auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderpass, subpass); newPipeline->GetPipelineState().SetVertexInputState(SHGraphicsGlobalData::GetDefaultViState()); + + SHColorBlendState colorBlendState{}; + colorBlendState.logic_op_enable = VK_FALSE; + colorBlendState.logic_op = vk::LogicOp::eCopy; + + auto const& subpassColorReferences = subpass->GetColorAttachmentReferences(); + colorBlendState.attachments.reserve(subpassColorReferences.size()); + + for (auto& att : subpassColorReferences) + { + colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState + { + .blendEnable = SHVkUtil::IsBlendCompatible (subpass->GetFormatFromAttachmentReference(att.attachment)) ? true : false, + .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, + .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, + .colorBlendOp = vk::BlendOp::eAdd, + .srcAlphaBlendFactor = vk::BlendFactor::eOne, + .dstAlphaBlendFactor = vk::BlendFactor::eZero, + .alphaBlendOp = vk::BlendOp::eAdd, + .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, + } + ); + } + + newPipeline->GetPipelineState().SetColorBlenState(colorBlendState); // Actually construct the pipeline newPipeline->ConstructPipeline(); diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h index 2769d6cc..4c8d679a 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineState.h @@ -137,22 +137,9 @@ namespace SHADE { VkBool32 logic_op_enable{ VK_FALSE }; - vk::LogicOp logic_op{ VK_LOGIC_OP_COPY }; + vk::LogicOp logic_op{ vk::LogicOp::eCopy }; - std::vector attachments = - { - vk::PipelineColorBlendAttachmentState - { - .blendEnable = true, - .srcColorBlendFactor = vk::BlendFactor::eSrcAlpha, - .dstColorBlendFactor = vk::BlendFactor::eOneMinusSrcAlpha, - .colorBlendOp = vk::BlendOp::eAdd, - .srcAlphaBlendFactor = vk::BlendFactor::eOne, - .dstAlphaBlendFactor = vk::BlendFactor::eZero, - .alphaBlendOp = vk::BlendOp::eAdd, - .colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA, - } - }; + std::vector attachments{}; }; // TODO: Specialization constants diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp index 05232af3..ea09dd47 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.cpp @@ -261,6 +261,7 @@ namespace SHADE return {}; } + Handle pipeline = pipelineLibrary.GetDrawPipline(vsFsPair); if (!pipeline) { @@ -301,4 +302,12 @@ namespace SHADE return subpasses[subpassIndexing.at(subpassName.data())]; } + Handle SHRenderGraphNode::GetResource(uint32_t resourceIndex) const noexcept + { + if (resourceIndex < attResources.size()) + return attResources[resourceIndex]; + else + return {}; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h index c713f402..28527a92 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNode.h @@ -105,6 +105,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ Handle GetRenderpass(void) const noexcept; Handle GetSubpass(std::string_view subpassName) const noexcept; + Handle GetResource (uint32_t resourceIndex) const noexcept; friend class SHRenderGraph; }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index cc881867..6da6593e 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -242,4 +242,9 @@ namespace SHADE } } + vk::Format SHRenderGraphResource::GetResourceFormat(void) const noexcept + { + return resourceFormat; + } + } \ 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 ebb699d8..d4782226 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -72,6 +72,8 @@ namespace SHADE void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept; + vk::Format GetResourceFormat (void) const noexcept; + friend class SHRenderGraphNode; friend class SHRenderGraph; }; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 007502dd..abd3a7be 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -2,6 +2,8 @@ #include "SHSubpass.h" #include "Graphics/MiddleEnd/Batching/SHSuperBatch.h" #include "Graphics/Devices/SHVkLogicalDevice.h" +#include "SHRenderGraphNode.h" +#include "SHRenderGraphResource.h" namespace SHADE { @@ -207,4 +209,15 @@ namespace SHADE { return superBatch; } + + std::vector const& SHSubpass::GetColorAttachmentReferences(void) const noexcept + { + return colorReferences; + } + + vk::Format SHSubpass::GetFormatFromAttachmentReference(uint32_t attachmentReference) const noexcept + { + return parentNode->GetResource(attachmentReference)->GetResourceFormat(); + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index b8b8717f..aba282b9 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -86,7 +86,8 @@ namespace SHADE Handle const& GetParentNode(void) const noexcept; SHSubPassIndex GetIndex() const noexcept; Handle GetSuperBatch(void) const noexcept; - + std::vector const& GetColorAttachmentReferences (void) const noexcept; + vk::Format GetFormatFromAttachmentReference (uint32_t attachmentReference) const noexcept; friend class SHRenderGraphNode; friend class SHRenderGraph; diff --git a/SHADE_Engine/src/Graphics/SHVkUtil.cpp b/SHADE_Engine/src/Graphics/SHVkUtil.cpp index e4f9f37e..2d0e7cf2 100644 --- a/SHADE_Engine/src/Graphics/SHVkUtil.cpp +++ b/SHADE_Engine/src/Graphics/SHVkUtil.cpp @@ -23,6 +23,25 @@ namespace SHADE IsDepthOnlyFormat(format); } + bool SHVkUtil::IsBlendCompatible(vk::Format format) noexcept + { + // TODO: Update with all formats + switch (format) + { + case vk::Format::eR32Sint: + case vk::Format::eR32G32Sint: + case vk::Format::eR32G32B32Sint: + case vk::Format::eR32G32B32A32Sint: + return false; + case vk::Format::eR32Sfloat: + case vk::Format::eR32G32Sfloat: + case vk::Format::eR32G32B32Sfloat: + case vk::Format::eR32G32B32A32Sfloat: + return true; + } + return false; + } + void SHVkUtil::EnsureBufferAndCopyData(Handle device, Handle cmdBuffer, Handle& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage) { if (bufferHandle) diff --git a/SHADE_Engine/src/Graphics/SHVkUtil.h b/SHADE_Engine/src/Graphics/SHVkUtil.h index cba5b062..d8625607 100644 --- a/SHADE_Engine/src/Graphics/SHVkUtil.h +++ b/SHADE_Engine/src/Graphics/SHVkUtil.h @@ -22,6 +22,7 @@ namespace SHADE public: static bool IsDepthOnlyFormat (vk::Format format) noexcept; static bool IsDepthStencilAttachment(vk::Format format) noexcept; + static bool IsBlendCompatible (vk::Format format) noexcept; /***********************************************************************************/ /*! diff --git a/TempShaderFolder/TestCubeFs.glsl b/TempShaderFolder/TestCubeFs.glsl index 3a25ad71..ab0f089f 100644 --- a/TempShaderFolder/TestCubeFs.glsl +++ b/TempShaderFolder/TestCubeFs.glsl @@ -33,12 +33,13 @@ layout (set = 3, binding = 0) buffer MaterialProperties // For materials } MatProp; layout(location = 0) out vec4 outColor; +layout(location = 1) out uint outEntityID; void main() { - outColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) + MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha; + outEntityID = 5; //outColor = vec4 (1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeFs.spv b/TempShaderFolder/TestCubeFs.spv index 07f67a459c18377f70ada5712194e5a5029322de..a069acf6e2e436753364704fd981a0cad627a143 100644 GIT binary patch delta 164 zcmX@WzeRwTnMs+Qfq{{Mi-DKHej;x!Bj?0wSw`E9Q`cv0W8ZE;{X5v delta 53 zcmdlYaDbnenMs+Qfq{{Mi-DKHdLnNwBge#Q*^P4)m^NQvQefP~BEhsdg6#w&$6uft H3m^snDAWsH From ab09d78e42ccef97d78fe9fcbf09d2772042d153 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 14 Oct 2022 00:08:14 +0800 Subject: [PATCH 2/4] removed routines for graphics from application (remember to add back after ingui update routine is added). Scene graph and physics system had some extra couts input system bug fix (this change is now in main) Mouse pick system wip --- .../src/Application/SBApplication.cpp | 6 +- SHADE_Application/src/Scenes/SBTestScene.cpp | 22 +++---- .../Graphics/Commands/SHVkCommandBuffer.cpp | 5 ++ .../src/Graphics/Commands/SHVkCommandBuffer.h | 3 +- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 12 +++- .../MiddleEnd/Interface/SHGraphicsSystem.h | 6 +- .../MiddleEnd/Interface/SHMousePickSystem.cpp | 59 +++++++++++++++++++ .../MiddleEnd/Interface/SHMousePickSystem.h | 38 ++++++++++++ .../Graphics/RenderGraph/SHRenderGraph.cpp | 9 +++ .../src/Graphics/RenderGraph/SHRenderGraph.h | 3 +- .../RenderGraph/SHRenderGraphResource.cpp | 52 ++++++++++++++++ .../RenderGraph/SHRenderGraphResource.h | 12 ++++ SHADE_Engine/src/Graphics/SHVkUtil.cpp | 13 ++++ SHADE_Engine/src/Graphics/SHVkUtil.h | 10 ++-- SHADE_Engine/src/Input/SHInputManager.cpp | 6 +- SHADE_Engine/src/Physics/SHPhysicsSystem.cpp | 14 ++--- SHADE_Engine/src/Scene/SHSceneGraph.cpp | 6 +- 17 files changed, 241 insertions(+), 35 deletions(-) create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index c6da6f1f..861a92d6 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -81,9 +81,9 @@ namespace Sandbox SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHSystemManager::RegisterRoutine(); - SHADE::SHSystemManager::RegisterRoutine(); - SHADE::SHSystemManager::RegisterRoutine(); - SHADE::SHSystemManager::RegisterRoutine(); + //SHADE::SHSystemManager::RegisterRoutine(); + //SHADE::SHSystemManager::RegisterRoutine(); + //SHADE::SHSystemManager::RegisterRoutine(); SHADE::SHComponentManager::CreateComponentSparseSet(); SHADE::SHComponentManager::CreateComponentSparseSet(); diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index 3b277e6c..96be39f0 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -86,10 +86,10 @@ namespace Sandbox for (int y = 0; y < NUM_ROWS; ++y) for (int x = 0; x < NUM_COLS; ++x) { - auto entity = SHEntityManager::CreateEntity(); + auto entity = SHEntityManager::CreateEntity(); auto& renderable = *SHComponentManager::GetComponent_s(entity); auto& transform = *SHComponentManager::GetComponent_s(entity); - auto& collider = *SHComponentManager::GetComponent_s(entity); + //auto& collider = *SHComponentManager::GetComponent_s(entity); //renderable.Mesh = handles.front(); renderable.Mesh = CUBE_MESH; @@ -99,13 +99,13 @@ namespace Sandbox renderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 0.0f, 0.0f, 1.0f)); //Set initial positions - transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, y * TEST_OBJ_SPACING.y, SHMath::GenerateRandomNumber(-3.5f, -5.0f)}); + transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, y * TEST_OBJ_SPACING.y, SHMath::GenerateRandomNumber(-300.5f, 500.0f)}); //transform.SetWorldPosition({-1.0f, -1.0f, -1.0f}); transform.SetWorldRotation(SHMath::GenerateRandomNumber(), SHMath::GenerateRandomNumber(), SHMath::GenerateRandomNumber()); transform.SetWorldScale(TEST_OBJ_SCALE); - auto* box = collider.AddBoundingBox(); - box->SetHalfExtents(transform.GetWorldScale() * 0.5f); + //auto* box = collider.AddBoundingBox(); + //box->SetHalfExtents(transform.GetWorldScale() * 0.5f); stressTestObjects.emplace_back(entity); } @@ -123,11 +123,11 @@ namespace Sandbox transform.SetWorldPosition({ -3.0f, -1.0f, -1.0f }); transform.SetLocalScale({ 5.0f, 5.0f, 5.0f }); - auto floor = SHEntityManager::CreateEntity(); + auto floor = SHEntityManager::CreateEntity(); auto& floorRenderable = *SHComponentManager::GetComponent_s(floor); auto& floorTransform = *SHComponentManager::GetComponent_s(floor); - auto& floorRigidBody = *SHComponentManager::GetComponent_s(floor); - auto& floorCollider = *SHComponentManager::GetComponent_s(floor); + //auto& floorRigidBody = *SHComponentManager::GetComponent_s(floor); + //auto& floorCollider = *SHComponentManager::GetComponent_s(floor); floorRenderable.Mesh = CUBE_MESH; floorRenderable.SetMaterial(customMat); @@ -136,10 +136,10 @@ namespace Sandbox floorTransform.SetWorldScale({7.5f, 0.5f, 7.5}); floorTransform.SetWorldPosition({0.0f, -3.0f, -5.0f}); - floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC); + //floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC); - auto* floorBox = floorCollider.AddBoundingBox(); - floorBox->SetHalfExtents(floorTransform.GetWorldScale() * 0.5f); + //auto* floorBox = floorCollider.AddBoundingBox(); + //floorBox->SetHalfExtents(floorTransform.GetWorldScale() * 0.5f); // Create blank entity with a script //testObj = SHADE::SHEntityManager::CreateEntity(); diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp index 9ebbd227..4501ba7b 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.cpp @@ -461,6 +461,11 @@ namespace SHADE ); } + void SHVkCommandBuffer::CopyImageToBuffer(const vk::Image& src, const vk::Buffer& dst, const std::vector& copyInfo) + { + vkCommandBuffer.copyImageToBuffer (src, vk::ImageLayout::eTransferSrcOptimal, dst, copyInfo); + } + void SHVkCommandBuffer::PipelineBarrier( vk::PipelineStageFlags srcStage, vk::PipelineStageFlags dstStage, diff --git a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h index c18527b3..9416a1aa 100644 --- a/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h +++ b/SHADE_Engine/src/Graphics/Commands/SHVkCommandBuffer.h @@ -120,7 +120,8 @@ namespace SHADE void DrawMultiIndirect (Handle indirectDrawData, uint32_t drawCount); // Buffer Copy - void CopyBufferToImage (const vk::Buffer& src, const vk::Image& dst, const std::vector& copyInfo); + void CopyBufferToImage (const vk::Buffer& src, const vk::Image& dst, const std::vector& copyInfo); + void CopyImageToBuffer (const vk::Image& src, const vk::Buffer& dst, const std::vector& copyInfo); // memory barriers void PipelineBarrier ( diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 09579f02..636aa27a 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -32,6 +32,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/Images/SHVkSampler.h" #include "Assets/Asset Types/SHTextureAsset.h" +#include "Graphics/MiddleEnd/Interface/SHMousePickSystem.h" namespace SHADE { @@ -197,6 +198,15 @@ namespace SHADE cubeFS->Reflect(); defaultMaterial = AddMaterial(cubeVS, cubeFS, gBufferWriteSubpass); + + mousePickSystem = resourceManager.Create(); + + std::vector> cmdPools; + cmdPools.reserve(swapchain->GetNumImages()); + for (uint32_t i = 0; i < swapchain->GetNumImages(); ++i) + cmdPools.push_back(renderContext.GetFrameData(i).cmdPoolHdls[0]); + + mousePickSystem->Init(device, cmdPools, worldRenderGraph->GetRenderGraphResource("Entity ID")); } /***************************************************************************/ @@ -396,10 +406,10 @@ namespace SHADE } - const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame(); auto& currFrameData = renderContext.GetCurrentFrameData(); + mousePickSystem->Run(graphicsQueue, CURR_FRAME_IDX); // #BackEndTest: queues an image for presentation if (auto result = graphicsQueue->Present(swapchain, { currFrameData.semRenderFinishHdl }, CURR_FRAME_IDX); result != vk::Result::eSuccess) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index c89e6ebc..981600f3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -52,6 +52,7 @@ namespace SHADE class SHVkShaderModule; class SHMaterial; class SHMaterialInstance; + class SHMousePickSystem; /*---------------------------------------------------------------------------------*/ /* Type Definitions */ @@ -294,7 +295,7 @@ namespace SHADE SHWindow* window = nullptr; // Middle End Resources - ResourceManager resourceManager; + ResourceManager resourceManager; SHMeshLibrary meshLibrary; SHTextureLibrary texLibrary; SHSamplerCache samplerCache; @@ -322,5 +323,8 @@ namespace SHADE Handle defaultMaterial; Handle worldRenderGraph; + + // Sub systems + Handle mousePickSystem; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp new file mode 100644 index 00000000..ec7a5491 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp @@ -0,0 +1,59 @@ +#include "SHpch.h" +#include "SHMousePickSystem.h" +#include "Input/SHInputManager.h" +#include "Graphics/Commands/SHVkCommandPool.h" +#include "Graphics/Devices/SHVkLogicalDevice.h" +#include "Graphics/Synchronization/SHVkFence.h" +#include "Graphics/Buffers/SHVkBuffer.h" +#include "Graphics/SHVkUtil.h" + +namespace SHADE +{ + void SHMousePickSystem::Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept + { + // Create command buffers + for (auto& pool : cmdPools) + { + commandBuffers.push_back(pool->RequestCommandBuffer (SH_CMD_BUFFER_TYPE::PRIMARY)); + } + + // assign the attachment + entityIDAttachment = eidAttachment; + + // Create the fence + afterCopyFence = logicalDevice->CreateFence(); + + uint32_t bufferSize = entityIDAttachment->GetWidth() * eidAttachment->GetHeight() * SHVkUtil::GetBytesPerPixelFromFormat(entityIDAttachment->GetResourceFormat()); + + // Create the buffer + imageDataDstBuffer = logicalDevice->CreateBuffer(bufferSize, nullptr, bufferSize, vk::BufferUsageFlagBits::eTransferDst, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); + } + + void SHMousePickSystem::Run(Handle queue, uint32_t frameIndex) noexcept + { + // if input detected + if (/*SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LEFT_CTRL) && */SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + { + std::cout << "Input registered... " << std::endl; + + //// begin command buffer for recording + //commandBuffers[frameIndex]->BeginRecording(); + + //// transition the image for optimized copying + //entityIDAttachment->TransitionImage (vk::ImageLayout::eColorAttachmentOptimal, vk::ImageLayout::eTransferSrcOptimal, commandBuffers[frameIndex], vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eTransfer, 0); + + //// copy the image here. Last argument is 0 because the attachment isn't a swapchain image. + //entityIDAttachment->CopyToBuffer(imageDataDstBuffer, commandBuffers[frameIndex], 0); + + //// end command buffer for recording + //commandBuffers[frameIndex]->EndRecording(); + + //// submit the command buffer to copy image to buffer + //queue->SubmitCommandBuffer({ commandBuffers[frameIndex] }, {}, {}, vk::PipelineStageFlagBits::eColorAttachmentOutput, afterCopyFence); + + //// wait for the copy to be done + //afterCopyFence->Wait(true, std::numeric_limits::max()); + } + } + +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h new file mode 100644 index 00000000..815eb938 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h @@ -0,0 +1,38 @@ +#pragma once + +#include "Graphics/RenderGraph/SHRenderGraphResource.h" +#include "ECS_Base/SHECSMacros.h" +#include "Math/Vector/SHVec2.h" +#include + +namespace SHADE +{ + class SHVkLogicalDevice; + class SHVkCommandPool; + class SHVkCommandBuffer; + class SHVkFence; + class SHVkQueue; + class SHVkBuffer; + + class SHMousePickSystem + { + private: + //! Handle to the render graph resource that will contain the entity IDs + Handle entityIDAttachment; + + //! Command buffers meant for copying image to buffer + std::vector> commandBuffers; + + //! After the attachment has copied its data to a buffer, we want to signal this fence + Handle afterCopyFence; + + //! buffer to contain the attachment data after copying + Handle imageDataDstBuffer; + + public: + void Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept; + + void Run (Handle queue, uint32_t frameIndex) noexcept; + + }; +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index cad6a78e..78bd1ca6 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -498,4 +498,13 @@ namespace SHADE } + Handle SHRenderGraph::GetRenderGraphResource(std::string const& resourceName) const noexcept + { + if (graphResources.contains(resourceName)) + { + return graphResources.at(resourceName); + } + return {}; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index a3140a4f..2e9a3310 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -85,7 +85,8 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - Handle GetNode (std::string const& nodeName) const noexcept; + Handle GetNode (std::string const& nodeName) const noexcept; + Handle GetRenderGraphResource (std::string const& resourceName) const noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index 6da6593e..e8c9863f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -3,6 +3,8 @@ #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Swapchain/SHVkSwapchain.h" #include "Graphics/Images/SHVkImageView.h" +#include "Graphics/Buffers/SHVkBuffer.h" +#include "Graphics/SHVkUtil.h" namespace SHADE { @@ -242,9 +244,59 @@ namespace SHADE } } + void SHRenderGraphResource::TransitionImage(vk::ImageLayout oldLayout, vk::ImageLayout newLayout, Handle commandBuffer, vk::PipelineStageFlagBits srcStage, vk::PipelineStageFlagBits dstStage, uint32_t frameIndex) noexcept + { + vk::ImageMemoryBarrier barrier; + barrier.oldLayout = oldLayout; + barrier.newLayout = newLayout; + barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + barrier.image = images[frameIndex]->GetVkImage(), + barrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor; // TODO: Need to change this to base it off image format. + barrier.subresourceRange.baseMipLevel = 0; + barrier.subresourceRange.levelCount = mipLevels; + barrier.subresourceRange.baseArrayLayer = 0; + barrier.subresourceRange.layerCount = 1; // always 1 since we wont have array of images for attachments + + commandBuffer->PipelineBarrier(srcStage, dstStage, {}, {}, {}, {barrier}); + } + + void SHRenderGraphResource::CopyToBuffer(Handle dstBuffer, Handle commandBuffer, uint32_t frameIndex) const noexcept + { + vk::ImageSubresourceLayers subResource + { + .aspectMask = SHVkUtil::IsDepthOnlyFormat(resourceFormat) ? vk::ImageAspectFlagBits::eDepth : vk::ImageAspectFlagBits::eColor, + .mipLevel = 0, + .baseArrayLayer = 0, + .layerCount = 1 + }; + + vk::BufferImageCopy region + { + .bufferOffset = 0, + .bufferRowLength = 0, + .bufferImageHeight = 0, + .imageSubresource = subResource, + .imageOffset = vk::Offset3D {0,0,0}, + .imageExtent = vk::Extent3D {width, height, 1} + }; + + commandBuffer->CopyImageToBuffer(images[frameIndex]->GetVkImage(), dstBuffer->GetVkBuffer(), {region}); + } + vk::Format SHRenderGraphResource::GetResourceFormat(void) const noexcept { return resourceFormat; } + uint32_t SHRenderGraphResource::GetWidth(void) const noexcept + { + return width; + } + + uint32_t SHRenderGraphResource::GetHeight(void) const noexcept + { + return height; + } + } \ 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 d4782226..a490ab95 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -13,6 +13,8 @@ namespace SHADE class SHVkImageView; class SHVkLogicalDevice; class SHVkSwapchain; + class SHVkCommandBuffer; + class SHVkBuffer; class SH_API SHRenderGraphResource { @@ -70,9 +72,19 @@ namespace SHADE SHRenderGraphResource& operator=(SHRenderGraphResource&& rhs) noexcept; ~SHRenderGraphResource(void) noexcept; + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ void HandleResize (uint32_t newWidth, uint32_t newHeight) noexcept; + void TransitionImage(vk::ImageLayout oldLayout, vk::ImageLayout newLayout, Handle commandBuffer, vk::PipelineStageFlagBits srcStage, vk::PipelineStageFlagBits dstStage, uint32_t frameIndex) noexcept; + void CopyToBuffer (Handle dstBuffer, Handle commandBuffer, uint32_t frameIndex = 0) const noexcept; + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ vk::Format GetResourceFormat (void) const noexcept; + uint32_t GetWidth (void) const noexcept; + uint32_t GetHeight (void) const noexcept; friend class SHRenderGraphNode; friend class SHRenderGraph; diff --git a/SHADE_Engine/src/Graphics/SHVkUtil.cpp b/SHADE_Engine/src/Graphics/SHVkUtil.cpp index 2d0e7cf2..c8c563a1 100644 --- a/SHADE_Engine/src/Graphics/SHVkUtil.cpp +++ b/SHADE_Engine/src/Graphics/SHVkUtil.cpp @@ -42,6 +42,19 @@ namespace SHADE return false; } + uint32_t SHVkUtil::GetBytesPerPixelFromFormat(vk::Format format) noexcept + { + // TODO: Update with all formats + switch (format) + { + case vk::Format::eR32Sint: + case vk::Format::eR32Uint: + case vk::Format::eR32Sfloat: + return 4; + } + return 0; + } + void SHVkUtil::EnsureBufferAndCopyData(Handle device, Handle cmdBuffer, Handle& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage) { if (bufferHandle) diff --git a/SHADE_Engine/src/Graphics/SHVkUtil.h b/SHADE_Engine/src/Graphics/SHVkUtil.h index d8625607..ca3b6f83 100644 --- a/SHADE_Engine/src/Graphics/SHVkUtil.h +++ b/SHADE_Engine/src/Graphics/SHVkUtil.h @@ -19,10 +19,12 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ class SHVkUtil { - public: - static bool IsDepthOnlyFormat (vk::Format format) noexcept; - static bool IsDepthStencilAttachment(vk::Format format) noexcept; - static bool IsBlendCompatible (vk::Format format) noexcept; + public: + static bool IsDepthOnlyFormat (vk::Format format) noexcept; + static bool IsDepthStencilAttachment (vk::Format format) noexcept; + static bool IsBlendCompatible (vk::Format format) noexcept; + static uint32_t GetBytesPerPixelFromFormat (vk::Format format) noexcept; + /***********************************************************************************/ /*! diff --git a/SHADE_Engine/src/Input/SHInputManager.cpp b/SHADE_Engine/src/Input/SHInputManager.cpp index 04f2b02e..a6090062 100644 --- a/SHADE_Engine/src/Input/SHInputManager.cpp +++ b/SHADE_Engine/src/Input/SHInputManager.cpp @@ -44,6 +44,9 @@ namespace SHADE void SHInputManager::UpdateInput(double dt) noexcept { //Keyboard and Mouse Buttons//////////////////////////////////////////////// + //Write to lastKeys + memcpy(keysLast, keys, sizeof(keys)); + //Poll unsigned char keyboardState[MAX_KEYS]; //if (GetKeyboardState(keyboardState) == false) return; @@ -96,9 +99,6 @@ namespace SHADE } } - //Write to lastKeys - memcpy(keysLast, keys, sizeof(keys)); - //Mouse Positioning///////////////////////////////////// //https://stackoverflow.com/a/6423739 diff --git a/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp index f3a4c276..7d2e257b 100644 --- a/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp +++ b/SHADE_Engine/src/Physics/SHPhysicsSystem.cpp @@ -203,9 +203,9 @@ namespace SHADE void SHPhysicsSystem::AddRigidBody(EntityID entityID) noexcept { - #ifdef _DEBUG - SHLOG_INFO("Adding a Rigidbody to the Physics World.") - #endif + //#ifdef _DEBUG + // SHLOG_INFO("Adding a Rigidbody to the Physics World.") + //#endif // Check if entity is already a physics object auto* physicsObject = GetPhysicsObject(entityID); @@ -274,9 +274,9 @@ namespace SHADE void SHPhysicsSystem::AddCollider(EntityID entityID) noexcept { - #ifdef _DEBUG - SHLOG_INFO("Adding a Collider to the Physics World.") - #endif + //#ifdef _DEBUG + // SHLOG_INFO("Adding a Collider to the Physics World.") + //#endif // Check if entity is already a physics object auto* physicsObject = GetPhysicsObject(entityID); @@ -488,7 +488,7 @@ namespace SHADE const auto it = map.find(entityID); if (it == map.end()) { - SHLOG_ERROR("Entity {} is not in the physics system!", entityID) + //SHLOG_ERROR("Entity {} is not in the physics system!", entityID) return nullptr; } diff --git a/SHADE_Engine/src/Scene/SHSceneGraph.cpp b/SHADE_Engine/src/Scene/SHSceneGraph.cpp index 3fe85809..bbbdb7e4 100644 --- a/SHADE_Engine/src/Scene/SHSceneGraph.cpp +++ b/SHADE_Engine/src/Scene/SHSceneGraph.cpp @@ -571,9 +571,9 @@ namespace SHADE { SHSceneNode* newNode = new SHSceneNode{entityID}; - #ifdef _DEBUG - SHLOG_INFO("Allocated a new Scene Node for Entity {}!", entityID) - #endif + //#ifdef _DEBUG + // SHLOG_INFO("Allocated a new Scene Node for Entity {}!", entityID) + //#endif entityNodeMap.emplace(entityID, newNode); return newNode; From 682a5a6cbfaf5313b59c26cebf9a9e6ded7efe54 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 14 Oct 2022 00:10:56 +0800 Subject: [PATCH 3/4] bug fix --- SHADE_Application/src/Scenes/SBTestScene.cpp | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/SHADE_Application/src/Scenes/SBTestScene.cpp b/SHADE_Application/src/Scenes/SBTestScene.cpp index e327f833..f1d656ee 100644 --- a/SHADE_Application/src/Scenes/SBTestScene.cpp +++ b/SHADE_Application/src/Scenes/SBTestScene.cpp @@ -86,10 +86,10 @@ namespace Sandbox for (int y = 0; y < NUM_ROWS; ++y) for (int x = 0; x < NUM_COLS; ++x) { - auto entity = SHEntityManager::CreateEntity(); + auto entity = SHEntityManager::CreateEntity(); auto& renderable = *SHComponentManager::GetComponent_s(entity); auto& transform = *SHComponentManager::GetComponent_s(entity); - //auto& collider = *SHComponentManager::GetComponent_s(entity); + auto& collider = *SHComponentManager::GetComponent_s(entity); //renderable.Mesh = handles.front(); renderable.Mesh = CUBE_MESH; @@ -99,7 +99,7 @@ namespace Sandbox renderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 0.0f, 0.0f, 1.0f)); //Set initial positions - transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, y * TEST_OBJ_SPACING.y, SHMath::GenerateRandomNumber(-300.5f, 500.0f)}); + transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, y * TEST_OBJ_SPACING.y, SHMath::GenerateRandomNumber(-3.5f, -5.0f) }); //transform.SetWorldPosition({-1.0f, -1.0f, -1.0f}); transform.SetWorldRotation(SHMath::GenerateRandomNumber(), SHMath::GenerateRandomNumber(), SHMath::GenerateRandomNumber()); transform.SetWorldScale(TEST_OBJ_SCALE); @@ -125,23 +125,23 @@ namespace Sandbox transform.SetWorldPosition({ -3.0f, -1.0f, -1.0f }); transform.SetLocalScale({ 5.0f, 5.0f, 5.0f }); - auto floor = SHEntityManager::CreateEntity(); + auto floor = SHEntityManager::CreateEntity(); auto& floorRenderable = *SHComponentManager::GetComponent_s(floor); auto& floorTransform = *SHComponentManager::GetComponent_s(floor); - //auto& floorRigidBody = *SHComponentManager::GetComponent_s(floor); - //auto& floorCollider = *SHComponentManager::GetComponent_s(floor); + auto& floorRigidBody = *SHComponentManager::GetComponent_s(floor); + auto& floorCollider = *SHComponentManager::GetComponent_s(floor); floorRenderable.Mesh = CUBE_MESH; floorRenderable.SetMaterial(customMat); floorRenderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 1.0f, 1.0f, 1.0f)); - floorTransform.SetWorldScale({7.5f, 0.5f, 7.5}); - floorTransform.SetWorldPosition({0.0f, -3.0f, -5.0f}); + floorTransform.SetWorldScale({ 7.5f, 0.5f, 7.5 }); + floorTransform.SetWorldPosition({ 0.0f, -3.0f, -5.0f }); - //floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC); + floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC); - //auto* floorBox = floorCollider.AddBoundingBox(); - //floorBox->SetHalfExtents(floorTransform.GetWorldScale() * 0.5f); + auto* floorBox = floorCollider.AddBoundingBox(); + floorBox->SetHalfExtents(floorTransform.GetWorldScale() * 0.5f); // Create blank entity with a script //testObj = SHADE::SHEntityManager::CreateEntity(); From faa55847cb5b139a0a957cd6e2efbd6f732c0df5 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Fri, 14 Oct 2022 11:52:15 +0800 Subject: [PATCH 4/4] Mouse picking is working from rendering side - Buffer now has function to get data from mapped pointer if it exists - Batches now also pass a buffer of EIDs to the GPU - Global vertex attributes now have 1 extra instanced attribute for storing EntityIDs - Render graph resources now have a usage flags on top of the usage flags calculated in the graph AddResource function. This is to tell vulkan that we want some resources to be copyable for example (EID render target copy to buffer). - Mouse pick system stores eid picked --- .../src/Graphics/Buffers/SHVkBuffer.h | 11 +++++ .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 45 +++++++++++++++++- .../src/Graphics/MiddleEnd/Batching/SHBatch.h | 6 ++- .../MiddleEnd/Batching/SHSuperBatch.cpp | 3 +- .../GlobalData/SHGraphicsGlobalData.cpp | 7 +-- .../MiddleEnd/Interface/SHGraphicsConstants.h | 8 ++++ .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 +- .../MiddleEnd/Interface/SHGraphicsSystem.h | 1 + .../MiddleEnd/Interface/SHMousePickSystem.cpp | 40 ++++++++++------ .../MiddleEnd/Interface/SHMousePickSystem.h | 11 ++++- .../Graphics/RenderGraph/SHRenderGraph.cpp | 4 +- .../src/Graphics/RenderGraph/SHRenderGraph.h | 2 +- .../RenderGraph/SHRenderGraphResource.cpp | 4 +- .../RenderGraph/SHRenderGraphResource.h | 2 +- TempShaderFolder/TestCubeFs.glsl | 3 +- TempShaderFolder/TestCubeFs.spv | Bin 2100 -> 2156 bytes TempShaderFolder/TestCubeVs.glsl | 4 ++ TempShaderFolder/TestCubeVs.spv | Bin 2152 -> 2300 bytes 18 files changed, 123 insertions(+), 30 deletions(-) diff --git a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h index 648a07e8..e931fec5 100644 --- a/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h +++ b/SHADE_Engine/src/Graphics/Buffers/SHVkBuffer.h @@ -105,6 +105,17 @@ namespace SHADE vk::Buffer GetVkBuffer (void) const noexcept; vk::BufferUsageFlags GetUsageBits(void) const noexcept; + template + T GetDataFromMappedPointer(uint32_t index) const noexcept + { + if (mappedPtr && index < sizeStored / sizeof (T)) + { + return (static_cast(mappedPtr))[index]; + } + else + return {}; + }; + }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 181c1f22..2705b4d1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -110,6 +110,7 @@ namespace SHADE // Clear CPU buffers drawData.clear(); transformData.clear(); + eidData.clear(); matPropsData.reset(); matPropsDataSize = 0; @@ -119,6 +120,7 @@ namespace SHADE { drawDataBuffer[i].Free(); transformDataBuffer[i].Free(); + eidBuffer[i].Free(); matPropsBuffer[i].Free(); } } @@ -206,7 +208,31 @@ namespace SHADE transformDataBuffer[frameIndex]->WriteToMemory(transformData.data(), static_cast(transformData.size() * sizeof(SHMatrix)), 0, 0); } - void SHBatch::Build(Handle _device, Handle descPool, uint32_t frameIndex) + void SHBatch::UpdateEIDBuffer(uint32_t frameIndex) + { + if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS) + { + SHLOG_WARNING("[SHBatch] Attempted to update eid buffers with an invalid frame index."); + return; + } + + // Reset Transform Data + eidData.clear(); + + // Populate on the CPU + for (auto& subBatch : subBatches) + for (const SHRenderable* renderable : subBatch.Renderables) + { + eidData.emplace_back(renderable->GetEID()); + } + + // Transfer to GPU + if (eidBuffer[frameIndex]) + eidBuffer[frameIndex]->WriteToMemory(eidData.data(), static_cast(eidData.size() * sizeof(EntityID)), 0, 0); + + } + + void SHBatch::Build(Handle _device, Handle descPool, uint32_t frameIndex) { if (frameIndex >= SHGraphicsConstants::NUM_FRAME_BUFFERS) { @@ -237,6 +263,11 @@ namespace SHADE // - Transform data transformData.reserve(numTotalElements); transformData.clear(); + // - EID data + eidData.reserve(numTotalElements); + eidData.clear(); + + // - Material Properties Data const Handle SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface ( @@ -277,7 +308,8 @@ namespace SHADE for (const SHRenderable* renderable : subBatch.Renderables) { // Transform - auto transform = SHComponentManager::GetComponent_s(renderable->GetEID()); + EntityID eid = renderable->GetEID(); + auto transform = SHComponentManager::GetComponent_s(eid); if (!transform) { SHLOG_WARNING("[SHBatch] Entity contianing a SHRenderable with no SHTransformComponent found!"); @@ -287,6 +319,8 @@ namespace SHADE { transformData.emplace_back(transform->GetTRS()); } + + eidData.emplace_back(eid); // Material Properties if (!EMPTY_MAT_PROPS) @@ -317,6 +351,12 @@ namespace SHADE device, transformDataBuffer[frameIndex], transformData.data(), TF_DATA_BYTES, BuffUsage::eVertexBuffer ); + const uint32_t EID_DATA_BYTES = static_cast(eidData.size() * sizeof(EntityID)); + SHVkUtil::EnsureBufferAndCopyHostVisibleData + ( + device, eidBuffer[frameIndex], eidData.data(), EID_DATA_BYTES, + BuffUsage::eVertexBuffer + ); // - Material Properties Buffer rebuildMaterialBuffers(frameIndex, descPool); @@ -339,6 +379,7 @@ namespace SHADE static std::array dynamicOffset { 0 }; cmdBuffer->BindPipeline(pipeline); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0); + cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::EID, eidBuffer[frameIndex], 0); if (matPropsDescSet[frameIndex]) { cmdBuffer->BindDescriptorSet diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h index abe691ca..37c57396 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.h @@ -22,6 +22,7 @@ of DigiPen Institute of Technology is prohibited. #include "Graphics/MiddleEnd/Interface/SHMaterial.h" #include "Math/SHMatrix.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" +#include "ECS_Base/SHECSMacros.h" namespace SHADE { @@ -78,6 +79,7 @@ namespace SHADE void Clear(); void UpdateMaterialBuffer(uint32_t frameIndex, Handle descPool); void UpdateTransformBuffer(uint32_t frameIndex); + void UpdateEIDBuffer(uint32_t frameIndex); void Build(Handle device, Handle descPool, uint32_t frameIndex) ; void Draw(Handle cmdBuffer, uint32_t frameIndex); @@ -109,14 +111,16 @@ namespace SHADE // CPU Buffers std::vector drawData; std::vector transformData; + std::vector eidData; std::unique_ptr matPropsData; Byte matPropsDataSize = 0; Byte singleMatPropAlignedSize = 0; - Byte singleMatPropSize = 0; + Byte singleMatPropSize = 0; bool isCPUBuffersDirty = true; // GPU Buffers TripleBuffer drawDataBuffer; TripleBuffer transformDataBuffer; + TripleBuffer eidBuffer; TripleBuffer matPropsBuffer; TripleDescSet matPropsDescSet; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp index 0d75dca8..add51196 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHSuperBatch.cpp @@ -83,8 +83,9 @@ namespace SHADE { for (auto& batch : batches) { - batch.UpdateMaterialBuffer(frameIndex, descPool); + batch.UpdateMaterialBuffer(frameIndex, descPool); batch.UpdateTransformBuffer(frameIndex); + batch.UpdateEIDBuffer(frameIndex); } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp index 6a7b23f2..d8b1bad1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.cpp @@ -91,9 +91,10 @@ namespace SHADE { defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1 - defaultVertexInputState.AddBinding(false, false, {SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); // Normals at binding 2 - defaultVertexInputState.AddBinding(false, false, {SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); // Tangents at binding 3 - defaultVertexInputState.AddBinding(true, true, {SHVertexAttribute(SHAttribFormat::MAT_4D)}); // Transform at binding 4 - 7 (4 slots) + defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Normals at binding 2 + defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Tangents at binding 3 + defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }); // Transform at binding 4 - 7 (4 slots) + defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_1D) }); // EID at binding 8 } void SHGraphicsGlobalData::Init(Handle logicalDevice) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index 0818ebab..ac2f1f8c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -144,6 +144,14 @@ namespace SHADE */ /***************************************************************************/ static constexpr uint32_t TRANSFORM = 4; + /***************************************************************************/ + /*! + \brief + Vertex buffer bindings for the eid buffer. + */ + /***************************************************************************/ + static constexpr uint32_t EID = 5; + }; /*******************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 636aa27a..09f1c93e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -146,7 +146,7 @@ namespace SHADE worldRenderGraph->Init(device, swapchain); worldRenderGraph->AddResource("Present", SH_ATT_DESC_TYPE::COLOR_PRESENT, windowDims.first, windowDims.second); worldRenderGraph->AddResource("Depth Buffer", SH_ATT_DESC_TYPE::DEPTH_STENCIL, windowDims.first, windowDims.second, vk::Format::eD32SfloatS8Uint); - worldRenderGraph->AddResource("Entity ID", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR32Uint); + worldRenderGraph->AddResource("Entity ID", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR32Uint, 1, vk::ImageUsageFlagBits::eTransferSrc); //worldRenderGraph->AddResource("Position", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); //worldRenderGraph->AddResource("Normals", SH_ATT_DESC_TYPE::COLOR, windowDims.first, windowDims.second, vk::Format::eR16G16B16A16Sfloat); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 981600f3..3160cd57 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -269,6 +269,7 @@ namespace SHADE Handle GetQueue() const { return graphicsQueue; } Handle GetDescriptorPool() const { return descPool; } Handle GetDefaultViewport() const {return defaultViewport;} + Handle GetMousePickSystem(void) const noexcept {return mousePickSystem;}; //SHRenderGraph const& GetRenderGraph(void) const noexcept; //Handle GetRenderPass() const { return renderPass; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp index ec7a5491..ee8665d5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp @@ -11,6 +11,8 @@ namespace SHADE { void SHMousePickSystem::Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept { + pickedEID = 0; + // Create command buffers for (auto& pool : cmdPools) { @@ -32,28 +34,38 @@ namespace SHADE void SHMousePickSystem::Run(Handle queue, uint32_t frameIndex) noexcept { // if input detected - if (/*SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LEFT_CTRL) && */SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LEFT_CTRL) && SHInputManager::GetKeyUp(SHInputManager::SH_KEYCODE::LMB)) { - std::cout << "Input registered... " << std::endl; + afterCopyFence->Reset(); - //// begin command buffer for recording - //commandBuffers[frameIndex]->BeginRecording(); + // begin command buffer for recording + commandBuffers[frameIndex]->BeginRecording(); - //// transition the image for optimized copying - //entityIDAttachment->TransitionImage (vk::ImageLayout::eColorAttachmentOptimal, vk::ImageLayout::eTransferSrcOptimal, commandBuffers[frameIndex], vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eTransfer, 0); + // transition the image for optimized copying + entityIDAttachment->TransitionImage (vk::ImageLayout::eColorAttachmentOptimal, vk::ImageLayout::eTransferSrcOptimal, commandBuffers[frameIndex], vk::PipelineStageFlagBits::eColorAttachmentOutput, vk::PipelineStageFlagBits::eTransfer, 0); - //// copy the image here. Last argument is 0 because the attachment isn't a swapchain image. - //entityIDAttachment->CopyToBuffer(imageDataDstBuffer, commandBuffers[frameIndex], 0); + // copy the image here. Last argument is 0 because the attachment isn't a swapchain image. + entityIDAttachment->CopyToBuffer(imageDataDstBuffer, commandBuffers[frameIndex], 0); - //// end command buffer for recording - //commandBuffers[frameIndex]->EndRecording(); + // end command buffer for recording + commandBuffers[frameIndex]->EndRecording(); - //// submit the command buffer to copy image to buffer - //queue->SubmitCommandBuffer({ commandBuffers[frameIndex] }, {}, {}, vk::PipelineStageFlagBits::eColorAttachmentOutput, afterCopyFence); + // submit the command buffer to copy image to buffer + queue->SubmitCommandBuffer({ commandBuffers[frameIndex] }, {}, {}, vk::PipelineStageFlagBits::eColorAttachmentOutput, afterCopyFence); - //// wait for the copy to be done - //afterCopyFence->Wait(true, std::numeric_limits::max()); + // wait for the copy to be done + afterCopyFence->Wait(true, std::numeric_limits::max()); + + int mouseX = 0, mouseY = 0; + SHInputManager::GetMouseWindowPosition(&mouseX, &mouseY); + + pickedEID = imageDataDstBuffer->GetDataFromMappedPointer(mouseY * entityIDAttachment->GetWidth() + mouseX); } } + EntityID SHMousePickSystem::GetPickedEntity(void) const noexcept + { + return pickedEID; + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h index 815eb938..080a192c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h @@ -29,10 +29,19 @@ namespace SHADE //! buffer to contain the attachment data after copying Handle imageDataDstBuffer; + //! eid picked from screen + EntityID pickedEID; public: + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ void Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept; - void Run (Handle queue, uint32_t frameIndex) noexcept; + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + EntityID GetPickedEntity (void) const noexcept; + }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 78bd1ca6..1861f6d2 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -40,7 +40,7 @@ namespace SHADE */ /***************************************************************************/ - void SHRenderGraph::AddResource(std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w /*= static_cast(-1)*/, uint32_t h /*= static_cast(-1)*/, vk::Format format/* = vk::Format::eB8G8R8A8Unorm*/, uint8_t levels /*= 1*/, vk::ImageCreateFlagBits createFlags /*= {}*/) + void SHRenderGraph::AddResource(std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w /*= static_cast(-1)*/, uint32_t h /*= static_cast(-1)*/, vk::Format format/* = vk::Format::eB8G8R8A8Unorm*/, uint8_t levels /*= 1*/, vk::ImageUsageFlagBits usageFlags/* = {}*/, vk::ImageCreateFlagBits createFlags /*= {}*/) { // If we set to if (w == static_cast(-1) && h == static_cast(-1)) @@ -50,7 +50,7 @@ namespace SHADE format = swapchainHdl->GetSurfaceFormatKHR().format; } - graphResources.try_emplace(resourceName, resourceManager.Create(logicalDeviceHdl, swapchainHdl, resourceName, type, format, w, h, levels, createFlags)); + graphResources.try_emplace(resourceName, resourceManager.Create(logicalDeviceHdl, swapchainHdl, resourceName, type, format, w, h, levels, usageFlags, createFlags)); } /***************************************************************************/ diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 2e9a3310..cfc29bc2 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -75,7 +75,7 @@ namespace SHADE /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ void Init (Handle const& logicalDevice, Handle const& swapchain) noexcept; - void AddResource (std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w = static_cast(-1), uint32_t h = static_cast(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageCreateFlagBits createFlags = {}); + void AddResource(std::string resourceName, SH_ATT_DESC_TYPE type, uint32_t w = static_cast(-1), uint32_t h = static_cast(-1), vk::Format format = vk::Format::eB8G8R8A8Unorm, uint8_t levels = 1, vk::ImageUsageFlagBits usageFlags = {}, vk::ImageCreateFlagBits createFlags = {}); Handle AddNode (std::string nodeName, std::initializer_list resourceNames, std::initializer_list predecessorNodes) noexcept; void Generate (void) noexcept; void Execute (uint32_t frameIndex, Handle cmdBuffer, Handle descPool) noexcept; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp index e8c9863f..bcd1dc9f 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.cpp @@ -45,7 +45,7 @@ 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 + 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::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept : logicalDevice {logicalDevice} , swapchain{ swapchain } , resourceType{ type } @@ -61,7 +61,7 @@ namespace SHADE if (resourceType != SH_ATT_DESC_TYPE::COLOR_PRESENT) { imageAspectFlags = vk::ImageAspectFlags{}; - usage = {}; + usage = usageFlags; // Check the resource type and set image usage flags and image aspect flags accordingly switch (resourceType) diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h index a490ab95..66f0677b 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphResource.h @@ -67,7 +67,7 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* CTORS AND DTORS */ /*-----------------------------------------------------------------------*/ - 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; + 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::ImageUsageFlagBits usageFlags, vk::ImageCreateFlagBits createFlags) noexcept; SHRenderGraphResource(SHRenderGraphResource&& rhs) noexcept; SHRenderGraphResource& operator=(SHRenderGraphResource&& rhs) noexcept; ~SHRenderGraphResource(void) noexcept; diff --git a/TempShaderFolder/TestCubeFs.glsl b/TempShaderFolder/TestCubeFs.glsl index ab0f089f..18890c92 100644 --- a/TempShaderFolder/TestCubeFs.glsl +++ b/TempShaderFolder/TestCubeFs.glsl @@ -22,6 +22,7 @@ layout(location = 0) in struct layout(location = 2) flat in struct { int materialIndex; + uint eid; } In2; //layout (set = 0, binding = ) @@ -40,6 +41,6 @@ void main() outColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv) + MatProp.data[In2.materialIndex].color / MatProp.data[In2.materialIndex].alpha; - outEntityID = 5; + outEntityID = In2.eid; //outColor = vec4 (1.0f); } \ No newline at end of file diff --git a/TempShaderFolder/TestCubeFs.spv b/TempShaderFolder/TestCubeFs.spv index a069acf6e2e436753364704fd981a0cad627a143..bde6213644b38cb5e844a04ac20ad1ca3e43b62c 100644 GIT binary patch literal 2156 zcmZ9MOH&g;5XVRJ5QC_wh>Btm-w#9t#J5qYn5tM%VyU;SH5qU}04;w3X=)>dBy z%Wqx=P1|iGQ73IDK@>Obb`)=zVN=ZRSLky9$()Q#Ho?(B-^5tM#Dr;&ITmoiGVg8+6}=O`8Pmx9@Eu?f&Z{ zlgbKOVZ6}`H*7FJH`@st9~5VZIJ6PB<6a!Cx0B7_V=rt)>yb@lFJZ5)tW@jEL8H?N zy6H~K2CXQzK{HB}DcZ8+%HlY`C~mZR%|VBPJO=wLm_pWTyO%y`x7vx?5>n87j7jZw z+DoiD=wqYe&%<;zX?LE6X{gB-w3q&AxXVRN2#mS9`!#lfm-lCOVXN~l9KhJdTdSZt z1;sclu3R>W!WIc_l15ZQ3~ZbxMd;Aen7FG=dd?ifphG=g-gNPNK}FreMy)n#X7|{6 zEuPEd3z9iS{dsvyh4?{nADsKWE$YZ+@1>>}#0+^in(K0$M(IxNsj14JcQq;Epfl$) znf6zol1|KLis9!w?R-3j9qizMA9DrMXYuDQa|J7l$ahG*DB>d^mY*d)oT_>N;~xIZ zmHGyC>f_+cyyyX6WO}0xY~1^zVvx@c$mjmZ`D|W;^I&G^^mka1h&84A76qs z{eXB`L@a7!H{>Gsq$GApUHE}xCkH#hHYu6eqmz$4(lZ$O(Afvr6_@X*WDfbq#mgu< zlhS$HbXd6Y%$1Rre7%ll4AE{oRO-7}KGh(9gP zH{rj3?(oj|Ho);=9#=%n$j4P z=bYWgyD9zuc=N)*iN`K(iF`b4?25kF&yooHs(gum+hO3IKD&PI2qQl}pB#2qGJRru gpl$I@gHa!QeJG+nKPPtlNCb{Q?*RRmUci#*H@-Bqy8r+H delta 902 zcmZ9Kxk^J(5QZnY$qg!TL1SFw5|_B|`$j5BCx}=JS_o<(Dt19^Y~^CK0|A~p@HZSc=JGe?r=#PrSnZJ2DKK}du%Qg5>k{D0>Yu55gq%PQ zF}C7!du0>fb+vu6;mUecHdGXNE_iC#)_@?s8YeOKsK6?`Fe?~y{Jw-(3)p&uiVb;3AheN+ZJCA%P-md(rV$(Cd_*=yOTej}QHD^Z{d>WyZ7d%NCv z-E8%G&3^tZiJD2AM$LAdMXfyEkI;<|>Eg7N4BEqjk`%+Wl(ffT?ZGJP=hypDmRGw; zH?w?TdCoJ~H-;F_usz7_nzMu-KiTyetr=xAX8gJn=1~@h$yVBqzFJ>kedLScw&DWY z3*~!AY)P^7WiM%NrTsiiTagd7d(bZzS2ow2ZYRnDzSn3No+BR|v**YO zM=w3c8ZMC4@;9BC;#L0@mh|&#Q8JP=h^@8j4*>U({s+~ zY6|Rk31;B0X$Jdz^cl=qPK$+~5dyQG(yFYvB0Hye>H?D=OfSJ`r-k_r(ZE-Pk7yFJeYg;{zfu{v561`6I6XZ1 zz`PrB`2Ejm&0zoYn%RpS=)t@zzyBqziFM})%$35&e(1sU*Xt`E#_6{l!lX`gm6c?=k;`>FF=U;C~=P1CNGYF3afSduiz5 zz4E#z1xMd@)MfhoR7N~{{M^S+<#l)9_D91RxSur{Z_M`u{LJ#Mwij9t s*S0PU$MAJ*Xbm@9+slF*uI-gL;x}aYsm<3>)tbBXb%4?TRn}G6KNk$B#sB~S literal 2152 zcmZ9NYflqF6ovc&^rtYs=lJxxBLa z9K{uri-l;$g&28R%kcvIQQ5d`N;WGi%O1;~$+l$`Sx&z}&408=Ub|Oo_3Ghawf4T= z=ydAc=)3RMeJ^n9O)qpCk=J+84QF&-(C~ZBte_x8wvK}KxTHN8Mg6Sbcf)A6?YG02 z&&NDx>Gh2vhx!kDQS5UL=ksaoPs(Q$&5*Hv%Zc33bNqv#>3&m;8aTJ|U!pBYOApTc z`a#f*oS@-asbWQQCy5=o;i;;MmxybHXDIKe-Sr}`9mM;>Q)|q7L3Hf>P-l{wh|yEU zc73n2=Oz1{=W%PqdcJ=ix5mVW1h6KN*@ zp5{g-pEGjzU)!PIJPDnk`=uSW5-sn+Nsg^E!sX-l;e3?D@#FO>Xil8q%njJWRHfm5 z<^dXD?g&gRVEPZH7hw8N&XR0jtJ>beF)T+u9JA$E1CHKV4j+!UR#n9Iow)6lo%f}} zXU&4lYQXSUFL3%8V~%x++cVJDg$uYW%;1dlm@_9e<>PNH+oSC?Zr7`%IH!41yTF&V zCm4TPUQu&NHltOk3(Wf9;S{5t7v|eS178vz(ac)#8!5JZoD#kq>yo}KrFcvneIcK} zD)_8NKA3y9@d^2?Pkde;-(#|7-ds;(aO8q{6X@+;)AAYYHKUnz$wv?7&Dgze$|sjN zwa;lT$r!8$zAZyPCrsbz72Lc$-iPfUF^qjnnpu}P`-00dxLM%^&E(N@dc2roc=GRR zrvLEdgLx-##P6rR)jtv*kb%*Ic{gy}=~K#Yz*@Lis2jC6wAHxZE)v1V!7{YGTspHWJ?)fH0ZgT8#3+< zJ$H6X#=Udb=)q`+)0+n}`o(&zL0=xq;4NN~Pmg{phxij28hAAHhJT9m<&!k@gg^Xn z49mTe4@WO7w~})7;YeMhZ>uu$(G#b?zqBr~H5vP(;SBV9T~?OaGlJ3C+TO^|*7jBy nj$!NAkPnxw?On=cYugk@K6>KRX6x9J&)wKM!07*J)pgl_O#Gk(