testsuite: Align udmabuf stride to 256

Aligned stride is necessary for compatibility with GPUs. Recent AMD GPUs
require 256 for non RGB formats. Direct3D 12's RowPitch in
D3D12_SUBRESOURCE_FOOTPRINT requires 256 as well so HW targeting D3D12
will not require a larger alignment.

Fixes: 6cefdfeddd ("testsuite: Fix udmabuf creation")
This commit is contained in:
Janne Grunau 2025-01-05 16:32:35 +01:00
parent 867d178e93
commit d903433315
3 changed files with 18 additions and 5 deletions

View File

@ -7,7 +7,7 @@
static void
test_dmabuf_no_gpu (void)
{
guchar buffer[4];
guchar buffer[UDMABUF_STRIDE_ALIGN];
GdkTexture *texture;
GError *error = NULL;
GdkTextureDownloader *downloader;
@ -27,14 +27,14 @@ test_dmabuf_no_gpu (void)
buffer[2] = 0;
buffer[3] = 255;
bytes = g_bytes_new_static (buffer, 4);
bytes = g_bytes_new_static (buffer, G_N_ELEMENTS(buffer));
texture = udmabuf_texture_new (1, 1,
DRM_FORMAT_RGBA8888,
gdk_color_state_get_srgb (),
FALSE,
bytes,
4,
UDMABUF_STRIDE_ALIGN,
&error);
g_assert_no_error (error);

View File

@ -180,6 +180,9 @@ udmabuf_texture_new (gsize width,
gconstpointer data;
gsize size;
/* Many graphics cards need this and Mesa tries to align its own buffers this way */
g_assert (stride % UDMABUF_STRIDE_ALIGN == 0);
data = g_bytes_get_data (bytes, &size);
udmabuf = udmabuf_allocate (size, error);
@ -236,7 +239,8 @@ udmabuf_texture_from_texture (GdkTexture *texture,
GdkTextureDownloader *downloader;
guint fourcc;
gboolean premultiplied;
gsize stride;
guchar *data;
gsize width, height, stride;
GBytes *bytes;
GdkTexture *texture2;
@ -275,12 +279,19 @@ udmabuf_texture_from_texture (GdkTexture *texture,
return NULL;
}
width = gdk_texture_get_width (texture);
height = gdk_texture_get_height (texture);
stride = (width * 4 + (UDMABUF_STRIDE_ALIGN - 1)) & ~(UDMABUF_STRIDE_ALIGN - 1);
data = g_malloc_n(stride, height);
downloader = gdk_texture_downloader_new (texture);
gdk_texture_downloader_set_format (downloader, gdk_texture_get_format (texture));
gdk_texture_downloader_set_color_state (downloader, gdk_texture_get_color_state (texture));
bytes = gdk_texture_downloader_download_bytes (downloader, &stride);
gdk_texture_downloader_download_into (downloader, data, stride);
gdk_texture_downloader_free (downloader);
bytes = g_bytes_new_take(data, stride * height);
texture2 = udmabuf_texture_new (gdk_texture_get_width (texture),
gdk_texture_get_height (texture),
fourcc,

View File

@ -2,6 +2,8 @@
#include <gtk/gtk.h>
#define UDMABUF_STRIDE_ALIGN 256U
gboolean udmabuf_initialize (GError **error);
GdkTexture * udmabuf_texture_new (gsize width,