diff --git a/bindings/bf/bgfx.bf b/bindings/bf/bgfx.bf
index 9e98e9092..6419511f7 100644
--- a/bindings/bf/bgfx.bf
+++ b/bindings/bf/bgfx.bf
@@ -728,6 +728,8 @@ public static class bgfx
RtWriteOnly = 0x0000008000000000,
RtShift = 36,
RtMask = 0x000000f000000000,
+ MipCountShift = 49,
+ MipCountMask = 0x003e000000000000,
}
[AllowDuplicates]
@@ -3870,7 +3872,7 @@ public static class bgfx
///
/// Width.
/// Height.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -3886,7 +3888,7 @@ public static class bgfx
///
///
/// Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -3901,7 +3903,7 @@ public static class bgfx
/// Width.
/// Height.
/// Depth.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
/// Texture data. If `_mem` is non-NULL, created texture will be immutable. If `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than 1, expected memory layout is texture and all mips together for each array element.
@@ -3915,7 +3917,7 @@ public static class bgfx
///
///
/// Cube side size.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -4961,9 +4963,11 @@ public static class bgfx
/// First (most detailed) mip level.
/// Number of mip levels.
/// Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
+ /// Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.
+ /// Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.
///
[LinkName("bgfx_encoder_set_texture_view")]
- public static extern void encoder_set_texture_view(Encoder* _this, uint8 _stage, UniformHandle _sampler, TextureHandle _handle, uint16 _firstLayer, uint16 _numLayers, uint8 _firstMip, uint8 _numMips, uint32 _flags);
+ public static extern void encoder_set_texture_view(Encoder* _this, uint8 _stage, UniformHandle _sampler, TextureHandle _handle, uint16 _firstLayer, uint16 _numLayers, uint8 _firstMip, uint8 _numMips, uint32 _flags, uint8 _lodMin, uint8 _lodMax);
///
/// Submit an empty primitive for rendering. Uniforms and draw state
@@ -5711,9 +5715,11 @@ public static class bgfx
/// First (most detailed) mip level.
/// Number of mip levels.
/// Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
+ /// Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.
+ /// Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.
///
[LinkName("bgfx_set_texture_view")]
- public static extern void set_texture_view(uint8 _stage, UniformHandle _sampler, TextureHandle _handle, uint16 _firstLayer, uint16 _numLayers, uint8 _firstMip, uint8 _numMips, uint32 _flags);
+ public static extern void set_texture_view(uint8 _stage, UniformHandle _sampler, TextureHandle _handle, uint16 _firstLayer, uint16 _numLayers, uint8 _firstMip, uint8 _numMips, uint32 _flags, uint8 _lodMin, uint8 _lodMax);
///
/// Submit an empty primitive for rendering. Uniforms and draw state
diff --git a/bindings/c3/bgfx.c3 b/bindings/c3/bgfx.c3
index dc0fe7dc8..bc9e09420 100644
--- a/bindings/c3/bgfx.c3
+++ b/bindings/c3/bgfx.c3
@@ -460,6 +460,8 @@ constdef TextureFlags : inline ulong
RTWRITEONLY = 0x0000008000000000,
RTSHIFT = 36,
RTMASK = 0x000000f000000000,
+ MIPCOUNTSHIFT = 49,
+ MIPCOUNTMASK = 0x003e000000000000,
}
constdef SamplerFlags : inline uint
@@ -2864,7 +2866,7 @@ extern fn TextureHandle create_texture(Memory* _mem, ulong _flags, char _skip, T
// Create 2D texture.
// _width : `Width.`
// _height : `Height.`
-// _hasMips : `Indicates that texture contains full mip-map chain.`
+// _hasMips : `Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.`
// _numLayers : `Number of layers in texture array.`
// _format : `Texture format. See: `TextureFormat::Enum`.`
// _flags : `Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.`
@@ -2875,7 +2877,7 @@ extern fn TextureHandle create_texture_2d(ushort _width, ushort _height, bool _h
// Create texture with size based on back-buffer ratio. Texture will maintain ratio
// if back buffer resolution changes.
// _ratio : `Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`.`
-// _hasMips : `Indicates that texture contains full mip-map chain.`
+// _hasMips : `Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.`
// _numLayers : `Number of layers in texture array.`
// _format : `Texture format. See: `TextureFormat::Enum`.`
// _flags : `Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.`
@@ -2885,7 +2887,7 @@ extern fn TextureHandle create_texture_2d_scaled(BackbufferRatio _ratio, bool _h
// _width : `Width.`
// _height : `Height.`
// _depth : `Depth.`
-// _hasMips : `Indicates that texture contains full mip-map chain.`
+// _hasMips : `Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.`
// _format : `Texture format. See: `TextureFormat::Enum`.`
// _flags : `Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.`
// _mem : `Texture data. If `_mem` is non-NULL, created texture will be immutable. If `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than 1, expected memory layout is texture and all mips together for each array element.`
@@ -2894,7 +2896,7 @@ extern fn TextureHandle create_texture_3d(ushort _width, ushort _height, ushort
// Create Cube texture.
// _size : `Cube side size.`
-// _hasMips : `Indicates that texture contains full mip-map chain.`
+// _hasMips : `Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.`
// _numLayers : `Number of layers in texture array.`
// _format : `Texture format. See: `TextureFormat::Enum`.`
// _flags : `Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.`
@@ -3566,7 +3568,9 @@ extern fn void encoder_set_texture(Encoder* _this, char _stage, UniformHandle _s
// _firstMip : `First (most detailed) mip level.`
// _numMips : `Number of mip levels.`
// _flags : `Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.`
-extern fn void encoder_set_texture_view(Encoder* _this, char _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, char _firstMip, char _numMips, uint _flags) @cname("bgfx_encoder_set_texture_view");
+// _lodMin : `Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.`
+// _lodMax : `Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.`
+extern fn void encoder_set_texture_view(Encoder* _this, char _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, char _firstMip, char _numMips, uint _flags, char _lodMin, char _lodMax) @cname("bgfx_encoder_set_texture_view");
// Submit an empty primitive for rendering. Uniforms and draw state
// will be applied but no geometry will be submitted. Useful in cases
@@ -4057,7 +4061,9 @@ extern fn void set_texture(char _stage, UniformHandle _sampler, TextureHandle _h
// _firstMip : `First (most detailed) mip level.`
// _numMips : `Number of mip levels.`
// _flags : `Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.`
-extern fn void set_texture_view(char _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, char _firstMip, char _numMips, uint _flags) @cname("bgfx_set_texture_view");
+// _lodMin : `Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.`
+// _lodMax : `Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.`
+extern fn void set_texture_view(char _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, char _firstMip, char _numMips, uint _flags, char _lodMin, char _lodMax) @cname("bgfx_set_texture_view");
// Submit an empty primitive for rendering. Uniforms and draw state
// will be applied but no geometry will be submitted.
diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs
index 3b20bc4f5..2e1a796f4 100644
--- a/bindings/cs/bgfx.cs
+++ b/bindings/cs/bgfx.cs
@@ -727,6 +727,8 @@ public static partial class bgfx
RtWriteOnly = 0x0000008000000000,
RtShift = 36,
RtMask = 0x000000f000000000,
+ MipCountShift = 49,
+ MipCountMask = 0x003e000000000000,
}
[Flags]
@@ -3817,7 +3819,7 @@ public static partial class bgfx
///
/// Width.
/// Height.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -3833,7 +3835,7 @@ public static partial class bgfx
///
///
/// Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -3848,7 +3850,7 @@ public static partial class bgfx
/// Width.
/// Height.
/// Depth.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
/// Texture data. If `_mem` is non-NULL, created texture will be immutable. If `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than 1, expected memory layout is texture and all mips together for each array element.
@@ -3862,7 +3864,7 @@ public static partial class bgfx
///
///
/// Cube side size.
- /// Indicates that texture contains full mip-map chain.
+ /// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -4908,9 +4910,11 @@ public static partial class bgfx
/// First (most detailed) mip level.
/// Number of mip levels.
/// Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
+ /// Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.
+ /// Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.
///
[DllImport(DllName, EntryPoint="bgfx_encoder_set_texture_view", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void encoder_set_texture_view(Encoder* _this, byte _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, byte _firstMip, byte _numMips, uint _flags);
+ public static extern unsafe void encoder_set_texture_view(Encoder* _this, byte _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, byte _firstMip, byte _numMips, uint _flags, byte _lodMin, byte _lodMax);
///
/// Submit an empty primitive for rendering. Uniforms and draw state
@@ -5658,9 +5662,11 @@ public static partial class bgfx
/// First (most detailed) mip level.
/// Number of mip levels.
/// Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
+ /// Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.
+ /// Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.
///
[DllImport(DllName, EntryPoint="bgfx_set_texture_view", CallingConvention = CallingConvention.Cdecl)]
- public static extern unsafe void set_texture_view(byte _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, byte _firstMip, byte _numMips, uint _flags);
+ public static extern unsafe void set_texture_view(byte _stage, UniformHandle _sampler, TextureHandle _handle, ushort _firstLayer, ushort _numLayers, byte _firstMip, byte _numMips, uint _flags, byte _lodMin, byte _lodMax);
///
/// Submit an empty primitive for rendering. Uniforms and draw state
diff --git a/bindings/d/package.d b/bindings/d/package.d
index b21159824..356d7c929 100644
--- a/bindings/d/package.d
+++ b/bindings/d/package.d
@@ -347,6 +347,20 @@ enum TextureRT: TextureRT_{
mask = 0x0000_00F0_0000_0000,
}
+/**
+Mip level count, `BGFX_TEXTURE_MIP_COUNT(n)`. Overrides `_hasMips` of
+`createTexture2D`, `createTexture3D` and `createTextureCube`: the texture
+gets `n` levels, clamped to the full chain for its size. Zero keeps the
+`_hasMips` behaviour. A texture created from an image container keeps the
+container's level count.
+*/
+alias TextureMIPCount_ = ulong;
+enum TextureMIPCount: TextureMIPCount_{
+ shift = 49, ///Mip level count bit shift
+ mask = 0x003E_0000_0000_0000, ///Mip level count bit mask
+}
+TextureMIPCount_ toTextureMIPCount(ulong v) nothrow @nogc pure @safe{ return (v << TextureMIPCount.shift) & TextureMIPCount.mask; }
+
///Sampler flags.
alias SamplerU_ = uint;
enum SamplerU: SamplerU_{
@@ -2203,8 +2217,13 @@ extern(C++, "bgfx") struct Encoder{
mode.
- `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
sampling.
+ lodMin = Lowest (most detailed) level of detail the sampler may use, in
+ quarter-mip steps, relative to `_firstMip`.
+ lodMax = Highest (least detailed) level of detail the sampler may use, in
+ quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it
+ unclamped.
*/
- {q{void}, q{setTexture}, q{ubyte stage, UniformHandle sampler, TextureHandle handle, ushort firstLayer, ushort numLayers, ubyte firstMIP, ubyte numMIPs, uint flags=uint.max}, ext: `C++`},
+ {q{void}, q{setTexture}, q{ubyte stage, UniformHandle sampler, TextureHandle handle, ushort firstLayer, ushort numLayers, ubyte firstMIP, ubyte numMIPs, uint flags=uint.max, ubyte lodMin=0, ubyte lodMax=ubyte.max}, ext: `C++`},
/**
Submit an empty primitive for rendering. Uniforms and draw state
@@ -3198,6 +3217,7 @@ mixin(joinFnBinds((){
width = Width.
height = Height.
hasMIPs = Indicates that texture contains full mip-map chain.
+ Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
numLayers = Number of layers in texture array.
format = Texture format. See: `TextureFormat::Enum`.
flags = Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -3219,6 +3239,7 @@ mixin(joinFnBinds((){
Params:
ratio = Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`.
hasMIPs = Indicates that texture contains full mip-map chain.
+ Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
numLayers = Number of layers in texture array.
format = Texture format. See: `TextureFormat::Enum`.
flags = Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -3237,6 +3258,7 @@ mixin(joinFnBinds((){
height = Height.
depth = Depth.
hasMIPs = Indicates that texture contains full mip-map chain.
+ Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
format = Texture format. See: `TextureFormat::Enum`.
flags = Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
flags. Default texture sampling mode is linear, and wrap mode is repeat.
@@ -3256,6 +3278,7 @@ mixin(joinFnBinds((){
Params:
size = Cube side size.
hasMIPs = Indicates that texture contains full mip-map chain.
+ Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
numLayers = Number of layers in texture array.
format = Texture format. See: `TextureFormat::Enum`.
flags = Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -4327,8 +4350,13 @@ mixin(joinFnBinds((){
mode.
- `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
sampling.
+ lodMin = Lowest (most detailed) level of detail the sampler may use, in
+ quarter-mip steps, relative to `_firstMip`.
+ lodMax = Highest (least detailed) level of detail the sampler may use, in
+ quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it
+ unclamped.
*/
- {q{void}, q{setTexture}, q{ubyte stage, UniformHandle sampler, TextureHandle handle, ushort firstLayer, ushort numLayers, ubyte firstMIP, ubyte numMIPs, uint flags=uint.max}, ext: `C++, "bgfx"`},
+ {q{void}, q{setTexture}, q{ubyte stage, UniformHandle sampler, TextureHandle handle, ushort firstLayer, ushort numLayers, ubyte firstMIP, ubyte numMIPs, uint flags=uint.max, ubyte lodMin=0, ubyte lodMax=ubyte.max}, ext: `C++, "bgfx"`},
/**
* Submit an empty primitive for rendering. Uniforms and draw state
diff --git a/bindings/py/bgfx.py b/bindings/py/bgfx.py
index 490c29d26..732768120 100644
--- a/bindings/py/bgfx.py
+++ b/bindings/py/bgfx.py
@@ -426,6 +426,8 @@ class TextureFlags(enum.IntFlag):
RtWriteOnly = 0x8000000000
RtShift = 0x24
RtMask = 0xf000000000
+ MipCountShift = 0x31
+ MipCountMask = 0x3e000000000000
class SamplerFlags(enum.IntFlag):
UMirror = 0x1
@@ -1701,7 +1703,7 @@ def _bind(lib):
bgfx_encoder_set_texture.restype = None
global bgfx_encoder_set_texture_view
bgfx_encoder_set_texture_view = lib.bgfx_encoder_set_texture_view
- bgfx_encoder_set_texture_view.argtypes = [ctypes.POINTER(Encoder), ctypes.c_uint8, UniformHandle, TextureHandle, ctypes.c_uint16, ctypes.c_uint16, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint32]
+ bgfx_encoder_set_texture_view.argtypes = [ctypes.POINTER(Encoder), ctypes.c_uint8, UniformHandle, TextureHandle, ctypes.c_uint16, ctypes.c_uint16, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint32, ctypes.c_uint8, ctypes.c_uint8]
bgfx_encoder_set_texture_view.restype = None
global bgfx_encoder_touch
bgfx_encoder_touch = lib.bgfx_encoder_touch
@@ -1909,7 +1911,7 @@ def _bind(lib):
bgfx_set_texture.restype = None
global bgfx_set_texture_view
bgfx_set_texture_view = lib.bgfx_set_texture_view
- bgfx_set_texture_view.argtypes = [ctypes.c_uint8, UniformHandle, TextureHandle, ctypes.c_uint16, ctypes.c_uint16, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint32]
+ bgfx_set_texture_view.argtypes = [ctypes.c_uint8, UniformHandle, TextureHandle, ctypes.c_uint16, ctypes.c_uint16, ctypes.c_uint8, ctypes.c_uint8, ctypes.c_uint32, ctypes.c_uint8, ctypes.c_uint8]
bgfx_set_texture_view.restype = None
global bgfx_touch
bgfx_touch = lib.bgfx_touch
diff --git a/bindings/py/bgfx.pyi b/bindings/py/bgfx.pyi
index 78839acb0..662348e28 100644
--- a/bindings/py/bgfx.pyi
+++ b/bindings/py/bgfx.pyi
@@ -803,6 +803,18 @@ class TextureFlags(enum.IntFlag):
RtWriteOnly = 0x8000000000
RtShift = 0x24
RtMask = 0xf000000000
+ # Mip level count, `BGFX_TEXTURE_MIP_COUNT(n)`. Overrides `_hasMips` of
+ # `createTexture2D`, `createTexture3D` and `createTextureCube`: the texture
+ # gets `n` levels, clamped to the full chain for its size. Zero keeps the
+ # `_hasMips` behaviour. A texture created from an image container keeps the
+ # container's level count.
+ MipCountShift = 0x31
+ # Mip level count, `BGFX_TEXTURE_MIP_COUNT(n)`. Overrides `_hasMips` of
+ # `createTexture2D`, `createTexture3D` and `createTextureCube`: the texture
+ # gets `n` levels, clamped to the full chain for its size. Zero keeps the
+ # `_hasMips` behaviour. A texture created from an image container keeps the
+ # container's level count.
+ MipCountMask = 0x3e000000000000
class SamplerFlags(enum.IntFlag):
# Wrap U mode: Mirror
@@ -2863,6 +2875,8 @@ def bgfx_encoder_set_texture_view(
_firstMip: int,
_numMips: int,
_flags: int,
+ _lodMin: int,
+ _lodMax: int,
/,
) -> None: ...
@@ -3283,6 +3297,8 @@ def bgfx_set_texture_view(
_firstMip: int,
_numMips: int,
_flags: int,
+ _lodMin: int,
+ _lodMax: int,
/,
) -> None: ...
diff --git a/bindings/zig/bgfx.zig b/bindings/zig/bgfx.zig
index 25622afa7..ca16f0360 100644
--- a/bindings/zig/bgfx.zig
+++ b/bindings/zig/bgfx.zig
@@ -448,6 +448,8 @@ pub const TextureFlags_RtMsaaMask: TextureFlags = 0x0000007000000000
pub const TextureFlags_RtWriteOnly: TextureFlags = 0x0000008000000000;
pub const TextureFlags_RtShift: TextureFlags = 36;
pub const TextureFlags_RtMask: TextureFlags = 0x000000f000000000;
+pub const TextureFlags_MipCountShift: TextureFlags = 49;
+pub const TextureFlags_MipCountMask: TextureFlags = 0x003e000000000000;
pub const SamplerFlags = u32;
/// Wrap U mode: Mirror
@@ -2184,8 +2186,10 @@ pub const Init = extern struct {
/// First (most detailed) mip level.
/// Number of mip levels.
/// Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
- pub inline fn setTextureView(self: ?*Encoder, _stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32) void {
- return bgfx_encoder_set_texture_view(self, _stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags);
+ /// Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.
+ /// Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.
+ pub inline fn setTextureView(self: ?*Encoder, _stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32, _lodMin: u8, _lodMax: u8) void {
+ return bgfx_encoder_set_texture_view(self, _stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags, _lodMin, _lodMax);
}
/// Submit an empty primitive for rendering. Uniforms and draw state
/// will be applied but no geometry will be submitted. Useful in cases
@@ -3145,7 +3149,7 @@ extern fn bgfx_create_texture(_mem: [*c]const Memory, _flags: u64, _skip: u8, _i
/// Create 2D texture.
/// Width.
/// Height.
-/// Indicates that texture contains full mip-map chain.
+/// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -3159,7 +3163,7 @@ extern fn bgfx_create_texture_2d(_width: u16, _height: u16, _hasMips: bool, _num
/// Create texture with size based on back-buffer ratio. Texture will maintain ratio
/// if back buffer resolution changes.
/// Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`.
-/// Indicates that texture contains full mip-map chain.
+/// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -3172,7 +3176,7 @@ extern fn bgfx_create_texture_2d_scaled(_ratio: BackbufferRatio, _hasMips: bool,
/// Width.
/// Height.
/// Depth.
-/// Indicates that texture contains full mip-map chain.
+/// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
/// Texture data. If `_mem` is non-NULL, created texture will be immutable. If `_mem` is NULL content of the texture is uninitialized. When `_numLayers` is more than 1, expected memory layout is texture and all mips together for each array element.
@@ -3184,7 +3188,7 @@ extern fn bgfx_create_texture_3d(_width: u16, _height: u16, _depth: u16, _hasMip
/// Create Cube texture.
/// Cube side size.
-/// Indicates that texture contains full mip-map chain.
+/// Indicates that texture contains full mip-map chain. Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// Number of layers in texture array.
/// Texture format. See: `TextureFormat::Enum`.
/// Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`) flags. Default texture sampling mode is linear, and wrap mode is repeat. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
@@ -3994,7 +3998,9 @@ extern fn bgfx_encoder_set_texture(self: ?*Encoder, _stage: u8, _sampler: Unifor
/// First (most detailed) mip level.
/// Number of mip levels.
/// Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
-extern fn bgfx_encoder_set_texture_view(self: ?*Encoder, _stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32) void;
+/// Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.
+/// Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.
+extern fn bgfx_encoder_set_texture_view(self: ?*Encoder, _stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32, _lodMin: u8, _lodMax: u8) void;
/// Submit an empty primitive for rendering. Uniforms and draw state
/// will be applied but no geometry will be submitted. Useful in cases
@@ -4581,10 +4587,12 @@ extern fn bgfx_set_texture(_stage: u8, _sampler: UniformHandle, _handle: Texture
/// First (most detailed) mip level.
/// Number of mip levels.
/// Texture sampling mode. Default value UINT32_MAX uses texture sampling settings from the texture. - `BGFX_SAMPLER_[U/V/W]_[MIRROR/CLAMP]` - Mirror or clamp to edge wrap mode. - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic sampling.
-pub inline fn setTextureView(_stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32) void {
- return bgfx_set_texture_view(_stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags);
+/// Lowest (most detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`.
+/// Highest (least detailed) level of detail the sampler may use, in quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it unclamped.
+pub inline fn setTextureView(_stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32, _lodMin: u8, _lodMax: u8) void {
+ return bgfx_set_texture_view(_stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags, _lodMin, _lodMax);
}
-extern fn bgfx_set_texture_view(_stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32) void;
+extern fn bgfx_set_texture_view(_stage: u8, _sampler: UniformHandle, _handle: TextureHandle, _firstLayer: u16, _numLayers: u16, _firstMip: u8, _numMips: u8, _flags: u32, _lodMin: u8, _lodMax: u8) void;
/// Submit an empty primitive for rendering. Uniforms and draw state
/// will be applied but no geometry will be submitted.
diff --git a/docs/bgfx.rst b/docs/bgfx.rst
index 776ee1555..2fff5ee77 100644
--- a/docs/bgfx.rst
+++ b/docs/bgfx.rst
@@ -462,7 +462,7 @@ Textures
Bind textures to texture stages for draw calls.
.. doxygenfunction:: bgfx::setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags = UINT32_MAX)
-.. doxygenfunction:: bgfx::setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags = UINT32_MAX)
+.. doxygenfunction:: bgfx::setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags = UINT32_MAX, uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX)
Uniforms
********
diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h
index 6c56eafa9..61ea6c370 100644
--- a/include/bgfx/bgfx.h
+++ b/include/bgfx/bgfx.h
@@ -1766,6 +1766,11 @@ namespace bgfx
/// mode.
/// - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
/// sampling.
+ /// @param[in] _lodMin Lowest (most detailed) level of detail the sampler may use, in
+ /// quarter-mip steps, relative to `_firstMip`.
+ /// @param[in] _lodMax Highest (least detailed) level of detail the sampler may use, in
+ /// quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it
+ /// unclamped.
///
/// @attention C99's equivalent binding is `bgfx_encoder_set_texture_view`.
///
@@ -1778,6 +1783,8 @@ namespace bgfx
, uint8_t _firstMip
, uint8_t _numMips
, uint32_t _flags = UINT32_MAX
+ , uint8_t _lodMin = 0
+ , uint8_t _lodMax = UINT8_MAX
);
/// Submit an empty primitive for rendering. Uniforms and draw state
@@ -3416,6 +3423,7 @@ namespace bgfx
/// @param[in] _width Width.
/// @param[in] _height Height.
/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ /// Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// @param[in] _numLayers Number of layers in texture array.
/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
/// @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -3449,6 +3457,7 @@ namespace bgfx
///
/// @param[in] _ratio Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`.
/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ /// Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// @param[in] _numLayers Number of layers in texture array.
/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
/// @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -3476,6 +3485,7 @@ namespace bgfx
/// @param[in] _height Height.
/// @param[in] _depth Depth.
/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ /// Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
/// @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
/// flags. Default texture sampling mode is linear, and wrap mode is repeat.
@@ -3507,6 +3517,7 @@ namespace bgfx
///
/// @param[in] _size Cube side size.
/// @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ /// Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
/// @param[in] _numLayers Number of layers in texture array.
/// @param[in] _format Texture format. See: `TextureFormat::Enum`.
/// @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -4941,6 +4952,11 @@ namespace bgfx
/// mode.
/// - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
/// sampling.
+ /// @param[in] _lodMin Lowest (most detailed) level of detail the sampler may use, in
+ /// quarter-mip steps, relative to `_firstMip`.
+ /// @param[in] _lodMax Highest (least detailed) level of detail the sampler may use, in
+ /// quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it
+ /// unclamped.
///
/// @attention C99's equivalent binding is `bgfx_set_texture_view`.
///
@@ -4953,6 +4969,8 @@ namespace bgfx
, uint8_t _firstMip
, uint8_t _numMips
, uint32_t _flags = UINT32_MAX
+ , uint8_t _lodMin = 0
+ , uint8_t _lodMax = UINT8_MAX
);
/// Submit an empty primitive for rendering. Uniforms and draw state
diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h
index 2e24f2928..2ac24fc2b 100644
--- a/include/bgfx/c99/bgfx.h
+++ b/include/bgfx/c99/bgfx.h
@@ -2318,6 +2318,7 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem,
* @param[in] _width Width.
* @param[in] _height Height.
* @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ * Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
* @param[in] _numLayers Number of layers in texture array.
* @param[in] _format Texture format. See: `TextureFormat::Enum`.
* @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -2342,6 +2343,7 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_
*
* @param[in] _ratio Texture size in respect to back-buffer size. See: `BackbufferRatio::Enum`.
* @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ * Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
* @param[in] _numLayers Number of layers in texture array.
* @param[in] _format Texture format. See: `TextureFormat::Enum`.
* @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -2363,6 +2365,7 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_r
* @param[in] _height Height.
* @param[in] _depth Depth.
* @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ * Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
* @param[in] _format Texture format. See: `TextureFormat::Enum`.
* @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
* flags. Default texture sampling mode is linear, and wrap mode is repeat.
@@ -2385,6 +2388,7 @@ BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_
*
* @param[in] _size Cube side size.
* @param[in] _hasMips Indicates that texture contains full mip-map chain.
+ * Ignored when `BGFX_TEXTURE_MIP_COUNT` is set in _flags.
* @param[in] _numLayers Number of layers in texture array.
* @param[in] _format Texture format. See: `TextureFormat::Enum`.
* @param[in] _flags Texture creation (see `BGFX_TEXTURE_*`.), and sampler (see `BGFX_SAMPLER_*`)
@@ -3451,9 +3455,14 @@ BGFX_C_API void bgfx_encoder_set_texture(bgfx_encoder_t* _this, uint8_t _stage,
* mode.
* - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
* sampling.
+ * @param[in] _lodMin Lowest (most detailed) level of detail the sampler may use, in
+ * quarter-mip steps, relative to `_firstMip`.
+ * @param[in] _lodMax Highest (least detailed) level of detail the sampler may use, in
+ * quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it
+ * unclamped.
*
*/
-BGFX_C_API void bgfx_encoder_set_texture_view(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags);
+BGFX_C_API void bgfx_encoder_set_texture_view(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax);
/**
* Submit an empty primitive for rendering. Uniforms and draw state
@@ -4177,9 +4186,14 @@ BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler,
* mode.
* - `BGFX_SAMPLER_[MIN/MAG/MIP]_[POINT/ANISOTROPIC]` - Point or anisotropic
* sampling.
+ * @param[in] _lodMin Lowest (most detailed) level of detail the sampler may use, in
+ * quarter-mip steps, relative to `_firstMip`.
+ * @param[in] _lodMax Highest (least detailed) level of detail the sampler may use, in
+ * quarter-mip steps, relative to `_firstMip`. `UINT8_MAX` leaves it
+ * unclamped.
*
*/
-BGFX_C_API void bgfx_set_texture_view(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags);
+BGFX_C_API void bgfx_set_texture_view(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax);
/**
* Submit an empty primitive for rendering. Uniforms and draw state
@@ -4855,7 +4869,7 @@ struct bgfx_interface_vtbl
void (*encoder_set_instance_data_from_dynamic_vertex_buffer)(bgfx_encoder_t* _this, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*encoder_set_instance_count)(bgfx_encoder_t* _this, uint32_t _numInstances);
void (*encoder_set_texture)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
- void (*encoder_set_texture_view)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags);
+ void (*encoder_set_texture_view)(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax);
void (*encoder_touch)(bgfx_encoder_t* _this, bgfx_view_id_t _id);
void (*encoder_submit)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags);
void (*encoder_submit_occlusion_query)(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags);
@@ -4907,7 +4921,7 @@ struct bgfx_interface_vtbl
void (*set_instance_data_from_dynamic_vertex_buffer)(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num);
void (*set_instance_count)(uint32_t _numInstances);
void (*set_texture)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags);
- void (*set_texture_view)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags);
+ void (*set_texture_view)(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax);
void (*touch)(bgfx_view_id_t _id);
void (*submit)(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags);
void (*submit_occlusion_query)(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags);
diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h
index 79204634c..099a8adf3 100644
--- a/include/bgfx/defines.h
+++ b/include/bgfx/defines.h
@@ -320,6 +320,18 @@
#define BGFX_TEXTURE_RT_SHIFT 36
#define BGFX_TEXTURE_RT_MASK UINT64_C(0x000000f000000000)
+/**
+ * Mip level count, `BGFX_TEXTURE_MIP_COUNT(n)`. Overrides `_hasMips` of
+ * `createTexture2D`, `createTexture3D` and `createTextureCube`: the texture
+ * gets `n` levels, clamped to the full chain for its size. Zero keeps the
+ * `_hasMips` behaviour. A texture created from an image container keeps the
+ * container's level count.
+ *
+ */
+#define BGFX_TEXTURE_MIP_COUNT_SHIFT 49 //!< Mip level count bit shift
+#define BGFX_TEXTURE_MIP_COUNT_MASK UINT64_C(0x003e000000000000) //!< Mip level count bit mask
+#define BGFX_TEXTURE_MIP_COUNT(v) ( ( (uint64_t)(v)<m_uniformHandle, _sampler);
BGFX_CHECK_HANDLE_INVALID_OK("setTexture/TextureHandle", s_ctx->m_textureHandle, _handle);
@@ -4619,7 +4619,7 @@ namespace bgfx
BX_UNUSED(ref);
}
- BGFX_ENCODER(setTexture(_stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags) );
+ BGFX_ENCODER(setTexture(_stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags, _lodMin, _lodMax) );
}
void Encoder::touch(ViewId _id)
@@ -6109,6 +6109,27 @@ namespace bgfx
bimg::imageGetSize( (bimg::TextureInfo*)&_info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bimg::TextureFormat::Enum(_format) );
}
+ static uint32_t calcTextureStorageSize(uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint8_t _numMips, uint16_t _numLayers, TextureFormat::Enum _format)
+ {
+ uint64_t size = 0;
+
+ for (uint8_t mip = 0; mip < _numMips; ++mip)
+ {
+ size += bimg::imageGetSize(
+ NULL
+ , bx::max(1, _width >> mip)
+ , bx::max(1, _height >> mip)
+ , bx::max(1, _depth >> mip)
+ , _cubeMap
+ , false
+ , 1
+ , bimg::TextureFormat::Enum(_format)
+ );
+ }
+
+ return uint32_t(size*_numLayers);
+ }
+
TextureHandle createTexture(const Memory* _mem, uint64_t _flags, uint8_t _skip, TextureInfo* _info)
{
BX_ASSERT(NULL != _mem, "_mem can't be NULL");
@@ -6175,18 +6196,17 @@ namespace bgfx
return BGFX_INVALID_HANDLE;
}
- const uint8_t numMips = calcNumMips(_hasMips, _width, _height);
+ const uint8_t numMips = calcNumMips(flags, _hasMips, _width, _height);
_numLayers = bx::max(_numLayers, 1);
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& NULL != _mem
&& 0 == (flags & BGFX_TEXTURE_INTERNAL_VIDEO_DECODE_DST) )
{
- TextureInfo ti;
- calcTextureSize(ti, _width, _height, 1, false, _hasMips, _numLayers, _format);
- BX_ASSERT(ti.storageSize == _mem->size
+ const uint32_t storageSize = calcTextureStorageSize(_width, _height, 1, false, numMips, _numLayers, _format);
+ BX_ASSERT(storageSize == _mem->size
, "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
- , ti.storageSize
+ , storageSize
, _mem->size
);
}
@@ -6250,16 +6270,15 @@ namespace bgfx
return BGFX_INVALID_HANDLE;
}
- const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth);
+ const uint8_t numMips = calcNumMips(_flags, _hasMips, _width, _height, _depth);
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& NULL != _mem)
{
- TextureInfo ti;
- calcTextureSize(ti, _width, _height, _depth, false, _hasMips, 1, _format);
- BX_ASSERT(ti.storageSize == _mem->size
+ const uint32_t storageSize = calcTextureStorageSize(_width, _height, _depth, false, numMips, 1, _format);
+ BX_ASSERT(storageSize == _mem->size
, "createTexture3D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
- , ti.storageSize
+ , storageSize
, _mem->size
);
}
@@ -6301,17 +6320,16 @@ namespace bgfx
return BGFX_INVALID_HANDLE;
}
- const uint8_t numMips = calcNumMips(_hasMips, _size, _size);
+ const uint8_t numMips = calcNumMips(_flags, _hasMips, _size, _size);
_numLayers = bx::max(_numLayers, 1);
if (BX_ENABLED(BGFX_CONFIG_DEBUG)
&& NULL != _mem)
{
- TextureInfo ti;
- calcTextureSize(ti, _size, _size, 1, true, _hasMips, _numLayers, _format);
- BX_ASSERT(ti.storageSize == _mem->size
+ const uint32_t storageSize = calcTextureStorageSize(_size, _size, 1, true, numMips, _numLayers, _format);
+ BX_ASSERT(storageSize == _mem->size
, "createTextureCube: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)"
- , ti.storageSize
+ , storageSize
, _mem->size
);
}
@@ -6956,10 +6974,10 @@ namespace bgfx
s_ctx->m_encoder0->setTexture(_stage, _sampler, _handle, _flags);
}
- void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags)
+ void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax)
{
BGFX_CHECK_ENCODER0();
- s_ctx->m_encoder0->setTexture(_stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags);
+ s_ctx->m_encoder0->setTexture(_stage, _sampler, _handle, _firstLayer, _numLayers, _firstMip, _numMips, _flags, _lodMin, _lodMax);
}
void touch(ViewId _id)
diff --git a/src/bgfx.idl.inl b/src/bgfx.idl.inl
index 30bc021e5..b94d59d88 100644
--- a/src/bgfx.idl.inl
+++ b/src/bgfx.idl.inl
@@ -981,12 +981,12 @@ BGFX_C_API void bgfx_encoder_set_texture(bgfx_encoder_t* _this, uint8_t _stage,
This->setTexture(_stage, sampler.cpp, handle.cpp, _flags);
}
-BGFX_C_API void bgfx_encoder_set_texture_view(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags)
+BGFX_C_API void bgfx_encoder_set_texture_view(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax)
{
bgfx::Encoder* This = (bgfx::Encoder*)_this;
union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler };
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
- This->setTexture(_stage, sampler.cpp, handle.cpp, _firstLayer, _numLayers, _firstMip, _numMips, _flags);
+ This->setTexture(_stage, sampler.cpp, handle.cpp, _firstLayer, _numLayers, _firstMip, _numMips, _flags, _lodMin, _lodMax);
}
BGFX_C_API void bgfx_encoder_touch(bgfx_encoder_t* _this, bgfx_view_id_t _id)
@@ -1306,11 +1306,11 @@ BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler,
bgfx::setTexture(_stage, sampler.cpp, handle.cpp, _flags);
}
-BGFX_C_API void bgfx_set_texture_view(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags)
+BGFX_C_API void bgfx_set_texture_view(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax)
{
union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler };
union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle };
- bgfx::setTexture(_stage, sampler.cpp, handle.cpp, _firstLayer, _numLayers, _firstMip, _numMips, _flags);
+ bgfx::setTexture(_stage, sampler.cpp, handle.cpp, _firstLayer, _numLayers, _firstMip, _numMips, _flags, _lodMin, _lodMax);
}
BGFX_C_API void bgfx_touch(bgfx_view_id_t _id)
diff --git a/src/bgfx_p.h b/src/bgfx_p.h
index 7af637d81..2656d34bf 100644
--- a/src/bgfx_p.h
+++ b/src/bgfx_p.h
@@ -764,6 +764,18 @@ namespace bgfx
return 1;
}
+ inline constexpr uint8_t calcNumMips(uint64_t _flags, bool _hasMips, uint16_t _width, uint16_t _height, uint16_t _depth = 1)
+ {
+ const uint8_t requested = uint8_t( (_flags & BGFX_TEXTURE_MIP_COUNT_MASK) >> BGFX_TEXTURE_MIP_COUNT_SHIFT);
+
+ if (0 == requested)
+ {
+ return calcNumMips(_hasMips, _width, _height, _depth);
+ }
+
+ return bx::min(requested, calcNumMips(true, _width, _height, _depth) );
+ }
+
/// Dump vertex layout info into debug output.
void dump(const VertexLayout& _layout);
@@ -2395,6 +2407,13 @@ namespace bgfx
Count
};
+ struct LodClamp
+ {
+ uint8_t min;
+ uint8_t max;
+ uint8_t pad[2];
+ };
+
void reset()
{
m_samplerFlags = BGFX_SAMPLER_NONE;
@@ -2414,7 +2433,10 @@ namespace bgfx
void setTexture(TextureHandle _handle, uint32_t _samplerFlags, uint8_t _firstMip = 0, uint8_t _numMips = UINT8_MAX)
{
m_samplerFlags = _samplerFlags;
- m_offset = 0;
+ m_lod.min = 0;
+ m_lod.max = UINT8_MAX;
+ m_lod.pad[0] = 0;
+ m_lod.pad[1] = 0;
m_size = UINT32_MAX;
m_firstLayer = 0;
m_numLayers = UINT16_MAX;
@@ -2427,10 +2449,13 @@ namespace bgfx
m_pad = 0;
}
- void setTexture(TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _samplerFlags)
+ void setTexture(TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _samplerFlags, uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX)
{
m_samplerFlags = _samplerFlags;
- m_offset = 0;
+ m_lod.min = _lodMin;
+ m_lod.max = _lodMax;
+ m_lod.pad[0] = 0;
+ m_lod.pad[1] = 0;
m_size = UINT32_MAX;
m_firstLayer = _firstLayer;
m_numLayers = _numLayers;
@@ -2501,10 +2526,17 @@ namespace bgfx
return kInvalidHandle != m_idx;
}
- bool operator==(const Binding& _rhs) const = default;
+ bool operator==(const Binding& _rhs) const
+ {
+ return 0 == bx::memCmp(this, &_rhs, sizeof(Binding) );
+ }
uint32_t m_samplerFlags;
- uint32_t m_offset;
+ union
+ {
+ uint32_t m_offset;
+ LodClamp m_lod;
+ };
uint32_t m_size;
uint16_t m_firstLayer;
uint16_t m_numLayers;
@@ -4369,7 +4401,7 @@ namespace bgfx
}
}
- void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags)
+ void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint32_t _flags, uint8_t _lodMin, uint8_t _lodMax)
{
Binding bind;
bind.setTexture(
@@ -4381,6 +4413,8 @@ namespace bgfx
, 0 != (_flags&BGFX_SAMPLER_INTERNAL_DEFAULT)
? BGFX_SAMPLER_INTERNAL_DEFAULT
: _flags
+ , _lodMin
+ , _lodMax
);
setBind(_stage, bind);
@@ -6980,7 +7014,7 @@ namespace bgfx
BX_ASSERT(BackbufferRatio::Count != ref.m_bbRatio, "");
getTextureSizeFromRatio(BackbufferRatio::Enum(ref.m_bbRatio), _width, _height);
- _numMips = calcNumMips(1 < _numMips, _width, _height);
+ _numMips = calcNumMips(ref.m_flags, 1 < _numMips, _width, _height);
ref.m_width = _width;
ref.m_height = _height;
diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp
index 3ebe8b4ee..589b00b18 100644
--- a/src/renderer_d3d11.cpp
+++ b/src/renderer_d3d11.cpp
@@ -3155,7 +3155,7 @@ namespace bgfx { namespace d3d11
m_deviceCtx->RSSetState(rs);
}
- ID3D11SamplerState* getSamplerState(uint32_t _flags, const float _rgba[4])
+ ID3D11SamplerState* getSamplerState(uint32_t _flags, const float _rgba[4], uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX)
{
const uint32_t index = (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT;
_flags &= BGFX_SAMPLER_BITS_MASK;
@@ -3169,12 +3169,14 @@ namespace bgfx { namespace d3d11
uint32_t hash;
ID3D11SamplerState* sampler;
+ const uint32_t lod = (uint32_t(_lodMin) << 8) | _lodMax;
if (!needBorderColor(_flags) )
{
bx::HashMurmur2A murmur;
murmur.begin();
murmur.add(_flags);
murmur.add(-1);
+ murmur.add(lod);
hash = murmur.end();
_rgba = s_zero.m_zerof;
@@ -3186,6 +3188,7 @@ namespace bgfx { namespace d3d11
murmur.begin();
murmur.add(_flags);
murmur.add(index);
+ murmur.add(lod);
hash = murmur.end();
_rgba = NULL == _rgba ? s_zero.m_zerof : _rgba;
@@ -3223,8 +3226,8 @@ namespace bgfx { namespace d3d11
sd.BorderColor[1] = _rgba[1];
sd.BorderColor[2] = _rgba[2];
sd.BorderColor[3] = _rgba[3];
- sd.MinLOD = 0;
- sd.MaxLOD = D3D11_FLOAT32_MAX;
+ sd.MinLOD = float(_lodMin) * 0.25f;
+ sd.MaxLOD = UINT8_MAX == _lodMax ? D3D11_FLOAT32_MAX : float(_lodMax) * 0.25f;
DX_CHECK(m_device->CreateSamplerState(&sd, &sampler));
DX_CHECK_REFCOUNT(sampler, 1);
@@ -5517,7 +5520,7 @@ namespace bgfx { namespace d3d11
}
}
- void TextureD3D11::commit(uint8_t _stage, uint32_t _flags, const float _palette[][4], uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, TextureDimension::Enum _dimension)
+ void TextureD3D11::commit(uint8_t _stage, uint32_t _flags, const float _palette[][4], uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint8_t _lodMin, uint8_t _lodMax, TextureDimension::Enum _dimension)
{
TextureStage& ts = s_renderD3D11->m_textureStage;
@@ -5590,7 +5593,7 @@ namespace bgfx { namespace d3d11
}
uint32_t index = (flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT;
- ts.m_sampler[_stage] = s_renderD3D11->getSamplerState(flags, _palette[index]);
+ ts.m_sampler[_stage] = s_renderD3D11->getSamplerState(flags, _palette[index], _lodMin, _lodMax);
}
void TextureD3D11::resolve(uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip) const
@@ -7102,7 +7105,7 @@ namespace bgfx { namespace d3d11
{
TextureD3D11& texture = m_textures[bind.m_idx];
const ProgramD3D11* program = m_currentProgram;
- texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstLayer, bind.m_numLayers, bind.m_firstMip, bind.m_numMips
+ texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstLayer, bind.m_numLayers, bind.m_firstMip, bind.m_numMips, bind.m_lod.min, bind.m_lod.max
, NULL != program ? program->getTextureDimension(stage) : TextureDimension::Count
);
}
@@ -7462,7 +7465,7 @@ namespace bgfx { namespace d3d11
{
TextureD3D11& texture = m_textures[bind.m_idx];
const ProgramD3D11* program = m_currentProgram;
- texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstLayer, bind.m_numLayers, bind.m_firstMip, bind.m_numMips
+ texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstLayer, bind.m_numLayers, bind.m_firstMip, bind.m_numMips, bind.m_lod.min, bind.m_lod.max
, NULL != program ? program->getTextureDimension(stage) : TextureDimension::Count
);
}
diff --git a/src/renderer_d3d11.h b/src/renderer_d3d11.h
index 609057cca..48729695c 100644
--- a/src/renderer_d3d11.h
+++ b/src/renderer_d3d11.h
@@ -365,7 +365,7 @@ namespace bgfx { namespace d3d11
void destroy();
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
void clear(uint8_t _mip, uint8_t _numMips, uint16_t _layer, uint16_t _numLayers);
- void commit(uint8_t _stage, uint32_t _flags, const float _palette[][4], uint16_t _firstLayer = 0, uint16_t _numLayers = UINT16_MAX, uint8_t _firstMip = 0, uint8_t _numMips = UINT8_MAX, TextureDimension::Enum _dimension = TextureDimension::Count);
+ void commit(uint8_t _stage, uint32_t _flags, const float _palette[][4], uint16_t _firstLayer = 0, uint16_t _numLayers = UINT16_MAX, uint8_t _firstMip = 0, uint8_t _numMips = UINT8_MAX, uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX, TextureDimension::Enum _dimension = TextureDimension::Count);
void resolve(uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip) const;
TextureHandle getHandle() const;
DXGI_FORMAT getSrvFormat(SrgbSelect::Enum _srgb = SrgbSelect::Native) const;
diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp
index 04f379312..cd5a6539f 100644
--- a/src/renderer_d3d12.cpp
+++ b/src/renderer_d3d12.cpp
@@ -4271,14 +4271,20 @@ namespace bgfx { namespace d3d12
return pso;
}
- uint16_t getSamplerState(const uint32_t* _flags, uint32_t _num, const float _palette[][4])
+ uint16_t getSamplerState(const uint32_t* _flags, uint32_t _num, const float _palette[][4], const uint16_t* _lod = NULL)
{
bx::HashMurmur3 murmur;
murmur.begin();
murmur.add(_flags, _num * sizeof(uint32_t) );
+
+ if (NULL != _lod)
+ {
+ murmur.add(_lod, _num * sizeof(uint16_t) );
+ }
+
uint32_t hash = murmur.end();
- return m_samplerAllocator.alloc(hash, _flags, _num, _palette);
+ return m_samplerAllocator.alloc(hash, _flags, _num, _palette, _lod);
}
bool isVisible(Frame* _render, OcclusionQueryHandle _handle, bool _visible)
@@ -5231,7 +5237,7 @@ namespace bgfx { namespace d3d12
return idx;
}
- uint16_t DescriptorAllocatorD3D12::alloc(uint32_t _hash, const uint32_t* _flags, uint32_t _num, const float _palette[][4])
+ uint16_t DescriptorAllocatorD3D12::alloc(uint32_t _hash, const uint32_t* _flags, uint32_t _num, const float _palette[][4], const uint16_t* _lod)
{
uint16_t idx = m_stateCache.find(_hash);
if (UINT16_MAX != idx)
@@ -5290,8 +5296,11 @@ namespace bgfx { namespace d3d12
sd.BorderColor[2] = 0.0f;
sd.BorderColor[3] = 0.0f;
}
- sd.MinLOD = 0;
- sd.MaxLOD = D3D12_FLOAT32_MAX;
+ const uint8_t lodMin = NULL != _lod ? uint8_t(_lod[ii] >> 8) : 0;
+ const uint8_t lodMax = NULL != _lod ? uint8_t(_lod[ii] & 0xff) : UINT8_MAX;
+
+ sd.MinLOD = float(lodMin) * 0.25f;
+ sd.MaxLOD = UINT8_MAX == lodMax ? D3D12_FLOAT32_MAX : float(lodMax) * 0.25f;
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle =
{
@@ -9803,6 +9812,8 @@ namespace bgfx { namespace d3d12
uint32_t numSet = 0;
D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_MAX_COMPUTE_BINDINGS] = {};
uint32_t samplerFlags[BGFX_MAX_COMPUTE_BINDINGS] = {};
+ uint16_t samplerLod[BGFX_MAX_COMPUTE_BINDINGS];
+ bx::memSet(samplerLod, 0xff, sizeof(samplerLod) );
{
const ProgramD3D12& program = m_program[key.m_program.idx];
@@ -9851,6 +9862,7 @@ namespace bgfx { namespace d3d12
, srgbSelect(resolvedFlags, BGFX_SAMPLER_SRGB)
);
samplerFlags[stage] = resolvedFlags & (BGFX_SAMPLER_BITS_MASK | BGFX_SAMPLER_BORDER_COLOR_MASK | BGFX_SAMPLER_COMPARE_MASK);
+ samplerLod[stage] = uint16_t(uint16_t(bind.m_lod.min)<<8) | bind.m_lod.max;
++numSet;
}
@@ -9891,7 +9903,7 @@ namespace bgfx { namespace d3d12
{
Bind& bind = bindCache[bindIdx];
bind.m_srvHandle = srvHandle[0];
- bind.m_samplerStateIdx = getSamplerState(samplerFlags, maxComputeBindings, _render->m_colorPalette);
+ bind.m_samplerStateIdx = getSamplerState(samplerFlags, maxComputeBindings, _render->m_colorPalette, samplerLod);
bind.m_rawSrvMask = currentRawSrvMask;
bind.m_rawUavMask = currentRawUavMask;
bind.m_texDimHash = currentTexDimHash;
@@ -10185,6 +10197,8 @@ namespace bgfx { namespace d3d12
uint32_t numSet = 0;
D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {};
uint32_t samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {};
+ uint16_t samplerLod[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+ bx::memSet(samplerLod, 0xff, sizeof(samplerLod) );
{
const ProgramD3D12& program = m_program[key.m_program.idx];
@@ -10233,6 +10247,7 @@ namespace bgfx { namespace d3d12
, srgbSelect(resolvedFlags, BGFX_SAMPLER_SRGB)
);
samplerFlags[stage] = resolvedFlags & (BGFX_SAMPLER_BITS_MASK | BGFX_SAMPLER_BORDER_COLOR_MASK | BGFX_SAMPLER_COMPARE_MASK);
+ samplerLod[stage] = uint16_t(uint16_t(bind.m_lod.min)<<8) | bind.m_lod.max;
++numSet;
}
@@ -10276,7 +10291,7 @@ namespace bgfx { namespace d3d12
{
Bind& bind = bindCache[bindIdx];
bind.m_srvHandle = srvHandle[0];
- bind.m_samplerStateIdx = getSamplerState(samplerFlags, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, _render->m_colorPalette);
+ bind.m_samplerStateIdx = getSamplerState(samplerFlags, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, _render->m_colorPalette, samplerLod);
bind.m_rawSrvMask = currentRawSrvMask;
bind.m_rawUavMask = currentRawUavMask;
bind.m_texDimHash = currentTexDimHash;
diff --git a/src/renderer_d3d12.h b/src/renderer_d3d12.h
index d2f637958..995ef6f91 100644
--- a/src/renderer_d3d12.h
+++ b/src/renderer_d3d12.h
@@ -211,7 +211,7 @@ namespace bgfx { namespace d3d12
void destroy();
uint16_t alloc(ID3D12Resource* _ptr, const D3D12_SHADER_RESOURCE_VIEW_DESC* _desc);
- uint16_t alloc(uint32_t _hash, const uint32_t* _flags, uint32_t _num, const float _palette[][4]);
+ uint16_t alloc(uint32_t _hash, const uint32_t* _flags, uint32_t _num, const float _palette[][4], const uint16_t* _lod = NULL);
void free(uint16_t _handle);
void reset();
diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp
index 2c3d1e1a3..f4567435c 100644
--- a/src/renderer_gl.cpp
+++ b/src/renderer_gl.cpp
@@ -4098,12 +4098,12 @@ namespace bgfx { namespace gl
{
FrameBufferGL& frameBuffer = m_frameBuffers[m_fbh.idx];
- m_glctx.makeCurrent(UINT16_MAX != frameBuffer.m_denseIdx
- ? frameBuffer.m_swapChain
- : NULL
- );
+ if (UINT16_MAX == frameBuffer.m_denseIdx)
+ {
+ m_glctx.makeCurrent(NULL);
+ frameBuffer.resolve();
+ }
- frameBuffer.resolve();
m_rtMsaa = false;
}
}
@@ -4491,7 +4491,7 @@ namespace bgfx { namespace gl
m_textureViewStateCache.invalidate();
}
- void setSamplerState(uint32_t _stage, uint32_t _numMips, uint32_t _flags, const float _rgba[4])
+ void setSamplerState(uint32_t _stage, uint32_t _numMips, uint32_t _flags, const float _rgba[4], uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX)
{
BX_ASSERT(m_samplerObjectSupport, "Cannot use Sampler Objects");
@@ -4505,6 +4505,8 @@ namespace bgfx { namespace gl
_flags |= srgb;
_flags |= _numMips<= 30) )
+ {
+ GL_CHECK(glTexParameterf(target, GL_TEXTURE_MIN_LOD, float(_lodMin) * 0.25f) );
+ GL_CHECK(glTexParameterf(target, GL_TEXTURE_MAX_LOD, UINT8_MAX == _lodMax ? 1000.0f : float(_lodMax) * 0.25f) );
+ }
+
if (s_renderGL->m_borderColorSupport
&& hasBorderColor)
{
@@ -6978,7 +6993,7 @@ namespace bgfx { namespace gl
return viewId;
}
- void TextureGL::commit(uint32_t _stage, uint32_t _flags, const float _palette[][4], uint8_t _firstMip, uint8_t _numMips, uint16_t _firstLayer, uint16_t _numLayers)
+ void TextureGL::commit(uint32_t _stage, uint32_t _flags, const float _palette[][4], uint8_t _firstMip, uint8_t _numMips, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _lodMin, uint8_t _lodMax)
{
const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags)
? _flags
@@ -7016,11 +7031,11 @@ namespace bgfx { namespace gl
if (s_renderGL->m_samplerObjectSupport)
{
- s_renderGL->setSamplerState(_stage, m_numMips, samplerFlags, _palette[index]);
+ s_renderGL->setSamplerState(_stage, m_numMips, samplerFlags, _palette[index], _lodMin, _lodMax);
}
else
{
- setSamplerState(samplerFlags, _palette[index]);
+ setSamplerState(samplerFlags, _palette[index], _lodMin, _lodMax);
}
if (id == m_id
@@ -8945,7 +8960,7 @@ namespace bgfx { namespace gl
case Binding::Texture:
{
TextureGL& texture = m_textures[bind.m_idx];
- texture.commit(ii, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers);
+ texture.commit(ii, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers, bind.m_lod.min, bind.m_lod.max);
}
break;
@@ -9622,7 +9637,7 @@ namespace bgfx { namespace gl
case Binding::Texture:
{
TextureGL& texture = m_textures[bind.m_idx];
- texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers);
+ texture.commit(stage, bind.m_samplerFlags, _render->m_colorPalette, bind.m_firstMip, bind.m_numMips, bind.m_firstLayer, bind.m_numLayers, bind.m_lod.min, bind.m_lod.max);
}
break;
diff --git a/src/renderer_gl.h b/src/renderer_gl.h
index 4ffc91f42..98f14417a 100644
--- a/src/renderer_gl.h
+++ b/src/renderer_gl.h
@@ -878,6 +878,14 @@ typedef double GLdouble;
# define GL_TEXTURE_MAX_LEVEL 0x813D
#endif // GL_TEXTURE_MAX_LEVEL
+#ifndef GL_TEXTURE_MIN_LOD
+# define GL_TEXTURE_MIN_LOD 0x813A
+#endif // GL_TEXTURE_MIN_LOD
+
+#ifndef GL_TEXTURE_MAX_LOD
+# define GL_TEXTURE_MAX_LOD 0x813B
+#endif // GL_TEXTURE_MAX_LOD
+
#ifndef GL_COMPUTE_SHADER
# define GL_COMPUTE_SHADER 0x91B9
#endif // GL_COMPUTE_SHADER
@@ -1490,8 +1498,8 @@ namespace bgfx { namespace gl
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
void clear(uint8_t _mip, uint8_t _numMips, uint16_t _layer, uint16_t _numLayers);
void clearAttached(uint8_t _mipBeg, uint8_t _mipEnd, uint16_t _layer, uint16_t _numLayers);
- void setSamplerState(uint32_t _flags, const float _rgba[4]);
- void commit(uint32_t _stage, uint32_t _flags, const float _palette[][4], uint8_t _firstMip, uint8_t _numMips, uint16_t _firstLayer, uint16_t _numLayers);
+ void setSamplerState(uint32_t _flags, const float _rgba[4], uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX);
+ void commit(uint32_t _stage, uint32_t _flags, const float _palette[][4], uint8_t _firstMip, uint8_t _numMips, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX);
GLenum getViewTarget(uint16_t _numLayers, bool _layered = false) const;
GLuint getViewId(uint8_t _firstMip, uint8_t _numMips, uint16_t _firstLayer, uint16_t _numLayers, GLenum* _target = NULL, bool _layered = false);
void resolve(uint8_t _resolve) const;
diff --git a/src/renderer_mtl.cpp b/src/renderer_mtl.cpp
index d7cf5be5b..8d196a1b9 100644
--- a/src/renderer_mtl.cpp
+++ b/src/renderer_mtl.cpp
@@ -3450,7 +3450,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
return result;
}
- MTL::SamplerState* getSamplerState(uint32_t _flags)
+ MTL::SamplerState* getSamplerState(uint32_t _flags, uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX)
{
const uint32_t index = bx::min(
BGFX_CONFIG_MAX_COLOR_PALETTE-1
@@ -3472,7 +3472,13 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
_flags |= uint32_t(borderColor) << BGFX_SAMPLER_BORDER_COLOR_SHIFT;
- MTL::SamplerState* sampler = m_samplerStateCache.find(_flags);
+ const uint64_t key = 0
+ | uint64_t(_flags)
+ | (uint64_t(_lodMin) << 40)
+ | (uint64_t(_lodMax) << 32)
+ ;
+
+ MTL::SamplerState* sampler = m_samplerStateCache.find(key);
if (NULL == sampler)
{
@@ -3484,8 +3490,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
desc->setMinFilter(s_textureFilterMinMag[(_flags & BGFX_SAMPLER_MIN_MASK) >> BGFX_SAMPLER_MIN_SHIFT]);
desc->setMagFilter(s_textureFilterMinMag[(_flags & BGFX_SAMPLER_MAG_MASK) >> BGFX_SAMPLER_MAG_SHIFT]);
desc->setMipFilter( s_textureFilterMip[(_flags & BGFX_SAMPLER_MIP_MASK) >> BGFX_SAMPLER_MIP_SHIFT]);
- desc->setLodMinClamp(0);
- desc->setLodMaxClamp(FLT_MAX);
+ desc->setLodMinClamp(float(_lodMin) * 0.25f);
+ desc->setLodMaxClamp(UINT8_MAX == _lodMax ? FLT_MAX : float(_lodMax) * 0.25f);
desc->setNormalizedCoordinates(TRUE);
desc->setBorderColor(borderColor);
desc->setMaxAnisotropy(true
@@ -3502,7 +3508,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
;
sampler = m_device->newSamplerState(desc);
- m_samplerStateCache.add(_flags, sampler);
+ m_samplerStateCache.add(key, sampler);
}
return sampler;
@@ -4619,7 +4625,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
}
- void TextureMtl::commit(uint8_t _stage, bool _vertex, bool _fragment, uint32_t _flags, uint8_t _mip, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips)
+ void TextureMtl::commit(uint8_t _stage, bool _vertex, bool _fragment, uint32_t _flags, uint8_t _mip, uint16_t _firstLayer, uint16_t _numLayers, uint8_t _firstMip, uint8_t _numMips, uint8_t _lodMin, uint8_t _lodMax)
{
if (!_vertex
&& !_fragment)
@@ -4643,7 +4649,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
s_renderMtl->m_renderCommandEncoder->setVertexTexture(ptr, _stage);
s_renderMtl->m_renderCommandEncoder->setVertexSamplerState(
0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags)
- ? s_renderMtl->getSamplerState(_flags)
+ ? s_renderMtl->getSamplerState(_flags, _lodMin, _lodMax)
: m_sampler
, _stage
);
@@ -4654,7 +4660,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
s_renderMtl->m_renderCommandEncoder->setFragmentTexture(ptr, _stage);
s_renderMtl->m_renderCommandEncoder->setFragmentSamplerState(
0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags)
- ? s_renderMtl->getSamplerState(_flags)
+ ? s_renderMtl->getSamplerState(_flags, _lodMin, _lodMax)
: m_sampler
, _stage
);
@@ -6544,7 +6550,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
);
m_computeCommandEncoder->setSamplerState(
0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & flags)
- ? getSamplerState(flags)
+ ? getSamplerState(flags, bind.m_lod.min, bind.m_lod.max)
: texture.m_sampler
, stage
);
@@ -6981,6 +6987,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
, bind.m_numLayers
, bind.m_firstMip
, bind.m_numMips
+ , bind.m_lod.min
+ , bind.m_lod.max
);
}
break;
diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h
index 181504829..8909ca587 100644
--- a/src/renderer_mtl.h
+++ b/src/renderer_mtl.h
@@ -487,6 +487,8 @@ namespace bgfx { namespace mtl
, uint16_t _numLayers = UINT16_MAX
, uint8_t _firstMip = 0
, uint8_t _numMips = UINT8_MAX
+ , uint8_t _lodMin = 0
+ , uint8_t _lodMax = UINT8_MAX
);
MTL::Texture* getTextureImage(uint8_t _mip, uint16_t _firstLayer = 0, uint16_t _numLayers = UINT16_MAX);
diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp
index 623099d08..eac7d0c1e 100644
--- a/src/renderer_vk.cpp
+++ b/src/renderer_vk.cpp
@@ -3958,11 +3958,13 @@ VK_IMPORT_DEVICE
return getRenderPass(num, formats, aspects, resolve, samples, _clearFlags, 0, _outRenderPass, _outHashKey);
}
- VkSampler getSampler(uint32_t _flags, VkFormat _format, const float _palette[][4])
+ VkSampler getSampler(uint32_t _flags, VkFormat _format, const float _palette[][4], uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX)
{
uint32_t index = ( (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT);
index = bx::min(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, index);
+ const uint32_t lod = (uint32_t(_lodMin) << 8) | _lodMax;
+
_flags &= BGFX_SAMPLER_BITS_MASK;
_flags &= ~(m_deviceFeatures.samplerAnisotropy ? 0 : (BGFX_SAMPLER_MIN_ANISOTROPIC | BGFX_SAMPLER_MAG_ANISOTROPIC) );
@@ -3992,6 +3994,7 @@ VK_IMPORT_DEVICE
hash.add(_flags);
hash.add(-1);
hash.add(VK_FORMAT_UNDEFINED);
+ hash.add(lod);
hashKey = hash.end();
sampler = m_samplerCache.find(hashKey);
@@ -4003,6 +4006,7 @@ VK_IMPORT_DEVICE
hash.add(_flags);
hash.add(index);
hash.add(_format);
+ hash.add(lod);
hashKey = hash.end();
const uint32_t colorHashKey = m_samplerBorderColorCache.find(hashKey);
@@ -4042,8 +4046,8 @@ VK_IMPORT_DEVICE
sci.maxAnisotropy = m_maxAnisotropy;
sci.compareEnable = 0 != cmpFunc;
sci.compareOp = s_cmpFunc[cmpFunc];
- sci.minLod = 0.0f;
- sci.maxLod = VK_LOD_CLAMP_NONE;
+ sci.minLod = float(_lodMin) * 0.25f;
+ sci.maxLod = UINT8_MAX == _lodMax ? VK_LOD_CLAMP_NONE : float(_lodMax) * 0.25f;
sci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
sci.unnormalizedCoordinates = VK_FALSE;
@@ -4626,7 +4630,7 @@ VK_IMPORT_DEVICE
: (uint32_t)texture.m_flags
;
const bool sampleStencil = !!(samplerFlags & BGFX_SAMPLER_SAMPLE_STENCIL);
- VkSampler sampler = getSampler(samplerFlags, texture.m_format, _palette);
+ VkSampler sampler = getSampler(samplerFlags, texture.m_format, _palette, bind.m_lod.min, bind.m_lod.max);
const VkImageViewType type = UINT32_MAX == bindInfo.index
? texture.m_type
diff --git a/src/renderer_webgpu.cpp b/src/renderer_webgpu.cpp
index 453f7ce9a..046a4b5cb 100644
--- a/src/renderer_webgpu.cpp
+++ b/src/renderer_webgpu.cpp
@@ -3641,7 +3641,7 @@ WGPU_IMPORT
.buffer = NULL,
.offset = 0,
.size = 0,
- .sampler = texture.getSamplerState(bind.m_samplerFlags),
+ .sampler = texture.getSamplerState(bind.m_samplerFlags, bind.m_lod.min, bind.m_lod.max),
.textureView = NULL,
};
}
@@ -5031,7 +5031,7 @@ WGPU_IMPORT
}
}
- WGPUSampler TextureWGPU::getSamplerState(uint32_t _samplerFlags) const
+ WGPUSampler TextureWGPU::getSamplerState(uint32_t _samplerFlags, uint8_t _lodMin, uint8_t _lodMax) const
{
uint32_t samplerFlags = (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _samplerFlags)
? _samplerFlags
@@ -5047,7 +5047,14 @@ WGPU_IMPORT
}
samplerFlags &= BGFX_SAMPLER_BITS_MASK;
- WGPUSampler sampler = s_renderWGPU->m_samplerStateCache.find(samplerFlags);
+
+ const uint64_t key = 0
+ | uint64_t(samplerFlags)
+ | (uint64_t(_lodMin) << 40)
+ | (uint64_t(_lodMax) << 32)
+ ;
+
+ WGPUSampler sampler = s_renderWGPU->m_samplerStateCache.find(key);
const bool disableAniso = true
&& (BGFX_SAMPLER_MIN_POINT == (samplerFlags&BGFX_SAMPLER_MIN_POINT) )
@@ -5067,14 +5074,14 @@ WGPU_IMPORT
.magFilter = s_textureFilterMinMag[(samplerFlags&BGFX_SAMPLER_MAG_MASK)>>BGFX_SAMPLER_MAG_SHIFT],
.minFilter = s_textureFilterMinMag[(samplerFlags&BGFX_SAMPLER_MIN_MASK)>>BGFX_SAMPLER_MIN_SHIFT],
.mipmapFilter = s_textureFilterMip[(samplerFlags&BGFX_SAMPLER_MIP_MASK)>>BGFX_SAMPLER_MIP_SHIFT],
- .lodMinClamp = 0,
- .lodMaxClamp = bx::kFloatLargest,
+ .lodMinClamp = float(_lodMin) * 0.25f,
+ .lodMaxClamp = UINT8_MAX == _lodMax ? bx::kFloatLargest : float(_lodMax) * 0.25f,
.compare = 0 == cmpFunc ? WGPUCompareFunction_Undefined : s_cmpFunc[cmpFunc],
.maxAnisotropy = disableAniso ? uint16_t(1) : s_renderWGPU->m_maxAnisotropy,
};
sampler = WGPU_CHECK(wgpuDeviceCreateSampler(s_renderWGPU->m_device, &samplerDesc) );
- s_renderWGPU->m_samplerStateCache.add(samplerFlags, sampler);
+ s_renderWGPU->m_samplerStateCache.add(key, sampler);
}
return sampler;
diff --git a/src/renderer_webgpu.h b/src/renderer_webgpu.h
index edb688de1..82c13b4ed 100644
--- a/src/renderer_webgpu.h
+++ b/src/renderer_webgpu.h
@@ -646,7 +646,7 @@ namespace wgpu {
void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem);
void clear(uint8_t _mip, uint8_t _numMips, uint16_t _layer, uint16_t _numLayers);
- WGPUSampler getSamplerState(uint32_t _samplerFlags) const;
+ WGPUSampler getSamplerState(uint32_t _samplerFlags, uint8_t _lodMin = 0, uint8_t _lodMax = UINT8_MAX) const;
WGPUTextureView getTextureView(uint8_t _baseMipLevel, uint8_t _mipLevelCount, bool _storage, uint16_t _baseArrayLayer = 0, uint16_t _arrayLayerCount = UINT16_MAX, WGPUTextureViewDimension _viewDimension = WGPUTextureViewDimension_Undefined, bool _stencil = false, WGPUTextureFormat _format = WGPUTextureFormat_Undefined) const;
WGPUTextureFormat getViewFormat(uint32_t _flags, uint32_t _bit) const;