Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bindings/bf/bgfx.bf
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,11 @@ public static class bgfx
/// Texture format supports auto-generated mips.
/// </summary>
TextureMipAutogen = 0x00008000,

/// <summary>
/// Texture format can be used as back buffer format.
/// </summary>
TextureBackbuffer = 0x00010000,
}

[AllowDuplicates]
Expand Down Expand Up @@ -2223,7 +2228,7 @@ public static class bgfx
public uint8 numGPUs;
public GPU[4] gpu;
public Limits limits;
public uint16[100] formats;
public uint32[100] formats;
}

[CRepr]
Expand Down
6 changes: 5 additions & 1 deletion bindings/c3/bgfx.c3
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ enum CapsFormatFlags : const uint

// Texture format supports auto-generated mips.
TEXTUREMIPAUTOGEN = 0x00008000,

// Texture format can be used as back buffer format.
TEXTUREBACKBUFFER = 0x00010000,
}

enum ResolveFlags : const uint
Expand Down Expand Up @@ -1510,7 +1513,8 @@ struct Caps
// - `BGFX_CAPS_FORMAT_TEXTURE_MSAA` - Texture can be sampled as MSAA.
// - `BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN` - Texture format supports auto-generated
// mips.
ushort[100] formats;
// - `BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER` - Texture format can be used as back buffer format.
uint[100] formats;
}

// Internal data.
Expand Down
7 changes: 6 additions & 1 deletion bindings/cs/bgfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,11 @@ public enum CapsFormatFlags : uint
/// Texture format supports auto-generated mips.
/// </summary>
TextureMipAutogen = 0x00008000,

/// <summary>
/// Texture format can be used as back buffer format.
/// </summary>
TextureBackbuffer = 0x00010000,
}

[Flags]
Expand Down Expand Up @@ -2202,7 +2207,7 @@ public unsafe struct Limits
public byte numGPUs;
public fixed uint gpu[4];
public Limits limits;
public fixed ushort formats[100];
public fixed uint formats[100];
}

public unsafe struct InternalData
Expand Down
6 changes: 4 additions & 2 deletions bindings/d/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import bindbc.common.types: c_int64, c_uint64, va_list;
import bindbc.bgfx.config;
static import bgfx.impl;

enum uint apiVersion = 139;
enum uint apiVersion = 140;

alias ViewID = ushort;

Expand Down Expand Up @@ -548,6 +548,7 @@ enum CapsFormat: CapsFormat_{
textureFramebufferMSAA = 0x0000_2000, ///Texture format can be used as MSAA frame buffer.
textureMSAA = 0x0000_4000, ///Texture can be sampled as MSAA.
textureMIPAutogen = 0x0000_8000, ///Texture format supports auto-generated mips.
textureBackbuffer = 0x0001_0000, ///Texture format can be used as back buffer format.
}

alias Resolve_ = ubyte;
Expand Down Expand Up @@ -1107,8 +1108,9 @@ extern(C++, "bgfx") struct Caps{
- `BGFX_CAPS_FORMAT_TEXTURE_MSAA` - Texture can be sampled as MSAA.
- `BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN` - Texture format supports auto-generated
mips.
- `BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER` - Texture format can be used as back buffer format.
*/
ushort[TextureFormat.count] formats;
uint[TextureFormat.count] formats;
}

///Internal data.
Expand Down
5 changes: 4 additions & 1 deletion bindings/zig/bgfx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ pub const CapsFormatFlags_TextureMsaa: CapsFormatFlags = 0x00004000;
/// Texture format supports auto-generated mips.
pub const CapsFormatFlags_TextureMipAutogen: CapsFormatFlags = 0x00008000;

/// Texture format can be used as back buffer format.
pub const CapsFormatFlags_TextureBackbuffer: CapsFormatFlags = 0x00010000;

