Skip to content

Commit

Permalink
IGL: Remove helper functions from TextureFormat.h
Browse files Browse the repository at this point in the history
Summary:
This diff removes two helper functions from TextureFormat.h. Each is only used in one place.

isTextureFormatBGR is inaccurately named as it only checks for two of the five supported BGR formats. It is be replaced with its implementation.

isTextureFormatsRGB is also a less functional version of checking isSRGB() on the format's properties so this call is replaced with using the texture format properties.

Reviewed By: KyleFung

Differential Revision: D49699222

fbshipit-source-id: af8811b765b999059621df3b5bccf7c1cf6c746e
  • Loading branch information
Eric Griffith authored and facebook-github-bot committed Sep 29, 2023
1 parent cf37732 commit 0ad4fc8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
20 changes: 10 additions & 10 deletions shell/mac/ViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,15 @@ - (void)loadView {
// vulkanView.wantsLayer =
// YES; // Back the view with a layer created by the makeBackingLayer method.

igl::vulkan::VulkanContextConfig vulkanContextConfig{
true, // terminateOnValidationError
false // enhancedShaderDebugging
};
const auto properties =
igl::TextureFormatProperties::fromTextureFormat(shellParams_.defaultColorFramebufferFormat);

igl::vulkan::VulkanContextConfig vulkanContextConfig;
vulkanContextConfig.terminateOnValidationError = true;
vulkanContextConfig.enhancedShaderDebugging = false;
vulkanContextConfig.swapChainColorSpace = properties.isSRGB() ? igl::ColorSpace::SRGB_NONLINEAR
: igl::ColorSpace::SRGB_LINEAR;

auto context =
igl::vulkan::HWDevice::createContext(vulkanContextConfig, (__bridge void*)vulkanView);
auto devices = igl::vulkan::HWDevice::queryDevices(
Expand All @@ -264,12 +269,7 @@ - (void)loadView {
devices = igl::vulkan::HWDevice::queryDevices(
*context.get(), igl::HWDeviceQueryDesc(igl::HWDeviceType::IntegratedGpu), nullptr);
}
auto device = igl::vulkan::HWDevice::create(
std::move(context),
devices[0],
0,
0,
!igl::isTextureFormatsRGB(shellParams_.defaultColorFramebufferFormat));
auto device = igl::vulkan::HWDevice::create(std::move(context), devices[0], 0, 0);

shellPlatform_ = std::make_shared<igl::shell::PlatformMac>(std::move(device));
[vulkanView prepareVulkan:shellPlatform_];
Expand Down
8 changes: 0 additions & 8 deletions src/igl/TextureFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,4 @@ enum class TextureFormat : uint8_t {
// account for this!
S_UInt8
};

constexpr bool isTextureFormatsRGB(TextureFormat textureFormat) {
return textureFormat == TextureFormat::RGBA_SRGB || textureFormat == TextureFormat::BGRA_SRGB;
}

constexpr bool isTextureFormatBGR(TextureFormat textureFormat) {
return textureFormat == TextureFormat::BGRA_SRGB || textureFormat == TextureFormat::BGRA_UNorm8;
}
} // namespace igl
2 changes: 1 addition & 1 deletion src/igl/metal/Texture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void bgrToRgb(unsigned char* dstImg, size_t width, size_t height, size_t bytesPe
igl::TextureFormat f = getFormat();
TextureFormatProperties props = TextureFormatProperties::fromTextureFormat(f);
auto bytesPerPixel = props.bytesPerBlock;
if (isTextureFormatBGR(f)) {
if (f == TextureFormat::BGRA_SRGB || f == TextureFormat::BGRA_UNorm8) {
bgrToRgb(static_cast<unsigned char*>(outData), range.width, range.height, bytesPerPixel);
}
return Result(Result::Code::Ok);
Expand Down

0 comments on commit 0ad4fc8

Please sign in to comment.