From a8564a09b7b2aac98a0319d40f8e5bc6984f8f1d Mon Sep 17 00:00:00 2001 From: SDK-Chan Date: Mon, 14 Jul 2025 22:30:07 +0200 Subject: [PATCH 1/2] [host1x] FreeBSD: Fix random crashes due to CUDA/VAAPI check sideeffects (#64) FreeBSD doesn't support NVDEC, CUDA, and partially supports VAAPI (mostly for firefox). Implementing VAAPI for other use cases would be a little bit complicated so, I chose to switch it off for FreeBSD. This PR ensures that FFmpeg will always default to software decoding on FreeBSD, but should remain the same functionalities for other OS's. The results are slight CPU increases while decoding in software mode, but still neglectable and they don't really harm performance. Co-authored-by: MaranBr Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/64 Co-authored-by: SDK-Chan Co-committed-by: SDK-Chan --- src/video_core/host1x/ffmpeg/ffmpeg.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/video_core/host1x/ffmpeg/ffmpeg.cpp b/src/video_core/host1x/ffmpeg/ffmpeg.cpp index 9b718f2591..5321c8c98c 100644 --- a/src/video_core/host1x/ffmpeg/ffmpeg.cpp +++ b/src/video_core/host1x/ffmpeg/ffmpeg.cpp @@ -26,13 +26,14 @@ namespace { constexpr AVPixelFormat PreferredGpuFormat = AV_PIX_FMT_NV12; constexpr AVPixelFormat PreferredCpuFormat = AV_PIX_FMT_YUV420P; constexpr std::array PreferredGpuDecoders = { - AV_HWDEVICE_TYPE_CUDA, #ifdef _WIN32 + AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_D3D11VA, AV_HWDEVICE_TYPE_DXVA2, +#elif defined(__FreeBSD__) + AV_HWDEVICE_TYPE_VDPAU, #elif defined(__unix__) AV_HWDEVICE_TYPE_VAAPI, - AV_HWDEVICE_TYPE_VDPAU, #endif AV_HWDEVICE_TYPE_VULKAN, }; From e9ca3f4c069b4ed4386d7086bc676c83e4334adc Mon Sep 17 00:00:00 2001 From: MaranBr Date: Mon, 14 Jul 2025 22:30:54 +0200 Subject: [PATCH 2/2] [host1x] Fix FFmpeg crash on Linux (#37) This fixes the FFmpeg crash on Linux / Steam Deck. Credit to Maufeat for AVERROR_EOF check. Co-authored-by: MaranBr Co-authored-by: crueter Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/37 Co-authored-by: MaranBr Co-committed-by: MaranBr --- .ci/linux/build.sh | 13 +++++++++---- .ci/windows/build.sh | 6 +++++- src/video_core/host1x/ffmpeg/ffmpeg.cpp | 6 ++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.ci/linux/build.sh b/.ci/linux/build.sh index aa15333ac2..093b30a7ea 100755 --- a/.ci/linux/build.sh +++ b/.ci/linux/build.sh @@ -36,15 +36,16 @@ case "$1" in ARCH=armv9 ARCH_FLAGS="-march=armv9-a -mtune=generic -w" ;; + *) + echo "Invalid target $1 specified, must be one of amd64, steamdeck, allyx, rog-ally, legacy, aarch64, armv9" + exit 1 + ;; esac export ARCH_FLAGS="$ARCH_FLAGS -O3" -NPROC="$2" if [ -z "$NPROC" ]; then NPROC="$(nproc)" -else - shift fi if [ "$1" != "" ]; then shift; fi @@ -72,11 +73,15 @@ else MULTIMEDIA=ON fi +if [ -z "$BUILD_TYPE" ]; then + export BUILD_TYPE="Release" +fi + export EXTRA_CMAKE_FLAGS=("${EXTRA_CMAKE_FLAGS[@]}" $@) mkdir -p build && cd build cmake .. -G Ninja \ - -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ -DENABLE_QT_TRANSLATION=ON \ -DUSE_DISCORD_PRESENCE=ON \ -DCMAKE_CXX_FLAGS="$ARCH_FLAGS" \ diff --git a/.ci/windows/build.sh b/.ci/windows/build.sh index 667fd316fa..d0c697655a 100644 --- a/.ci/windows/build.sh +++ b/.ci/windows/build.sh @@ -17,6 +17,10 @@ else export EXTRA_CMAKE_FLAGS=("${EXTRA_CMAKE_FLAGS[@]}" -DYUZU_USE_BUNDLED_QT=OFF) fi +if [ -z "$BUILD_TYPE" ]; then + export BUILD_TYPE="Release" +fi + if [ "$WINDEPLOYQT" == "" ]; then echo "You must supply the WINDEPLOYQT environment variable." exit 1 @@ -38,7 +42,7 @@ export EXTRA_CMAKE_FLAGS=("${EXTRA_CMAKE_FLAGS[@]}" $@) mkdir -p build && cd build cmake .. -G Ninja \ - -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \ -DENABLE_QT_TRANSLATION=ON \ -DUSE_DISCORD_PRESENCE=ON \ -DYUZU_USE_BUNDLED_SDL2=OFF \ diff --git a/src/video_core/host1x/ffmpeg/ffmpeg.cpp b/src/video_core/host1x/ffmpeg/ffmpeg.cpp index 5321c8c98c..d6eff2bdd7 100644 --- a/src/video_core/host1x/ffmpeg/ffmpeg.cpp +++ b/src/video_core/host1x/ffmpeg/ffmpeg.cpp @@ -216,18 +216,16 @@ bool DecoderContext::OpenContext(const Decoder& decoder) { bool DecoderContext::SendPacket(const Packet& packet) { m_temp_frame = std::make_shared(); - - if (const int ret = avcodec_send_packet(m_codec_context, packet.GetPacket()); ret < 0) { + if (const int ret = avcodec_send_packet(m_codec_context, packet.GetPacket()); ret < 0 && ret != AVERROR_EOF) { LOG_ERROR(HW_GPU, "avcodec_send_packet error: {}", AVError(ret)); return false; } - return true; } std::shared_ptr DecoderContext::ReceiveFrame() { auto ReceiveImpl = [&](AVFrame* frame) -> bool { - if (const int ret = avcodec_receive_frame(m_codec_context, frame); ret < 0) { + if (const int ret = avcodec_receive_frame(m_codec_context, frame); ret < 0 && ret != AVERROR_EOF) { LOG_ERROR(HW_GPU, "avcodec_receive_frame error: {}", AVError(ret)); return false; }