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
struct Vulkan_Framebuffers
{
	uint32_t imageIndex;
	VkImageView view;
	VkFramebuffer frameBuffer;
	// Allocation for all images (Win32_Alloc, ok for now)
	VkImage* images;
};

struct Vulkan_Queue
{
	VkQueue queue;
	VkSemaphore semaphoreSubmit;
};

struct VulkanSystem
{
	VkInstance instance;
	VkPhysicalDevice physicalDevice;
	VkDevice device;

	VkSurfaceKHR surfaceKHR;
	VkSwapchainKHR swapchainKHR;

	VkSemaphore semaphoreNextImage;

	VkCommandBuffer commandBuffer;
	VkCommandPool commandPool;

	Vulkan_Framebuffers frameBuffers;
	Vulkan_Queue queue;

	VkRenderPass renderPass;
};



// Get the Swapchain images
int GetSwapchainImages(VkDevice device, VkSwapchainKHR swapchain, VkSemaphore semaphore, VkImage** pImages, uint32_t* pImageIndex)
{
	VkResult res;

	uint32_t swapchainCount;

	res = vkGetSwapchainImagesKHR(device, swapchain, &swapchainCount, 0);
	if (res != VK_SUCCESS)
		return 1;

	VkImage* image = (VkImage*)Win32_Alloc(sizeof(VkImage)*swapchainCount);
	res = vkGetSwapchainImagesKHR(device, swapchain, &swapchainCount, image);
	if (res != VK_SUCCESS)
		return 1;

	uint32_t imageIndex;
	res = vkAcquireNextImageKHR(device, swapchain, 0, semaphore, 0, &imageIndex);

	VkImage images = image[imageIndex];

	*pImages = image;
	*pImageIndex = imageIndex;

	//Win32_Free(image);

	return res;
}