From 621fd54575f7004714ed9e9018b5841b990b3c41 Mon Sep 17 00:00:00 2001
From: Tobias Frisch <tfrisch@uni-koblenz.de>
Date: Fri, 9 Jul 2021 12:05:40 +0200
Subject: [PATCH] [#56] Reduced code in first_triangle example

Signed-off-by: Tobias Frisch <tfrisch@uni-koblenz.de>
---
 projects/first_triangle/src/main.cpp | 108 +--------------------------
 1 file changed, 3 insertions(+), 105 deletions(-)

diff --git a/projects/first_triangle/src/main.cpp b/projects/first_triangle/src/main.cpp
index db175a80..43095fbb 100644
--- a/projects/first_triangle/src/main.cpp
+++ b/projects/first_triangle/src/main.cpp
@@ -27,57 +27,16 @@ int main(int argc, const char** argv) {
 		{},
 		{ "VK_KHR_swapchain" }
 	);
-	
-	vkcv::gui::GUI gui (core, window);
 
 	const auto& context = core.getContext();
 	const vk::Instance& instance = context.getInstance();
 	const vk::PhysicalDevice& physicalDevice = context.getPhysicalDevice();
 	const vk::Device& device = context.getDevice();
 
-	struct vec3 {
-		float x, y, z;
-	};
-
-	const size_t n = 5027;
-
-	auto testBuffer = core.createBuffer<vec3>(vkcv::BufferType::VERTEX, n, vkcv::BufferMemoryType::DEVICE_LOCAL);
-	vec3 vec_data[n];
-
-	for (size_t i = 0; i < n; i++) {
-		vec_data[i] = { 42, static_cast<float>(i), 7 };
-	}
-
-	testBuffer.fill(vec_data);
-
-	auto triangleIndexBuffer = core.createBuffer<uint16_t>(vkcv::BufferType::INDEX, n, vkcv::BufferMemoryType::DEVICE_LOCAL);
+	auto triangleIndexBuffer = core.createBuffer<uint16_t>(vkcv::BufferType::INDEX, 3, vkcv::BufferMemoryType::DEVICE_LOCAL);
 	uint16_t indices[3] = { 0, 1, 2 };
 	triangleIndexBuffer.fill(&indices[0], sizeof(indices));
 
-	/*vec3* m = buffer.map();
-	m[0] = { 0, 0, 0 };
-	m[1] = { 0, 0, 0 };
-	m[2] = { 0, 0, 0 };
-	buffer.unmap();*/
-
-	vkcv::SamplerHandle sampler = core.createSampler(
-		vkcv::SamplerFilterType::NEAREST,
-		vkcv::SamplerFilterType::NEAREST,
-		vkcv::SamplerMipmapMode::NEAREST,
-		vkcv::SamplerAddressMode::REPEAT
-	);
-
-	std::cout << "Physical device: " << physicalDevice.getProperties().deviceName << std::endl;
-
-	switch (physicalDevice.getProperties().vendorID) {
-	case 0x1002: std::cout << "Running AMD huh? You like underdogs, are you a Linux user?" << std::endl; break;
-	case 0x10DE: std::cout << "An NVidia GPU, how predictable..." << std::endl; break;
-	case 0x8086: std::cout << "Poor child, running on an Intel GPU, probably integrated..."
-		"or perhaps you are from the future with a dedicated one?" << std::endl; break;
-	case 0x13B5: std::cout << "ARM? What the hell are you running on, next thing I know you're trying to run Vulkan on a leg..." << std::endl; break;
-	default: std::cout << "Unknown GPU vendor?! Either you're on an exotic system or your driver is broken..." << std::endl;
-	}
-
 	// an example attachment for passes that output to the window
 	const vkcv::AttachmentDescription present_color_attachment(
 		vkcv::AttachmentOperation::STORE,
@@ -123,49 +82,9 @@ int main(int argc, const char** argv) {
 		std::cout << "Error. Could not create graphics pipeline. Exiting." << std::endl;
 		return EXIT_FAILURE;
 	}
-
-	// Compute Pipeline
-	vkcv::ShaderProgram computeShaderProgram{};
-	computeShaderProgram.addShader(vkcv::ShaderStage::COMPUTE, std::filesystem::path("shaders/comp.spv"));
-
-	// take care, assuming shader has exactly one descriptor set
-	vkcv::DescriptorSetHandle computeDescriptorSet = core.createDescriptorSet(computeShaderProgram.getReflectedDescriptors()[0]);
-
-	vkcv::PipelineHandle computePipeline = core.createComputePipeline(
-		computeShaderProgram, 
-		{ core.getDescriptorSet(computeDescriptorSet).layout });
-
-	struct ComputeTestBuffer {
-		float test1[10];
-		float test2[10];
-		float test3[10];
-	};
-
-	vkcv::Buffer computeTestBuffer = core.createBuffer<ComputeTestBuffer>(vkcv::BufferType::STORAGE, 1);
-
-	vkcv::DescriptorWrites computeDescriptorWrites;
-	computeDescriptorWrites.storageBufferWrites = { vkcv::StorageBufferDescriptorWrite(0, computeTestBuffer.getHandle()) };
-	core.writeDescriptorSet(computeDescriptorSet, computeDescriptorWrites);
-
-	/*
-	 * BufferHandle triangleVertices = core.createBuffer(vertices);
-	 * BufferHandle triangleIndices = core.createBuffer(indices);
-	 *
-	 * // triangle Model creation goes here
-	 *
-	 *
-	 * // attachment creation goes here
-	 * PassHandle trianglePass = core.CreatePass(presentationPass);
-	 *
-	 * // shader creation goes here
-	 * // material creation goes here
-	 *
-	 * PipelineHandle trianglePipeline = core.CreatePipeline(trianglePipeline);
-	 */
+	
 	auto start = std::chrono::system_clock::now();
 
-	vkcv::ImageHandle swapchainImageHandle = vkcv::ImageHandle::createSwapchainImageHandle();
-
 	const vkcv::Mesh renderMesh({}, triangleIndexBuffer.getVulkanHandle(), 3);
 	vkcv::DrawcallInfo drawcall(renderMesh, {},1);
 
@@ -181,7 +100,7 @@ int main(int argc, const char** argv) {
 
 	while (window.isWindowOpen())
 	{
-        window.pollEvents();
+        vkcv::Window::pollEvents();
 
 		uint32_t swapchainWidth, swapchainHeight; // No resizing = No problem
 		if (!core.beginFrame(swapchainWidth, swapchainHeight)) {
@@ -208,29 +127,8 @@ int main(int argc, const char** argv) {
 			{ drawcall },
 			{ swapchainInput });
 
-		const uint32_t dispatchSize[3] = { 2, 1, 1 };
-		const float theMeaningOfLife = 42;
-		
-		vkcv::PushConstants pushConstantsCompute (sizeof(theMeaningOfLife));
-		pushConstantsCompute.appendDrawcall(theMeaningOfLife);
-
-		core.recordComputeDispatchToCmdStream(
-			cmdStream,
-			computePipeline,
-			dispatchSize,
-			{ vkcv::DescriptorSetUsage(0, core.getDescriptorSet(computeDescriptorSet).vulkanHandle) },
-			pushConstantsCompute);
-
 		core.prepareSwapchainImageForPresent(cmdStream);
 		core.submitCommandStream(cmdStream);
-		
-		gui.beginGUI();
-		
-		ImGui::Begin("Hello world");
-		ImGui::Text("This is a test!");
-		ImGui::End();
-		
-		gui.endGUI();
 	    
 	    core.endFrame();
 	}
-- 
GitLab