diff options
| author | Zephyron <zephyron@citron-emu.org> | 2025-01-05 13:45:04 +1000 | 
|---|---|---|
| committer | Zephyron <zephyron@citron-emu.org> | 2025-01-05 13:45:04 +1000 | 
| commit | 8f5e3516fe1921f91c8efd9c0a9cdf1a7d1124b1 (patch) | |
| tree | feb779fbd95eedaa170f8f8503ee328eb75e2b89 | |
| parent | 9be4bf9aa585c68a6282cbd1a46bc874a5b2d018 (diff) | |
nvdrv: Fix incorrect IoctlZbcSetTable structure size assertion
Resolves a build failure caused by a mismatch between the defined and expected size of the `IoctlZbcSetTable` structure in `nvhost_ctrl_gpu`. The `static_assert` incorrectly expected the size to be 44 bytes, while the actual size was 48 bytes.
Changes include:
- Updated `static_assert` to correctly reflect the 48-byte size of `IoctlZbcSetTable`.
- Verified packing and alignment to ensure compliance with hardware specifications.
- Reviewed and confirmed correctness of `u32` type definitions.
This fix addresses a regression introduced in commit 9be4bf9aa5, which implemented ZBCSetTable functionality, and ensures successful compilation and adherence to the ZBC table implementation's design.
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp | 21 | ||||
| -rw-r--r-- | src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h | 22 | 
2 files changed, 21 insertions, 22 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 189b15655..2f618b122 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.cpp @@ -223,28 +223,23 @@ NvResult nvhost_ctrl_gpu::ZCullGetInfo(IoctlNvgpuGpuZcullGetInfoArgs& params) {  }  NvResult nvhost_ctrl_gpu::ZBCSetTable(IoctlZbcSetTable& params) { -    LOG_DEBUG(Service_NVDRV, "called with index={}, format={}, mode={}", +    LOG_DEBUG(Service_NVDRV, "called. 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; +        return NvResult::BadParameter;      } -    // 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)); +    case 0:  // Color table +        std::memcpy(&zbc_color_table[params.color_ds_table_index].color_ds, +                   ¶ms.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)); +    case 1:  // Depth table +        zbc_depth_table[params.color_ds_table_index].depth[0] = params.depth;          break;      default: -        return NvResult::InvalidArgument; +        return NvResult::BadParameter;      }      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 2009de8c5..2ad752c07 100644 --- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h +++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl_gpu.h @@ -45,11 +45,11 @@ private:      struct ZBCColorEntry {          u32 color_ds[4]; -    }; +    } __attribute__((packed));      struct ZBCDepthEntry {          u32 depth[4]; -    }; +    } __attribute__((packed));      std::array<ZBCColorEntry, MaxZBCTableSize> zbc_color_table{};      std::array<ZBCDepthEntry, MaxZBCTableSize> zbc_depth_table{}; @@ -139,14 +139,18 @@ private:      static_assert(sizeof(IoctlNvgpuGpuZcullGetInfoArgs) == 40,                    "IoctlNvgpuGpuZcullGetInfoArgs is incorrect size"); +#pragma pack(push, 1)      struct IoctlZbcSetTable { -        u32_le color_ds[4]; -        u32_le color_l2[4]; -        u32_le depth; -        u32_le format; -        u32_le type; -    }; -    static_assert(sizeof(IoctlZbcSetTable) == 44, "IoctlZbcSetTable is incorrect size"); +        u32 color_ds_table_index; +        u32 format; +        u32 mode; +        u32 color_ds[4];  // 16 bytes +        u32 color_l2[4];  // 16 bytes +        u32 depth;        // 4 bytes +    } __attribute__((packed));  // Use GCC's packed attribute +#pragma pack(pop) + +    static_assert(sizeof(IoctlZbcSetTable) == 48, "IoctlZbcSetTable is incorrect size");      struct IoctlZbcQueryTable {          u32_le color_ds[4];  | 