pub const ResolveFlags = u32;
/// No resolve flags.
pub const ResolveFlags_None: ResolveFlags = 0x00000000;
Expand Down Expand Up @@ -1398,7 +1401,7 @@ pub const Caps = extern struct {
numGPUs: u8,
gpu: [4]GPU,
limits: Limits,
formats: [100]u16,
formats: [100]u32,
};

pub const InternalData = extern struct {
Expand Down
3 changes: 2 additions & 1 deletion include/bgfx/bgfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,8 @@ namespace bgfx
/// - `BGFX_CAPS_FORMAT_TEXTURE_MSAA` - Texture can be sampled as MSAA.
/// - `BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN` - Texture format supports auto-generated
/// mips.
uint16_t formats[TextureFormat::Count];
/// - `BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER` - Texture format can be used as back buffer format.
uint32_t formats[TextureFormat::Count];
};

/// Transient index buffer.
Expand Down
3 changes: 2 additions & 1 deletion include/bgfx/c99/bgfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,9 @@ typedef struct bgfx_caps_s
* - `BGFX_CAPS_FORMAT_TEXTURE_MSAA` - Texture can be sampled as MSAA.
* - `BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN` - Texture format supports auto-generated
* mips.
* - `BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER` - Texture format can be used as back buffer format.
*/
uint16_t formats[BGFX_TEXTURE_FORMAT_COUNT];
uint32_t formats[BGFX_TEXTURE_FORMAT_COUNT];

} bgfx_caps_t;

Expand Down
3 changes: 2 additions & 1 deletion include/bgfx/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD

#define BGFX_API_VERSION UINT32_C(139)
#define BGFX_API_VERSION UINT32_C(140)

