render/vulkan: use _SRGB image view when possible

This is the last of a set of commits which ensures that both textures
and render buffers can be accessed through _UNORM and _SRGB image
views. While _UNORM image views are not yet used for 8-bpc image
formats, they will be needed in the future to support color transforms
for both textures and render buffers.
master
Manuel Stoeckl 1 year ago committed by Simon Ser
parent 566c413d8f
commit d6859da3b4

@ -394,6 +394,7 @@ struct wlr_vk_texture {
bool owned; // if dmabuf_imported: whether we have ownership of the image bool owned; // if dmabuf_imported: whether we have ownership of the image
bool transitioned; // if dma_imported: whether we transitioned it away from preinit bool transitioned; // if dma_imported: whether we transitioned it away from preinit
bool has_alpha; // whether the image is has alpha channel bool has_alpha; // whether the image is has alpha channel
bool using_mutable_srgb; // is this accessed through _SRGB format view
struct wl_list foreign_link; // wlr_vk_renderer.foreign_textures struct wl_list foreign_link; // wlr_vk_renderer.foreign_textures
struct wl_list destroy_link; // wlr_vk_command_buffer.destroy_textures struct wl_list destroy_link; // wlr_vk_command_buffer.destroy_textures
struct wl_list link; // wlr_vk_renderer.textures struct wl_list link; // wlr_vk_renderer.textures
@ -411,7 +412,7 @@ struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture);
VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,
const struct wlr_dmabuf_attributes *attribs, const struct wlr_dmabuf_attributes *attribs,
VkDeviceMemory mems[static WLR_DMABUF_MAX_PLANES], uint32_t *n_mems, VkDeviceMemory mems[static WLR_DMABUF_MAX_PLANES], uint32_t *n_mems,
bool for_render); bool for_render, bool *using_mutable_srgb);
struct wlr_texture *vulkan_texture_from_buffer( struct wlr_texture *vulkan_texture_from_buffer(
struct wlr_renderer *wlr_renderer, struct wlr_buffer *buffer); struct wlr_renderer *wlr_renderer, struct wlr_buffer *buffer);
void vulkan_texture_destroy(struct wlr_vk_texture *texture); void vulkan_texture_destroy(struct wlr_vk_texture *texture);

