mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-10 21:28:32 +09:00
[Feat] (MG_Backend/DirectVulkan): inspect ChooseSwapchainSurfaceFormat, ChooseSwapchainPresentMode
This commit is contained in:
@@ -67,16 +67,30 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VulkanRenderer::Shutdown() {
|
void VulkanRenderer::Shutdown() {
|
||||||
if (m_device != VK_NULL_HANDLE)
|
if (m_swapchain != VK_NULL_HANDLE) {
|
||||||
|
vkDestroySwapchainKHR(m_device, m_swapchain, nullptr);
|
||||||
|
m_swapchain = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_device != VK_NULL_HANDLE) {
|
||||||
vkDestroyDevice(m_device, nullptr);
|
vkDestroyDevice(m_device, nullptr);
|
||||||
|
m_device = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_surface != VK_NULL_HANDLE)
|
if (m_surface != VK_NULL_HANDLE) {
|
||||||
vkDestroySurfaceKHR(m_instance, m_surface, nullptr);
|
vkDestroySurfaceKHR(m_instance, m_surface, nullptr);
|
||||||
|
m_surface = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_debugMessenger != VK_NULL_HANDLE)
|
if (m_debugMessenger != VK_NULL_HANDLE) {
|
||||||
DestroyDebugMessenger();
|
DestroyDebugMessenger();
|
||||||
|
m_debugMessenger = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
DestroyInstance();
|
if (m_instance != VK_NULL_HANDLE) {
|
||||||
|
vkDestroyInstance(m_instance, nullptr);
|
||||||
|
m_instance = VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
MGLOG_I("VulkanRenderer shut down completed");
|
MGLOG_I("VulkanRenderer shut down completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,13 +174,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
VK_VERIFY(SetupDebugMessenger());
|
VK_VERIFY(SetupDebugMessenger());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VulkanRenderer::DestroyInstance() {
|
|
||||||
if (m_instance != VK_NULL_HANDLE) {
|
|
||||||
vkDestroyInstance(m_instance, nullptr);
|
|
||||||
m_instance = VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VkResult VulkanRenderer::SetupDebugMessenger() {
|
VkResult VulkanRenderer::SetupDebugMessenger() {
|
||||||
auto createInfo = PopulateDebugMessengerCreateInfo();
|
auto createInfo = PopulateDebugMessengerCreateInfo();
|
||||||
auto vkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(m_instance, "vkCreateDebugUtilsMessengerEXT");
|
auto vkCreateDebugUtilsMessengerEXT = (PFN_vkCreateDebugUtilsMessengerEXT) vkGetInstanceProcAddr(m_instance, "vkCreateDebugUtilsMessengerEXT");
|
||||||
@@ -314,6 +321,32 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkSurfaceFormatKHR VulkanRenderer::ChooseSwapchainSurfaceFormat(
|
||||||
|
const Vector<VkSurfaceFormatKHR>& availableFormats) {
|
||||||
|
for (const auto& availableFormat : availableFormats) {
|
||||||
|
if (availableFormat.format == VK_FORMAT_B8G8R8A8_SRGB && availableFormat.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR) {
|
||||||
|
return availableFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Properly rank other formats
|
||||||
|
return availableFormats[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
VkPresentModeKHR VulkanRenderer::ChooseSwapchainPresentMode(
|
||||||
|
const Vector<VkPresentModeKHR>& availablePresentModes) {
|
||||||
|
for (const auto& presentMode : availablePresentModes) {
|
||||||
|
if (presentMode == VK_PRESENT_MODE_IMMEDIATE_KHR) {
|
||||||
|
return presentMode;
|
||||||
|
} else if (presentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
|
||||||
|
return presentMode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Properly rank other modes
|
||||||
|
return availablePresentModes[0];
|
||||||
|
}
|
||||||
|
|
||||||
Bool VulkanRenderer::IsNecessaryDeviceExtensionSupported(VkPhysicalDevice device) {
|
Bool VulkanRenderer::IsNecessaryDeviceExtensionSupported(VkPhysicalDevice device) {
|
||||||
Uint32 extensionCount = 0;
|
Uint32 extensionCount = 0;
|
||||||
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);
|
vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionCount, nullptr);
|
||||||
@@ -412,6 +445,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
MGLOG_I("Queues got successfully.");
|
MGLOG_I("Queues got successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VulkanRenderer::CreateSwapchain() {}
|
||||||
|
|
||||||
void VulkanRenderer::CreateSurface() {
|
void VulkanRenderer::CreateSurface() {
|
||||||
#if defined VK_USE_PLATFORM_ANDROID_KHR
|
#if defined VK_USE_PLATFORM_ANDROID_KHR
|
||||||
auto* nativeWindow = static_cast<ANativeWindow*>(m_window);
|
auto* nativeWindow = static_cast<ANativeWindow*>(m_window);
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
// VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
|
// VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
|
||||||
VkDevice m_device = VK_NULL_HANDLE;
|
VkDevice m_device = VK_NULL_HANDLE;
|
||||||
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
|
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
|
||||||
|
VkSwapchainKHR m_swapchain = VK_NULL_HANDLE;
|
||||||
|
|
||||||
// Vector<VkQueueFamilyProperties> m_queueFamilies;
|
// Vector<VkQueueFamilyProperties> m_queueFamilies;
|
||||||
// QueueFamilyIndices m_queueFamilyIndices;
|
// QueueFamilyIndices m_queueFamilyIndices;
|
||||||
@@ -92,13 +93,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
VkQueue m_presentQueue = VK_NULL_HANDLE;
|
VkQueue m_presentQueue = VK_NULL_HANDLE;
|
||||||
|
|
||||||
void CreateInstance();
|
void CreateInstance();
|
||||||
void DestroyInstance();
|
|
||||||
VkResult SetupDebugMessenger();
|
VkResult SetupDebugMessenger();
|
||||||
VkResult DestroyDebugMessenger();
|
VkResult DestroyDebugMessenger();
|
||||||
VkDebugUtilsMessengerCreateInfoEXT PopulateDebugMessengerCreateInfo();
|
VkDebugUtilsMessengerCreateInfoEXT PopulateDebugMessengerCreateInfo();
|
||||||
|
void CreateSurface();
|
||||||
void PickPhysicalDevice();
|
void PickPhysicalDevice();
|
||||||
void CreateLogicalDeviceAndQueues();
|
void CreateLogicalDeviceAndQueues();
|
||||||
void CreateSurface();
|
void CreateSwapchain();
|
||||||
|
|
||||||
static Int GetPresentQueueFamilyIndex(
|
static Int GetPresentQueueFamilyIndex(
|
||||||
const PhysicalDevice& physicalDevice, VkSurfaceKHR surface,
|
const PhysicalDevice& physicalDevice, VkSurfaceKHR surface,
|
||||||
@@ -109,6 +110,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
static Bool IsNecessaryDeviceExtensionSupported(VkPhysicalDevice device);
|
static Bool IsNecessaryDeviceExtensionSupported(VkPhysicalDevice device);
|
||||||
static SwapchainCapabilities GetSwapchainCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
|
static SwapchainCapabilities GetSwapchainCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
|
||||||
static Bool GetMoreCapablePhysicalDevice(VkPhysicalDevice newVkDevice, VkSurfaceKHR surface, const PhysicalDevice& compareWithDevice, PhysicalDevice& outBetterDevice);
|
static Bool GetMoreCapablePhysicalDevice(VkPhysicalDevice newVkDevice, VkSurfaceKHR surface, const PhysicalDevice& compareWithDevice, PhysicalDevice& outBetterDevice);
|
||||||
|
static VkSurfaceFormatKHR ChooseSwapchainSurfaceFormat(const Vector<VkSurfaceFormatKHR>& availableFormats);
|
||||||
|
static VkPresentModeKHR ChooseSwapchainPresentMode(const Vector<VkPresentModeKHR>& availablePresentModes);
|
||||||
static constexpr const char* s_validationLayerNames[] = {
|
static constexpr const char* s_validationLayerNames[] = {
|
||||||
"VK_LAYER_KHRONOS_validation"
|
"VK_LAYER_KHRONOS_validation"
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user