diff --git a/config/Sources.cmake b/config/Sources.cmake index 98dc2bc3d1bfb342d282b63eb28c242e149e1ac2..ad7b1bbf84ea515af449b81c505de24d8cf0ecf9 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -17,7 +17,6 @@ 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/DescriptorConfig.hpp b/include/vkcv/DescriptorConfig.hpp index 1d116e69f0887128d32bfb07824464f6e2da89bb..bc2435f6246f616c907e206e4a3de62aafaebebc 100644 --- a/include/vkcv/DescriptorConfig.hpp +++ b/include/vkcv/DescriptorConfig.hpp @@ -59,31 +59,37 @@ namespace vkcv } } - struct DescriptorBinding - { - uint32_t bindingID; - DescriptorType descriptorType; - uint32_t descriptorCount; - ShaderStages shaderStages; - bool variableCount; + /** + * @brief Structure to store details from a descriptor binding. + */ + struct DescriptorBinding { + uint32_t bindingID; + DescriptorType descriptorType; + uint32_t descriptorCount; + ShaderStages shaderStages; + bool variableCount; bool operator ==(const DescriptorBinding &other) const; }; typedef std::unordered_map<uint32_t, DescriptorBinding> DescriptorBindings; - - struct DescriptorSetLayout - { + + /** + * @brief Structure to store details about a descriptor set layout. + */ + struct DescriptorSetLayout { vk::DescriptorSetLayout vulkanHandle; - DescriptorBindings descriptorBindings; - size_t layoutUsageCount; + DescriptorBindings descriptorBindings; + size_t layoutUsageCount; }; - - struct DescriptorSet - { - vk::DescriptorSet vulkanHandle; - DescriptorSetLayoutHandle setLayoutHandle; - size_t poolIndex; + + /** + * @brief Structure to store details about a descriptor set. + */ + struct DescriptorSet { + vk::DescriptorSet vulkanHandle; + DescriptorSetLayoutHandle setLayoutHandle; + size_t poolIndex; }; } diff --git a/include/vkcv/DrawcallRecording.hpp b/include/vkcv/DrawcallRecording.hpp index 8cdaaa9b9a4779d10554a393195c68f142cb894e..750685f0da15225a811643334bee933fbcd63b40 100644 --- a/include/vkcv/DrawcallRecording.hpp +++ b/include/vkcv/DrawcallRecording.hpp @@ -15,12 +15,12 @@ namespace vkcv { + /** + * @brief Structure to store details about a vertex buffer binding. + */ struct VertexBufferBinding { - inline VertexBufferBinding(vk::DeviceSize offset, vk::Buffer buffer) noexcept - : offset(offset), buffer(buffer) {} - - vk::DeviceSize offset; - vk::Buffer buffer; + vk::DeviceSize offset; + vk::Buffer buffer; }; /** @@ -34,8 +34,10 @@ namespace vkcv { struct DescriptorSetUsage { inline DescriptorSetUsage(uint32_t setLocation, DescriptorSetHandle descriptorSet, - const std::vector<uint32_t>& dynamicOffsets = {}) noexcept - : setLocation(setLocation), descriptorSet(descriptorSet), dynamicOffsets(dynamicOffsets) {} + const std::vector<uint32_t>& dynamicOffsets = {}) noexcept : + setLocation(setLocation), + descriptorSet(descriptorSet), + dynamicOffsets(dynamicOffsets) {} const uint32_t setLocation; const DescriptorSetHandle descriptorSet; @@ -43,53 +45,50 @@ namespace vkcv { }; struct Mesh { - - inline Mesh(){} - - inline Mesh( - std::vector<VertexBufferBinding> vertexBufferBindings, - vk::Buffer indexBuffer, - size_t indexCount, - IndexBitCount indexBitCount = IndexBitCount::Bit16) noexcept - : - vertexBufferBindings(vertexBufferBindings), - indexBuffer(indexBuffer), + inline Mesh() {} + + inline Mesh(std::vector<VertexBufferBinding> vertexBufferBindings, + vk::Buffer indexBuffer, + size_t indexCount, + IndexBitCount indexBitCount = IndexBitCount::Bit16) noexcept : + vertexBufferBindings(vertexBufferBindings), + indexBuffer(indexBuffer), indexCount(indexCount), indexBitCount(indexBitCount) {} - std::vector<VertexBufferBinding> vertexBufferBindings; - vk::Buffer indexBuffer; - size_t indexCount; - IndexBitCount indexBitCount; + std::vector<VertexBufferBinding> vertexBufferBindings; + vk::Buffer indexBuffer; + size_t indexCount; + IndexBitCount indexBitCount; }; struct DrawcallInfo { - inline DrawcallInfo(const Mesh& mesh, const std::vector<DescriptorSetUsage>& descriptorSets, const uint32_t instanceCount = 1) - : mesh(mesh), descriptorSets(descriptorSets), instanceCount(instanceCount){} - - Mesh mesh; + inline DrawcallInfo(const Mesh& mesh, + const std::vector<DescriptorSetUsage>& descriptorSets, + const uint32_t instanceCount = 1) : + mesh(mesh), + descriptorSets(descriptorSets), + instanceCount(instanceCount){} + + Mesh mesh; std::vector<DescriptorSetUsage> descriptorSets; - uint32_t instanceCount; + uint32_t instanceCount; }; void InitMeshShaderDrawFunctions(vk::Device device); struct MeshShaderDrawcall { - inline MeshShaderDrawcall(const std::vector<DescriptorSetUsage> descriptorSets, uint32_t taskCount) - : descriptorSets(descriptorSets), taskCount(taskCount) {} - std::vector<DescriptorSetUsage> descriptorSets; - uint32_t taskCount; + uint32_t taskCount; }; - void recordMeshShaderDrawcall( - const Core& core, - vk::CommandBuffer cmdBuffer, - vk::PipelineLayout pipelineLayout, - const PushConstants& pushConstantData, - const uint32_t pushConstantOffset, - const MeshShaderDrawcall& drawcall, - const uint32_t firstTask); + void recordMeshShaderDrawcall(const Core& core, + vk::CommandBuffer cmdBuffer, + vk::PipelineLayout pipelineLayout, + const PushConstants& pushConstantData, + uint32_t pushConstantOffset, + const MeshShaderDrawcall& drawcall, + uint32_t firstTask); } diff --git a/include/vkcv/FeatureManager.hpp b/include/vkcv/FeatureManager.hpp index d7d7b992c742506b9672dc4d6b28ba19c3793f54..51e422c949b66fe021ec3a5afd95f50a94e39544 100644 --- a/include/vkcv/FeatureManager.hpp +++ b/include/vkcv/FeatureManager.hpp @@ -15,7 +15,7 @@ namespace vkcv { /** - * Class to manage extension and feature requirements, support and usage. + * @brief Class to manage extension and feature requirements, support and usage. */ class FeatureManager { private: diff --git a/include/vkcv/Features.hpp b/include/vkcv/Features.hpp index 16b6e155a62f52287d35c6c8736ed562328c3537..bb0e88c2b52775f00e5d74804d055fe35ee6bd58 100644 --- a/include/vkcv/Features.hpp +++ b/include/vkcv/Features.hpp @@ -19,7 +19,7 @@ namespace vkcv { typedef std::function<bool(FeatureManager&)> Feature; /** - * Class to manage a list of feature requests at once. + * @brief Class to manage a list of feature requests at once. */ class Features { private: diff --git a/include/vkcv/GraphicsPipelineConfig.hpp b/include/vkcv/GraphicsPipelineConfig.hpp index b5ce9e0a8357916a9fda29c60eb55a9ddb479710..85cabc135ddfa8e6e6762c16c269741e232cff4d 100644 --- a/include/vkcv/GraphicsPipelineConfig.hpp +++ b/include/vkcv/GraphicsPipelineConfig.hpp @@ -15,13 +15,47 @@ namespace vkcv { - enum class PrimitiveTopology{PointList, LineList, TriangleList, PatchList }; - enum class CullMode{ None, Front, Back, Both }; - enum class DepthTest { None, Less, LessEqual, Greater, GreatherEqual, Equal }; + /** + * @brief Enum class to specify types of primitive topology. + */ + enum class PrimitiveTopology { + PointList, + LineList, + TriangleList, + PatchList + }; + + /** + * @brief Enum class to specify modes of culling. + */ + enum class CullMode { + None, + Front, + Back, + Both + }; + + /** + * @brief Enum class to specify depth-test modes. + */ + enum class DepthTest { + None, + Less, + LessEqual, + Greater, + GreatherEqual, + Equal + }; // add more as needed // alternatively we could expose the blend factors directly - enum class BlendMode{ None, Additive }; + /** + * @brief Enum class to specify blending modes. + */ + enum class BlendMode { + None, + Additive + }; /** * @brief Structure to configure a graphics pipeline before its creation. diff --git a/include/vkcv/PassConfig.hpp b/include/vkcv/PassConfig.hpp index 7ddb01a2adb7fdc1067baebda10cafd268733363..ad3e3c0dff150f5ba41859477d4bb5a53c4365f8 100644 --- a/include/vkcv/PassConfig.hpp +++ b/include/vkcv/PassConfig.hpp @@ -13,8 +13,10 @@ namespace vkcv { - enum class AttachmentLayout - { + /** + * @brief Enum class to specify kinds of attachment layouts. + */ + enum class AttachmentLayout { UNDEFINED, GENERAL, @@ -30,31 +32,30 @@ namespace vkcv PRESENTATION }; - enum class AttachmentOperation - { + /** + * @brief Enum class to specify types of attachment operations. + */ + enum class AttachmentOperation { LOAD, CLEAR, STORE, DONT_CARE }; - struct AttachmentDescription - { - AttachmentDescription( - AttachmentOperation store_op, - AttachmentOperation load_op, - vk::Format format) noexcept; - + /** + * @brief Structure to store details about an attachment of a pass. + */ + struct AttachmentDescription { AttachmentOperation store_operation; AttachmentOperation load_operation; - vk::Format format; }; - struct PassConfig - { - explicit PassConfig(std::vector<AttachmentDescription> attachments, Multisampling msaa = Multisampling::None) noexcept; - std::vector<AttachmentDescription> attachments{}; + /** + * @brief Structure to configure a pass for usage. + */ + struct PassConfig { + std::vector<AttachmentDescription> attachments; Multisampling msaa; }; diff --git a/include/vkcv/ShaderProgram.hpp b/include/vkcv/ShaderProgram.hpp index cfcc69f6bafc1ae8fa8dca342b7cdb781504e5cb..c815834a3d7a948df3307769f34abe94cbd2ff22 100644 --- a/include/vkcv/ShaderProgram.hpp +++ b/include/vkcv/ShaderProgram.hpp @@ -97,7 +97,7 @@ namespace vkcv { std::unordered_map<ShaderStage, std::vector<uint32_t> > m_Shaders; // contains all vertex input attachments used in the vertex buffer - std::vector<VertexAttachment> m_VertexAttachments; + VertexAttachments m_VertexAttachments; std::unordered_map<uint32_t, DescriptorBindings> m_DescriptorSets; size_t m_pushConstantsSize = 0; diff --git a/include/vkcv/VertexLayout.hpp b/include/vkcv/VertexLayout.hpp index b375aaf6cb8dd98d8b6dad738af47210a7038410..330be708525b3e1a90e15919abb9f3f2f2ea1729 100644 --- a/include/vkcv/VertexLayout.hpp +++ b/include/vkcv/VertexLayout.hpp @@ -15,7 +15,7 @@ namespace vkcv { /** * @brief Enum class to specify the format of vertex attributes. */ - enum class VertexAttachmentFormat{ + enum class VertexAttachmentFormat { FLOAT, FLOAT2, FLOAT3, @@ -35,50 +35,56 @@ namespace vkcv { */ uint32_t getFormatSize(VertexAttachmentFormat format); - struct VertexAttachment{ - friend struct VertexBinding; - /** - * Describes an individual vertex input attribute/attachment. - * @param inputLocation its location in the vertex shader. - * @param name the name referred to in the shader. - * @param format the format (and therefore, the size) this attachment is in. - * The offset is calculated when a collection of attachments forms a binding, hence the friend declaration. - */ - VertexAttachment(uint32_t inputLocation, const std::string &name, VertexAttachmentFormat format) noexcept; - VertexAttachment() = delete; - - uint32_t inputLocation; - std::string name; - VertexAttachmentFormat format; - uint32_t offset; + /** + * @brief Structure to store the details of a vertex input attachment. + * + * Describes an individual vertex input attribute/attachment. The offset + * is calculated when a collection of attachments forms a binding. + */ + struct VertexAttachment { + uint32_t inputLocation; + std::string name; + VertexAttachmentFormat format; + uint32_t offset; }; - - struct VertexBinding{ - /** - * Describes all vertex input attachments _one_ buffer contains to create a vertex buffer binding. - * NOTE: multiple vertex layouts may contain various (mutually exclusive) vertex input attachments - * to form one complete vertex buffer binding! - * @param bindingLocation its entry in the buffers that make up the whole vertex buffer. - * @param attachments the vertex input attachments this specific buffer layout contains. - */ - VertexBinding(uint32_t bindingLocation, const std::vector<VertexAttachment> &attachments) noexcept; - VertexBinding() = delete; - - uint32_t bindingLocation; - uint32_t stride; - std::vector<VertexAttachment> vertexAttachments; + + typedef std::vector<VertexAttachment> VertexAttachments; + + /** + * @brief Structure to store the details of a vertex buffer binding. + * + * Describes all vertex input attachments _one_ buffer contains to create + * a vertex buffer binding. NOTE: multiple vertex layouts may contain + * various (mutually exclusive) vertex input attachments to form one + * complete vertex buffer binding! + */ + struct VertexBinding { + uint32_t bindingLocation; + uint32_t stride; + VertexAttachments vertexAttachments; }; + + /** + * Creates a vertex binding with given parameters and calculates its strides + * depending on its attachments. + * + * @param[in] bindingLocation Its entry in the buffers that make up the whole vertex buffer. + * @param[in] attachments The vertex input attachments this specific buffer layout contains. + * @return Vertex buffer binding with calculated stride + */ + VertexBinding createVertexBinding(uint32_t bindingLocation, const VertexAttachments &attachments); + + typedef std::vector<VertexBinding> VertexBindings; - struct VertexLayout{ - /** - * Describes the complete layout of one vertex, e.g. all of the vertex input attachments used, - * and all of the buffer bindings that refer to the attachments (for when multiple buffers are used). - * @param bindings bindings the complete vertex buffer is comprised of. - */ - VertexLayout() noexcept; - VertexLayout(const std::vector<VertexBinding> &bindings) noexcept; - - std::vector<VertexBinding> vertexBindings; + /** + * @brief Structure to store the details of a vertex layout. + * + * Describes the complete layout of one vertex, e.g. all of the vertex input + * attachments used, and all of the buffer bindings that refer to the attachments + * (for when multiple buffers are used). + */ + struct VertexLayout { + VertexBindings vertexBindings; }; } diff --git a/projects/bindless_textures/src/main.cpp b/projects/bindless_textures/src/main.cpp index b6d20341220704be39a73b5a4c2b3dc7a015668a..0986b0910b6e7486c2dc3fc244269672a58d0730 100644 --- a/projects/bindless_textures/src/main.cpp +++ b/projects/bindless_textures/src/main.cpp @@ -109,7 +109,7 @@ int main(int argc, const char** argv) { vk::Format::eD32Sfloat ); - vkcv::PassConfig firstMeshPassDefinition({ present_color_attachment, depth_attachment }); + vkcv::PassConfig firstMeshPassDefinition({ present_color_attachment, depth_attachment }, vkcv::Multisampling::None); vkcv::PassHandle firstMeshPass = core.createPass(firstMeshPassDefinition); if (!firstMeshPass) { @@ -134,11 +134,10 @@ int main(int argc, const char** argv) { const std::vector<vkcv::VertexAttachment> vertexAttachments = firstMeshProgram.getVertexAttachments(); std::vector<vkcv::VertexBinding> bindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } - const vkcv::VertexLayout firstMeshLayout (bindings); - + const vkcv::VertexLayout firstMeshLayout { bindings }; const std::unordered_map<uint32_t, vkcv::DescriptorBinding> &descriptorBindings = firstMeshProgram.getReflectedDescriptors().at(0); std::unordered_map<uint32_t, vkcv::DescriptorBinding> adjustedBindings = descriptorBindings; diff --git a/projects/first_mesh/src/main.cpp b/projects/first_mesh/src/main.cpp index 1fdea63635bd77aa0e6ab76eef1bf124b9c601fb..fe8acb3cfbb65de71763c2c30b50daf5f598234d 100644 --- a/projects/first_mesh/src/main.cpp +++ b/projects/first_mesh/src/main.cpp @@ -59,7 +59,11 @@ int main(int argc, const char** argv) { vk::Format::eD32Sfloat ); - vkcv::PassConfig firstMeshPassDefinition({ present_color_attachment, depth_attachment }); + vkcv::PassConfig firstMeshPassDefinition( + { present_color_attachment, depth_attachment }, + vkcv::Multisampling::None + ); + vkcv::PassHandle firstMeshPass = core.createPass(firstMeshPassDefinition); if (!firstMeshPass) { @@ -84,11 +88,10 @@ int main(int argc, const char** argv) { const std::vector<vkcv::VertexAttachment> vertexAttachments = firstMeshProgram.getVertexAttachments(); std::vector<vkcv::VertexBinding> bindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } - const vkcv::VertexLayout firstMeshLayout (bindings); - + const vkcv::VertexLayout firstMeshLayout { bindings }; // since we only use one descriptor set (namely, desc set 0), directly address it // recreate copies of the bindings and the handles (to check whether they are properly reused instead of actually recreated) diff --git a/projects/first_scene/src/main.cpp b/projects/first_scene/src/main.cpp index 3e424919d2289c45e129c6b476ff026455403982..3c4f51bb119f585e449aa48de2aef086d0789dd7 100644 --- a/projects/first_scene/src/main.cpp +++ b/projects/first_scene/src/main.cpp @@ -50,7 +50,11 @@ int main(int argc, const char** argv) { vk::Format::eD32Sfloat ); - vkcv::PassConfig scenePassDefinition({ present_color_attachment, depth_attachment }); + vkcv::PassConfig scenePassDefinition( + { present_color_attachment, depth_attachment }, + vkcv::Multisampling::None + ); + vkcv::PassHandle scenePass = core.createPass(scenePassDefinition); if (!scenePass) { @@ -68,12 +72,12 @@ int main(int argc, const char** argv) { const std::vector<vkcv::VertexAttachment> vertexAttachments = sceneShaderProgram.getVertexAttachments(); std::vector<vkcv::VertexBinding> bindings; + for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } - const vkcv::VertexLayout sceneLayout(bindings); - + const vkcv::VertexLayout sceneLayout { bindings }; const auto& material0 = scene.getMaterial(0); const vkcv::GraphicsPipelineConfig scenePipelineDefinition{ diff --git a/projects/first_triangle/src/main.cpp b/projects/first_triangle/src/main.cpp index 3d1331ed986a0324fbd542d25fd71c2055308960..c2d8bf817dd1d6b2c7cc069f2037ee090abc4415 100644 --- a/projects/first_triangle/src/main.cpp +++ b/projects/first_triangle/src/main.cpp @@ -33,7 +33,7 @@ int main(int argc, const char** argv) { vkcv::AttachmentOperation::CLEAR, core.getSwapchain(windowHandle).getFormat()); - vkcv::PassConfig trianglePassDefinition({ present_color_attachment }); + vkcv::PassConfig trianglePassDefinition({ present_color_attachment }, vkcv::Multisampling::None); vkcv::PassHandle trianglePass = core.createPass(trianglePassDefinition); if (!trianglePass) diff --git a/projects/head_demo/src/main.cpp b/projects/head_demo/src/main.cpp index d6a67e636d5ce255afea8880a6698f840d9855da..89fb5e08d1c4a5ceec8c43f3c4043f8978d5d404 100644 --- a/projects/head_demo/src/main.cpp +++ b/projects/head_demo/src/main.cpp @@ -66,10 +66,18 @@ int main(int argc, const char** argv) { vk::Format::eD32Sfloat ); - vkcv::PassConfig linePassDefinition({ color_attachment0, depth_attachment0 }); + vkcv::PassConfig linePassDefinition( + { color_attachment0, depth_attachment0 }, + vkcv::Multisampling::None + ); + vkcv::PassHandle linePass = core.createPass(linePassDefinition); - vkcv::PassConfig scenePassDefinition({ color_attachment1, depth_attachment1 }); + vkcv::PassConfig scenePassDefinition( + { color_attachment1, depth_attachment1 }, + vkcv::Multisampling::None + ); + vkcv::PassHandle scenePass = core.createPass(scenePassDefinition); if ((!scenePass) || (!linePass)) { @@ -95,8 +103,9 @@ int main(int argc, const char** argv) { const std::vector<vkcv::VertexAttachment> vertexAttachments = sceneShaderProgram.getVertexAttachments(); std::vector<vkcv::VertexBinding> bindings; + for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } const auto& clipBindings = sceneShaderProgram.getReflectedDescriptors().at(1); @@ -139,8 +148,7 @@ int main(int argc, const char** argv) { } }); - const vkcv::VertexLayout sceneLayout(bindings); - + const vkcv::VertexLayout sceneLayout { bindings }; const auto& material0 = scene.getMaterial(0); const vkcv::GraphicsPipelineConfig scenePipelineDefinition{ diff --git a/projects/indirect_dispatch/src/AppSetup.cpp b/projects/indirect_dispatch/src/AppSetup.cpp index 1d40204b1ab7c6cd49a0c7924fa1fdbf6c2cc24e..342d2d705f831bc98705c9ecaaa5b369befda7b6 100644 --- a/projects/indirect_dispatch/src/AppSetup.cpp +++ b/projects/indirect_dispatch/src/AppSetup.cpp @@ -115,10 +115,10 @@ bool loadGraphicPass( const std::vector<vkcv::VertexAttachment> vertexAttachments = shaderProgram.getVertexAttachments(); std::vector<vkcv::VertexBinding> bindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } - const vkcv::VertexLayout vertexLayout(bindings); + const vkcv::VertexLayout vertexLayout { bindings }; const auto descriptorBindings = shaderProgram.getReflectedDescriptors(); const bool hasDescriptor = descriptorBindings.size() > 0; @@ -169,7 +169,10 @@ bool loadMeshPass(vkcv::Core& core, GraphicPassHandles* outHandles) { core, "assets/shaders/mesh.vert", "assets/shaders/mesh.frag", - vkcv::PassConfig({ colorAttachment, depthAttachment }), + vkcv::PassConfig( + { colorAttachment, depthAttachment }, + vkcv::Multisampling::None + ), vkcv::DepthTest::Equal, outHandles); } @@ -192,7 +195,10 @@ bool loadSkyPass(vkcv::Core& core, GraphicPassHandles* outHandles) { core, "assets/shaders/sky.vert", "assets/shaders/sky.frag", - vkcv::PassConfig({ colorAttachment, depthAttachment }), + vkcv::PassConfig( + { colorAttachment, depthAttachment }, + vkcv::Multisampling::None + ), vkcv::DepthTest::Equal, outHandles); } @@ -214,7 +220,10 @@ bool loadPrePass(vkcv::Core& core, GraphicPassHandles* outHandles) { core, "assets/shaders/prepass.vert", "assets/shaders/prepass.frag", - vkcv::PassConfig({ motionAttachment, depthAttachment }), + vkcv::PassConfig( + { motionAttachment, depthAttachment }, + vkcv::Multisampling::None + ), vkcv::DepthTest::LessEqual, outHandles); } @@ -236,7 +245,10 @@ bool loadSkyPrePass(vkcv::Core& core, GraphicPassHandles* outHandles) { core, "assets/shaders/skyPrepass.vert", "assets/shaders/skyPrepass.frag", - vkcv::PassConfig({ motionAttachment, depthAttachment }), + vkcv::PassConfig( + { motionAttachment, depthAttachment }, + vkcv::Multisampling::None + ), vkcv::DepthTest::LessEqual, outHandles); } diff --git a/projects/indirect_draw/src/main.cpp b/projects/indirect_draw/src/main.cpp index 7bcf4cefc0748a9bb44a573a96e5f360061f5bd3..16e3e83994a1a7ca14fa2163799ee8d034eb8deb 100644 --- a/projects/indirect_draw/src/main.cpp +++ b/projects/indirect_draw/src/main.cpp @@ -334,7 +334,7 @@ int main(int argc, const char** argv) { vk::Format::eD32Sfloat ); - vkcv::PassConfig passDefinition({ present_color_attachment, depth_attachment }); + vkcv::PassConfig passDefinition({ present_color_attachment, depth_attachment }, vkcv::Multisampling::None); vkcv::PassHandle passHandle = core.createPass(passDefinition); if (!passHandle) { std::cerr << "Error. Could not create renderpass. Exiting." << std::endl; @@ -361,7 +361,9 @@ int main(int argc, const char** argv) { // vertex layout for the pipeline. (assumed to be) used by all sponza meshes. const std::vector<vkcv::VertexAttachment> vertexAttachments = sponzaProgram.getVertexAttachments(); - const vkcv::VertexLayout sponzaVertexLayout({ vkcv::VertexBinding(0, { vertexAttachments }) }); + const vkcv::VertexLayout sponzaVertexLayout { + { vkcv::createVertexBinding(0, { vertexAttachments }) } + }; std::vector<uint8_t> compiledVertexBuffer; // IGNORED, since the vertex buffer is not interleaved! diff --git a/projects/mesh_shader/src/main.cpp b/projects/mesh_shader/src/main.cpp index cebcab24798ecd0696dc6a0e6679d2ecde291d21..a74561ca07f7a052fe71c9e1d1efc751c2ab258c 100644 --- a/projects/mesh_shader/src/main.cpp +++ b/projects/mesh_shader/src/main.cpp @@ -168,7 +168,11 @@ int main(int argc, const char** argv) { vk::Format::eD32Sfloat ); - vkcv::PassConfig bunnyPassDefinition({ present_color_attachment, depth_attachment }); + vkcv::PassConfig bunnyPassDefinition( + { present_color_attachment, depth_attachment }, + vkcv::Multisampling::None + ); + vkcv::PassHandle renderPass = core.createPass(bunnyPassDefinition); if (!renderPass) @@ -193,9 +197,9 @@ int main(int argc, const char** argv) { const std::vector<vkcv::VertexAttachment> vertexAttachments = bunnyShaderProgram.getVertexAttachments(); std::vector<vkcv::VertexBinding> bindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } - const vkcv::VertexLayout bunnyLayout (bindings); + const vkcv::VertexLayout bunnyLayout { bindings }; vkcv::DescriptorSetLayoutHandle vertexShaderDescriptorSetLayout = core.createDescriptorSetLayout(bunnyShaderProgram.getReflectedDescriptors().at(0)); vkcv::DescriptorSetHandle vertexShaderDescriptorSet = core.createDescriptorSet(vertexShaderDescriptorSetLayout); diff --git a/projects/particle_simulation/src/main.cpp b/projects/particle_simulation/src/main.cpp index eaaed424634c2243998d55c7e73bf4739ee89013..db538796201ee4c1cf5830bfd82036f16a82e693 100644 --- a/projects/particle_simulation/src/main.cpp +++ b/projects/particle_simulation/src/main.cpp @@ -39,7 +39,7 @@ int main(int argc, const char **argv) { colorFormat); - vkcv::PassConfig particlePassDefinition({present_color_attachment}); + vkcv::PassConfig particlePassDefinition({present_color_attachment}, vkcv::Multisampling::None); vkcv::PassHandle particlePass = core.createPass(particlePassDefinition); vkcv::PassConfig computePassDefinition({}); @@ -83,9 +83,9 @@ int main(int argc, const char **argv) { std::vector<vkcv::VertexBinding> computeBindings; for (size_t i = 0; i < computeVertexAttachments.size(); i++) { - computeBindings.push_back(vkcv::VertexBinding(i, { computeVertexAttachments[i] })); + computeBindings.push_back(vkcv::createVertexBinding(i, { computeVertexAttachments[i] })); } - const vkcv::VertexLayout computeLayout(computeBindings); + const vkcv::VertexLayout computeLayout { computeBindings }; vkcv::ShaderProgram particleShaderProgram{}; compiler.compile(vkcv::ShaderStage::VERTEX, "shaders/shader.vert", [&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) { @@ -110,10 +110,10 @@ int main(int argc, const char **argv) { std::vector<vkcv::VertexBinding> bindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, {vertexAttachments[i]})); + bindings.push_back(vkcv::createVertexBinding(i, {vertexAttachments[i]})); } - const vkcv::VertexLayout particleLayout(bindings); + const vkcv::VertexLayout particleLayout { bindings }; vkcv::GraphicsPipelineConfig particlePipelineDefinition{ particleShaderProgram, diff --git a/projects/saf_r/src/main.cpp b/projects/saf_r/src/main.cpp index e6738de699b87b13cfe38c09958f7cb5ec2b2162..68bc546ded40e7f45454d62bfc4e8cd7227da4b7 100644 --- a/projects/saf_r/src/main.cpp +++ b/projects/saf_r/src/main.cpp @@ -86,9 +86,9 @@ int main(int argc, const char** argv) { std::vector<vkcv::VertexBinding> computeBindings; for (size_t i = 0; i < computeVertexAttachments.size(); i++) { - computeBindings.push_back(vkcv::VertexBinding(i, { computeVertexAttachments[i] })); + computeBindings.push_back(vkcv::createVertexBinding(i, { computeVertexAttachments[i] })); } - const vkcv::VertexLayout computeLayout(computeBindings); + const vkcv::VertexLayout computeLayout { computeBindings }; /* * create the scene @@ -163,7 +163,7 @@ int main(int argc, const char** argv) { vkcv::AttachmentOperation::CLEAR, core.getSwapchain(windowHandle).getFormat()); - vkcv::PassConfig safrPassDefinition({ present_color_attachment }); + vkcv::PassConfig safrPassDefinition({ present_color_attachment }, vkcv::Multisampling::None); vkcv::PassHandle safrPass = core.createPass(safrPassDefinition); if (!safrPass) diff --git a/projects/sph/src/PipelineInit.cpp b/projects/sph/src/PipelineInit.cpp index 052c983cb094114853d19dac3e76149db99116db..e507f1edebf6e39fb65bf81dbd4cf4915602313b 100644 --- a/projects/sph/src/PipelineInit.cpp +++ b/projects/sph/src/PipelineInit.cpp @@ -15,9 +15,9 @@ vkcv::DescriptorSetHandle PipelineInit::ComputePipelineInit(vkcv::Core *pCore, v std::vector<vkcv::VertexBinding> bindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } - const vkcv::VertexLayout layout(bindings); + const vkcv::VertexLayout layout { bindings }; pipeline = pCore->createComputePipeline({ shaderProgram, diff --git a/projects/sph/src/main.cpp b/projects/sph/src/main.cpp index 34a0e7cfce722fc0f45cb584ae8874d5de682e52..601075421a7bf2814e10514ae010fc83b7024f0a 100644 --- a/projects/sph/src/main.cpp +++ b/projects/sph/src/main.cpp @@ -38,7 +38,7 @@ int main(int argc, const char **argv) { colorFormat); - vkcv::PassConfig particlePassDefinition({present_color_attachment}); + vkcv::PassConfig particlePassDefinition({present_color_attachment}, vkcv::Multisampling::None); vkcv::PassHandle particlePass = core.createPass(particlePassDefinition); vkcv::PassConfig computePassDefinition({}); @@ -109,10 +109,10 @@ int main(int argc, const char **argv) { std::vector<vkcv::VertexBinding> bindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - bindings.push_back(vkcv::VertexBinding(i, {vertexAttachments[i]})); + bindings.push_back(vkcv::createVertexBinding(i, {vertexAttachments[i]})); } - const vkcv::VertexLayout particleLayout(bindings); + const vkcv::VertexLayout particleLayout { bindings }; // initializing graphics pipeline vkcv::GraphicsPipelineConfig particlePipelineDefinition{ diff --git a/projects/voxelization/src/Voxelization.cpp b/projects/voxelization/src/Voxelization.cpp index 60a3a1c89ab7b24ceef16fc5934eb4421c3cf651..616eed83e0687e03c1d9bfe0ee3127a72457d241 100644 --- a/projects/voxelization/src/Voxelization.cpp +++ b/projects/voxelization/src/Voxelization.cpp @@ -92,10 +92,13 @@ Voxelization::Voxelization( const vkcv::ShaderProgram voxelizationShader = loadVoxelizationShader(); - const vkcv::PassConfig voxelizationPassConfig({vkcv::AttachmentDescription( - vkcv::AttachmentOperation::DONT_CARE, - vkcv::AttachmentOperation::DONT_CARE, - voxelizationDummyFormat) }); + const vkcv::PassConfig voxelizationPassConfig {{ + { + vkcv::AttachmentOperation::DONT_CARE, + vkcv::AttachmentOperation::DONT_CARE, + voxelizationDummyFormat + } + }, vkcv::Multisampling::None }; m_voxelizationPass = m_corePtr->createPass(voxelizationPassConfig); m_voxelizationDescriptorSetLayout = m_corePtr->createDescriptorSetLayout(voxelizationShader.getReflectedDescriptors().at(0)); @@ -146,9 +149,11 @@ Voxelization::Voxelization( dependencies.depthBufferFormat ); - vkcv::PassConfig voxelVisualisationPassDefinition( - { voxelVisualisationColorAttachments, voxelVisualisationDepthAttachments }); - voxelVisualisationPassDefinition.msaa = msaa; + vkcv::PassConfig voxelVisualisationPassDefinition{ + { voxelVisualisationColorAttachments, voxelVisualisationDepthAttachments }, + msaa + }; + m_visualisationPass = m_corePtr->createPass(voxelVisualisationPassDefinition); vkcv::GraphicsPipelineConfig voxelVisualisationPipeConfig{ diff --git a/projects/voxelization/src/main.cpp b/projects/voxelization/src/main.cpp index 6bafbbd42271fe4460b953d143eed2ac6f172c55..02533e447724ad8d83c7af415b01acc2350126eb 100644 --- a/projects/voxelization/src/main.cpp +++ b/projects/voxelization/src/main.cpp @@ -195,9 +195,9 @@ int main(int argc, const char** argv) { std::vector<vkcv::VertexBinding> vertexBindings; for (size_t i = 0; i < vertexAttachments.size(); i++) { - vertexBindings.push_back(vkcv::VertexBinding(i, { vertexAttachments[i] })); + vertexBindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] })); } - const vkcv::VertexLayout vertexLayout (vertexBindings); + const vkcv::VertexLayout vertexLayout { vertexBindings }; vkcv::DescriptorSetLayoutHandle forwardShadingDescriptorSetLayout = core.createDescriptorSetLayout(forwardProgram.getReflectedDescriptors().at(0)); vkcv::DescriptorSetHandle forwardShadingDescriptorSet = core.createDescriptorSet(forwardShadingDescriptorSetLayout); @@ -217,9 +217,9 @@ int main(int argc, const char** argv) { std::vector<vkcv::VertexBinding> prepassVertexBindings; for (size_t i = 0; i < prepassVertexAttachments.size(); i++) { - prepassVertexBindings.push_back(vkcv::VertexBinding(i, { prepassVertexAttachments[i] })); + prepassVertexBindings.push_back(vkcv::createVertexBinding(i, { prepassVertexAttachments[i] })); } - const vkcv::VertexLayout prepassVertexLayout(prepassVertexBindings); + const vkcv::VertexLayout prepassVertexLayout { prepassVertexBindings }; const vkcv::AttachmentDescription prepassAttachment( vkcv::AttachmentOperation::STORE, diff --git a/projects/wobble_bobble/src/main.cpp b/projects/wobble_bobble/src/main.cpp index 989e6cff7030dc5e81c94c3f854971b87c7d3c6b..d554687b503fa4460f27aa4db5374cc0e4d0acb9 100644 --- a/projects/wobble_bobble/src/main.cpp +++ b/projects/wobble_bobble/src/main.cpp @@ -452,7 +452,7 @@ int main(int argc, const char **argv) { { vkcv::ShaderStage::FRAGMENT, "shaders/lines.frag" } }, nullptr); - vkcv::PassConfig passConfigGrid ({ + vkcv::PassConfig passConfigGrid {{ vkcv::AttachmentDescription( vkcv::AttachmentOperation::STORE, vkcv::AttachmentOperation::CLEAR, @@ -463,9 +463,9 @@ int main(int argc, const char **argv) { vkcv::AttachmentOperation::CLEAR, vk::Format::eD32Sfloat ) - }); + }, vkcv::Multisampling::None }; - vkcv::PassConfig passConfigParticles ({ + vkcv::PassConfig passConfigParticles {{ vkcv::AttachmentDescription( vkcv::AttachmentOperation::STORE, vkcv::AttachmentOperation::CLEAR, @@ -476,9 +476,9 @@ int main(int argc, const char **argv) { vkcv::AttachmentOperation::CLEAR, vk::Format::eD32Sfloat ) - }); + }, vkcv::Multisampling::None }; - vkcv::PassConfig passConfigLines ({ + vkcv::PassConfig passConfigLines {{ vkcv::AttachmentDescription( vkcv::AttachmentOperation::STORE, vkcv::AttachmentOperation::LOAD, @@ -489,7 +489,7 @@ int main(int argc, const char **argv) { vkcv::AttachmentOperation::LOAD, vk::Format::eD32Sfloat ) - }); + }, vkcv::Multisampling::None }; vkcv::DescriptorSetLayoutHandle gfxSetLayoutGrid = core.createDescriptorSetLayout( gfxProgramGrid.getReflectedDescriptors().at(0) @@ -522,7 +522,7 @@ int main(int argc, const char **argv) { vkcv::PassHandle gfxPassLines = core.createPass(passConfigLines); vkcv::VertexLayout vertexLayoutGrid ({ - vkcv::VertexBinding(0, gfxProgramGrid.getVertexAttachments()) + vkcv::createVertexBinding(0, gfxProgramGrid.getVertexAttachments()) }); vkcv::GraphicsPipelineConfig gfxPipelineConfigGrid; @@ -535,7 +535,7 @@ int main(int argc, const char **argv) { gfxPipelineConfigGrid.m_UseDynamicViewport = true; vkcv::VertexLayout vertexLayoutParticles ({ - vkcv::VertexBinding(0, gfxProgramParticles.getVertexAttachments()) + vkcv::createVertexBinding(0, gfxProgramParticles.getVertexAttachments()) }); vkcv::GraphicsPipelineConfig gfxPipelineConfigParticles; @@ -548,7 +548,7 @@ int main(int argc, const char **argv) { gfxPipelineConfigParticles.m_UseDynamicViewport = true; vkcv::VertexLayout vertexLayoutLines ({ - vkcv::VertexBinding(0, gfxProgramLines.getVertexAttachments()) + vkcv::createVertexBinding(0, gfxProgramLines.getVertexAttachments()) }); vkcv::GraphicsPipelineConfig gfxPipelineConfigLines; diff --git a/src/vkcv/DrawcallRecording.cpp b/src/vkcv/DrawcallRecording.cpp index e13b4d24148e9d76d8be4ad7fd3db0db87249c59..ce7c2e600147c19859e570e1c3d1483511e323fd 100644 --- a/src/vkcv/DrawcallRecording.cpp +++ b/src/vkcv/DrawcallRecording.cpp @@ -19,14 +19,13 @@ namespace vkcv { MeshShaderFunctions.cmdDrawMeshTasksIndirectCount = PFN_vkCmdDrawMeshTasksIndirectCountNV (device.getProcAddr( "vkCmdDrawMeshTasksIndirectCountNV")); } - void recordMeshShaderDrawcall( - const Core& core, - vk::CommandBuffer cmdBuffer, - vk::PipelineLayout pipelineLayout, - const PushConstants& pushConstantData, - const uint32_t pushConstantOffset, - const MeshShaderDrawcall& drawcall, - const uint32_t firstTask) { + void recordMeshShaderDrawcall(const Core& core, + vk::CommandBuffer cmdBuffer, + vk::PipelineLayout pipelineLayout, + const PushConstants& pushConstantData, + uint32_t pushConstantOffset, + const MeshShaderDrawcall& drawcall, + uint32_t firstTask) { for (const auto& descriptorUsage : drawcall.descriptorSets) { cmdBuffer.bindDescriptorSets( diff --git a/src/vkcv/PassConfig.cpp b/src/vkcv/PassConfig.cpp deleted file mode 100644 index b203fab4f02afcc8f51b468ab4504480a8e60e4e..0000000000000000000000000000000000000000 --- a/src/vkcv/PassConfig.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "vkcv/PassConfig.hpp" - -#include <utility> - -namespace vkcv -{ - AttachmentDescription::AttachmentDescription( - AttachmentOperation store_op, - AttachmentOperation load_op, - vk::Format format) noexcept : - store_operation{store_op}, - load_operation{load_op}, - format(format) - {} - - PassConfig::PassConfig(std::vector<AttachmentDescription> attachments, Multisampling msaa) noexcept : - attachments{std::move(attachments) }, msaa(msaa) - {} -} \ No newline at end of file diff --git a/src/vkcv/ShaderProgram.cpp b/src/vkcv/ShaderProgram.cpp index 4b2afbd43cd965a14b6e2748122f9866077e8f6f..97eea880cbc38fee1a71d52a1e154471344d7758 100644 --- a/src/vkcv/ShaderProgram.cpp +++ b/src/vkcv/ShaderProgram.cpp @@ -136,7 +136,12 @@ namespace vkcv { // vertex input format (implies its size) const VertexAttachmentFormat attachment_format = convertFormat(base_type.basetype, base_type.vecsize); - m_VertexAttachments.emplace_back(attachment_loc, attachment_name, attachment_format); + m_VertexAttachments.push_back({ + attachment_loc, + attachment_name, + attachment_format, + 0 + }); } } @@ -352,7 +357,7 @@ namespace vkcv { } } - const std::vector<VertexAttachment> &ShaderProgram::getVertexAttachments() const + const VertexAttachments &ShaderProgram::getVertexAttachments() const { return m_VertexAttachments; } diff --git a/src/vkcv/VertexLayout.cpp b/src/vkcv/VertexLayout.cpp index 5298dd4117cd61c7b3ce7e6f4aa0ed0ad2855f68..73e3885bf8f97854712d5b202123c7f7202042d1 100644 --- a/src/vkcv/VertexLayout.cpp +++ b/src/vkcv/VertexLayout.cpp @@ -30,34 +30,18 @@ namespace vkcv { return 0; } } + + VertexBinding createVertexBinding(uint32_t bindingLocation, const VertexAttachments &attachments) { + VertexBinding binding { bindingLocation, 0, attachments }; + uint32_t offset = 0; + + for (auto& attachment : binding.vertexAttachments) { + attachment.offset = offset; + offset += getFormatSize(attachment.format); + } + + binding.stride = offset; + return binding; + } - VertexAttachment::VertexAttachment(uint32_t inputLocation, const std::string &name, VertexAttachmentFormat format) noexcept: - inputLocation{inputLocation}, - name{name}, - format{format}, - offset{0} - {} - - - VertexBinding::VertexBinding(uint32_t bindingLocation, const std::vector<VertexAttachment> &attachments) noexcept : - bindingLocation{bindingLocation}, - stride{0}, - vertexAttachments{attachments} - { - uint32_t offset = 0; - for (auto &attachment : vertexAttachments) - { - attachment.offset = offset; - offset += getFormatSize(attachment.format); - } - stride = offset; - } - - VertexLayout::VertexLayout() noexcept : - vertexBindings{} - {} - - VertexLayout::VertexLayout(const std::vector<VertexBinding> &bindings) noexcept : - vertexBindings{bindings} - {} } \ No newline at end of file