/**
* Color RGB/alpha/depth write. When it's not specified write will be disabled.
Expand Down Expand Up @@ -521,6 +521,7 @@
#define BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA UINT32_C(0x00002000) //!< Texture format can be used as MSAA frame buffer.
#define BGFX_CAPS_FORMAT_TEXTURE_MSAA UINT32_C(0x00004000) //!< Texture can be sampled as MSAA.
#define BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN UINT32_C(0x00008000) //!< Texture format supports auto-generated mips.
#define BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER UINT32_C(0x00010000) //!< Texture format can be used as back buffer format.

#define BGFX_RESOLVE_NONE UINT8_C(0x00) //!< No resolve flags.
#define BGFX_RESOLVE_AUTO_GEN_MIPS UINT8_C(0x01) //!< Auto-generate mip maps on resolve.
Expand Down
6 changes: 4 additions & 2 deletions scripts/bgfx.idl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- vim: syntax=lua
-- bgfx interface

version(139)
version(140)

typedef "bool"
typedef "char"
Expand Down Expand Up @@ -423,6 +423,7 @@ flag.CapsFormat { bits = 32 }
.TextureFramebufferMsaa --- Texture format can be used as MSAA frame buffer.
.TextureMsaa --- Texture can be sampled as MSAA.
.TextureMipAutogen --- Texture format supports auto-generated mips.
.TextureBackbuffer --- Texture format can be used as back buffer format.
()

flag.Resolve { bits = 8 }
Expand Down Expand Up @@ -781,7 +782,7 @@ struct.Caps
.numGPUs "uint8_t" --- Number of enumerated GPUs.
.gpu "GPU[4]" --- Enumerated GPUs.
.limits "Limits" --- Renderer runtime limits.
.formats "uint16_t[TextureFormat::Count]"
.formats "uint32_t[TextureFormat::Count]"
--- Supported texture format capabilities flags:
--- - `BGFX_CAPS_FORMAT_TEXTURE_NONE` - Texture format is not supported.
--- - `BGFX_CAPS_FORMAT_TEXTURE_2D` - Texture format is supported.
Expand All @@ -805,6 +806,7 @@ struct.Caps
--- - `BGFX_CAPS_FORMAT_TEXTURE_MSAA` - Texture can be sampled as MSAA.
--- - `BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN` - Texture format supports auto-generated
--- mips.
--- - `BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER` - Texture format can be used as back buffer format.

--- Internal data.
struct.InternalData
Expand Down
61 changes: 34 additions & 27 deletions src/bgfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,39 +1798,46 @@ namespace bgfx

BX_TRACE("");
BX_TRACE("Supported texture formats:");
BX_TRACE("\t +---------------- 2D: x = supported / * = emulated");
BX_TRACE("\t |+--------------- 2D: sRGB format");
BX_TRACE("\t ||+-------------- 3D: x = supported / * = emulated");
BX_TRACE("\t |||+------------- 3D: sRGB format");
BX_TRACE("\t ||||+------------ Cube: x = supported / * = emulated");
BX_TRACE("\t |||||+----------- Cube: sRGB format");
BX_TRACE("\t ||||||+---------- vertex format");
BX_TRACE("\t |||||||+--------- image: i = read-write / r = read / w = write");
BX_TRACE("\t ||||||||+-------- framebuffer");
BX_TRACE("\t |||||||||+------- MSAA framebuffer");
BX_TRACE("\t ||||||||||+------ MSAA texture");
BX_TRACE("\t |||||||||||+----- Auto-generated mips");
BX_TRACE("\t |||||||||||| +-- name");
BX_TRACE("\t +----------------- 2D: x = supported / * = emulated");
BX_TRACE("\t |+---------------- 2D: sRGB format");
BX_TRACE("\t ||+--------------- 3D: x = supported / * = emulated");
BX_TRACE("\t |||+-------------- 3D: sRGB format");
BX_TRACE("\t ||||+------------- Cube: x = supported / * = emulated");
BX_TRACE("\t |||||+------------ Cube: sRGB format");
BX_TRACE("\t ||||||+----------- Vertex format");
BX_TRACE("\t |||||||+---------- Image: i = read-write / r = read / w = write");
BX_TRACE("\t ||||||||+--------- Framebuffer");
BX_TRACE("\t |||||||||+-------- MSAA framebuffer");
BX_TRACE("\t ||||||||||+------- MSAA texture");
BX_TRACE("\t |||||||||||+------ Auto-generated mips");
BX_TRACE("\t ||||||||||||+----- Back-buffer");
BX_TRACE("\t ||||||||||||| +-- name");
for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
if (TextureFormat::Unknown != ii
&& TextureFormat::UnknownDepth != ii)
{
uint32_t flags = g_caps.formats[ii];
BX_TRACE("\t[%c%c%c%c%c%c%c%c%c%c%c%c] %s"
, flags&BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_3D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED ? '*' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB ? 'l' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED ? '*' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB ? 'l' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' '
, (flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ) &&
(flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE) ? 'i' : flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ ? 'r' : flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE ? 'w' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA ? '+' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_MSAA ? 'm' : ' '
, flags&BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN ? 'M' : ' '
BX_TRACE("\t[%c%c%c%c%c%c%c%c%c%c%c%c%c] %s"
, flags & BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x'
: flags & BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_3D ? 'x'
: flags & BGFX_CAPS_FORMAT_TEXTURE_3D_EMULATED ? '*' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB ? 'l' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_CUBE ? 'x'
: flags & BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED ? '*' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB ? 'l' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' '
, (flags & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ) &&
(flags & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE) ? 'i'
: flags & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ ? 'r'
: flags & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE ? 'w' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA ? '+' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_MSAA ? 'm' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN ? 'M' : ' '
, flags & BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER ? 'b' : ' '
, getName(TextureFormat::Enum(ii) )
);
BX_UNUSED(flags);
Expand Down
5 changes: 5 additions & 0 deletions src/bgfx_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -3791,6 +3791,11 @@ namespace bgfx
: m_init.resolution.formatColor
;

BX_ASSERT(0 != (g_caps.formats[formatColor] & BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER)
, "Format %s can't be used for back buffer!"
, getName(formatColor)
);

if (!g_platformDataChangedSinceReset
&& m_init.resolution.formatColor == formatColor
&& m_init.resolution.width == _width
Expand Down
16 changes: 15 additions & 1 deletion src/renderer_d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ namespace bgfx { namespace d3d11

for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE;
uint32_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE;

const bool isDepthFormat = bimg::isDepth(bimg::TextureFormat::Enum(ii));
const DXGI_FORMAT fmt = isDepthFormat
Expand Down Expand Up @@ -1457,6 +1457,13 @@ namespace bgfx { namespace d3d11
? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;

support |= 0 != (data.OutFormatSupport & (0
| D3D11_FORMAT_SUPPORT_DISPLAY
) )
? BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
}
else
{
Expand Down Expand Up @@ -1569,6 +1576,13 @@ namespace bgfx { namespace d3d11
? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;

support |= 0 != (data.OutFormatSupport & (0
| D3D11_FORMAT_SUPPORT_DISPLAY
) )
? BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
}
else
{
Expand Down
21 changes: 20 additions & 1 deletion src/renderer_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ namespace bgfx { namespace d3d12

for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE;
uint32_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE;

const bool isDepthFormat = bimg::isDepth(bimg::TextureFormat::Enum(ii));
const DXGI_FORMAT fmt = isDepthFormat
Expand Down Expand Up @@ -1714,6 +1714,19 @@ namespace bgfx { namespace d3d12
? BGFX_CAPS_FORMAT_TEXTURE_MSAA
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;

support |= 0 != (data.Support1 & (0
| D3D12_FORMAT_SUPPORT1_DISPLAY
) )
? BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;

support |= 0 != (data.Support1 & D3D12_FORMAT_SUPPORT1_DISPLAY)
|| 0 != (data.Support2 & D3D12_FORMAT_SUPPORT2_DISPLAYABLE)
? BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
}
else
{
Expand Down Expand Up @@ -1803,6 +1816,12 @@ namespace bgfx { namespace d3d12
? BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;

support |= 0 != (data.Support1 & D3D12_FORMAT_SUPPORT1_DISPLAY)
|| 0 != (data.Support2 & D3D12_FORMAT_SUPPORT2_DISPLAYABLE)
? BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER
: BGFX_CAPS_FORMAT_TEXTURE_NONE
;
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion src/renderer_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2741,7 +2741,7 @@ namespace bgfx { namespace gl
{
const TextureFormat::Enum fmt = TextureFormat::Enum(ii);

uint16_t supported = BGFX_CAPS_FORMAT_TEXTURE_NONE;
uint32_t supported = BGFX_CAPS_FORMAT_TEXTURE_NONE;
supported |= s_textureFormat[ii].m_supported
? BGFX_CAPS_FORMAT_TEXTURE_2D
| BGFX_CAPS_FORMAT_TEXTURE_3D
Expand Down Expand Up @@ -2811,6 +2811,8 @@ namespace bgfx { namespace gl
g_caps.formats[ii] = supported;
}

g_caps.formats[TextureFormat::BGRA8] |= BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER;

g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3)
|| s_extension[Extension::OES_texture_3D].m_supported
? BGFX_CAPS_TEXTURE_3D
Expand Down
4 changes: 3 additions & 1 deletion src/renderer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ bool init(const Init& _init)

for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii)
{
uint16_t support = 0;
uint32_t support = 0;

support |= kMtlPixelFormatInvalid != s_textureFormat[ii].m_fmt
? BGFX_CAPS_FORMAT_TEXTURE_2D
Expand Down Expand Up @@ -757,6 +757,8 @@ bool init(const Init& _init)
g_caps.formats[ii] = support;
}

g_caps.formats[TextureFormat::BGRA8] |= BGFX_CAPS_FORMAT_TEXTURE_BACKBUFFER;

g_caps.formats[TextureFormat::A8 ] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA);
g_caps.formats[TextureFormat::RG32I ] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA);
g_caps.formats[TextureFormat::RG32U ] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA);
Expand Down
Loading