summaryrefslogtreecommitdiff
path: root/src/utils.c
blob: 5b3b87ddc057079fa8dfcf600b4e75c291f1530e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "utils.h"
#include "renderer.h"

VkCommandBuffer begin_single_command(struct vlkn_renderer *ren) {
	VkCommandBufferAllocateInfo alloc_info = {
		.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
		.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
		.commandPool = ren->command.pool,
		.commandBufferCount = 1
	};

	VkCommandBuffer buffer;
	vkAllocateCommandBuffers(ren->gpu.device, &alloc_info, &buffer);

	VkCommandBufferBeginInfo begin_info = {
		.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
		.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
	};

	vkBeginCommandBuffer(buffer, &begin_info);

	return buffer;
}

void end_single_command(struct vlkn_renderer *ren, VkCommandBuffer buffer) {
	vkEndCommandBuffer(buffer);

	VkSubmitInfo submit_info = {
		.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
		.commandBufferCount = 1,
		.pCommandBuffers = &buffer
	};

	vkQueueSubmit(ren->gpu.gfx_queue, 1, &submit_info, VK_NULL_HANDLE);
	vkQueueWaitIdle(ren->gpu.gfx_queue);

	vkFreeCommandBuffers(ren->gpu.device, ren->command.pool, 1, &buffer);
}