From b93152eaec13253ad452b67f8f61bf4c9bcb89c5 Mon Sep 17 00:00:00 2001 From: Tobias Frisch <tfrisch@uni-koblenz.de> Date: Mon, 7 Feb 2022 10:48:59 +0100 Subject: [PATCH] Moved drawcall recording into core hiding internal calls Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de> --- include/vkcv/DrawcallRecording.hpp | 19 ---------- src/vkcv/Core.cpp | 50 ++++++++++++++++++++++++ src/vkcv/DrawcallRecording.cpp | 61 ------------------------------ 3 files changed, 50 insertions(+), 80 deletions(-) diff --git a/include/vkcv/DrawcallRecording.hpp b/include/vkcv/DrawcallRecording.hpp index 4e15403c..70b23107 100644 --- a/include/vkcv/DrawcallRecording.hpp +++ b/include/vkcv/DrawcallRecording.hpp @@ -52,8 +52,6 @@ namespace vkcv { }; - vk::IndexType getIndexType(IndexBitCount indexByteCount); - struct DrawcallInfo { inline DrawcallInfo(const Mesh& mesh, const std::vector<DescriptorSetUsage>& descriptorSets, const uint32_t instanceCount = 1) : mesh(mesh), descriptorSets(descriptorSets), instanceCount(instanceCount){} @@ -63,23 +61,6 @@ namespace vkcv { uint32_t instanceCount; }; - void recordDrawcall( - const Core &core, - const DrawcallInfo &drawcall, - vk::CommandBuffer cmdBuffer, - vk::PipelineLayout pipelineLayout, - const PushConstants &pushConstants, - const size_t drawcallIndex); - - void recordIndirectDrawcall( - const DrawcallInfo &drawcall, - vk::CommandBuffer cmdBuffer, - const vkcv::Buffer<vk::DrawIndexedIndirectCommand> &drawBuffer, - const uint32_t drawCount, - vk::PipelineLayout pipelineLayout, - const PushConstants &pushConstants, - const size_t drawcallIndex); - void InitMeshShaderDrawFunctions(vk::Device device); struct MeshShaderDrawcall { diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index a5786b1a..ba69cab5 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -268,6 +268,56 @@ namespace vkcv cmdBuffer.setViewport(0, 1, &dynamicViewport); cmdBuffer.setScissor(0, 1, &dynamicScissor); } + + vk::IndexType getIndexType(IndexBitCount indexByteCount){ + switch (indexByteCount) { + case IndexBitCount::Bit16: return vk::IndexType::eUint16; + case IndexBitCount::Bit32: return vk::IndexType::eUint32; + default: + vkcv_log(LogLevel::ERROR, "unknown Enum"); + return vk::IndexType::eUint16; + } + } + + void recordDrawcall( + const Core &core, + const DrawcallInfo &drawcall, + vk::CommandBuffer cmdBuffer, + vk::PipelineLayout pipelineLayout, + 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, + pipelineLayout, + descriptorUsage.setLocation, + core.getDescriptorSet(descriptorUsage.descriptorSet).vulkanHandle, + nullptr); + } + + if (pushConstants.getSizePerDrawcall() > 0) { + cmdBuffer.pushConstants( + pipelineLayout, + vk::ShaderStageFlagBits::eAll, + 0, + pushConstants.getSizePerDrawcall(), + pushConstants.getDrawcallData(drawcallIndex)); + } + + if (drawcall.mesh.indexBuffer) { + cmdBuffer.bindIndexBuffer(drawcall.mesh.indexBuffer, 0, getIndexType(drawcall.mesh.indexBitCount)); + cmdBuffer.drawIndexed(drawcall.mesh.indexCount, drawcall.instanceCount, 0, 0, {}); + } + else { + cmdBuffer.draw(drawcall.mesh.indexCount, drawcall.instanceCount, 0, 0, {}); + } + } void Core::recordDrawcallsToCmdStream( const CommandStreamHandle& cmdStreamHandle, diff --git a/src/vkcv/DrawcallRecording.cpp b/src/vkcv/DrawcallRecording.cpp index 0a13785b..e13b4d24 100644 --- a/src/vkcv/DrawcallRecording.cpp +++ b/src/vkcv/DrawcallRecording.cpp @@ -5,67 +5,6 @@ namespace vkcv { - vk::IndexType getIndexType(IndexBitCount indexByteCount){ - switch (indexByteCount) { - case IndexBitCount::Bit16: return vk::IndexType::eUint16; - case IndexBitCount::Bit32: return vk::IndexType::eUint32; - default: - vkcv_log(LogLevel::ERROR, "unknown Enum"); - return vk::IndexType::eUint16; - } - } - - void recordDrawcall( - const Core &core, - const DrawcallInfo &drawcall, - vk::CommandBuffer cmdBuffer, - vk::PipelineLayout pipelineLayout, - 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, - pipelineLayout, - descriptorUsage.setLocation, - core.getDescriptorSet(descriptorUsage.descriptorSet).vulkanHandle, - nullptr); - } - - if (pushConstants.getSizePerDrawcall() > 0) { - cmdBuffer.pushConstants( - pipelineLayout, - vk::ShaderStageFlagBits::eAll, - 0, - pushConstants.getSizePerDrawcall(), - pushConstants.getDrawcallData(drawcallIndex)); - } - - if (drawcall.mesh.indexBuffer) { - cmdBuffer.bindIndexBuffer(drawcall.mesh.indexBuffer, 0, getIndexType(drawcall.mesh.indexBitCount)); - cmdBuffer.drawIndexed(drawcall.mesh.indexCount, drawcall.instanceCount, 0, 0, {}); - } - else { - cmdBuffer.draw(drawcall.mesh.indexCount, drawcall.instanceCount, 0, 0, {}); - } - } - - void recordIndirectDrawcall( - const DrawcallInfo &drawcall, - vk::CommandBuffer cmdBuffer, - const Buffer <vk::DrawIndexedIndirectCommand> &drawBuffer, - const uint32_t drawCount, - vk::PipelineLayout pipelineLayout, - const PushConstants &pushConstants, - const size_t drawcallIndex) { - return; - } - struct MeshShaderFunctions { PFN_vkCmdDrawMeshTasksNV cmdDrawMeshTasks = nullptr; -- GitLab