vulkan-renderer: support fragment debug binding

Add a debug binding and mode to highlight (green tint) what has
been rendered through vulkan-renderer composition. This is useful
to visually identify/debug clients which have been offloaded to
DRM planes, since those won't go through the renderer composition
process and therefore won't be highlighted the same way.
Since this is the first debug mode in vulkan-renderer, add some
initial infrastructure to handle debug bindings.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
This commit is contained in:
Erico Nunes 2025-10-05 11:48:42 +02:00 committed by Marius Vlad
parent 68d3d3badc
commit 53895cac2f
5 changed files with 46 additions and 2 deletions

View file

@ -62,6 +62,7 @@ struct vertex_tc {
struct fs_specialization_consts {
uint32_t c_variant;
uint32_t c_input_is_premult;
uint32_t c_green_tint;
};
static void create_graphics_pipeline(struct vulkan_renderer *vr,
@ -93,11 +94,13 @@ static void create_graphics_pipeline(struct vulkan_renderer *vr,
const struct fs_specialization_consts fsc = {
req->variant,
req->input_is_premult
req->input_is_premult,
req->green_tint,
};
const VkSpecializationMapEntry fsc_entries[] = {
{ 0, offsetof(struct fs_specialization_consts, c_variant), sizeof(fsc.c_variant) },
{ 1, offsetof(struct fs_specialization_consts, c_input_is_premult), sizeof(fsc.c_input_is_premult) },
{ 2, offsetof(struct fs_specialization_consts, c_green_tint), sizeof(fsc.c_green_tint) },
};
const VkSpecializationInfo fs_specialization = {
.mapEntryCount = ARRAY_LENGTH(fsc_entries),

View file

@ -102,6 +102,7 @@ struct vulkan_pipeline_requirements
unsigned variant:4; /* enum vulkan_pipeline_texture_variant */
bool input_is_premult:1;
bool blend:1;
bool green_tint:1;
VkRenderPass renderpass;
};
@ -182,6 +183,10 @@ struct vulkan_renderer {
PFN_vkGetSemaphoreFdKHR get_semaphore_fd;
PFN_vkImportSemaphoreFdKHR import_semaphore_fd;
/* Debug modes. */
struct weston_binding *debug_mode_binding;
int debug_mode;
/* This can be removed if a different shader is defined
* to avoid requiring a valid sampler descriptor to run
* for solids */

View file

@ -31,6 +31,7 @@
#include "config.h"
#include <fcntl.h>
#include <linux/input.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -62,6 +63,12 @@
#include <xf86drm.h> /* Physical device drm */
enum vulkan_debug_mode {
DEBUG_MODE_NONE = 0,
DEBUG_MODE_FRAGMENT,
DEBUG_MODE_LAST,
};
enum vulkan_border_status {
BORDER_STATUS_CLEAN = 0,
BORDER_TOP_DIRTY = 1 << WESTON_RENDERER_BORDER_TOP,
@ -1497,6 +1504,7 @@ static bool
vulkan_pipeline_config_init_for_paint_node(struct vulkan_pipeline_config *pconf,
struct weston_paint_node *pnode)
{
struct vulkan_renderer *vr = get_renderer(pnode->surface->compositor);
struct vulkan_output_state *vo = get_output_state(pnode->output);
struct vulkan_surface_state *vs = get_surface_state(pnode->surface);
struct vulkan_buffer_state *vb = vs->buffer;
@ -1509,6 +1517,7 @@ vulkan_pipeline_config_init_for_paint_node(struct vulkan_pipeline_config *pconf,
.req = {
.texcoord_input = SHADER_TEXCOORD_INPUT_SURFACE,
.renderpass = vo->renderpass,
.green_tint = (vr->debug_mode == DEBUG_MODE_FRAGMENT),
},
.projection = pnode->view->transform.matrix,
.surface_to_buffer =
@ -2128,6 +2137,7 @@ draw_output_borders(struct weston_output *output,
.renderpass = vo->renderpass,
.variant = pipeline_variant,
.input_is_premult = true,
.green_tint = (vr->debug_mode == DEBUG_MODE_FRAGMENT),
},
.view_alpha = 1.0f,
};
@ -4119,6 +4129,21 @@ populate_supported_shm_formats(struct weston_compositor *ec)
return 0;
}
static void
debug_mode_binding(struct weston_keyboard *keyboard,
const struct timespec *time,
uint32_t key, void *data)
{
struct weston_compositor *compositor = data;
struct vulkan_renderer *vr = get_renderer(compositor);
int mode;
mode = (vr->debug_mode + 1) % DEBUG_MODE_LAST;
vr->debug_mode = mode;
weston_compositor_damage_all(compositor);
}
/*
* Add extension flags to the bitfield that 'flags_out' points to.
* 'table' stores extension names and flags to check for and 'avail'
@ -4442,6 +4467,10 @@ vulkan_renderer_display_create(struct weston_compositor *ec,
create_texture_image_dummy(vr); /* Workaround for solids */
vr->debug_mode_binding =
weston_compositor_add_debug_binding(ec, KEY_M,
debug_mode_binding, ec);
return 0;
}

View file

@ -12,6 +12,7 @@ layout(location = 0) out vec4 fragcolor;
layout(constant_id = 0) const int c_variant = 0;
layout(constant_id = 1) const bool c_input_is_premult = false;
layout(constant_id = 2) const bool c_green_tint = false;
#define PIPELINE_VARIANT_RGBA 1
#define PIPELINE_VARIANT_RGBX 2
@ -53,5 +54,9 @@ void main() {
color *= ubo.view_alpha;
/* Fragment shader (composition) debug */
if (c_green_tint)
color = vec4(0.0, 0.3, 0.0, 0.2) + color * 0.8;
fragcolor = color;
}

View file

@ -142,7 +142,9 @@ Start VAAPI recorder.
.RE
- KEY_M :
.RS 4
Cycle through gl-renderer debug modes: none, wireframe, batches, damage, opaque.
Cycle through renderer debug modes.
gl-renderer debug modes: none, wireframe, batches, damage, opaque.
vulkan-renderer debug modes: none, fragment.
.RE
- KEY_R :
.RS 4