forked from MoonsideGames/Refresh
Compare commits
No commits in common. "e62b5b919ce4a46bddda1fd106a7f91d4b4bed99" and "fabd31448bf642f7a4800b34c212cdf453ec10f8" have entirely different histories.
e62b5b919c
...
fabd31448b
|
@ -9,7 +9,7 @@ option(BUILD_SHARED_LIBS "Build shared library" ON)
|
||||||
# Version
|
# Version
|
||||||
SET(LIB_MAJOR_VERSION "1")
|
SET(LIB_MAJOR_VERSION "1")
|
||||||
SET(LIB_MINOR_VERSION "8")
|
SET(LIB_MINOR_VERSION "8")
|
||||||
SET(LIB_REVISION "2")
|
SET(LIB_REVISION "0")
|
||||||
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
|
SET(LIB_VERSION "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_REVISION}")
|
||||||
|
|
||||||
# Build Type
|
# Build Type
|
||||||
|
|
|
@ -56,7 +56,7 @@ extern "C" {
|
||||||
|
|
||||||
#define REFRESH_MAJOR_VERSION 1
|
#define REFRESH_MAJOR_VERSION 1
|
||||||
#define REFRESH_MINOR_VERSION 8
|
#define REFRESH_MINOR_VERSION 8
|
||||||
#define REFRESH_PATCH_VERSION 2
|
#define REFRESH_PATCH_VERSION 0
|
||||||
|
|
||||||
#define REFRESH_COMPILED_VERSION ( \
|
#define REFRESH_COMPILED_VERSION ( \
|
||||||
(REFRESH_MAJOR_VERSION * 100 * 100) + \
|
(REFRESH_MAJOR_VERSION * 100 * 100) + \
|
||||||
|
|
|
@ -77,7 +77,7 @@ static uint32_t deviceExtensionCount = SDL_arraysize(deviceExtensionNames);
|
||||||
#define UBO_BUFFER_SIZE 16000 /* 16KB */
|
#define UBO_BUFFER_SIZE 16000 /* 16KB */
|
||||||
#define DESCRIPTOR_POOL_STARTING_SIZE 128
|
#define DESCRIPTOR_POOL_STARTING_SIZE 128
|
||||||
#define DESCRIPTOR_SET_DEACTIVATE_FRAMES 10
|
#define DESCRIPTOR_SET_DEACTIVATE_FRAMES 10
|
||||||
#define WINDOW_DATA "Refresh_VulkanWindowData"
|
#define WINDOW_SWAPCHAIN_DATA "Refresh_VulkanSwapchain"
|
||||||
|
|
||||||
#define IDENTITY_SWIZZLE \
|
#define IDENTITY_SWIZZLE \
|
||||||
{ \
|
{ \
|
||||||
|
@ -789,6 +789,7 @@ typedef struct VulkanSwapchainData
|
||||||
/* Window surface */
|
/* Window surface */
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
VkSurfaceFormatKHR surfaceFormat;
|
VkSurfaceFormatKHR surfaceFormat;
|
||||||
|
void *windowHandle;
|
||||||
|
|
||||||
/* Swapchain for window surface */
|
/* Swapchain for window surface */
|
||||||
VkSwapchainKHR swapchain;
|
VkSwapchainKHR swapchain;
|
||||||
|
@ -806,13 +807,6 @@ typedef struct VulkanSwapchainData
|
||||||
VkSemaphore renderFinishedSemaphore;
|
VkSemaphore renderFinishedSemaphore;
|
||||||
} VulkanSwapchainData;
|
} VulkanSwapchainData;
|
||||||
|
|
||||||
typedef struct WindowData
|
|
||||||
{
|
|
||||||
void *windowHandle;
|
|
||||||
VkPresentModeKHR preferredPresentMode;
|
|
||||||
VulkanSwapchainData *swapchainData;
|
|
||||||
} WindowData;
|
|
||||||
|
|
||||||
typedef struct SwapChainSupportDetails
|
typedef struct SwapChainSupportDetails
|
||||||
{
|
{
|
||||||
VkSurfaceCapabilitiesKHR capabilities;
|
VkSurfaceCapabilitiesKHR capabilities;
|
||||||
|
@ -824,7 +818,7 @@ typedef struct SwapChainSupportDetails
|
||||||
|
|
||||||
typedef struct VulkanPresentData
|
typedef struct VulkanPresentData
|
||||||
{
|
{
|
||||||
WindowData *windowData;
|
VulkanSwapchainData *swapchainData;
|
||||||
uint32_t swapchainImageIndex;
|
uint32_t swapchainImageIndex;
|
||||||
} VulkanPresentData;
|
} VulkanPresentData;
|
||||||
|
|
||||||
|
@ -1687,9 +1681,9 @@ typedef struct VulkanRenderer
|
||||||
VulkanMemoryAllocator *memoryAllocator;
|
VulkanMemoryAllocator *memoryAllocator;
|
||||||
VkPhysicalDeviceMemoryProperties memoryProperties;
|
VkPhysicalDeviceMemoryProperties memoryProperties;
|
||||||
|
|
||||||
WindowData **claimedWindows;
|
VulkanSwapchainData **swapchainDatas;
|
||||||
uint32_t claimedWindowCount;
|
uint32_t swapchainDataCount;
|
||||||
uint32_t claimedWindowCapacity;
|
uint32_t swapchainDataCapacity;
|
||||||
|
|
||||||
QueueFamilyIndices queueFamilyIndices;
|
QueueFamilyIndices queueFamilyIndices;
|
||||||
VkQueue graphicsQueue;
|
VkQueue graphicsQueue;
|
||||||
|
@ -1786,7 +1780,6 @@ typedef struct VulkanRenderer
|
||||||
/* Forward declarations */
|
/* Forward declarations */
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_BeginCommandBuffer(VulkanRenderer *renderer, VulkanCommandBuffer *commandBuffer);
|
static void VULKAN_INTERNAL_BeginCommandBuffer(VulkanRenderer *renderer, VulkanCommandBuffer *commandBuffer);
|
||||||
static void VULKAN_UnclaimWindow(Refresh_Renderer *driverData, void *windowHandle);
|
|
||||||
static void VULKAN_Wait(Refresh_Renderer *driverData);
|
static void VULKAN_Wait(Refresh_Renderer *driverData);
|
||||||
static void VULKAN_Submit(Refresh_Renderer *driverData, uint32_t commandBufferCount, Refresh_CommandBuffer **pCommandBuffers);
|
static void VULKAN_Submit(Refresh_Renderer *driverData, uint32_t commandBufferCount, Refresh_CommandBuffer **pCommandBuffers);
|
||||||
static void VULKAN_INTERNAL_DestroyRenderTarget(VulkanRenderer *renderer, VulkanRenderTarget *renderTarget);
|
static void VULKAN_INTERNAL_DestroyRenderTarget(VulkanRenderer *renderer, VulkanRenderTarget *renderTarget);
|
||||||
|
@ -3230,17 +3223,12 @@ static void VULKAN_INTERNAL_DestroySampler(
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_DestroySwapchain(
|
static void VULKAN_INTERNAL_DestroySwapchain(
|
||||||
VulkanRenderer* renderer,
|
VulkanRenderer* renderer,
|
||||||
WindowData *windowData
|
void *windowHandle
|
||||||
) {
|
) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
VulkanSwapchainData *swapchainData;
|
VulkanSwapchainData *swapchainData;
|
||||||
|
|
||||||
if (windowData == NULL)
|
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
swapchainData = windowData->swapchainData;
|
|
||||||
|
|
||||||
if (swapchainData == NULL)
|
if (swapchainData == NULL)
|
||||||
{
|
{
|
||||||
|
@ -3287,7 +3275,17 @@ static void VULKAN_INTERNAL_DestroySwapchain(
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
windowData->swapchainData = NULL;
|
for (i = 0; i < renderer->swapchainDataCount; i += 1)
|
||||||
|
{
|
||||||
|
if (windowHandle == renderer->swapchainDatas[i]->windowHandle)
|
||||||
|
{
|
||||||
|
renderer->swapchainDatas[i] = renderer->swapchainDatas[renderer->swapchainDataCount - 1];
|
||||||
|
renderer->swapchainDataCount -= 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, NULL);
|
||||||
SDL_free(swapchainData);
|
SDL_free(swapchainData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4252,7 +4250,8 @@ static uint8_t VULKAN_INTERNAL_ChooseSwapPresentMode(
|
||||||
|
|
||||||
static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
VulkanRenderer *renderer,
|
VulkanRenderer *renderer,
|
||||||
WindowData *windowData
|
void *windowHandle,
|
||||||
|
Refresh_PresentMode presentMode
|
||||||
) {
|
) {
|
||||||
VkResult vulkanResult;
|
VkResult vulkanResult;
|
||||||
VulkanSwapchainData *swapchainData;
|
VulkanSwapchainData *swapchainData;
|
||||||
|
@ -4265,11 +4264,12 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
swapchainData = SDL_malloc(sizeof(VulkanSwapchainData));
|
swapchainData = SDL_malloc(sizeof(VulkanSwapchainData));
|
||||||
|
swapchainData->windowHandle = windowHandle;
|
||||||
|
|
||||||
/* Each swapchain must have its own surface. */
|
/* Each swapchain must have its own surface. */
|
||||||
|
|
||||||
if (!SDL_Vulkan_CreateSurface(
|
if (!SDL_Vulkan_CreateSurface(
|
||||||
(SDL_Window*) windowData->windowHandle,
|
(SDL_Window*) windowHandle,
|
||||||
renderer->instance,
|
renderer->instance,
|
||||||
&swapchainData->surface
|
&swapchainData->surface
|
||||||
)) {
|
)) {
|
||||||
|
@ -4306,27 +4306,6 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( swapchainSupportDetails.capabilities.currentExtent.width == 0 ||
|
|
||||||
swapchainSupportDetails.capabilities.currentExtent.height == 0)
|
|
||||||
{
|
|
||||||
/* Not an error, just minimize behavior! */
|
|
||||||
renderer->vkDestroySurfaceKHR(
|
|
||||||
renderer->instance,
|
|
||||||
swapchainData->surface,
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
if (swapchainSupportDetails.formatsLength > 0)
|
|
||||||
{
|
|
||||||
SDL_free(swapchainSupportDetails.formats);
|
|
||||||
}
|
|
||||||
if (swapchainSupportDetails.presentModesLength > 0)
|
|
||||||
{
|
|
||||||
SDL_free(swapchainSupportDetails.presentModes);
|
|
||||||
}
|
|
||||||
SDL_free(swapchainData);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
swapchainData->swapchainFormat = VK_FORMAT_R8G8B8A8_UNORM;
|
swapchainData->swapchainFormat = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
swapchainData->swapchainSwizzle.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
swapchainData->swapchainSwizzle.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
swapchainData->swapchainSwizzle.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
swapchainData->swapchainSwizzle.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||||
|
@ -4371,7 +4350,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!VULKAN_INTERNAL_ChooseSwapPresentMode(
|
if (!VULKAN_INTERNAL_ChooseSwapPresentMode(
|
||||||
windowData->preferredPresentMode,
|
presentMode,
|
||||||
swapchainSupportDetails.presentModes,
|
swapchainSupportDetails.presentModes,
|
||||||
swapchainSupportDetails.presentModesLength,
|
swapchainSupportDetails.presentModesLength,
|
||||||
&swapchainData->presentMode
|
&swapchainData->presentMode
|
||||||
|
@ -4395,7 +4374,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Vulkan_GetDrawableSize(
|
SDL_Vulkan_GetDrawableSize(
|
||||||
(SDL_Window*) windowData->windowHandle,
|
(SDL_Window*) windowHandle,
|
||||||
&drawableWidth,
|
&drawableWidth,
|
||||||
&drawableHeight
|
&drawableHeight
|
||||||
);
|
);
|
||||||
|
@ -4405,6 +4384,27 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
drawableHeight < swapchainSupportDetails.capabilities.minImageExtent.height ||
|
drawableHeight < swapchainSupportDetails.capabilities.minImageExtent.height ||
|
||||||
drawableHeight > swapchainSupportDetails.capabilities.maxImageExtent.height )
|
drawableHeight > swapchainSupportDetails.capabilities.maxImageExtent.height )
|
||||||
{
|
{
|
||||||
|
if ( swapchainSupportDetails.capabilities.currentExtent.width == 0 ||
|
||||||
|
swapchainSupportDetails.capabilities.currentExtent.height == 0)
|
||||||
|
{
|
||||||
|
renderer->vkDestroySurfaceKHR(
|
||||||
|
renderer->instance,
|
||||||
|
swapchainData->surface,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if (swapchainSupportDetails.formatsLength > 0)
|
||||||
|
{
|
||||||
|
SDL_free(swapchainSupportDetails.formats);
|
||||||
|
}
|
||||||
|
if (swapchainSupportDetails.presentModesLength > 0)
|
||||||
|
{
|
||||||
|
SDL_free(swapchainSupportDetails.presentModes);
|
||||||
|
}
|
||||||
|
SDL_free(swapchainData);
|
||||||
|
/* Not an error, just Windows minimize behavior! */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (swapchainSupportDetails.capabilities.currentExtent.width != UINT32_MAX)
|
if (swapchainSupportDetails.capabilities.currentExtent.width != UINT32_MAX)
|
||||||
{
|
{
|
||||||
drawableWidth = VULKAN_INTERNAL_clamp(
|
drawableWidth = VULKAN_INTERNAL_clamp(
|
||||||
|
@ -4622,17 +4622,31 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
|
||||||
&swapchainData->renderFinishedSemaphore
|
&swapchainData->renderFinishedSemaphore
|
||||||
);
|
);
|
||||||
|
|
||||||
windowData->swapchainData = swapchainData;
|
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, swapchainData);
|
||||||
|
|
||||||
|
if (renderer->swapchainDataCount >= renderer->swapchainDataCapacity)
|
||||||
|
{
|
||||||
|
renderer->swapchainDataCapacity *= 2;
|
||||||
|
renderer->swapchainDatas = SDL_realloc(
|
||||||
|
renderer->swapchainDatas,
|
||||||
|
renderer->swapchainDataCapacity * sizeof(VulkanSwapchainData*)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer->swapchainDatas[renderer->swapchainDataCount] = swapchainData;
|
||||||
|
renderer->swapchainDataCount += 1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void VULKAN_INTERNAL_RecreateSwapchain(
|
static void VULKAN_INTERNAL_RecreateSwapchain(
|
||||||
VulkanRenderer* renderer,
|
VulkanRenderer* renderer,
|
||||||
WindowData *windowData
|
void *windowHandle,
|
||||||
|
Refresh_PresentMode presentMode
|
||||||
) {
|
) {
|
||||||
VULKAN_Wait((Refresh_Renderer*) renderer);
|
VULKAN_Wait((Refresh_Renderer*) renderer);
|
||||||
VULKAN_INTERNAL_DestroySwapchain(renderer, windowData);
|
VULKAN_INTERNAL_DestroySwapchain(renderer, windowHandle);
|
||||||
VULKAN_INTERNAL_CreateSwapchain(renderer, windowData);
|
VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle, presentMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Command Buffers */
|
/* Command Buffers */
|
||||||
|
@ -4705,12 +4719,12 @@ static void VULKAN_DestroyDevice(
|
||||||
|
|
||||||
VULKAN_Wait(device->driverData);
|
VULKAN_Wait(device->driverData);
|
||||||
|
|
||||||
for (i = renderer->claimedWindowCount - 1; i >= 0; i -= 1)
|
for (i = renderer->swapchainDataCount - 1; i >= 0; i -= 1)
|
||||||
{
|
{
|
||||||
VULKAN_UnclaimWindow(device->driverData, renderer->claimedWindows[i]->windowHandle);
|
VULKAN_INTERNAL_DestroySwapchain(renderer, renderer->swapchainDatas[i]->windowHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_free(renderer->claimedWindows);
|
SDL_free(renderer->swapchainDatas);
|
||||||
|
|
||||||
VULKAN_Wait(device->driverData);
|
VULKAN_Wait(device->driverData);
|
||||||
|
|
||||||
|
@ -9250,10 +9264,10 @@ static Refresh_CommandBuffer* VULKAN_AcquireCommandBuffer(
|
||||||
return (Refresh_CommandBuffer*) commandBuffer;
|
return (Refresh_CommandBuffer*) commandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WindowData* VULKAN_INTERNAL_FetchWindowData(
|
static VulkanSwapchainData* VULKAN_INTERNAL_FetchSwapchainData(
|
||||||
void *windowHandle
|
void *windowHandle
|
||||||
) {
|
) {
|
||||||
return (WindowData*) SDL_GetWindowData(windowHandle, WINDOW_DATA);
|
return (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t VULKAN_ClaimWindow(
|
static uint8_t VULKAN_ClaimWindow(
|
||||||
|
@ -9262,38 +9276,11 @@ static uint8_t VULKAN_ClaimWindow(
|
||||||
Refresh_PresentMode presentMode
|
Refresh_PresentMode presentMode
|
||||||
) {
|
) {
|
||||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||||
WindowData *windowData = VULKAN_INTERNAL_FetchWindowData(windowHandle);
|
VulkanSwapchainData *swapchainData = VULKAN_INTERNAL_FetchSwapchainData(windowHandle);
|
||||||
|
|
||||||
if (windowData == NULL)
|
if (swapchainData == NULL)
|
||||||
{
|
{
|
||||||
windowData = SDL_malloc(sizeof(WindowData));
|
return VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle, presentMode);
|
||||||
windowData->windowHandle = windowHandle;
|
|
||||||
windowData->preferredPresentMode = presentMode;
|
|
||||||
|
|
||||||
if (VULKAN_INTERNAL_CreateSwapchain(renderer, windowData))
|
|
||||||
{
|
|
||||||
SDL_SetWindowData((SDL_Window*) windowHandle, WINDOW_DATA, windowData);
|
|
||||||
|
|
||||||
if (renderer->claimedWindowCount >= renderer->claimedWindowCapacity)
|
|
||||||
{
|
|
||||||
renderer->claimedWindowCapacity *= 2;
|
|
||||||
renderer->claimedWindows = SDL_realloc(
|
|
||||||
renderer->claimedWindows,
|
|
||||||
renderer->claimedWindowCapacity * sizeof(WindowData*)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer->claimedWindows[renderer->claimedWindowCount] = windowData;
|
|
||||||
renderer->claimedWindowCount += 1;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Refresh_LogError("Could not create swapchain, failed to claim window!");
|
|
||||||
SDL_free(windowData);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -9306,36 +9293,11 @@ static void VULKAN_UnclaimWindow(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
void *windowHandle
|
void *windowHandle
|
||||||
) {
|
) {
|
||||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
|
||||||
WindowData *windowData = VULKAN_INTERNAL_FetchWindowData(windowHandle);
|
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
if (windowData == NULL)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (windowData->swapchainData != NULL)
|
|
||||||
{
|
|
||||||
VULKAN_Wait(driverData);
|
VULKAN_Wait(driverData);
|
||||||
VULKAN_INTERNAL_DestroySwapchain(
|
VULKAN_INTERNAL_DestroySwapchain(
|
||||||
(VulkanRenderer*) driverData,
|
(VulkanRenderer*) driverData,
|
||||||
windowData
|
windowHandle
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < renderer->claimedWindowCount; i += 1)
|
|
||||||
{
|
|
||||||
if (renderer->claimedWindows[i]->windowHandle == windowHandle)
|
|
||||||
{
|
|
||||||
renderer->claimedWindows[i] = renderer->claimedWindows[renderer->claimedWindowCount - 1];
|
|
||||||
renderer->claimedWindowCount -= 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_free(windowData);
|
|
||||||
SDL_SetWindowData((SDL_Window*) windowHandle, WINDOW_DATA, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
|
@ -9348,42 +9310,19 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
VulkanRenderer *renderer = (VulkanRenderer*) driverData;
|
||||||
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
VulkanCommandBuffer *vulkanCommandBuffer = (VulkanCommandBuffer*) commandBuffer;
|
||||||
uint32_t swapchainImageIndex;
|
uint32_t swapchainImageIndex;
|
||||||
WindowData *windowData;
|
|
||||||
VulkanSwapchainData *swapchainData;
|
VulkanSwapchainData *swapchainData;
|
||||||
VkResult acquireResult = VK_SUCCESS;
|
VkResult acquireResult = VK_SUCCESS;
|
||||||
VulkanTexture *swapchainTexture = NULL;
|
VulkanTexture *swapchainTexture = NULL;
|
||||||
VulkanPresentData *presentData;
|
VulkanPresentData *presentData;
|
||||||
|
|
||||||
windowData = VULKAN_INTERNAL_FetchWindowData(windowHandle);
|
swapchainData = VULKAN_INTERNAL_FetchSwapchainData(windowHandle);
|
||||||
|
|
||||||
if (windowData == NULL)
|
if (swapchainData == NULL)
|
||||||
{
|
{
|
||||||
Refresh_LogError("Cannot acquire swapchain texture, window has not been claimed!");
|
Refresh_LogError("Cannot acquire swapchain texture, window has not been claimed!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
swapchainData = windowData->swapchainData;
|
|
||||||
|
|
||||||
/* Window is claimed but swapchain is invalid! */
|
|
||||||
if (swapchainData == NULL)
|
|
||||||
{
|
|
||||||
if (SDL_GetWindowFlags(windowHandle) & SDL_WINDOW_MINIMIZED)
|
|
||||||
{
|
|
||||||
/* Window is minimized, don't bother */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Let's try to recreate */
|
|
||||||
VULKAN_INTERNAL_RecreateSwapchain(renderer, windowData);
|
|
||||||
swapchainData = windowData->swapchainData;
|
|
||||||
|
|
||||||
if (swapchainData == NULL)
|
|
||||||
{
|
|
||||||
Refresh_LogWarn("Failed to recreate swapchain!");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
acquireResult = renderer->vkAcquireNextImageKHR(
|
acquireResult = renderer->vkAcquireNextImageKHR(
|
||||||
renderer->logicalDevice,
|
renderer->logicalDevice,
|
||||||
swapchainData->swapchain,
|
swapchainData->swapchain,
|
||||||
|
@ -9393,11 +9332,14 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
&swapchainImageIndex
|
&swapchainImageIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Acquisition is invalid, let's try to recreate */
|
/* Swapchain is invalid, let's try to recreate */
|
||||||
if (acquireResult != VK_SUCCESS && acquireResult != VK_SUBOPTIMAL_KHR)
|
if (acquireResult != VK_SUCCESS && acquireResult != VK_SUBOPTIMAL_KHR)
|
||||||
{
|
{
|
||||||
VULKAN_INTERNAL_RecreateSwapchain(renderer, windowData);
|
swapchainData = VULKAN_INTERNAL_FetchSwapchainData(windowHandle);
|
||||||
swapchainData = windowData->swapchainData;
|
|
||||||
|
VULKAN_INTERNAL_RecreateSwapchain(renderer, windowHandle, swapchainData->presentMode);
|
||||||
|
|
||||||
|
swapchainData = VULKAN_INTERNAL_FetchSwapchainData(windowHandle);
|
||||||
|
|
||||||
if (swapchainData == NULL)
|
if (swapchainData == NULL)
|
||||||
{
|
{
|
||||||
|
@ -9416,7 +9358,6 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
|
|
||||||
if (acquireResult != VK_SUCCESS && acquireResult != VK_SUBOPTIMAL_KHR)
|
if (acquireResult != VK_SUCCESS && acquireResult != VK_SUBOPTIMAL_KHR)
|
||||||
{
|
{
|
||||||
Refresh_LogWarn("Failed to acquire swapchain texture!");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9451,7 +9392,7 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
|
||||||
presentData = &vulkanCommandBuffer->presentDatas[vulkanCommandBuffer->presentDataCount];
|
presentData = &vulkanCommandBuffer->presentDatas[vulkanCommandBuffer->presentDataCount];
|
||||||
vulkanCommandBuffer->presentDataCount += 1;
|
vulkanCommandBuffer->presentDataCount += 1;
|
||||||
|
|
||||||
presentData->windowData = windowData;
|
presentData->swapchainData = swapchainData;
|
||||||
presentData->swapchainImageIndex = swapchainImageIndex;
|
presentData->swapchainImageIndex = swapchainImageIndex;
|
||||||
|
|
||||||
/* Set up present semaphores */
|
/* Set up present semaphores */
|
||||||
|
@ -9490,25 +9431,19 @@ static Refresh_TextureFormat VULKAN_GetSwapchainFormat(
|
||||||
Refresh_Renderer *driverData,
|
Refresh_Renderer *driverData,
|
||||||
void *windowHandle
|
void *windowHandle
|
||||||
) {
|
) {
|
||||||
WindowData *windowData = VULKAN_INTERNAL_FetchWindowData(windowHandle);
|
VulkanSwapchainData *swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
||||||
|
|
||||||
if (windowData == NULL)
|
if (swapchainData == NULL)
|
||||||
{
|
{
|
||||||
Refresh_LogWarn("Cannot get swapchain format, window has not been claimed!");
|
Refresh_LogWarn("No swapchain for this window!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (windowData->swapchainData == NULL)
|
if (swapchainData->swapchainFormat == VK_FORMAT_R8G8B8A8_UNORM)
|
||||||
{
|
|
||||||
Refresh_LogWarn("Cannot get swapchain format, swapchain is currently invalid!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (windowData->swapchainData->swapchainFormat == VK_FORMAT_R8G8B8A8_UNORM)
|
|
||||||
{
|
{
|
||||||
return REFRESH_TEXTUREFORMAT_R8G8B8A8;
|
return REFRESH_TEXTUREFORMAT_R8G8B8A8;
|
||||||
}
|
}
|
||||||
else if (windowData->swapchainData->swapchainFormat == VK_FORMAT_B8G8R8A8_UNORM)
|
else if (swapchainData->swapchainFormat == VK_FORMAT_B8G8R8A8_UNORM)
|
||||||
{
|
{
|
||||||
return REFRESH_TEXTUREFORMAT_B8G8R8A8;
|
return REFRESH_TEXTUREFORMAT_B8G8R8A8;
|
||||||
}
|
}
|
||||||
|
@ -9524,9 +9459,9 @@ static void VULKAN_SetSwapchainPresentMode(
|
||||||
void *windowHandle,
|
void *windowHandle,
|
||||||
Refresh_PresentMode presentMode
|
Refresh_PresentMode presentMode
|
||||||
) {
|
) {
|
||||||
WindowData *windowData = VULKAN_INTERNAL_FetchWindowData(windowHandle);
|
VulkanSwapchainData *swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
|
||||||
|
|
||||||
if (windowData == NULL)
|
if (swapchainData == NULL)
|
||||||
{
|
{
|
||||||
Refresh_LogWarn("Cannot set present mode, window has not been claimed!");
|
Refresh_LogWarn("Cannot set present mode, window has not been claimed!");
|
||||||
return;
|
return;
|
||||||
|
@ -9534,7 +9469,8 @@ static void VULKAN_SetSwapchainPresentMode(
|
||||||
|
|
||||||
VULKAN_INTERNAL_RecreateSwapchain(
|
VULKAN_INTERNAL_RecreateSwapchain(
|
||||||
(VulkanRenderer *)driverData,
|
(VulkanRenderer *)driverData,
|
||||||
windowData
|
windowHandle,
|
||||||
|
presentMode
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9879,8 +9815,8 @@ static void VULKAN_Submit(
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
currentCommandBuffer->presentDatas[j].windowData->swapchainData->textures[swapchainImageIndex].image,
|
currentCommandBuffer->presentDatas[j].swapchainData->textures[swapchainImageIndex].image,
|
||||||
¤tCommandBuffer->presentDatas[j].windowData->swapchainData->textures[swapchainImageIndex].resourceAccessType
|
¤tCommandBuffer->presentDatas[j].swapchainData->textures[swapchainImageIndex].resourceAccessType
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9933,9 +9869,9 @@ static void VULKAN_Submit(
|
||||||
|
|
||||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||||
presentInfo.pNext = NULL;
|
presentInfo.pNext = NULL;
|
||||||
presentInfo.pWaitSemaphores = &presentData->windowData->swapchainData->renderFinishedSemaphore;
|
presentInfo.pWaitSemaphores = &presentData->swapchainData->renderFinishedSemaphore;
|
||||||
presentInfo.waitSemaphoreCount = 1;
|
presentInfo.waitSemaphoreCount = 1;
|
||||||
presentInfo.pSwapchains = &presentData->windowData->swapchainData->swapchain;
|
presentInfo.pSwapchains = &presentData->swapchainData->swapchain;
|
||||||
presentInfo.swapchainCount = 1;
|
presentInfo.swapchainCount = 1;
|
||||||
presentInfo.pImageIndices = &presentData->swapchainImageIndex;
|
presentInfo.pImageIndices = &presentData->swapchainImageIndex;
|
||||||
presentInfo.pResults = NULL;
|
presentInfo.pResults = NULL;
|
||||||
|
@ -9949,7 +9885,8 @@ static void VULKAN_Submit(
|
||||||
{
|
{
|
||||||
VULKAN_INTERNAL_RecreateSwapchain(
|
VULKAN_INTERNAL_RecreateSwapchain(
|
||||||
renderer,
|
renderer,
|
||||||
presentData->windowData
|
presentData->swapchainData->windowHandle,
|
||||||
|
presentData->swapchainData->presentMode
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10549,7 +10486,6 @@ static uint8_t VULKAN_INTERNAL_CreateLogicalDevice(
|
||||||
deviceFeatures.occlusionQueryPrecise = VK_TRUE;
|
deviceFeatures.occlusionQueryPrecise = VK_TRUE;
|
||||||
deviceFeatures.fillModeNonSolid = VK_TRUE;
|
deviceFeatures.fillModeNonSolid = VK_TRUE;
|
||||||
deviceFeatures.depthClamp = VK_TRUE;
|
deviceFeatures.depthClamp = VK_TRUE;
|
||||||
deviceFeatures.samplerAnisotropy = VK_TRUE;
|
|
||||||
|
|
||||||
/* creating the logical device */
|
/* creating the logical device */
|
||||||
|
|
||||||
|
@ -10818,10 +10754,10 @@ static Refresh_Device* VULKAN_CreateDevice(
|
||||||
* Create initial swapchain array
|
* Create initial swapchain array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
renderer->claimedWindowCapacity = 1;
|
renderer->swapchainDataCapacity = 1;
|
||||||
renderer->claimedWindowCount = 0;
|
renderer->swapchainDataCount = 0;
|
||||||
renderer->claimedWindows = SDL_malloc(
|
renderer->swapchainDatas = SDL_malloc(
|
||||||
renderer->claimedWindowCapacity * sizeof(WindowData*)
|
renderer->swapchainDataCapacity * sizeof(VulkanSwapchainData*)
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Threading */
|
/* Threading */
|
||||||
|
|
Loading…
Reference in New Issue