Skip to content

Commit 5dae76d

Browse files
evelikovXinfengZhang
authored andcommitted
drm: implement vaGetDriverNames
v2: Add WSL case v3: Drop sentinel, use ARRAY_SIZE Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
1 parent 451e18b commit 5dae76d

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

va/drm/va_drm.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
3+
* Copyright (c) 2023 Emil Velikov
34
*
45
* Permission is hereby granted, free of charge, to any person obtaining a
56
* copy of this software and associated documentation files (the
@@ -94,6 +95,21 @@ va_DisplayContextGetDriverNameByIndex(
9495
return VA_DRM_GetDriverName(ctx, driver_name_ptr, candidate_index);
9596
}
9697

98+
static VAStatus
99+
va_DisplayContextGetDriverNames(
100+
VADisplayContextP pDisplayContext,
101+
char **drivers,
102+
unsigned *num_drivers
103+
)
104+
{
105+
VADriverContextP const ctx = pDisplayContext->pDriverContext;
106+
VAStatus status = va_DisplayContextConnect(pDisplayContext);
107+
if (status != VA_STATUS_SUCCESS)
108+
return status;
109+
110+
return VA_DRM_GetDriverNames(ctx, drivers, num_drivers);
111+
}
112+
97113
VADisplay
98114
vaGetDisplayDRM(int fd)
99115
{
@@ -119,6 +135,7 @@ vaGetDisplayDRM(int fd)
119135
pDisplayContext->vaDestroy = va_DisplayContextDestroy;
120136
pDisplayContext->vaGetNumCandidates = va_DisplayContextGetNumCandidates;
121137
pDisplayContext->vaGetDriverNameByIndex = va_DisplayContextGetDriverNameByIndex;
138+
pDisplayContext->vaGetDriverNames = va_DisplayContextGetDriverNames;
122139

123140
pDriverContext = va_newDriverContext(pDisplayContext);
124141
if (!pDriverContext)

va/drm/va_drm_utils.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* va_drm_utils.c - VA/DRM Utilities
33
*
44
* Copyright (c) 2012 Intel Corporation. All Rights Reserved.
5+
* Copyright (c) 2023 Emil Velikov
56
*
67
* Permission is hereby granted, free of charge, to any person obtaining a
78
* copy of this software and associated documentation files (the
@@ -31,6 +32,8 @@
3132
#include "va_drm_utils.h"
3233
#include "va_drmcommon.h"
3334

35+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
36+
3437
struct driver_name_map {
3538
const char *key;
3639
const char *name;
@@ -148,3 +151,65 @@ VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr, int candidate
148151

149152
return VA_STATUS_SUCCESS;
150153
}
154+
155+
/* Returns the VA driver names and how many they are, for the active display */
156+
VAStatus
157+
VA_DRM_GetDriverNames(VADriverContextP ctx, char **drivers, unsigned *num_drivers)
158+
{
159+
#define MAX_NAMES 2 // Adjust if needed
160+
161+
static const struct {
162+
const char * const drm_driver;
163+
const char * const va_driver[MAX_NAMES];
164+
} map[] = {
165+
{ "i915", { "iHD", "i965" } }, // Intel Media and OTC GenX
166+
{ "pvrsrvkm", { "pvr" } }, // Intel UMG PVR
167+
{ "radeon", { "r600", "radeonsi" } }, // Mesa Gallium
168+
{ "amdgpu", { "radeonsi" } }, // Mesa Gallium
169+
{ "WSL", { "d3d12" } }, // Mesa Gallium
170+
{ "nvidia-drm", { "nvidia" } }, // Unofficial NVIDIA
171+
};
172+
173+
const struct drm_state * const drm_state = ctx->drm_state;
174+
char *drm_driver;
175+
unsigned count = 0;
176+
177+
drm_driver = va_DRM_GetDrmDriverName(drm_state->fd);
178+
if (!drm_driver)
179+
return VA_STATUS_ERROR_UNKNOWN;
180+
181+
/* Map vgem to WSL2 for Windows subsystem for linux */
182+
struct utsname sysinfo = {};
183+
if (!strncmp(drm_driver, "vgem", 4) && uname(&sysinfo) >= 0 &&
184+
strstr(sysinfo.release, "WSL")) {
185+
free(drm_driver);
186+
drm_driver = strdup("WSL");
187+
if (!drm_driver)
188+
return VA_STATUS_ERROR_UNKNOWN;
189+
}
190+
191+
for (unsigned i = 0; i < ARRAY_SIZE(map); i++) {
192+
if (strcmp(map[i].drm_driver, drm_driver) == 0) {
193+
const char * const *va_drivers = map[i].va_driver;
194+
195+
while (va_drivers[count]) {
196+
if (count < MAX_NAMES && count < *num_drivers)
197+
drivers[count] = strdup(va_drivers[count]);
198+
count++;
199+
}
200+
break;
201+
}
202+
}
203+
204+
/* Fallback to the drm driver, if there's no va equivalent in the map. */
205+
if (!count) {
206+
drivers[count] = drm_driver;
207+
count++;
208+
} else {
209+
free(drm_driver);
210+
}
211+
212+
*num_drivers = count;
213+
214+
return VA_STATUS_SUCCESS;
215+
}

va/drm/va_drm_utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
#ifdef __cplusplus
4242
extern "C" {
4343
#endif
44+
4445
DLL_HIDDEN
4546
VAStatus
4647
VA_DRM_GetNumCandidates(VADriverContextP ctx, int * num_candidates);
48+
4749
/**
4850
* \brief Returns the VA driver name for the active display.
4951
*
@@ -66,6 +68,10 @@ DLL_HIDDEN
6668
VAStatus
6769
VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr, int candidate_index);
6870

71+
DLL_HIDDEN
72+
VAStatus
73+
VA_DRM_GetDriverNames(VADriverContextP ctx, char **drivers, unsigned *num_drivers);
74+
6975
/**@}*/
7076

7177
#ifdef __cplusplus

0 commit comments

Comments
 (0)