From b90bdaaac01cff5b1d32e0cbfd973438dac4738e Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 2 Sep 2024 14:02:26 +0200 Subject: [PATCH 1/2] sokol_gfx.h: remove SG_FILTER_NONE (fixes #929) --- sokol_gfx.h | 18 +++--------------- tests/functional/sokol_gfx_test.c | 26 +++----------------------- tests/functional/sokol_spine_test.c | 2 +- util/sokol_fontstash.h | 1 - util/sokol_gfx_imgui.h | 1 - util/sokol_imgui.h | 1 - util/sokol_spine.h | 24 ++++++++++++++---------- 7 files changed, 21 insertions(+), 52 deletions(-) diff --git a/sokol_gfx.h b/sokol_gfx.h index 7e94f9d11..35c81e7d6 100644 --- a/sokol_gfx.h +++ b/sokol_gfx.h @@ -2098,13 +2098,10 @@ typedef enum sg_primitive_type { used in the sg_sampler_desc.min_filter, sg_sampler_desc.mag_filter and sg_sampler_desc.mipmap_filter members when creating a sampler object. - For min_filter and mag_filter the default is SG_FILTER_NEAREST. - - For mipmap_filter the default is SG_FILTER_NONE. + For the default is SG_FILTER_NEAREST. */ typedef enum sg_filter { _SG_FILTER_DEFAULT, // value 0 reserved for default-init - SG_FILTER_NONE, // FIXME: deprecated SG_FILTER_NEAREST, SG_FILTER_LINEAR, _SG_FILTER_NUM, @@ -2893,7 +2890,7 @@ typedef struct sg_image_desc { .min_filter: SG_FILTER_NEAREST .mag_filter: SG_FILTER_NEAREST - .mipmap_filter SG_FILTER_NONE + .mipmap_filter SG_FILTER_NEAREST .wrap_u: SG_WRAP_REPEAT .wrap_v: SG_WRAP_REPEAT .wrap_w: SG_WRAP_REPEAT (only SG_IMAGETYPE_3D) @@ -3652,8 +3649,6 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_DYNAMIC_NO_DATA, "dynamic/stream images cannot be initialized with data") \ _SG_LOGITEM_XMACRO(VALIDATE_IMAGEDESC_COMPRESSED_IMMUTABLE, "compressed images must be immutable") \ _SG_LOGITEM_XMACRO(VALIDATE_SAMPLERDESC_CANARY, "sg_sampler_desc not initialized") \ - _SG_LOGITEM_XMACRO(VALIDATE_SAMPLERDESC_MINFILTER_NONE, "sg_sampler_desc.min_filter cannot be SG_FILTER_NONE") \ - _SG_LOGITEM_XMACRO(VALIDATE_SAMPLERDESC_MAGFILTER_NONE, "sg_sampler_desc.mag_filter cannot be SG_FILTER_NONE") \ _SG_LOGITEM_XMACRO(VALIDATE_SAMPLERDESC_ANISTROPIC_REQUIRES_LINEAR_FILTERING, "sg_sampler_desc.max_anisotropy > 1 requires min/mag/mipmap_filter to be SG_FILTER_LINEAR") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_CANARY, "sg_shader_desc not initialized") \ _SG_LOGITEM_XMACRO(VALIDATE_SHADERDESC_SOURCE, "shader source code required") \ @@ -7161,14 +7156,12 @@ _SOKOL_PRIVATE GLenum _sg_gl_blend_op(sg_blend_op op) { _SOKOL_PRIVATE GLenum _sg_gl_min_filter(sg_filter min_f, sg_filter mipmap_f) { if (min_f == SG_FILTER_NEAREST) { switch (mipmap_f) { - case SG_FILTER_NONE: return GL_NEAREST; case SG_FILTER_NEAREST: return GL_NEAREST_MIPMAP_NEAREST; case SG_FILTER_LINEAR: return GL_NEAREST_MIPMAP_LINEAR; default: SOKOL_UNREACHABLE; return (GLenum)0; } } else if (min_f == SG_FILTER_LINEAR) { switch (mipmap_f) { - case SG_FILTER_NONE: return GL_LINEAR; case SG_FILTER_NEAREST: return GL_LINEAR_MIPMAP_NEAREST; case SG_FILTER_LINEAR: return GL_LINEAR_MIPMAP_LINEAR; default: SOKOL_UNREACHABLE; return (GLenum)0; @@ -11907,8 +11900,6 @@ _SOKOL_PRIVATE MTLSamplerMinMagFilter _sg_mtl_minmag_filter(sg_filter f) { _SOKOL_PRIVATE MTLSamplerMipFilter _sg_mtl_mipmap_filter(sg_filter f) { switch (f) { - case SG_FILTER_NONE: - return MTLSamplerMipFilterNotMipmapped; case SG_FILTER_NEAREST: return MTLSamplerMipFilterNearest; case SG_FILTER_LINEAR: @@ -13464,7 +13455,6 @@ _SOKOL_PRIVATE WGPUFilterMode _sg_wgpu_sampler_minmag_filter(sg_filter f) { _SOKOL_PRIVATE WGPUMipmapFilterMode _sg_wgpu_sampler_mipmap_filter(sg_filter f) { switch (f) { - case SG_FILTER_NONE: case SG_FILTER_NEAREST: return WGPUMipmapFilterMode_Nearest; case SG_FILTER_LINEAR: @@ -16325,8 +16315,6 @@ _SOKOL_PRIVATE bool _sg_validate_sampler_desc(const sg_sampler_desc* desc) { _sg_validate_begin(); _SG_VALIDATE(desc->_start_canary == 0, VALIDATE_SAMPLERDESC_CANARY); _SG_VALIDATE(desc->_end_canary == 0, VALIDATE_SAMPLERDESC_CANARY); - _SG_VALIDATE(desc->min_filter != SG_FILTER_NONE, VALIDATE_SAMPLERDESC_MINFILTER_NONE); - _SG_VALIDATE(desc->mag_filter != SG_FILTER_NONE, VALIDATE_SAMPLERDESC_MAGFILTER_NONE); // restriction from WebGPU: when anisotropy > 1, all filters must be linear if (desc->max_anisotropy > 1) { _SG_VALIDATE((desc->min_filter == SG_FILTER_LINEAR) @@ -17146,7 +17134,7 @@ _SOKOL_PRIVATE sg_sampler_desc _sg_sampler_desc_defaults(const sg_sampler_desc* sg_sampler_desc def = *desc; def.min_filter = _sg_def(def.min_filter, SG_FILTER_NEAREST); def.mag_filter = _sg_def(def.mag_filter, SG_FILTER_NEAREST); - def.mipmap_filter = _sg_def(def.mipmap_filter, SG_FILTER_NONE); + def.mipmap_filter = _sg_def(def.mipmap_filter, SG_FILTER_NEAREST); def.wrap_u = _sg_def(def.wrap_u, SG_WRAP_REPEAT); def.wrap_v = _sg_def(def.wrap_v, SG_WRAP_REPEAT); def.wrap_w = _sg_def(def.wrap_w, SG_WRAP_REPEAT); diff --git a/tests/functional/sokol_gfx_test.c b/tests/functional/sokol_gfx_test.c index 121b3d0f3..910d08149 100644 --- a/tests/functional/sokol_gfx_test.c +++ b/tests/functional/sokol_gfx_test.c @@ -429,7 +429,7 @@ UTEST(sokol_gfx, make_destroy_samplers) { T(smpptr->slot.state == SG_RESOURCESTATE_VALID); T(smpptr->cmn.min_filter == SG_FILTER_NEAREST); T(smpptr->cmn.mag_filter == SG_FILTER_NEAREST); - T(smpptr->cmn.mipmap_filter == SG_FILTER_NONE); + T(smpptr->cmn.mipmap_filter == SG_FILTER_NEAREST); T(smpptr->cmn.wrap_u == SG_WRAP_REPEAT); T(smpptr->cmn.wrap_v == SG_WRAP_REPEAT); T(smpptr->cmn.wrap_w == SG_WRAP_REPEAT); @@ -635,7 +635,7 @@ UTEST(sokol_gfx, query_sampler_defaults) { const sg_sampler_desc desc = sg_query_sampler_defaults(&(sg_sampler_desc){0}); T(desc.min_filter == SG_FILTER_NEAREST); T(desc.mag_filter == SG_FILTER_NEAREST); - T(desc.mipmap_filter == SG_FILTER_NONE); + T(desc.mipmap_filter == SG_FILTER_NEAREST); T(desc.wrap_u == SG_WRAP_REPEAT); T(desc.wrap_v == SG_WRAP_REPEAT); T(desc.wrap_w == SG_WRAP_REPEAT); @@ -2151,26 +2151,6 @@ UTEST(sokol_gfx, make_sampler_validate_start_canary) { sg_shutdown(); } -UTEST(sokol_gfx, make_sampler_validate_minfilter_none) { - setup(&(sg_desc){0}); - sg_sampler smp = sg_make_sampler(&(sg_sampler_desc){ - .min_filter = SG_FILTER_NONE, - }); - T(sg_query_sampler_state(smp) == SG_RESOURCESTATE_FAILED); - T(log_items[0] == SG_LOGITEM_VALIDATE_SAMPLERDESC_MINFILTER_NONE); - sg_shutdown(); -} - -UTEST(sokol_gfx, make_sampler_validate_magfilter_none) { - setup(&(sg_desc){0}); - sg_sampler smp = sg_make_sampler(&(sg_sampler_desc){ - .mag_filter = SG_FILTER_NONE, - }); - T(sg_query_sampler_state(smp) == SG_RESOURCESTATE_FAILED); - T(log_items[0] == SG_LOGITEM_VALIDATE_SAMPLERDESC_MAGFILTER_NONE); - sg_shutdown(); -} - UTEST(sokol_gfx, make_sampler_validate_anistropic_requires_linear_filtering) { setup(&(sg_desc){0}); sg_sampler smp; @@ -2179,7 +2159,7 @@ UTEST(sokol_gfx, make_sampler_validate_anistropic_requires_linear_filtering) { .max_anisotropy = 2, .min_filter = SG_FILTER_LINEAR, .mag_filter = SG_FILTER_LINEAR, - .mipmap_filter = SG_FILTER_NONE, + .mipmap_filter = SG_FILTER_NEAREST, }); T(sg_query_sampler_state(smp) == SG_RESOURCESTATE_FAILED); T(log_items[0] == SG_LOGITEM_VALIDATE_SAMPLERDESC_ANISTROPIC_REQUIRES_LINEAR_FILTERING); diff --git a/tests/functional/sokol_spine_test.c b/tests/functional/sokol_spine_test.c index 435b32b28..1c69d3504 100644 --- a/tests/functional/sokol_spine_test.c +++ b/tests/functional/sokol_spine_test.c @@ -655,7 +655,7 @@ UTEST(sokol_spine, atlas_get_atlas_page_info_with_overrides) { T(strcmp(info.image.filename.cstr, "spineboy.png") == 0); T(info.image.min_filter == SG_FILTER_LINEAR); T(info.image.mag_filter == SG_FILTER_LINEAR); - T(info.image.mipmap_filter == SG_FILTER_NONE); + T(info.image.mipmap_filter == SG_FILTER_NEAREST); T(info.image.wrap_u == SG_WRAP_CLAMP_TO_EDGE); T(info.image.wrap_v == SG_WRAP_CLAMP_TO_EDGE); T(info.image.width == 1024); diff --git a/util/sokol_fontstash.h b/util/sokol_fontstash.h index a65058576..861241e73 100644 --- a/util/sokol_fontstash.h +++ b/util/sokol_fontstash.h @@ -1661,7 +1661,6 @@ static int _sfons_render_create(void* user_ptr, int width, int height) { _sfons_clear(&smp_desc, sizeof(smp_desc)); smp_desc.min_filter = SG_FILTER_LINEAR; smp_desc.mag_filter = SG_FILTER_LINEAR; - smp_desc.mipmap_filter = SG_FILTER_NONE; sfons->smp = sg_make_sampler(&smp_desc); } diff --git a/util/sokol_gfx_imgui.h b/util/sokol_gfx_imgui.h index ba9d25fc9..5aea7ec1c 100644 --- a/util/sokol_gfx_imgui.h +++ b/util/sokol_gfx_imgui.h @@ -1287,7 +1287,6 @@ _SOKOL_PRIVATE const char* _sgimgui_pixelformat_string(sg_pixel_format fmt) { _SOKOL_PRIVATE const char* _sgimgui_filter_string(sg_filter f) { switch (f) { - case SG_FILTER_NONE: return "SG_FILTER_NONE"; case SG_FILTER_NEAREST: return "SG_FILTER_NEAREST"; case SG_FILTER_LINEAR: return "SG_FILTER_LINEAR"; default: return "???"; diff --git a/util/sokol_imgui.h b/util/sokol_imgui.h index 0362a9a98..05426791f 100644 --- a/util/sokol_imgui.h +++ b/util/sokol_imgui.h @@ -2400,7 +2400,6 @@ SOKOL_API_IMPL void simgui_create_fonts_texture(const simgui_font_tex_desc_t* de font_smp_desc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; font_smp_desc.min_filter = desc->min_filter; font_smp_desc.mag_filter = desc->mag_filter; - font_smp_desc.mipmap_filter = SG_FILTER_NONE; font_smp_desc.label = "sokol-imgui-font-sampler"; _simgui.font_smp = sg_make_sampler(&font_smp_desc); diff --git a/util/sokol_spine.h b/util/sokol_spine.h index 4eb9b66a2..7b6774803 100644 --- a/util/sokol_spine.h +++ b/util/sokol_spine.h @@ -236,7 +236,7 @@ .overrides = { .min_filter = SG_FILTER_NEAREST, .mag_filter = SG_FILTER_NEAREST, - .mipmap_filter = SG_FILTER_NONE, + .mipmap_filter = SG_FILTER_NEAREST, .wrap_u = SG_WRAP_MIRROR, .wrap_v = SG_WRAP_MIRROR, .premul_alpha_enabled = ..., @@ -4573,15 +4573,19 @@ static sg_filter _sspine_as_sampler_filter(spAtlasFilter filter) { static sg_filter _sspine_as_sampler_mipmap_filter(spAtlasFilter filter) { switch (filter) { - case SP_ATLAS_UNKNOWN_FILTER: return _SG_FILTER_DEFAULT; - case SP_ATLAS_NEAREST: return SG_FILTER_NONE; - case SP_ATLAS_LINEAR: return SG_FILTER_NONE; - case SP_ATLAS_MIPMAP: return SG_FILTER_NEAREST; - case SP_ATLAS_MIPMAP_NEAREST_NEAREST: return SG_FILTER_NEAREST; - case SP_ATLAS_MIPMAP_LINEAR_NEAREST: return SG_FILTER_NEAREST; - case SP_ATLAS_MIPMAP_NEAREST_LINEAR: return SG_FILTER_LINEAR; - case SP_ATLAS_MIPMAP_LINEAR_LINEAR: return SG_FILTER_LINEAR; - default: return SG_FILTER_NEAREST; + case SP_ATLAS_UNKNOWN_FILTER: + return _SG_FILTER_DEFAULT; + case SP_ATLAS_NEAREST: + case SP_ATLAS_LINEAR: + case SP_ATLAS_MIPMAP: + case SP_ATLAS_MIPMAP_NEAREST_NEAREST: + case SP_ATLAS_MIPMAP_LINEAR_NEAREST: + return SG_FILTER_NEAREST; + case SP_ATLAS_MIPMAP_NEAREST_LINEAR: + case SP_ATLAS_MIPMAP_LINEAR_LINEAR: + return SG_FILTER_LINEAR; + default: + return SG_FILTER_NEAREST; } } From 19004d3f7cd1a087915b3de706b6bb00ab3eb4bc Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Mon, 2 Sep 2024 14:13:56 +0200 Subject: [PATCH 2/2] update changelog (https://github.com/floooh/sokol/pull/1103) --- CHANGELOG.md | 15 +++++++++++++++ README.md | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d73e84c8e..9ab250677 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ ## Updates +### 02-Sep-2024 + +- Minor breaking change in sokol_gfx.h: The enum item `SG_FILTER_NONE` has been + removed. Until around Oct-2023 this was required to be used as mip-filter + on textures without mipmaps because of an unnecessary restriction in the + GL backend (see https://github.com/floooh/sokol/issues/929 for details). + The concept of a 'none' mipmap filter never mapped to some 3D backends + (specifically D3D11 and WebGPU). + If you are currently creating samplers with `.mipmap_filter = SG_FILTER_NONE` + you can simply remove that line. The new default value is `SG_FILTER_NEAREST`. + To restrict mipmap sampling access to a specific mipmap (or mipmap range), + use the `.min_lod` and `.max_lod` items in struct `sg_sampler_desc`. + + The change has been implemented in PR https://github.com/floooh/sokol/pull/1103. + ### 01-Sep-2024 - sokol_gfx.h d3d11: added a new configuration flag `d3d11_shader_debugging` diff --git a/README.md b/README.md index c7dad0d2f..cf4cab0b5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # Sokol -[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**24-Jul-2024**: sokol_gfx.h WebGL2: important workaround for recent Chrome 127 regression on macOS) +[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**02-Sep-2024** in sokol_gfx.h, SG_FILTER_NONE has been removed) [![Build](/../../actions/workflows/main.yml/badge.svg)](/../../actions/workflows/main.yml) [![Bindings](/../../actions/workflows/gen_bindings.yml/badge.svg)](/../../actions/workflows/gen_bindings.yml) [![build](https://github.com/floooh/sokol-zig/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-zig/actions/workflows/main.yml) [![build](https://github.com/floooh/sokol-nim/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-nim/actions/workflows/main.yml) [![Odin](https://github.com/floooh/sokol-odin/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-odin/actions/workflows/main.yml)[![Rust](https://github.com/floooh/sokol-rust/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-rust/actions/workflows/main.yml)[![Dlang](https://github.com/kassane/sokol-d/actions/workflows/build.yml/badge.svg)](https://github.com/kassane/sokol-d/actions/workflows/build.yml)