Skip to content

Commit

Permalink
Move functions from Common to TextureFormat
Browse files Browse the repository at this point in the history
Summary: ^^

Reviewed By: EricGriffith, rameshviswanathan

Differential Revision: D62810776

fbshipit-source-id: 781aa7dd9a289a66c0bca4e5bd9d4097bb038663
  • Loading branch information
francoiscoulombe authored and facebook-github-bot committed Sep 19, 2024
1 parent 7511f0a commit df4d8c1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 37 deletions.
29 changes: 0 additions & 29 deletions src/igl/vulkan/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,6 @@ void setResultFrom(Result* outResult, VkResult result) {
*outResult = getResultFromVkResult(result);
}

VkFormat invertRedAndBlue(VkFormat format) {
switch (format) {
case VK_FORMAT_B8G8R8A8_UNORM:
return VK_FORMAT_R8G8B8A8_UNORM;
case VK_FORMAT_R8G8B8A8_UNORM:
return VK_FORMAT_B8G8R8A8_UNORM;
case VK_FORMAT_R8G8B8A8_SRGB:
return VK_FORMAT_B8G8R8A8_SRGB;
case VK_FORMAT_B8G8R8A8_SRGB:
return VK_FORMAT_R8G8B8A8_SRGB;
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
default:
IGL_UNREACHABLE_RETURN(format);
}
}

VkStencilOp stencilOperationToVkStencilOp(igl::StencilOperation op) {
switch (op) {
case igl::StencilOperation::Keep:
Expand Down Expand Up @@ -335,16 +316,6 @@ igl::ColorSpace vkColorSpaceToColorSpace(VkColorSpaceKHR colorSpace) {
}
}

bool isTextureFormatRGB(VkFormat format) {
return format == VK_FORMAT_R8G8B8A8_UNORM || format == VK_FORMAT_R8G8B8A8_SRGB ||
format == VK_FORMAT_A2R10G10B10_UNORM_PACK32;
}

bool isTextureFormatBGR(VkFormat format) {
return format == VK_FORMAT_B8G8R8A8_UNORM || format == VK_FORMAT_B8G8R8A8_SRGB ||
format == VK_FORMAT_A2B10G10R10_UNORM_PACK32;
}

igl::TextureFormat vkFormatToTextureFormat(VkFormat format) {
return util::vkTextureFormatToTextureFormat(format);
}
Expand Down
3 changes: 0 additions & 3 deletions src/igl/vulkan/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ void setResultFrom(Result* outResult, VkResult result);
VkFormat textureFormatToVkFormat(igl::TextureFormat format);
igl::TextureFormat vkFormatToTextureFormat(VkFormat format);
igl::ColorSpace vkColorSpaceToColorSpace(VkColorSpaceKHR colorSpace);
VkFormat invertRedAndBlue(VkFormat format);
bool isTextureFormatRGB(VkFormat format);
bool isTextureFormatBGR(VkFormat format);
uint32_t getNumImagePlanes(VkFormat format);
VkColorSpaceKHR colorSpaceToVkColorSpace(igl::ColorSpace colorSpace);
VkMemoryPropertyFlags resourceStorageToVkMemoryPropertyFlags(igl::ResourceStorage resourceStorage);
Expand Down
9 changes: 5 additions & 4 deletions src/igl/vulkan/VulkanSwapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <igl/vulkan/VulkanRenderPassBuilder.h>
#include <igl/vulkan/VulkanSemaphore.h>
#include <igl/vulkan/VulkanTexture.h>
#include <igl/vulkan/util/TextureFormat.h>

namespace {

Expand All @@ -34,10 +35,10 @@ bool isNativeSwapChainBGR(const std::vector<VkSurfaceFormatKHR>& formats) {
// The preferred format should be the one which is closer to the beginning of the formats
// container. If BGR is encountered earlier, it should be picked as the format of choice. If RGB
// happens to be earlier, take it.
if (igl::vulkan::isTextureFormatRGB(format.format)) {
if (igl::vulkan::util::isTextureFormatRGB(format.format)) {
return false;
}
if (igl::vulkan::isTextureFormatBGR(format.format)) {
if (igl::vulkan::util::isTextureFormatBGR(format.format)) {
return true;
}
}
Expand All @@ -51,9 +52,9 @@ VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>

const bool isNativeSwapchainBGR = isNativeSwapChainBGR(formats);
auto vulkanTextureFormat = igl::vulkan::textureFormatToVkFormat(textureFormat);
const bool isRequestedFormatBGR = igl::vulkan::isTextureFormatBGR(vulkanTextureFormat);
const bool isRequestedFormatBGR = igl::vulkan::util::isTextureFormatBGR(vulkanTextureFormat);
if (isNativeSwapchainBGR != isRequestedFormatBGR) {
vulkanTextureFormat = igl::vulkan::invertRedAndBlue(vulkanTextureFormat);
vulkanTextureFormat = igl::vulkan::util::invertRedAndBlue(vulkanTextureFormat);
}
const auto preferred =
VkSurfaceFormatKHR{vulkanTextureFormat, igl::vulkan::colorSpaceToVkColorSpace(colorSpace)};
Expand Down
20 changes: 20 additions & 0 deletions src/igl/vulkan/util/TextureFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,24 @@ TextureFormat vkTextureFormatToTextureFormat(VkFormat vkFormat) {
return TextureFormat::Invalid;
}

VkFormat invertRedAndBlue(VkFormat format) {
switch (format) {
case VK_FORMAT_B8G8R8A8_UNORM:
return VK_FORMAT_R8G8B8A8_UNORM;
case VK_FORMAT_R8G8B8A8_UNORM:
return VK_FORMAT_B8G8R8A8_UNORM;
case VK_FORMAT_R8G8B8A8_SRGB:
return VK_FORMAT_B8G8R8A8_SRGB;
case VK_FORMAT_B8G8R8A8_SRGB:
return VK_FORMAT_R8G8B8A8_SRGB;
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
default:
IGL_ASSERT_NOT_REACHED();
return format;
}
}

} // namespace igl::vulkan::util
11 changes: 11 additions & 0 deletions src/igl/vulkan/util/TextureFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ namespace igl::vulkan::util {
/// @return The corresponding IGL format if known; otherwise returns TextureFormat::Invalid.
TextureFormat vkTextureFormatToTextureFormat(VkFormat vkFormat);

VkFormat invertRedAndBlue(VkFormat format);

inline bool isTextureFormatRGB(VkFormat format) {
return format == VK_FORMAT_R8G8B8A8_UNORM || format == VK_FORMAT_R8G8B8A8_SRGB ||
format == VK_FORMAT_A2R10G10B10_UNORM_PACK32;
}

inline bool isTextureFormatBGR(VkFormat format) {
return format == VK_FORMAT_B8G8R8A8_UNORM || format == VK_FORMAT_B8G8R8A8_SRGB ||
format == VK_FORMAT_A2B10G10R10_UNORM_PACK32;
}
} // namespace igl::vulkan::util
1 change: 0 additions & 1 deletion src/igl/vulkan/util/TextureFormatInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
namespace igl::vulkan::util {

TextureFormat intVkTextureFormatToTextureFormat(int32_t vkFormat);

} // namespace igl::vulkan::util

0 comments on commit df4d8c1

Please sign in to comment.