diff --git a/include/vkcv/DrawcallRecording.hpp b/include/vkcv/DrawcallRecording.hpp index 4e15403c84757fc68623a567891ce13645bcfc4a..70b23107c4605e6ac01aa80fa4a431c62d7a7219 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 a5786b1a79cf2e51ddda6ca251b7dd8d7fffd46a..ba69cab5fcd2a1ce78e5a3491e24ab7f273e0474 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 0a13785b93a8d3efb0217e94ad056293d70c0be0..e13b4d24148e9d76d8be4ad7fd3db0db87249c59 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;