Skip to content

Commit

Permalink
[dxvk] Properly encode KHR_maintenance5 formats
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Dec 9, 2024
1 parent 45da7d6 commit 4ed9894
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/dxvk/dxvk_graphics_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
}};

};


Expand Down

0 comments on commit 4ed9894

Please sign in to comment.