diff options
author | 2023-01-05 15:32:40 +0100 | |
---|---|---|
committer | 2023-01-05 09:32:40 -0500 | |
commit | 812e6094f47bb8d1da5a6b421aa4c724cf2035c0 (patch) | |
tree | 0f5bab2fe9393d1f629e9bf63e76cecca74ec0c9 /3rdparty/bimg/src | |
parent | 4a1b41854bba8fc2567906b88bab8ca81e75d187 (diff) |
Update BGFX, BX and BIMG (#10789)
* Update to bgfx a93a714632b79b5ddbf5c86ac323fa9b76ed3433
Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
Diffstat (limited to '3rdparty/bimg/src')
-rw-r--r-- | 3rdparty/bimg/src/bimg_p.h | 39 | ||||
-rw-r--r-- | 3rdparty/bimg/src/config.h | 4 | ||||
-rw-r--r-- | 3rdparty/bimg/src/image.cpp | 312 | ||||
-rw-r--r-- | 3rdparty/bimg/src/image_cubemap_filter.cpp | 22 | ||||
-rw-r--r-- | 3rdparty/bimg/src/image_decode.cpp | 8 | ||||
-rw-r--r-- | 3rdparty/bimg/src/image_encode.cpp | 116 | ||||
-rw-r--r-- | 3rdparty/bimg/src/image_gnf.cpp | 6 |
7 files changed, 397 insertions, 110 deletions
diff --git a/3rdparty/bimg/src/bimg_p.h b/3rdparty/bimg/src/bimg_p.h index 83a9e28dc25..909d654f848 100644 --- a/3rdparty/bimg/src/bimg_p.h +++ b/3rdparty/bimg/src/bimg_p.h @@ -1,13 +1,48 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bimg/blob/master/LICENSE */ #ifndef BIMG_P_H_HEADER_GUARD #define BIMG_P_H_HEADER_GUARD +#ifndef BX_CONFIG_DEBUG +# error "BX_CONFIG_DEBUG must be defined in build script!" +#endif // BIMG_CONFIG_DEBUG + +#if BX_CONFIG_DEBUG +# define BX_TRACE _BIMG_TRACE +# define BX_WARN _BIMG_WARN +# define BX_ASSERT _BIMG_ASSERT +#endif // BX_CONFIG_DEBUG + +#define BX_ASSERT2 BX_ASSERT + +#define _BIMG_TRACE(_format, ...) \ + BX_MACRO_BLOCK_BEGIN \ + bx::debugPrintf(__FILE__ "(" BX_STRINGIZE(__LINE__) "): BX " _format "\n", ##__VA_ARGS__); \ + BX_MACRO_BLOCK_END + +#define _BIMG_WARN(_condition, _format, ...) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ + { \ + BX_TRACE("WARN " _format, ##__VA_ARGS__); \ + } \ + BX_MACRO_BLOCK_END + +#define _BIMG_ASSERT(_condition, _format, ...) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ + { \ + BX_TRACE("ASSERT " _format, ##__VA_ARGS__); \ + bx::debugBreak(); \ + } \ + BX_MACRO_BLOCK_END + #include <bimg/bimg.h> #include <bx/allocator.h> +#include <bx/debug.h> #include <bx/readerwriter.h> #include <bx/pixelformat.h> #include <bx/endian.h> diff --git a/3rdparty/bimg/src/config.h b/3rdparty/bimg/src/config.h index 4c2beb105c1..8d4d94fe99a 100644 --- a/3rdparty/bimg/src/config.h +++ b/3rdparty/bimg/src/config.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bimg/blob/master/LICENSE */ #ifndef BIMG_CONFIG_H_HEADER_GUARD diff --git a/3rdparty/bimg/src/image.cpp b/3rdparty/bimg/src/image.cpp index 63b0d5f5f0e..63d46254a09 100644 --- a/3rdparty/bimg/src/image.cpp +++ b/3rdparty/bimg/src/image.cpp @@ -1,12 +1,12 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bimg/blob/master/LICENSE */ #include "bimg_p.h" #include <bx/hash.h> -#include <astc-codec/astc-codec.h> +#include <astcenc.h> #include <bx/debug.h> @@ -46,11 +46,19 @@ namespace bimg { 8, 4, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ATCE { 8, 4, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ATCI { 8, 4, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC4x4 + { 6, 5, 4, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC5x4 { 6, 5, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC5x5 + { 4, 6, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC6x5 { 4, 6, 6, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC6x6 { 4, 8, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC8x5 { 3, 8, 6, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC8x6 + { 2, 8, 8, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC8x8 { 3, 10, 5, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x5 + { 2, 10, 6, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x6 + { 2, 10, 8, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x8 + { 1, 10,10, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC10x10 + { 1, 12,10, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC12x10 + { 1, 12,12, 16, 1, 1, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // ASTC12x12 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint8_t(bx::EncodingType::Count) }, // Unknown { 1, 8, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, uint8_t(bx::EncodingType::Unorm) }, // R1 { 8, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 8, uint8_t(bx::EncodingType::Unorm) }, // A8 @@ -96,8 +104,11 @@ namespace bimg { 128, 1, 1, 16, 1, 1, 0, 0, 32, 32, 32, 32, uint8_t(bx::EncodingType::Int ) }, // RGBA32I { 128, 1, 1, 16, 1, 1, 0, 0, 32, 32, 32, 32, uint8_t(bx::EncodingType::Uint ) }, // RGBA32U { 128, 1, 1, 16, 1, 1, 0, 0, 32, 32, 32, 32, uint8_t(bx::EncodingType::Float) }, // RGBA32F + { 16, 1, 1, 2, 1, 1, 0, 0, 5, 6, 5, 0, uint8_t(bx::EncodingType::Unorm) }, // B5G6R5 { 16, 1, 1, 2, 1, 1, 0, 0, 5, 6, 5, 0, uint8_t(bx::EncodingType::Unorm) }, // R5G6B5 + { 16, 1, 1, 2, 1, 1, 0, 0, 4, 4, 4, 4, uint8_t(bx::EncodingType::Unorm) }, // BGRA4 { 16, 1, 1, 2, 1, 1, 0, 0, 4, 4, 4, 4, uint8_t(bx::EncodingType::Unorm) }, // RGBA4 + { 16, 1, 1, 2, 1, 1, 0, 0, 5, 5, 5, 1, uint8_t(bx::EncodingType::Unorm) }, // BGR5A1 { 16, 1, 1, 2, 1, 1, 0, 0, 5, 5, 5, 1, uint8_t(bx::EncodingType::Unorm) }, // RGB5A1 { 32, 1, 1, 4, 1, 1, 0, 0, 10, 10, 10, 2, uint8_t(bx::EncodingType::Unorm) }, // RGB10A2 { 32, 1, 1, 4, 1, 1, 0, 0, 11, 11, 10, 0, uint8_t(bx::EncodingType::Unorm) }, // RG11B10F @@ -136,11 +147,19 @@ namespace bimg "ATCE", // ATCE "ATCI", // ATCI "ASTC4x4", // ASTC4x4 + "ASTC5x4", // ASTC5x4 "ASTC5x5", // ASTC5x5 + "ASTC6x5", // ASTC6x5 "ASTC6x6", // ASTC6x6 "ASTC8x5", // ASTC8x5 "ASTC8x6", // ASTC8x6 + "ASTC8x8", // ASTC8x8 "ASTC10x5", // ASTC10x5 + "ASTC10x6", // ASTC10x6 + "ASTC10x8", // ASTC10x8 + "ASTC10x10", // ASTC10x10 + "ASTC12x10", // ASTC12x10 + "ASTC12x12", // ASTC12x12 "<unknown>", // Unknown "R1", // R1 "A8", // A8 @@ -186,11 +205,14 @@ namespace bimg "RGBA32I", // RGBA32I "RGBA32U", // RGBA32U "RGBA32F", // RGBA32F + "B5G6R5", // B5G6R5 "R5G6B5", // R5G6B5 + "BGRA4", // BGRA4 "RGBA4", // RGBA4 + "BGR5A1", // BGR5A1 "RGB5A1", // RGB5A1 "RGB10A2", // RGB10A2 - "RG11B10F", // RG11B10F + "RG11B10F", // RG11B10F "<unknown>", // UnknownDepth "D16", // D16 "D24", // D24 @@ -1058,11 +1080,19 @@ namespace bimg { NULL, NULL }, // ATCE { NULL, NULL }, // ATCI { NULL, NULL }, // ASTC4x4 + { NULL, NULL }, // ASTC5x4 { NULL, NULL }, // ASTC5x5 + { NULL, NULL }, // ASTC6x5 { NULL, NULL }, // ASTC6x6 { NULL, NULL }, // ASTC8x5 { NULL, NULL }, // ASTC8x6 + { NULL, NULL }, // ASTC8x8 { NULL, NULL }, // ASTC10x5 + { NULL, NULL }, // ASTC10x6 + { NULL, NULL }, // ASTC10x8 + { NULL, NULL }, // ASTC10x10 + { NULL, NULL }, // ASTC12x10 + { NULL, NULL }, // ASTC12x12 { NULL, NULL }, // Unknown { NULL, NULL }, // R1 { bx::packA8, bx::unpackA8 }, // A8 @@ -1108,8 +1138,11 @@ namespace bimg { bx::packRgba32I, bx::unpackRgba32I }, // RGBA32I { bx::packRgba32U, bx::unpackRgba32U }, // RGBA32U { bx::packRgba32F, bx::unpackRgba32F }, // RGBA32F + { bx::packB5G6R5, bx::unpackB5G6R5 }, // B5G6R5 { bx::packR5G6B5, bx::unpackR5G6B5 }, // R5G6B5 + { bx::packBgra4, bx::unpackBgra4 }, // BGRA4 { bx::packRgba4, bx::unpackRgba4 }, // RGBA4 + { bx::packBgr5a1, bx::unpackBgr5a1 }, // BGR5A1 { bx::packRgb5a1, bx::unpackRgb5a1 }, // RGB5A1 { bx::packRgb10A2, bx::unpackRgb10A2 }, // RGB10A2 { bx::packRG11B10F, bx::unpackRG11B10F }, // RG11B10F @@ -1123,7 +1156,7 @@ namespace bimg { bx::packR32F, bx::unpackR32F }, // D32F { bx::packR8, bx::unpackR8 }, // D0S8 }; - BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_packUnpack) ); + BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_packUnpack) ); PackFn getPack(TextureFormat::Enum _format) { @@ -1284,7 +1317,7 @@ namespace bimg bx::MemoryReader reader(_src, _size); uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, bx::ErrorIgnore{}); ImageContainer imageContainer; if (magicT != magic) @@ -3315,20 +3348,28 @@ namespace bimg #define DDS_BC5U BX_MAKEFOURCC('B', 'C', '5', 'U') #define DDS_DX10 BX_MAKEFOURCC('D', 'X', '1', '0') -#define DDS_ETC1 BX_MAKEFOURCC('E', 'T', 'C', '1') -#define DDS_ETC2 BX_MAKEFOURCC('E', 'T', 'C', '2') -#define DDS_ET2A BX_MAKEFOURCC('E', 'T', '2', 'A') -#define DDS_PTC2 BX_MAKEFOURCC('P', 'T', 'C', '2') -#define DDS_PTC4 BX_MAKEFOURCC('P', 'T', 'C', '4') -#define DDS_ATC BX_MAKEFOURCC('A', 'T', 'C', ' ') -#define DDS_ATCE BX_MAKEFOURCC('A', 'T', 'C', 'E') -#define DDS_ATCI BX_MAKEFOURCC('A', 'T', 'C', 'I') -#define DDS_ASTC4x4 BX_MAKEFOURCC('A', 'S', '4', '4') -#define DDS_ASTC5x5 BX_MAKEFOURCC('A', 'S', '5', '5') -#define DDS_ASTC6x6 BX_MAKEFOURCC('A', 'S', '6', '6') -#define DDS_ASTC8x5 BX_MAKEFOURCC('A', 'S', '8', '5') -#define DDS_ASTC8x6 BX_MAKEFOURCC('A', 'S', '8', '6') -#define DDS_ASTC10x5 BX_MAKEFOURCC('A', 'S', ':', '5') +#define DDS_ETC1 BX_MAKEFOURCC('E', 'T', 'C', '1') +#define DDS_ETC2 BX_MAKEFOURCC('E', 'T', 'C', '2') +#define DDS_ET2A BX_MAKEFOURCC('E', 'T', '2', 'A') +#define DDS_PTC2 BX_MAKEFOURCC('P', 'T', 'C', '2') +#define DDS_PTC4 BX_MAKEFOURCC('P', 'T', 'C', '4') +#define DDS_ATC BX_MAKEFOURCC('A', 'T', 'C', ' ') +#define DDS_ATCE BX_MAKEFOURCC('A', 'T', 'C', 'E') +#define DDS_ATCI BX_MAKEFOURCC('A', 'T', 'C', 'I') +#define DDS_ASTC4x4 BX_MAKEFOURCC('A', 'S', '4', '4') +#define DDS_ASTC5x4 BX_MAKEFOURCC('A', 'S', '5', '4') +#define DDS_ASTC5x5 BX_MAKEFOURCC('A', 'S', '5', '5') +#define DDS_ASTC6x5 BX_MAKEFOURCC('A', 'S', '6', '5') +#define DDS_ASTC6x6 BX_MAKEFOURCC('A', 'S', '6', '6') +#define DDS_ASTC8x5 BX_MAKEFOURCC('A', 'S', '8', '5') +#define DDS_ASTC8x6 BX_MAKEFOURCC('A', 'S', '8', '6') +#define DDS_ASTC8x8 BX_MAKEFOURCC('A', 'S', '8', '8') +#define DDS_ASTC10x5 BX_MAKEFOURCC('A', 'S', ':', '5') +#define DDS_ASTC10x6 BX_MAKEFOURCC('A', 'S', ':', '6') +#define DDS_ASTC10x8 BX_MAKEFOURCC('A', 'S', ':', '8') +#define DDS_ASTC10x10 BX_MAKEFOURCC('A', 'S', ':', ':') +#define DDS_ASTC12x10 BX_MAKEFOURCC('A', 'S', '<', ':') +#define DDS_ASTC12x12 BX_MAKEFOURCC('A', 'S', '<', '<') #define DDS_R8G8B8 20 #define DDS_A8R8G8B8 21 @@ -3456,11 +3497,19 @@ namespace bimg { DDS_ATCE, TextureFormat::ATCE, false }, { DDS_ATCI, TextureFormat::ATCI, false }, { DDS_ASTC4x4, TextureFormat::ASTC4x4, false }, + { DDS_ASTC5x4, TextureFormat::ASTC5x4, false }, { DDS_ASTC5x5, TextureFormat::ASTC5x5, false }, + { DDS_ASTC6x5, TextureFormat::ASTC6x5, false }, { DDS_ASTC6x6, TextureFormat::ASTC6x6, false }, { DDS_ASTC8x5, TextureFormat::ASTC8x5, false }, { DDS_ASTC8x6, TextureFormat::ASTC8x6, false }, + { DDS_ASTC8x8, TextureFormat::ASTC8x8, false }, { DDS_ASTC10x5, TextureFormat::ASTC10x5, false }, + { DDS_ASTC10x6, TextureFormat::ASTC10x6, false }, + { DDS_ASTC10x8, TextureFormat::ASTC10x8, false }, + { DDS_ASTC10x10, TextureFormat::ASTC10x10,false }, + { DDS_ASTC12x10, TextureFormat::ASTC12x10,false }, + { DDS_ASTC12x12, TextureFormat::ASTC12x12,false }, { DDS_A16B16G16R16, TextureFormat::RGBA16, false }, { DDS_A16B16G16R16F, TextureFormat::RGBA16F, false }, @@ -3479,8 +3528,11 @@ namespace bimg { DDS_A16B16G16R16, TextureFormat::RGBA16, false }, { DDS_A16B16G16R16F, TextureFormat::RGBA16F, false }, { DDS_A32B32G32R32F, TextureFormat::RGBA32F, false }, + { DDS_R5G6B5, TextureFormat::B5G6R5, false }, { DDS_R5G6B5, TextureFormat::R5G6B5, false }, + { DDS_A4R4G4B4, TextureFormat::BGRA4, false }, { DDS_A4R4G4B4, TextureFormat::RGBA4, false }, + { DDS_A1R5G5B5, TextureFormat::BGR5A1, false }, { DDS_A1R5G5B5, TextureFormat::RGB5A1, false }, { DDS_A2B10G10R10, TextureFormat::RGB10A2, false }, }; @@ -3519,8 +3571,11 @@ namespace bimg { DDS_FORMAT_R16G16B16A16_FLOAT, TextureFormat::RGBA16F, false }, { DDS_FORMAT_R32G32B32A32_UINT, TextureFormat::RGBA32U, false }, { DDS_FORMAT_R32G32B32A32_FLOAT, TextureFormat::RGBA32F, false }, + { DDS_FORMAT_B5G6R5_UNORM, TextureFormat::B5G6R5, false }, { DDS_FORMAT_B5G6R5_UNORM, TextureFormat::R5G6B5, false }, + { DDS_FORMAT_B4G4R4A4_UNORM, TextureFormat::BGRA4, false }, { DDS_FORMAT_B4G4R4A4_UNORM, TextureFormat::RGBA4, false }, + { DDS_FORMAT_B5G5R5A1_UNORM, TextureFormat::BGR5A1, false }, { DDS_FORMAT_B5G5R5A1_UNORM, TextureFormat::RGB5A1, false }, { DDS_FORMAT_R10G10B10A2_UNORM, TextureFormat::RGB10A2, false }, { DDS_FORMAT_R11G11B10_FLOAT, TextureFormat::RG11B10F, false }, @@ -3539,8 +3594,11 @@ namespace bimg { 8, DDPF_LUMINANCE, { 0x000000ff, 0x00000000, 0x00000000, 0x00000000 }, TextureFormat::R8 }, { 16, DDPF_BUMPDUDV, { 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000 }, TextureFormat::RG8S }, { 16, DDPF_RGB, { 0x0000ffff, 0x00000000, 0x00000000, 0x00000000 }, TextureFormat::R16U }, + { 16, DDPF_RGB|DDPF_ALPHAPIXELS, { 0x0000000f, 0x000000f0, 0x00000f00, 0x0000f000 }, TextureFormat::BGRA4 }, { 16, DDPF_RGB|DDPF_ALPHAPIXELS, { 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000 }, TextureFormat::RGBA4 }, + { 16, DDPF_RGB, { 0x0000001f, 0x000007e0, 0x0000f800, 0x00000000 }, TextureFormat::B5G6R5 }, { 16, DDPF_RGB, { 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000 }, TextureFormat::R5G6B5 }, + { 16, DDPF_RGB, { 0x0000001f, 0x000003e0, 0x00007c00, 0x00008000 }, TextureFormat::BGR5A1 }, { 16, DDPF_RGB, { 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000 }, TextureFormat::RGB5A1 }, { 24, DDPF_RGB, { 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000 }, TextureFormat::RGB8 }, { 24, DDPF_RGB, { 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000 }, TextureFormat::RGB8 }, @@ -3648,6 +3706,8 @@ namespace bimg total += bx::read(_reader, miscFlags2, _err); } + BX_UNUSED(total); + if (!_err->isOk() ) { return false; @@ -3792,17 +3852,33 @@ namespace bimg #define KTX_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 #define KTX_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE #define KTX_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 +#define KTX_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 #define KTX_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 +#define KTX_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 #define KTX_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 #define KTX_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 #define KTX_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 +#define KTX_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 #define KTX_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 +#define KTX_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#define KTX_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#define KTX_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#define KTX_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#define KTX_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 #define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC +#define KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD #define KTX_A8 0x803C #define KTX_R8 0x8229 @@ -3916,11 +3992,19 @@ namespace bimg { KTX_ATC_RGBA_EXPLICIT_ALPHA_AMD, KTX_ZERO, KTX_ATC_RGBA_EXPLICIT_ALPHA_AMD, KTX_ZERO, }, // ATCE { KTX_ATC_RGBA_INTERPOLATED_ALPHA_AMD, KTX_ZERO, KTX_ATC_RGBA_INTERPOLATED_ALPHA_AMD, KTX_ZERO, }, // ATCI { KTX_COMPRESSED_RGBA_ASTC_4x4_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, KTX_COMPRESSED_RGBA_ASTC_4x4_KHR, KTX_ZERO, }, // ASTC4x4 + { KTX_COMPRESSED_RGBA_ASTC_5x4_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, KTX_COMPRESSED_RGBA_ASTC_5x4_KHR, KTX_ZERO, }, // ASTC5x4 { KTX_COMPRESSED_RGBA_ASTC_5x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, KTX_COMPRESSED_RGBA_ASTC_5x5_KHR, KTX_ZERO, }, // ASTC5x5 + { KTX_COMPRESSED_RGBA_ASTC_6x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, KTX_COMPRESSED_RGBA_ASTC_6x5_KHR, KTX_ZERO, }, // ASTC6x5 { KTX_COMPRESSED_RGBA_ASTC_6x6_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, KTX_COMPRESSED_RGBA_ASTC_6x6_KHR, KTX_ZERO, }, // ASTC6x6 { KTX_COMPRESSED_RGBA_ASTC_8x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, KTX_COMPRESSED_RGBA_ASTC_8x5_KHR, KTX_ZERO, }, // ASTC8x5 { KTX_COMPRESSED_RGBA_ASTC_8x6_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, KTX_COMPRESSED_RGBA_ASTC_8x6_KHR, KTX_ZERO, }, // ASTC8x6 + { KTX_COMPRESSED_RGBA_ASTC_8x8_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, KTX_COMPRESSED_RGBA_ASTC_8x8_KHR, KTX_ZERO, }, // ASTC8x8 { KTX_COMPRESSED_RGBA_ASTC_10x5_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, KTX_COMPRESSED_RGBA_ASTC_10x5_KHR, KTX_ZERO, }, // ASTC10x5 + { KTX_COMPRESSED_RGBA_ASTC_10x6_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, KTX_COMPRESSED_RGBA_ASTC_10x6_KHR, KTX_ZERO, }, // ASTC10x6 + { KTX_COMPRESSED_RGBA_ASTC_10x8_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, KTX_COMPRESSED_RGBA_ASTC_10x8_KHR, KTX_ZERO, }, // ASTC10x8 + { KTX_COMPRESSED_RGBA_ASTC_10x10_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, KTX_COMPRESSED_RGBA_ASTC_10x10_KHR, KTX_ZERO, }, // ASTC10x10 + { KTX_COMPRESSED_RGBA_ASTC_12x10_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, KTX_COMPRESSED_RGBA_ASTC_12x10_KHR, KTX_ZERO, }, // ASTC12x10 + { KTX_COMPRESSED_RGBA_ASTC_12x12_KHR, KTX_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, KTX_COMPRESSED_RGBA_ASTC_12x12_KHR, KTX_ZERO, }, // ASTC12x12 { KTX_ZERO, KTX_ZERO, KTX_ZERO, KTX_ZERO, }, // Unknown { KTX_ZERO, KTX_ZERO, KTX_ZERO, KTX_ZERO, }, // R1 { KTX_ALPHA, KTX_ZERO, KTX_ALPHA, KTX_UNSIGNED_BYTE, }, // A8 @@ -3966,8 +4050,11 @@ namespace bimg { KTX_RGBA32I, KTX_ZERO, KTX_RGBA, KTX_INT, }, // RGBA32I { KTX_RGBA32UI, KTX_ZERO, KTX_RGBA, KTX_UNSIGNED_INT, }, // RGBA32U { KTX_RGBA32F, KTX_ZERO, KTX_RGBA, KTX_FLOAT, }, // RGBA32F + { KTX_RGB565, KTX_ZERO, KTX_RGB, KTX_UNSIGNED_SHORT_5_6_5, }, // B5G6R5 { KTX_RGB565, KTX_ZERO, KTX_RGB, KTX_UNSIGNED_SHORT_5_6_5, }, // R5G6B5 + { KTX_RGBA4, KTX_ZERO, KTX_BGRA, KTX_UNSIGNED_SHORT_4_4_4_4, }, // BGRA4 { KTX_RGBA4, KTX_ZERO, KTX_RGBA, KTX_UNSIGNED_SHORT_4_4_4_4, }, // RGBA4 + { KTX_RGB5_A1, KTX_ZERO, KTX_BGRA, KTX_UNSIGNED_SHORT_5_5_5_1, }, // BGR5A1 { KTX_RGB5_A1, KTX_ZERO, KTX_RGBA, KTX_UNSIGNED_SHORT_5_5_5_1, }, // RGB5A1 { KTX_RGB10_A2, KTX_ZERO, KTX_RGBA, KTX_UNSIGNED_INT_2_10_10_10_REV, }, // RGB10A2 { KTX_R11F_G11F_B10F, KTX_ZERO, KTX_RGB, KTX_UNSIGNED_INT_10F_11F_11F_REV, }, // RG11B10F @@ -3994,7 +4081,7 @@ namespace bimg BX_ERROR_SCOPE(_err); uint8_t identifier[8]; - bx::read(_reader, identifier); + bx::read(_reader, identifier, _err); if (identifier[1] != '1' && identifier[2] != '1') @@ -4004,45 +4091,50 @@ namespace bimg } uint32_t endianness; - bx::read(_reader, endianness); + bx::read(_reader, endianness, _err); bool fromLittleEndian = 0x04030201 == endianness; uint32_t glType; - bx::readHE(_reader, glType, fromLittleEndian); + bx::readHE(_reader, glType, fromLittleEndian, _err); uint32_t glTypeSize; - bx::readHE(_reader, glTypeSize, fromLittleEndian); + bx::readHE(_reader, glTypeSize, fromLittleEndian, _err); uint32_t glFormat; - bx::readHE(_reader, glFormat, fromLittleEndian); + bx::readHE(_reader, glFormat, fromLittleEndian, _err); uint32_t glInternalFormat; - bx::readHE(_reader, glInternalFormat, fromLittleEndian); + bx::readHE(_reader, glInternalFormat, fromLittleEndian, _err); uint32_t glBaseInternalFormat; - bx::readHE(_reader, glBaseInternalFormat, fromLittleEndian); + bx::readHE(_reader, glBaseInternalFormat, fromLittleEndian, _err); uint32_t width; - bx::readHE(_reader, width, fromLittleEndian); + bx::readHE(_reader, width, fromLittleEndian, _err); uint32_t height; - bx::readHE(_reader, height, fromLittleEndian); + bx::readHE(_reader, height, fromLittleEndian, _err); uint32_t depth; - bx::readHE(_reader, depth, fromLittleEndian); + bx::readHE(_reader, depth, fromLittleEndian, _err); uint32_t numberOfArrayElements; - bx::readHE(_reader, numberOfArrayElements, fromLittleEndian); + bx::readHE(_reader, numberOfArrayElements, fromLittleEndian, _err); uint32_t numFaces; - bx::readHE(_reader, numFaces, fromLittleEndian); + bx::readHE(_reader, numFaces, fromLittleEndian, _err); uint32_t numMips; - bx::readHE(_reader, numMips, fromLittleEndian); + bx::readHE(_reader, numMips, fromLittleEndian, _err); uint32_t metaDataSize; - bx::readHE(_reader, metaDataSize, fromLittleEndian); + bx::readHE(_reader, metaDataSize, fromLittleEndian, _err); + + if (!_err->isOk() ) + { + return false; + } // skip meta garbage... int64_t offset = bx::skip(_reader, metaDataSize); @@ -4141,8 +4233,11 @@ namespace bimg #define PVR3_BGRA8 PVR3_MAKE8CC('b', 'g', 'r', 'a', 8, 8, 8, 8) #define PVR3_RGBA16 PVR3_MAKE8CC('r', 'g', 'b', 'a', 16, 16, 16, 16) #define PVR3_RGBA32 PVR3_MAKE8CC('r', 'g', 'b', 'a', 32, 32, 32, 32) +#define PVR3_BGR565 PVR3_MAKE8CC('b', 'g', 'r', 0, 5, 6, 5, 0) #define PVR3_RGB565 PVR3_MAKE8CC('r', 'g', 'b', 0, 5, 6, 5, 0) +#define PVR3_BGRA4 PVR3_MAKE8CC('b', 'g', 'r', 'a', 4, 4, 4, 4) #define PVR3_RGBA4 PVR3_MAKE8CC('r', 'g', 'b', 'a', 4, 4, 4, 4) +#define PVR3_BGRA51 PVR3_MAKE8CC('b', 'g', 'r', 'a', 5, 5, 5, 1) #define PVR3_RGBA51 PVR3_MAKE8CC('r', 'g', 'b', 'a', 5, 5, 5, 1) #define PVR3_RGB10A2 PVR3_MAKE8CC('r', 'g', 'b', 'a', 10, 10, 10, 2) @@ -4187,8 +4282,11 @@ namespace bimg { PVR3_RGBA16, PVR3_CHANNEL_TYPE_FLOAT, TextureFormat::RGBA16F }, { PVR3_RGBA32, PVR3_CHANNEL_TYPE_ANY, TextureFormat::RGBA32U }, { PVR3_RGBA32, PVR3_CHANNEL_TYPE_FLOAT, TextureFormat::RGBA32F }, + { PVR3_RGB565, PVR3_CHANNEL_TYPE_ANY, TextureFormat::B5G6R5 }, { PVR3_RGB565, PVR3_CHANNEL_TYPE_ANY, TextureFormat::R5G6B5 }, + { PVR3_BGRA4, PVR3_CHANNEL_TYPE_ANY, TextureFormat::BGRA4 }, { PVR3_RGBA4, PVR3_CHANNEL_TYPE_ANY, TextureFormat::RGBA4 }, + { PVR3_BGRA51, PVR3_CHANNEL_TYPE_ANY, TextureFormat::BGR5A1 }, { PVR3_RGBA51, PVR3_CHANNEL_TYPE_ANY, TextureFormat::RGB5A1 }, { PVR3_RGB10A2, PVR3_CHANNEL_TYPE_ANY, TextureFormat::RGB10A2 }, }; @@ -4198,37 +4296,42 @@ namespace bimg BX_ERROR_SCOPE(_err); uint32_t flags; - bx::read(_reader, flags); + bx::read(_reader, flags, _err); uint64_t pixelFormat; - bx::read(_reader, pixelFormat); + bx::read(_reader, pixelFormat, _err); uint32_t colorSpace; - bx::read(_reader, colorSpace); // 0 - linearRGB, 1 - sRGB + bx::read(_reader, colorSpace, _err); // 0 - linearRGB, 1 - sRGB uint32_t channelType; - bx::read(_reader, channelType); + bx::read(_reader, channelType, _err); uint32_t height; - bx::read(_reader, height); + bx::read(_reader, height, _err); uint32_t width; - bx::read(_reader, width); + bx::read(_reader, width, _err); uint32_t depth; - bx::read(_reader, depth); + bx::read(_reader, depth, _err); uint32_t numSurfaces; - bx::read(_reader, numSurfaces); + bx::read(_reader, numSurfaces, _err); uint32_t numFaces; - bx::read(_reader, numFaces); + bx::read(_reader, numFaces, _err); uint32_t numMips; - bx::read(_reader, numMips); + bx::read(_reader, numMips, _err); uint32_t metaDataSize; - bx::read(_reader, metaDataSize); + bx::read(_reader, metaDataSize, _err); + + if (!_err->isOk() ) + { + return false; + } // skip meta garbage... int64_t offset = bx::skip(_reader, metaDataSize); @@ -4298,7 +4401,7 @@ namespace bimg else if (BIMG_CHUNK_MAGIC_TEX == magic) { TextureCreate tc; - bx::read(_reader, tc); + bx::read(_reader, tc, _err); _imageContainer.m_format = tc.m_format; _imageContainer.m_orientation = Orientation::R0; @@ -4734,11 +4837,19 @@ namespace bimg break; case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x4: case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x5: case TextureFormat::ASTC6x6: case TextureFormat::ASTC8x5: case TextureFormat::ASTC8x6: + case TextureFormat::ASTC8x8: case TextureFormat::ASTC10x5: + case TextureFormat::ASTC10x6: + case TextureFormat::ASTC10x8: + case TextureFormat::ASTC10x10: + case TextureFormat::ASTC12x10: + case TextureFormat::ASTC12x12: imageDecodeToRgba8(_allocator, _dst, _src, _width, _height, _dstPitch, _srcFormat); imageSwizzleBgra8(_dst, _dstPitch, _width, _height, _dst, _dstPitch); break; @@ -4792,31 +4903,89 @@ namespace bimg break; case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x4: case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x5: case TextureFormat::ASTC6x6: case TextureFormat::ASTC8x5: case TextureFormat::ASTC8x6: + case TextureFormat::ASTC8x8: case TextureFormat::ASTC10x5: + case TextureFormat::ASTC10x6: + case TextureFormat::ASTC10x8: + case TextureFormat::ASTC10x10: + case TextureFormat::ASTC12x10: + case TextureFormat::ASTC12x12: if (BX_ENABLED(BIMG_DECODE_ASTC) ) { - if (!astc_codec::ASTCDecompressToRGBA( - (const uint8_t*)_src - , imageGetSize(NULL, uint16_t(_width), uint16_t(_height), 0, false, false, 1, _srcFormat) - , _width - , _height - , TextureFormat::ASTC4x4 == _srcFormat ? astc_codec::FootprintType::k4x4 - : TextureFormat::ASTC5x5 == _srcFormat ? astc_codec::FootprintType::k5x5 - : TextureFormat::ASTC6x6 == _srcFormat ? astc_codec::FootprintType::k6x6 - : TextureFormat::ASTC8x5 == _srcFormat ? astc_codec::FootprintType::k8x5 - : TextureFormat::ASTC8x6 == _srcFormat ? astc_codec::FootprintType::k8x6 - : astc_codec::FootprintType::k10x5 - , (uint8_t*)_dst - , _width*_height*4 - , _dstPitch - ) ) - { - imageCheckerboard(_dst, _width, _height, 16, UINT32_C(0xff000000), UINT32_C(0xffffff00) ); - } + const bimg::ImageBlockInfo& astcBlockInfo = bimg::getBlockInfo(_srcFormat); + + astcenc_config config{}; + + astcenc_error status = astcenc_config_init( + ASTCENC_PRF_LDR + , astcBlockInfo.blockWidth + , astcBlockInfo.blockHeight + , 1 + , ASTCENC_PRE_MEDIUM + , ASTCENC_FLG_DECOMPRESS_ONLY + , &config + ); + + if (status != ASTCENC_SUCCESS) + { + BX_TRACE("astc error in config init %s", astcenc_get_error_string(status)); + imageCheckerboard(_dst, _width, _height, 16, UINT32_C(0xff000000), UINT32_C(0xffffff00) ); + break; + } + + astcenc_context* context; + status = astcenc_context_alloc(&config, 1, &context); + + if (status != ASTCENC_SUCCESS) + { + BX_TRACE("astc error in context alloc %s", astcenc_get_error_string(status)); + imageCheckerboard(_dst, _width, _height, 16, UINT32_C(0xff000000), UINT32_C(0xffffff00) ); + break; + } + + //Put image data into an astcenc_image + astcenc_image image{}; + image.dim_x = _width; + image.dim_y = _height; + image.dim_z = 1; + image.data_type = ASTCENC_TYPE_U8; + image.data = &_dst; + + const uint32_t size = imageGetSize(NULL, uint16_t(_width), uint16_t(_height), 0, false, false, 1, _srcFormat); + + static const astcenc_swizzle swizzle + { //0123/rgba swizzle corresponds to ASTC_RGBA + ASTCENC_SWZ_R, + ASTCENC_SWZ_G, + ASTCENC_SWZ_B, + ASTCENC_SWZ_A, + }; + + status = astcenc_decompress_image( + context + , (const uint8_t*)_src + , size + , &image + , &swizzle + , 0 + ); + + if (status != ASTCENC_SUCCESS) + { + BX_TRACE("astc error in compress image %s", astcenc_get_error_string(status)); + imageCheckerboard(_dst, _width, _height, 16, UINT32_C(0xff000000), UINT32_C(0xffffff00) ); + + astcenc_context_free(context); + break; + } + + astcenc_context_free(context); } else { @@ -5039,7 +5208,7 @@ namespace bimg if (_imageContainer.m_ktx) { - const uint32_t size = mipSize * ((_imageContainer.m_numLayers<=1 && _imageContainer.m_cubeMap) ? 1 : numSides); + const uint32_t size = mipSize * numSides; uint32_t imageSize = bx::toHostEndian(*(const uint32_t*)&data[offset], _imageContainer.m_ktxLE); BX_ASSERT(size == imageSize, "KTX: Image size mismatch %d (expected %d).", size, imageSize); BX_UNUSED(size, imageSize); @@ -5471,7 +5640,7 @@ namespace bimg return total; } - static int32_t imageWriteDdsHeader(bx::WriterI* _writer, TextureFormat::Enum _format, bool _cubeMap, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, bx::Error* _err) + static int32_t imageWriteDdsHeader(bx::WriterI* _writer, TextureFormat::Enum _format, bool _cubeMap, uint32_t _width, uint32_t _height, uint32_t _depth, uint8_t _numMips, uint32_t _numLayers, bx::Error* _err) { BX_ERROR_SCOPE(_err); @@ -5548,7 +5717,6 @@ namespace bimg total += bx::write(_writer, pitchOrLinearSize, _err); total += bx::write(_writer, _depth, _err); total += bx::write(_writer, uint32_t(_numMips), _err); - total += bx::writeRep(_writer, 0, 44, _err); // reserved1 if (UINT32_MAX != ddspf) @@ -5586,7 +5754,8 @@ namespace bimg 0, 0, }; - total += bx::write(_writer, caps, sizeof(caps) ); + + total += bx::write(_writer, caps, sizeof(caps), _err); total += bx::writeRep(_writer, 0, 4, _err); // reserved2 @@ -5598,10 +5767,10 @@ namespace bimg if (UINT32_MAX != dxgiFormat) { - total += bx::write(_writer, dxgiFormat); + total += bx::write(_writer, dxgiFormat, _err); total += bx::write(_writer, uint32_t(1 < _depth ? DDS_DX10_DIMENSION_TEXTURE3D : DDS_DX10_DIMENSION_TEXTURE2D), _err); // dims total += bx::write(_writer, uint32_t(_cubeMap ? DDS_DX10_MISC_TEXTURECUBE : 0), _err); // miscFlags - total += bx::write(_writer, uint32_t(1), _err); // arraySize + total += bx::write(_writer, uint32_t(_numLayers), _err); // arraySize total += bx::write(_writer, uint32_t(0), _err); // miscFlags2 BX_WARN(total-headerStart == DDS_HEADER_SIZE+20 @@ -5627,6 +5796,7 @@ namespace bimg , _imageContainer.m_height , _imageContainer.m_depth , _imageContainer.m_numMips + , _imageContainer.m_numLayers , _err ); @@ -5635,7 +5805,7 @@ namespace bimg return total; } - for (uint8_t side = 0, numSides = _imageContainer.m_cubeMap ? 6 : 1; side < numSides && _err->isOk(); ++side) + for (uint8_t side = 0, numSides = _imageContainer.m_numLayers * (_imageContainer.m_cubeMap ? 6 : 1); side < numSides && _err->isOk(); ++side) { for (uint8_t lod = 0, num = _imageContainer.m_numMips; lod < num && _err->isOk(); ++lod) { diff --git a/3rdparty/bimg/src/image_cubemap_filter.cpp b/3rdparty/bimg/src/image_cubemap_filter.cpp index fcc36fc8f6e..99338998238 100644 --- a/3rdparty/bimg/src/image_cubemap_filter.cpp +++ b/3rdparty/bimg/src/image_cubemap_filter.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bimg/blob/master/LICENSE */ #include "bimg_p.h" @@ -430,10 +430,10 @@ namespace bimg { Aabb() { - m_min[0] = bx::kFloatMax; - m_min[1] = bx::kFloatMax; - m_max[0] = -bx::kFloatMax; - m_max[1] = -bx::kFloatMax; + m_min[0] = bx::max<float>(); + m_min[1] = bx::max<float>(); + m_max[0] = bx::min<float>(); + m_max[1] = bx::min<float>(); } void add(float _x, float _y) @@ -455,10 +455,10 @@ namespace bimg bool isEmpty() const { // Has to have at least two points added so that no value is equal to initial state. - return ( (m_min[0] == bx::kFloatMax) - || (m_min[1] == bx::kFloatMax) - || (m_max[0] == -bx::kFloatMax) - || (m_max[1] == -bx::kFloatMax) + return ( (m_min[0] == bx::max<float>() ) + || (m_min[1] == bx::max<float>() ) + || (m_max[0] == bx::min<float>() ) + || (m_max[1] == bx::min<float>() ) ); } @@ -896,7 +896,7 @@ namespace bimg if (0.0f < totalWeight) { - // Optimized Reversible Tonemapper for Resovle + // Optimized Reversible Tonemapper for Resolve // https://web.archive.org/web/20180717182019/https://gpuopen.com/optimized-reversible-tonemapper-for-resolve/ // Average, then reverse the tonemapper // diff --git a/3rdparty/bimg/src/image_decode.cpp b/3rdparty/bimg/src/image_decode.cpp index d7213aef6fd..dd391e5f8d1 100644 --- a/3rdparty/bimg/src/image_decode.cpp +++ b/3rdparty/bimg/src/image_decode.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bimg/blob/master/LICENSE */ #include "bimg_p.h" @@ -491,7 +491,6 @@ namespace bimg if (UINT8_MAX != idxR) { const bool asFloat = exrHeader.pixel_types[idxR] == TINYEXR_PIXELTYPE_FLOAT; - uint32_t srcBpp = 32; uint32_t dstBpp = asFloat ? 32 : 16; format = asFloat ? TextureFormat::R32F : TextureFormat::R16F; uint32_t stepR = 1; @@ -501,7 +500,6 @@ namespace bimg if (UINT8_MAX != idxG) { - srcBpp += 32; dstBpp = asFloat ? 64 : 32; format = asFloat ? TextureFormat::RG32F : TextureFormat::RG16F; stepG = 1; @@ -509,7 +507,6 @@ namespace bimg if (UINT8_MAX != idxB) { - srcBpp += 32; dstBpp = asFloat ? 128 : 64; format = asFloat ? TextureFormat::RGBA32F : TextureFormat::RGBA16F; stepB = 1; @@ -517,7 +514,6 @@ namespace bimg if (UINT8_MAX != idxA) { - srcBpp += 32; dstBpp = asFloat ? 128 : 64; format = asFloat ? TextureFormat::RGBA32F : TextureFormat::RGBA16F; stepA = 1; diff --git a/3rdparty/bimg/src/image_encode.cpp b/3rdparty/bimg/src/image_encode.cpp index 47f5f68e016..e006940a3a8 100644 --- a/3rdparty/bimg/src/image_encode.cpp +++ b/3rdparty/bimg/src/image_encode.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bimg/blob/master/LICENSE */ #include <bimg/encode.h> @@ -12,7 +12,7 @@ #include <nvtt/nvtt.h> #include <pvrtc/PvrTcEncoder.h> #include <edtaa3/edtaa3func.h> -#include <astc/astc_lib.h> +#include <astcenc.h> BX_PRAGMA_DIAGNOSTIC_PUSH(); BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4100) // warning C4100: 'alloc_context': unreferenced formal parameter @@ -41,18 +41,18 @@ namespace bimg }; BX_STATIC_ASSERT(Quality::Count == BX_COUNTOF(s_squishQuality) ); - static const ASTC_COMPRESS_MODE s_astcQuality[] = + static const float s_astcQuality[] = { // Standard - ASTC_COMPRESS_MEDIUM, // Default - ASTC_COMPRESS_THOROUGH, // Highest - ASTC_COMPRESS_FAST, // Fastest + ASTCENC_PRE_MEDIUM, // Default + ASTCENC_PRE_THOROUGH, // Highest + ASTCENC_PRE_FAST, // Fastest // Normal map - ASTC_COMPRESS_MEDIUM, // Default - ASTC_COMPRESS_THOROUGH, // Highest - ASTC_COMPRESS_FAST, // Fastest + ASTCENC_PRE_MEDIUM, // Default + ASTCENC_PRE_THOROUGH, // Highest + ASTCENC_PRE_FAST, // Fastest }; - BX_STATIC_ASSERT(Quality::Count == BX_COUNTOF(s_astcQuality)); + BX_STATIC_ASSERT(Quality::Count == BX_COUNTOF(s_astcQuality) ); void imageEncodeFromRgba8(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, uint32_t _depth, TextureFormat::Enum _format, Quality::Enum _quality, bx::Error* _err) { @@ -142,25 +142,103 @@ namespace bimg break; case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x4: case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x5: case TextureFormat::ASTC6x6: case TextureFormat::ASTC8x5: case TextureFormat::ASTC8x6: + case TextureFormat::ASTC8x8: case TextureFormat::ASTC10x5: + case TextureFormat::ASTC10x6: + case TextureFormat::ASTC10x8: + case TextureFormat::ASTC10x10: + case TextureFormat::ASTC12x10: + case TextureFormat::ASTC12x12: { const bimg::ImageBlockInfo& astcBlockInfo = bimg::getBlockInfo(_format); - ASTC_COMPRESS_MODE compress_mode = s_astcQuality[_quality]; - ASTC_DECODE_MODE decode_mode = ASTC_DECODE_LDR_LINEAR; + astcenc_config config{}; + + uint32_t astcFlags = ASTCENC_FLG_SELF_DECOMPRESS_ONLY; + + if (Quality::NormalMapDefault <= _quality) + { + astcFlags |= ASTCENC_FLG_MAP_NORMAL; + } + + astcenc_error status = astcenc_config_init( + ASTCENC_PRF_LDR + , astcBlockInfo.blockWidth + , astcBlockInfo.blockHeight + , 1 + , s_astcQuality[_quality] + , astcFlags + , &config + ); + + if (status != ASTCENC_SUCCESS) + { + BX_TRACE("astc error in config init %s", astcenc_get_error_string(status) ); + BX_ERROR_SET(_err, BIMG_ERROR, "Unable to initialize astc config!"); + break; + } + + astcenc_context* context; + status = astcenc_context_alloc(&config, 1, &context); + + if (status != ASTCENC_SUCCESS) + { + BX_TRACE("astc error in context alloc %s", astcenc_get_error_string(status) ); + BX_ERROR_SET(_err, BIMG_ERROR, "Unable to alloc astc context!"); + break; + } + + astcenc_image image{}; + image.dim_x = _width; + image.dim_y = _height; + image.dim_z = 1; + image.data_type = ASTCENC_TYPE_U8; + image.data = (void**)&src; + + const size_t blockCountX = (_width + astcBlockInfo.blockWidth - 1) / astcBlockInfo.blockWidth; + const size_t blockCountY = (_height + astcBlockInfo.blockHeight - 1) / astcBlockInfo.blockHeight; + const size_t compLen = blockCountX * blockCountY * 16; if (Quality::NormalMapDefault <= _quality) { - astc_compress(_width, _height, src, ASTC_ENC_NORMAL_RA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + static const astcenc_swizzle swizzle + { //0001/rrrg swizzle corresponds to ASTC_ENC_NORMAL_RA + ASTCENC_SWZ_R, + ASTCENC_SWZ_R, + ASTCENC_SWZ_R, + ASTCENC_SWZ_G, + }; + + status = astcenc_compress_image(context, &image, &swizzle, dst, compLen, 0); } else { - astc_compress(_width, _height, src, ASTC_RGBA, srcPitch, astcBlockInfo.blockWidth, astcBlockInfo.blockHeight, compress_mode, decode_mode, dst); + static const astcenc_swizzle swizzle + { //0123/rgba swizzle corresponds to ASTC_RGBA + ASTCENC_SWZ_R, + ASTCENC_SWZ_G, + ASTCENC_SWZ_B, + ASTCENC_SWZ_A, + }; + + status = astcenc_compress_image(context, &image, &swizzle, dst, compLen, 0); } + + if (status != ASTCENC_SUCCESS) + { + BX_TRACE("astc error in compress image %s", astcenc_get_error_string(status) ); + BX_ERROR_SET(_err, BIMG_ERROR, "Unable to compress astc image!"); + astcenc_context_free(context); + break; + } + + astcenc_context_free(context); } break; @@ -252,11 +330,19 @@ namespace bimg case TextureFormat::PTC14: case TextureFormat::PTC14A: case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x4: case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x5: case TextureFormat::ASTC6x6: case TextureFormat::ASTC8x5: case TextureFormat::ASTC8x6: + case TextureFormat::ASTC8x8: case TextureFormat::ASTC10x5: + case TextureFormat::ASTC10x6: + case TextureFormat::ASTC10x8: + case TextureFormat::ASTC10x10: + case TextureFormat::ASTC12x10: + case TextureFormat::ASTC12x12: { uint8_t* temp = (uint8_t*)BX_ALLOC(_allocator, _width*_height*_depth*4); imageDecodeToRgba8(_allocator, temp, _src, _width, _height, _width*4, _srcFormat); diff --git a/3rdparty/bimg/src/image_gnf.cpp b/3rdparty/bimg/src/image_gnf.cpp index 6d346192f59..7d7f0aa190e 100644 --- a/3rdparty/bimg/src/image_gnf.cpp +++ b/3rdparty/bimg/src/image_gnf.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bimg#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bimg/blob/master/LICENSE */ #include "bimg_p.h" @@ -21,7 +21,7 @@ namespace bimg bx::MemoryReader reader(_src, _size); uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, bx::ErrorIgnore{}); ImageContainer imageContainer; if (BIMG_CHUNK_MAGIC_GNF != magic |