clang-format

This commit is contained in:
Lander Gallastegi 2024-10-15 00:08:33 +02:00
parent 282d6801a4
commit d7ae8970e2
3 changed files with 153 additions and 148 deletions

View File

@ -213,7 +213,7 @@ static constexpr std::array component_offset = {
std::array{0, 4, 8, 12}, // 19 Format4_4_4_4 std::array{0, 4, 8, 12}, // 19 Format4_4_4_4
std::array{0, 24, -1, -1}, // 20 Format8_24 std::array{0, 24, -1, -1}, // 20 Format8_24
std::array{0, 8, -1, -1}, // 21 Format24_8 std::array{0, 8, -1, -1}, // 21 Format24_8
std::array{0, 8, -1, -1}, // 22 FormatX24_8_32 std::array{0, 8, -1, -1}, // 22 FormatX24_8_32
std::array{-1, -1, -1, -1}, // 23 std::array{-1, -1, -1, -1}, // 23
std::array{-1, -1, -1, -1}, // 24 std::array{-1, -1, -1, -1}, // 24
std::array{-1, -1, -1, -1}, // 25 std::array{-1, -1, -1, -1}, // 25

View File

@ -8,7 +8,8 @@
#include <magic_enum.hpp> #include <magic_enum.hpp>
#define INVALID_NUMBER_FORMAT_COMBO LOG_ERROR(Render_Vulkan, "Unsupported number type {} for format {}", number_type, format); #define INVALID_NUMBER_FORMAT_COMBO \
LOG_ERROR(Render_Vulkan, "Unsupported number type {} for format {}", number_type, format);
namespace Vulkan::LiverpoolToVK { namespace Vulkan::LiverpoolToVK {
@ -738,10 +739,12 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
const auto num_bits = AmdGpu::NumBits(color_buffer.info.format); const auto num_bits = AmdGpu::NumBits(color_buffer.info.format);
auto num_components = AmdGpu::NumComponents(format); auto num_components = AmdGpu::NumComponents(format);
const bool comp_swap_alt = comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::Alternate || const bool comp_swap_alt =
comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::AlternateReverse; comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::Alternate ||
const bool comp_swap_reverse = comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::StandardReverse || comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::AlternateReverse;
comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::AlternateReverse; const bool comp_swap_reverse =
comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::StandardReverse ||
comp_swap == AmdGpu::Liverpool::ColorBuffer::SwapMode::AlternateReverse;
vk::ClearColorValue color{}; vk::ClearColorValue color{};
@ -752,7 +755,7 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
case AmdGpu::NumberFormat::Srgb: // Should we handle gamma correction here? case AmdGpu::NumberFormat::Srgb: // Should we handle gamma correction here?
color.float32[0] = NumberUtils::U8ToUnorm(c0 & 0xff); color.float32[0] = NumberUtils::U8ToUnorm(c0 & 0xff);
break; break;
break; break;
case AmdGpu::NumberFormat::Snorm: case AmdGpu::NumberFormat::Snorm:
color.float32[0] = NumberUtils::S8ToSnorm(c0 & 0xff); color.float32[0] = NumberUtils::S8ToSnorm(c0 & 0xff);
break; break;
@ -789,16 +792,16 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
switch (number_type) { switch (number_type) {
case AmdGpu::NumberFormat::Unorm: case AmdGpu::NumberFormat::Unorm:
case AmdGpu::NumberFormat::Srgb: // Should we handle gamma correction here? case AmdGpu::NumberFormat::Srgb: // Should we handle gamma correction here?
color.float32[0] = NumberUtils::U8ToUnorm( c0 & 0xff); color.float32[0] = NumberUtils::U8ToUnorm(c0 & 0xff);
color.float32[1] = NumberUtils::U8ToUnorm((c0 >> 8) & 0xff); color.float32[1] = NumberUtils::U8ToUnorm((c0 >> 8) & 0xff);
break; break;
case AmdGpu::NumberFormat::Snorm: case AmdGpu::NumberFormat::Snorm:
color.float32[0] = NumberUtils::S8ToSnorm( c0 & 0xff); color.float32[0] = NumberUtils::S8ToSnorm(c0 & 0xff);
color.float32[1] = NumberUtils::S8ToSnorm((c0 >> 8) & 0xff); color.float32[1] = NumberUtils::S8ToSnorm((c0 >> 8) & 0xff);
break; break;
case AmdGpu::NumberFormat::Uint: case AmdGpu::NumberFormat::Uint:
case AmdGpu::NumberFormat::Sint: case AmdGpu::NumberFormat::Sint:
color.uint32[0] = c0 & 0xff; color.uint32[0] = c0 & 0xff;
color.uint32[1] = (c0 >> 8) & 0xff; color.uint32[1] = (c0 >> 8) & 0xff;
break; break;
default: default:
@ -823,20 +826,20 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
case AmdGpu::DataFormat::Format16_16: case AmdGpu::DataFormat::Format16_16:
switch (number_type) { switch (number_type) {
case AmdGpu::NumberFormat::Unorm: case AmdGpu::NumberFormat::Unorm:
color.float32[0] = NumberUtils::U16ToUnorm( c0 & 0xffff); color.float32[0] = NumberUtils::U16ToUnorm(c0 & 0xffff);
color.float32[1] = NumberUtils::U16ToUnorm((c0 >> 16) & 0xffff); color.float32[1] = NumberUtils::U16ToUnorm((c0 >> 16) & 0xffff);
break; break;
case AmdGpu::NumberFormat::Snorm: case AmdGpu::NumberFormat::Snorm:
color.float32[0] = NumberUtils::S16ToSnorm( c0 & 0xffff); color.float32[0] = NumberUtils::S16ToSnorm(c0 & 0xffff);
color.float32[1] = NumberUtils::S16ToSnorm((c0 >> 16) & 0xffff); color.float32[1] = NumberUtils::S16ToSnorm((c0 >> 16) & 0xffff);
break; break;
case AmdGpu::NumberFormat::Uint: case AmdGpu::NumberFormat::Uint:
case AmdGpu::NumberFormat::Sint: case AmdGpu::NumberFormat::Sint:
color.uint32[0] = c0 & 0xffff; color.uint32[0] = c0 & 0xffff;
color.uint32[1] = (c0 >> 16) & 0xffff; color.uint32[1] = (c0 >> 16) & 0xffff;
break; break;
case AmdGpu::NumberFormat::Float: case AmdGpu::NumberFormat::Float:
color.float32[0] = NumberUtils::Uf16ToF32( c0 & 0xffff); color.float32[0] = NumberUtils::Uf16ToF32(c0 & 0xffff);
color.float32[1] = NumberUtils::Uf16ToF32((c0 >> 16) & 0xffff); color.float32[1] = NumberUtils::Uf16ToF32((c0 >> 16) & 0xffff);
break; break;
default: default:
@ -845,47 +848,50 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
} }
break; break;
case AmdGpu::DataFormat::Format10_11_11: case AmdGpu::DataFormat::Format10_11_11:
color.float32[0] = NumberUtils::Uf11ToF32( c0 & 0x7ff); color.float32[0] = NumberUtils::Uf11ToF32(c0 & 0x7ff);
color.float32[1] = NumberUtils::Uf11ToF32((c0 >> 11) & 0x7ff); color.float32[1] = NumberUtils::Uf11ToF32((c0 >> 11) & 0x7ff);
color.float32[2] = NumberUtils::Uf10ToF32((c0 >> 22) & 0x3ff); color.float32[2] = NumberUtils::Uf10ToF32((c0 >> 22) & 0x3ff);
break; break;
case AmdGpu::DataFormat::Format11_11_10: case AmdGpu::DataFormat::Format11_11_10:
color.float32[0] = NumberUtils::Uf10ToF32( c0 & 0x3ff); color.float32[0] = NumberUtils::Uf10ToF32(c0 & 0x3ff);
color.float32[1] = NumberUtils::Uf11ToF32((c0 >> 10) & 0x7ff); color.float32[1] = NumberUtils::Uf11ToF32((c0 >> 10) & 0x7ff);
color.float32[2] = NumberUtils::Uf11ToF32((c0 >> 21) & 0x7ff); color.float32[2] = NumberUtils::Uf11ToF32((c0 >> 21) & 0x7ff);
break; break;
case AmdGpu::DataFormat::Format5_9_9_9: { case AmdGpu::DataFormat::Format5_9_9_9: {
int exponent; int exponent;
union { float f; u32 u; } scale; union {
float f;
u32 u;
} scale;
exponent = (c0 >> 27) - 10; exponent = (c0 >> 27) - 10;
scale.u = (exponent + 127) << 23; scale.u = (exponent + 127) << 23;
color.float32[0] = ( c0 & 0x1ff) * scale.f; color.float32[0] = (c0 & 0x1ff) * scale.f;
color.float32[1] = ((c0 >> 9) & 0x1ff) * scale.f; color.float32[1] = ((c0 >> 9) & 0x1ff) * scale.f;
color.float32[2] = ((c0 >> 18) & 0x1ff) * scale.f; color.float32[2] = ((c0 >> 18) & 0x1ff) * scale.f;
break; break;
} }
case AmdGpu::DataFormat::Format10_10_10_2: case AmdGpu::DataFormat::Format10_10_10_2:
switch (number_type) { switch (number_type) {
case AmdGpu::NumberFormat::Unorm: case AmdGpu::NumberFormat::Unorm:
color.float32[0] = NumberUtils::U2ToUnorm( c0 & 0x3); color.float32[0] = NumberUtils::U2ToUnorm(c0 & 0x3);
color.float32[1] = NumberUtils::U10ToUnorm((c0 >> 2) & 0x3ff); color.float32[1] = NumberUtils::U10ToUnorm((c0 >> 2) & 0x3ff);
color.float32[2] = NumberUtils::U10ToUnorm((c0 >> 12) & 0x3ff); color.float32[2] = NumberUtils::U10ToUnorm((c0 >> 12) & 0x3ff);
color.float32[3] = NumberUtils::U10ToUnorm( c0 >> 22); color.float32[3] = NumberUtils::U10ToUnorm(c0 >> 22);
break; break;
case AmdGpu::NumberFormat::Snorm: case AmdGpu::NumberFormat::Snorm:
color.float32[0] = NumberUtils::S2ToSnorm( c0 & 0x3); color.float32[0] = NumberUtils::S2ToSnorm(c0 & 0x3);
color.float32[1] = NumberUtils::S10ToSnorm((c0 >> 2) & 0x3ff); color.float32[1] = NumberUtils::S10ToSnorm((c0 >> 2) & 0x3ff);
color.float32[2] = NumberUtils::S10ToSnorm((c0 >> 12) & 0x3ff); color.float32[2] = NumberUtils::S10ToSnorm((c0 >> 12) & 0x3ff);
color.float32[3] = NumberUtils::S2ToSnorm( c0 >> 22); color.float32[3] = NumberUtils::S2ToSnorm(c0 >> 22);
break; break;
case AmdGpu::NumberFormat::Uint: case AmdGpu::NumberFormat::Uint:
case AmdGpu::NumberFormat::Sint: case AmdGpu::NumberFormat::Sint:
color.uint32[0] = c0 & 0x3; color.uint32[0] = c0 & 0x3;
color.uint32[1] = (c0 >> 2) & 0x3ff; color.uint32[1] = (c0 >> 2) & 0x3ff;
color.uint32[2] = (c0 >> 12) & 0x3ff; color.uint32[2] = (c0 >> 12) & 0x3ff;
color.uint32[3] = c0 >> 22; color.uint32[3] = c0 >> 22;
break; break;
default: default:
INVALID_NUMBER_FORMAT_COMBO; INVALID_NUMBER_FORMAT_COMBO;
@ -895,23 +901,23 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
case AmdGpu::DataFormat::Format2_10_10_10: case AmdGpu::DataFormat::Format2_10_10_10:
switch (number_type) { switch (number_type) {
case AmdGpu::NumberFormat::Unorm: case AmdGpu::NumberFormat::Unorm:
color.float32[0] = NumberUtils::U10ToUnorm( c0 & 0x3ff); color.float32[0] = NumberUtils::U10ToUnorm(c0 & 0x3ff);
color.float32[1] = NumberUtils::U10ToUnorm((c0 >> 10) & 0x3ff); color.float32[1] = NumberUtils::U10ToUnorm((c0 >> 10) & 0x3ff);
color.float32[2] = NumberUtils::U10ToUnorm((c0 >> 20) & 0x3ff); color.float32[2] = NumberUtils::U10ToUnorm((c0 >> 20) & 0x3ff);
color.float32[3] = NumberUtils::U2ToUnorm( c0 >> 30); color.float32[3] = NumberUtils::U2ToUnorm(c0 >> 30);
break; break;
case AmdGpu::NumberFormat::Snorm: case AmdGpu::NumberFormat::Snorm:
color.float32[0] = NumberUtils::S10ToSnorm( c0 & 0x3ff); color.float32[0] = NumberUtils::S10ToSnorm(c0 & 0x3ff);
color.float32[1] = NumberUtils::S10ToSnorm((c0 >> 10) & 0x3ff); color.float32[1] = NumberUtils::S10ToSnorm((c0 >> 10) & 0x3ff);
color.float32[2] = NumberUtils::S10ToSnorm((c0 >> 20) & 0x3ff); color.float32[2] = NumberUtils::S10ToSnorm((c0 >> 20) & 0x3ff);
color.float32[3] = NumberUtils::S2ToSnorm( c0 >> 30); color.float32[3] = NumberUtils::S2ToSnorm(c0 >> 30);
break; break;
case AmdGpu::NumberFormat::Uint: case AmdGpu::NumberFormat::Uint:
case AmdGpu::NumberFormat::Sint: case AmdGpu::NumberFormat::Sint:
color.uint32[0] = c0 & 0x3ff; color.uint32[0] = c0 & 0x3ff;
color.uint32[1] = (c0 >> 10) & 0x3ff; color.uint32[1] = (c0 >> 10) & 0x3ff;
color.uint32[2] = (c0 >> 20) & 0x3ff; color.uint32[2] = (c0 >> 20) & 0x3ff;
color.uint32[3] = c0 >> 30; color.uint32[3] = c0 >> 30;
break; break;
default: default:
INVALID_NUMBER_FORMAT_COMBO; INVALID_NUMBER_FORMAT_COMBO;
@ -922,23 +928,23 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
switch (number_type) { switch (number_type) {
case AmdGpu::NumberFormat::Unorm: case AmdGpu::NumberFormat::Unorm:
case AmdGpu::NumberFormat::Srgb: // Should we handle gamma correction here? case AmdGpu::NumberFormat::Srgb: // Should we handle gamma correction here?
color.float32[0] = NumberUtils::U8ToUnorm( c0 & 0xff); color.float32[0] = NumberUtils::U8ToUnorm(c0 & 0xff);
color.float32[1] = NumberUtils::U8ToUnorm((c0 >> 8) & 0xff); color.float32[1] = NumberUtils::U8ToUnorm((c0 >> 8) & 0xff);
color.float32[2] = NumberUtils::U8ToUnorm((c0 >> 16) & 0xff); color.float32[2] = NumberUtils::U8ToUnorm((c0 >> 16) & 0xff);
color.float32[3] = NumberUtils::U8ToUnorm( c0 >> 24); color.float32[3] = NumberUtils::U8ToUnorm(c0 >> 24);
break; break;
case AmdGpu::NumberFormat::Snorm: case AmdGpu::NumberFormat::Snorm:
color.float32[0] = NumberUtils::S8ToSnorm( c0 & 0xff); color.float32[0] = NumberUtils::S8ToSnorm(c0 & 0xff);
color.float32[1] = NumberUtils::S8ToSnorm((c0 >> 8) & 0xff); color.float32[1] = NumberUtils::S8ToSnorm((c0 >> 8) & 0xff);
color.float32[2] = NumberUtils::S8ToSnorm((c0 >> 16) & 0xff); color.float32[2] = NumberUtils::S8ToSnorm((c0 >> 16) & 0xff);
color.float32[3] = NumberUtils::S8ToSnorm( c0 >> 24); color.float32[3] = NumberUtils::S8ToSnorm(c0 >> 24);
break; break;
case AmdGpu::NumberFormat::Uint: case AmdGpu::NumberFormat::Uint:
case AmdGpu::NumberFormat::Sint: case AmdGpu::NumberFormat::Sint:
color.uint32[0] = c0 & 0xff; color.uint32[0] = c0 & 0xff;
color.uint32[1] = (c0 >> 8) & 0xff; color.uint32[1] = (c0 >> 8) & 0xff;
color.uint32[2] = (c0 >> 16) & 0xff; color.uint32[2] = (c0 >> 16) & 0xff;
color.uint32[3] = c0 >> 24; color.uint32[3] = c0 >> 24;
break; break;
default: default:
INVALID_NUMBER_FORMAT_COMBO; INVALID_NUMBER_FORMAT_COMBO;
@ -964,28 +970,28 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
case AmdGpu::DataFormat::Format16_16_16_16: case AmdGpu::DataFormat::Format16_16_16_16:
switch (number_type) { switch (number_type) {
case AmdGpu::NumberFormat::Unorm: case AmdGpu::NumberFormat::Unorm:
color.float32[0] = NumberUtils::U16ToUnorm( c0 & 0xffff); color.float32[0] = NumberUtils::U16ToUnorm(c0 & 0xffff);
color.float32[1] = NumberUtils::U16ToUnorm((c0 >> 16) & 0xffff); color.float32[1] = NumberUtils::U16ToUnorm((c0 >> 16) & 0xffff);
color.float32[2] = NumberUtils::U16ToUnorm( c1 & 0xffff); color.float32[2] = NumberUtils::U16ToUnorm(c1 & 0xffff);
color.float32[3] = NumberUtils::U16ToUnorm((c1 >> 16) & 0xffff); color.float32[3] = NumberUtils::U16ToUnorm((c1 >> 16) & 0xffff);
break; break;
case AmdGpu::NumberFormat::Snorm: case AmdGpu::NumberFormat::Snorm:
color.float32[0] = NumberUtils::S16ToSnorm( c0 & 0xffff); color.float32[0] = NumberUtils::S16ToSnorm(c0 & 0xffff);
color.float32[1] = NumberUtils::S16ToSnorm((c0 >> 16) & 0xffff); color.float32[1] = NumberUtils::S16ToSnorm((c0 >> 16) & 0xffff);
color.float32[2] = NumberUtils::S16ToSnorm( c1 & 0xffff); color.float32[2] = NumberUtils::S16ToSnorm(c1 & 0xffff);
color.float32[3] = NumberUtils::S16ToSnorm((c1 >> 16) & 0xffff); color.float32[3] = NumberUtils::S16ToSnorm((c1 >> 16) & 0xffff);
break; break;
case AmdGpu::NumberFormat::Uint: case AmdGpu::NumberFormat::Uint:
case AmdGpu::NumberFormat::Sint: case AmdGpu::NumberFormat::Sint:
color.uint32[0] = c0 & 0xffff; color.uint32[0] = c0 & 0xffff;
color.uint32[1] = (c0 >> 16) & 0xffff; color.uint32[1] = (c0 >> 16) & 0xffff;
color.uint32[2] = c1 & 0xffff; color.uint32[2] = c1 & 0xffff;
color.uint32[3] = (c1 >> 16) & 0xffff; color.uint32[3] = (c1 >> 16) & 0xffff;
break; break;
case AmdGpu::NumberFormat::Float: case AmdGpu::NumberFormat::Float:
color.float32[0] = NumberUtils::Uf16ToF32( c0 & 0xffff); color.float32[0] = NumberUtils::Uf16ToF32(c0 & 0xffff);
color.float32[1] = NumberUtils::Uf16ToF32((c0 >> 16) & 0xffff); color.float32[1] = NumberUtils::Uf16ToF32((c0 >> 16) & 0xffff);
color.float32[2] = NumberUtils::Uf16ToF32( c1 & 0xffff); color.float32[2] = NumberUtils::Uf16ToF32(c1 & 0xffff);
color.float32[3] = NumberUtils::Uf16ToF32((c1 >> 16) & 0xffff); color.float32[3] = NumberUtils::Uf16ToF32((c1 >> 16) & 0xffff);
break; break;
default: default:
@ -1014,27 +1020,27 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
} }
break; break;
case AmdGpu::DataFormat::Format5_6_5: case AmdGpu::DataFormat::Format5_6_5:
color.float32[0] = NumberUtils::U5ToUnorm( c0 & 0x1f); color.float32[0] = NumberUtils::U5ToUnorm(c0 & 0x1f);
color.float32[1] = NumberUtils::U6ToUnorm((c0 >> 5) & 0x3f); color.float32[1] = NumberUtils::U6ToUnorm((c0 >> 5) & 0x3f);
color.float32[2] = NumberUtils::U5ToUnorm( c0 >> 11); color.float32[2] = NumberUtils::U5ToUnorm(c0 >> 11);
break; break;
case AmdGpu::DataFormat::Format1_5_5_5: case AmdGpu::DataFormat::Format1_5_5_5:
color.float32[0] = NumberUtils::U5ToUnorm( c0 & 0x1f); color.float32[0] = NumberUtils::U5ToUnorm(c0 & 0x1f);
color.float32[1] = NumberUtils::U5ToUnorm((c0 >> 5) & 0x1f); color.float32[1] = NumberUtils::U5ToUnorm((c0 >> 5) & 0x1f);
color.float32[2] = NumberUtils::U5ToUnorm((c0 >> 10) & 0x1f); color.float32[2] = NumberUtils::U5ToUnorm((c0 >> 10) & 0x1f);
color.float32[3] = (c0 >> 15) ? 1.0f : 0.0f; color.float32[3] = (c0 >> 15) ? 1.0f : 0.0f;
break; break;
case AmdGpu::DataFormat::Format5_5_5_1: case AmdGpu::DataFormat::Format5_5_5_1:
color.float32[0] = (c0 & 0x1) ? 1.0f : 0.0f; color.float32[0] = (c0 & 0x1) ? 1.0f : 0.0f;
color.float32[1] = NumberUtils::U5ToUnorm((c0 >> 1) & 0x1f); color.float32[1] = NumberUtils::U5ToUnorm((c0 >> 1) & 0x1f);
color.float32[2] = NumberUtils::U5ToUnorm((c0 >> 6) & 0x1f); color.float32[2] = NumberUtils::U5ToUnorm((c0 >> 6) & 0x1f);
color.float32[3] = NumberUtils::U5ToUnorm((c0 >> 11) & 0x1f); color.float32[3] = NumberUtils::U5ToUnorm((c0 >> 11) & 0x1f);
break; break;
case AmdGpu::DataFormat::Format4_4_4_4: case AmdGpu::DataFormat::Format4_4_4_4:
color.float32[0] = NumberUtils::U4ToUnorm( c0 & 0xf); color.float32[0] = NumberUtils::U4ToUnorm(c0 & 0xf);
color.float32[1] = NumberUtils::U4ToUnorm((c0 >> 4) & 0xf); color.float32[1] = NumberUtils::U4ToUnorm((c0 >> 4) & 0xf);
color.float32[2] = NumberUtils::U4ToUnorm((c0 >> 8) & 0xf); color.float32[2] = NumberUtils::U4ToUnorm((c0 >> 8) & 0xf);
color.float32[3] = NumberUtils::U4ToUnorm( c0 >> 12); color.float32[3] = NumberUtils::U4ToUnorm(c0 >> 12);
break; break;
default: default:
LOG_ERROR(Render_Vulkan, "Unsupported color buffer format: {}", format); LOG_ERROR(Render_Vulkan, "Unsupported color buffer format: {}", format);

View File

@ -8,155 +8,154 @@
#include "video_core/amdgpu/types.h" #include "video_core/amdgpu/types.h"
#include "video_core/renderer_vulkan/number_utils.h" #include "video_core/renderer_vulkan/number_utils.h"
#define UF11_EXPONENT_SHIFT 6 #define UF11_EXPONENT_SHIFT 6
#define UF10_EXPONENT_SHIFT 5 #define UF10_EXPONENT_SHIFT 5
#define RGB9E5_MANTISSA_BITS 9 #define RGB9E5_MANTISSA_BITS 9
#define RGB9E5_EXP_BIAS 1 #define RGB9E5_EXP_BIAS 1
#define F32_INFINITY 0x7f800000 #define F32_INFINITY 0x7f800000
namespace Vulkan::NumberUtils { namespace Vulkan::NumberUtils {
float Uf11ToF32(u16 val) { float Uf11ToF32(u16 val) {
union { union {
float f; float f;
u32 ui; u32 ui;
} f32; } f32;
int exponent = (val & 0x07c0) >> UF11_EXPONENT_SHIFT; int exponent = (val & 0x07c0) >> UF11_EXPONENT_SHIFT;
int mantissa = (val & 0x003f); int mantissa = (val & 0x003f);
f32.f = 0.0; f32.f = 0.0;
if (exponent == 0) { if (exponent == 0) {
if (mantissa != 0) { if (mantissa != 0) {
const float scale = 1.0 / (1 << 20); const float scale = 1.0 / (1 << 20);
f32.f = scale * mantissa; f32.f = scale * mantissa;
} }
} else if (exponent == 31) { } else if (exponent == 31) {
f32.ui = F32_INFINITY | mantissa; f32.ui = F32_INFINITY | mantissa;
} else { } else {
float scale, decimal; float scale, decimal;
exponent -= 15; exponent -= 15;
if (exponent < 0) { if (exponent < 0) {
scale = 1.0f / (1 << -exponent); scale = 1.0f / (1 << -exponent);
} else { } else {
scale = (float) (1 << exponent); scale = (float)(1 << exponent);
} }
decimal = 1.0f + (float) mantissa / 64; decimal = 1.0f + (float)mantissa / 64;
f32.f = scale * decimal; f32.f = scale * decimal;
} }
return f32.f; return f32.f;
} }
float Uf10ToF32(u16 val) { float Uf10ToF32(u16 val) {
union { union {
float f; float f;
u32 ui; u32 ui;
} f32; } f32;
int exponent = (val & 0x03e0) >> UF10_EXPONENT_SHIFT; int exponent = (val & 0x03e0) >> UF10_EXPONENT_SHIFT;
int mantissa = (val & 0x001f); int mantissa = (val & 0x001f);
f32.f = 0.0; f32.f = 0.0;
if (exponent == 0) { if (exponent == 0) {
if (mantissa != 0) { if (mantissa != 0) {
const float scale = 1.0 / (1 << 19); const float scale = 1.0 / (1 << 19);
f32.f = scale * mantissa; f32.f = scale * mantissa;
} }
} else if (exponent == 31) { } else if (exponent == 31) {
f32.ui = F32_INFINITY | mantissa; f32.ui = F32_INFINITY | mantissa;
} else { } else {
float scale, decimal; float scale, decimal;
exponent -= 15; exponent -= 15;
if (exponent < 0) { if (exponent < 0) {
scale = 1.0f / (1 << -exponent); scale = 1.0f / (1 << -exponent);
} } else {
else { scale = (float)(1 << exponent);
scale = (float) (1 << exponent); }
} decimal = 1.0f + (float)mantissa / 32;
decimal = 1.0f + (float) mantissa / 32; f32.f = scale * decimal;
f32.f = scale * decimal; }
}
return f32.f; return f32.f;
} }
float Uf16ToF32(u16 val) { float Uf16ToF32(u16 val) {
return half_float::half_cast<float>(reinterpret_cast<half_float::half&>(val)); return half_float::half_cast<float>(reinterpret_cast<half_float::half&>(val));
} }
float U2ToUnorm(u8 val) { float U2ToUnorm(u8 val) {
static constexpr auto c = 1.0f / 3.0f; static constexpr auto c = 1.0f / 3.0f;
return float(val * c); return float(val * c);
} }
float S2ToSnorm(s8 val) { float S2ToSnorm(s8 val) {
static constexpr auto c = 1.0f / 1.0f; static constexpr auto c = 1.0f / 1.0f;
return float(val * c); return float(val * c);
} }
float U4ToUnorm(u8 val) { float U4ToUnorm(u8 val) {
static constexpr auto c = 1.0f / 15.0f; static constexpr auto c = 1.0f / 15.0f;
return float(val * c); return float(val * c);
} }
float S4ToSnorm(s8 val) { float S4ToSnorm(s8 val) {
static constexpr auto c = 1.0f / 7.0f; static constexpr auto c = 1.0f / 7.0f;
return float(val * c); return float(val * c);
} }
float U5ToUnorm(u8 val) { float U5ToUnorm(u8 val) {
static constexpr auto c = 1.0f / 31.0f; static constexpr auto c = 1.0f / 31.0f;
return float(val * c); return float(val * c);
} }
float S5ToSnorm(s8 val) { float S5ToSnorm(s8 val) {
static constexpr auto c = 1.0f / 15.0f; static constexpr auto c = 1.0f / 15.0f;
return float(val * c); return float(val * c);
} }
float U6ToUnorm(u8 val) { float U6ToUnorm(u8 val) {
static constexpr auto c = 1.0f / 63.0f; static constexpr auto c = 1.0f / 63.0f;
return float(val * c); return float(val * c);
} }
float S6ToSnorm(s8 val) { float S6ToSnorm(s8 val) {
static constexpr auto c = 1.0f / 31.0f; static constexpr auto c = 1.0f / 31.0f;
return float(val * c); return float(val * c);
} }
float U8ToUnorm(u8 val) { float U8ToUnorm(u8 val) {
static constexpr auto c = 1.0f / 255.0f; static constexpr auto c = 1.0f / 255.0f;
return float(val * c); return float(val * c);
} }
float S8ToSnorm(s8 val) { float S8ToSnorm(s8 val) {
static constexpr auto c = 1.0f / 127.0f; static constexpr auto c = 1.0f / 127.0f;
return float(val * c); return float(val * c);
} }
float U10ToUnorm(u16 val) { float U10ToUnorm(u16 val) {
static constexpr auto c = 1.0f / 1023.0f; static constexpr auto c = 1.0f / 1023.0f;
return float(val * c); return float(val * c);
} }
float S10ToSnorm(s16 val) { float S10ToSnorm(s16 val) {
static constexpr auto c = 1.0f / 511.0f; static constexpr auto c = 1.0f / 511.0f;
return float(val * c); return float(val * c);
} }
float U16ToUnorm(u16 val) { float U16ToUnorm(u16 val) {
static constexpr auto c = 1.0f / 65535.0f; static constexpr auto c = 1.0f / 65535.0f;
return float(val * c); return float(val * c);
} }
float S16ToSnorm(s16 val) { float S16ToSnorm(s16 val) {
static constexpr auto c = 1.0f / 32767.0f; static constexpr auto c = 1.0f / 32767.0f;
return float(val * c); return float(val * c);
} }
} // namespace Vulkan::NumberUtils } // namespace Vulkan::NumberUtils