Merge pull request #11901 from Filoppi/add_texture_types

Video: add R10B10G10A2 and R16G16B16A16F texture types
This commit is contained in:
Admiral H. Curtiss 2023-06-08 15:28:15 +02:00 committed by GitHub
commit 3dbdf0472d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 54 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#define GL_INT 0x1404 #define GL_INT 0x1404
#define GL_UNSIGNED_INT 0x1405 #define GL_UNSIGNED_INT 0x1405
#define GL_FLOAT 0x1406 #define GL_FLOAT 0x1406
#define GL_HALF_FLOAT 0x140B
#define GL_2_BYTES 0x1407 #define GL_2_BYTES 0x1407
#define GL_3_BYTES 0x1408 #define GL_3_BYTES 0x1408
#define GL_4_BYTES 0x1409 #define GL_4_BYTES 0x1409

View File

@ -71,6 +71,7 @@
#define GL_RGB16I 0x8D89 #define GL_RGB16I 0x8D89
#define GL_RGBA8I 0x8D8E #define GL_RGBA8I 0x8D8E
#define GL_RGB8I 0x8D8F #define GL_RGB8I 0x8D8F
#define GL_RGB10_A2 0x8059
#define GL_RED_INTEGER 0x8D94 #define GL_RED_INTEGER 0x8D94
#define GL_GREEN_INTEGER 0x8D95 #define GL_GREEN_INTEGER 0x8D95
#define GL_BLUE_INTEGER 0x8D96 #define GL_BLUE_INTEGER 0x8D96
@ -108,6 +109,7 @@
#define GL_DEPTH_COMPONENT32F 0x8CAC #define GL_DEPTH_COMPONENT32F 0x8CAC
#define GL_DEPTH32F_STENCIL8 0x8CAD #define GL_DEPTH32F_STENCIL8 0x8CAD
#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD #define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD
#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 #define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 #define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210
#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 #define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211

View File

