diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c index 5b49d0fde3..22dcd7a4ae 100644 --- a/render/vulkan/renderer.c +++ b/render/vulkan/renderer.c @@ -412,7 +412,7 @@ static void destroy_render_buffer(struct wlr_vk_render_buffer *buffer) { } static struct wlr_vk_render_buffer *get_render_buffer( - struct wlr_vk_renderer* renderer, struct wlr_buffer *wlr_buffer) { + struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) { struct wlr_vk_render_buffer *buffer; wl_list_for_each(buffer, &renderer->render_buffers, link) { if (buffer->wlr_buffer == wlr_buffer) { @@ -431,6 +431,7 @@ static void handle_render_buffer_destroy(struct wl_listener *listener, void *dat static struct wlr_vk_render_buffer *create_render_buffer( struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) { VkResult res; + struct wlr_vk_render_buffer *buffer = calloc(1, sizeof(*buffer)); if (buffer == NULL) { wlr_log_errno(WLR_ERROR, "Allocation failed"); @@ -444,6 +445,9 @@ static struct wlr_vk_render_buffer *create_render_buffer( goto error_buffer; } + wlr_log(WLR_DEBUG, "vulkan create_render_buffer: %.4s, %dx%d", + (const char*) &dmabuf.format, dmabuf.width, dmabuf.height); + // NOTE: we could at least support WLR_DMABUF_ATTRIBUTES_FLAGS_Y_INVERT // if it is needed by anyone. Can be implemented using negative viewport // height or flipping matrix. @@ -463,7 +467,8 @@ static struct wlr_vk_render_buffer *create_render_buffer( struct wlr_vk_format_props *fmt = wlr_vk_format_from_drm(renderer->dev, dmabuf.format); if (fmt == NULL) { - wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIu32, dmabuf.format); + wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIx32 " (%.4s)", + dmabuf.format, (const char*) &dmabuf.format); goto error_buffer; } @@ -522,6 +527,7 @@ static struct wlr_vk_render_buffer *create_render_buffer( vkFreeMemory(dev, buffer->memories[i], NULL); } error_buffer: + wlr_dmabuf_attributes_finish(&dmabuf); free(buffer); return NULL; } @@ -808,7 +814,7 @@ static bool vulkan_render_subtexture_with_matrix(struct wlr_renderer *wlr_render renderer->pipe_layout, 0, 1, &texture->ds, 0, NULL); } - struct vert_pcr_data vert_pcr_data; + struct vert_pcr_data vert_pcr_data; mat3_to_mat4(matrix, vert_pcr_data.mat4); vert_pcr_data.uv_off[0] = box->x / wlr_texture->width; vert_pcr_data.uv_off[1] = box->y / wlr_texture->height; @@ -820,6 +826,10 @@ static bool vulkan_render_subtexture_with_matrix(struct wlr_renderer *wlr_render vert_pcr_data.uv_size[1] = -vert_pcr_data.uv_size[1]; } + if (!texture->format->has_alpha) { + alpha *= -1; + } + vkCmdPushConstants(cb, renderer->pipe_layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(vert_pcr_data), &vert_pcr_data); vkCmdPushConstants(cb, renderer->pipe_layout, diff --git a/render/vulkan/shaders/common.vert b/render/vulkan/shaders/common.vert index 8868670d13..1a076d8ddc 100644 --- a/render/vulkan/shaders/common.vert +++ b/render/vulkan/shaders/common.vert @@ -19,7 +19,8 @@ const vec2[] values = { }; void main() { - uv = data.uv_offset + values[gl_VertexIndex % 4] * data.uv_size; - gl_Position = data.proj * vec4(uv, 0.0, 1.0); + vec2 pos = values[gl_VertexIndex % 4]; + uv = data.uv_offset + pos * data.uv_size; + gl_Position = data.proj * vec4(pos, 0.0, 1.0); gl_Position.y = -gl_Position.y; // invert y coord for screen space } diff --git a/render/vulkan/shaders/texture.frag b/render/vulkan/shaders/texture.frag index 02d99580e4..be3785b7bb 100644 --- a/render/vulkan/shaders/texture.frag +++ b/render/vulkan/shaders/texture.frag @@ -11,6 +11,11 @@ layout(push_constant) uniform UBO { void main() { out_color = texture(tex, uv); - out_color.a *= data.alpha; + + if (data.alpha < 0.0) { + out_color.a = -data.alpha; + } else { + out_color.a *= data.alpha; + } } diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c index d27f0e5d8f..56771d0af2 100644 --- a/render/vulkan/texture.c +++ b/render/vulkan/texture.c @@ -231,10 +231,13 @@ struct wlr_texture *vulkan_texture_from_pixels(struct wlr_renderer *wlr_renderer VkResult res; VkDevice dev = renderer->dev->dev; + wlr_log(WLR_DEBUG, "vulkan_texture_from_pixels: %.4s, %dx%d", + (const char*) &drm_fmt, width, height); + const struct wlr_vk_format_props *fmt = wlr_vk_format_from_drm(renderer->dev, drm_fmt); if (fmt == NULL) { - wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIu32 " (%.4s)", + wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIx32 " (%.4s)", drm_fmt, (const char*) &drm_fmt); return NULL; } @@ -387,7 +390,7 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, struct wlr_vk_format_props *fmt = wlr_vk_format_from_drm(renderer->dev, attribs->format); if (fmt == NULL) { - wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIu32 " (%.4s)", + wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIx32 " (%.4s)", attribs->format, (const char*) &attribs->format); return VK_NULL_HANDLE; } @@ -397,8 +400,9 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, struct wlr_vk_format_modifier_props *mod = wlr_vk_format_props_find_modifier(fmt, attribs->modifier, for_render); if (!mod || !(mod->dmabuf_flags & VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT)) { - wlr_log(WLR_ERROR, "Format %"PRIu32" can't be used with modifier " - "%"PRIu64, attribs->format, attribs->modifier); + wlr_log(WLR_ERROR, "Format %"PRIx32" (%.4s) can't be used with modifier " + "%"PRIu64, attribs->format, (const char*) &attribs->format, + attribs->modifier); return VK_NULL_HANDLE; } @@ -596,15 +600,19 @@ VkImage vulkan_import_dmabuf(struct wlr_vk_renderer *renderer, struct wlr_texture *vulkan_texture_from_dmabuf(struct wlr_renderer *wlr_renderer, struct wlr_dmabuf_attributes *attribs) { - struct wlr_vk_renderer* renderer = vulkan_get_renderer(wlr_renderer); + struct wlr_vk_renderer *renderer = vulkan_get_renderer(wlr_renderer); VkResult res; VkDevice dev = renderer->dev->dev; + wlr_log(WLR_DEBUG, "vulkan_texture_from_dmabuf: %.4s, %dx%d", + (const char*) &attribs->format, attribs->width, attribs->height); + struct wlr_vk_format_props *fmt = wlr_vk_format_from_drm(renderer->dev, attribs->format); if (fmt == NULL) { - wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIu32, attribs->format); + wlr_log(WLR_ERROR, "Unsupported pixel format %"PRIx32 " (%.4s)", + attribs->format, (const char*) &attribs->format); return NULL; } diff --git a/render/vulkan/vulkan.c b/render/vulkan/vulkan.c index 993352fc61..ebb40ddb69 100644 --- a/render/vulkan/vulkan.c +++ b/render/vulkan/vulkan.c @@ -290,7 +290,7 @@ static void log_phdev(const VkPhysicalDeviceProperties *props) { uint32_t dv_minor = (props->driverVersion >> 12) & 0x3ff; uint32_t dv_patch = (props->driverVersion) & 0xfff; - const char* dev_type = "unknown"; + const char *dev_type = "unknown"; switch(props->deviceType) { case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: dev_type = "integrated"; @@ -387,7 +387,7 @@ VkPhysicalDevice wlr_vk_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd) continue; } - const char* name = VK_EXT_PCI_BUS_INFO_EXTENSION_NAME; + const char *name = VK_EXT_PCI_BUS_INFO_EXTENSION_NAME; if (find_extensions(avail_ext_props, avail_extc, &name, 1) != NULL) { wlr_log(WLR_INFO, " Can't check pci info of device, " @@ -488,7 +488,7 @@ struct wlr_vk_device *wlr_vk_device_create(struct wlr_vk_instance *ini, }; unsigned nc = sizeof(names) / sizeof(names[0]); - const char* not_found = find_extensions(avail_ext_props, avail_extc, names, nc); + const char *not_found = find_extensions(avail_ext_props, avail_extc, names, nc); if (not_found) { wlr_log(WLR_ERROR, "vulkan: required device extesnion %s not found", not_found); @@ -503,7 +503,7 @@ struct wlr_vk_device *wlr_vk_device_create(struct wlr_vk_instance *ini, // isn't well-defined without it. But since the only platform // I could test this on (anv with VK_EXT_image_drm_format_modifier MR) // does not expose it and works fine without it, it's optional for now. - const char* name = VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME; + const char *name = VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME; if (find_extensions(avail_ext_props, avail_extc, names, nc) != NULL) { dev->extensions[dev->extension_count++] = name; } else {