From fa4dc381ed87a796fab042b6674fa525a6c63379 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 30 Nov 2024 14:31:50 +1000 Subject: [PATCH] GPUDevice: Rename RGBA5551 to RGB5A1 And fix the incorrect format for Vulkan. --- src/core/gpu_sw.cpp | 22 ++++----- src/util/d3d_common.cpp | 2 +- src/util/gpu_texture.cpp | 82 ++++++++++++++++----------------- src/util/gpu_texture.h | 2 +- src/util/image.cpp | 28 +++++------ src/util/image.h | 2 +- src/util/metal_device.mm | 4 +- src/util/opengl_context_egl.cpp | 4 +- src/util/opengl_texture.cpp | 4 +- src/util/vulkan_device.cpp | 2 +- 10 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index c8b12fa87..fd781af63 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -41,10 +41,10 @@ bool GPU_SW::Initialize(Error* error) if (!GPU::Initialize(error) || !m_backend.Initialize(g_settings.gpu_use_thread)) return false; - static constexpr const std::array formats_for_16bit = {GPUTexture::Format::RGB565, GPUTexture::Format::RGBA5551, + static constexpr const std::array formats_for_16bit = {GPUTexture::Format::RGB565, GPUTexture::Format::RGB5A1, GPUTexture::Format::RGBA8, GPUTexture::Format::BGRA8}; static constexpr const std::array formats_for_24bit = {GPUTexture::Format::RGBA8, GPUTexture::Format::BGRA8, - GPUTexture::Format::RGB565, GPUTexture::Format::RGBA5551}; + GPUTexture::Format::RGB565, GPUTexture::Format::RGB5A1}; for (const GPUTexture::Format format : formats_for_16bit) { if (g_gpu_device->SupportsTextureFormat(format)) @@ -115,7 +115,7 @@ template static out_type VRAM16ToOutput(u16 value); template<> -ALWAYS_INLINE u16 VRAM16ToOutput(u16 value) +ALWAYS_INLINE u16 VRAM16ToOutput(u16 value) { return (value & 0x3E0) | ((value >> 10) & 0x1F) | ((value & 0x1F) << 10); } @@ -148,7 +148,7 @@ ALWAYS_INLINE u32 VRAM16ToOutput(u16 value) } template<> -ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u16* dst_ptr, u32 width) +ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u16* dst_ptr, u32 width) { u32 col = 0; @@ -167,7 +167,7 @@ ALWAYS_INLINE void CopyOutRow16(const u16* sr } for (; col < width; col++) - *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++)); + *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++)); } template<> @@ -317,7 +317,7 @@ ALWAYS_INLINE_RELEASE bool GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x src_row_ptr += 3; } } - else if constexpr (display_format == GPUTexture::Format::RGBA5551) + else if constexpr (display_format == GPUTexture::Format::RGB5A1) { const u8* src_row_ptr = src_ptr; u16* dst_row_ptr = reinterpret_cast(dst_ptr); @@ -362,7 +362,7 @@ ALWAYS_INLINE_RELEASE bool GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x { *(dst_row_ptr++) = ((rgb >> 3) & 0x1F) | (((rgb >> 10) << 5) & 0x7E0) | (((rgb >> 19) << 11) & 0x3E0000); } - else if constexpr (display_format == GPUTexture::Format::RGBA5551) + else if constexpr (display_format == GPUTexture::Format::RGB5A1) { *(dst_row_ptr++) = ((rgb >> 3) & 0x1F) | (((rgb >> 11) << 5) & 0x3E0) | (((rgb >> 19) << 10) & 0x1F0000); } @@ -389,8 +389,8 @@ bool GPU_SW::CopyOut(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 height, u3 switch (m_16bit_display_format) { - case GPUTexture::Format::RGBA5551: - return CopyOut15Bit(src_x, src_y, width, height, line_skip); + case GPUTexture::Format::RGB5A1: + return CopyOut15Bit(src_x, src_y, width, height, line_skip); case GPUTexture::Format::RGB565: return CopyOut15Bit(src_x, src_y, width, height, line_skip); @@ -409,8 +409,8 @@ bool GPU_SW::CopyOut(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 height, u3 { switch (m_24bit_display_format) { - case GPUTexture::Format::RGBA5551: - return CopyOut24Bit(src_x, src_y, skip_x, width, height, line_skip); + case GPUTexture::Format::RGB5A1: + return CopyOut24Bit(src_x, src_y, skip_x, width, height, line_skip); case GPUTexture::Format::RGB565: return CopyOut24Bit(src_x, src_y, skip_x, width, height, line_skip); diff --git a/src/util/d3d_common.cpp b/src/util/d3d_common.cpp index e99d8ce46..ce5ac6ea0 100644 --- a/src/util/d3d_common.cpp +++ b/src/util/d3d_common.cpp @@ -629,7 +629,7 @@ static constexpr std::array(GPUTe {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN }, // RGBA8 {DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN }, // BGRA8 {DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN }, // RGB565 - {DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN }, // RGBA5551 + {DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN }, // RGB5A1 {DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN }, // R8 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_D16_UNORM }, // D16 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT }, // D24S8 diff --git a/src/util/gpu_texture.cpp b/src/util/gpu_texture.cpp index c29e5482c..deeaec939 100644 --- a/src/util/gpu_texture.cpp +++ b/src/util/gpu_texture.cpp @@ -30,7 +30,7 @@ const char* GPUTexture::GetFormatName(Format format) "RGBA8", // RGBA8 "BGRA8", // BGRA8 "RGB565", // RGB565 - "RGB5551", // RGBA5551 + "RGB5A1", // RGB5A1 "R8", // R8 "D16", // D16 "D24S8", // D24S8 @@ -147,16 +147,16 @@ void GPUTexture::CopyTextureDataForUpload(u32 width, u32 height, Format format, GPUTexture::Format GPUTexture::GetTextureFormatForImageFormat(ImageFormat format) { static constexpr const std::array mapping = { - Format::Unknown, // None - Format::RGBA8, // RGBA8 - Format::BGRA8, // BGRA8 - Format::RGB565, // RGB565 - Format::RGBA5551, // RGBA5551 - Format::Unknown, // BGR8 - Format::BC1, // BC1 - Format::BC2, // BC2 - Format::BC3, // BC3 - Format::BC7, // BC7 + Format::Unknown, // None + Format::RGBA8, // RGBA8 + Format::BGRA8, // BGRA8 + Format::RGB565, // RGB565 + Format::RGB5A1, // RGB5A1 + Format::Unknown, // BGR8 + Format::BC1, // BC1 + Format::BC2, // BC2 + Format::BC3, // BC3 + Format::BC7, // BC7 }; static_assert(mapping.size() == static_cast(ImageFormat::MaxCount)); @@ -166,35 +166,35 @@ GPUTexture::Format GPUTexture::GetTextureFormatForImageFormat(ImageFormat format ImageFormat GPUTexture::GetImageFormatForTextureFormat(Format format) { static constexpr const std::array mapping = { - ImageFormat::None, // Unknown - ImageFormat::RGBA8, // RGBA8 - ImageFormat::BGRA8, // BGRA8 - ImageFormat::RGB565, // RGB565 - ImageFormat::RGBA5551, // RGBA5551 - ImageFormat::None, // R8 - ImageFormat::None, // D16 - ImageFormat::None, // D24S8 - ImageFormat::None, // D32F - ImageFormat::None, // D32FS8 - ImageFormat::None, // R16 - ImageFormat::None, // R16I - ImageFormat::None, // R16U - ImageFormat::None, // R16F - ImageFormat::None, // R32I - ImageFormat::None, // R32U - ImageFormat::None, // R32F - ImageFormat::None, // RG8 - ImageFormat::None, // RG16 - ImageFormat::None, // RG16F - ImageFormat::None, // RG32F - ImageFormat::None, // RGBA16 - ImageFormat::None, // RGBA16F - ImageFormat::None, // RGBA32F - ImageFormat::None, // RGB10A2 - ImageFormat::BC1, // BC1 - ImageFormat::BC2, // BC2 - ImageFormat::BC3, // BC3 - ImageFormat::BC7, // BC7 + ImageFormat::None, // Unknown + ImageFormat::RGBA8, // RGBA8 + ImageFormat::BGRA8, // BGRA8 + ImageFormat::RGB565, // RGB565 + ImageFormat::RGB5A1, // RGB5A1 + ImageFormat::None, // R8 + ImageFormat::None, // D16 + ImageFormat::None, // D24S8 + ImageFormat::None, // D32F + ImageFormat::None, // D32FS8 + ImageFormat::None, // R16 + ImageFormat::None, // R16I + ImageFormat::None, // R16U + ImageFormat::None, // R16F + ImageFormat::None, // R32I + ImageFormat::None, // R32U + ImageFormat::None, // R32F + ImageFormat::None, // RG8 + ImageFormat::None, // RG16 + ImageFormat::None, // RG16F + ImageFormat::None, // RG32F + ImageFormat::None, // RGBA16 + ImageFormat::None, // RGBA16F + ImageFormat::None, // RGBA32F + ImageFormat::None, // RGB10A2 + ImageFormat::BC1, // BC1 + ImageFormat::BC2, // BC2 + ImageFormat::BC3, // BC3 + ImageFormat::BC7, // BC7 }; static_assert(mapping.size() == static_cast(Format::MaxCount)); @@ -252,7 +252,7 @@ u32 GPUTexture::GetPixelSize(GPUTexture::Format format) 4, // RGBA8 4, // BGRA8 2, // RGB565 - 2, // RGBA5551 + 2, // RGB5A1 1, // R8 2, // D16 4, // D24S8 diff --git a/src/util/gpu_texture.h b/src/util/gpu_texture.h index 386034ba8..dc04d9f59 100644 --- a/src/util/gpu_texture.h +++ b/src/util/gpu_texture.h @@ -40,7 +40,7 @@ public: RGBA8, BGRA8, RGB565, - RGBA5551, + RGB5A1, R8, D16, D24S8, diff --git a/src/util/image.cpp b/src/util/image.cpp index 7d5e91d27..632e243b0 100644 --- a/src/util/image.cpp +++ b/src/util/image.cpp @@ -163,16 +163,16 @@ Image& Image::operator=(Image&& move) const char* Image::GetFormatName(ImageFormat format) { static constexpr std::array names = { - "None", // None - "RGBA8", // RGBA8 - "BGRA8", // BGRA8 - "RGB565", // RGB565 - "RGB5551", // RGBA5551 - "BGR8", // BGR8 - "BC1", // BC1 - "BC2", // BC2 - "BC3", // BC3 - "BC7", // BC7 + "None", // None + "RGBA8", // RGBA8 + "BGRA8", // BGRA8 + "RGB565", // RGB565 + "RGB5A1", // RGB5A1 + "BGR8", // BGR8 + "BC1", // BC1 + "BC2", // BC2 + "BC3", // BC3 + "BC7", // BC7 }; static_assert(names.size() == static_cast(ImageFormat::MaxCount)); @@ -186,7 +186,7 @@ u32 Image::GetPixelSize(ImageFormat format) 4, // RGBA8 4, // BGRA8 2, // RGB565 - 2, // RGBA5551 + 2, // RGB5A1 3, // BGR8 8, // BC1 - 16 pixels in 64 bits 16, // BC2 - 16 pixels in 128 bits @@ -298,7 +298,7 @@ bool Image::SetAllPixelsOpaque() return true; } - else if (m_format == ImageFormat::RGBA5551) + else if (m_format == ImageFormat::RGB5A1) { for (u32 y = 0; y < m_height; y++) { @@ -604,7 +604,7 @@ std::optional Image::ConvertToRGBA8(Error* error) const } break; - case ImageFormat::RGBA5551: + case ImageFormat::RGB5A1: { ret = Image(m_width, m_height, ImageFormat::RGBA8); for (u32 y = 0; y < m_height; y++) @@ -614,7 +614,7 @@ std::optional Image::ConvertToRGBA8(Error* error) const for (u32 x = 0; x < m_width; x++) { - // RGBA5551 -> RGBA8 + // RGB5A1 -> RGBA8 u16 pixel_in; std::memcpy(&pixel_in, pixels_in, sizeof(u16)); pixels_in += sizeof(u16); diff --git a/src/util/image.h b/src/util/image.h index 400ec0b42..c57548e0f 100644 --- a/src/util/image.h +++ b/src/util/image.h @@ -20,7 +20,7 @@ enum class ImageFormat : u8 RGBA8, BGRA8, RGB565, - RGBA5551, + RGB5A1, BGR8, BC1, BC2, diff --git a/src/util/metal_device.mm b/src/util/metal_device.mm index 343469013..26b504230 100644 --- a/src/util/metal_device.mm +++ b/src/util/metal_device.mm @@ -50,7 +50,7 @@ static constexpr std::array(GPUTexture::Format: MTLPixelFormatRGBA8Unorm, // RGBA8 MTLPixelFormatBGRA8Unorm, // BGRA8 MTLPixelFormatB5G6R5Unorm, // RGB565 - MTLPixelFormatA1BGR5Unorm, // RGBA5551 + MTLPixelFormatA1BGR5Unorm, // RGB5A1 MTLPixelFormatR8Unorm, // R8 MTLPixelFormatDepth16Unorm, // D16 MTLPixelFormatDepth24Unorm_Stencil8, // D24S8 @@ -1490,7 +1490,7 @@ std::unique_ptr MetalDevice::CreateSampler(const GPUSampler::Config& bool MetalDevice::SupportsTextureFormat(GPUTexture::Format format) const { - if (format == GPUTexture::Format::RGB565 || format == GPUTexture::Format::RGBA5551) + if (format == GPUTexture::Format::RGB565 || format == GPUTexture::Format::RGB5A1) { // These formats require an Apple Silicon GPU. // See https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf diff --git a/src/util/opengl_context_egl.cpp b/src/util/opengl_context_egl.cpp index 372b4e321..43f6d8ab8 100644 --- a/src/util/opengl_context_egl.cpp +++ b/src/util/opengl_context_egl.cpp @@ -423,7 +423,7 @@ bool OpenGLContextEGL::CheckConfigSurfaceFormat(EGLConfig config, GPUTexture::Fo case GPUTexture::Format::RGB565: return (red_size == 5 && green_size == 6 && blue_size == 5); - case GPUTexture::Format::RGBA5551: + case GPUTexture::Format::RGB5A1: return (red_size == 5 && green_size == 5 && blue_size == 5 && alpha_size == 1); case GPUTexture::Format::Unknown: @@ -461,7 +461,7 @@ void OpenGLContextEGL::UpdateWindowInfoSize(WindowInfo& wi, EGLSurface surface) } else if (red_size == 5 && green_size == 5 && blue_size == 5 && alpha_size == 1) { - wi.surface_format = GPUTexture::Format::RGBA5551; + wi.surface_format = GPUTexture::Format::RGB5A1; } else if (red_size == 8 && green_size == 8 && blue_size == 8 && alpha_size == 8) { diff --git a/src/util/opengl_texture.cpp b/src/util/opengl_texture.cpp index f26b68c39..9aa63f020 100644 --- a/src/util/opengl_texture.cpp +++ b/src/util/opengl_texture.cpp @@ -37,7 +37,7 @@ const std::tuple& OpenGLTexture::GetPixelFormatMapping(G {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // RGBA8 {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, // BGRA8 {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // RGB565 - {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // RGBA5551 + {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // RGB5A1 {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // R8 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_SHORT}, // D16 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT}, // D24S8 @@ -71,7 +71,7 @@ const std::tuple& OpenGLTexture::GetPixelFormatMapping(G {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // RGBA8 {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, // BGRA8 {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // RGB565 - {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // RGBA5551 + {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // RGB5A1 {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // R8 {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_SHORT}, // D16 {GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT}, // D24S8 diff --git a/src/util/vulkan_device.cpp b/src/util/vulkan_device.cpp index b6061b8a6..6f99076cd 100644 --- a/src/util/vulkan_device.cpp +++ b/src/util/vulkan_device.cpp @@ -75,7 +75,7 @@ const std::array(GPUTexture::Format::MaxCount)> Vulka VK_FORMAT_R8G8B8A8_UNORM, // RGBA8 VK_FORMAT_B8G8R8A8_UNORM, // BGRA8 VK_FORMAT_R5G6B5_UNORM_PACK16, // RGB565 - VK_FORMAT_R5G5B5A1_UNORM_PACK16, // RGBA5551 + VK_FORMAT_A1R5G5B5_UNORM_PACK16, // RGB5A1 VK_FORMAT_R8_UNORM, // R8 VK_FORMAT_D16_UNORM, // D16 VK_FORMAT_D24_UNORM_S8_UINT, // D24S8