Skip to content

Commit

Permalink
Back out "Use vulkan headers instead of redefining the symbols"
Browse files Browse the repository at this point in the history
Summary:
Original commit changeset: bc6547a857bb

Original Phabricator Diff: D62810195

Reviewed By: ChristianK275, corporateshark

Differential Revision: D63074127

fbshipit-source-id: 81a191d08f08fde01fdf5aa971d7e5d0ee81dac7
  • Loading branch information
francoiscoulombe authored and facebook-github-bot committed Sep 20, 2024
1 parent c9c0023 commit 94e82a7
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 62 deletions.
12 changes: 6 additions & 6 deletions IGLU/texture_loader/ktx2/TextureLoaderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <IGLU/texture_loader/ktx2/Header.h>
#include <igl/IGLSafeC.h>
#include <igl/vulkan/util/TextureFormatInt.h>
#include <igl/vulkan/util/TextureFormat.h>
#include <ktx.h>
#include <numeric>
#include <vector>
Expand Down Expand Up @@ -49,8 +49,8 @@ bool TextureLoaderFactory::canCreateInternal(DataReader headerReader,
// In either case, we need to process the DFD to understand whether we can really handle the
// format or not.
if (header->vkFormat != 0 &&
igl::vulkan::util::intVkTextureFormatToTextureFormat(
static_cast<int32_t>(header->vkFormat)) == igl::TextureFormat::Invalid) {
igl::vulkan::util::vkTextureFormatToTextureFormat(static_cast<int32_t>(header->vkFormat)) ==
igl::TextureFormat::Invalid) {
igl::Result::setResult(
outResult, igl::Result::Code::InvalidOperation, "Unrecognized texture format.");
return false;
Expand Down Expand Up @@ -93,8 +93,8 @@ bool TextureLoaderFactory::validate(DataReader reader,
}

if (header->vkFormat != 0u) {
const auto format = igl::vulkan::util::intVkTextureFormatToTextureFormat(
static_cast<int32_t>(header->vkFormat));
const auto format =
igl::vulkan::util::vkTextureFormatToTextureFormat(static_cast<int32_t>(header->vkFormat));
const auto properties = igl::TextureFormatProperties::fromTextureFormat(format);

const uint32_t mipLevelAlignment =
Expand Down Expand Up @@ -178,7 +178,7 @@ bool TextureLoaderFactory::validate(DataReader reader,
igl::TextureFormat TextureLoaderFactory::textureFormat(const ktxTexture* texture) const noexcept {
if (texture->classId == ktxTexture2_c) {
const auto* texture2 = reinterpret_cast<const ktxTexture2*>(texture);
return igl::vulkan::util::intVkTextureFormatToTextureFormat(
return igl::vulkan::util::vkTextureFormatToTextureFormat(
static_cast<int32_t>(texture2->vkFormat));
}

Expand Down
4 changes: 2 additions & 2 deletions samples/desktop/Tiny/Tiny_MeshLarge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include <igl/FPSCounter.h>
#include <igl/IGL.h>
#include <igl/vulkan/util/TextureFormatInt.h>
#include <igl/vulkan/util/TextureFormat.h>

#include <glm/ext.hpp>
#include <glm/glm.hpp>
Expand Down Expand Up @@ -2295,7 +2295,7 @@ void loadCubemapTexture(const std::string& fileNameKTX, std::shared_ptr<ITexture
}

auto desc =
TextureDesc::newCube(igl::vulkan::util::intVkTextureFormatToTextureFormat(texture->vkFormat),
TextureDesc::newCube(igl::vulkan::util::vkTextureFormatToTextureFormat(texture->vkFormat),
texRefRange.width,
texRefRange.height,
TextureDesc::TextureUsageBits::Sampled,
Expand Down
8 changes: 4 additions & 4 deletions src/igl/tests/iglu/texture_loader/Ktx2TextureLoaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <IGLU/texture_loader/ktx2/Header.h>
#include <IGLU/texture_loader/ktx2/TextureLoaderFactory.h>
#include <cstring>
#include <igl/vulkan/util/TextureFormatInt.h>
#include <igl/vulkan/util/TextureFormat.h>
#include <numeric>
#include <vector>

Expand Down Expand Up @@ -60,7 +60,7 @@ uint32_t getTotalDataSize(uint32_t vkFormat,
uint32_t height,
uint32_t numMipLevels) {
const auto format =
igl::vulkan::util::intVkTextureFormatToTextureFormat(static_cast<int32_t>(vkFormat));
igl::vulkan::util::vkTextureFormatToTextureFormat(static_cast<int32_t>(vkFormat));
const auto properties = igl::TextureFormatProperties::fromTextureFormat(format);

const auto range = igl::TextureRangeDesc::new2D(0, 0, std::max(width, 1u), std::max(height, 1u));
Expand Down Expand Up @@ -90,7 +90,7 @@ void putDfd(std::vector<uint8_t>& buffer, uint32_t vkFormat, uint32_t numMipLeve
vkFormat == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK);

const auto format =
igl::vulkan::util::intVkTextureFormatToTextureFormat(static_cast<int32_t>(vkFormat));
igl::vulkan::util::vkTextureFormatToTextureFormat(static_cast<int32_t>(vkFormat));
const auto properties = igl::TextureFormatProperties::fromTextureFormat(format);

const uint16_t descriptorType = 0;
Expand Down Expand Up @@ -155,7 +155,7 @@ void putDfd(std::vector<uint8_t>& buffer, uint32_t vkFormat, uint32_t numMipLeve
void putMipLevel(std::vector<uint8_t>& buffer, uint32_t mipLevel, uint32_t imageSize) {
const auto* header = reinterpret_cast<const iglu::textureloader::ktx2::Header*>(buffer.data());
const auto format =
igl::vulkan::util::intVkTextureFormatToTextureFormat(static_cast<int32_t>(header->vkFormat));
igl::vulkan::util::vkTextureFormatToTextureFormat(static_cast<int32_t>(header->vkFormat));
const auto properties = igl::TextureFormatProperties::fromTextureFormat(format);

const auto range = igl::TextureRangeDesc::new2D(
Expand Down
2 changes: 1 addition & 1 deletion src/igl/vulkan/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ bool isTextureFormatBGR(VkFormat format) {
}

igl::TextureFormat vkFormatToTextureFormat(VkFormat format) {
return util::vkTextureFormatToTextureFormat(format);
return util::vkTextureFormatToTextureFormat(static_cast<int32_t>(format));
}

VkMemoryPropertyFlags resourceStorageToVkMemoryPropertyFlags(igl::ResourceStorage resourceStorage) {
Expand Down
85 changes: 83 additions & 2 deletions src/igl/vulkan/util/TextureFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,90 @@

namespace igl::vulkan::util {

using TextureFormat = ::igl::TextureFormat;
// @fb-only

TextureFormat vkTextureFormatToTextureFormat(VkFormat vkFormat) {
// Vulkan Defines
#define VK_FORMAT_UNDEFINED 0
#define VK_FORMAT_R8_UNORM 9
#define VK_FORMAT_R16_UNORM 70
#define VK_FORMAT_R16_SFLOAT 76
#define VK_FORMAT_R16_UINT 74
#define VK_FORMAT_B5G5R5A1_UNORM_PACK16 7
#define VK_FORMAT_B5G6R5_UNORM_PACK16 5
#define VK_FORMAT_B4G4R4A4_UNORM_PACK16 3
#define VK_FORMAT_R8G8_UNORM 16
#define VK_FORMAT_R5G5B5A1_UNORM_PACK16 6
#define VK_FORMAT_B8G8R8A8_UNORM 44
#define VK_FORMAT_R8G8B8A8_UNORM 37
#define VK_FORMAT_R8G8B8A8_SRGB 43
#define VK_FORMAT_B8G8R8A8_SRGB 50
#define VK_FORMAT_R16G16_UNORM 77
#define VK_FORMAT_R16G16_SFLOAT 83
#define VK_FORMAT_R16G16_UINT 81
#define VK_FORMAT_A2R10G10B10_UNORM_PACK32 58
#define VK_FORMAT_A2R10G10B10_UINT_PACK32 62
#define VK_FORMAT_A2B10G10R10_UNORM_PACK32 64
#define VK_FORMAT_R32_SFLOAT 100
#define VK_FORMAT_R32G32_SFLOAT 103
#define VK_FORMAT_R16G16B16_SFLOAT 90
#define VK_FORMAT_R16G16B16A16_SFLOAT 97
#define VK_FORMAT_R32G32B32_SFLOAT 106
#define VK_FORMAT_R32G32B32A32_UINT 107
#define VK_FORMAT_R32G32B32A32_SFLOAT 109
#define VK_FORMAT_ASTC_4x4_UNORM_BLOCK 157
#define VK_FORMAT_ASTC_4x4_SRGB_BLOCK 158
#define VK_FORMAT_ASTC_5x4_UNORM_BLOCK 159
#define VK_FORMAT_ASTC_5x4_SRGB_BLOCK 160
#define VK_FORMAT_ASTC_5x5_UNORM_BLOCK 161
#define VK_FORMAT_ASTC_5x5_SRGB_BLOCK 162
#define VK_FORMAT_ASTC_6x5_UNORM_BLOCK 163
#define VK_FORMAT_ASTC_6x5_SRGB_BLOCK 164
#define VK_FORMAT_ASTC_6x6_UNORM_BLOCK 165
#define VK_FORMAT_ASTC_6x6_SRGB_BLOCK 166
#define VK_FORMAT_ASTC_8x5_UNORM_BLOCK 167
#define VK_FORMAT_ASTC_8x5_SRGB_BLOCK 168
#define VK_FORMAT_ASTC_8x6_UNORM_BLOCK 169
#define VK_FORMAT_ASTC_8x6_SRGB_BLOCK 170
#define VK_FORMAT_ASTC_8x8_UNORM_BLOCK 171
#define VK_FORMAT_ASTC_8x8_SRGB_BLOCK 172
#define VK_FORMAT_ASTC_10x5_UNORM_BLOCK 173
#define VK_FORMAT_ASTC_10x5_SRGB_BLOCK 174
#define VK_FORMAT_ASTC_10x6_UNORM_BLOCK 175
#define VK_FORMAT_ASTC_10x6_SRGB_BLOCK 176
#define VK_FORMAT_ASTC_10x8_UNORM_BLOCK 177
#define VK_FORMAT_ASTC_10x8_SRGB_BLOCK 178
#define VK_FORMAT_ASTC_10x10_UNORM_BLOCK 179
#define VK_FORMAT_ASTC_10x10_SRGB_BLOCK 180
#define VK_FORMAT_ASTC_12x10_UNORM_BLOCK 181
#define VK_FORMAT_ASTC_12x10_SRGB_BLOCK 182
#define VK_FORMAT_ASTC_12x12_UNORM_BLOCK 183
#define VK_FORMAT_ASTC_12x12_SRGB_BLOCK 184
#define VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG 1000054000
#define VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG 1000054001
#define VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG 1000054002
#define VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG 1000054003
#define VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG 1000054004
#define VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG 1000054005
#define VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG 1000054006
#define VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG 1000054007
#define VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK 147
#define VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK 148
#define VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK 149
#define VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK 150
#define VK_FORMAT_EAC_R11G11_UNORM_BLOCK 155
#define VK_FORMAT_EAC_R11G11_SNORM_BLOCK 156
#define VK_FORMAT_EAC_R11_UNORM_BLOCK 153
#define VK_FORMAT_EAC_R11_SNORM_BLOCK 154
#define VK_FORMAT_D16_UNORM 124
#define VK_FORMAT_BC7_UNORM_BLOCK 145
#define VK_FORMAT_BC7_SRGB_BLOCK 146
#define VK_FORMAT_X8_D24_UNORM_PACK32 125
#define VK_FORMAT_D24_UNORM_S8_UINT 129
#define VK_FORMAT_S8_UINT 127
#define VK_FORMAT_D32_SFLOAT_S8_UINT 130
#define VK_FORMAT_D32_SFLOAT 126

TextureFormat vkTextureFormatToTextureFormat(int32_t vkFormat) {
switch (vkFormat) {
case VK_FORMAT_UNDEFINED:
return TextureFormat::Invalid;
Expand Down
9 changes: 1 addition & 8 deletions src/igl/vulkan/util/TextureFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@
#pragma once

#include <cstdint>
#include <igl/Macros.h>
#include <igl/TextureFormat.h>

#if !defined(IGL_CMAKE_BUILD)
#include <vulkan/vulkan_core.h>
#else
#include <volk/volk.h>
#endif

namespace igl::vulkan::util {

/// Converts Vulkan texture format to an IGL TextureFormat.
/// @return The corresponding IGL format if known; otherwise returns TextureFormat::Invalid.
TextureFormat vkTextureFormatToTextureFormat(VkFormat vkFormat);
TextureFormat vkTextureFormatToTextureFormat(int32_t vkFormat);

} // namespace igl::vulkan::util
22 changes: 0 additions & 22 deletions src/igl/vulkan/util/TextureFormatInt.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions src/igl/vulkan/util/TextureFormatInt.h

This file was deleted.

0 comments on commit 94e82a7

Please sign in to comment.