summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/window.cpp13
-rw-r--r--src/window.hpp2
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 */