Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETC2 pixel format cleanup #1044

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## Updates

### 10-May-2024

A minor breaking change regarding ETC2/EAC pixel formats:

- `SG_PIXELFORMAT_ETC2_RG11` has been renamed to `SG_PIXELFORMAT_EAC_RG11`
- `SG_PIXELFORMAT_ETC2_RG11SN` has been renamed to `SG_PIXELFORMAT_EAC_RG11SN`
- the pixel formats `SG_PIXELFORMAT_ETC2_R11` and `SG_PIXELFORMAT_ETC2_R11SN` have been added
- fixed a pixel format mapping bug in WebGPU (the EAC RG11 formats were actually mapped to R11)

See ticket https://github.com/floooh/sokol/issues/1041, and PR https://github.com/floooh/sokol/pull/1044 for details.

### 09-May-2024

The 'storage buffer update'. sokol_gfx.h now has (readonly) storage buffer support, providing
Expand Down
74 changes: 52 additions & 22 deletions sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -1796,8 +1796,10 @@ typedef enum sg_pixel_format {
SG_PIXELFORMAT_ETC2_RGB8A1,
SG_PIXELFORMAT_ETC2_RGBA8,
SG_PIXELFORMAT_ETC2_SRGB8A8,
SG_PIXELFORMAT_ETC2_RG11,
SG_PIXELFORMAT_ETC2_RG11SN,
SG_PIXELFORMAT_EAC_R11,
SG_PIXELFORMAT_EAC_R11SN,
SG_PIXELFORMAT_EAC_RG11,
SG_PIXELFORMAT_EAC_RG11SN,

SG_PIXELFORMAT_ASTC_4x4_RGBA,
SG_PIXELFORMAT_ASTC_4x4_SRGBA,
Expand Down Expand Up @@ -4844,6 +4846,12 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_
#ifndef GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276
#endif
#ifndef GL_COMPRESSED_R11_EAC
#define GL_COMPRESSED_R11_EAC 0x9270
#endif
#ifndef GL_COMPRESSED_SIGNED_R11_EAC
#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271
#endif
#ifndef GL_COMPRESSED_RG11_EAC
#define GL_COMPRESSED_RG11_EAC 0x9272
#endif
Expand Down Expand Up @@ -6218,8 +6226,10 @@ _SOKOL_PRIVATE bool _sg_is_compressed_pixel_format(sg_pixel_format fmt) {
case SG_PIXELFORMAT_ETC2_RGB8A1:
case SG_PIXELFORMAT_ETC2_RGBA8:
case SG_PIXELFORMAT_ETC2_SRGB8A8:
case SG_PIXELFORMAT_ETC2_RG11:
case SG_PIXELFORMAT_ETC2_RG11SN:
case SG_PIXELFORMAT_EAC_R11:
case SG_PIXELFORMAT_EAC_R11SN:
case SG_PIXELFORMAT_EAC_RG11:
case SG_PIXELFORMAT_EAC_RG11SN:
case SG_PIXELFORMAT_ASTC_4x4_RGBA:
case SG_PIXELFORMAT_ASTC_4x4_SRGBA:
return true;
Expand Down Expand Up @@ -6347,6 +6357,8 @@ _SOKOL_PRIVATE int _sg_row_pitch(sg_pixel_format fmt, int width, int row_align)
case SG_PIXELFORMAT_ETC2_RGB8:
case SG_PIXELFORMAT_ETC2_SRGB8:
case SG_PIXELFORMAT_ETC2_RGB8A1:
case SG_PIXELFORMAT_EAC_R11:
case SG_PIXELFORMAT_EAC_R11SN:
pitch = ((width + 3) / 4) * 8;
pitch = pitch < 8 ? 8 : pitch;
break;
Expand All @@ -6361,8 +6373,8 @@ _SOKOL_PRIVATE int _sg_row_pitch(sg_pixel_format fmt, int width, int row_align)
case SG_PIXELFORMAT_BC7_SRGBA:
case SG_PIXELFORMAT_ETC2_RGBA8:
case SG_PIXELFORMAT_ETC2_SRGB8A8:
case SG_PIXELFORMAT_ETC2_RG11:
case SG_PIXELFORMAT_ETC2_RG11SN:
case SG_PIXELFORMAT_EAC_RG11:
case SG_PIXELFORMAT_EAC_RG11SN:
case SG_PIXELFORMAT_ASTC_4x4_RGBA:
case SG_PIXELFORMAT_ASTC_4x4_SRGBA:
pitch = ((width + 3) / 4) * 16;
Expand Down Expand Up @@ -6396,8 +6408,10 @@ _SOKOL_PRIVATE int _sg_num_rows(sg_pixel_format fmt, int height) {
case SG_PIXELFORMAT_ETC2_RGB8A1:
case SG_PIXELFORMAT_ETC2_RGBA8:
case SG_PIXELFORMAT_ETC2_SRGB8A8:
case SG_PIXELFORMAT_ETC2_RG11:
case SG_PIXELFORMAT_ETC2_RG11SN:
case SG_PIXELFORMAT_EAC_R11:
case SG_PIXELFORMAT_EAC_R11SN:
case SG_PIXELFORMAT_EAC_RG11:
case SG_PIXELFORMAT_EAC_RG11SN:
case SG_PIXELFORMAT_BC2_RGBA:
case SG_PIXELFORMAT_BC3_RGBA:
case SG_PIXELFORMAT_BC3_SRGBA:
Expand Down Expand Up @@ -7319,9 +7333,13 @@ _SOKOL_PRIVATE GLenum _sg_gl_teximage_format(sg_pixel_format fmt) {
return GL_COMPRESSED_RGBA8_ETC2_EAC;
case SG_PIXELFORMAT_ETC2_SRGB8A8:
return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
case SG_PIXELFORMAT_ETC2_RG11:
case SG_PIXELFORMAT_EAC_R11:
return GL_COMPRESSED_R11_EAC;
case SG_PIXELFORMAT_EAC_R11SN:
return GL_COMPRESSED_SIGNED_R11_EAC;
case SG_PIXELFORMAT_EAC_RG11:
return GL_COMPRESSED_RG11_EAC;
case SG_PIXELFORMAT_ETC2_RG11SN:
case SG_PIXELFORMAT_EAC_RG11SN:
return GL_COMPRESSED_SIGNED_RG11_EAC;
case SG_PIXELFORMAT_ASTC_4x4_RGBA:
return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
Expand Down Expand Up @@ -7403,8 +7421,10 @@ _SOKOL_PRIVATE GLenum _sg_gl_teximage_internal_format(sg_pixel_format fmt) {
case SG_PIXELFORMAT_ETC2_RGB8A1: return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
case SG_PIXELFORMAT_ETC2_RGBA8: return GL_COMPRESSED_RGBA8_ETC2_EAC;
case SG_PIXELFORMAT_ETC2_SRGB8A8: return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
case SG_PIXELFORMAT_ETC2_RG11: return GL_COMPRESSED_RG11_EAC;
case SG_PIXELFORMAT_ETC2_RG11SN: return GL_COMPRESSED_SIGNED_RG11_EAC;
case SG_PIXELFORMAT_EAC_R11: return GL_COMPRESSED_R11_EAC;
case SG_PIXELFORMAT_EAC_R11SN: return GL_COMPRESSED_SIGNED_R11_EAC;
case SG_PIXELFORMAT_EAC_RG11: return GL_COMPRESSED_RG11_EAC;
case SG_PIXELFORMAT_EAC_RG11SN: return GL_COMPRESSED_SIGNED_RG11_EAC;
case SG_PIXELFORMAT_ASTC_4x4_RGBA: return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
default: SOKOL_UNREACHABLE; return 0;
Expand Down Expand Up @@ -7549,8 +7569,10 @@ _SOKOL_PRIVATE void _sg_gl_init_pixelformats_etc2(void) {
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11SN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]);
}

_SOKOL_PRIVATE void _sg_gl_init_pixelformats_astc(void) {
Expand Down Expand Up @@ -11638,8 +11660,10 @@ _SOKOL_PRIVATE MTLPixelFormat _sg_mtl_pixel_format(sg_pixel_format fmt) {
case SG_PIXELFORMAT_ETC2_RGB8A1: return MTLPixelFormatETC2_RGB8A1;
case SG_PIXELFORMAT_ETC2_RGBA8: return MTLPixelFormatEAC_RGBA8;
case SG_PIXELFORMAT_ETC2_SRGB8A8: return MTLPixelFormatEAC_RGBA8_sRGB;
case SG_PIXELFORMAT_ETC2_RG11: return MTLPixelFormatEAC_RG11Unorm;
case SG_PIXELFORMAT_ETC2_RG11SN: return MTLPixelFormatEAC_RG11Snorm;
case SG_PIXELFORMAT_EAC_R11: return MTLPixelFormatEAC_R11Unorm;
case SG_PIXELFORMAT_EAC_R11SN: return MTLPixelFormatEAC_R11Snorm;
case SG_PIXELFORMAT_EAC_RG11: return MTLPixelFormatEAC_RG11Unorm;
case SG_PIXELFORMAT_EAC_RG11SN: return MTLPixelFormatEAC_RG11Snorm;
case SG_PIXELFORMAT_ASTC_4x4_RGBA: return MTLPixelFormatASTC_4x4_LDR;
case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return MTLPixelFormatASTC_4x4_sRGB;
#endif
Expand Down Expand Up @@ -12113,8 +12137,10 @@ _SOKOL_PRIVATE void _sg_mtl_init_caps(void) {
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11SN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_RGBA]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ASTC_4x4_SRGBA]);

Expand Down Expand Up @@ -13518,8 +13544,10 @@ _SOKOL_PRIVATE WGPUTextureFormat _sg_wgpu_textureformat(sg_pixel_format p) {
case SG_PIXELFORMAT_ETC2_RGBA8: return WGPUTextureFormat_ETC2RGBA8Unorm;
case SG_PIXELFORMAT_ETC2_SRGB8: return WGPUTextureFormat_ETC2RGB8UnormSrgb;
case SG_PIXELFORMAT_ETC2_SRGB8A8: return WGPUTextureFormat_ETC2RGBA8UnormSrgb;
case SG_PIXELFORMAT_ETC2_RG11: return WGPUTextureFormat_EACR11Unorm;
case SG_PIXELFORMAT_ETC2_RG11SN: return WGPUTextureFormat_EACR11Snorm;
case SG_PIXELFORMAT_EAC_R11: return WGPUTextureFormat_EACR11Unorm;
case SG_PIXELFORMAT_EAC_R11SN: return WGPUTextureFormat_EACR11Snorm;
case SG_PIXELFORMAT_EAC_RG11: return WGPUTextureFormat_EACRG11Unorm;
case SG_PIXELFORMAT_EAC_RG11SN: return WGPUTextureFormat_EACRG11Snorm;
case SG_PIXELFORMAT_RGB9E5: return WGPUTextureFormat_RGB9E5Ufloat;
case SG_PIXELFORMAT_ASTC_4x4_RGBA: return WGPUTextureFormat_ASTC4x4Unorm;
case SG_PIXELFORMAT_ASTC_4x4_SRGBA: return WGPUTextureFormat_ASTC4x4UnormSrgb;
Expand Down Expand Up @@ -13758,8 +13786,10 @@ _SOKOL_PRIVATE void _sg_wgpu_init_caps(void) {
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGB8A1]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RGBA8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_SRGB8A8]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_ETC2_RG11SN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_R11SN]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11]);
_sg_pixelformat_sf(&_sg.formats[SG_PIXELFORMAT_EAC_RG11SN]);
}