@ -136,6 +136,10 @@ DXGI_FORMAT GetDXGIFormatForAbstractFormat(AbstractTextureFormat format, bool ty
return typeless ? DXGI_FORMAT_R8G8B8A8_TYPELESS : DXGI_FORMAT_R8G8B8A8_UNORM; return typeless ? DXGI_FORMAT_R8G8B8A8_TYPELESS : DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
return typeless ? DXGI_FORMAT_B8G8R8A8_TYPELESS : DXGI_FORMAT_B8G8R8A8_UNORM; return typeless ? DXGI_FORMAT_B8G8R8A8_TYPELESS : DXGI_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::RGB10_A2:
return typeless ? DXGI_FORMAT_R10G10B10A2_TYPELESS : DXGI_FORMAT_R10G10B10A2_UNORM;
case AbstractTextureFormat::RGBA16F:
return typeless ? DXGI_FORMAT_R16G16B16A16_TYPELESS : DXGI_FORMAT_R16G16B16A16_FLOAT;
case AbstractTextureFormat::R16: case AbstractTextureFormat::R16:
return typeless ? DXGI_FORMAT_R16_TYPELESS : DXGI_FORMAT_R16_UNORM; return typeless ? DXGI_FORMAT_R16_TYPELESS : DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:
@ -169,6 +173,10 @@ DXGI_FORMAT GetSRVFormatForAbstractFormat(AbstractTextureFormat format)
return DXGI_FORMAT_R8G8B8A8_UNORM; return DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
return DXGI_FORMAT_B8G8R8A8_UNORM; return DXGI_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::RGB10_A2:
return DXGI_FORMAT_R10G10B10A2_UNORM;
case AbstractTextureFormat::RGBA16F:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case AbstractTextureFormat::R16: case AbstractTextureFormat::R16:
return DXGI_FORMAT_R16_UNORM; return DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:
@ -195,6 +203,10 @@ DXGI_FORMAT GetRTVFormatForAbstractFormat(AbstractTextureFormat format, bool int
return integer ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM; return integer ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
return DXGI_FORMAT_B8G8R8A8_UNORM; return DXGI_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::RGB10_A2:
return DXGI_FORMAT_R10G10B10A2_UNORM;
case AbstractTextureFormat::RGBA16F:
return DXGI_FORMAT_R16G16B16A16_FLOAT;
case AbstractTextureFormat::R16: case AbstractTextureFormat::R16:
return integer ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R16_UNORM; return integer ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R16_UNORM;
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:
@ -235,6 +247,14 @@ AbstractTextureFormat GetAbstractFormatForDXGIFormat(DXGI_FORMAT format)
case DXGI_FORMAT_B8G8R8A8_TYPELESS: case DXGI_FORMAT_B8G8R8A8_TYPELESS:
return AbstractTextureFormat::BGRA8; return AbstractTextureFormat::BGRA8;
case DXGI_FORMAT_R10G10B10A2_UNORM:
case DXGI_FORMAT_R10G10B10A2_TYPELESS:
return AbstractTextureFormat::RGB10_A2;
case DXGI_FORMAT_R16G16B16A16_FLOAT:
case DXGI_FORMAT_R16G16B16A16_TYPELESS:
return AbstractTextureFormat::RGBA16F;
case DXGI_FORMAT_R16_UINT: case DXGI_FORMAT_R16_UINT:
case DXGI_FORMAT_R16_UNORM: case DXGI_FORMAT_R16_UNORM:
case DXGI_FORMAT_R16_TYPELESS: case DXGI_FORMAT_R16_TYPELESS:

View File

@ -263,6 +263,8 @@ AbstractTextureFormat Metal::Util::ToAbstract(MTLPixelFormat format)
{ {
case MTLPixelFormatRGBA8Unorm: return AbstractTextureFormat::RGBA8; case MTLPixelFormatRGBA8Unorm: return AbstractTextureFormat::RGBA8;
case MTLPixelFormatBGRA8Unorm: return AbstractTextureFormat::BGRA8; case MTLPixelFormatBGRA8Unorm: return AbstractTextureFormat::BGRA8;
case MTLPixelFormatRGB10A2Unorm: return AbstractTextureFormat::RGB10_A2;
case MTLPixelFormatRGBA16Float: return AbstractTextureFormat::RGBA16F;
case MTLPixelFormatBC1_RGBA: return AbstractTextureFormat::DXT1; case MTLPixelFormatBC1_RGBA: return AbstractTextureFormat::DXT1;
case MTLPixelFormatBC2_RGBA: return AbstractTextureFormat::DXT3; case MTLPixelFormatBC2_RGBA: return AbstractTextureFormat::DXT3;
case MTLPixelFormatBC3_RGBA: return AbstractTextureFormat::DXT5; case MTLPixelFormatBC3_RGBA: return AbstractTextureFormat::DXT5;
@ -289,6 +291,8 @@ MTLPixelFormat Metal::Util::FromAbstract(AbstractTextureFormat format)
{ {
case AbstractTextureFormat::RGBA8: return MTLPixelFormatRGBA8Unorm; case AbstractTextureFormat::RGBA8: return MTLPixelFormatRGBA8Unorm;
case AbstractTextureFormat::BGRA8: return MTLPixelFormatBGRA8Unorm; case AbstractTextureFormat::BGRA8: return MTLPixelFormatBGRA8Unorm;
case AbstractTextureFormat::RGB10_A2: return MTLPixelFormatRGB10A2Unorm;
case AbstractTextureFormat::RGBA16F: return MTLPixelFormatRGBA16Float;
case AbstractTextureFormat::DXT1: return MTLPixelFormatBC1_RGBA; case AbstractTextureFormat::DXT1: return MTLPixelFormatBC1_RGBA;
case AbstractTextureFormat::DXT3: return MTLPixelFormatBC2_RGBA; case AbstractTextureFormat::DXT3: return MTLPixelFormatBC2_RGBA;
case AbstractTextureFormat::DXT5: return MTLPixelFormatBC3_RGBA; case AbstractTextureFormat::DXT5: return MTLPixelFormatBC3_RGBA;

View File

@ -33,6 +33,10 @@ GLenum GetGLInternalFormatForTextureFormat(AbstractTextureFormat format, bool st
return storage ? GL_RGBA8 : GL_RGBA; return storage ? GL_RGBA8 : GL_RGBA;
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
return storage ? GL_RGBA8 : GL_BGRA; return storage ? GL_RGBA8 : GL_BGRA;
case AbstractTextureFormat::RGB10_A2:
return GL_RGB10_A2;
case AbstractTextureFormat::RGBA16F:
return GL_RGBA16F;
case AbstractTextureFormat::R16: case AbstractTextureFormat::R16:
return GL_R16; return GL_R16;
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:
@ -59,6 +63,10 @@ GLenum GetGLFormatForTextureFormat(AbstractTextureFormat format)
return GL_RGBA; return GL_RGBA;
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
return GL_BGRA; return GL_BGRA;
case AbstractTextureFormat::RGB10_A2:
return GL_RGB10_A2;
case AbstractTextureFormat::RGBA16F:
return GL_RGBA16F;
case AbstractTextureFormat::R16: case AbstractTextureFormat::R16:
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:
return GL_RED; return GL_RED;
@ -81,6 +89,10 @@ GLenum GetGLTypeForTextureFormat(AbstractTextureFormat format)
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
return GL_UNSIGNED_BYTE; return GL_UNSIGNED_BYTE;
case AbstractTextureFormat::RGB10_A2:
return GL_UNSIGNED_INT_2_10_10_10_REV;
case AbstractTextureFormat::RGBA16F:
return GL_HALF_FLOAT;
case AbstractTextureFormat::R16: case AbstractTextureFormat::R16:
return GL_UNSIGNED_SHORT; return GL_UNSIGNED_SHORT;
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:

View File

@ -189,6 +189,12 @@ VkFormat VKTexture::GetVkFormatForHostTextureFormat(AbstractTextureFormat format
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
return VK_FORMAT_B8G8R8A8_UNORM; return VK_FORMAT_B8G8R8A8_UNORM;
case AbstractTextureFormat::RGB10_A2:
return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
case AbstractTextureFormat::RGBA16F:
return VK_FORMAT_R16G16B16A16_SFLOAT;
case AbstractTextureFormat::R16: case AbstractTextureFormat::R16:
return VK_FORMAT_R16_UNORM; return VK_FORMAT_R16_UNORM;

View File

@ -26,6 +26,9 @@ bool AbstractTexture::Save(const std::string& filename, unsigned int level, int
// anyway, so this is fine for now. // anyway, so this is fine for now.
ASSERT(!IsCompressedFormat(m_config.format)); ASSERT(!IsCompressedFormat(m_config.format));
ASSERT(level < m_config.levels); ASSERT(level < m_config.levels);
// We can't copy from float (HDR) textures to RGBA8
// (most other formats would probably fail as well)
ASSERT(m_config.format != AbstractTextureFormat::RGBA16F);
// Determine dimensions of image we want to save. // Determine dimensions of image we want to save.
u32 level_width = std::max(1u, m_config.width >> level); u32 level_width = std::max(1u, m_config.width >> level);
@ -120,11 +123,13 @@ u32 AbstractTexture::CalculateStrideForFormat(AbstractTextureFormat format, u32
return static_cast<size_t>(row_length) * 2; return static_cast<size_t>(row_length) * 2;
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
case AbstractTextureFormat::RGB10_A2:
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:
case AbstractTextureFormat::D32F: case AbstractTextureFormat::D32F:
case AbstractTextureFormat::D24_S8: case AbstractTextureFormat::D24_S8:
return static_cast<size_t>(row_length) * 4; return static_cast<size_t>(row_length) * 4;
case AbstractTextureFormat::D32F_S8: case AbstractTextureFormat::D32F_S8:
case AbstractTextureFormat::RGBA16F:
return static_cast<size_t>(row_length) * 8; return static_cast<size_t>(row_length) * 8;
default: default:
PanicAlertFmt("Unhandled texture format."); PanicAlertFmt("Unhandled texture format.");
@ -147,11 +152,13 @@ u32 AbstractTexture::GetTexelSizeForFormat(AbstractTextureFormat format)
return 2; return 2;
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
case AbstractTextureFormat::BGRA8: case AbstractTextureFormat::BGRA8:
case AbstractTextureFormat::RGB10_A2:
case AbstractTextureFormat::D24_S8: case AbstractTextureFormat::D24_S8:
case AbstractTextureFormat::R32F: case AbstractTextureFormat::R32F:
case AbstractTextureFormat::D32F: case AbstractTextureFormat::D32F:
return 4; return 4;
case AbstractTextureFormat::D32F_S8: case AbstractTextureFormat::D32F_S8:
case AbstractTextureFormat::RGBA16F:
return 8; return 8;
default: default:
PanicAlertFmt("Unhandled texture format."); PanicAlertFmt("Unhandled texture format.");

View File

@ -13,6 +13,8 @@ enum class AbstractTextureFormat : u32
{ {
RGBA8, RGBA8,
BGRA8, BGRA8,
RGB10_A2,
RGBA16F,
DXT1, DXT1,
DXT3, DXT3,
DXT5, DXT5,