diff --git a/Assets/Shaders/ToSwapchain_FS.glsl b/Assets/Shaders/ToSwapchain_FS.glsl index 9a35d1c4..a68fa0c7 100644 --- a/Assets/Shaders/ToSwapchain_FS.glsl +++ b/Assets/Shaders/ToSwapchain_FS.glsl @@ -3,17 +3,12 @@ #extension GL_ARB_shading_language_420pack : enable #extension GL_EXT_nonuniform_qualifier : require -layout (input_attachment_index = 0, set = 4, binding = 0) uniform subpassInput vec4 sceneTexture; +layout (input_attachment_index = 0, set = 4, binding = 0) uniform subpassInput sceneTexture; -layout(location = 0) in struct -{ - vec2 uv; // location = 0 - -} In; layout(location = 0) out vec4 fragColor; void main() { - fragColor = vec4 (texture (sceneTexture, In.uv).rgb, 1.0f); + fragColor = vec4 (subpassLoad(sceneTexture).rgb, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/ToSwapchain_FS.shshaderb b/Assets/Shaders/ToSwapchain_FS.shshaderb new file mode 100644 index 00000000..b10a9d6c Binary files /dev/null and b/Assets/Shaders/ToSwapchain_FS.shshaderb differ diff --git a/Assets/Shaders/ToSwapchain_FS.shshaderb.shmeta b/Assets/Shaders/ToSwapchain_FS.shshaderb.shmeta new file mode 100644 index 00000000..731b2783 --- /dev/null +++ b/Assets/Shaders/ToSwapchain_FS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ToSwapchain_FS +ID: 36869006 +Type: 2 diff --git a/Assets/Shaders/ToSwapchain_VS.glsl b/Assets/Shaders/ToSwapchain_VS.glsl index cc3e2c28..eee22015 100644 --- a/Assets/Shaders/ToSwapchain_VS.glsl +++ b/Assets/Shaders/ToSwapchain_VS.glsl @@ -1,11 +1,6 @@ #version 450 #extension GL_KHR_vulkan_glsl : enable -layout(location = 0) out struct -{ - vec2 uv; // location = 0 - -} Out; vec2 CreateQuad(in uint vertexID) { @@ -15,7 +10,6 @@ vec2 CreateQuad(in uint vertexID) void main() { - vec2 texCoord = CreateQuad (gl_VertexIndex); - vec2 vertexPos = texCoord - vec2(0.5f); + vec2 vertexPos = 2 * (CreateQuad(gl_VertexIndex) - vec2(0.5f)); gl_Position = vec4 (vertexPos, 0.0f, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/ToSwapchain_VS.shshaderb b/Assets/Shaders/ToSwapchain_VS.shshaderb new file mode 100644 index 00000000..4c3157f9 Binary files /dev/null and b/Assets/Shaders/ToSwapchain_VS.shshaderb differ diff --git a/Assets/Shaders/ToSwapchain_VS.shshaderb.shmeta b/Assets/Shaders/ToSwapchain_VS.shshaderb.shmeta new file mode 100644 index 00000000..23bcbe08 --- /dev/null +++ b/Assets/Shaders/ToSwapchain_VS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ToSwapchain_VS +ID: 48082949 +Type: 2 diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 5062b4de..1a00941f 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -80,8 +80,8 @@ namespace Sandbox SHSystemManager::CreateSystem(); SHSystemManager::CreateSystem(); - std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf"); - std::system("FontCompiler.exe ../../Assets/Fonts/ALGER.ttf"); + //std::system("FontCompiler.exe ../../Assets/Fonts/SegoeUI.ttf"); + //std::system("FontCompiler.exe ../../Assets/Fonts/ALGER.ttf"); SHSystemManager::CreateSystem(); SHGraphicsSystem* graphicsSystem = static_cast(SHSystemManager::GetSystem()); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index a2276ed6..af09c819 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -84,7 +84,7 @@ namespace SHADE if (width == 0 || height == 0) return; - PrepareResize(resizeWidth, resizeHeight); + PrepareResize(width, height); }); window->RegisterWindowCloseCallback([&](void) @@ -125,6 +125,8 @@ namespace SHADE //SHAssetManager::CompileAsset("../../Assets/Shaders/UI_VS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/UI_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Models/Quad.gltf", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_VS.glsl", false); + //SHAssetManager::CompileAsset("../../Assets/Shaders/ToSwapchain_FS.glsl", false); // Load Built In Shaders static constexpr AssetID VS_DEFAULT = 39210065; defaultVertShader = SHResourceManager::LoadOrGet(VS_DEFAULT); @@ -136,6 +138,8 @@ namespace SHADE static constexpr AssetID SSAO_BLUR = 39760835; ssaoBlurShader = SHResourceManager::LoadOrGet(SSAO_BLUR); static constexpr AssetID TEXT_VS = 39816727; textVS = SHResourceManager::LoadOrGet(TEXT_VS); static constexpr AssetID TEXT_FS = 38024754; textFS = SHResourceManager::LoadOrGet(TEXT_FS); + static constexpr AssetID RENDER_SC_VS = 48082949; renderToSwapchainVS = SHResourceManager::LoadOrGet(RENDER_SC_VS); + static constexpr AssetID RENDER_SC_FS = 36869006; renderToSwapchainFS = SHResourceManager::LoadOrGet(RENDER_SC_FS); } void SHGraphicsSystem::InitSceneRenderGraph(void) noexcept @@ -299,6 +303,7 @@ namespace SHADE textRenderingSubSystem->Render(cmdBuffer, frameIndex); }); +#ifdef SHEDITOR { // Dummy Node to transition scene render graph resource auto dummyNode = screenRenderGraph->AddNode("Dummy Pass", { "Scene" }, { "Screen Space Pass" }); // no predecessors @@ -306,7 +311,9 @@ namespace SHADE dummySubpass->AddInput("Scene"); } - //screenRenderGraph->AddRenderToSwapchainNode ("Scene", "Present", ) +#else + screenRenderGraph->AddRenderToSwapchainNode("Scene", "Present", {"Screen Space Pass"}, {renderToSwapchainVS, renderToSwapchainFS}); +#endif screenRenderGraph->Generate(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index c201e9a5..8c65f233 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -444,6 +444,8 @@ namespace SHADE Handle ssaoBlurShader; Handle textVS; Handle textFS; + Handle renderToSwapchainVS; + Handle renderToSwapchainFS; // Fonts Handle testFont; diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index 0580d650..2ffd6d13 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -565,8 +565,10 @@ namespace SHADE { cmdBuffer->BindPipeline(renderToSwapchainImageSystem->GetPipeline()); + newSubpass->BindDescriptorInputDescriptorSets (cmdBuffer, frameIndex); + // draw a quad. - cmdBuffer->DrawIndexed(4, 0, 0); + cmdBuffer->DrawArrays(4, 1, 0, 0); }); } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp index e4f020e4..770217ee 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp @@ -3,6 +3,8 @@ #include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/MiddleEnd/GlobalData/SHGraphicsGlobalData.h" #include "Graphics/RenderGraph/SHRenderGraphNode.h" +#include "Graphics/RenderGraph/SHSubpass.h" +#include "Graphics/SHVkUtil.h" namespace SHADE { @@ -25,14 +27,34 @@ namespace SHADE .globalDescSetLayouts = SHGraphicsGlobalData::GetDescSetLayouts(), }); - auto newPipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); + pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass); SHInputAssemblyState inputAssembly{}; inputAssembly.topology = vk::PrimitiveTopology::eTriangleFan; - newPipeline->GetPipelineState().SetInputAssemblyState(inputAssembly); + pipeline->GetPipelineState().SetInputAssemblyState(inputAssembly); - newPipeline->ConstructPipeline(); + SHColorBlendState colorBlendState{}; + colorBlendState.logic_op_enable = VK_FALSE; + colorBlendState.logic_op = vk::LogicOp::eCopy; + + auto const& subpassColorReference = subpass->GetColorAttachmentReferences()[0]; + colorBlendState.attachments.push_back(vk::PipelineColorBlendAttachmentState + { + .blendEnable = SHVkUtil::IsBlendCompatible(subpass->GetFormatFromAttachmentReference(subpassColorReference.attachment)), + .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, + } + ); + + pipeline->GetPipelineState().SetColorBlenState(colorBlendState); + + pipeline->ConstructPipeline(); } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp index 1eae9768..c1d53632 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.cpp @@ -40,7 +40,7 @@ namespace SHADE , inputReferences{} , name { name } , graphStorage{ renderGraphStorage } - , inputImageDescriptors {SHGraphicsConstants::NUM_FRAME_BUFFERS} + , inputImageDescriptorSets{} { } @@ -67,7 +67,7 @@ namespace SHADE , exteriorDrawCalls{ std::move(rhs.exteriorDrawCalls) } , graphStorage{ rhs.graphStorage } , inputNames{ std::move(rhs.inputNames) } - , inputImageDescriptors{ std::move(rhs.inputImageDescriptors) } + , inputImageDescriptorSets{ std::move(rhs.inputImageDescriptorSets) } , inputDescriptorLayout{ rhs.inputDescriptorLayout } , inputSamplers{ rhs.inputSamplers } , name { rhs.name } @@ -102,7 +102,7 @@ namespace SHADE exteriorDrawCalls = std::move(rhs.exteriorDrawCalls); graphStorage = rhs.graphStorage; inputNames = std::move(rhs.inputNames); - inputImageDescriptors = std::move(rhs.inputImageDescriptors); + inputImageDescriptorSets = std::move(rhs.inputImageDescriptorSets); inputDescriptorLayout = rhs.inputDescriptorLayout; inputSamplers = rhs.inputSamplers; name = std::move(rhs.name); @@ -202,6 +202,8 @@ namespace SHADE void SHSubpass::Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept { commandBuffer->BeginLabeledSegment(name); + + // Ensure correct transforms are provided superBatch->UpdateBuffers(frameIndex, descPool); @@ -221,6 +223,14 @@ namespace SHADE UpdateWriteDescriptors(); } + void SHSubpass::BindDescriptorInputDescriptorSets(Handle cmdBuffer, uint32_t frameIndex) const noexcept + { + if (!inputImageDescriptorSets.empty()) + { + cmdBuffer->BindDescriptorSet(inputImageDescriptorSets[frameIndex], SH_PIPELINE_TYPE::GRAPHICS, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, { }); + } + } + void SHSubpass::AddExteriorDrawCalls(std::function&, uint32_t)> const& newDrawCall) noexcept { exteriorDrawCalls.push_back(newDrawCall); @@ -237,6 +247,8 @@ namespace SHADE if (inputNames.empty()) return; + inputImageDescriptorSets.resize(SHGraphicsConstants::NUM_FRAME_BUFFERS); + std::vector bindings{}; for (auto& input : inputReferences) @@ -280,8 +292,8 @@ namespace SHADE } } - //// maybe do this in handle resize? - //UpdateWriteDescriptors(); + // maybe do this in handle resize? + UpdateWriteDescriptors(); } void SHSubpass::UpdateWriteDescriptors(void) noexcept @@ -296,7 +308,7 @@ namespace SHADE // For every frame's descriptor set - for (auto& group : inputImageDescriptors) + for (auto& group : inputImageDescriptorSets) { if (group) group.Free(); diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h index c28ff919..69b8fd56 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHSubpass.h @@ -55,8 +55,11 @@ namespace SHADE //! For getting attachment reference indices using handles std::unordered_map const* resourceAttachmentMapping; - //! Descriptor set group to hold the images for input - std::vector> inputImageDescriptors; + //! Descriptor set group to hold the images for input. We have 3 here just in case + //! one of the images is a swapchain image. Practically speaking its not likely not + //! swapchain images will end up being images used in descriptor sets, but this is + //! to have the support for it. The cost is not much. + std::vector> inputImageDescriptorSets; //! Descriptor set layout for allocating descriptor set for inputs Handle inputDescriptorLayout; @@ -104,6 +107,7 @@ namespace SHADE // Runtime functions void Execute(Handle& commandBuffer, Handle descPool, uint32_t frameIndex) noexcept; void HandleResize (void) noexcept; + void BindDescriptorInputDescriptorSets (Handle cmdBuffer, uint32_t frameIndex) const noexcept; void Init(SHResourceHub& resourceManager) noexcept;