Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vaGetDeviceNames inspired fixes and documentation #733

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions va/va.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,6 @@ static VAStatus va_new_opendriver(VADisplay dpy)
const char *driver_name_env;
VADriverContextP ctx;

/* XXX: Temporary dummy return, until all platforms are converted */
if (!pDisplayContext->vaGetDriverNames)
return VA_STATUS_ERROR_INVALID_PARAMETER;

/* XXX: The order is bonkers - env var should take highest priority, then
* override (which ought to be nuked) than native. It's not possible atm,
* since the DPY connect/init happens during the GetDriverNames.
Expand All @@ -687,9 +683,6 @@ static VAStatus va_new_opendriver(VADisplay dpy)
/* Print and error yet continue, as per the above ordering note */
va_errorMessage(dpy, "vaGetDriverNames() failed with %s\n", vaErrorStr(vaStatus));
num_drivers = 0;
} else if (num_drivers > ARRAY_SIZE(drivers)) {
va_errorMessage(dpy, "DRIVER BUG: vaGetDriverNames() provides too many drivers\n");
num_drivers = ARRAY_SIZE(drivers);
}

ctx = CTX(dpy);
Expand Down
21 changes: 21 additions & 0 deletions va/va_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,30 +663,51 @@ struct VADisplayContext {
VADisplayContextP ctx
);

/* Deprecated */
VAStatus(*vaGetDriverName)(
VADisplayContextP ctx,
char **driver_name
);

void *opaque; /* opaque for display extensions (e.g. GLX) */
void *vatrace; /* opaque for VA trace context */
/* Deprecated */
void *vafool; /* opaque for VA fool context */

VAMessageCallback error_callback;
void *error_callback_user_context;
VAMessageCallback info_callback;
void *info_callback_user_context;

/* Deprecated */
VAStatus(*vaGetNumCandidates)(
VADisplayContextP ctx,
int * num_candidates
);

/* Deprecated */
VAStatus(*vaGetDriverNameByIndex)(
VADisplayContextP ctx,
char **driver_name,
int candidate_index
);

/**
* \brief Callback to get an array of driver names.
*
*
* The caller must provide a num_drivers
* This structure is allocated from libva with calloc().
*
* @param drivers An num_drivers sized array of null terminated strings.
* The array is managed my the caller. The callee will
* populate the individual driver name strings and the
* caller must free them.
* @param num_driver The number of driver strings contained within drivers.
* The caller must set that to the size of the drivers
* array, where the callee will update the value to
* min(caller num_driver, num_drivers_support).
*/
VAStatus(*vaGetDriverNames)(
VADisplayContextP ctx,
char **drivers,
Expand Down
14 changes: 5 additions & 9 deletions va/win32/va_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,17 @@
const char VAAPI_DEFAULT_DRIVER_NAME[] = "vaon12";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is Reviewed-by: Sil Vilerino <[email protected]>


typedef struct _VADisplayContextWin32 {
LUID adapter_luid;
char registry_driver_name[MAX_PATH];
bool registry_driver_available_flag;
} VADisplayContextWin32;

static void LoadDriverNameFromRegistry(VADisplayContextWin32* pWin32Ctx)
static void LoadDriverNameFromRegistry(const LUID* adapter_luid, VADisplayContextWin32* pWin32Ctx)
{
HMODULE hGdi32 = LoadLibraryA("gdi32.dll");
if (!hGdi32)
return;

D3DKMT_OPENADAPTERFROMLUID OpenArgs = { .AdapterLuid = pWin32Ctx->adapter_luid };
D3DKMT_OPENADAPTERFROMLUID OpenArgs = { .AdapterLuid = *adapter_luid };
D3DDDI_QUERYREGISTRY_INFO RegistryInfo = {
.QueryType = D3DDDI_QUERYREGISTRY_ADAPTERKEY,
.QueryFlags.TranslatePath = true,
Expand Down Expand Up @@ -180,16 +179,13 @@ VADisplay vaGetDisplayWin32(

VADisplayContextWin32* pWin32Ctx = (VADisplayContextWin32*) pDisplayContext->opaque;
if (adapter_luid) {
/* Copy LUID information to display context */
memcpy(&pWin32Ctx->adapter_luid, adapter_luid, sizeof(pWin32Ctx->adapter_luid));

/* Load the preferred driver name from the driver registry if available */
LoadDriverNameFromRegistry(pWin32Ctx);
LoadDriverNameFromRegistry(adapter_luid, pWin32Ctx);
#ifdef _DEBUG
if (pWin32Ctx->registry_driver_available_flag) {
fprintf(stderr, "VA_Win32: Found driver %s in the registry for LUID %ld %ld \n", pWin32Ctx->registry_driver_name, pWin32Ctx->adapter_luid.LowPart, pWin32Ctx->adapter_luid.HighPart);
fprintf(stderr, "VA_Win32: Found driver %s in the registry for LUID %ld %ld \n", pWin32Ctx->registry_driver_name, adapter_luid.LowPart, adapter_luid.HighPart);
} else {
fprintf(stderr, "VA_Win32: Couldn't find a driver in the registry for LUID %ld %ld. Using default driver: %s \n", pWin32Ctx->adapter_luid.LowPart, pWin32Ctx->adapter_luid.HighPart, VAAPI_DEFAULT_DRIVER_NAME);
fprintf(stderr, "VA_Win32: Couldn't find a driver in the registry for LUID %ld %ld. Using default driver: %s \n", adapter_luid.LowPart, adapter_luid.HighPart, VAAPI_DEFAULT_DRIVER_NAME);
}
#endif // _DEBUG
}
Expand Down
8 changes: 3 additions & 5 deletions va/x11/va_dri2.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,9 @@ VAStatus va_DRI2_GetDriverNames(
if (strcmp(map[i].dri_driver, dri_driver) == 0) {
const char * const *va_drivers = map[i].va_driver;

while (va_drivers[count]) {
if (count < MAX_NAMES && count < *num_drivers)
drivers[count] = strdup(va_drivers[count]);
count++;
}
for (; count < MAX_NAMES && va_drivers[count] && count < *num_drivers; count++)
drivers[count] = strdup(va_drivers[count]);

break;
}
}
Expand Down