-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrtl_solo.c
More file actions
82 lines (59 loc) · 2.09 KB
/
trtl_solo.c
File metadata and controls
82 lines (59 loc) · 2.09 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <assert.h>
#include <talloc.h>
#include <vulkan/vulkan.h>
#include "trtl_solo.h"
static VkCommandPool solo_pool;
static VkDevice solo_device;
static VkQueue solo_queue;
struct trtl_solo_internal {
struct trtl_solo solo;
};
// FIXME: Proper decleration in a header file
VkCommandPool create_command_pool(VkDevice device, VkPhysicalDevice physical_device,
VkSurfaceKHR surface);
void
trtl_solo_init(VkDevice device, VkQueue queue, uint32_t graphics_family)
{
// Create a command pool for us
VkCommandPoolCreateInfo pool_info = {0};
pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
pool_info.queueFamilyIndex = graphics_family;
// FIXME: Should check this
pool_info.flags = 0;
solo_device = device;
solo_queue = queue;
assert(vkCreateCommandPool(device, &pool_info, NULL, &solo_pool) == 0);
}
static int
trtl_solo_destroy(struct trtl_solo_internal *solo)
{
vkEndCommandBuffer(solo->solo.command_buffer);
VkSubmitInfo submit_info = {0};
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &solo->solo.command_buffer;
vkQueueSubmit(solo_queue, 1, &submit_info, VK_NULL_HANDLE);
vkQueueWaitIdle(solo_queue);
vkFreeCommandBuffers(solo_device, solo_pool, 1, &solo->solo.command_buffer);
return 0;
}
struct trtl_solo *
trtl_solo_start(void)
{
struct trtl_solo_internal *solo;
solo = talloc_zero(NULL, struct trtl_solo_internal);
talloc_set_destructor(solo, trtl_solo_destroy);
VkCommandBufferAllocateInfo alloc_info = {0};
alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
alloc_info.commandPool = solo_pool;
alloc_info.commandBufferCount = 1;
VkCommandBuffer command_buffer;
vkAllocateCommandBuffers(solo_device, &alloc_info, &command_buffer);
VkCommandBufferBeginInfo beginInfo = {0};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
vkBeginCommandBuffer(command_buffer, &beginInfo);
solo->solo.command_buffer = command_buffer;
return &solo->solo;
}