From 9be4bf9aa585c68a6282cbd1a46bc874a5b2d018 Mon Sep 17 00:00:00 2001 From: Zephyron Date: Sat, 4 Jan 2025 18:57:12 +1000 Subject: [PATCH] nvdrv: Implement ZBCSetTable functionality Implements basic Zero Bandwidth Clear (ZBC) table support in nvhost_ctrl_gpu. This adds storage and validation for both color and depth clear values, replacing the previous stub implementation. ZBC is a hardware optimization technique used by NVIDIA GPUs to efficiently handle buffer clearing operations. Changes include: - Added ZBC table storage structures - Implemented parameter validation - Added separate handling for color and depth modes - Improved debug logging - Added documentation explaining ZBC functionality --- .../service/nvdrv/devices/nvhost_ctrl_gpu.cpp | 26 +++++++++++++++++-- .../service/nvdrv/devices/nvhost_ctrl_gpu.h | 20 ++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp index b7a5c7089..189b15655 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp @@ -223,8 +223,30 @@ NvResult nvhost_ctrl_gpu::ZCullGetInfo(IoctlNvgpuGpuZcullGetInfoArgs& params) { } NvResult nvhost_ctrl_gpu::ZBCSetTable(IoctlZbcSetTable& params) { - LOG_WARNING(Service_NVDRV, "(STUBBED) called"); - // TODO(ogniK): What does this even actually do? + LOG_DEBUG(Service_NVDRV, "called with index={}, format={}, mode={}", + params.color_ds_table_index, params.format, params.mode); + + // Validate parameters + if (params.color_ds_table_index >= MaxZBCTableSize || params.format >= MaxZBCFormats) { + return NvResult::InvalidArgument; + } + + // Store the color/depth values + switch (params.mode) { + case ZBCTableMode::COLOR: + // Store color values + std::memcpy(zbc_color_table[params.color_ds_table_index].color_ds, + params.color_ds, sizeof(params.color_ds)); + break; + case ZBCTableMode::DEPTH: + // Store depth values + std::memcpy(zbc_depth_table[params.color_ds_table_index].depth, + params.depth, sizeof(params.depth)); + break; + default: + return NvResult::InvalidArgument; + } + return NvResult::Success; } diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h index 100b612da..2009de8c5 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include "common/common_funcs.h" #include "common/common_types.h" @@ -34,6 +35,25 @@ public: Kernel::KEvent* QueryEvent(u32 event_id) override; private: + static constexpr std::size_t MaxZBCTableSize = 16; + static constexpr std::size_t MaxZBCFormats = 32; + + enum class ZBCTableMode : u32 { + COLOR = 0, + DEPTH = 1, + }; + + struct ZBCColorEntry { + u32 color_ds[4]; + }; + + struct ZBCDepthEntry { + u32 depth[4]; + }; + + std::array zbc_color_table{}; + std::array zbc_depth_table{}; + struct IoctlGpuCharacteristics { u32_le arch; // 0x120 (NVGPU_GPU_ARCH_GM200) u32_le impl; // 0xB (NVGPU_GPU_IMPL_GM20B)