1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[dxvk] Properly encode KHR_maintenance5 formats

This commit is contained in:
Philip Rebohle 2024-12-09 17:01:40 +01:00 committed by Philip Rebohle
parent 4dd0afe121
commit 32399461da

View File

@ -534,13 +534,15 @@ namespace dxvk {
}
static uint64_t encodeColorFormat(VkFormat format, uint32_t index) {
uint64_t value = uint64_t(format);
uint64_t value = 0u;
if (value >= uint64_t(VK_FORMAT_A4R4G4B4_UNORM_PACK16)) {
value -= uint64_t(VK_FORMAT_A4R4G4B4_UNORM_PACK16);
value += uint64_t(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) + 1;
} else if (value > uint64_t(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32)) {
value = 0;
for (const auto& p : s_colorFormatRanges) {
if (format >= p.first && format <= p.second) {
value += uint32_t(format) - uint32_t(p.first);
break;
}
value += uint32_t(p.second) - uint32_t(p.first) + 1u;
}
return value << (7 * index);
@ -561,14 +563,24 @@ namespace dxvk {
static VkFormat decodeColorFormat(uint64_t value, uint32_t index) {
value = (value >> (7 * index)) & 0x7F;
if (value > uint64_t(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32)) {
value -= uint64_t(VK_FORMAT_E5B9G9R9_UFLOAT_PACK32) + 1ull;
value += uint64_t(VK_FORMAT_A4R4G4B4_UNORM_PACK16);
for (const auto& p : s_colorFormatRanges) {
uint32_t rangeSize = uint32_t(p.second) - uint32_t(p.first) + 1u;
if (value < rangeSize)
return VkFormat(uint32_t(p.first) + uint32_t(value));
value -= rangeSize;
}
return VkFormat(value);
return VK_FORMAT_UNDEFINED;
}
static constexpr std::array<std::pair<VkFormat, VkFormat>, 3> s_colorFormatRanges = {{
{ VK_FORMAT_UNDEFINED, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32 }, /* 0 - 123 */
{ VK_FORMAT_A4R4G4B4_UNORM_PACK16, VK_FORMAT_A4B4G4R4_UNORM_PACK16 }, /* 124 - 125 */
{ VK_FORMAT_A1B5G5R5_UNORM_PACK16_KHR, VK_FORMAT_A8_UNORM_KHR }, /* 126 - 127 */
}};
};