Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
vulkan: Add detailed texture logging & fix flipped y
Browse files Browse the repository at this point in the history
  • Loading branch information
nyorain committed Mar 10, 2021
1 parent 31ed467 commit c890a1f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
16 changes: 13 additions & 3 deletions render/vulkan/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand All @@ -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.
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions render/vulkan/shaders/common.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion render/vulkan/shaders/texture.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

20 changes: 14 additions & 6 deletions render/vulkan/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions render/vulkan/vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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, "
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down

0 comments on commit c890a1f

Please sign in to comment.