From 1d3de2a1d70ee3738892b51672481a26ba44e83d Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sat, 27 Nov 2021 01:35:58 +0100 Subject: [PATCH] early-access version 2244 --- README.md | 2 +- .../command_classes/codecs/codec.cpp | 43 ++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 110a8ae4d..d5fa567a6 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 2243. +This is the source code for early-access 2244. ## Legal Notice diff --git a/src/video_core/command_classes/codecs/codec.cpp b/src/video_core/command_classes/codecs/codec.cpp index 916277811..02d309170 100755 --- a/src/video_core/command_classes/codecs/codec.cpp +++ b/src/video_core/command_classes/codecs/codec.cpp @@ -2,6 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include #include #include #include "common/assert.h" @@ -59,6 +61,34 @@ Codec::~Codec() { av_buffer_unref(&av_gpu_decoder); } +#ifdef LIBVA_FOUND +// List all the currently loaded Linux modules +static std::vector ListLinuxKernelModules() { + using FILEPtr = std::unique_ptr; + auto module_listing = FILEPtr{fopen("/proc/modules", "rt"), std::fclose}; + std::vector modules{}; + if (!module_listing) { + LOG_WARNING(Service_NVDRV, "Could not open /proc/modules to collect available modules"); + return modules; + } + char* buffer = nullptr; + size_t buf_len = 0; + while (getline(&buffer, &buf_len, module_listing.get()) != -1) { + // format for the module listing file (sysfs) + // + auto line = std::string(buffer); + // we are only interested in module names + auto name_pos = line.find_first_of(" "); + if (name_pos == std::string::npos) { + continue; + } + modules.push_back(line.erase(name_pos)); + } + free(buffer); + return modules; +} +#endif + bool Codec::CreateGpuAvDevice() { #if defined(LIBVA_FOUND) static constexpr std::array VAAPI_DRIVERS = { @@ -67,8 +97,16 @@ bool Codec::CreateGpuAvDevice() { "amdgpu", }; AVDictionary* hwdevice_options = nullptr; + const auto loaded_modules = ListLinuxKernelModules(); av_dict_set(&hwdevice_options, "connection_type", "drm", 0); for (const auto& driver : VAAPI_DRIVERS) { + // first check if the target driver is loaded in the kernel + bool found = std::any_of(loaded_modules.begin(), loaded_modules.end(), + [&driver](const auto& module) { return module == driver; }); + if (!found) { + LOG_DEBUG(Service_NVDRV, "Kernel driver {} is not loaded, trying the next one", driver); + continue; + } av_dict_set(&hwdevice_options, "kernel_driver", driver, 0); const int hwdevice_error = av_hwdevice_ctx_create(&av_gpu_decoder, AV_HWDEVICE_TYPE_VAAPI, nullptr, hwdevice_options, 0); @@ -85,11 +123,12 @@ bool Codec::CreateGpuAvDevice() { #endif static constexpr auto HW_CONFIG_METHOD = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX; static constexpr std::array GPU_DECODER_TYPES{ +#ifdef linux + AV_HWDEVICE_TYPE_VDPAU, +#endif AV_HWDEVICE_TYPE_CUDA, #ifdef _WIN32 AV_HWDEVICE_TYPE_D3D11VA, -#else - AV_HWDEVICE_TYPE_VDPAU, #endif }; for (const auto& type : GPU_DECODER_TYPES) {