diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-09-07 22:43:29 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-09-07 22:43:29 -0400 |
| commit | ccc2759ad777c9b289d4ae4f48bb25890296e8ae (patch) | |
| tree | 9d0db6efca3df2ea7df2804bcd989bbb4d5d38d1 | |
| parent | 8f4ccd91072415aa56ab609d1eeafe416b00e0a3 (diff) | |
window add and expose FindMemoryTypeIndex function
| -rw-r--r-- | src/window.cpp | 13 | ||||
| -rw-r--r-- | src/window.hpp | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/window.cpp b/src/window.cpp index 3eea64c..47b328c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -15,6 +15,7 @@ GLFWwindow *window = nullptr; VkInstance vkInstance = nullptr; VkPhysicalDevice vkPhysicalDevice = nullptr; VkPhysicalDeviceProperties vkPhysicalDeviceProperties; +VkPhysicalDeviceMemoryProperties vkPhysicalDeviceMemoryProperties; VkDevice vkDevice = nullptr; VkQueue graphicsQueue = nullptr; VkQueue presentQueue = nullptr; @@ -98,6 +99,16 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL DebugReport(VkDebugReportFlagsEXT flags, V return VK_FALSE; } +unsigned int FindMemoryTypeIndex(uint32_t typeFilter, VkMemoryPropertyFlags memPropertyFlags) { + for (uint32_t i = 0; i < vkPhysicalDeviceMemoryProperties.memoryTypeCount; i++) { + if ((typeFilter & (1 << i)) && (vkPhysicalDeviceMemoryProperties.memoryTypes[i].propertyFlags & memPropertyFlags) == memPropertyFlags) { + return i; + } + } + fprintf(stdout, "[vulkan] Failed to find appropriate memory type index: typeFilter: %u - memPropertyFlags: %u\n", typeFilter, memPropertyFlags); + return 0; +} + unsigned int FindQueueFamilyIndex(VkPhysicalDevice device, short hasPresentSupport = -1, VkQueueFlagBits includeBits = (VkQueueFlagBits)0U, VkQueueFlagBits excludeBits = (VkQueueFlagBits)0U) { if (hasPresentSupport == -1 && includeBits == 0 && excludeBits == 0) { @@ -302,6 +313,8 @@ void InitVulkan() { vkPhysicalDevice = device; vkGetPhysicalDeviceProperties(vkPhysicalDevice, &vkPhysicalDeviceProperties); printf("Selected VkPhysicalDevice: %s\n", vkPhysicalDeviceProperties.deviceName); + + vkGetPhysicalDeviceMemoryProperties(vkPhysicalDevice, &vkPhysicalDeviceMemoryProperties); break; } assert(vkPhysicalDevice != nullptr && "Failed to find suitable physical device"); diff --git a/src/window.hpp b/src/window.hpp index 05a5ae9..423dd14 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -35,4 +35,6 @@ void DestroyWindow(); VkShaderModule UploadShader(AssetHandle handle); void Render(); +unsigned int FindMemoryTypeIndex(uint32_t typeFilter, VkMemoryPropertyFlags memPropertyFlags); + #endif /* PKE_WINDOW_HPP */ |