if (wgpuDeviceHasFeature(_sg.wgpu.dev, WGPUFeatureName_TextureCompressionASTC)) {
Expand Down
6 changes: 4 additions & 2 deletions tests/functional/sokol_gfx_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2928,8 +2928,10 @@ UTEST(sokol_gfx, query_pixelformat_bytesperpixel) {
T(sg_query_pixelformat(SG_PIXELFORMAT_ETC2_RGB8).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_ETC2_RGB8A1).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_ETC2_RGBA8).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_ETC2_RG11).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_ETC2_RG11SN).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_EAC_R11).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_EAC_R11SN).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_EAC_R11).bytes_per_pixel == 0);
T(sg_query_pixelformat(SG_PIXELFORMAT_EAC_R11SN).bytes_per_pixel == 0);
sg_shutdown();
}

Expand Down
6 changes: 4 additions & 2 deletions util/sokol_gfx_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,10 @@ _SOKOL_PRIVATE const char* _sgimgui_pixelformat_string(sg_pixel_format fmt) {
case SG_PIXELFORMAT_ETC2_RGB8: return "SG_PIXELFORMAT_ETC2_RGB8";
case SG_PIXELFORMAT_ETC2_RGB8A1: return "SG_PIXELFORMAT_ETC2_RGB8A1";
case SG_PIXELFORMAT_ETC2_RGBA8: return "SG_PIXELFORMAT_ETC2_RGBA8";
case SG_PIXELFORMAT_ETC2_RG11: return "SG_PIXELFORMAT_ETC2_RG11";
case SG_PIXELFORMAT_ETC2_RG11SN: return "SG_PIXELFORMAT_ETC2_RG11SN";
case SG_PIXELFORMAT_EAC_R11: return "SG_PIXELFORMAT_EAC_R11";
case SG_PIXELFORMAT_EAC_R11SN: return "SG_PIXELFORMAT_EAC_R11SN";
case SG_PIXELFORMAT_EAC_RG11: return "SG_PIXELFORMAT_EAC_RG11";
case SG_PIXELFORMAT_EAC_RG11SN: return "SG_PIXELFORMAT_EAC_RG11SN";
case SG_PIXELFORMAT_RGB9E5: return "SG_PIXELFORMAT_RGB9E5";
case SG_PIXELFORMAT_BC3_SRGBA: return "SG_PIXELFORMAT_BC3_SRGBA";
case SG_PIXELFORMAT_BC7_SRGBA: return "SG_PIXELFORMAT_BC7_SRGBA";
Expand Down
Loading