From 924388a653fe15ed80ad36eed5d49b1be22562c2 Mon Sep 17 00:00:00 2001
From: Alexander Gauggel <agauggel@uni-koblenz.de>
Date: Thu, 17 Jun 2021 17:42:24 +0200
Subject: [PATCH] [#70] Allowing drawcall recording without index buffer, which
 fixes voxelization vis at higher resolutions

---
 projects/voxelization/src/Voxelization.cpp |  6 ++----
 projects/voxelization/src/Voxelization.hpp |  1 -
 src/vkcv/DrawcallRecording.cpp             | 10 +++++++---
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/projects/voxelization/src/Voxelization.cpp b/projects/voxelization/src/Voxelization.cpp
index e9748aa3..6ce571a3 100644
--- a/projects/voxelization/src/Voxelization.cpp
+++ b/projects/voxelization/src/Voxelization.cpp
@@ -58,7 +58,7 @@ vkcv::ShaderProgram loadVoxelBufferToImageShader() {
 	return shader;
 }
 
-const uint32_t voxelResolution = 32;
+const uint32_t voxelResolution = 128;
 const size_t voxelCount = voxelResolution * voxelResolution * voxelResolution;
 const vk::Format voxelizationDummyFormat = vk::Format::eR8Unorm;
 
@@ -68,7 +68,6 @@ Voxelization::Voxelization(vkcv::Core* corePtr, const Dependencies& dependencies
 	m_voxelImage(m_corePtr->createImage(vk::Format::eR16G16B16A16Sfloat, voxelResolution, voxelResolution, voxelResolution, true)),
 	m_dummyRenderTarget(m_corePtr->createImage(voxelizationDummyFormat, voxelResolution, voxelResolution, 1, false, true)),
 	m_voxelInfoBuffer(m_corePtr->createBuffer<VoxelizationInfo>(vkcv::BufferType::UNIFORM, 1)),
-	m_visualisationIndexBuffer(m_corePtr->createBuffer<uint16_t>(vkcv::BufferType::INDEX, voxelCount)),
 	m_voxelBuffer(m_corePtr->createBuffer<VoxelBufferContent>(vkcv::BufferType::STORAGE, voxelCount)){
 
 	const vkcv::ShaderProgram voxelizationShader = loadVoxelizationShader();
@@ -143,7 +142,6 @@ Voxelization::Voxelization(vkcv::Core* corePtr, const Dependencies& dependencies
 	for (int i = 0; i < voxelCount; i++) {
 		voxelIndexData.push_back(i);
 	}
-	m_visualisationIndexBuffer.fill(voxelIndexData);
 
 	vkcv::DescriptorWrites voxelVisualisationDescriptorWrite;
 	voxelVisualisationDescriptorWrite.storageImageWrites = 
@@ -274,7 +272,7 @@ void Voxelization::renderVoxelVisualisation(
 	const vkcv::PushConstantData voxelVisualisationPushConstantData((void*)&viewProjectin, sizeof(glm::mat4));
 
 	const auto drawcall = vkcv::DrawcallInfo(
-		vkcv::Mesh({}, m_visualisationIndexBuffer.getVulkanHandle(), voxelCount),
+		vkcv::Mesh({}, nullptr, voxelCount),
 		{ vkcv::DescriptorSetUsage(0, m_corePtr->getDescriptorSet(m_visualisationDescriptorSet).vulkanHandle) });
 
 	m_corePtr->recordDrawcallsToCmdStream(
diff --git a/projects/voxelization/src/Voxelization.hpp b/projects/voxelization/src/Voxelization.hpp
index f0f88493..f9b96998 100644
--- a/projects/voxelization/src/Voxelization.hpp
+++ b/projects/voxelization/src/Voxelization.hpp
@@ -46,7 +46,6 @@ private:
 
 	vkcv::PassHandle            m_visualisationPass;
 	vkcv::PipelineHandle        m_visualisationPipe;
-	vkcv::Buffer<uint16_t>      m_visualisationIndexBuffer;
 
 	vkcv::DescriptorSetHandle   m_visualisationDescriptorSet;
 
diff --git a/src/vkcv/DrawcallRecording.cpp b/src/vkcv/DrawcallRecording.cpp
index 85b6eeb5..df7b7bbc 100644
--- a/src/vkcv/DrawcallRecording.cpp
+++ b/src/vkcv/DrawcallRecording.cpp
@@ -23,8 +23,6 @@ namespace vkcv {
                 nullptr);
         }
 
-        cmdBuffer.bindIndexBuffer(drawcall.mesh.indexBuffer, 0, vk::IndexType::eUint16);	//FIXME: choose proper size
-
         const size_t drawcallPushConstantOffset = drawcallIndex * pushConstantData.sizePerDrawcall;
         // char* cast because void* does not support pointer arithmetic
         const void* drawcallPushConstantData = drawcallPushConstantOffset + (char*)pushConstantData.data;
@@ -36,6 +34,12 @@ namespace vkcv {
             pushConstantData.sizePerDrawcall,
             drawcallPushConstantData);
 
-        cmdBuffer.drawIndexed(drawcall.mesh.indexCount, 1, 0, 0, {});
+        if (drawcall.mesh.indexBuffer) {
+            cmdBuffer.bindIndexBuffer(drawcall.mesh.indexBuffer, 0, vk::IndexType::eUint16);	//FIXME: choose proper size
+            cmdBuffer.drawIndexed(drawcall.mesh.indexCount, 1, 0, 0, {});
+        }
+        else {
+            cmdBuffer.draw(drawcall.mesh.indexCount, 1, 0, 0, {});
+        }
     }
 }
\ No newline at end of file
-- 
GitLab