Skip to content

Commit

Permalink
Merge pull request #1103 from floooh/issue929_remove_filter_none
Browse files Browse the repository at this point in the history
sokol_gfx.h: remove SG_FILTER_NONE (fixes #929)
  • Loading branch information
floooh authored Sep 2, 2024
2 parents ec18cd9 + 19004d3 commit c28138a
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 53 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 3 additions & 15 deletions sokol_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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") \
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 3 additions & 23 deletions tests/functional/sokol_gfx_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/sokol_spine_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion util/sokol_fontstash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion util/sokol_gfx_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 "???";
Expand Down
1 change: 0 additions & 1 deletion util/sokol_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 14 additions & 10 deletions util/sokol_spine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...,
Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit c28138a

Please sign in to comment.