From 16803aaf595fb238de9965f7aa114ebb4653548d Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Sat, 18 Jun 2022 19:04:31 +0200 Subject: [PATCH] Throw vertex bindings and layout out of the framework Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- config/Sources.cmake | 3 - include/vkcv/DrawcallRecording.hpp | 13 +--- include/vkcv/GraphicsPipelineConfig.hpp | 2 - include/vkcv/ShaderProgram.hpp | 13 +--- include/vkcv/VertexLayout.hpp | 90 ------------------------- src/vkcv/Core.cpp | 7 -- src/vkcv/GraphicsPipelineManager.cpp | 85 ++--------------------- src/vkcv/ShaderProgram.cpp | 68 +------------------ src/vkcv/VertexLayout.cpp | 47 ------------- 9 files changed, 12 insertions(+), 316 deletions(-) delete mode 100644 include/vkcv/VertexLayout.hpp delete mode 100644 src/vkcv/VertexLayout.cpp diff --git a/config/Sources.cmake b/config/Sources.cmake index f0fd0ed7..0a088ca4 100644 --- a/config/Sources.cmake +++ b/config/Sources.cmake @@ -71,9 +71,6 @@ set(vkcv_sources ${vkcv_include}/vkcv/QueueManager.hpp ${vkcv_source}/vkcv/QueueManager.cpp - ${vkcv_include}/vkcv/VertexLayout.hpp - ${vkcv_source}/vkcv/VertexLayout.cpp - ${vkcv_include}/vkcv/Event.hpp ${vkcv_source}/vkcv/DescriptorManager.hpp diff --git a/include/vkcv/DrawcallRecording.hpp b/include/vkcv/DrawcallRecording.hpp index 76b94dc8..a70ab05a 100644 --- a/include/vkcv/DrawcallRecording.hpp +++ b/include/vkcv/DrawcallRecording.hpp @@ -14,14 +14,6 @@ #include "Buffer.hpp" namespace vkcv { - - /** - * @brief Structure to store details about a vertex buffer binding. - */ - struct VertexBufferBinding { - vk::DeviceSize offset; - vk::Buffer buffer; - }; /** * @brief Enum class to specify the size of indexes. @@ -53,16 +45,13 @@ namespace vkcv { struct Mesh { inline Mesh() {} - inline Mesh(std::vector<VertexBufferBinding> vertexBufferBindings, - vk::Buffer indexBuffer, + inline Mesh(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; diff --git a/include/vkcv/GraphicsPipelineConfig.hpp b/include/vkcv/GraphicsPipelineConfig.hpp index 85cabc13..b3c882f7 100644 --- a/include/vkcv/GraphicsPipelineConfig.hpp +++ b/include/vkcv/GraphicsPipelineConfig.hpp @@ -10,7 +10,6 @@ #include "Handles.hpp" #include "ShaderProgram.hpp" -#include "VertexLayout.hpp" #include "ImageConfig.hpp" namespace vkcv { @@ -65,7 +64,6 @@ namespace vkcv { uint32_t m_Width; uint32_t m_Height; PassHandle m_PassHandle; - VertexLayout m_VertexLayout; std::vector<DescriptorSetLayoutHandle> m_DescriptorLayouts; bool m_UseDynamicViewport; bool m_UseConservativeRasterization = false; diff --git a/include/vkcv/ShaderProgram.hpp b/include/vkcv/ShaderProgram.hpp index c815834a..c1105d2d 100644 --- a/include/vkcv/ShaderProgram.hpp +++ b/include/vkcv/ShaderProgram.hpp @@ -13,7 +13,6 @@ #include <vulkan/vulkan.hpp> #include <spirv_cross.hpp> -#include "VertexLayout.hpp" #include "DescriptorConfig.hpp" #include "ShaderStage.hpp" @@ -61,14 +60,6 @@ namespace vkcv { * @return True, if a shader exists for the stage, else false */ bool existsShader(ShaderStage stage) const; - - /** - * @brief Returns the vertex attachments for the program and its - * shader stages. - * - * @return Vertex attachments - */ - const std::vector<VertexAttachment> &getVertexAttachments() const; /** * @brief Returns the size of the programs push constants. @@ -95,9 +86,7 @@ namespace vkcv { void reflectShader(ShaderStage shaderStage); std::unordered_map<ShaderStage, std::vector<uint32_t> > m_Shaders; - - // contains all vertex input attachments used in the vertex buffer - 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 deleted file mode 100644 index 330be708..00000000 --- a/include/vkcv/VertexLayout.hpp +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once -/** - * @authors Alexander Gauggel, Artur Wasmut, Mara Vogt, Susanne DÃķtsch, - * Trevor Hollmann, Leonie Franken, Simeon Hermann, Tobias Frisch - * @file vkcv/VertexLayout.hpp - * @brief Structures to handle vertex layout, bindings and attachments. - */ - -#include <vector> -#include <iostream> -#include <string> - -namespace vkcv { - - /** - * @brief Enum class to specify the format of vertex attributes. - */ - enum class VertexAttachmentFormat { - FLOAT, - FLOAT2, - FLOAT3, - FLOAT4, - INT, - INT2, - INT3, - INT4 - }; - - /** - * @brief Returns the size in bytes of a vertex with a - * given vertex format. - * - * @param[in] format Vertex format - * @return Size in bytes - */ - uint32_t getFormatSize(VertexAttachmentFormat format); - - /** - * @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; - }; - - 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; - - /** - * @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/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index 06942b87..368517b2 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -293,11 +293,6 @@ namespace vkcv const PushConstants &pushConstants, const size_t drawcallIndex) { - for (uint32_t i = 0; i < drawcall.mesh.vertexBufferBindings.size(); i++) { - const auto& vertexBinding = drawcall.mesh.vertexBufferBindings[i]; - cmdBuffer.bindVertexBuffers(i, vertexBinding.buffer, vertexBinding.offset); - } - for (const auto& descriptorUsage : drawcall.descriptorSets) { cmdBuffer.bindDescriptorSets( vk::PipelineBindPoint::eGraphics, @@ -470,8 +465,6 @@ namespace vkcv descSet.vulkanHandle, nullptr); - vk::DeviceSize deviceSize = 0; - cmdBuffer.bindVertexBuffers(0, 1, &compiledMesh.vertexBufferBindings[0].buffer,&deviceSize); cmdBuffer.bindIndexBuffer(compiledMesh.indexBuffer, 0, getIndexType(compiledMesh.indexBitCount)); cmdBuffer.drawIndexedIndirect( diff --git a/src/vkcv/GraphicsPipelineManager.cpp b/src/vkcv/GraphicsPipelineManager.cpp index 2ebc84ad..b08225cf 100644 --- a/src/vkcv/GraphicsPipelineManager.cpp +++ b/src/vkcv/GraphicsPipelineManager.cpp @@ -18,31 +18,6 @@ namespace vkcv } } - // currently assuming default 32 bit formats, no lower precision or normalized variants supported - vk::Format vertexFormatToVulkanFormat(const VertexAttachmentFormat format) { - switch (format) { - case VertexAttachmentFormat::FLOAT: - return vk::Format::eR32Sfloat; - case VertexAttachmentFormat::FLOAT2: - return vk::Format::eR32G32Sfloat; - case VertexAttachmentFormat::FLOAT3: - return vk::Format::eR32G32B32Sfloat; - case VertexAttachmentFormat::FLOAT4: - return vk::Format::eR32G32B32A32Sfloat; - case VertexAttachmentFormat::INT: - return vk::Format::eR32Sint; - case VertexAttachmentFormat::INT2: - return vk::Format::eR32G32Sint; - case VertexAttachmentFormat::INT3: - return vk::Format::eR32G32B32Sint; - case VertexAttachmentFormat::INT4: - return vk::Format::eR32G32B32A32Sint; - default: - vkcv_log(LogLevel::WARNING, "Unknown vertex format"); - return vk::Format::eUndefined; - } - } - vk::PrimitiveTopology primitiveTopologyToVulkanPrimitiveTopology(const PrimitiveTopology topology) { switch (topology) { case(PrimitiveTopology::PointList): @@ -128,56 +103,17 @@ namespace vkcv } /** - * Fills Vertex Attribute and Binding Description with the corresponding objects form the Vertex Layout. - * @param vertexAttributeDescriptions - * @param vertexBindingDescriptions - * @param existsVertexShader - * @param config - */ - void fillVertexInputDescription( - std::vector<vk::VertexInputAttributeDescription> &vertexAttributeDescriptions, - std::vector<vk::VertexInputBindingDescription> &vertexBindingDescriptions, - const bool existsVertexShader, - const GraphicsPipelineConfig &config) { - - if (existsVertexShader) { - const VertexLayout& layout = config.m_VertexLayout; - - // iterate over the layout's specified, mutually exclusive buffer bindings that make up a vertex buffer - for (const auto& vertexBinding : layout.vertexBindings) - { - vertexBindingDescriptions.emplace_back(vertexBinding.bindingLocation, - vertexBinding.stride, - vk::VertexInputRate::eVertex); - - // iterate over the bindings' specified, mutually exclusive vertex input attachments that make up a vertex - for (const auto& vertexAttachment : vertexBinding.vertexAttachments) - { - vertexAttributeDescriptions.emplace_back(vertexAttachment.inputLocation, - vertexBinding.bindingLocation, - vertexFormatToVulkanFormat(vertexAttachment.format), - vertexAttachment.offset % vertexBinding.stride); - } - } - } - } - - /** - * Creates a Pipeline Vertex Input State Create Info Struct and fills it with Attribute and Binding data. - * @param vertexAttributeDescriptions - * @param vertexBindingDescriptions + * Creates a Pipeline Vertex Input State Create Info Struct. * @return Pipeline Vertex Input State Create Info Struct */ - vk::PipelineVertexInputStateCreateInfo createPipelineVertexInputStateCreateInfo( - std::vector<vk::VertexInputAttributeDescription> &vertexAttributeDescriptions, - std::vector<vk::VertexInputBindingDescription> &vertexBindingDescriptions) { + vk::PipelineVertexInputStateCreateInfo createPipelineVertexInputStateCreateInfo() { vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo( {}, - vertexBindingDescriptions.size(), - vertexBindingDescriptions.data(), - vertexAttributeDescriptions.size(), - vertexAttributeDescriptions.data() + 0, + nullptr, + 0, + nullptr ); return pipelineVertexInputStateCreateInfo; } @@ -587,16 +523,9 @@ namespace vkcv } } - // vertex input state - // Fill up VertexInputBindingDescription and VertexInputAttributeDescription Containers - std::vector<vk::VertexInputAttributeDescription> vertexAttributeDescriptions; - std::vector<vk::VertexInputBindingDescription> vertexBindingDescriptions; - fillVertexInputDescription(vertexAttributeDescriptions, vertexBindingDescriptions, existsVertexShader, config); - // Handover Containers to PipelineVertexInputStateCreateIngo Struct vk::PipelineVertexInputStateCreateInfo pipelineVertexInputStateCreateInfo = - createPipelineVertexInputStateCreateInfo(vertexAttributeDescriptions, - vertexBindingDescriptions); + createPipelineVertexInputStateCreateInfo(); // input assembly state vk::PipelineInputAssemblyStateCreateInfo pipelineInputAssemblyStateCreateInfo = diff --git a/src/vkcv/ShaderProgram.cpp b/src/vkcv/ShaderProgram.cpp index e1af4e1b..4dc1d022 100644 --- a/src/vkcv/ShaderProgram.cpp +++ b/src/vkcv/ShaderProgram.cpp @@ -38,47 +38,8 @@ namespace vkcv { return buffer; } - VertexAttachmentFormat convertFormat(spirv_cross::SPIRType::BaseType basetype, uint32_t vecsize){ - switch (basetype) { - case spirv_cross::SPIRType::Int: - switch (vecsize) { - case 1: - return VertexAttachmentFormat::INT; - case 2: - return VertexAttachmentFormat::INT2; - case 3: - return VertexAttachmentFormat::INT3; - case 4: - return VertexAttachmentFormat::INT4; - default: - break; - } - break; - case spirv_cross::SPIRType::Float: - switch (vecsize) { - case 1: - return VertexAttachmentFormat::FLOAT; - case 2: - return VertexAttachmentFormat::FLOAT2; - case 3: - return VertexAttachmentFormat::FLOAT3; - case 4: - return VertexAttachmentFormat::FLOAT4; - default: - break; - } - break; - default: - break; - } - - vkcv_log(LogLevel::WARNING, "Unknown vertex format"); - return VertexAttachmentFormat::FLOAT; - } - ShaderProgram::ShaderProgram() noexcept : m_Shaders{}, - m_VertexAttachments{}, m_DescriptorSets{} {} @@ -122,27 +83,9 @@ namespace vkcv { //reflect vertex input if (shaderStage == ShaderStage::VERTEX) { - // spirv-cross API (hopefully) returns the stage_inputs in order - for (uint32_t i = 0; i < resources.stage_inputs.size(); i++) - { - // spirv-cross specific objects - auto& stage_input = resources.stage_inputs[i]; - const spirv_cross::SPIRType& base_type = comp.get_type(stage_input.base_type_id); - - // vertex input location - const uint32_t attachment_loc = comp.get_decoration(stage_input.id, spv::DecorationLocation); - // vertex input name - const std::string attachment_name = stage_input.name; - // vertex input format (implies its size) - const VertexAttachmentFormat attachment_format = convertFormat(base_type.basetype, base_type.vecsize); - - m_VertexAttachments.push_back({ - attachment_loc, - attachment_name, - attachment_format, - 0 - }); - } + if (!resources.stage_inputs.empty()) { + vkcv_log(LogLevel::WARNING, "Vertex bindings are not supported"); + } } //reflect descriptor sets (uniform buffer, storage buffer, sampler, sampled image, storage image) @@ -372,11 +315,6 @@ namespace vkcv { } } - const VertexAttachments &ShaderProgram::getVertexAttachments() const - { - return m_VertexAttachments; - } - const std::unordered_map<uint32_t, DescriptorBindings>& ShaderProgram::getReflectedDescriptors() const { return m_DescriptorSets; diff --git a/src/vkcv/VertexLayout.cpp b/src/vkcv/VertexLayout.cpp deleted file mode 100644 index 73e3885b..00000000 --- a/src/vkcv/VertexLayout.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// -// Created by Charlotte on 28.05.2021. -// - -#include "vkcv/VertexLayout.hpp" -#include "vkcv/Logger.hpp" - -namespace vkcv { - - uint32_t getFormatSize(VertexAttachmentFormat format) { - switch (format) { - case VertexAttachmentFormat::FLOAT: - return 4; - case VertexAttachmentFormat::FLOAT2: - return 8; - case VertexAttachmentFormat::FLOAT3: - return 12; - case VertexAttachmentFormat::FLOAT4: - return 16; - case VertexAttachmentFormat::INT: - return 4; - case VertexAttachmentFormat::INT2: - return 8; - case VertexAttachmentFormat::INT3: - return 12; - case VertexAttachmentFormat::INT4: - return 16; - default: - vkcv_log(LogLevel::WARNING, "No format given"); - 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; - } - -} \ No newline at end of file -- GitLab