diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-10-17 17:16:05 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-10-17 17:16:05 -0400 |
| commit | df450f7344dff3451bb3627830956f6f933eaba3 (patch) | |
| tree | f0fa1a625aae40b4ac8a4466018ca8c9575ddecc /src/window.cpp | |
| parent | eff34c523b4816bb06ffbc19e6d368cac35f538c (diff) | |
red assert
Diffstat (limited to 'src/window.cpp')
| -rw-r--r-- | src/window.cpp | 126 |
1 files changed, 76 insertions, 50 deletions
diff --git a/src/window.cpp b/src/window.cpp index 6655c88..91e23f2 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -173,7 +173,8 @@ void BeginTransferBuffer(VkDeviceSize requestedMemorySize, VkBuffer &buffer, VkD transferBufferCI.sharingMode = VK_SHARING_MODE_EXCLUSIVE; transferBufferCI.queueFamilyIndexCount = 1; transferBufferCI.pQueueFamilyIndices = &transferFamilyIndex; - vkCreateBuffer(vkDevice, &transferBufferCI, vkAllocator, &buffer); + VkResult vkResult = vkCreateBuffer(vkDevice, &transferBufferCI, vkAllocator, &buffer); + assert(vkResult == VK_SUCCESS); VkMemoryRequirements memoryRequirements; vkGetBufferMemoryRequirements(vkDevice, buffer, &memoryRequirements); @@ -183,10 +184,13 @@ void BeginTransferBuffer(VkDeviceSize requestedMemorySize, VkBuffer &buffer, VkD transferMemAllocInfo.pNext = nullptr; transferMemAllocInfo.allocationSize = memoryRequirements.size; transferMemAllocInfo.memoryTypeIndex = FindMemoryTypeIndex(memoryRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); - vkAllocateMemory(vkDevice, &transferMemAllocInfo, vkAllocator, &deviceMemory); + vkResult = vkAllocateMemory(vkDevice, &transferMemAllocInfo, vkAllocator, &deviceMemory); + assert(vkResult == VK_SUCCESS); - vkBindBufferMemory(vkDevice, buffer, deviceMemory, 0); - vkMapMemory(vkDevice, deviceMemory, 0, transferMemAllocInfo.allocationSize, 0, &deviceData); + vkResult = vkBindBufferMemory(vkDevice, buffer, deviceMemory, 0); + assert(vkResult == VK_SUCCESS); + vkResult = vkMapMemory(vkDevice, deviceMemory, 0, transferMemAllocInfo.allocationSize, 0, &deviceData); + assert(vkResult == VK_SUCCESS); } void EndTransferBuffer(VkBuffer &buffer, VkDeviceMemory &deviceMemory) { @@ -215,7 +219,8 @@ unsigned int FindQueueFamilyIndex(VkPhysicalDevice device, short hasPresentSuppo } if (hasPresentSupport != -1) { VkBool32 presentSupport; - vkGetPhysicalDeviceSurfaceSupportKHR(device, i, vkSurfaceKHR, &presentSupport); + VkResult vkResult = vkGetPhysicalDeviceSurfaceSupportKHR(device, i, vkSurfaceKHR, &presentSupport); + assert(vkResult == VK_SUCCESS); if (presentSupport != hasPresentSupport) { continue; } @@ -230,11 +235,14 @@ unsigned int FindQueueFamilyIndex(VkPhysicalDevice device, short hasPresentSuppo void InitVulkan() { + VkResult vkResult; if (ENABLE_VALIDATION_LAYERS) { unsigned int layerCount; - vkEnumerateInstanceLayerProperties(&layerCount, nullptr); + vkResult = vkEnumerateInstanceLayerProperties(&layerCount, nullptr); + assert(vkResult == VK_SUCCESS); VkLayerProperties *availableLayerProperties = Pke_New<VkLayerProperties>(layerCount); - vkEnumerateInstanceLayerProperties(&layerCount, availableLayerProperties); + vkResult = vkEnumerateInstanceLayerProperties(&layerCount, availableLayerProperties); + assert(vkResult == VK_SUCCESS); printf("Available Layers:\n"); for (long i = 0; i < layerCount; ++i) { printf("\t%s\n", availableLayerProperties[i].layerName); @@ -307,9 +315,11 @@ void InitVulkan() { if (ENABLE_VALIDATION_LAYERS) { unsigned int extensionCount = 0; - vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); + vkResult = vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); + assert(vkResult == VK_SUCCESS); auto *extensions = Pke_New<VkExtensionProperties>(extensionCount); - vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions); + vkResult = vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions); + assert(vkResult == VK_SUCCESS); printf("Available Extensions:\n"); for (long i = 0; i < extensionCount; ++i) { printf("\t%s\n", extensions[i].extensionName); @@ -317,10 +327,10 @@ void InitVulkan() { Pke_Delete<VkExtensionProperties>(extensions, extensionCount); } - auto result = vkCreateInstance(&createInfo, nullptr, &vkInstance); - if (result != VK_SUCCESS) { - printf("Failed to create VkInstance! : %d\n", result); - throw result; + vkResult = vkCreateInstance(&createInfo, nullptr, &vkInstance); + if (vkResult != VK_SUCCESS) { + printf("Failed to create VkInstance! : %d\n", vkResult); + throw vkResult; } if (VULKAN_DEBUG_REPORT) { @@ -337,9 +347,9 @@ void InitVulkan() { debugReportCallbackCreateInfo.pfnCallback = DebugReport; debugReportCallbackCreateInfo.pUserData = nullptr; - result = func(vkInstance, &debugReportCallbackCreateInfo, nullptr, &vkDebugReport); + vkResult = func(vkInstance, &debugReportCallbackCreateInfo, nullptr, &vkDebugReport); - if (result != VK_SUCCESS) { + if (vkResult != VK_SUCCESS) { fprintf(stderr, "%s\n", "Failed to create debug report!"); } } @@ -351,10 +361,12 @@ void InitVulkan() { // pick physical device unsigned int physicalDeviceCount = 0; - vkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, nullptr); + vkResult = vkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, nullptr); + assert(vkResult == VK_SUCCESS); assert(physicalDeviceCount > 0); auto *physicalDevices = Pke_New<VkPhysicalDevice>(physicalDeviceCount); - vkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, physicalDevices); + vkResult = vkEnumeratePhysicalDevices(vkInstance, &physicalDeviceCount, physicalDevices); + assert(vkResult == VK_SUCCESS); graphicsFamilyIndex = 0; presentFamilyIndex = 0; for (long i = 0; i < physicalDeviceCount; ++i) @@ -370,9 +382,11 @@ void InitVulkan() { // check device extension support std::vector<const char *> requiredExtensions(REQUIRED_EXTENSIONS.begin(), REQUIRED_EXTENSIONS.end()); unsigned int extensionCount = 0; - vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr); + vkResult = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr); + assert(vkResult == VK_SUCCESS); auto *extensionProperties = Pke_New<VkExtensionProperties>(extensionCount); - vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, extensionProperties); + vkResult = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, extensionProperties); + assert(vkResult == VK_SUCCESS); for (long k = 0; k < extensionCount; ++k) { const auto &property = extensionProperties[k]; auto it = requiredExtensions.begin(); @@ -391,14 +405,16 @@ void InitVulkan() { // surface formats unsigned int surfaceCount = 0; - vkGetPhysicalDeviceSurfaceFormatsKHR(device, vkSurfaceKHR, &surfaceCount, nullptr); + vkResult = vkGetPhysicalDeviceSurfaceFormatsKHR(device, vkSurfaceKHR, &surfaceCount, nullptr); + assert(vkResult == VK_SUCCESS); if (surfaceCount == 0) { continue; } // check present modes unsigned int presentModeCount = 0; - vkGetPhysicalDeviceSurfacePresentModesKHR(device, vkSurfaceKHR, &presentModeCount, nullptr); + vkResult = vkGetPhysicalDeviceSurfacePresentModesKHR(device, vkSurfaceKHR, &presentModeCount, nullptr); + assert(vkResult == VK_SUCCESS); if (presentModeCount == 0) { continue; } @@ -467,10 +483,10 @@ void InitVulkan() { vkDeviceCreateInfo.ppEnabledExtensionNames = REQUIRED_EXTENSIONS.data(); vkDeviceCreateInfo.pEnabledFeatures = &requestedFeatures; - result = vkCreateDevice(vkPhysicalDevice, &vkDeviceCreateInfo, vkAllocator, &vkDevice); - if (result != VK_SUCCESS) { - printf("Failed to create VkInstance! : %d\n", result); - throw result; + vkResult = vkCreateDevice(vkPhysicalDevice, &vkDeviceCreateInfo, vkAllocator, &vkDevice); + if (vkResult != VK_SUCCESS) { + printf("Failed to create VkInstance! : %d\n", vkResult); + throw vkResult; } } @@ -531,12 +547,15 @@ void InitVulkan() { samplerCreateInfo.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE; samplerCreateInfo.unnormalizedCoordinates = {}; - vkCreateSampler(vkDevice, &samplerCreateInfo, vkAllocator, &presentSampler); + vkResult = vkCreateSampler(vkDevice, &samplerCreateInfo, vkAllocator, &presentSampler); + assert(vkResult == VK_SUCCESS); } void CreateImageResources_Inner(VkImageCreateInfo *imageCreateInfo, VkImageViewCreateInfo *imageViewCreateInfo, VkBufferUsageFlagBits bufferUsageFlagBits, VkBuffer *imagesBuffer, VkImage *images, VkImageView *imageViews, VkDeviceMemory *deviceMemory) { VkImage tmpImage; - vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &tmpImage); + VkResult vkResult; + vkResult = vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &tmpImage); + assert(vkResult == VK_SUCCESS); VkMemoryRequirements imageMemoryRequirements; vkGetImageMemoryRequirements(vkDevice, tmpImage, &imageMemoryRequirements); @@ -553,33 +572,37 @@ void CreateImageResources_Inner(VkImageCreateInfo *imageCreateInfo, VkImageViewC vkMemoryAllocateInfo.memoryTypeIndex = FindMemoryTypeIndex(imageMemoryRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, deviceMemory); + vkResult = vkAllocateMemory(vkDevice, &vkMemoryAllocateInfo, vkAllocator, deviceMemory); + assert(vkResult == VK_SUCCESS); for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { - VkResult result; - result = vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &images[i]); - assert(result == VK_SUCCESS); - result = vkBindImageMemory(vkDevice, images[i], *deviceMemory, paddedImageSize * i); - assert(result == VK_SUCCESS); + vkResult = vkCreateImage(vkDevice, imageCreateInfo, vkAllocator, &images[i]); + assert(vkResult == VK_SUCCESS); + vkResult = vkBindImageMemory(vkDevice, images[i], *deviceMemory, paddedImageSize * i); + assert(vkResult == VK_SUCCESS); imageViewCreateInfo->image = images[i]; - result = vkCreateImageView(vkDevice, imageViewCreateInfo, vkAllocator, &imageViews[i]); - assert(result == VK_SUCCESS); + vkResult = vkCreateImageView(vkDevice, imageViewCreateInfo, vkAllocator, &imageViews[i]); + assert(vkResult == VK_SUCCESS); } } void CreateSwapchain() { + VkResult vkResult; VkSurfaceCapabilitiesKHR surfaceCapabilities; - vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vkPhysicalDevice, vkSurfaceKHR, &surfaceCapabilities); + vkResult = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vkPhysicalDevice, vkSurfaceKHR, &surfaceCapabilities); + assert(vkResult == VK_SUCCESS); assert(MAX_FRAMES_IN_FLIGHT >= surfaceCapabilities.minImageCount); assert(surfaceCapabilities.maxImageCount == 0 || MAX_FRAMES_IN_FLIGHT <= surfaceCapabilities.maxImageCount); if (selectedSurfaceIndex == -1u) { unsigned int surfaceFormatCounts; - vkGetPhysicalDeviceSurfaceFormatsKHR(vkPhysicalDevice, vkSurfaceKHR, &surfaceFormatCounts, nullptr); + vkResult = vkGetPhysicalDeviceSurfaceFormatsKHR(vkPhysicalDevice, vkSurfaceKHR, &surfaceFormatCounts, nullptr); + assert(vkResult == VK_SUCCESS); VkSurfaceFormatKHR *surfaceFormats = Pke_New<VkSurfaceFormatKHR>(surfaceFormatCounts); - vkGetPhysicalDeviceSurfaceFormatsKHR(vkPhysicalDevice, vkSurfaceKHR, &surfaceFormatCounts, surfaceFormats); + vkResult = vkGetPhysicalDeviceSurfaceFormatsKHR(vkPhysicalDevice, vkSurfaceKHR, &surfaceFormatCounts, surfaceFormats); + assert(vkResult == VK_SUCCESS); selectedSurfaceIndex = 0; for (long i = 0; i < surfaceFormatCounts; ++i) { if (surfaceFormats[i].format != VkFormat::VK_FORMAT_B8G8R8A8_SRGB) continue; @@ -606,9 +629,11 @@ void CreateSwapchain() { vkPresentModeKHR = VK_PRESENT_MODE_FIFO_KHR; if (pkeSettings.graphicsSettings.isWaitingForVsync == false || pkeSettings.graphicsSettings.isFramerateUnlocked == true) { unsigned int presentModeCount = 0; - vkGetPhysicalDeviceSurfacePresentModesKHR(vkPhysicalDevice, vkSurfaceKHR, &presentModeCount, nullptr); + vkResult = vkGetPhysicalDeviceSurfacePresentModesKHR(vkPhysicalDevice, vkSurfaceKHR, &presentModeCount, nullptr); + assert(vkResult == VK_SUCCESS); VkPresentModeKHR *presentModes = Pke_New<VkPresentModeKHR>(presentModeCount); - vkGetPhysicalDeviceSurfacePresentModesKHR(vkPhysicalDevice, vkSurfaceKHR, &presentModeCount, presentModes); + vkResult = vkGetPhysicalDeviceSurfacePresentModesKHR(vkPhysicalDevice, vkSurfaceKHR, &presentModeCount, presentModes); + assert(vkResult == VK_SUCCESS); uint32_t immediateIndex = -1; uint32_t fifoRelaxedIndex = -1; /* @@ -677,7 +702,7 @@ void CreateSwapchain() { vkSwapchainCreateInfo.queueFamilyIndexCount = 0; } - VkResult vkResult = vkCreateSwapchainKHR(vkDevice, &vkSwapchainCreateInfo, vkAllocator, &vkSwapchainKHR); + vkResult = vkCreateSwapchainKHR(vkDevice, &vkSwapchainCreateInfo, vkAllocator, &vkSwapchainKHR); assert(vkResult == VK_SUCCESS); VkImageSubresourceRange vkImageSubresourceRange; @@ -1061,8 +1086,8 @@ void CreatePresentPipeline() { descriptorSetLayoutCreateInfo.bindingCount = 1; descriptorSetLayoutCreateInfo.pBindings = &imageSamplerLayoutBinding; - auto result = vkCreateDescriptorSetLayout(vkDevice, &descriptorSetLayoutCreateInfo, vkAllocator, &vkDescriptorSetLayout); - if (result != VK_SUCCESS) { + auto vkResult = vkCreateDescriptorSetLayout(vkDevice, &descriptorSetLayoutCreateInfo, vkAllocator, &vkDescriptorSetLayout); + if (vkResult != VK_SUCCESS) { throw "failed to create descriptor set layout"; } @@ -1078,7 +1103,8 @@ void CreatePresentPipeline() { descriptorPoolCreateInfo.poolSizeCount = 1; descriptorPoolCreateInfo.pPoolSizes = &vkDescriptorPoolSize; - vkCreateDescriptorPool(vkDevice, &descriptorPoolCreateInfo, vkAllocator, &presentDescriptorPool); + vkResult = vkCreateDescriptorPool(vkDevice, &descriptorPoolCreateInfo, vkAllocator, &presentDescriptorPool); + assert(vkResult == VK_SUCCESS); VkDescriptorSetLayout setLayouts[MAX_FRAMES_IN_FLIGHT]; for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { @@ -1091,8 +1117,8 @@ void CreatePresentPipeline() { allocInfo.descriptorSetCount = MAX_FRAMES_IN_FLIGHT; allocInfo.pSetLayouts = setLayouts; - result = vkAllocateDescriptorSets(vkDevice, &allocInfo, presentDescriptorSets); - if (result != VK_SUCCESS) { + vkResult = vkAllocateDescriptorSets(vkDevice, &allocInfo, presentDescriptorSets); + if (vkResult != VK_SUCCESS) { throw "failed to allocate present descriptor sets"; } @@ -1105,8 +1131,8 @@ void CreatePresentPipeline() { pipelineLayoutInfo.pushConstantRangeCount = 0; pipelineLayoutInfo.pPushConstantRanges = nullptr; - result = vkCreatePipelineLayout(vkDevice, &pipelineLayoutInfo, vkAllocator, &pipelineLayout); - if (result != VK_SUCCESS) { + vkResult = vkCreatePipelineLayout(vkDevice, &pipelineLayoutInfo, vkAllocator, &pipelineLayout); + if (vkResult != VK_SUCCESS) { throw "failed to create pipeline layout"; } @@ -1133,8 +1159,8 @@ void CreatePresentPipeline() { pipelineInfo.basePipelineHandle = VK_NULL_HANDLE; pipelineInfo.basePipelineIndex = {}; - result = vkCreateGraphicsPipelines(vkDevice, VK_NULL_HANDLE, 1, &pipelineInfo, vkAllocator, &graphicsPipeline); - if (result != VK_SUCCESS) { + vkResult = vkCreateGraphicsPipelines(vkDevice, VK_NULL_HANDLE, 1, &pipelineInfo, vkAllocator, &graphicsPipeline); + if (vkResult != VK_SUCCESS) { throw "failed to create graphics pipeline."; } |
