Cleanup: Vulkan: Use full surface format

GHOST_ContextVK used to pass only the surface texture format to
the GPU backend, it didn't pass the color space. This PR also includes
the color space.

Pull Request: https://projects.blender.org/blender/blender/pulls/133185
This commit is contained in:
Jeroen Bakker
2025-01-17 10:28:22 +01:00
parent 963c638a5b
commit 80ec04b4ef
4 changed files with 18 additions and 14 deletions

View File

@@ -724,8 +724,8 @@ typedef struct {
typedef struct {
/** Image handle to the image that will be presented to the user. */
VkImage image;
/** Format of the image. */
VkFormat format;
/** Format of the swap chain. */
VkSurfaceFormatKHR surface_format;
/** Resolution of the image. */
VkExtent2D extent;
} GHOST_VulkanSwapChainData;

View File

@@ -585,7 +585,7 @@ GHOST_TSuccess GHOST_ContextVK::swapBuffers()
GHOST_VulkanSwapChainData swap_chain_data;
swap_chain_data.image = m_swapchain_images[image_index];
swap_chain_data.format = m_surface_format.format;
swap_chain_data.surface_format = m_surface_format;
swap_chain_data.extent = m_render_extent;
if (swap_buffers_pre_callback_) {
@@ -636,7 +636,7 @@ GHOST_TSuccess GHOST_ContextVK::getVulkanSwapChainFormat(
GHOST_VulkanSwapChainData *r_swap_chain_data)
{
r_swap_chain_data->image = VK_NULL_HANDLE;
r_swap_chain_data->format = m_surface_format.format;
r_swap_chain_data->surface_format = m_surface_format;
r_swap_chain_data->extent = m_render_extent;
return GHOST_kSuccess;

View File

@@ -70,7 +70,10 @@ void VKContext::sync_backbuffer(bool cycle_resource_pool)
resource_pool.discard_pool.move_data(device.orphaned_data);
}
const bool reset_framebuffer = swap_chain_format_ != swap_chain_data.format ||
const bool reset_framebuffer = swap_chain_format_.format !=
swap_chain_data.surface_format.format ||
swap_chain_format_.colorSpace !=
swap_chain_data.surface_format.colorSpace ||
vk_extent_.width != swap_chain_data.extent.width ||
vk_extent_.height != swap_chain_data.extent.height;
if (reset_framebuffer) {
@@ -81,13 +84,14 @@ void VKContext::sync_backbuffer(bool cycle_resource_pool)
GPU_texture_free(surface_texture_);
surface_texture_ = nullptr;
}
surface_texture_ = GPU_texture_create_2d("back-left",
swap_chain_data.extent.width,
swap_chain_data.extent.height,
1,
to_gpu_format(swap_chain_data.format),
GPU_TEXTURE_USAGE_ATTACHMENT,
nullptr);
surface_texture_ = GPU_texture_create_2d(
"back-left",
swap_chain_data.extent.width,
swap_chain_data.extent.height,
1,
to_gpu_format(swap_chain_data.surface_format.format),
GPU_TEXTURE_USAGE_ATTACHMENT,
nullptr);
back_left->attachment_set(GPU_FB_COLOR_ATTACHMENT0,
GPU_ATTACHMENT_TEXTURE(surface_texture_));
@@ -96,7 +100,7 @@ void VKContext::sync_backbuffer(bool cycle_resource_pool)
back_left->bind(false);
swap_chain_format_ = swap_chain_data.format;
swap_chain_format_ = swap_chain_data.surface_format;
vk_extent_ = swap_chain_data.extent;
}
}

View File

@@ -29,7 +29,7 @@ class VKThreadData;
class VKContext : public Context, NonCopyable {
private:
VkExtent2D vk_extent_ = {};
VkFormat swap_chain_format_ = {};
VkSurfaceFormatKHR swap_chain_format_ = {};
GPUTexture *surface_texture_ = nullptr;
void *ghost_context_;