@ -730,8 +730,9 @@ static struct wlr_vk_render_buffer *create_render_buffer(
wlr_log(WLR_DEBUG, "vulkan create_render_buffer: %.4s, %dx%d", wlr_log(WLR_DEBUG, "vulkan create_render_buffer: %.4s, %dx%d",
(const char*) &dmabuf.format, dmabuf.width, dmabuf.height); (const char*) &dmabuf.format, dmabuf.width, dmabuf.height);
bool using_mutable_srgb = false;
buffer->image = vulkan_import_dmabuf(renderer, &dmabuf, buffer->image = vulkan_import_dmabuf(renderer, &dmabuf,
buffer->memories, &buffer->mem_count, true); buffer->memories, &buffer->mem_count, true, &using_mutable_srgb);
if (!buffer->image) { if (!buffer->image) {
goto error; goto error;
} }
@ -748,7 +749,7 @@ static struct wlr_vk_render_buffer *create_render_buffer(
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.image = buffer->image, .image = buffer->image,
.viewType = VK_IMAGE_VIEW_TYPE_2D, .viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = fmt->format.vk, .format = using_mutable_srgb ? fmt->format.vk_srgb : fmt->format.vk,
.components.r = VK_COMPONENT_SWIZZLE_IDENTITY, .components.r = VK_COMPONENT_SWIZZLE_IDENTITY,
.components.g = VK_COMPONENT_SWIZZLE_IDENTITY, .components.g = VK_COMPONENT_SWIZZLE_IDENTITY,
.components.b = VK_COMPONENT_SWIZZLE_IDENTITY, .components.b = VK_COMPONENT_SWIZZLE_IDENTITY,
@ -768,7 +769,7 @@ static struct wlr_vk_render_buffer *create_render_buffer(
goto error; goto error;
} }
bool has_blending_buffer = !fmt->format.vk_srgb || true /* temporary */; bool has_blending_buffer = !using_mutable_srgb;
buffer->render_setup = find_or_create_render_setup( buffer->render_setup = find_or_create_render_setup(
renderer, &fmt->format, has_blending_buffer); renderer, &fmt->format, has_blending_buffer);
@ -2028,8 +2029,9 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
goto error; goto error;
} }
} else { } else {
assert(format->vk_srgb);
VkAttachmentDescription attachment = { VkAttachmentDescription attachment = {
.format = format->vk, .format = format->vk_srgb,
.samples = VK_SAMPLE_COUNT_1_BIT, .samples = VK_SAMPLE_COUNT_1_BIT,
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD, .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
.storeOp = VK_ATTACHMENT_STORE_OP_STORE, .storeOp = VK_ATTACHMENT_STORE_OP_STORE,

@ -311,7 +311,8 @@ struct wlr_vk_texture_view *vulkan_texture_get_or_create_view(struct wlr_vk_text
VkImageViewCreateInfo view_info = { VkImageViewCreateInfo view_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
.viewType = VK_IMAGE_VIEW_TYPE_2D, .viewType = VK_IMAGE_VIEW_TYPE_2D,
.format = texture->format->vk, .format = texture->using_mutable_srgb ? texture->format->vk_srgb
: texture->format->vk,
.components.r = VK_COMPONENT_SWIZZLE_IDENTITY, .components.r = VK_COMPONENT_SWIZZLE_IDENTITY,
.components.g = VK_COMPONENT_SWIZZLE_IDENTITY, .components.g = VK_COMPONENT_SWIZZLE_IDENTITY,
.components.b = VK_COMPONENT_SWIZZLE_IDENTITY, .components.b = VK_COMPONENT_SWIZZLE_IDENTITY,
@ -372,10 +373,10 @@ struct wlr_vk_texture_view *vulkan_texture_get_or_create_view(struct wlr_vk_text
} }
static void texture_set_format(struct wlr_vk_texture *texture, static void texture_set_format(struct wlr_vk_texture *texture,
const struct wlr_vk_format *format) { const struct wlr_vk_format *format, bool has_mutable_srgb) {
texture->format = format; texture->format = format;
texture->transform = !format->is_ycbcr && texture->using_mutable_srgb = has_mutable_srgb;
(format->vk_srgb && false /* temporary */) ? texture->transform = !format->is_ycbcr && has_mutable_srgb ?
WLR_VK_TEXTURE_TRANSFORM_IDENTITY : WLR_VK_TEXTURE_TRANSFORM_SRGB; WLR_VK_TEXTURE_TRANSFORM_IDENTITY : WLR_VK_TEXTURE_TRANSFORM_SRGB;
const struct wlr_pixel_format_info *format_info = const struct wlr_pixel_format_info *format_info =
@ -409,7 +410,7 @@ static struct wlr_texture *vulkan_texture_from_pixels(
return NULL; return NULL;
} }
texture_set_format(texture, &fmt->format); texture_set_format(texture, &fmt->format, fmt->shm.has_mutable_srgb);
VkFormat view_formats[2] = { VkFormat view_formats[2] = {
fmt->format.vk, fmt->format.vk,
@ -516,7 +517,7 @@ static bool is_dmabuf_disjoint(const struct wlr_dmabuf_attributes *attribs) {
VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,
const struct wlr_dmabuf_attributes *attribs, const struct wlr_dmabuf_attributes *attribs,
VkDeviceMemory mems[static WLR_DMABUF_MAX_PLANES], uint32_t *n_mems, VkDeviceMemory mems[static WLR_DMABUF_MAX_PLANES], uint32_t *n_mems,
bool for_render) { bool for_render, bool *using_mutable_srgb) {
VkResult res; VkResult res;
VkDevice dev = renderer->dev->dev; VkDevice dev = renderer->dev->dev;
*n_mems = 0u; *n_mems = 0u;
@ -729,6 +730,7 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,
goto error_image; goto error_image;
} }
*using_mutable_srgb = mod->has_mutable_srgb;
return image; return image;
error_image: error_image:
@ -760,13 +762,13 @@ static struct wlr_vk_texture *vulkan_texture_from_dmabuf(
return NULL; return NULL;
} }
texture_set_format(texture, &fmt->format); bool using_mutable_srgb = false;
texture->image = vulkan_import_dmabuf(renderer, attribs, texture->image = vulkan_import_dmabuf(renderer, attribs,
texture->memories, &texture->mem_count, false); texture->memories, &texture->mem_count, false, &using_mutable_srgb);
if (!texture->image) { if (!texture->image) {
goto error; goto error;
} }
texture_set_format(texture, &fmt->format, using_mutable_srgb);
texture->dmabuf_imported = true; texture->dmabuf_imported = true;

Loading…
Cancel
Save