diff --git a/config/Sources.cmake b/config/Sources.cmake index 85a87f5dfc97e3f1bbb345ad3a5ff64ffa587937..45dc8bc8248e19868234f9fa7963c5098838c22c 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -17,6 +17,7 @@ set(vkcv_sources ${vkcv_source}/vkcv/File.cpp ${vkcv_include}/vkcv/PassConfig.hpp + ${vkcv_source}/vkcv/PassConfig.cpp ${vkcv_source}/vkcv/PassManager.hpp ${vkcv_source}/vkcv/PassManager.cpp diff --git a/include/vkcv/GraphicsPipelineConfig.hpp b/include/vkcv/GraphicsPipelineConfig.hpp index e425773508c0b59fc75594c7d4f6bd220f57bae0..91e9fa75cb553ed2b98edfb363192d071ec1bd09 100644 --- a/include/vkcv/GraphicsPipelineConfig.hpp +++ b/include/vkcv/GraphicsPipelineConfig.hpp @@ -71,7 +71,6 @@ namespace vkcv { PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList; BlendMode m_blendMode = BlendMode::None; bool m_EnableDepthClamping = false; - Multisampling m_Multisampling = Multisampling::None; CullMode m_Culling = CullMode::None; DepthTest m_DepthTest = DepthTest::LessEqual; bool m_DepthWrite = true; @@ -131,11 +130,6 @@ namespace vkcv { void setDepthClampingEnabled(bool depthClamping); - [[nodiscard]] - Multisampling getMultisampling() const; - - void setMultisampling(Multisampling multisampling); - [[nodiscard]] CullMode getCulling() const; diff --git a/include/vkcv/PassConfig.hpp b/include/vkcv/PassConfig.hpp index 26c4f8156a4e7d7d7f2576435c474727699a112f..7f06ab141bf5893178341f0a80e3d4aa35f9b8a3 100644 --- a/include/vkcv/PassConfig.hpp +++ b/include/vkcv/PassConfig.hpp @@ -12,25 +12,6 @@ namespace vkcv { - - /** - * @brief Enum class to specify kinds of attachment layouts. - */ - enum class AttachmentLayout { - UNDEFINED, - GENERAL, - - COLOR_ATTACHMENT, - SHADER_READ_ONLY, - - DEPTH_STENCIL_ATTACHMENT, - DEPTH_STENCIL_READ_ONLY, - - TRANSFER_SRC, - TRANSFER_DST, - - PRESENTATION - }; /** * @brief Enum class to specify types of attachment operations. @@ -45,10 +26,42 @@ namespace vkcv /** * @brief Structure to store details about an attachment of a pass. */ - struct AttachmentDescription { - AttachmentOperation store_operation; - AttachmentOperation load_operation; - vk::Format format; + class AttachmentDescription { + private: + vk::Format m_format; + + AttachmentOperation m_load_op; + AttachmentOperation m_store_op; + + vk::ClearValue m_clear_value; + public: + AttachmentDescription(vk::Format format, + AttachmentOperation load, + AttachmentOperation store); + + AttachmentDescription(vk::Format format, + AttachmentOperation load, + AttachmentOperation store, + const vk::ClearValue &clear); + + AttachmentDescription(const AttachmentDescription &other) = default; + AttachmentDescription(AttachmentDescription &&other) = default; + + ~AttachmentDescription() = default; + + AttachmentDescription& operator=(const AttachmentDescription &other) = default; + AttachmentDescription& operator=(AttachmentDescription &&other) = default; + + vk::Format getFormat() const; + + AttachmentOperation getLoadOperation() const; + + AttachmentOperation getStoreOperation() const; + + void setClearValue(const vk::ClearValue &clear); + + const vk::ClearValue& getClearValue() const; + }; /** diff --git a/projects/bindless_textures/src/main.cpp b/projects/bindless_textures/src/main.cpp index bec0ca45bb7e0dac1b10c30592751f4572b42b62..f196db2e2812c6d46f2853f1e686b4238befce24 100644 --- a/projects/bindless_textures/src/main.cpp +++ b/projects/bindless_textures/src/main.cpp @@ -101,15 +101,15 @@ int main(int argc, const char** argv) { // an example attachment for passes that output to the window const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain()) + core.getSwapchainFormat(window.getSwapchain()), + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE ); const vkcv::AttachmentDescription depth_attachment( - vkcv::AttachmentOperation::STORE, + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ); vkcv::PassConfig firstMeshPassDefinition({ present_color_attachment, depth_attachment }, vkcv::Multisampling::None); diff --git a/projects/fire_works/src/main.cpp b/projects/fire_works/src/main.cpp index 9f086bdf5b335e08373c20f9e9c6da80a54882a6..500f5f5e45596ca136c717f05a9a052f124aadaa 100644 --- a/projects/fire_works/src/main.cpp +++ b/projects/fire_works/src/main.cpp @@ -590,10 +590,10 @@ int main(int argc, const char **argv) { vkcv::PassHandle renderPass = core.createPass(vkcv::PassConfig( { vkcv::AttachmentDescription( - vkcv::AttachmentOperation::STORE, + colorFormat, vkcv::AttachmentOperation::CLEAR, - colorFormat - ) + vkcv::AttachmentOperation::STORE + ) }, vkcv::Multisampling::None )); diff --git a/projects/first_mesh/src/main.cpp b/projects/first_mesh/src/main.cpp index c68238d42d7300945de2e03118a15b8958e792a9..356fd9f11eaafb093f9432dd9536896e01793461 100644 --- a/projects/first_mesh/src/main.cpp +++ b/projects/first_mesh/src/main.cpp @@ -52,15 +52,15 @@ int main(int argc, const char** argv) { // an example attachment for passes that output to the window const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain()) + core.getSwapchainFormat(window.getSwapchain()), + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE ); const vkcv::AttachmentDescription depth_attachment( - vkcv::AttachmentOperation::STORE, + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ); vkcv::PassConfig firstMeshPassDefinition( diff --git a/projects/first_scene/src/main.cpp b/projects/first_scene/src/main.cpp index dfa58d88d06872007a5fdc0978ba18231942a23b..bd3b2ac74fdac27abc553987d307ae3100178b07 100644 --- a/projects/first_scene/src/main.cpp +++ b/projects/first_scene/src/main.cpp @@ -49,15 +49,15 @@ int main(int argc, const char** argv) { )); const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain()) + core.getSwapchainFormat(window.getSwapchain()), + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE ); const vkcv::AttachmentDescription depth_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vk::Format::eD32Sfloat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE ); vkcv::PassConfig scenePassDefinition( diff --git a/projects/first_triangle/src/main.cpp b/projects/first_triangle/src/main.cpp index 4723d17e7c0c7d3e0d2ffeaa5d5614d29bdfaa51..edf8fa8fa0f041854db452e7b335d34f7dbc5cf0 100644 --- a/projects/first_triangle/src/main.cpp +++ b/projects/first_triangle/src/main.cpp @@ -30,9 +30,10 @@ int main(int argc, const char** argv) { // an example attachment for passes that output to the window const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain())); + core.getSwapchainFormat(window.getSwapchain()), + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); vkcv::PassConfig trianglePassDefinition({ present_color_attachment }, vkcv::Multisampling::None); vkcv::PassHandle trianglePass = core.createPass(trianglePassDefinition); diff --git a/projects/head_demo/src/main.cpp b/projects/head_demo/src/main.cpp index fb3170d45c7b02bade1b83558cf5494386b2c854..9c92128f46d1f7c2472e2a082bac03219cdd5615 100644 --- a/projects/head_demo/src/main.cpp +++ b/projects/head_demo/src/main.cpp @@ -44,27 +44,27 @@ int main(int argc, const char** argv) { vk::Format colorFormat = vk::Format::eR16G16B16A16Sfloat; const vkcv::AttachmentDescription color_attachment0( - vkcv::AttachmentOperation::STORE, + colorFormat, vkcv::AttachmentOperation::CLEAR, - colorFormat + vkcv::AttachmentOperation::STORE ); const vkcv::AttachmentDescription depth_attachment0( - vkcv::AttachmentOperation::STORE, + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ); const vkcv::AttachmentDescription color_attachment1( - vkcv::AttachmentOperation::STORE, + colorFormat, vkcv::AttachmentOperation::LOAD, - colorFormat + vkcv::AttachmentOperation::STORE ); const vkcv::AttachmentDescription depth_attachment1( - vkcv::AttachmentOperation::STORE, + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::LOAD, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ); vkcv::PassConfig linePassDefinition( diff --git a/projects/indirect_dispatch/src/AppSetup.cpp b/projects/indirect_dispatch/src/AppSetup.cpp index 8a5977ceeea8e08e74a96ab2570fad694bf86614..4f00858608c2976801bf0ffa8338bbff4896f547 100644 --- a/projects/indirect_dispatch/src/AppSetup.cpp +++ b/projects/indirect_dispatch/src/AppSetup.cpp @@ -160,14 +160,16 @@ bool loadMeshPass(vkcv::Core& core, GraphicPassHandles* outHandles) { assert(outHandles); vkcv::AttachmentDescription colorAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::DONT_CARE, - AppConfig::colorBufferFormat); + AppConfig::colorBufferFormat, + vkcv::AttachmentOperation::DONT_CARE, + vkcv::AttachmentOperation::STORE + ); vkcv::AttachmentDescription depthAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - AppConfig::depthBufferFormat); + AppConfig::depthBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE + ); return loadGraphicPass( core, @@ -186,14 +188,16 @@ bool loadSkyPass(vkcv::Core& core, GraphicPassHandles* outHandles) { assert(outHandles); vkcv::AttachmentDescription colorAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - AppConfig::colorBufferFormat); + AppConfig::colorBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE + ); vkcv::AttachmentDescription depthAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - AppConfig::depthBufferFormat); + AppConfig::depthBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE + ); return loadGraphicPass( core, @@ -211,14 +215,16 @@ bool loadPrePass(vkcv::Core& core, GraphicPassHandles* outHandles) { assert(outHandles); vkcv::AttachmentDescription motionAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - AppConfig::motionBufferFormat); + AppConfig::motionBufferFormat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); vkcv::AttachmentDescription depthAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - AppConfig::depthBufferFormat); + AppConfig::depthBufferFormat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); return loadGraphicPass( core, @@ -236,14 +242,16 @@ bool loadSkyPrePass(vkcv::Core& core, GraphicPassHandles* outHandles) { assert(outHandles); vkcv::AttachmentDescription motionAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - AppConfig::motionBufferFormat); + AppConfig::motionBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE + ); vkcv::AttachmentDescription depthAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - AppConfig::depthBufferFormat); + AppConfig::depthBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE + ); return loadGraphicPass( core, diff --git a/projects/indirect_draw/src/main.cpp b/projects/indirect_draw/src/main.cpp index ce4bada126105e092bd93162b7c4fdc82b57de8b..f3fa7f8d2712eb5f465c6899983298fa63cfd564 100644 --- a/projects/indirect_draw/src/main.cpp +++ b/projects/indirect_draw/src/main.cpp @@ -328,15 +328,16 @@ int main(int argc, const char** argv) { return EXIT_FAILURE; } - const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain()) + const vkcv::AttachmentDescription present_color_attachment ( + core.getSwapchainFormat(window.getSwapchain()), + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE ); - const vkcv::AttachmentDescription depth_attachment( - vkcv::AttachmentOperation::STORE, + + const vkcv::AttachmentDescription depth_attachment ( + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ); vkcv::PassConfig passDefinition({ present_color_attachment, depth_attachment }, vkcv::Multisampling::None); diff --git a/projects/mesh_shader/src/main.cpp b/projects/mesh_shader/src/main.cpp index 34a9de9e4678468d9a1ba443fdba1541a7f2a152..77df9f4e04d2a32487faa1b7f61be80a31be516e 100644 --- a/projects/mesh_shader/src/main.cpp +++ b/projects/mesh_shader/src/main.cpp @@ -164,14 +164,15 @@ int main(int argc, const char** argv) { // attachments const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain())); + core.getSwapchainFormat(window.getSwapchain()), + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); const vkcv::AttachmentDescription depth_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vk::Format::eD32Sfloat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE ); vkcv::PassConfig bunnyPassDefinition( diff --git a/projects/particle_simulation/src/main.cpp b/projects/particle_simulation/src/main.cpp index c87afc9892fd13016cb81865eee6819e193db171..a1e40221efe9a4bdd076ed9bef0a30d129c43d87 100644 --- a/projects/particle_simulation/src/main.cpp +++ b/projects/particle_simulation/src/main.cpp @@ -35,9 +35,10 @@ int main(int argc, const char **argv) { vk::Format colorFormat = vk::Format::eR16G16B16A16Sfloat; // an example attachment for passes that output to the window const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - colorFormat); + colorFormat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); vkcv::PassConfig particlePassDefinition({present_color_attachment}, vkcv::Multisampling::None); diff --git a/projects/saf_r/src/main.cpp b/projects/saf_r/src/main.cpp index dda23973809f3523b3b7337b0f5a03c3f575019a..19ecf20d44416cba37e6f37d2d4298fb45602432 100644 --- a/projects/saf_r/src/main.cpp +++ b/projects/saf_r/src/main.cpp @@ -163,9 +163,10 @@ int main(int argc, const char** argv) { // an example attachment for passes that output to the window const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain())); + core.getSwapchainFormat(window.getSwapchain()), + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); vkcv::PassConfig safrPassDefinition({ present_color_attachment }, vkcv::Multisampling::None); vkcv::PassHandle safrPass = core.createPass(safrPassDefinition); diff --git a/projects/sph/src/main.cpp b/projects/sph/src/main.cpp index a5bf4bf0cff8d37d9acbeaae80584aad68c93102..f6ed05058f3bae8609aefeffbbc5b16177a433f3 100644 --- a/projects/sph/src/main.cpp +++ b/projects/sph/src/main.cpp @@ -33,10 +33,10 @@ int main(int argc, const char **argv) { vk::Format colorFormat = vk::Format::eR16G16B16A16Sfloat; // an example attachment for passes that output to the window const vkcv::AttachmentDescription present_color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - colorFormat); - + colorFormat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); vkcv::PassConfig particlePassDefinition({present_color_attachment}, vkcv::Multisampling::None); vkcv::PassHandle particlePass = core.createPass(particlePassDefinition); diff --git a/projects/voxelization/src/ShadowMapping.cpp b/projects/voxelization/src/ShadowMapping.cpp index 6aa315775997eef82f72ae454bbed2012d289333..990007cb6b28b40c716aaf907ed0accc87312c00 100644 --- a/projects/voxelization/src/ShadowMapping.cpp +++ b/projects/voxelization/src/ShadowMapping.cpp @@ -160,7 +160,11 @@ ShadowMapping::ShadowMapping(vkcv::Core* corePtr, const vkcv::VertexLayout& vert // pass const std::vector<vkcv::AttachmentDescription> shadowAttachments = { - vkcv::AttachmentDescription(vkcv::AttachmentOperation::STORE, vkcv::AttachmentOperation::CLEAR, shadowMapDepthFormat) + vkcv::AttachmentDescription( + shadowMapDepthFormat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ) }; vkcv::PassConfig shadowPassConfig(shadowAttachments, msaa); m_shadowMapPass = corePtr->createPass(shadowPassConfig); @@ -174,7 +178,6 @@ ShadowMapping::ShadowMapping(vkcv::Core* corePtr, const vkcv::VertexLayout& vert ); shadowPipeConfig.setResolution(shadowMapResolution, shadowMapResolution); - shadowPipeConfig.setMultisampling(msaa); shadowPipeConfig.setDepthClampingEnabled(true); shadowPipeConfig.setCulling(vkcv::CullMode::Front); m_shadowMapPipe = corePtr->createGraphicsPipeline(shadowPipeConfig); diff --git a/projects/voxelization/src/Voxelization.cpp b/projects/voxelization/src/Voxelization.cpp index dd2cda78f4f74993a3cf855ed3c89362f90d4ce3..63316208057c246f42c712f7d09aea72f0631e8e 100644 --- a/projects/voxelization/src/Voxelization.cpp +++ b/projects/voxelization/src/Voxelization.cpp @@ -93,11 +93,11 @@ Voxelization::Voxelization( const vkcv::ShaderProgram voxelizationShader = loadVoxelizationShader(); const vkcv::PassConfig voxelizationPassConfig {{ - { + vkcv::AttachmentDescription( + voxelizationDummyFormat, vkcv::AttachmentOperation::DONT_CARE, - vkcv::AttachmentOperation::DONT_CARE, - voxelizationDummyFormat - } + vkcv::AttachmentOperation::DONT_CARE + ) }, vkcv::Multisampling::None }; m_voxelizationPass = m_corePtr->createPass(voxelizationPassConfig); @@ -137,16 +137,16 @@ Voxelization::Voxelization( m_visualisationDescriptorSetLayout = m_corePtr->createDescriptorSetLayout(voxelVisualisationShader.getReflectedDescriptors().at(0)); m_visualisationDescriptorSet = m_corePtr->createDescriptorSet(m_visualisationDescriptorSetLayout); - const vkcv::AttachmentDescription voxelVisualisationColorAttachments( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - dependencies.colorBufferFormat + const vkcv::AttachmentDescription voxelVisualisationColorAttachments ( + dependencies.colorBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE ); - const vkcv::AttachmentDescription voxelVisualisationDepthAttachments( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - dependencies.depthBufferFormat + const vkcv::AttachmentDescription voxelVisualisationDepthAttachments ( + dependencies.depthBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE ); vkcv::PassConfig voxelVisualisationPassDefinition{ @@ -164,7 +164,6 @@ Voxelization::Voxelization( ); // points are extended to cubes in the geometry shader voxelVisualisationPipeConfig.setPrimitiveTopology(vkcv::PrimitiveTopology::PointList); - voxelVisualisationPipeConfig.setMultisampling(msaa); m_visualisationPipe = m_corePtr->createGraphicsPipeline(voxelVisualisationPipeConfig); std::vector<uint16_t> voxelIndexData; diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp index 449993d1ab7a1ac4142c7ebcf9b1ad5ecacb0009..e2e1f0ee6115cc7f6e7d792ebf185acf9035ad8c 100644 --- a/projects/voxelization/src/main.cpp +++ b/projects/voxelization/src/main.cpp @@ -181,17 +181,17 @@ int main(int argc, const char** argv) { } const vk::Format colorBufferFormat = vk::Format::eB10G11R11UfloatPack32; - const vkcv::AttachmentDescription color_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - colorBufferFormat + const vkcv::AttachmentDescription color_attachment ( + colorBufferFormat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE ); const vk::Format depthBufferFormat = vk::Format::eD32Sfloat; - const vkcv::AttachmentDescription depth_attachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - depthBufferFormat + const vkcv::AttachmentDescription depth_attachment ( + depthBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE ); // forward shading config @@ -241,9 +241,10 @@ int main(int argc, const char** argv) { const vkcv::VertexLayout prepassVertexLayout { prepassVertexBindings }; const vkcv::AttachmentDescription prepassAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::CLEAR, - depthBufferFormat); + depthBufferFormat, + vkcv::AttachmentOperation::CLEAR, + vkcv::AttachmentOperation::STORE + ); vkcv::PassConfig prepassPassDefinition({ prepassAttachment }, msaa); vkcv::PassHandle prepassPass = core.createPass(prepassPassDefinition); @@ -343,7 +344,6 @@ int main(int argc, const char** argv) { ); prepassPipelineConfig.setCulling(vkcv::CullMode::Back); - prepassPipelineConfig.setMultisampling(msaa); prepassPipelineConfig.setDepthTest(vkcv::DepthTest::LessEqual); prepassPipelineConfig.setWritingAlphaToCoverage(true); @@ -358,7 +358,6 @@ int main(int argc, const char** argv) { ); forwardPipelineConfig.setCulling(vkcv::CullMode::Back); - forwardPipelineConfig.setMultisampling(msaa); forwardPipelineConfig.setDepthTest(vkcv::DepthTest::Equal); forwardPipelineConfig.setWritingDepth(false); @@ -378,15 +377,17 @@ int main(int argc, const char** argv) { skySettings.color = glm::vec3(0.15, 0.65, 1); skySettings.strength = 5; - const vkcv::AttachmentDescription skyColorAttachment( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - colorBufferFormat); + const vkcv::AttachmentDescription skyColorAttachment ( + colorBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE + ); - const vkcv::AttachmentDescription skyDepthAttachments( - vkcv::AttachmentOperation::STORE, - vkcv::AttachmentOperation::LOAD, - depthBufferFormat); + const vkcv::AttachmentDescription skyDepthAttachments ( + depthBufferFormat, + vkcv::AttachmentOperation::LOAD, + vkcv::AttachmentOperation::STORE + ); vkcv::PassConfig skyPassConfig({ skyColorAttachment, skyDepthAttachments }, msaa); vkcv::PassHandle skyPass = core.createPass(skyPassConfig); @@ -408,7 +409,6 @@ int main(int argc, const char** argv) { {} ); - skyPipeConfig.setMultisampling(msaa); skyPipeConfig.setWritingDepth(false); vkcv::GraphicsPipelineHandle skyPipe = core.createGraphicsPipeline(skyPipeConfig); diff --git a/projects/wobble_bobble/src/main.cpp b/projects/wobble_bobble/src/main.cpp index 5e31155d24bb9d193d73e1fafcd704822c6f6ea6..23ab97c5e9038303144632e9d79cf0b94abf0a7d 100644 --- a/projects/wobble_bobble/src/main.cpp +++ b/projects/wobble_bobble/src/main.cpp @@ -456,40 +456,40 @@ int main(int argc, const char **argv) { vkcv::PassConfig passConfigGrid {{ vkcv::AttachmentDescription( - vkcv::AttachmentOperation::STORE, + core.getSwapchainFormat(window.getSwapchain()), vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain()) + vkcv::AttachmentOperation::STORE ), vkcv::AttachmentDescription( - vkcv::AttachmentOperation::STORE, + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ) }, vkcv::Multisampling::None }; vkcv::PassConfig passConfigParticles {{ vkcv::AttachmentDescription( - vkcv::AttachmentOperation::STORE, + core.getSwapchainFormat(window.getSwapchain()), vkcv::AttachmentOperation::CLEAR, - core.getSwapchainFormat(window.getSwapchain()) + vkcv::AttachmentOperation::STORE ), vkcv::AttachmentDescription( - vkcv::AttachmentOperation::STORE, + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::CLEAR, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ) }, vkcv::Multisampling::None }; vkcv::PassConfig passConfigLines {{ vkcv::AttachmentDescription( - vkcv::AttachmentOperation::STORE, + core.getSwapchainFormat(window.getSwapchain()), vkcv::AttachmentOperation::LOAD, - core.getSwapchainFormat(window.getSwapchain()) + vkcv::AttachmentOperation::STORE ), vkcv::AttachmentDescription( - vkcv::AttachmentOperation::STORE, + vk::Format::eD32Sfloat, vkcv::AttachmentOperation::LOAD, - vk::Format::eD32Sfloat + vkcv::AttachmentOperation::STORE ) }, vkcv::Multisampling::None }; diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index 176e07ae073135b0311226f825cc639cc34e9610..9cbba1973741078c3ee7571351df7c8bf9b63172 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -355,19 +355,8 @@ namespace vkcv std::vector<vk::ClearValue> createAttachmentClearValues(const std::vector<AttachmentDescription>& attachments) { std::vector<vk::ClearValue> clearValues; for (const auto& attachment : attachments) { - if (attachment.load_operation == AttachmentOperation::CLEAR) { - float clear = 0.0f; - - if (isDepthFormat(attachment.format)) { - clear = 1.0f; - } - - clearValues.emplace_back(std::array<float, 4>{ - clear, - clear, - clear, - 0.f - }); + if (attachment.getLoadOperation() == AttachmentOperation::CLEAR) { + clearValues.push_back(attachment.getClearValue()); } } return clearValues; diff --git a/src/vkcv/GraphicsPipelineConfig.cpp b/src/vkcv/GraphicsPipelineConfig.cpp index 5dea0238dc3f469b56166dc81b10aebe0d5b4cc7..37e86240e782460fe317c91e71c1ddcb5880fff0 100644 --- a/src/vkcv/GraphicsPipelineConfig.cpp +++ b/src/vkcv/GraphicsPipelineConfig.cpp @@ -78,14 +78,6 @@ namespace vkcv { m_EnableDepthClamping = depthClamping; } - Multisampling GraphicsPipelineConfig::getMultisampling() const { - return m_Multisampling; - } - - void GraphicsPipelineConfig::setMultisampling(Multisampling multisampling) { - m_Multisampling = multisampling; - } - CullMode GraphicsPipelineConfig::getCulling() const { return m_Culling; } diff --git a/src/vkcv/GraphicsPipelineManager.cpp b/src/vkcv/GraphicsPipelineManager.cpp index 95a33c08c577d270476ac5d5611a436b1f6dd625..57eedcaca4d59cc2d27c25ae8a212f7a436d5f2d 100644 --- a/src/vkcv/GraphicsPipelineManager.cpp +++ b/src/vkcv/GraphicsPipelineManager.cpp @@ -326,10 +326,11 @@ namespace vkcv { * @param config set MSAA Sample Count Flag * @return Pipeline Multisample State Create Info Struct */ - vk::PipelineMultisampleStateCreateInfo createPipelineMultisampleStateCreateInfo(const GraphicsPipelineConfig &config) { + vk::PipelineMultisampleStateCreateInfo createPipelineMultisampleStateCreateInfo(const GraphicsPipelineConfig &config, + const PassConfig &passConfig) { vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo( {}, - msaaToSampleCountFlagBits(config.getMultisampling()), + msaaToSampleCountFlagBits(passConfig.msaa), false, 0.f, nullptr, @@ -598,6 +599,8 @@ namespace vkcv { return {}; } } + + const PassConfig& passConfig = passManager.getPassConfig(config.getPass()); // vertex input state // Fill up VertexInputBindingDescription and VertexInputAttributeDescription Containers @@ -633,7 +636,7 @@ namespace vkcv { // multisample state vk::PipelineMultisampleStateCreateInfo pipelineMultisampleStateCreateInfo = - createPipelineMultisampleStateCreateInfo(config); + createPipelineMultisampleStateCreateInfo(config, passConfig); // color blend state vk::PipelineColorBlendStateCreateInfo pipelineColorBlendStateCreateInfo = @@ -666,10 +669,10 @@ namespace vkcv { createPipelineDepthStencilStateCreateInfo(config); const vk::PipelineDepthStencilStateCreateInfo* p_depthStencilCreateInfo = nullptr; - const PassConfig& passConfig = passManager.getPassConfig(config.getPass()); for (const auto& attachment : passConfig.attachments) { - if (isDepthFormat(attachment.format)) { + if ((isDepthFormat(attachment.getFormat())) || + (isStencilFormat(attachment.getFormat()))) { p_depthStencilCreateInfo = &depthStencilCreateInfo; break; } diff --git a/src/vkcv/PassConfig.cpp b/src/vkcv/PassConfig.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bfb93c8783fd12ee03629b8b4ec523482fc81227 --- /dev/null +++ b/src/vkcv/PassConfig.cpp @@ -0,0 +1,59 @@ + +#include "vkcv/PassConfig.hpp" +#include "vkcv/Image.hpp" + +namespace vkcv +{ + + AttachmentDescription::AttachmentDescription(vk::Format format, + AttachmentOperation load, + AttachmentOperation store) + : m_format(format), + m_load_op(load), + m_store_op(store), + m_clear_value() + { + if (isDepthFormat(format)) { + setClearValue(vk::ClearValue( + vk::ClearDepthStencilValue(1.0f, 0) + )); + } else { + setClearValue(vk::ClearValue( + vk::ClearColorValue(std::array<float, 4>{ + 0.0f, 0.0f, 0.0f, 0.0f + }) + )); + } + } + + AttachmentDescription::AttachmentDescription(vk::Format format, + AttachmentOperation load, + AttachmentOperation store, + const vk::ClearValue &clear) + : m_format(format), + m_load_op(load), + m_store_op(store), + m_clear_value(clear) + {} + + vk::Format AttachmentDescription::getFormat() const { + return m_format; + } + + AttachmentOperation AttachmentDescription::getLoadOperation() const { + return m_load_op; + } + + AttachmentOperation AttachmentDescription::getStoreOperation() const { + return m_store_op; + } + + void AttachmentDescription::setClearValue(const vk::ClearValue &clear) { + m_clear_value = clear; + } + + const vk::ClearValue &AttachmentDescription::getClearValue() const { + return m_clear_value; + } + +} diff --git a/src/vkcv/PassManager.cpp b/src/vkcv/PassManager.cpp index 740ab333e797e968b7a307a552ec4a4117f3aba9..71fa8006285f34661c5be419b7db92ca4c6b2db0 100644 --- a/src/vkcv/PassManager.cpp +++ b/src/vkcv/PassManager.cpp @@ -59,63 +59,91 @@ namespace vkcv // individual references to color attachments (of a subpass) std::vector<vk::AttachmentReference> colorAttachmentReferences{}; // individual reference to depth attachment (of a subpass) - vk::AttachmentReference depthAttachmentReference{}; - vk::AttachmentReference *pDepthAttachment = nullptr; //stays nullptr if no depth attachment used + vk::AttachmentReference depthStencilAttachmentRef; + + // stays nullptr if no depth attachment used + vk::AttachmentReference *pDepthStencil = nullptr; + + const auto &featureManager = getCore().getContext().getFeatureManager(); + + const bool separateDepthStencil = ( + featureManager.checkFeatures<vk::PhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR>( + vk::StructureType::ePhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR, + [](const vk::PhysicalDeviceSeparateDepthStencilLayoutsFeaturesKHR& features) { + return features.separateDepthStencilLayouts; + } + ) + ); - for (uint32_t i = 0; i < config.attachments.size(); i++) - { - // TODO: Renderpass struct should hold proper format information - vk::Format format = config.attachments[i].format; + for (uint32_t i = 0; i < config.attachments.size(); i++) { + vk::Format format = config.attachments[i].getFormat(); vk::ImageLayout layout; - - if (isDepthFormat(config.attachments[i].format)) - { - layout = vk::ImageLayout::eDepthStencilAttachmentOptimal; - depthAttachmentReference.attachment = i; - depthAttachmentReference.layout = layout; - pDepthAttachment = &depthAttachmentReference; - } - else - { - layout = vk::ImageLayout::eColorAttachmentOptimal; - vk::AttachmentReference attachmentRef(i, layout); + + bool depthFormat = isDepthFormat(config.attachments[i].getFormat()); + bool stencilFormat = isStencilFormat(config.attachments[i].getFormat()); + + if ((separateDepthStencil) && (depthFormat) && (!stencilFormat)) { + layout = vk::ImageLayout::eDepthAttachmentOptimal; + } else + if ((separateDepthStencil) && (!depthFormat) && (stencilFormat)) { + layout = vk::ImageLayout::eStencilAttachmentOptimal; + } else + if ((depthFormat) || (stencilFormat)) { + layout = vk::ImageLayout::eDepthStencilAttachmentOptimal; + } else { + layout = vk::ImageLayout::eColorAttachmentOptimal; + } + + if ((depthFormat) || (stencilFormat)) { + depthStencilAttachmentRef = vk::AttachmentReference(i, layout); + pDepthStencil = &depthStencilAttachmentRef; + } else { + vk::AttachmentReference attachmentRef (i, layout); colorAttachmentReferences.push_back(attachmentRef); } - vk::AttachmentDescription attachmentDesc( - {}, - format, - msaaToSampleCountFlagBits(config.msaa), - getVKLoadOpFromAttachOp(config.attachments[i].load_operation), - getVkStoreOpFromAttachOp(config.attachments[i].store_operation), - vk::AttachmentLoadOp::eDontCare, - vk::AttachmentStoreOp::eDontCare, - layout, - layout); + vk::AttachmentDescription attachmentDesc ( + {}, + format, + msaaToSampleCountFlagBits(config.msaa), + getVKLoadOpFromAttachOp(config.attachments[i].getLoadOperation()), + getVkStoreOpFromAttachOp(config.attachments[i].getStoreOperation()), + vk::AttachmentLoadOp::eDontCare, + vk::AttachmentStoreOp::eDontCare, + layout, + layout + ); + + if (stencilFormat) { + attachmentDesc.setStencilLoadOp(attachmentDesc.loadOp); + attachmentDesc.setStencilStoreOp(attachmentDesc.storeOp); + } attachmentDescriptions.push_back(attachmentDesc); } - const vk::SubpassDescription subpassDescription( - {}, - vk::PipelineBindPoint::eGraphics, - 0, - {}, - static_cast<uint32_t>(colorAttachmentReferences.size()), - colorAttachmentReferences.data(), - {}, - pDepthAttachment, - 0, - {}); + const vk::SubpassDescription subpassDescription ( + {}, + vk::PipelineBindPoint::eGraphics, + 0, + {}, + static_cast<uint32_t>(colorAttachmentReferences.size()), + colorAttachmentReferences.data(), + {}, + pDepthStencil, + 0, + {} + ); - const vk::RenderPassCreateInfo passInfo( - {}, - static_cast<uint32_t>(attachmentDescriptions.size()), - attachmentDescriptions.data(), - 1, - &subpassDescription, - 0, - {}); + const vk::RenderPassCreateInfo passInfo ( + {}, + static_cast<uint32_t>(attachmentDescriptions.size()), + attachmentDescriptions.data(), + 1, + &subpassDescription, + 0, + {} + ); vk::RenderPass renderPass = getCore().getContext().getDevice().createRenderPass(passInfo);