From 46ddbea71c6be735e9a1117432d1201bf3416daa Mon Sep 17 00:00:00 2001 From: SDK-Chan Date: Thu, 24 Jul 2025 16:34:18 +0200 Subject: [PATCH] [nvdrv] Unstub Allocate Object Context (#104) Adds proper checking to allocate object context, and saves each context separately, based on old stubs from Yuzu's, implemented now to resolve services and better handling of future issues. Co-authored-by: Shinmegumi Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/104 Co-authored-by: SDK-Chan Co-committed-by: SDK-Chan --- .../hle/service/nvdrv/devices/nvhost_gpu.cpp | 27 ++++++++++++++++--- .../hle/service/nvdrv/devices/nvhost_gpu.h | 6 ++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp index efc9cca1cc..63725e4055 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -192,11 +195,27 @@ NvResult nvhost_gpu::AllocGPFIFOEx2(IoctlAllocGpfifoEx2& params, DeviceFD fd) { } NvResult nvhost_gpu::AllocateObjectContext(IoctlAllocObjCtx& params) { - LOG_WARNING(Service_NVDRV, "(STUBBED) called, class_num={:X}, flags={:X}", params.class_num, - params.flags); + LOG_DEBUG(Service_NVDRV, "called, class_num={:X}, flags={:X}, obj_id={:X}", params.class_num, + params.flags, params.obj_id); - params.obj_id = 0x0; - return NvResult::Success; + if (!channel_state->initialized) { + LOG_CRITICAL(Service_NVDRV, "No address space bound to allocate a object context!"); + return NvResult::NotInitialized; + } + + switch (static_cast(params.class_num)) { + case CtxClasses::Ctx2D: + case CtxClasses::Ctx3D: + case CtxClasses::CtxCompute: + case CtxClasses::CtxKepler: + case CtxClasses::CtxDMA: + case CtxClasses::CtxChannelGPFIFO: + ctxObj_params.push_back(params); + return NvResult::Success; + default: + LOG_ERROR(Service_NVDRV, "Invalid class number for object context: {:X}", params.class_num); + return NvResult::BadParameter; + } } static boost::container::small_vector BuildWaitCommandList( diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h index e0aeef9536..040de78734 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.h @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -54,7 +57,7 @@ public: private: friend class nvhost_as_gpu; - enum class CtxObjects : u32_le { + enum class CtxClasses : u32_le { Ctx2D = 0x902D, Ctx3D = 0xB197, CtxCompute = 0xB1C0, @@ -183,6 +186,7 @@ private: s32_le nvmap_fd{}; u64_le user_data{}; IoctlZCullBind zcull_params{}; + std::vector ctxObj_params{}; u32_le channel_priority{}; u32_le channel_timeslice{};