Skip to content

Commit

Permalink
Remove unused pixel formats; added RG_F32
Browse files Browse the repository at this point in the history
  • Loading branch information
corporateshark committed Jul 12, 2023
1 parent 11b036a commit 57a566c
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 162 deletions.
2 changes: 1 addition & 1 deletion lvk/HelpersImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ImGuiRenderer::ImGuiRenderer(igl::IDevice& device, const char* defaultFontTTF, f
int width, height;
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
fontTexture_ = device.createTexture({.type = igl::TextureType::TwoD,
.format = igl::TextureFormat::RGBA_UNorm8,
.format = igl::TextureFormat::RGBA_UN8,
.width = (uint32_t)width,
.height = (uint32_t)height,
.usage = igl::TextureUsageBits_Sampled},
Expand Down
56 changes: 23 additions & 33 deletions lvk/LVK.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,45 +374,35 @@ enum class VertexFormat {
enum TextureFormat : uint8_t {
Invalid = 0,


R_UNorm8,

R_UN8,
R_UI16,
R_UN16,
R_F16,
R_UInt16,
R_UNorm16,
RG_UNorm8,

RGBA_UNorm8,
BGRA_UNorm8,
RGBA_SRGB,
BGRA_SRGB,
RG_F16,
RG_UInt16,
RG_UNorm16,
RGB10_A2_UNorm_Rev,
RGB10_A2_Uint_Rev,
BGR10_A2_Unorm,
R_F32,

RGBA_F16,
RG_UN8,
RG_UI16,
RG_UN16,
RG_F16,
RG_F32,

RGBA_UInt32,
RGBA_UN8,
RGBA_UI32,
RGBA_F16,
RGBA_F32,
RGBA_SRGB8,

BGRA_UN8,
BGRA_SRGB8,

ETC2_RGB8,
ETC2_SRGB8,
BC7_RGBA,

RGB8_ETC2,
SRGB8_ETC2,
RGB8_Punchthrough_A1_ETC2,
SRGB8_Punchthrough_A1_ETC2,
RG_EAC_UNorm,
RG_EAC_SNorm,
R_EAC_UNorm,
R_EAC_SNorm,
RGBA_BC7_UNORM_4x4,

Z_UNorm16,
Z_UNorm24,
Z_UNorm32,
S8_UInt_Z24_UNorm,
Z_UN16,
Z_UN24,
Z_F32,
Z_UN24_S_UI8,
};

enum LoadOp : uint8_t {
Expand Down
4 changes: 2 additions & 2 deletions samples/Tiny_Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static void initIGL() {
texture0_ = device_->createTexture(
{
.type = TextureType::TwoD,
.format = igl::TextureFormat::BGRA_UNorm8,
.format = igl::TextureFormat::BGRA_UN8,
.width = texWidth,
.height = texHeight,
.usage = igl::TextureUsageBits_Sampled,
Expand Down Expand Up @@ -257,7 +257,7 @@ static void initIGL() {
texture1_ = device_->createTexture(
{
.type = TextureType::TwoD,
.format = igl::TextureFormat::RGBA_UNorm8,
.format = igl::TextureFormat::RGBA_UN8,
.width = (uint32_t)texWidth,
.height = (uint32_t)texHeight,
.usage = igl::TextureUsageBits_Sampled,
Expand Down
15 changes: 7 additions & 8 deletions samples/Tiny_MeshLarge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ void initIGL() {
textureDummyWhite_ = device_->createTexture(
{
.type = igl::TextureType::TwoD,
.format = igl::TextureFormat::RGBA_UNorm8,
.format = igl::TextureFormat::RGBA_UN8,
.width = 1,
.height = 1,
.usage = igl::TextureUsageBits_Sampled,
Expand Down Expand Up @@ -1033,7 +1033,7 @@ void createShadowMap() {
const uint32_t h = 4096;
const TextureDesc desc = {
.type = TextureType::TwoD,
.format = igl::TextureFormat::Z_UNorm16,
.format = igl::TextureFormat::Z_UN16,
.width = w,
.height = h,
.usage = igl::TextureUsageBits_Attachment | igl::TextureUsageBits_Sampled,
Expand All @@ -1050,7 +1050,7 @@ void createOffscreenFramebuffer() {
const uint32_t h = height_;
TextureDesc descDepth = {
.type = TextureType::TwoD,
.format = igl::TextureFormat::Z_UNorm24,
.format = igl::TextureFormat::Z_UN24,
.width = w,
.height = h,
.usage = igl::TextureUsageBits_Attachment | igl::TextureUsageBits_Sampled,
Expand All @@ -1066,7 +1066,7 @@ void createOffscreenFramebuffer() {

const uint8_t usage =
TextureUsageBits_Attachment | TextureUsageBits_Sampled | TextureUsageBits_Storage;
const TextureFormat format = igl::TextureFormat::RGBA_UNorm8;
const TextureFormat format = igl::TextureFormat::RGBA_UN8;

TextureDesc descColor = {
.type = TextureType::TwoD,
Expand Down Expand Up @@ -1344,7 +1344,7 @@ igl::TextureFormat gli2iglTextureFormat(gli::texture2d::format_type format) {
return igl::TextureFormat::RG_F16;
}
IGL_ASSERT_MSG(false, "Code should NOT be reached");
return igl::TextureFormat::RGBA_UNorm8;
return igl::TextureFormat::RGBA_UN8;
}

LoadedImage loadImage(const char* fileName, int channels) {
Expand Down Expand Up @@ -1622,12 +1622,11 @@ void loadSkyboxTexture() {

igl::TextureFormat formatFromChannels(uint32_t channels) {
if (channels == 1) {
return igl::TextureFormat::R_UNorm8;
return igl::TextureFormat::R_UN8;
}

if (channels == 4) {
return kEnableCompression ? igl::TextureFormat::RGBA_BC7_UNORM_4x4
: igl::TextureFormat::RGBA_UNorm8;
return kEnableCompression ? igl::TextureFormat::BC7_RGBA : igl::TextureFormat::RGBA_UN8;
}

return igl::TextureFormat::Invalid;
Expand Down
49 changes: 21 additions & 28 deletions src/igl/IGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,33 @@ size_t getTextureBytesPerRow(size_t texWidth, TextureFormat texFormat, size_t mi
#define STENCIL(fmt, bpb) PROPERTIES(fmt, bpb, 1, 1, 1, 1, 1, 1, Flags::Stencil)

TextureFormatProperties TextureFormatProperties::fromTextureFormat(TextureFormat format) {

switch (format) {
INVALID(Invalid)
COLOR(R_UNorm8, 1)
COLOR(R_UN8, 1)
COLOR(R_UI16, 2)
COLOR(R_UN16, 2)
COLOR(R_F16, 2)
COLOR(R_UInt16, 2)
COLOR(R_UNorm16, 2)
COLOR(RG_UNorm8, 2)
COLOR(RGBA_UNorm8, 4)
COLOR(BGRA_UNorm8, 4)
COLOR(RGBA_SRGB, 4)
COLOR(BGRA_SRGB, 4)
COLOR(RG_F16, 4)
COLOR(RG_UInt16, 4)
COLOR(RG_UNorm16, 4)
COLOR(RGB10_A2_UNorm_Rev, 4)
COLOR(RGB10_A2_Uint_Rev, 4)
COLOR(BGR10_A2_Unorm, 4)
COLOR(R_F32, 4)
COLOR(RG_UN8, 2)
COLOR(RG_UI16, 4)
COLOR(RG_UN16, 4)
COLOR(RG_F16, 4)
COLOR(RG_F32, 8)
COLOR(RGBA_UN8, 4)
COLOR(RGBA_UI32, 16)
COLOR(RGBA_F16, 8)
COLOR(RGBA_UInt32, 16)
COLOR(RGBA_F32, 16)
COMPRESSED(RGB8_ETC2, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(SRGB8_ETC2, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(RGB8_Punchthrough_A1_ETC2, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(SRGB8_Punchthrough_A1_ETC2, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(RG_EAC_UNorm, 16, 4, 4, 1, 1, 1, 1)
COMPRESSED(RG_EAC_SNorm, 16, 4, 4, 1, 1, 1, 1)
COMPRESSED(R_EAC_UNorm, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(R_EAC_SNorm, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(RGBA_BC7_UNORM_4x4, 16, 4, 4, 1, 1, 1, 1)
DEPTH(Z_UNorm16, 2)
DEPTH(Z_UNorm24, 3)
DEPTH(Z_UNorm32, 4)
DEPTH_STENCIL(S8_UInt_Z24_UNorm, 4)
COLOR(RGBA_SRGB8, 4)
COLOR(BGRA_UN8, 4)
COLOR(BGRA_SRGB8, 4)
COMPRESSED(ETC2_RGB8, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(ETC2_SRGB8, 8, 4, 4, 1, 1, 1, 1)
COMPRESSED(BC7_RGBA, 16, 4, 4, 1, 1, 1, 1)
DEPTH(Z_UN16, 2)
DEPTH(Z_UN24, 3)
DEPTH(Z_F32, 4)
DEPTH_STENCIL(Z_UN24_S_UI8, 4)
}
#if defined(_MSC_VER)
return TextureFormatProperties{};
Expand Down
112 changes: 40 additions & 72 deletions src/igl/vulkan/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,69 +53,53 @@ VkFormat textureFormatToVkFormat(igl::TextureFormat format) {
switch (format) {
case TextureFormat::Invalid:
return VK_FORMAT_UNDEFINED;
case TextureFormat::R_UNorm8:
case TextureFormat::R_UN8:
return VK_FORMAT_R8_UNORM;
case TextureFormat::R_UNorm16:
case TextureFormat::R_UN16:
return VK_FORMAT_R16_UNORM;
case TextureFormat::R_F16:
return VK_FORMAT_R16_SFLOAT;
case TextureFormat::R_UInt16:
case TextureFormat::R_UI16:
return VK_FORMAT_R16_UINT;
case TextureFormat::RG_UNorm8:
case TextureFormat::RG_UN8:
return VK_FORMAT_R8G8_UNORM;
case TextureFormat::RG_UNorm16:
case TextureFormat::RG_UN16:
return VK_FORMAT_R16G16_UNORM;
case TextureFormat::BGRA_UNorm8:
case TextureFormat::BGRA_UN8:
return VK_FORMAT_B8G8R8A8_UNORM;
case TextureFormat::RGBA_UNorm8:
case TextureFormat::RGBA_UN8:
return VK_FORMAT_R8G8B8A8_UNORM;
case TextureFormat::RGBA_SRGB:
case TextureFormat::RGBA_SRGB8:
return VK_FORMAT_R8G8B8A8_SRGB;
case TextureFormat::BGRA_SRGB:
case TextureFormat::BGRA_SRGB8:
return VK_FORMAT_B8G8R8A8_SRGB;
case TextureFormat::RG_F16:
return VK_FORMAT_R16G16_SFLOAT;
case TextureFormat::RG_UInt16:
case TextureFormat::RG_F32:
return VK_FORMAT_R32G32_SFLOAT;
case TextureFormat::RG_UI16:
return VK_FORMAT_R16G16_UINT;
case TextureFormat::RGB10_A2_UNorm_Rev:
return VK_FORMAT_A2R10G10B10_UNORM_PACK32;
case TextureFormat::RGB10_A2_Uint_Rev:
return VK_FORMAT_A2R10G10B10_UINT_PACK32;
case TextureFormat::BGR10_A2_Unorm:
return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case TextureFormat::R_F32:
return VK_FORMAT_R32_SFLOAT;
case TextureFormat::RGBA_F16:
return VK_FORMAT_R16G16B16A16_SFLOAT;
case TextureFormat::RGBA_UInt32:
case TextureFormat::RGBA_UI32:
return VK_FORMAT_R32G32B32A32_UINT;
case TextureFormat::RGBA_F32:
return VK_FORMAT_R32G32B32A32_SFLOAT;
case TextureFormat::RGB8_ETC2:
case TextureFormat::ETC2_RGB8:
return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
case TextureFormat::SRGB8_ETC2:
case TextureFormat::ETC2_SRGB8:
return VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK;
case TextureFormat::RGB8_Punchthrough_A1_ETC2:
return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
case TextureFormat::SRGB8_Punchthrough_A1_ETC2:
return VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK;
case TextureFormat::RG_EAC_UNorm:
return VK_FORMAT_EAC_R11G11_UNORM_BLOCK;
case TextureFormat::RG_EAC_SNorm:
return VK_FORMAT_EAC_R11G11_SNORM_BLOCK;
case TextureFormat::R_EAC_UNorm:
return VK_FORMAT_EAC_R11_UNORM_BLOCK;
case TextureFormat::R_EAC_SNorm:
return VK_FORMAT_EAC_R11_SNORM_BLOCK;
case TextureFormat::RGBA_BC7_UNORM_4x4:
case TextureFormat::BC7_RGBA:
return VK_FORMAT_BC7_UNORM_BLOCK;
case TextureFormat::Z_UNorm16:
case TextureFormat::Z_UN16:
return VK_FORMAT_D16_UNORM;
case TextureFormat::Z_UNorm24:
case TextureFormat::Z_UN24:
return VK_FORMAT_D24_UNORM_S8_UINT;
case TextureFormat::Z_UNorm32:
case TextureFormat::Z_F32:
return VK_FORMAT_D32_SFLOAT;
case TextureFormat::S8_UInt_Z24_UNorm:
case TextureFormat::Z_UN24_S_UI8:
return VK_FORMAT_D24_UNORM_S8_UINT;
default:
IGL_ASSERT_MSG(false, "TextureFormat value not handled: %d", (int)format);
Expand All @@ -131,70 +115,54 @@ igl::TextureFormat vkFormatToTextureFormat(VkFormat format) {
case VK_FORMAT_UNDEFINED:
return TextureFormat::Invalid;
case VK_FORMAT_R8_UNORM:
return TextureFormat::R_UNorm8;
return TextureFormat::R_UN8;
case VK_FORMAT_R16_UNORM:
return TextureFormat::R_UNorm16;
return TextureFormat::R_UN16;
case VK_FORMAT_R16_SFLOAT:
return TextureFormat::R_F16;
case VK_FORMAT_R16_UINT:
return TextureFormat::R_UInt16;
return TextureFormat::R_UI16;
case VK_FORMAT_R8G8_UNORM:
return TextureFormat::RG_UNorm8;
return TextureFormat::RG_UN8;
case VK_FORMAT_B8G8R8A8_UNORM:
return TextureFormat::BGRA_UNorm8;
return TextureFormat::BGRA_UN8;
case VK_FORMAT_R8G8B8A8_UNORM:
return TextureFormat::RGBA_UNorm8;
return TextureFormat::RGBA_UN8;
case VK_FORMAT_R8G8B8A8_SRGB:
return TextureFormat::RGBA_SRGB;
return TextureFormat::RGBA_SRGB8;
case VK_FORMAT_B8G8R8A8_SRGB:
return TextureFormat::BGRA_SRGB;
return TextureFormat::BGRA_SRGB8;
case VK_FORMAT_R16G16_UNORM:
return TextureFormat::RG_UNorm16;
return TextureFormat::RG_UN16;
case VK_FORMAT_R16G16_SFLOAT:
return TextureFormat::RG_F16;
case VK_FORMAT_R32G32_SFLOAT:
return TextureFormat::RG_F32;
case VK_FORMAT_R16G16_UINT:
return TextureFormat::RG_UInt16;
case VK_FORMAT_A2R10G10B10_UNORM_PACK32:
return TextureFormat::RGB10_A2_UNorm_Rev;
case VK_FORMAT_A2R10G10B10_UINT_PACK32:
return TextureFormat::RGB10_A2_Uint_Rev;
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
return TextureFormat::BGR10_A2_Unorm;
return TextureFormat::RG_UI16;
case VK_FORMAT_R32_SFLOAT:
return TextureFormat::R_F32;
case VK_FORMAT_R16G16B16A16_SFLOAT:
return TextureFormat::RGBA_F16;
case VK_FORMAT_R32G32B32A32_UINT:
return TextureFormat::RGBA_UInt32;
return TextureFormat::RGBA_UI32;
case VK_FORMAT_R32G32B32A32_SFLOAT:
return TextureFormat::RGBA_F32;
case VK_FORMAT_ASTC_4x4_SRGB_BLOCK:
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
return TextureFormat::RGB8_ETC2;
return TextureFormat::ETC2_RGB8;
case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
return TextureFormat::SRGB8_ETC2;
case VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK:
return TextureFormat::RGB8_Punchthrough_A1_ETC2;
case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
return TextureFormat::SRGB8_Punchthrough_A1_ETC2;
case VK_FORMAT_EAC_R11G11_UNORM_BLOCK:
return TextureFormat::RG_EAC_UNorm;
case VK_FORMAT_EAC_R11G11_SNORM_BLOCK:
return TextureFormat::RG_EAC_SNorm;
case VK_FORMAT_EAC_R11_UNORM_BLOCK:
return TextureFormat::R_EAC_UNorm;
case VK_FORMAT_EAC_R11_SNORM_BLOCK:
return TextureFormat::R_EAC_SNorm;
return TextureFormat::ETC2_SRGB8;
case VK_FORMAT_D16_UNORM:
return TextureFormat::Z_UNorm16;
return TextureFormat::Z_UN16;
case VK_FORMAT_BC7_UNORM_BLOCK:
return TextureFormat::RGBA_BC7_UNORM_4x4;
return TextureFormat::BC7_RGBA;
case VK_FORMAT_X8_D24_UNORM_PACK32:
return TextureFormat::Z_UNorm24;
return TextureFormat::Z_UN24;
case VK_FORMAT_D24_UNORM_S8_UINT:
return TextureFormat::S8_UInt_Z24_UNorm;
return TextureFormat::Z_UN24_S_UI8;
case VK_FORMAT_D32_SFLOAT:
return TextureFormat::Z_UNorm32;
return TextureFormat::Z_F32;
default:
IGL_ASSERT_MSG(false, "VkFormat value not handled: %d", (int)format);
}
Expand Down
Loading

0 comments on commit 57a566c

Please sign in to comment.