From 7d7a81133444b72c64712ab55ac30a0765f5ac09 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 20 Jul 2023 09:16:25 +0100 Subject: [PATCH 1/6] win32: remove duplicate adapter_luid entry The adapter_luid is already stored in pDriverContext->native_dpy. The copy in VADisplayContextWin32, is not needed. Signed-off-by: Emil Velikov --- va/win32/va_win32.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/va/win32/va_win32.c b/va/win32/va_win32.c index 789933e6b..7a6a895d3 100644 --- a/va/win32/va_win32.c +++ b/va/win32/va_win32.c @@ -38,18 +38,17 @@ const char VAAPI_DEFAULT_DRIVER_NAME[] = "vaon12"; 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, @@ -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 } From 936587b4e21ce988ee28a015c7b74498c72eb7d8 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 20 Jul 2023 09:01:07 +0100 Subject: [PATCH 2/6] va/backend: annotate vafool as deprecated All the vafool codebase was removed a while ago, with little sign of it coming back. Signed-off-by: Emil Velikov --- va/va_backend.h | 1 + 1 file changed, 1 insertion(+) diff --git a/va/va_backend.h b/va/va_backend.h index ea626b0fc..eec0f3e2a 100644 --- a/va/va_backend.h +++ b/va/va_backend.h @@ -670,6 +670,7 @@ struct VADisplayContext { 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; From d80a546aad79001b5753b73f173c652d6a7ebc20 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 20 Jul 2023 08:57:32 +0100 Subject: [PATCH 3/6] va/backend: document the vaGetDriver* APIs Note that the old ones are deprecated. For the new one mention the ownership model and num_drivers meaning/handling. Signed-off-by: Emil Velikov --- va/va_backend.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/va/va_backend.h b/va/va_backend.h index eec0f3e2a..51e80d058 100644 --- a/va/va_backend.h +++ b/va/va_backend.h @@ -663,6 +663,7 @@ struct VADisplayContext { VADisplayContextP ctx ); + /* Deprecated */ VAStatus(*vaGetDriverName)( VADisplayContextP ctx, char **driver_name @@ -677,17 +678,36 @@ struct VADisplayContext { 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, From 26301a81a1ea777d243a9799fb1bd07ff888ef9f Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 20 Jul 2023 09:37:39 +0100 Subject: [PATCH 4/6] x11/dri2: limit the array handling to avoid out of range access Similar to ce9898ce515b593b28daa4a7d06276c982031ffd Signed-off-by: Emil Velikov --- va/x11/va_dri2.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/va/x11/va_dri2.c b/va/x11/va_dri2.c index 109c2e126..da2a9f40b 100644 --- a/va/x11/va_dri2.c +++ b/va/x11/va_dri2.c @@ -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; } } From 2a46d84093a9478751318ee13ebbf0676df61856 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 20 Jul 2023 09:39:32 +0100 Subject: [PATCH 5/6] va: remove unreachable "DRIVER BUG" As documented (and updated) the callee(s) cannot set the num_drivers past the original size. So drop the unreachable code. Signed-off-by: Emil Velikov --- va/va.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/va/va.c b/va/va.c index fc1f51736..4e6a4a9aa 100644 --- a/va/va.c +++ b/va/va.c @@ -687,9 +687,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); From ee49ceba54a58afaff3f8d77ff6e8a7c517b1cb2 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Thu, 20 Jul 2023 09:43:57 +0100 Subject: [PATCH 6/6] va: drop no longer applicable vaGetDriverNames check All the backends implement the callback. So this temporary check can go now. Signed-off-by: Emil Velikov --- va/va.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/va/va.c b/va/va.c index 4e6a4a9aa..920b76c50 100644 --- a/va/va.c +++ b/va/va.c @@ -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.