|
2 | 2 | * va_drm_utils.c - VA/DRM Utilities
|
3 | 3 | *
|
4 | 4 | * Copyright (c) 2012 Intel Corporation. All Rights Reserved.
|
| 5 | + * Copyright (c) 2023 Emil Velikov |
5 | 6 | *
|
6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a
|
7 | 8 | * copy of this software and associated documentation files (the
|
|
31 | 32 | #include "va_drm_utils.h"
|
32 | 33 | #include "va_drmcommon.h"
|
33 | 34 |
|
| 35 | +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
| 36 | + |
34 | 37 | struct driver_name_map {
|
35 | 38 | const char *key;
|
36 | 39 | const char *name;
|
@@ -148,3 +151,65 @@ VA_DRM_GetDriverName(VADriverContextP ctx, char **driver_name_ptr, int candidate
|
148 | 151 |
|
149 | 152 | return VA_STATUS_SUCCESS;
|
150 | 153 | }
|
| 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 | +} |
0 commit comments