add swapchain format query
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

pull/15/head
cosmonaut 2022-03-01 22:21:07 -08:00
parent c9290c90ce
commit ed020691cc
4 changed files with 81 additions and 18 deletions

View File

@ -1242,6 +1242,12 @@ REFRESHAPI Refresh_Texture* Refresh_AcquireSwapchainTexture(
void *windowHandle void *windowHandle
); );
/* Returns the format of the swapchain for the given window. */
REFRESHAPI Refresh_TextureFormat Refresh_GetSwapchainFormat(
Refresh_Device *device,
void *windowHandle
);
/* Submits all of the enqueued commands. */ /* Submits all of the enqueued commands. */
REFRESHAPI void Refresh_Submit( REFRESHAPI void Refresh_Submit(
Refresh_Device* device, Refresh_Device* device,
@ -1249,7 +1255,7 @@ REFRESHAPI void Refresh_Submit(
Refresh_CommandBuffer **pCommandBuffers Refresh_CommandBuffer **pCommandBuffers
); );
/* Waits for the previous submission to complete. */ /* Waits for all submissions to complete. */
REFRESHAPI void Refresh_Wait( REFRESHAPI void Refresh_Wait(
Refresh_Device *device Refresh_Device *device
); );

View File

@ -725,6 +725,17 @@ Refresh_Texture* Refresh_AcquireSwapchainTexture(
); );
} }
Refresh_TextureFormat Refresh_GetSwapchainFormat(
Refresh_Device *device,
void *windowHandle
) {
if (device == NULL) { return 0; }
return device->GetSwapchainFormat(
device->driverData,
windowHandle
);
}
void Refresh_Submit( void Refresh_Submit(
Refresh_Device *device, Refresh_Device *device,
uint32_t commandBufferCount, uint32_t commandBufferCount,

View File

@ -448,6 +448,11 @@ struct Refresh_Device
void *windowHandle void *windowHandle
); );
Refresh_TextureFormat (*GetSwapchainFormat)(
Refresh_Renderer *driverData,
void *windowHandle
);
void(*Submit)( void(*Submit)(
Refresh_Renderer *driverData, Refresh_Renderer *driverData,
uint32_t commandBufferCount, uint32_t commandBufferCount,
@ -504,6 +509,7 @@ struct Refresh_Device
ASSIGN_DRIVER_FUNC(BindComputeTextures, name) \ ASSIGN_DRIVER_FUNC(BindComputeTextures, name) \
ASSIGN_DRIVER_FUNC(AcquireCommandBuffer, name) \ ASSIGN_DRIVER_FUNC(AcquireCommandBuffer, name) \
ASSIGN_DRIVER_FUNC(AcquireSwapchainTexture, name) \ ASSIGN_DRIVER_FUNC(AcquireSwapchainTexture, name) \
ASSIGN_DRIVER_FUNC(GetSwapchainFormat, name) \
ASSIGN_DRIVER_FUNC(Submit, name) \ ASSIGN_DRIVER_FUNC(Submit, name) \
ASSIGN_DRIVER_FUNC(Wait, name) ASSIGN_DRIVER_FUNC(Wait, name)

View File

@ -3849,7 +3849,6 @@ static uint8_t VULKAN_INTERNAL_ChooseSwapSurfaceFormat(
} }
} }
Refresh_LogError("Desired surface format is unavailable.");
return 0; return 0;
} }
@ -3961,12 +3960,25 @@ static CreateSwapchainResult VULKAN_INTERNAL_CreateSwapchain(
return CREATE_SWAPCHAIN_FAIL; return CREATE_SWAPCHAIN_FAIL;
} }
swapchainData->swapchainFormat = VK_FORMAT_B8G8R8A8_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;
swapchainData->swapchainSwizzle.b = VK_COMPONENT_SWIZZLE_IDENTITY; swapchainData->swapchainSwizzle.b = VK_COMPONENT_SWIZZLE_IDENTITY;
swapchainData->swapchainSwizzle.a = VK_COMPONENT_SWIZZLE_IDENTITY; swapchainData->swapchainSwizzle.a = VK_COMPONENT_SWIZZLE_IDENTITY;
if (!VULKAN_INTERNAL_ChooseSwapSurfaceFormat(
swapchainData->swapchainFormat,
swapchainSupportDetails.formats,
swapchainSupportDetails.formatsLength,
&swapchainData->surfaceFormat
)) {
Refresh_LogWarn("RGBA8 swapchain unsupported, falling back to BGRA8 with swizzle");
swapchainData->swapchainFormat = VK_FORMAT_B8G8R8A8_UNORM;
swapchainData->swapchainSwizzle.r = VK_COMPONENT_SWIZZLE_B;
swapchainData->swapchainSwizzle.g = VK_COMPONENT_SWIZZLE_G;
swapchainData->swapchainSwizzle.b = VK_COMPONENT_SWIZZLE_R;
swapchainData->swapchainSwizzle.a = VK_COMPONENT_SWIZZLE_A;
if (!VULKAN_INTERNAL_ChooseSwapSurfaceFormat( if (!VULKAN_INTERNAL_ChooseSwapSurfaceFormat(
swapchainData->swapchainFormat, swapchainData->swapchainFormat,
swapchainSupportDetails.formats, swapchainSupportDetails.formats,
@ -3990,6 +4002,7 @@ static CreateSwapchainResult VULKAN_INTERNAL_CreateSwapchain(
Refresh_LogError("Device does not support swap chain format"); Refresh_LogError("Device does not support swap chain format");
return CREATE_SWAPCHAIN_FAIL; return CREATE_SWAPCHAIN_FAIL;
} }
}
if (!VULKAN_INTERNAL_ChooseSwapPresentMode( if (!VULKAN_INTERNAL_ChooseSwapPresentMode(
renderer->presentMode, renderer->presentMode,
@ -8626,6 +8639,33 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
return (Refresh_Texture*) swapchainTexture; return (Refresh_Texture*) swapchainTexture;
} }
static Refresh_TextureFormat VULKAN_GetSwapchainFormat(
Refresh_Renderer *driverData,
void *windowHandle
) {
VulkanSwapchainData *swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
if (swapchainData == NULL)
{
Refresh_LogWarn("No swapchain for this window!");
return 0;
}
if (swapchainData->swapchainFormat == VK_FORMAT_R8G8B8A8_UNORM)
{
return REFRESH_TEXTUREFORMAT_R8G8B8A8;
}
else if (swapchainData->swapchainFormat == VK_FORMAT_B8G8R8A8_UNORM)
{
return REFRESH_TEXTUREFORMAT_B8G8R8A8;
}
else
{
Refresh_LogWarn("Unrecognized swapchain format!");
return 0;
}
}
/* Synchronization management */ /* Synchronization management */
static VkFence VULKAN_INTERNAL_AcquireFence( static VkFence VULKAN_INTERNAL_AcquireFence(