Skip to content

Instantly share code, notes, and snippets.

@nowrep
Created November 8, 2024 10:25
Show Gist options
  • Save nowrep/4c3eab86ad77dcfa605f516b567a66c1 to your computer and use it in GitHub Desktop.
Save nowrep/4c3eab86ad77dcfa605f516b567a66c1 to your computer and use it in GitHub Desktop.
VAAPI VASurfaceFormatAttribDRMFormatModifiers query
/* gcc main.c -o vaapi-modif $(pkg-config --cflags --libs libva libva-drm libdrm) */
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <va/va.h>
#include <va/va_drm.h>
#include <va/va_drmcommon.h>
#include <xf86drm.h>
#define VA_CHECK(x) { if (x != VA_STATUS_SUCCESS) abort(); }
int main(int argc, char *argv[])
{
int fd = open("/dev/dri/renderD128", O_RDWR);
VADisplay dpy = vaGetDisplayDRM(fd);
int major_ver, minor_ver;
VA_CHECK(vaInitialize(dpy, &major_ver, &minor_ver));
VAConfigID config;
VA_CHECK(vaCreateConfig(dpy, VAProfileNone, VAEntrypointVideoProc, NULL, 0, &config));
unsigned int num_attribs;
VA_CHECK(vaQuerySurfaceAttributes(dpy, config, NULL, &num_attribs));
VASurfaceAttrib *attrib_list = calloc(num_attribs, sizeof(VASurfaceAttrib));
VA_CHECK(vaQuerySurfaceAttributes(dpy, config, attrib_list, &num_attribs));
for (unsigned int i = 0; i < num_attribs; i++) {
if (attrib_list[i].type != VASurfaceAttribPixelFormat)
continue;
VADRMFormatModifierList drm_list = {0};
uint32_t fourcc = attrib_list[i].value.value.i;
VASurfaceFormatAttrib format_attrib;
format_attrib.type == VASurfaceFormatAttribDRMFormatModifiers;
format_attrib.value.value.p = &drm_list;
VA_CHECK(vaGetSurfaceFormatAttributes(dpy, config, fourcc, &format_attrib, 1));
drm_list.modifiers = malloc(sizeof(uint64_t) * drm_list.num_modifiers);
VA_CHECK(vaGetSurfaceFormatAttributes(dpy, config, fourcc, &format_attrib, 1));
printf("Format %.4s:\n", &fourcc);
for (unsigned int j = 0; j < drm_list.num_modifiers; j++)
printf("\t%"PRIx64" : %s\n", drm_list.modifiers[j], drmGetFormatModifierName(drm_list.modifiers[j]));
printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment