config: add tweak.min-stride-alignment

This allows the user to configure the value by which a surface
buffer's stride must be an even multiple of.

This can be used to ensure the stride meets the GPU driver's
requirements for direct import.

Defaults to 256. Set to 0 to disable.

Closes #2182
This commit is contained in:
Daniel Eklöf 2025-10-04 09:29:56 +02:00
parent 80951ab7a6
commit fac3994154
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 29 additions and 1 deletions

View file

@ -2848,6 +2848,10 @@ parse_section_tweak(struct context *ctx)
#endif
}
else if (streq(key, "min-stride-alignment")) {
return value_to_uint32(ctx, 10, &conf->tweak.min_stride_alignment);
}
else {
LOG_CONTEXTUAL_ERR("not a valid option: %s", key);
return false;
@ -3496,6 +3500,7 @@ config_load(struct config *conf, const char *conf_path,
.font_monospace_warn = true,
.sixel = true,
.surface_bit_depth = SHM_BITS_AUTO,
.min_stride_alignment = 256,
},
.touch = {

View file

@ -435,6 +435,7 @@ struct config {
bool font_monospace_warn;
bool sixel;
enum shm_bit_depth surface_bit_depth;
uint32_t min_stride_alignment;
} tweak;
struct {

1
main.c
View file

@ -597,6 +597,7 @@ main(int argc, char *const *argv)
}
shm_set_max_pool_size(conf.tweak.max_shm_pool_size);
shm_set_min_stride_alignment(conf.tweak.min_stride_alignment);
if ((fdm = fdm_init()) == NULL)
goto out;

17
shm.c
View file

@ -13,7 +13,6 @@
#include <pixman.h>
#include <fcft/stride.h>
#include <tllist.h>
#define LOG_MODULE "shm"
@ -21,6 +20,7 @@
#include "log.h"
#include "debug.h"
#include "macros.h"
#include "stride.h"
#include "xmalloc.h"
#if !defined(MAP_UNINITIALIZED)
@ -61,6 +61,8 @@ static off_t max_pool_size = 512 * 1024 * 1024;
static bool can_punch_hole = false;
static bool can_punch_hole_initialized = false;
static size_t min_stride_alignment = 0;
struct buffer_pool {
int fd; /* memfd */
struct wl_shm_pool *wl_pool;
@ -113,6 +115,12 @@ shm_set_max_pool_size(off_t _max_pool_size)
max_pool_size = _max_pool_size;
}
void
shm_set_min_stride_alignment(size_t _min_stride_alignment)
{
min_stride_alignment = _min_stride_alignment;
}
static void
buffer_destroy_dont_close(struct buffer *buf)
{
@ -342,6 +350,13 @@ get_new_buffers(struct buffer_chain *chain, size_t count,
? chain->pixman_fmt_with_alpha
: chain->pixman_fmt_without_alpha,
widths[i]);
if (min_stride_alignment > 0) {
const size_t m = min_stride_alignment;
stride[i] = (stride[i] + m - 1) / m * m;
}
xassert(min_stride_alignment == 0 || stride[i] % min_stride_alignment == 0);
sizes[i] = stride[i] * heights[i];
total_size += sizes[i];
}

3
shm.h
View file

@ -42,7 +42,10 @@ struct buffer {
};
void shm_fini(void);
/* TODO: combine into shm_init() */
void shm_set_max_pool_size(off_t max_pool_size);
void shm_set_min_stride_alignment(size_t min_stride_alignment);
struct buffer_chain;
struct buffer_chain *shm_chain_new(

View file

@ -1413,6 +1413,9 @@ test_section_tweak(void)
test_float(&ctx, &parse_section_tweak, "bold-text-in-bright-amount",
&conf.bold_in_bright.amount);
test_uint32(&ctx, &parse_section_tweak, "min-stride-alignment",
&conf.tweak.min_stride_alignment);
#if 0 /* Must be equal to, or less than INT32_MAX */
test_uint32(&ctx, &parse_section_tweak, "max-shm-pool-size-mb",
&conf.tweak.max_shm_pool_size);