Skip to content

Commit

Permalink
Adding support for sRGB bc7 textures
Browse files Browse the repository at this point in the history
Summary: Adding support for sRGB bc7 textures

Reviewed By: corporateshark

Differential Revision: D46647850

fbshipit-source-id: 7da4a9bacb87b7edf3f1352935bd46a1fca7e1a3
  • Loading branch information
francoiscoulombe authored and facebook-github-bot committed Aug 1, 2023
1 parent c5c0bd6 commit cab9f8f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/igl/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ TextureFormatProperties TextureFormatProperties::fromTextureFormat(TextureFormat
COMPRESSED(R_EAC_UNorm, 1, 8, 4, 4, 1, 1, 1, 1, 0)
COMPRESSED(R_EAC_SNorm, 1, 8, 4, 4, 1, 1, 1, 1, 0)
COMPRESSED(RGBA_BC7_UNORM_4x4, 4, 16, 4, 4, 1, 1, 1, 1, 0)
COMPRESSED(RGBA_BC7_SRGB_4x4, 4, 16, 4, 4, 1, 1, 1, 1, Flags::sRGB)
DEPTH_STENCIL(Z_UNorm16, 1, 2)
DEPTH_STENCIL(Z_UNorm24, 1, 3)
DEPTH_STENCIL(Z_UNorm32, 1, 4)
Expand Down
1 change: 1 addition & 0 deletions src/igl/TextureFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ enum class TextureFormat : uint8_t {
R_EAC_UNorm,
R_EAC_SNorm,
RGBA_BC7_UNORM_4x4, // block compression
RGBA_BC7_SRGB_4x4, // block compression

// Depth and Stencil formats
Z_UNorm16, // NA on iOS/Metal but works on iOS GLES. The client has to account for
Expand Down
1 change: 1 addition & 0 deletions src/igl/metal/DeviceFeatureSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
#endif

case TextureFormat::RGBA_BC7_UNORM_4x4:
case TextureFormat::RGBA_BC7_SRGB_4x4:

#if IGL_PLATFORM_MACOS || IGL_PLATFORM_MACCATALYST
return sampled;
Expand Down
6 changes: 6 additions & 0 deletions src/igl/metal/Texture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,12 @@ bool isFilterable(MTLPixelFormat format, bool supports32BitFloatFiltering) {
#else
return MTLPixelFormatInvalid;
#endif
case TextureFormat::RGBA_BC7_SRGB_4x4:
#if IGL_PLATFORM_MACOS || IGL_PLATFORM_MACCATALYST
return MTLPixelFormatBC7_RGBAUnorm_sRGB;
#else
return MTLPixelFormatInvalid;
#endif

// Depth & Stencil
case TextureFormat::Z_UNorm16:
Expand Down
1 change: 1 addition & 0 deletions src/igl/opengl/DeviceFeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ ICapabilities::TextureFormatCapabilities DeviceFeatureSet::getTextureFormatCapab
}
break;
case TextureFormat::RGBA_BC7_UNORM_4x4:
case TextureFormat::RGBA_BC7_SRGB_4x4:
if (hasTextureFeature(TextureFeatures::TextureCompressionBptc)) {
capabilities |= compressed;
}
Expand Down
9 changes: 9 additions & 0 deletions src/igl/opengl/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ TextureFormat Texture::glInternalFormatToTextureFormat(GLuint glTexInternalForma
case GL_COMPRESSED_RGBA_BPTC_UNORM:
return TextureFormat::RGBA_BC7_UNORM_4x4;

case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
return TextureFormat::RGBA_BC7_SRGB_4x4;

case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
return TextureFormat::RGBA_PVRTC_2BPPV1;

Expand Down Expand Up @@ -1107,6 +1110,12 @@ bool Texture::toFormatDescGL(IContext& ctx,
type = 0;
return compressedValid;

case TextureFormat::RGBA_BC7_SRGB_4x4:
internalFormat = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
format = 0;
type = 0;
return compressedValid;

case TextureFormat::RGBA_PVRTC_2BPPV1:
internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
format = 0;
Expand Down
1 change: 1 addition & 0 deletions src/igl/tests/util/TextureFormatTestBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ std::vector<std::pair<TextureFormat, bool>> TextureFormatTestBase::getFormatSupp
formatSupport.emplace_back(checkSupport(TextureFormat::R_EAC_UNorm, usage));
formatSupport.emplace_back(checkSupport(TextureFormat::R_EAC_SNorm, usage));
formatSupport.emplace_back(checkSupport(TextureFormat::RGBA_BC7_UNORM_4x4, usage));
formatSupport.emplace_back(checkSupport(TextureFormat::RGBA_BC7_SRGB_4x4, usage));
formatSupport.emplace_back(checkSupport(TextureFormat::Z_UNorm16, usage));
formatSupport.emplace_back(checkSupport(TextureFormat::Z_UNorm24, usage));
formatSupport.emplace_back(checkSupport(TextureFormat::Z_UNorm32, usage));
Expand Down
4 changes: 4 additions & 0 deletions src/igl/vulkan/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ VkFormat textureFormatToVkFormat(igl::TextureFormat format) {
return VK_FORMAT_EAC_R11_SNORM_BLOCK;
case TextureFormat::RGBA_BC7_UNORM_4x4:
return VK_FORMAT_BC7_UNORM_BLOCK;
case TextureFormat::RGBA_BC7_SRGB_4x4:
return VK_FORMAT_BC7_SRGB_BLOCK;
case TextureFormat::Z_UNorm16:
return VK_FORMAT_D16_UNORM;
case TextureFormat::Z_UNorm24:
Expand Down Expand Up @@ -378,6 +380,8 @@ igl::TextureFormat vkFormatToTextureFormat(VkFormat format) {
return TextureFormat::Z_UNorm16;
case VK_FORMAT_BC7_UNORM_BLOCK:
return TextureFormat::RGBA_BC7_UNORM_4x4;
case VK_FORMAT_BC7_SRGB_BLOCK:
return TextureFormat::RGBA_BC7_SRGB_4x4;
case VK_FORMAT_X8_D24_UNORM_PACK32:
return TextureFormat::Z_UNorm24;
case VK_FORMAT_D24_UNORM_S8_UINT:
Expand Down

0 comments on commit cab9f8f

Please sign in to comment.