c/main: Refactor arguments to comp_target::create_images

This commit is contained in:
Jakob Bornecrantz 2024-01-07 14:50:11 +00:00 committed by Simon Zeni
parent 206bdfe0ba
commit a6e9893f99
4 changed files with 72 additions and 73 deletions

View file

@ -529,14 +529,19 @@ renderer_ensure_images_and_renderings(struct comp_renderer *r, bool force_recrea
image_usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
}
comp_target_create_images( //
r->c->target, //
r->c->settings.preferred.width, //
r->c->settings.preferred.height, //
r->settings->color_format, //
r->settings->color_space, //
image_usage, //
r->settings->present_mode); //
struct comp_target_create_images_info info = {
.extent =
{
.width = r->c->settings.preferred.width,
.height = r->c->settings.preferred.height,
},
.format = r->settings->color_format,
.image_usage = image_usage,
.color_space = r->settings->color_space,
.present_mode = r->settings->present_mode,
};
comp_target_create_images(r->c->target, &info);
bool pre_rotate = false;
if (r->c->target->surface_transform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR ||

View file

@ -64,6 +64,30 @@ struct comp_target_image
VkImageView view;
};
/*!
* Information given in when creating the swapchain images,
* argument to @ref comp_target_create_images.
*
* @ingroup comp_main
*/
struct comp_target_create_images_info
{
//! Image usage for the images, must be followed.
VkImageUsageFlags image_usage;
//! Preferred format for the images, can be ignored by the target.
VkFormat format;
//! Preferred extent, can be ignored by the target.
VkExtent2D extent;
//! Preferred color space, can be ignored by the target.
VkColorSpaceKHR color_space;
// Preferred present_mode, can be ignored by the target.
VkPresentModeKHR present_mode;
};
/*!
* Collection of semaphores needed for a target.
*
@ -157,13 +181,7 @@ struct comp_target
*
* @pre @ref check_ready returns true
*/
void (*create_images)(struct comp_target *ct,
uint32_t preferred_width,
uint32_t preferred_height,
VkFormat preferred_color_format,
VkColorSpaceKHR preferred_color_space,
VkImageUsageFlags image_usage,
VkPresentModeKHR present_mode);
void (*create_images)(struct comp_target *ct, const struct comp_target_create_images_info *create_info);
/*!
* Has this target successfully had images created?
@ -326,24 +344,11 @@ comp_target_check_ready(struct comp_target *ct)
* @ingroup comp_main
*/
static inline void
comp_target_create_images(struct comp_target *ct,
uint32_t preferred_width,
uint32_t preferred_height,
VkFormat preferred_color_format,
VkColorSpaceKHR preferred_color_space,
VkImageUsageFlags image_usage,
VkPresentModeKHR present_mode)
comp_target_create_images(struct comp_target *ct, const struct comp_target_create_images_info *create_info)
{
COMP_TRACE_MARKER();
ct->create_images( //
ct, //
preferred_width, //
preferred_height, //
preferred_color_format, //
preferred_color_space, //
image_usage, //
present_mode); //
ct->create_images(ct, create_info);
}
/*!

View file

@ -145,10 +145,7 @@ err:
}
static VkExtent2D
select_extent(struct comp_target_swapchain *cts,
VkSurfaceCapabilitiesKHR caps,
uint32_t preferred_width,
uint32_t preferred_height)
select_extent(struct comp_target_swapchain *cts, VkSurfaceCapabilitiesKHR caps, VkExtent2D preferred)
{
/*
* A sub-class wants us to use these extents over the ones the
@ -156,29 +153,29 @@ select_extent(struct comp_target_swapchain *cts,
* upporting this size so we better respect those wishes.
*/
if (cts->override.compositor_extent) {
preferred_width = cts->override.extent.width;
preferred_height = cts->override.extent.height;
preferred.width = cts->override.extent.width;
preferred.height = cts->override.extent.height;
}
// If width (and height) equals the special value 0xFFFFFFFF,
// the size of the surface will be set by the swapchain
if (caps.currentExtent.width == (uint32_t)-1) {
assert(preferred_width > 0 && preferred_height > 0);
assert(preferred.width > 0 && preferred.height > 0);
VkExtent2D extent = {
.width = preferred_width,
.height = preferred_height,
.width = preferred.width,
.height = preferred.height,
};
return extent;
}
if (caps.currentExtent.width != preferred_width || //
caps.currentExtent.height != preferred_height) {
if (caps.currentExtent.width != preferred.width || //
caps.currentExtent.height != preferred.height) {
COMP_DEBUG(cts->base.c, "Using swap chain extent dimensions %dx%d instead of requested %dx%d.",
caps.currentExtent.width, //
caps.currentExtent.height, //
preferred_width, //
preferred_height); //
preferred.width, //
preferred.height); //
}
return caps.currentExtent;
@ -641,13 +638,7 @@ target_init_semaphores(struct comp_target_swapchain *cts)
*/
static void
comp_target_swapchain_create_images(struct comp_target *ct,
uint32_t preferred_width,
uint32_t preferred_height,
VkFormat color_format,
VkColorSpaceKHR color_space,
VkImageUsageFlags image_usage,
VkPresentModeKHR present_mode)
comp_target_swapchain_create_images(struct comp_target *ct, const struct comp_target_create_images_info *create_info)
{
struct comp_target_swapchain *cts = (struct comp_target_swapchain *)ct;
struct vk_bundle *vk = get_vk(cts);
@ -673,9 +664,9 @@ comp_target_swapchain_create_images(struct comp_target *ct,
cts->base.image_count = 0;
cts->swapchain.handle = VK_NULL_HANDLE;
cts->present_mode = present_mode;
cts->preferred.color_format = color_format;
cts->preferred.color_space = color_space;
cts->present_mode = create_info->present_mode;
cts->preferred.color_format = create_info->format;
cts->preferred.color_space = create_info->color_space;
/*
@ -737,7 +728,7 @@ comp_target_swapchain_create_images(struct comp_target *ct,
*/
// Get the extents of the swapchain.
VkExtent2D extent = select_extent(cts, surface_caps, preferred_width, preferred_height);
VkExtent2D extent = select_extent(cts, surface_caps, create_info->extent);
if (surface_caps.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR ||
surface_caps.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
@ -785,7 +776,7 @@ comp_target_swapchain_create_images(struct comp_target *ct,
.height = extent.height,
},
.imageArrayLayers = 1,
.imageUsage = image_usage,
.imageUsage = create_info->image_usage,
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
.queueFamilyIndexCount = 0,
.preTransform = surface_caps.currentTransform,

View file

@ -50,6 +50,20 @@ get_vk(struct comp_window_peek *w)
return &w->c->base.vk;
}
static inline void
create_images(struct comp_window_peek *w)
{
struct comp_target_create_images_info info = {
.extent = {w->width, w->height},
.format = w->c->settings.color_format,
.color_space = w->c->settings.color_space,
.image_usage = PEEK_IMAGE_USAGE,
.present_mode = VK_PRESENT_MODE_MAILBOX_KHR,
};
comp_target_create_images(&w->base.base, &info);
}
static void *
window_peek_run_thread(void *ptr)
{
@ -204,16 +218,7 @@ comp_window_peek_create(struct comp_compositor *c)
* Images
*/
/* TODO: present mode fallback to FIFO if MAILBOX is not available */
comp_target_create_images( //
&w->base.base, //
w->width, //
w->height, //
w->c->settings.color_format, //
w->c->settings.color_space, //
PEEK_IMAGE_USAGE, //
VK_PRESENT_MODE_MAILBOX_KHR); //
create_images(w);
/*
* Thread
@ -280,14 +285,7 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
if (w->width != w->base.base.width || w->height != w->base.base.height) {
COMP_DEBUG(w->c, "Resizing swapchain");
comp_target_create_images( //
&w->base.base, //
w->width, //
w->height, //
w->c->settings.color_format, //
w->c->settings.color_space, //
PEEK_IMAGE_USAGE, //
VK_PRESENT_MODE_MAILBOX_KHR); //
create_images(w);
}
while (!comp_target_check_ready(&w->base.base))