render/vulkan: de-duplicate VkImageUsageFlags

The flags passed to vkCreateImage() must match the flags used when
querying formats. Make this clearer by using the same variable.
master
Simon Ser 1 year ago
parent b18a849fc3
commit 65bbbbbf0c

@ -90,6 +90,8 @@ struct wlr_vk_format {
bool is_ycbcr; bool is_ycbcr;
}; };
extern const VkImageUsageFlags vulkan_render_usage, vulkan_shm_tex_usage, vulkan_dma_tex_usage;
// Returns all known format mappings. // Returns all known format mappings.
// Might not be supported for gpu/usecase. // Might not be supported for gpu/usecase.
const struct wlr_vk_format *vulkan_get_format_list(size_t *len); const struct wlr_vk_format *vulkan_get_format_list(size_t *len);

@ -230,13 +230,13 @@ const struct wlr_vk_format *vulkan_get_format_from_drm(uint32_t drm_format) {
return NULL; return NULL;
} }
static const VkImageUsageFlags render_usage = const VkImageUsageFlags vulkan_render_usage =
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT; VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
static const VkImageUsageFlags shm_tex_usage = const VkImageUsageFlags vulkan_shm_tex_usage =
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_SAMPLED_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT; VK_IMAGE_USAGE_TRANSFER_DST_BIT;
static const VkImageUsageFlags dma_tex_usage = const VkImageUsageFlags vulkan_dma_tex_usage =
VK_IMAGE_USAGE_SAMPLED_BIT; VK_IMAGE_USAGE_SAMPLED_BIT;
static const VkFormatFeatureFlags render_features = static const VkFormatFeatureFlags render_features =
@ -357,7 +357,7 @@ static bool query_modifier_support(struct wlr_vk_device *dev,
if ((m.drmFormatModifierTilingFeatures & render_features) == render_features && if ((m.drmFormatModifierTilingFeatures & render_features) == render_features &&
!props->format.is_ycbcr) { !props->format.is_ycbcr) {
struct wlr_vk_format_modifier_props p = {0}; struct wlr_vk_format_modifier_props p = {0};
if (query_modifier_usage_support(dev, props->format.vk, render_usage, &m, &p, &errmsg)) { if (query_modifier_usage_support(dev, props->format.vk, vulkan_render_usage, &m, &p, &errmsg)) {
props->dmabuf.render_mods[props->dmabuf.render_mod_count++] = p; props->dmabuf.render_mods[props->dmabuf.render_mod_count++] = p;
wlr_drm_format_set_add(&dev->dmabuf_render_formats, wlr_drm_format_set_add(&dev->dmabuf_render_formats,
props->format.drm, m.drmFormatModifier); props->format.drm, m.drmFormatModifier);
@ -380,7 +380,7 @@ static bool query_modifier_support(struct wlr_vk_device *dev,
} }
if ((m.drmFormatModifierTilingFeatures & features) == features) { if ((m.drmFormatModifierTilingFeatures & features) == features) {
struct wlr_vk_format_modifier_props p = {0}; struct wlr_vk_format_modifier_props p = {0};
if (query_modifier_usage_support(dev, props->format.vk, dma_tex_usage, &m, &p, &errmsg)) { if (query_modifier_usage_support(dev, props->format.vk, vulkan_dma_tex_usage, &m, &p, &errmsg)) {
props->dmabuf.texture_mods[props->dmabuf.texture_mod_count++] = p; props->dmabuf.texture_mods[props->dmabuf.texture_mod_count++] = p;
wlr_drm_format_set_add(&dev->dmabuf_texture_formats, wlr_drm_format_set_add(&dev->dmabuf_texture_formats,
props->format.drm, m.drmFormatModifier); props->format.drm, m.drmFormatModifier);
@ -445,7 +445,7 @@ void vulkan_format_props_query(struct wlr_vk_device *dev,
.type = VK_IMAGE_TYPE_2D, .type = VK_IMAGE_TYPE_2D,
.format = format->vk, .format = format->vk,
.tiling = VK_IMAGE_TILING_OPTIMAL, .tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = shm_tex_usage, .usage = vulkan_shm_tex_usage,
}; };
VkImageFormatProperties2 ifmtp = { VkImageFormatProperties2 ifmtp = {
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,

@ -402,7 +402,7 @@ static struct wlr_texture *vulkan_texture_from_pixels(
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.extent = (VkExtent3D) { width, height, 1 }, .extent = (VkExtent3D) { width, height, 1 },
.tiling = VK_IMAGE_TILING_OPTIMAL, .tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, .usage = vulkan_shm_tex_usage,
}; };
res = vkCreateImage(dev, &img_info, NULL, &texture->image); res = vkCreateImage(dev, &img_info, NULL, &texture->image);
@ -546,9 +546,7 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer,
.sharingMode = VK_SHARING_MODE_EXCLUSIVE, .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.extent = (VkExtent3D) { attribs->width, attribs->height, 1 }, .extent = (VkExtent3D) { attribs->width, attribs->height, 1 },
.usage = for_render ? .usage = for_render ? vulkan_render_usage : vulkan_dma_tex_usage,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT :
VK_IMAGE_USAGE_SAMPLED_BIT,
}; };
if (disjoint) { if (disjoint) {
img_info.flags = VK_IMAGE_CREATE_DISJOINT_BIT; img_info.flags = VK_IMAGE_CREATE_DISJOINT_BIT;

Loading…
Cancel
Save