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

@ -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,9 +739,11 @@ 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::Alternate ||
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 || 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;
vk::ClearColorValue color{}; vk::ClearColorValue color{};
@ -789,11 +792,11 @@ 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:
@ -823,11 +826,11 @@ 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:
@ -836,7 +839,7 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
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,23 +848,26 @@ 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;
@ -869,16 +875,16 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
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:
@ -895,16 +901,16 @@ 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:
@ -922,16 +928,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);
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:
@ -964,15 +970,15 @@ 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:
@ -983,9 +989,9 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
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,12 +1020,12 @@ 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;
@ -1031,10 +1037,10 @@ vk::ClearValue ColorBufferClearValue(const AmdGpu::Liverpool::ColorBuffer& color
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

@ -42,9 +42,9 @@ float Uf11ToF32(u16 val) {
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;
} }
@ -74,11 +74,10 @@ float Uf10ToF32(u16 val) {
exponent -= 15; exponent -= 15;
if (exponent < 0) { if (exponent < 0) {
scale = 1.0f / (1 << -exponent); scale = 1.0f / (1 << -exponent);
} else {
scale = (float)(1 << exponent);
} }
else { decimal = 1.0f + (float)mantissa / 32;
scale = (float) (1 << exponent);
}
decimal = 1.0f + (float) mantissa / 32;
f32.f = scale * decimal; f32.f = scale * decimal;
} }