mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 05:38:31 +09:00
[Chore] (MG_Test/Backend/DirectVulkan): encapsulate SwapchainObject
This commit is contained in:
@@ -8,15 +8,10 @@
|
||||
|
||||
#pragma once
|
||||
#include "Config.h"
|
||||
#include "SwapchainObject.h"
|
||||
#include <Includes.h>
|
||||
|
||||
#define VK_VERIFY(expr, ...) \
|
||||
do { \
|
||||
VkResult _vk_verify_result = (expr); \
|
||||
MOBILEGL_ASSERT(_vk_verify_result == VK_SUCCESS, "Vulkan error %d at %s:%d" __VA_OPT__(" - ") __VA_ARGS__, _vk_verify_result, __FILE__, __LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define ENUM_STR_CASE(c) case c: return #c;
|
||||
#include "../VkIncludes.h"
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
using RenderCallback = std::function<void(VkCommandBuffer cmdBuf, uint32_t imageIndex, VkExtent2D extent)>;
|
||||
@@ -48,20 +43,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
Int32 presentFamily = -1;
|
||||
};
|
||||
|
||||
struct SwapchainCapabilities {
|
||||
VkSurfaceCapabilitiesKHR capabilities;
|
||||
Vector<VkSurfaceFormatKHR> surfaceFormats;
|
||||
Vector<VkPresentModeKHR> presentModes;
|
||||
|
||||
Bool IsComplete() const {
|
||||
return !surfaceFormats.empty() && !presentModes.empty();
|
||||
}
|
||||
};
|
||||
|
||||
struct PhysicalDevice {
|
||||
QueueFamilyIndices queueFamilies;
|
||||
VkPhysicalDeviceProperties properties;
|
||||
SwapchainCapabilities swapchainCapabilities;
|
||||
VkPhysicalDevice handle = VK_NULL_HANDLE;
|
||||
|
||||
Bool IsComplete() const {
|
||||
@@ -83,12 +67,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice m_device = VK_NULL_HANDLE;
|
||||
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR m_swapchain = VK_NULL_HANDLE;
|
||||
VkSurfaceFormatKHR m_swapchainSurfaceFormat;
|
||||
Vector<VkImage> m_swapchainImages;
|
||||
Vector<VkImageLayout> m_swapchainImageLayouts;
|
||||
VkExtent2D m_swapchainExtent;
|
||||
Vector<VkImageView> m_swapchainImageViews;
|
||||
SwapchainObject m_swapchainObject;
|
||||
|
||||
// Vector<VkQueueFamilyProperties> m_queueFamilies;
|
||||
// QueueFamilyIndices m_queueFamilyIndices;
|
||||
@@ -120,7 +99,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
void PickPhysicalDevice();
|
||||
void CreateLogicalDeviceAndQueues();
|
||||
void CreateSwapchain();
|
||||
void CreateSwapchainImageViews();
|
||||
void CreateCommandPool();
|
||||
void CreateCommandBuffers();
|
||||
void CreateDefaultRenderPass();
|
||||
@@ -137,20 +115,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
static Int GetQueueFamilyIndex(const Vector<VkQueueFamilyProperties>& queueFamilies, VkQueueFlagBits flag);
|
||||
static Vector<VkExtensionProperties> EnumerateInstanceExtensions();
|
||||
static Bool IsNecessaryDeviceExtensionSupported(VkPhysicalDevice device);
|
||||
static SwapchainCapabilities GetSwapchainCapabilities(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface);
|
||||
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 VkDynamicState s_dynamicStates[] = {
|
||||
VK_DYNAMIC_STATE_VIEWPORT,
|
||||
VK_DYNAMIC_STATE_SCISSOR
|
||||
};
|
||||
static constexpr VkPresentModeKHR s_desiredPresentModes[] {
|
||||
VK_PRESENT_MODE_MAILBOX_KHR,
|
||||
VK_PRESENT_MODE_IMMEDIATE_KHR,
|
||||
VK_PRESENT_MODE_FIFO_RELAXED_KHR,
|
||||
VK_PRESENT_MODE_FIFO_KHR
|
||||
};
|
||||
static constexpr const char* s_validationLayerNames[] = {
|
||||
"VK_LAYER_KHRONOS_validation"
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user