nvdrv: Add MSVC compatibility for packed structs

Add conditional compilation directives to handle packed struct definitions
differently between MSVC and other compilers. MSVC uses #pragma pack
while GCC/Clang use __attribute__((packed)). This change affects:

- ZBCColorEntry
- ZBCDepthEntry
- IoctlZbcSetTable

The functionality remains the same, but ensures proper struct packing
across different compiler environments.
This commit is contained in:
Zephyron 2025-01-08 21:16:04 +10:00
parent c65c8ac45e
commit 3f151c5111
No known key found for this signature in database
GPG key ID: 8DA271B6A74353F1

View file

@ -45,11 +45,19 @@ private:
struct ZBCColorEntry {
u32 color_ds[4];
#ifdef _MSC_VER
};
#else
} __attribute__((packed));
#endif
struct ZBCDepthEntry {
u32 depth[4];
#ifdef _MSC_VER
};
#else
} __attribute__((packed));
#endif
std::array<ZBCColorEntry, MaxZBCTableSize> zbc_color_table{};
std::array<ZBCDepthEntry, MaxZBCTableSize> zbc_depth_table{};
@ -139,6 +147,7 @@ private:
static_assert(sizeof(IoctlNvgpuGpuZcullGetInfoArgs) == 40,
"IoctlNvgpuGpuZcullGetInfoArgs is incorrect size");
#ifdef _MSC_VER
#pragma pack(push, 1)
struct IoctlZbcSetTable {
u32 color_ds_table_index;
@ -147,8 +156,18 @@ private:
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)
#else
struct IoctlZbcSetTable {
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));
#endif
static_assert(sizeof(IoctlZbcSetTable) == 48, "IoctlZbcSetTable is incorrect size");