Added ability to configure backbuffer depth/stencil.

This commit is contained in:
Бранимир Караџић
2025-10-28 15:49:09 -07:00
parent f7c4dd70f2
commit 959cab248e
26 changed files with 691 additions and 523 deletions

View File

@@ -2120,7 +2120,8 @@ public static class bgfx
[CRepr]
public struct Resolution
{
public TextureFormat format;
public TextureFormat formatColor;
public TextureFormat formatDepthStencil;
public uint32 width;
public uint32 height;
public uint32 reset;

View File

@@ -1465,8 +1465,10 @@ struct PlatformData
// Backbuffer resolution and reset parameters.
struct Resolution
{
// Backbuffer format.
TextureFormat format;
// Backbuffer color format.
TextureFormat formatColor;
// Backbuffer depth/stencil format.
TextureFormat formatDepthStencil;
// Backbuffer width.
uint width;
// Backbuffer height.

View File

@@ -2098,7 +2098,8 @@ public static partial class bgfx
public unsafe struct Resolution
{
public TextureFormat format;
public TextureFormat formatColor;
public TextureFormat formatDepthStencil;
public uint width;
public uint height;
public uint reset;

View File

@@ -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 = 130;
enum uint apiVersion = 131;
alias ViewID = ushort;
@@ -1112,7 +1112,8 @@ extern(C++, "bgfx") struct PlatformData{
///Backbuffer resolution and reset parameters.
extern(C++, "bgfx") struct Resolution{
TextureFormat format; ///Backbuffer format.
TextureFormat formatColor; ///Backbuffer color format.
TextureFormat formatDepthStencil; ///Backbuffer depth/stencil format.
uint width; ///Backbuffer width.
uint height; ///Backbuffer height.
uint reset; ///Reset parameters.

View File

@@ -1340,7 +1340,8 @@ pub const Caps = extern struct {
};
pub const Resolution = extern struct {
format: TextureFormat,
formatColor: TextureFormat,
formatDepthStencil: TextureFormat,
width: u32,
height: u32,
reset: u32,

View File

@@ -33,7 +33,7 @@ int32_t _main_(int32_t _argc, char** _argv)
init.platformData.type = entry_get_native_window_handle_type();
bgfx_init(&init);
bgfx_reset(width, height, reset, init.resolution.format);
bgfx_reset(width, height, reset, init.resolution.formatColor);
// Enable debug text.
bgfx_set_debug(debug);

View File

@@ -658,7 +658,8 @@ namespace bgfx
{
Resolution();
TextureFormat::Enum format; //!< Backbuffer format.
TextureFormat::Enum formatColor; //!< Backbuffer color format.
TextureFormat::Enum formatDepthStencil; //!< Backbuffer depth/stencil format.
uint32_t width; //!< Backbuffer width.
uint32_t height; //!< Backbuffer height.
uint32_t reset; //!< Reset parameters.

View File

@@ -645,7 +645,8 @@ typedef struct bgfx_platform_data_s
*/
typedef struct bgfx_resolution_s
{
bgfx_texture_format_t format; /** Backbuffer format. */
bgfx_texture_format_t formatColor; /** Backbuffer color format. */
bgfx_texture_format_t formatDepthStencil; /** Backbuffer depth/stencil format. */
uint32_t width; /** Backbuffer width. */
uint32_t height; /** Backbuffer height. */
uint32_t reset; /** Reset parameters. */

View File

@@ -15,7 +15,7 @@
#ifndef BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_DEFINES_H_HEADER_GUARD
#define BGFX_API_VERSION UINT32_C(130)
#define BGFX_API_VERSION UINT32_C(131)
/**
* Color RGB/alpha/depth write. When it's not specified write will be disabled.

View File

@@ -1,7 +1,7 @@
-- vim: syntax=lua
-- bgfx interface
version(130)
version(131)
typedef "bool"
typedef "char"
@@ -792,7 +792,8 @@ struct.PlatformData { ctor }
--- Backbuffer resolution and reset parameters.
struct.Resolution { ctor }
.format "TextureFormat::Enum" --- Backbuffer format.
.formatColor "TextureFormat::Enum" --- Backbuffer color format.
.formatDepthStencil "TextureFormat::Enum" --- Backbuffer depth/stencil format.
.width "uint32_t" --- Backbuffer width.
.height "uint32_t" --- Backbuffer height.
.reset "uint32_t" --- Reset parameters.

View File

@@ -1710,12 +1710,15 @@ namespace bgfx
BX_UNUSED(reset, msaa);
BX_TRACE("Reset back-buffer swap chain:");
BX_TRACE("\t%dx%d, format: %s, numBackBuffers: %d, maxFrameLatency: %d"
BX_TRACE("\t%dx%d, formatColor: %s, formatDepthStencil: %s, numBackBuffers: %d, maxFrameLatency: %d"
, _resolution.width
, _resolution.height
, TextureFormat::Count == _resolution.format
, TextureFormat::Count == _resolution.formatColor
? "*default*"
: bimg::getName(bimg::TextureFormat::Enum(_resolution.format) )
: bimg::getName(bimg::TextureFormat::Enum(_resolution.formatColor) )
, TextureFormat::Count == _resolution.formatDepthStencil
? "*default*"
: bimg::getName(bimg::TextureFormat::Enum(_resolution.formatDepthStencil) )
, _resolution.numBackBuffers
, _resolution.maxFrameLatency
);
@@ -3494,7 +3497,8 @@ namespace bgfx
}
Resolution::Resolution()
: format(TextureFormat::RGBA8)
: formatColor(TextureFormat::RGBA8)
, formatDepthStencil(TextureFormat::D24S8)
, width(1280)
, height(720)
, reset(BGFX_RESET_NONE)

View File

@@ -3179,7 +3179,7 @@ namespace bgfx
return cmdbuf;
}
BGFX_API_FUNC(void reset(uint32_t _width, uint32_t _height, uint32_t _flags, TextureFormat::Enum _format) )
BGFX_API_FUNC(void reset(uint32_t _width, uint32_t _height, uint32_t _flags, TextureFormat::Enum _formatColor) )
{
BGFX_MUTEX_SCOPE(m_resourceApiLock);
@@ -3190,13 +3190,17 @@ namespace bgfx
, "Running in headless mode, resolution of non-existing backbuffer can't be larger than 0x0!"
);
const TextureFormat::Enum format = TextureFormat::Count != _format ? _format : m_init.resolution.format;
const TextureFormat::Enum formatColor = TextureFormat::Count != _formatColor
? _formatColor
: m_init.resolution.formatColor
;
if (!g_platformDataChangedSinceReset
&& m_init.resolution.format == format
&& m_init.resolution.formatColor == formatColor
&& m_init.resolution.width == _width
&& m_init.resolution.height == _height
&& m_init.resolution.reset == _flags)
&& m_init.resolution.reset == _flags
)
{
// Nothing changed, ignore request.
return;
@@ -3228,7 +3232,7 @@ namespace bgfx
, _width
, _height
);
m_init.resolution.format = format;
m_init.resolution.formatColor = formatColor;
m_init.resolution.width = bx::clamp(_width, 1u, g_caps.limits.maxTextureSize);
m_init.resolution.height = bx::clamp(_height, 1u, g_caps.limits.maxTextureSize);
m_init.resolution.reset = 0

View File

@@ -133,7 +133,7 @@ EGL_IMPORT
# define WL_EGL_FUNC(rt, fname, params) \
typedef rt(*PFNWLEGL_##fname) params; \
PFNWLEGL_##fname BGFX_WAYLAND_##fname;
PFNWLEGL_##fname fname;
WL_EGL_IMPORT
@@ -144,7 +144,7 @@ WL_EGL_IMPORT
void* handle = bx::dlopen("libwayland-egl.so.1");
BGFX_FATAL(handle != NULL, Fatal::UnableToInitialize, "Could not dlopen() libwayland-egl.so.1");
# define WL_EGL_FUNC(rt, fname, params) BGFX_WAYLAND_##fname = (PFNWLEGL_##fname) bx::dlsym(handle, #fname);
# define WL_EGL_FUNC(rt, fname, params) fname = (PFNWLEGL_##fname) bx::dlsym(handle, #fname);
WL_EGL_IMPORT
# undef WL_EGL_FUNC
@@ -155,7 +155,7 @@ WL_EGL_IMPORT
{
bx::dlclose(_handle);
# define WL_EGL_FUNC(rt, fname, params) BGFX_WAYLAND_##fname = NULL;
# define WL_EGL_FUNC(rt, fname, params) fname = NULL;
WL_EGL_IMPORT
# undef WL_EGL_FUNC
}
@@ -168,7 +168,7 @@ WL_EGL_IMPORT
struct SwapChainGL
{
SwapChainGL(EGLDisplay _display, EGLConfig _config, EGLContext _context, EGLNativeWindowType _nwh, int _width, int _height)
SwapChainGL(EGLDisplay _display, EGLConfig _config, EGLContext _context, EGLNativeWindowType _nwh, int32_t _width, int32_t _height)
: m_nwh(_nwh)
, m_display(_display)
# if BX_PLATFORM_LINUX
@@ -190,7 +190,7 @@ WL_EGL_IMPORT
{
// A wl_surface needs to be first wrapped in a wl_egl_window
// before it can be used to create the EGLSurface.
m_eglWindow = BGFX_WAYLAND_wl_egl_window_create( (wl_surface*)_nwh, _width, _height);
m_eglWindow = wl_egl_window_create( (wl_surface*)_nwh, _width, _height);
_nwh = (EGLNativeWindowType) m_eglWindow;
}
# endif
@@ -224,7 +224,7 @@ WL_EGL_IMPORT
# if BX_PLATFORM_LINUX
if (m_eglWindow)
{
BGFX_WAYLAND_wl_egl_window_destroy(m_eglWindow);
wl_egl_window_destroy(m_eglWindow);
}
# endif
EGL_CHECK(eglMakeCurrent(m_display, defaultSurface, defaultSurface, defaultContext) );
@@ -259,10 +259,8 @@ WL_EGL_IMPORT
static EGL_DISPMANX_WINDOW_T s_dispmanWindow;
# endif // BX_PLATFORM_RPI
void GlContext::create(uint32_t _width, uint32_t _height, uint32_t _flags)
void GlContext::create(const Resolution& _resolution)
{
BX_UNUSED(_flags);
# if BX_PLATFORM_RPI
bcm_host_init();
# endif // BX_PLATFORM_RPI
@@ -275,7 +273,6 @@ WL_EGL_IMPORT
g_platformData.ndt = EGL_DEFAULT_DISPLAY;
# endif // BX_PLATFORM_RPI
BX_UNUSED(_width, _height);
EGLNativeDisplayType ndt = (EGLNativeDisplayType)g_platformData.ndt;
EGLNativeWindowType nwh = (EGLNativeWindowType )g_platformData.nwh;
@@ -321,14 +318,15 @@ WL_EGL_IMPORT
: BGFX_CONFIG_RENDERER_OPENGLES
;
#if BX_PLATFORM_ANDROID
const uint32_t msaa = (_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
const uint32_t msaa = (_resolution.reset & BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
const uint32_t msaaSamples = msaa == 0 ? 0 : 1<<msaa;
m_msaaContext = true;
#endif // BX_PLATFORM_ANDROID
const bool headless = EGLNativeWindowType(0) == nwh;
const bimg::ImageBlockInfo& colorBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatColor) );
const bimg::ImageBlockInfo& depthStecilBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatDepthStencil) );
EGLint attrs[] =
{
EGL_RENDERABLE_TYPE, !!BGFX_CONFIG_RENDERER_OPENGL
@@ -338,18 +336,14 @@ WL_EGL_IMPORT
EGL_SURFACE_TYPE, headless ? EGL_PBUFFER_BIT : EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_BLUE_SIZE, colorBlockInfo.bBits,
EGL_GREEN_SIZE, colorBlockInfo.gBits,
EGL_RED_SIZE, colorBlockInfo.rBits,
EGL_ALPHA_SIZE, colorBlockInfo.aBits,
EGL_DEPTH_SIZE, depthStecilBlockInfo.depthBits,
EGL_STENCIL_SIZE, depthStecilBlockInfo.stencilBits,
# if BX_PLATFORM_ANDROID
EGL_DEPTH_SIZE, 16,
EGL_SAMPLES, (EGLint)msaaSamples,
# else
EGL_DEPTH_SIZE, 24,
# endif // BX_PLATFORM_
EGL_STENCIL_SIZE, 8,
// Android Recordable surface
hasEglAndroidRecordable ? EGL_RECORDABLE_ANDROID : EGL_NONE,
@@ -400,7 +394,7 @@ WL_EGL_IMPORT
{
m_waylandEglDll = waylandEglOpen();
}
# endif
# endif // BX_PLATFORM_LINUX
if (headless)
{
@@ -421,10 +415,14 @@ WL_EGL_IMPORT
{
// A wl_surface needs to be first wrapped in a wl_egl_window
// before it can be used to create the EGLSurface.
m_eglWindow = BGFX_WAYLAND_wl_egl_window_create( (wl_surface*)nwh, _width, _height);
m_eglWindow = wl_egl_window_create(
(wl_surface*)nwh
, _resolution.width
, _resolution.height
);
nwh = (EGLNativeWindowType) m_eglWindow;
}
# endif
# endif // BX_PLATFORM_LINUX
m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
}
@@ -517,7 +515,7 @@ WL_EGL_IMPORT
# if BX_PLATFORM_LINUX
if (m_eglWindow)
{
BGFX_WAYLAND_wl_egl_window_destroy(m_eglWindow);
wl_egl_window_destroy(m_eglWindow);
waylandEglClose(m_waylandEglDll);
m_waylandEglDll = NULL;
}
@@ -536,7 +534,7 @@ WL_EGL_IMPORT
# endif // BX_PLATFORM_RPI
}
void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
void GlContext::resize(const Resolution& _resolution)
{
# if BX_PLATFORM_ANDROID
if (NULL != m_display)
@@ -554,19 +552,28 @@ WL_EGL_IMPORT
ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format);
}
# elif BX_PLATFORM_EMSCRIPTEN
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(HTML5_TARGET_CANVAS_SELECTOR, _width, _height) );
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(
HTML5_TARGET_CANVAS_SELECTOR
, _resolution.width
, _resolution.height
)
);
# elif BX_PLATFORM_LINUX
if (NULL != m_eglWindow)
{
BGFX_WAYLAND_wl_egl_window_resize(m_eglWindow, _width, _height, 0, 0);
wl_egl_window_resize(
m_eglWindow
, _resolution.width
, _resolution.height
, 0
, 0
);
}
# else
BX_UNUSED(_width, _height);
# endif // BX_PLATFORM_*
if (NULL != m_display)
{
bool vsync = !!(_flags&BGFX_RESET_VSYNC);
const bool vsync = !!(_resolution.reset & BGFX_RESET_VSYNC);
EGL_CHECK(eglSwapInterval(m_display, vsync ? 1 : 0) );
}
}
@@ -583,7 +590,7 @@ WL_EGL_IMPORT
;
}
SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height)
SwapChainGL* GlContext::createSwapChain(void* _nwh, int32_t _width, int32_t _height)
{
return BX_NEW(g_allocator, SwapChainGL)(m_display, m_config, m_context, (EGLNativeWindowType)_nwh, _width, _height);
}

View File

@@ -46,12 +46,12 @@ namespace bgfx { namespace gl
{
}
void create(uint32_t _width, uint32_t _height, uint32_t _flags);
void create(const Resolution& _resolution);
void destroy();
void resize(uint32_t _width, uint32_t _height, uint32_t _flags);
void resize(const Resolution& _resolution);
uint64_t getCaps() const;
SwapChainGL* createSwapChain(void* _nwh, int _w, int _h);
SwapChainGL* createSwapChain(void* _nwh, int32_t _width, int32_t _height);
void destroySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);
void makeCurrent(SwapChainGL* _swapChain = NULL);

View File

@@ -64,14 +64,25 @@ namespace bgfx { namespace gl
char* m_canvas;
};
void GlContext::create(uint32_t _width, uint32_t _height, uint32_t /*_flags*/)
void GlContext::create(const Resolution& _resolution)
{
if (NULL != m_primary)
{
// assert?
if (m_primary != NULL)
return;
}
const bimg::ImageBlockInfo& colorBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatColor) );
const bimg::ImageBlockInfo& depthStecilBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatDepthStencil) );
emscripten_webgl_init_context_attributes(&s_attrs);
s_attrs.alpha = 0 != colorBlockInfo.aBits;
s_attrs.premultipliedAlpha = false;
s_attrs.depth = 0 != depthStecilBlockInfo.depthBits;
s_attrs.stencil = 0 != depthStecilBlockInfo.stencilBits;
s_attrs.enableExtensionsByDefault = true;
s_attrs.antialias = false;
s_attrs.minorVersion = 0;
const char* canvas = (const char*)g_platformData.nwh;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = bx::narrowCast<EMSCRIPTEN_WEBGL_CONTEXT_HANDLE>( (uintptr_t) g_platformData.context);
if (context > 0)
{
@@ -87,13 +98,17 @@ namespace bgfx { namespace gl
}
else
{
m_primary = createSwapChain((void*)canvas, (int)_width, (int)_height);
m_primary = createSwapChain( (void*)canvas, _resolution.width, _resolution.height);
}
if (0 != _width
&& 0 != _height)
if (0 != _resolution.width
&& 0 != _resolution.height)
{
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(canvas, (int)_width, (int)_height) );
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(
canvas
, _resolution.width
, _resolution.height
) );
}
makeCurrent(m_primary);
@@ -113,31 +128,24 @@ namespace bgfx { namespace gl
}
}
void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t /* _flags */)
void GlContext::resize(const Resolution& _resolution)
{
if (m_primary == NULL)
{
return;
}
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(m_primary->m_canvas, (int) _width, (int) _height) );
EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(
m_primary->m_canvas
, _resolution.width
, _resolution.height
) );
}
SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height)
SwapChainGL* GlContext::createSwapChain(void* _nwh, int32_t _width, int32_t _height)
{
emscripten_webgl_init_context_attributes(&s_attrs);
BX_UNUSED(_width, _height);
// Work around bug https://bugs.chromium.org/p/chromium/issues/detail?id=1045643 in Chrome
// by having alpha always enabled.
s_attrs.alpha = true;
s_attrs.premultipliedAlpha = false;
s_attrs.depth = true;
s_attrs.stencil = true;
s_attrs.enableExtensionsByDefault = true;
s_attrs.antialias = false;
s_attrs.minorVersion = 0;
const char* canvas = (const char*)_nwh;
int32_t error = 0;

View File

@@ -21,12 +21,12 @@ namespace bgfx { namespace gl
{
}
void create(uint32_t _width, uint32_t _height, uint32_t _flags);
void create(const Resolution& _resolution);
void destroy();
void resize(uint32_t _width, uint32_t _height, uint32_t _flags);
void resize(const Resolution& _resolution);
uint64_t getCaps() const;
SwapChainGL* createSwapChain(void* _nwh, int _width, int _height);
SwapChainGL* createSwapChain(void* _nwh, int32_t _width, int32_t _height);
void destroySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);
void makeCurrent(SwapChainGL* _swapChain = NULL);

View File

@@ -63,18 +63,21 @@ namespace bgfx { namespace gl
HGLRC m_context;
};
static HGLRC createContext(HDC _hdc)
static HGLRC createContext(HDC _hdc, const Resolution& _resolution)
{
const bimg::ImageBlockInfo& colorBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatColor) );
const bimg::ImageBlockInfo& depthStecilBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatDepthStencil) );
PIXELFORMATDESCRIPTOR pfd;
bx::memSet(&pfd, 0, sizeof(pfd) );
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cAlphaBits = 8;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
pfd.cColorBits = colorBlockInfo.bitsPerPixel;
pfd.cAlphaBits = colorBlockInfo.aBits;
pfd.cDepthBits = depthStecilBlockInfo.depthBits;
pfd.cStencilBits = depthStecilBlockInfo.stencilBits;
pfd.iLayerType = PFD_MAIN_PLANE;
int pixelFormat = ChoosePixelFormat(_hdc, &pfd);
@@ -108,7 +111,7 @@ namespace bgfx { namespace gl
return context;
}
void GlContext::create(uint32_t /*_width*/, uint32_t /*_height*/, uint32_t /*_flags*/)
void GlContext::create(const Resolution& _resolution)
{
m_opengl32dll = bx::dlopen("opengl32.dll");
BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load opengl32.dll.");
@@ -174,7 +177,7 @@ namespace bgfx { namespace gl
HDC hdc = GetDC(hwnd);
BGFX_FATAL(NULL != hdc, Fatal::UnableToInitialize, "GetDC failed!");
HGLRC context = createContext(hdc);
HGLRC context = createContext(hdc, _resolution);
wglGetExtensionsStringARB = wglGetProc<PFNWGLGETEXTENSIONSSTRINGARBPROC >("wglGetExtensionsStringARB");
wglChoosePixelFormatARB = wglGetProc<PFNWGLCHOOSEPIXELFORMATARBPROC >("wglChoosePixelFormatARB");
@@ -191,6 +194,9 @@ namespace bgfx { namespace gl
if (NULL != wglChoosePixelFormatARB
&& NULL != wglCreateContextAttribsARB)
{
const bimg::ImageBlockInfo& colorBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatColor) );
const bimg::ImageBlockInfo& depthStecilBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatDepthStencil) );
int32_t attrs[] =
{
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
@@ -198,10 +204,10 @@ namespace bgfx { namespace gl
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_ALPHA_BITS_ARB, 8,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, colorBlockInfo.aBits,
WGL_COLOR_BITS_ARB, colorBlockInfo.bitsPerPixel,
WGL_DEPTH_BITS_ARB, depthStecilBlockInfo.depthBits,
WGL_STENCIL_BITS_ARB, depthStecilBlockInfo.stencilBits,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_SAMPLES_ARB, 0,
@@ -282,7 +288,7 @@ namespace bgfx { namespace gl
if (NULL == m_context)
{
m_context = createContext(m_hdc);
m_context = createContext(m_hdc, _resolution);
}
int result = wglMakeCurrent(m_hdc, m_context);
@@ -321,11 +327,11 @@ namespace bgfx { namespace gl
m_opengl32dll = NULL;
}
void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, uint32_t _flags)
void GlContext::resize(const Resolution& _resolution)
{
if (NULL != wglSwapIntervalEXT)
{
bool vsync = !!(_flags&BGFX_RESET_VSYNC);
const bool vsync = !!(_resolution.reset & BGFX_RESET_VSYNC);
wglSwapIntervalEXT(vsync ? 1 : 0);
}
}
@@ -335,7 +341,7 @@ namespace bgfx { namespace gl
return BGFX_CAPS_SWAP_CHAIN;
}
SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height)
SwapChainGL* GlContext::createSwapChain(void* _nwh, int32_t _width, int32_t _height)
{
BX_UNUSED(_width, _height);
SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(_nwh);

View File

@@ -69,12 +69,12 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z
{
}
void create(uint32_t _width, uint32_t _height, uint32_t _flags);
void create(const Resolution& _resolution);
void destroy();
void resize(uint32_t _width, uint32_t _height, uint32_t _flags);
void resize(const Resolution& _resolution);
uint64_t getCaps() const;
SwapChainGL* createSwapChain(void* _nwh, int _width, int _height);
SwapChainGL* createSwapChain(void* _nwh, int32_t _width, int32_t _height);
void destroySwapChain(SwapChainGL* _swapChain);
void swap(SwapChainGL* _swapChain = NULL);
void makeCurrent(SwapChainGL* _swapChain = NULL);

View File

@@ -1049,7 +1049,7 @@ namespace bgfx { namespace d3d11
* is incompatible with the flip presentation model, which is desirable for various reasons including
* player embedding.
*/
m_scd.format = s_textureFormat[_init.resolution.format].m_fmt;
m_scd.format = s_textureFormat[_init.resolution.formatColor].m_fmt;
updateMsaa(m_scd.format);
m_scd.sampleDesc = s_msaa[(_init.resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT];
@@ -1126,7 +1126,10 @@ namespace bgfx { namespace d3d11
* ONLY the backbuffer from swapchain can be created without *_SRGB format, custom backbuffer should be created the same
* format as well as render target view.
*/
desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? s_textureFormat[m_resolution.format].m_fmtSrgb : s_textureFormat[m_resolution.format].m_fmt;
desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[m_resolution.formatColor].m_fmtSrgb
: s_textureFormat[m_resolution.formatColor].m_fmt
;
desc.SampleDesc = m_scd.sampleDesc;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
@@ -2251,7 +2254,10 @@ namespace bgfx { namespace d3d11
* with the srgb version. this is OK because of this:
* https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/converting-data-color-space
*/
desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? s_textureFormat[m_resolution.format].m_fmtSrgb : s_textureFormat[m_resolution.format].m_fmt;
desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[m_resolution.formatColor].m_fmtSrgb
: s_textureFormat[m_resolution.formatColor].m_fmt
;
DX_CHECK(m_device->CreateRenderTargetView(NULL == m_msaaRt ? backBufferColor : m_msaaRt, &desc, &m_backBufferColor) );
DX_RELEASE(backBufferColor, 0);
@@ -2261,16 +2267,17 @@ namespace bgfx { namespace d3d11
{
m_gpuTimer.postReset();
}
m_occlusionQuery.postReset();
if (NULL == m_backBufferDepthStencil)
if (bimg::isDepth(bimg::TextureFormat::Enum(m_resolution.formatDepthStencil) ) )
{
D3D11_TEXTURE2D_DESC dsd;
dsd.Width = bx::uint32_max(m_scd.width, 1);
dsd.Height = bx::uint32_max(m_scd.height, 1);
dsd.MipLevels = 1;
dsd.ArraySize = 1;
dsd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
dsd.Format = s_textureFormat[m_resolution.formatDepthStencil].m_fmtDsv;
dsd.SampleDesc = m_scd.sampleDesc;
dsd.Usage = D3D11_USAGE_DEFAULT;
dsd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
@@ -2467,8 +2474,10 @@ namespace bgfx { namespace d3d11
if (m_resolution.width != _resolution.width
|| m_resolution.height != _resolution.height
|| m_resolution.format != _resolution.format
|| (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) )
|| m_resolution.formatColor != _resolution.formatColor
|| m_resolution.formatDepthStencil != _resolution.formatDepthStencil
|| (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags)
)
{
uint32_t flags = _resolution.reset & (~BGFX_RESET_INTERNAL_FORCE);
@@ -2486,8 +2495,7 @@ namespace bgfx { namespace d3d11
m_scd.width = _resolution.width;
m_scd.height = _resolution.height;
// see comment in init() about why we don't worry about BGFX_RESET_SRGB_BACKBUFFER here
m_scd.format = s_textureFormat[_resolution.format].m_fmt
;
m_scd.format = s_textureFormat[_resolution.formatColor].m_fmt;
preReset();
@@ -2532,7 +2540,10 @@ namespace bgfx { namespace d3d11
desc.Height = m_scd.height;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? s_textureFormat[m_resolution.format].m_fmtSrgb : s_textureFormat[m_resolution.format].m_fmt;
desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[m_resolution.formatColor].m_fmtSrgb
: s_textureFormat[m_resolution.formatColor].m_fmt
;
desc.SampleDesc = m_scd.sampleDesc;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_RENDER_TARGET;

View File

@@ -713,6 +713,7 @@ namespace bgfx { namespace d3d12
, m_backBufferColorIdx(0)
, m_rtMsaa(false)
, m_directAccessSupport(false)
, m_backBufferDepthStencil(NULL)
{
}
@@ -1230,7 +1231,7 @@ namespace bgfx { namespace d3d12
bx::memSet(&m_scd, 0, sizeof(m_scd) );
m_scd.width = _init.resolution.width;
m_scd.height = _init.resolution.height;
m_scd.format = s_textureFormat[_init.resolution.format].m_fmt;
m_scd.format = s_textureFormat[_init.resolution.formatColor].m_fmt;
m_scd.stereo = false;
updateMsaa(m_scd.format);
@@ -1290,8 +1291,9 @@ namespace bgfx { namespace d3d12
resourceDesc.Height = m_scd.height;
resourceDesc.MipLevels = 1;
resourceDesc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[m_resolution.format].m_fmtSrgb
: s_textureFormat[m_resolution.format].m_fmt;
? s_textureFormat[m_resolution.formatColor].m_fmtSrgb
: s_textureFormat[m_resolution.formatColor].m_fmt
;
resourceDesc.SampleDesc = m_scd.sampleDesc;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
@@ -2375,6 +2377,7 @@ namespace bgfx { namespace d3d12
DX_RELEASE(m_backBufferColor[ii], 1);
#endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT
}
DX_RELEASE(m_backBufferDepthStencil, 0);
}
@@ -2407,13 +2410,16 @@ namespace bgfx { namespace d3d12
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[m_resolution.format].m_fmtSrgb
: s_textureFormat[m_resolution.format].m_fmt;
? s_textureFormat[m_resolution.formatColor].m_fmtSrgb
: s_textureFormat[m_resolution.formatColor].m_fmt
;
if (1 < getResourceDesc(m_backBufferColor[ii]).DepthOrArraySize)
{
rtvDesc.ViewDimension = (NULL == m_msaaRt) ?
D3D12_RTV_DIMENSION_TEXTURE2DARRAY : D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY;
rtvDesc.ViewDimension = (NULL == m_msaaRt)
? D3D12_RTV_DIMENSION_TEXTURE2DARRAY
: D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY
;
rtvDesc.Texture2DArray.FirstArraySlice = 0;
rtvDesc.Texture2DArray.ArraySize = getResourceDesc(m_backBufferColor[ii]).DepthOrArraySize;
rtvDesc.Texture2DArray.MipSlice = 0;
@@ -2421,8 +2427,10 @@ namespace bgfx { namespace d3d12
}
else
{
rtvDesc.ViewDimension = (NULL == m_msaaRt) ?
D3D12_RTV_DIMENSION_TEXTURE2D : D3D12_RTV_DIMENSION_TEXTURE2DMS;
rtvDesc.ViewDimension = (NULL == m_msaaRt)
? D3D12_RTV_DIMENSION_TEXTURE2D
: D3D12_RTV_DIMENSION_TEXTURE2DMS
;
rtvDesc.Texture2D.MipSlice = 0;
rtvDesc.Texture2D.PlaneSlice = 0;
}
@@ -2450,6 +2458,10 @@ namespace bgfx { namespace d3d12
}
}
m_commandList = m_cmd.alloc();
if (bimg::isDepth(bimg::TextureFormat::Enum(m_resolution.formatDepthStencil) ) )
{
D3D12_RESOURCE_DESC resourceDesc;
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
resourceDesc.Alignment = 1 < m_scd.sampleDesc.Count ? D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT : 0;
@@ -2457,7 +2469,7 @@ namespace bgfx { namespace d3d12
resourceDesc.Height = bx::uint32_max(m_resolution.height, 1);
resourceDesc.DepthOrArraySize = 1;
resourceDesc.MipLevels = 1;
resourceDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
resourceDesc.Format = s_textureFormat[m_resolution.formatDepthStencil].m_fmtDsv;
resourceDesc.SampleDesc = m_scd.sampleDesc;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
@@ -2467,8 +2479,6 @@ namespace bgfx { namespace d3d12
clearValue.DepthStencil.Depth = 1.0f;
clearValue.DepthStencil.Stencil = 0;
m_commandList = m_cmd.alloc();
m_backBufferDepthStencil = createCommittedResource(m_device, HeapProperty::Default, &resourceDesc, &clearValue);
m_device->CreateDepthStencilView(m_backBufferDepthStencil, NULL, getCPUHandleHeapStart(m_dsvDescriptorHeap) );
@@ -2477,6 +2487,7 @@ namespace bgfx { namespace d3d12
, D3D12_RESOURCE_STATE_COMMON
, D3D12_RESOURCE_STATE_DEPTH_WRITE
);
}
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
{
@@ -2566,7 +2577,8 @@ namespace bgfx { namespace d3d12
if (m_resolution.width != _resolution.width
|| m_resolution.height != _resolution.height
|| m_resolution.format != _resolution.format
|| m_resolution.formatColor != _resolution.formatColor
|| m_resolution.formatDepthStencil != _resolution.formatDepthStencil
|| (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) )
{
uint32_t flags = _resolution.reset & (~BGFX_RESET_INTERNAL_FORCE);
@@ -2584,7 +2596,7 @@ namespace bgfx { namespace d3d12
m_scd.width = _resolution.width;
m_scd.height = _resolution.height;
m_scd.format = s_textureFormat[_resolution.format].m_fmt;
m_scd.format = s_textureFormat[_resolution.formatColor].m_fmt;
preReset();
@@ -2637,8 +2649,9 @@ namespace bgfx { namespace d3d12
resourceDesc.Height = m_scd.height;
resourceDesc.MipLevels = 1;
resourceDesc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[m_resolution.format].m_fmtSrgb
: s_textureFormat[m_resolution.format].m_fmt;
? s_textureFormat[m_resolution.formatColor].m_fmtSrgb
: s_textureFormat[m_resolution.formatColor].m_fmt
;
resourceDesc.SampleDesc = m_scd.sampleDesc;
resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
@@ -2780,7 +2793,11 @@ namespace bgfx { namespace d3d12
m_dsvHandle = getCPUHandleHeapStart(m_dsvDescriptorHeap);
m_currentColor = &m_rtvHandle;
m_currentDepthStencil = &m_dsvHandle;
m_currentDepthStencil = NULL != m_backBufferDepthStencil
? &m_dsvHandle
: NULL
;
m_commandList->OMSetRenderTargets(1, m_currentColor, true, m_currentDepthStencil);
}
}

View File

@@ -2284,7 +2284,7 @@ namespace bgfx { namespace gl
bx::memSet(m_uniforms, 0, sizeof(m_uniforms) );
bx::memSet(&m_resolution, 0, sizeof(m_resolution) );
setRenderContextSize(_init.resolution.width, _init.resolution.height, _init.resolution.reset);
setRenderContextSize(_init.resolution);
m_vendor = getGLString(GL_VENDOR);
m_renderer = getGLString(GL_RENDERER);
@@ -3522,9 +3522,10 @@ namespace bgfx { namespace gl
void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override
{
BX_UNUSED(_format, _depthFormat);
uint16_t denseIdx = m_numWindows++;
m_windows[denseIdx] = _handle;
m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat);
m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height);
}
void destroyFrameBuffer(FrameBufferHandle _handle) override
@@ -3778,10 +3779,7 @@ namespace bgfx { namespace gl
m_textVideoMem.resize(false, _resolution.width, _resolution.height);
m_textVideoMem.clear();
setRenderContextSize(m_resolution.width
, m_resolution.height
, flags
);
setRenderContextSize(m_resolution);
updateCapture();
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
@@ -4156,22 +4154,22 @@ namespace bgfx { namespace gl
}
}
void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _flags = 0)
void setRenderContextSize(const Resolution& _resolution)
{
if (!m_glctx.isValid() )
{
m_glctx.create(_width, _height, _flags);
m_glctx.create(_resolution);
}
else
{
destroyMsaaFbo();
m_glctx.resize(_width, _height, _flags);
m_glctx.resize(_resolution);
uint32_t msaa = (_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
uint32_t msaa = (_resolution.reset & BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT;
msaa = bx::uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa);
createMsaaFbo(_width, _height, msaa);
createMsaaFbo(_resolution.width, _resolution.height, msaa);
}
m_flip = true;
@@ -4811,7 +4809,8 @@ namespace bgfx { namespace gl
GLenum m_readPixelsFmt;
GLuint m_backBufferFbo;
GLuint m_msaaBackBufferFbo;
union {
union
{
GLuint m_msaaBackBufferRbos[2];
GLuint m_msaaBackBufferTextures[2];
};
@@ -7156,9 +7155,8 @@ namespace bgfx { namespace gl
}
}
void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat)
void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height)
{
BX_UNUSED(_format, _depthFormat);
m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh, _width, _height);
m_width = _width;
m_height = _height;

View File

@@ -1492,7 +1492,7 @@ namespace bgfx { namespace gl
}
void create(uint8_t _num, const Attachment* _attachment);
void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat);
void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height);
void postReset();
uint16_t destroy();
void resolve();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2015 Attila Kocsis, Branimir Karadzic. All rights reserved.
* Copyright 2011-2025 Attila Kocsis. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
@@ -20,7 +20,7 @@
#if BX_PLATFORM_VISIONOS
# import <CompositorServices/CompositorServices.h>
#endif
#endif // BX_PLATFORM_VISIONOS
#define BGFX_MTL_PROFILER_BEGIN(_view, _abgr) \
BX_MACRO_BLOCK_BEGIN \
@@ -47,7 +47,7 @@ namespace bgfx { namespace mtl
#else
BX_UNUSED(_version);
return false;
#endif
#endif // BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS
}
inline bool macOSVersionEqualOrGreater(
@@ -59,11 +59,12 @@ namespace bgfx { namespace mtl
#if BX_PLATFORM_OSX
NSOperatingSystemVersion v = [[NSProcessInfo processInfo] operatingSystemVersion];
return (v.majorVersion<<16) + (v.minorVersion<<8) + v.patchVersion >=
(_majorVersion<<16) + (_minorVersion<<8) + _patchVersion;
( _majorVersion<<16) + ( _minorVersion<<8) + _patchVersion
;
#else
BX_UNUSED(_majorVersion, _minorVersion, _patchVersion);
return false;
#endif
#endif // BX_PLATFORM_OSX
}
// c++ wrapper
@@ -749,8 +750,11 @@ namespace bgfx { namespace mtl
#define MTL_RELEASE(_obj) \
BX_MACRO_BLOCK_BEGIN \
if (NULL != _obj) \
{ \
[_obj release]; \
_obj = NULL; \
} \
BX_MACRO_BLOCK_END
// end of c++ wrapper
@@ -996,7 +1000,9 @@ namespace bgfx { namespace mtl
MTL_RELEASE(m_ptr);
MTL_RELEASE(m_ptrMsaa);
}
MTL_RELEASE(m_ptrStencil);
for (uint32_t ii = 0; ii < m_numMips; ++ii)
{
MTL_RELEASE(m_ptrMips[ii]);
@@ -1028,7 +1034,7 @@ namespace bgfx { namespace mtl
, uint8_t _mip = UINT8_MAX
);
Texture getTextureMipLevel(int _mip);
Texture getTextureMipLevel(uint8_t _mip);
Texture m_ptr;
Texture m_ptrMsaa;
@@ -1056,7 +1062,7 @@ namespace bgfx { namespace mtl
, m_layerRendererDrawable(NULL)
, m_frame(NULL)
, m_useLayerRenderer(true)
#endif
#endif // BX_PLATFORM_VISIONOS
, m_drawable(nil)
, m_drawableTexture(nil)
, m_backBufferColorMsaa()
@@ -1069,7 +1075,12 @@ namespace bgfx { namespace mtl
~SwapChainMtl();
void init(void* _nwh);
void resize(FrameBufferMtl &_frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags, uint32_t _maximumDrawableCount);
uint32_t resize(
uint32_t _width
, uint32_t _height
, TextureFormat::Enum _format
, TextureFormat::Enum _depthFormat
);
id<MTLTexture> currentDrawableTexture();
@@ -1080,7 +1091,7 @@ namespace bgfx { namespace mtl
cp_layer_renderer_configuration_t m_layerRendererConfiguration;
cp_frame_t m_frame;
bool m_useLayerRenderer;
#endif
#endif // BX_PLATFORM_VISIONOS
id <CAMetalDrawable> m_drawable;
id <MTLTexture> m_drawableTexture;
@@ -1096,8 +1107,8 @@ namespace bgfx { namespace mtl
FrameBufferMtl()
: m_swapChain(NULL)
, m_nwh(NULL)
, m_denseIdx(UINT16_MAX)
, m_pixelFormatHash(0)
, m_denseIdx(UINT16_MAX)
, m_num(0)
{
m_depthHandle.idx = kInvalidHandle;
@@ -1116,15 +1127,20 @@ namespace bgfx { namespace mtl
uint16_t destroy();
void resolve();
void resizeSwapChain(
uint32_t _width
, uint32_t _height
, TextureFormat::Enum _format = TextureFormat::Count
, TextureFormat::Enum _depthFormat = TextureFormat::Count
);
SwapChainMtl* m_swapChain;
void* m_nwh;
uint32_t m_pixelFormatHash;
uint32_t m_width;
uint32_t m_height;
uint16_t m_denseIdx;
uint32_t m_pixelFormatHash;
TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
TextureHandle m_depthHandle;
Attachment m_colorAttachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 Attila Kocsis. All rights reserved.
* Copyright 2011-2025 Attila Kocsis. All rights reserved.
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
@@ -13,7 +13,7 @@
#if BX_PLATFORM_OSX
# include <Cocoa/Cocoa.h>
#endif
#endif // BX_PLATFORM_OSX
#import <Foundation/Foundation.h>
@@ -247,7 +247,6 @@ namespace bgfx { namespace mtl
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ATC
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ATCE
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ATCI
#if (BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS) && !TARGET_OS_MACCATALYST
{ MTLPixelFormatASTC_4x4_LDR, MTLPixelFormatASTC_4x4_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC4x4
{ MTLPixelFormatASTC_5x4_LDR, MTLPixelFormatASTC_5x4_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x4
{ MTLPixelFormatASTC_5x5_LDR, MTLPixelFormatASTC_5x5_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x5
@@ -262,22 +261,6 @@ namespace bgfx { namespace mtl
{ MTLPixelFormatASTC_10x10_LDR, MTLPixelFormatASTC_10x10_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x10
{ MTLPixelFormatASTC_12x10_LDR, MTLPixelFormatASTC_12x10_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x10
{ MTLPixelFormatASTC_12x12_LDR, MTLPixelFormatASTC_12x12_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x12
#else
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC4x4
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x4
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x5
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC6x5
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC6x6
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x5
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x6
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x8
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x5
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x6
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x8
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x10
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x10
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x12
#endif // (BX_PLATFORM_IOS || BX_PLATFORM_VISIONOS) && !TARGET_OS_MACCATALYST
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // Unknown
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // R1
{ MTLPixelFormatA8Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // A8
@@ -334,7 +317,7 @@ namespace bgfx { namespace mtl
{ MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // UnknownDepth
{ MTLPixelFormatDepth16Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D16
{ MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D24
{ MTLPixelFormat(255/*Depth24Unorm_Stencil8*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D24S8
{ MTLPixelFormatDepth24Unorm_Stencil8, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D24S8
{ MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D32
{ MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D16F
{ MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D24F
@@ -429,13 +412,15 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
#ifndef __IPHONE_OS_VERSION_MAX_ALLOWED
# define __IPHONE_OS_VERSION_MAX_ALLOWED 0
#endif
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED
#ifndef __MAC_OS_X_VERSION_MAX_ALLOWED
# define __MAC_OS_X_VERSION_MAX_ALLOWED 0
#endif
#endif // __IPHONE_OS_VERSION_MAX_ALLOWED
#ifndef __VISION_OS_VERSION_MAX_ALLOWED
# define __VISION_OS_VERSION_MAX_ALLOWED 0
#endif
#endif // __VISION_OS_VERSION_MAX_ALLOWED
#ifndef BX_XCODE_15
# define BX_XCODE_15 (0 \
@@ -469,7 +454,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
# define VISION_OS_MINIMUM visionOS 1.0,
#else
# define VISION_OS_MINIMUM
#endif
#endif // __VISION_OS_VERSION_MAX_ALLOWED >= 10000
#define SHADER_FUNCTION_NAME "xlatMtlMain"
#define SHADER_UNIFORM_NAME "_mtl_u"
@@ -510,9 +495,9 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
CHECK_FEATURE_AVAILABLE(m_hasVSync, macOS 10.13, macCatalyst 13.1, *);
CHECK_FEATURE_AVAILABLE(m_hasMaximumDrawableCount, iOS 11.2, macOS 10.13.2, macCatalyst 13.1, tvOS 11.2, VISION_OS_MINIMUM *);
m_fbh.idx = kInvalidHandle;
m_fbh = BGFX_INVALID_HANDLE;
bx::memSet(m_uniforms, 0, sizeof(m_uniforms) );
bx::memSet(&m_resolution, 0, sizeof(m_resolution) );
m_resolution = _init.resolution;
m_device = (id<MTLDevice>)g_platformData.context;
@@ -532,10 +517,10 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
m_mainFrameBuffer.create(
0
, g_platformData.nwh
, _init.resolution.width
, _init.resolution.height
, TextureFormat::Unknown
, TextureFormat::UnknownDepth
, m_resolution.width
, m_resolution.height
, m_resolution.formatColor
, m_resolution.formatDepthStencil
);
#if BX_PLATFORM_VISIONOS
@@ -546,13 +531,15 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
m_arSession = ar_session_create();
ar_session_run(m_arSession, ar_data_providers_create_with_data_providers(m_worldTracking, nil) );
}
#endif
#endif // BX_PLATFORM_VISIONOS
m_numWindows = 1;
#if BX_PLATFORM_VISIONOS
bool useLayerRenderer = m_mainFrameBuffer.m_swapChain->m_useLayerRenderer;
if ( (useLayerRenderer && NULL == m_mainFrameBuffer.m_swapChain->m_layerRenderer)
|| (!useLayerRenderer && NULL == m_mainFrameBuffer.m_swapChain->m_metalLayer))
|| (!useLayerRenderer && NULL == m_mainFrameBuffer.m_swapChain->m_metalLayer)
)
#else
if (NULL == m_mainFrameBuffer.m_swapChain->m_metalLayer)
#endif // BX_PLATFORM_VISIONOS
@@ -735,8 +722,22 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
// It is decremented by 1 because 1 entry is used for uniforms.
g_caps.limits.maxComputeBindings = bx::uint32_min(30, BGFX_MAX_COMPUTE_BINDINGS);
CHECK_FEATURE_AVAILABLE(m_hasPixelFormatDepth32Float_Stencil8, iOS 9.0, macOS 10.11, macCatalyst 13.1, tvOS 9.0, VISION_OS_MINIMUM *);
CHECK_FEATURE_AVAILABLE(m_hasStoreActionStoreAndMultisampleResolve, iOS 10.0, macOS 10.12, macCatalyst 13.1, tvOS 10.0, VISION_OS_MINIMUM *);
CHECK_FEATURE_AVAILABLE(
m_hasPixelFormatDepth32Float_Stencil8
, iOS 9.0
, macOS 10.11
, macCatalyst 13.1
, tvOS 9.0
, VISION_OS_MINIMUM *
);
CHECK_FEATURE_AVAILABLE(
m_hasStoreActionStoreAndMultisampleResolve
, iOS 10.0
, macOS 10.12
, macCatalyst 13.1
, tvOS 10.0
, VISION_OS_MINIMUM *
);
if (BX_ENABLED(BX_PLATFORM_OSX) )
{
@@ -745,7 +746,15 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
bool hasPacked16Formats;
CHECK_FEATURE_AVAILABLE(hasPacked16Formats, iOS 8.0, macOS 11.0, macCatalyst 14.0, tvOS 9.0, VISION_OS_MINIMUM *);
CHECK_FEATURE_AVAILABLE(
hasPacked16Formats
, iOS 8.0
, macOS 11.0
, macCatalyst 14.0
, tvOS 9.0
, VISION_OS_MINIMUM *
);
if (g_caps.vendorId == BGFX_PCI_ID_AMD)
{
hasPacked16Formats = false;
@@ -766,7 +775,15 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
;
bool hasD16Format;
CHECK_FEATURE_AVAILABLE(hasD16Format, iOS 13.0, macOS 10.12, macCatalyst 13.1, tvOS 13.0, VISION_OS_MINIMUM *);
CHECK_FEATURE_AVAILABLE(
hasD16Format
, iOS 13.0
, macOS 10.12
, macCatalyst 13.1
, tvOS 13.0
, VISION_OS_MINIMUM *
);
if (!hasD16Format)
{
s_textureFormat[TextureFormat::D16].m_fmt = MTLPixelFormatDepth32Float;
@@ -945,7 +962,9 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
{
MTL_RELEASE(m_uniformBuffers[i]);
}
m_cmd.shutdown();
MTL_RELEASE(m_device);
}
@@ -1101,8 +1120,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
BX_ASSERT(_mip<texture.m_numMips,"Invalid mip: %d num mips:",_mip,texture.m_numMips);
uint32_t srcWidth = bx::uint32_max(1, texture.m_ptr.width() >> _mip);
uint32_t srcHeight = bx::uint32_max(1, texture.m_ptr.height() >> _mip);
const uint32_t srcWidth = bx::uint32_max(1, texture.m_ptr.width() >> _mip);
const uint32_t srcHeight = bx::uint32_max(1, texture.m_ptr.height() >> _mip);
const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(texture.m_textureFormat) );
MTLRegion region =
@@ -1122,8 +1141,9 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
const Memory* mem = alloc(size);
bx::StaticMemoryBlockWriter writer(mem->data, mem->size);
uint32_t magic = BGFX_CHUNK_MAGIC_TEX;
bx::write(&writer, magic, bx::ErrorAssert{});
constexpr uint32_t kMagic = BGFX_CHUNK_MAGIC_TEX;
bx::write(&writer, kMagic, bx::ErrorAssert{});
TextureCreate tc;
tc.m_width = _width;
@@ -1179,7 +1199,6 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
FrameBufferMtl& fb = m_frameBuffers[_handle.idx];
fb.create(denseIdx, _nwh, _width, _height, _format, _depthFormat);
fb.m_swapChain->resize(m_frameBuffers[_handle.idx], _width, _height, m_resolution.reset, m_resolution.maxFrameLatency);
}
void destroyFrameBuffer(FrameBufferHandle _handle) override
@@ -1383,8 +1402,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
endEncoding();
uint32_t width = m_resolution.width;
uint32_t height = m_resolution.height;
const uint32_t width = m_resolution.width;
const uint32_t height = m_resolution.height;
FrameBufferHandle fbh = BGFX_INVALID_HANDLE;
@@ -1541,6 +1560,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
else
#endif // BX_PLATFORM_VISIONOS
{
if (NULL != frameBuffer.m_swapChain->m_drawable)
{
m_commandBuffer.presentDrawable(frameBuffer.m_swapChain->m_drawable);
@@ -1548,6 +1568,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
}
}
}
m_cmd.kick(true);
m_commandBuffer = 0;
@@ -1578,9 +1599,10 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
{
m_mainFrameBuffer.m_swapChain->init(g_platformData.nwh);
}
m_resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE;
m_mainFrameBuffer.m_swapChain->resize(m_mainFrameBuffer, _resolution.width, _resolution.height, _resolution.reset, m_resolution.maxFrameLatency);
m_mainFrameBuffer.resizeSwapChain(_resolution.width, _resolution.height);
for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
{
@@ -1592,7 +1614,6 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
m_textVideoMem.resize(false, _resolution.width, _resolution.height);
m_textVideoMem.clear();
if (prevMetalLayerPixelFormat != getSwapChainPixelFormat(m_mainFrameBuffer.m_swapChain) )
{
MTL_RELEASE(m_screenshotBlitRenderPipelineState);
@@ -2390,9 +2411,16 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
else
#endif // BX_PLATFORM_VISIONOS
{
pd.depthAttachmentPixelFormat = swapChain->m_backBufferDepth.m_obj.pixelFormat;
pd.depthAttachmentPixelFormat = NULL != swapChain->m_backBufferDepth
? swapChain->m_backBufferDepth.m_obj.pixelFormat
: MTLPixelFormatInvalid
;
}
pd.stencilAttachmentPixelFormat = swapChain->m_backBufferStencil.m_obj.pixelFormat;
pd.stencilAttachmentPixelFormat = NULL != swapChain->m_backBufferStencil
? swapChain->m_backBufferStencil.m_obj.pixelFormat
: MTLPixelFormatInvalid
;
}
else
{
@@ -2411,22 +2439,20 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
if (isValid(frameBuffer.m_depthHandle) )
{
const TextureMtl& texture = m_textures[frameBuffer.m_depthHandle.idx];
pd.depthAttachmentPixelFormat = texture.m_ptr.m_obj.pixelFormat;
pd.rasterSampleCount = NULL != texture.m_ptrMsaa
? texture.m_ptrMsaa.sampleCount()
const TextureMtl& depthStencilTexture = m_textures[frameBuffer.m_depthHandle.idx];
pd.depthAttachmentPixelFormat = depthStencilTexture.m_ptr.m_obj.pixelFormat;
pd.rasterSampleCount = NULL != depthStencilTexture.m_ptrMsaa
? depthStencilTexture.m_ptrMsaa.sampleCount()
: 1
;
if (NULL != texture.m_ptrStencil)
if (NULL != depthStencilTexture.m_ptrStencil)
{
pd.stencilAttachmentPixelFormat = texture.m_ptrStencil.m_obj.pixelFormat;
pd.stencilAttachmentPixelFormat = depthStencilTexture.m_ptrStencil.m_obj.pixelFormat;
}
else
else if (depthStencilTexture.m_textureFormat == TextureFormat::D24S8)
{
if (texture.m_textureFormat == TextureFormat::D24S8)
{
pd.stencilAttachmentPixelFormat = texture.m_ptr.m_obj.pixelFormat;
}
pd.stencilAttachmentPixelFormat = depthStencilTexture.m_ptr.m_obj.pixelFormat;
}
}
}
@@ -2500,7 +2526,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
pd.maxVertexAmplificationCount = cp_layer_renderer_properties_get_view_count(properties);
}
}
#endif
#endif // BX_PLATFORM_VISIONOS
VertexDescriptor vertexDesc = m_vertexDescriptor;
reset(vertexDesc);
@@ -2803,7 +2829,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
ar_session_t m_arSession;
ar_world_tracking_provider_t m_worldTracking;
ar_device_anchor_t m_deviceAnchor;
#endif
#endif // BX_PLATFORM_VISIONOS
// descriptors
RenderPipelineDescriptor m_renderPipelineDescriptor;
@@ -3437,11 +3463,11 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
}
Texture TextureMtl::getTextureMipLevel(int _mip)
Texture TextureMtl::getTextureMipLevel(uint8_t _mip)
{
if (_mip >= 0
&& _mip < m_numMips
&& NULL != m_ptr)
_mip = bx::clamp(_mip, 0, m_numMips);
if (NULL != m_ptr)
{
if (NULL == m_ptrMips[_mip])
{
@@ -3468,7 +3494,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
return m_ptrMips[_mip];
}
return 0;
return nil;
}
SwapChainMtl::~SwapChainMtl()
@@ -3485,18 +3511,15 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
MTL_RELEASE(m_backBufferDepth);
MTL_RELEASE(m_backBufferStencil);
if (NULL != m_backBufferColorMsaa)
{
MTL_RELEASE(m_backBufferColorMsaa);
}
}
void SwapChainMtl::init(void* _nwh)
{
#if BX_PLATFORM_VISIONOS
NSObject* nvh = (NSObject*)_nwh;
m_useLayerRenderer = ![nvh isKindOfClass:[CAMetalLayer class]];
if (m_useLayerRenderer)
{
cp_layer_renderer_t layerRenderer = (cp_layer_renderer_t)_nwh;
@@ -3513,11 +3536,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
else
#endif // BX_PLATFORM_VISIONOS
{
if (NULL != m_metalLayer)
{
MTL_RELEASE(m_metalLayer);
}
#if !BX_PLATFORM_VISIONOS
if (NULL != NSClassFromString(@"MTKView") )
@@ -3574,8 +3594,10 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
return;
}
void (^setLayer)(void) = ^{
void (^setLayer)(void) =
^{
CALayer* layer = contentView.layer;
if(NULL != layer && [layer isKindOfClass:NSClassFromString(@"CAMetalLayer")])
{
m_metalLayer = (CAMetalLayer*)layer;
@@ -3597,12 +3619,12 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
bx::Semaphore semaphore;
bx::Semaphore* psemaphore = &semaphore;
CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop],
kCFRunLoopCommonModes,
CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop], kCFRunLoopCommonModes,
^{
setLayer();
psemaphore->post();
});
semaphore.wait();
}
}
@@ -3617,29 +3639,66 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
m_metalLayer.device = s_renderMtl->m_device;
m_metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
m_metalLayer.magnificationFilter = kCAFilterNearest;
const Resolution& resolution = s_renderMtl->m_resolution;
m_metalLayer.pixelFormat = (resolution.reset & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[resolution.formatColor].m_fmtSrgb
: s_textureFormat[resolution.formatColor].m_fmt
;
retain(m_metalLayer);
}
m_nwh = _nwh;
}
void SwapChainMtl::resize(FrameBufferMtl &_frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags, uint32_t _maximumDrawableCount)
uint32_t SwapChainMtl::resize(uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat)
{
const int32_t sampleCount = s_msaa[(_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT];
const Resolution& resolution = s_renderMtl->m_resolution;
const uint32_t resetFlags = resolution.reset;
const uint32_t maxFrameLatency = resolution.maxFrameLatency;
const TextureFormat::Enum formatColor = TextureFormat::Count == _format
? resolution.formatColor
: _format
;
const TextureFormat::Enum formatDepthStencil = TextureFormat::Count == _depthFormat
? resolution.formatDepthStencil
: _depthFormat
;
const int32_t sampleCount = s_msaa[(resetFlags & BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT];
if (NULL != m_backBufferDepth)
{
release(m_backBufferDepth);
m_backBufferDepth = NULL;
}
if (NULL != m_backBufferStencil)
{
release(m_backBufferStencil);
m_backBufferStencil = NULL;
}
if (NULL != m_backBufferColorMsaa)
{
release(m_backBufferColorMsaa);
m_backBufferColorMsaa = NULL;
}
#if BX_PLATFORM_OSX
# if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
if (s_renderMtl->m_hasVSync)
{
m_metalLayer.displaySyncEnabled = 0 != (_flags&BGFX_RESET_VSYNC);
m_metalLayer.displaySyncEnabled = !!(resetFlags & BGFX_RESET_VSYNC);
}
if (s_renderMtl->m_hasMaximumDrawableCount)
{
m_metalLayer.maximumDrawableCount = bx::clamp<uint32_t>(
_maximumDrawableCount != 0 ? _maximumDrawableCount : BGFX_CONFIG_MAX_FRAME_LATENCY
maxFrameLatency != 0 ? maxFrameLatency : BGFX_CONFIG_MAX_FRAME_LATENCY
, 2
, 3
);
@@ -3652,24 +3711,18 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
#endif // BX_PLATFORM_VISIONOS
{
m_metalLayer.drawableSize = CGSizeMake(_width, _height);
m_metalLayer.pixelFormat = (_flags & BGFX_RESET_SRGB_BACKBUFFER)
? MTLPixelFormatBGRA8Unorm_sRGB
: MTLPixelFormatBGRA8Unorm
m_metalLayer.pixelFormat = (resetFlags & BGFX_RESET_SRGB_BACKBUFFER)
? s_textureFormat[formatColor].m_fmtSrgb
: s_textureFormat[formatColor].m_fmt
;
}
TextureDescriptor desc = s_renderMtl->m_textureDescriptor;
desc.textureType = sampleCount > 1 ? MTLTextureType2DMultisample : MTLTextureType2D;
if (s_renderMtl->m_hasPixelFormatDepth32Float_Stencil8)
{
desc.pixelFormat = MTLPixelFormatDepth32Float_Stencil8;
}
else
{
desc.pixelFormat = MTLPixelFormatDepth32Float;
}
desc.textureType = sampleCount > 1
? MTLTextureType2DMultisample
: MTLTextureType2D
;
desc.width = _width;
desc.height = _height;
@@ -3686,10 +3739,9 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
desc.usage = MTLTextureUsageRenderTarget;
}
if (NULL != m_backBufferDepth)
if (bimg::isDepth(bimg::TextureFormat::Enum(formatDepthStencil) ) )
{
release(m_backBufferDepth);
}
const MTLPixelFormat depthFormat = s_textureFormat[formatDepthStencil].m_fmt;
#if BX_PLATFORM_VISIONOS
if (m_useLayerRenderer)
@@ -3702,14 +3754,12 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
else
#endif // BX_PLATFORM_VISIONOS
{
desc.pixelFormat = depthFormat;
m_backBufferDepth = s_renderMtl->m_device.newTextureWithDescriptor(desc);
}
if (NULL != m_backBufferStencil)
{
release(m_backBufferStencil);
}
if (s_renderMtl->m_hasPixelFormatDepth32Float_Stencil8)
if (MTLPixelFormatDepth24Unorm_Stencil8 == depthFormat
|| MTLPixelFormatDepth32Float_Stencil8 == depthFormat)
{
m_backBufferStencil = m_backBufferDepth;
retain(m_backBufferStencil);
@@ -3719,25 +3769,11 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
desc.pixelFormat = MTLPixelFormatStencil8;
m_backBufferStencil = s_renderMtl->m_device.newTextureWithDescriptor(desc);
}
if (NULL != m_backBufferColorMsaa)
{
release(m_backBufferColorMsaa);
m_backBufferColorMsaa = NULL;
}
if (sampleCount > 1)
{
#if BX_PLATFORM_VISIONOS
if (m_useLayerRenderer)
{
desc.pixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;
}
else
#endif // BX_PLATFORM_VISIONOS
{
desc.pixelFormat = m_metalLayer.pixelFormat;
}
m_backBufferColorMsaa = s_renderMtl->m_device.newTextureWithDescriptor(desc);
}
@@ -3748,12 +3784,13 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
if (!m_useLayerRenderer)
#endif // !BX_PLATFORM_VISIONOS
{
murmur.add( (uint32_t)m_metalLayer.pixelFormat);
murmur.add(m_metalLayer.pixelFormat);
}
murmur.add( (uint32_t)m_backBufferDepth.pixelFormat() );
murmur.add( (uint32_t)m_backBufferStencil.pixelFormat() );
murmur.add( (uint32_t)sampleCount);
_frameBuffer.m_pixelFormatHash = murmur.end();
murmur.add(formatColor);
murmur.add(formatDepthStencil);
murmur.add(sampleCount);
return murmur.end();
}
id <MTLTexture> SwapChainMtl::currentDrawableTexture()
@@ -3923,6 +3960,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
m_denseIdx = _denseIdx;
m_swapChain->init(_nwh);
resizeSwapChain(_width, _height, _format, _depthFormat);
}
void FrameBufferMtl::postReset()
@@ -3939,7 +3977,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
m_num = 0;
m_nwh = NULL;
m_depthHandle.idx = kInvalidHandle;
m_depthHandle = BGFX_INVALID_HANDLE;
uint16_t denseIdx = m_denseIdx;
m_denseIdx = UINT16_MAX;
@@ -3971,6 +4009,11 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
s_renderMtl->endEncoding();
}
void FrameBufferMtl::resizeSwapChain(uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat)
{
m_pixelFormatHash = m_swapChain->resize(_width, _height, _format, _depthFormat);
}
void CommandQueueMtl::init(Device _device)
{
m_commandQueue = _device.newCommandQueue();
@@ -4292,30 +4335,32 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
if (NULL == m_screenshotTarget)
{
m_textureDescriptor.textureType = MTLTextureType2D;
m_textureDescriptor.pixelFormat = getSwapChainPixelFormat(m_mainFrameBuffer.m_swapChain);
m_textureDescriptor.width = m_resolution.width;
m_textureDescriptor.height = m_resolution.height;
m_textureDescriptor.depth = 1;
m_textureDescriptor.mipmapLevelCount = 1;
m_textureDescriptor.sampleCount = 1;
m_textureDescriptor.arrayLength = 1;
TextureDescriptor desc = m_textureDescriptor;
desc.textureType = MTLTextureType2D;
desc.pixelFormat = getSwapChainPixelFormat(m_mainFrameBuffer.m_swapChain);
desc.width = m_resolution.width;
desc.height = m_resolution.height;
desc.depth = 1;
desc.mipmapLevelCount = 1;
desc.sampleCount = 1;
desc.arrayLength = 1;
if (s_renderMtl->m_hasCPUCacheModesAndStorageModes)
{
m_textureDescriptor.cpuCacheMode = MTLCPUCacheModeDefaultCache;
m_textureDescriptor.storageMode = BX_ENABLED(BX_PLATFORM_IOS) || BX_ENABLED(BX_PLATFORM_VISIONOS)
desc.cpuCacheMode = MTLCPUCacheModeDefaultCache;
desc.storageMode = BX_ENABLED(BX_PLATFORM_IOS) || BX_ENABLED(BX_PLATFORM_VISIONOS)
? (MTLStorageMode)0 // MTLStorageModeShared
: (MTLStorageMode)1 // MTLStorageModeManaged
;
m_textureDescriptor.usage = 0
desc.usage = 0
| MTLTextureUsageRenderTarget
| MTLTextureUsageShaderRead
;
}
m_screenshotTarget = m_device.newTextureWithDescriptor(m_textureDescriptor);
m_screenshotTarget = m_device.newTextureWithDescriptor(desc);
}
}
else
@@ -5480,7 +5525,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
}
endEncoding();
m_renderCommandEncoderFrameBufferHandle.idx = kInvalidHandle;
m_renderCommandEncoderFrameBufferHandle = BGFX_INVALID_HANDLE;
if (m_screenshotTarget)
{

View File

@@ -1949,7 +1949,13 @@ VK_IMPORT_DEVICE
m_swapChainFormats[ii] = TextureFormat::Enum(ii);
}
result = m_backBuffer.create(UINT16_MAX, g_platformData.nwh, m_resolution.width, m_resolution.height, m_resolution.format);
result = m_backBuffer.create(
UINT16_MAX
, g_platformData.nwh
, m_resolution.width
, m_resolution.height
, m_resolution.formatColor
);
if (VK_SUCCESS != result)
{
@@ -2357,7 +2363,7 @@ VK_IMPORT_DEVICE
m_commandBuffer
, stagingBuffer
, texture.m_currentImageLayout
, texture.m_aspectMask
, texture.m_aspectFlags
, _mip
);
@@ -2815,7 +2821,8 @@ VK_IMPORT_DEVICE
);
if (false
|| m_resolution.format != _resolution.format
|| m_resolution.formatColor != _resolution.formatColor
|| m_resolution.formatDepthStencil != _resolution.formatDepthStencil
|| m_resolution.width != _resolution.width
|| m_resolution.height != _resolution.height
|| m_resolution.reset != flags
@@ -3379,7 +3386,7 @@ VK_IMPORT_DEVICE
{
const TextureVK& texture = m_textures[_attachments[ii].handle.idx];
formats[ii] = texture.m_format;
aspects[ii] = texture.m_aspectMask;
aspects[ii] = texture.m_aspectFlags;
samples = texture.m_sampler.Sample;
}
@@ -3393,19 +3400,27 @@ VK_IMPORT_DEVICE
swapChain.m_sci.imageFormat,
swapChain.m_backBufferDepthStencil.m_format
};
const VkImageAspectFlags aspects[2] =
{
VK_IMAGE_ASPECT_COLOR_BIT,
swapChain.m_backBufferDepthStencil.m_aspectMask
swapChain.m_backBufferDepthStencil.m_aspectFlags
};
const bool resolve[2] =
{
swapChain.m_supportsManualResolve ? false : true,
false
};
const VkSampleCountFlagBits samples = swapChain.m_sampler.Sample;
return getRenderPass(BX_COUNTOF(formats), formats, aspects, resolve, samples, _renderPass, _clearFlags);
const uint8_t num = swapChain.hasDepthStencil()
? BX_COUNTOF(formats)
: 1
;
return getRenderPass(num, formats, aspects, resolve, samples, _renderPass, _clearFlags);
}
VkSampler getSampler(uint32_t _flags, VkFormat _format, const float _palette[][4])
@@ -3519,7 +3534,7 @@ VK_IMPORT_DEVICE
{
const TextureVK& texture = m_textures[_handle.idx];
_stencil = _stencil && !!(texture.m_aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT);
_stencil = _stencil && !!(texture.m_aspectFlags & VK_IMAGE_ASPECT_STENCIL_BIT);
bx::HashMurmur2A hash;
hash.begin();
@@ -4263,14 +4278,14 @@ VK_IMPORT_DEVICE
{
mrtFormat[ii] = bgfx::TextureFormat::Enum(m_textures[fb.m_texture[ii].idx].m_requestedFormat);
}
depthAspectMask = isValid(fb.m_depth) ? m_textures[fb.m_depth.idx].m_aspectMask : 0;
depthAspectMask = isValid(fb.m_depth) ? m_textures[fb.m_depth.idx].m_aspectFlags : 0;
rect[0].layerCount = fb.m_attachment[0].numLayers;
}
else
{
numMrt = 1;
mrtFormat[0] = fb.m_swapChain.m_colorFormat;
depthAspectMask = fb.m_swapChain.m_backBufferDepthStencil.m_aspectMask;
depthAspectMask = fb.m_swapChain.m_backBufferDepthStencil.m_aspectFlags;
}
VkClearAttachment attachments[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS + 1];
@@ -5986,7 +6001,7 @@ VK_DESTROY
m_textureFormat = uint8_t(bimg::TextureFormat::Count);
m_format = _format;
m_components = { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY };
m_aspectMask = getAspectMask(m_format);
m_aspectFlags = getAspectMask(m_format);
m_sampler = s_msaa[bx::uint32_satsub( (m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT, 1)];
m_type = VK_IMAGE_VIEW_TYPE_2D;
m_numMips = 1;
@@ -5996,7 +6011,7 @@ VK_DESTROY
if (VK_SUCCESS == result)
{
const VkImageLayout layout = 0 != (m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) )
const VkImageLayout layout = 0 != (m_aspectFlags & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) )
? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
;
@@ -6044,9 +6059,10 @@ VK_DESTROY
| VK_IMAGE_USAGE_TRANSFER_DST_BIT
| VK_IMAGE_USAGE_SAMPLED_BIT
| (m_flags & BGFX_TEXTURE_RT_MASK
? (m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
? (m_aspectFlags & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
)
: 0
)
| (m_flags & BGFX_TEXTURE_COMPUTE_WRITE ? VK_IMAGE_USAGE_STORAGE_BIT : 0)
@@ -6178,7 +6194,7 @@ VK_DESTROY
const bool convert = m_textureFormat != m_requestedFormat;
const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) );
m_aspectMask = getAspectMask(m_format);
m_aspectFlags = getAspectMask(m_format);
m_sampler = s_msaa[bx::uint32_satsub( (m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT, 1)];
if (imageContainer.m_cubeMap)
@@ -6355,7 +6371,7 @@ VK_DESTROY
bufferCopyInfo[ii].bufferOffset = totalMemSize;
bufferCopyInfo[ii].bufferRowLength = 0; // assume that image data are tightly aligned
bufferCopyInfo[ii].bufferImageHeight = 0; // assume that image data are tightly aligned
bufferCopyInfo[ii].imageSubresource.aspectMask = m_aspectMask;
bufferCopyInfo[ii].imageSubresource.aspectMask = m_aspectFlags;
bufferCopyInfo[ii].imageSubresource.mipLevel = imageInfos[ii].mipLevel;
bufferCopyInfo[ii].imageSubresource.baseArrayLayer = imageInfos[ii].layer;
bufferCopyInfo[ii].imageSubresource.layerCount = 1;
@@ -6453,6 +6469,7 @@ VK_DESTROY
s_renderVK->recycleMemory(m_singleMsaaDeviceMem);
}
m_aspectFlags = VK_IMAGE_ASPECT_NONE;
m_currentImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
m_currentSingleMsaaImageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
}
@@ -6479,7 +6496,7 @@ VK_DESTROY
region.bufferOffset = 0;
region.bufferRowLength = (_pitch == UINT16_MAX ? 0 : _pitch * 8 / bpp);
region.bufferImageHeight = 0;
region.imageSubresource.aspectMask = m_aspectMask;
region.imageSubresource.aspectMask = m_aspectFlags;
region.imageSubresource.mipLevel = _mip;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
@@ -6613,13 +6630,13 @@ VK_DESTROY
VkImageBlit blit;
blit.srcOffsets[0] = { 0, 0, 0 };
blit.srcOffsets[1] = { mipWidth, mipHeight, 1 };
blit.srcSubresource.aspectMask = m_aspectMask;
blit.srcSubresource.aspectMask = m_aspectFlags;
blit.srcSubresource.mipLevel = 0;
blit.srcSubresource.baseArrayLayer = _layer;
blit.srcSubresource.layerCount = numLayers;
blit.dstOffsets[0] = { 0, 0, 0 };
blit.dstOffsets[1] = { mipWidth, mipHeight, 1 };
blit.dstSubresource.aspectMask = m_aspectMask;
blit.dstSubresource.aspectMask = m_aspectFlags;
blit.dstSubresource.mipLevel = 0;
blit.dstSubresource.baseArrayLayer = _layer;
blit.dstSubresource.layerCount = numLayers;
@@ -6640,7 +6657,7 @@ VK_DESTROY
vk::setImageMemoryBarrier(
_commandBuffer
, m_textureImage
, m_aspectMask
, m_aspectFlags
, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
, blit.srcSubresource.mipLevel
@@ -6664,7 +6681,7 @@ VK_DESTROY
vk::setImageMemoryBarrier(
_commandBuffer
, m_textureImage
, m_aspectMask
, m_aspectFlags
, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL
, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
, _mip
@@ -6740,7 +6757,7 @@ VK_DESTROY
vk::setImageMemoryBarrier(
_commandBuffer
, image
, m_aspectMask
, m_aspectFlags
, currentLayout
, _newImageLayout
);
@@ -6757,7 +6774,7 @@ VK_DESTROY
{
BX_ASSERT(false
|| !_renderTarget
|| !(m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) )
|| !(m_aspectFlags & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) )
, "3D image can't be a depth attachment"
);
}
@@ -6783,7 +6800,7 @@ VK_DESTROY
viewInfo.viewType = _type;
viewInfo.format = m_format;
viewInfo.components = m_components;
viewInfo.subresourceRange.aspectMask = m_aspectMask & _aspectMask;
viewInfo.subresourceRange.aspectMask = m_aspectFlags & _aspectMask;
viewInfo.subresourceRange.baseMipLevel = _mip;
viewInfo.subresourceRange.levelCount = _numMips;
viewInfo.subresourceRange.baseArrayLayer = _layer;
@@ -6824,21 +6841,23 @@ VK_DESTROY
{
case VK_FORMAT_S8_UINT:
return VK_IMAGE_ASPECT_STENCIL_BIT;
break;
case VK_FORMAT_D16_UNORM:
case VK_FORMAT_X8_D24_UNORM_PACK32:
case VK_FORMAT_D32_SFLOAT:
return VK_IMAGE_ASPECT_DEPTH_BIT;
case VK_FORMAT_D16_UNORM_S8_UINT:
case VK_FORMAT_D24_UNORM_S8_UINT:
case VK_FORMAT_D32_SFLOAT_S8_UINT:
return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
default:
return VK_IMAGE_ASPECT_COLOR_BIT;
}
}
VkResult SwapChainVK::create(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution, TextureFormat::Enum _depthFormat)
VkResult SwapChainVK::create(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution)
{
struct ErrorState
{
@@ -6862,7 +6881,6 @@ VK_DESTROY
m_nwh = _nwh;
m_resolution = _resolution;
m_depthFormat = TextureFormat::Count == _depthFormat ? TextureFormat::D24S8 : _depthFormat;
m_queue = s_renderVK->m_globalQueue;
@@ -6883,7 +6901,6 @@ VK_DESTROY
m_sci.imageArrayLayers = 1;
m_sci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
m_sci.queueFamilyIndexCount = 0;
m_sci.pQueueFamilyIndices = NULL;
m_sci.preTransform = BX_ENABLED(BX_PLATFORM_NX)
? VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR
: VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
@@ -7002,7 +7019,8 @@ VK_DESTROY
const bool recreateSwapchain = false
|| m_needToRecreateSwapchain
|| m_resolution.format != _resolution.format
|| m_resolution.formatColor != _resolution.formatColor
|| m_resolution.formatDepthStencil != _resolution.formatDepthStencil
|| m_resolution.width != _resolution.width
|| m_resolution.height != _resolution.height
|| (m_resolution.reset & recreateSwapchainMask) != (_resolution.reset & recreateSwapchainMask)
@@ -7305,7 +7323,8 @@ VK_DESTROY
const VkColorSpaceKHR surfaceColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
const bool srgb = !!(m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER);
m_colorFormat = findSurfaceFormat(m_resolution.format, surfaceColorSpace, srgb);
m_colorFormat = findSurfaceFormat(m_resolution.formatColor, surfaceColorSpace, srgb);
m_depthFormat = bgfx::TextureFormat::UnknownDepth;
if (TextureFormat::Count == m_colorFormat)
{
@@ -7534,12 +7553,14 @@ VK_DESTROY
: BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
;
if (bimg::isDepth(bimg::TextureFormat::Enum(m_resolution.formatDepthStencil) ) )
{
// the spec guarantees that at least one of D24S8 and D32FS8 is supported
VkFormat depthFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
if (g_caps.formats[m_depthFormat] & requiredCaps)
if (g_caps.formats[m_resolution.formatDepthStencil] & requiredCaps)
{
depthFormat = s_textureFormat[m_depthFormat].m_fmtDsv;
depthFormat = s_textureFormat[m_resolution.formatDepthStencil].m_fmtDsv;
}
else if (g_caps.formats[TextureFormat::D24S8] & requiredCaps)
{
@@ -7560,7 +7581,12 @@ VK_DESTROY
return result;
}
result = m_backBufferDepthStencil.createView(0, 1, 0, 1, VK_IMAGE_VIEW_TYPE_2D, m_backBufferDepthStencil.m_aspectMask, true, &m_backBufferDepthStencilImageView);
result = m_backBufferDepthStencil.createView(0, 1, 0, 1
, VK_IMAGE_VIEW_TYPE_2D
, m_backBufferDepthStencil.m_aspectFlags
, true
, &m_backBufferDepthStencilImageView
);
if (VK_SUCCESS != result)
{
@@ -7584,7 +7610,12 @@ VK_DESTROY
return result;
}
result = m_backBufferColorMsaa.createView(0, 1, 0, 1, VK_IMAGE_VIEW_TYPE_2D, m_backBufferColorMsaa.m_aspectMask, true, &m_backBufferColorMsaaImageView);
result = m_backBufferColorMsaa.createView(0, 1, 0, 1
, VK_IMAGE_VIEW_TYPE_2D
, m_backBufferColorMsaa.m_aspectFlags
, true
, &m_backBufferColorMsaaImageView
);
if (VK_SUCCESS != result)
{
@@ -7592,6 +7623,7 @@ VK_DESTROY
return result;
}
}
}
return result;
}
@@ -7626,14 +7658,18 @@ VK_DESTROY
for (uint32_t ii = 0; ii < m_numSwapChainImages; ++ii)
{
uint32_t numAttachments = 2;
::VkImageView attachments[3] =
{
m_sampler.Count > 1
uint32_t numAttachments = 0;
::VkImageView attachments[3];
attachments[numAttachments++] = m_sampler.Count > 1
? m_backBufferColorMsaaImageView
: m_backBufferColorImageView[ii],
m_backBufferDepthStencilImageView,
};
: m_backBufferColorImageView[ii]
;
if (NULL != m_backBufferDepthStencilImageView)
{
attachments[numAttachments++] = m_backBufferDepthStencilImageView;
}
if (m_sampler.Count > 1 && !m_supportsManualResolve)
{
@@ -7971,22 +8007,24 @@ VK_DESTROY
postReset();
}
VkResult FrameBufferVK::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat)
VkResult FrameBufferVK::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _colorFormat, TextureFormat::Enum _depthFormat)
{
BGFX_PROFILER_SCOPE("FrameBufferVK::create", kColorFrame);
VkResult result = VK_SUCCESS;
Resolution resolution = s_renderVK->m_resolution;
resolution.format = TextureFormat::Count == _format ? resolution.format : _format;
resolution.formatColor = TextureFormat::Count == _colorFormat ? resolution.formatColor : _colorFormat;
resolution.formatDepthStencil = TextureFormat::Count == _depthFormat ? resolution.formatDepthStencil : _depthFormat;
resolution.width = _width;
resolution.height = _height;
if (_denseIdx != UINT16_MAX)
{
resolution.reset &= ~BGFX_RESET_MSAA_MASK;
}
result = m_swapChain.create(s_renderVK->m_commandBuffer, _nwh, resolution, _depthFormat);
result = m_swapChain.create(s_renderVK->m_commandBuffer, _nwh, resolution);
if (VK_SUCCESS != result)
{
@@ -8009,7 +8047,6 @@ VK_DESTROY
return result;
}
VkRenderPass FrameBufferVK::getRenderPass(uint16_t _clearFlags) const
{
VkRenderPass renderPass;
@@ -8065,17 +8102,17 @@ VK_DESTROY
, at.mip
, 1
, at.numLayers > 1 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D
, texture.m_aspectMask
, texture.m_aspectFlags
, true
, &m_textureImageViews[ii]
) );
if (texture.m_aspectMask & VK_IMAGE_ASPECT_COLOR_BIT)
if (texture.m_aspectFlags & VK_IMAGE_ASPECT_COLOR_BIT)
{
m_texture[m_num] = at.handle;
m_num++;
}
else if (texture.m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) )
else if (texture.m_aspectFlags & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) )
{
m_depth = at.handle;
}
@@ -8574,14 +8611,14 @@ VK_DESTROY
);
VkImageCopy copyInfo;
copyInfo.srcSubresource.aspectMask = src.m_aspectMask;
copyInfo.srcSubresource.aspectMask = src.m_aspectFlags;
copyInfo.srcSubresource.mipLevel = blit.m_srcMip;
copyInfo.srcSubresource.baseArrayLayer = 0;
copyInfo.srcSubresource.layerCount = 1;
copyInfo.srcOffset.x = blit.m_srcX;
copyInfo.srcOffset.y = blit.m_srcY;
copyInfo.srcOffset.z = 0;
copyInfo.dstSubresource.aspectMask = dst.m_aspectMask;
copyInfo.dstSubresource.aspectMask = dst.m_aspectFlags;
copyInfo.dstSubresource.mipLevel = blit.m_dstMip;
copyInfo.dstSubresource.baseArrayLayer = 0;
copyInfo.dstSubresource.layerCount = 1;
@@ -8804,12 +8841,13 @@ VK_DESTROY
currentBindHash = 0;
}
if (beginRenderPass && (_render->m_view[view].m_fbh.idx != fbh.idx ||
_render->m_view[view].m_rect.m_x != viewState.m_rect.m_x ||
_render->m_view[view].m_rect.m_y != viewState.m_rect.m_y ||
_render->m_view[view].m_rect.m_width != viewState.m_rect.m_width ||
_render->m_view[view].m_rect.m_height != viewState.m_rect.m_height)
)
if (beginRenderPass && (false
|| _render->m_view[view].m_fbh.idx != fbh.idx
|| _render->m_view[view].m_rect.m_x != viewState.m_rect.m_x
|| _render->m_view[view].m_rect.m_y != viewState.m_rect.m_y
|| _render->m_view[view].m_rect.m_width != viewState.m_rect.m_width
|| _render->m_view[view].m_rect.m_height != viewState.m_rect.m_height
) )
{
vkCmdEndRenderPass(m_commandBuffer);
beginRenderPass = false;
@@ -8902,13 +8940,14 @@ VK_DESTROY
{
mrtFormat[ii] = bgfx::TextureFormat::Enum(m_textures[fb.m_texture[ii].idx].m_requestedFormat);
}
depthAspectMask = isValid(fb.m_depth) ? m_textures[fb.m_depth.idx].m_aspectMask : 0;
depthAspectMask = isValid(fb.m_depth) ? m_textures[fb.m_depth.idx].m_aspectFlags : 0;
}
else
{
numMrt = 1;
mrtFormat[0] = fb.m_swapChain.m_colorFormat;
depthAspectMask = fb.m_swapChain.m_backBufferDepthStencil.m_aspectMask;
depthAspectMask = fb.m_swapChain.m_backBufferDepthStencil.m_aspectFlags;
}
VkClearValue clearValues[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS + 1];

View File

@@ -679,6 +679,7 @@ VK_DESTROY_FUNC(DescriptorSet);
: m_directAccessPtr(NULL)
, m_sampler({ 1, VK_SAMPLE_COUNT_1_BIT })
, m_format(VK_FORMAT_UNDEFINED)
, m_aspectFlags(VK_IMAGE_ASPECT_NONE)
, m_textureImage(VK_NULL_HANDLE)
, m_textureDeviceMem()
, m_currentImageLayout(VK_IMAGE_LAYOUT_UNDEFINED)
@@ -718,7 +719,7 @@ VK_DESTROY_FUNC(DescriptorSet);
VkImageViewType m_type;
VkFormat m_format;
VkComponentMapping m_components;
VkImageAspectFlags m_aspectMask;
VkImageAspectFlags m_aspectFlags;
VkImage m_textureImage;
DeviceMemoryAllocationVK m_textureDeviceMem;
@@ -746,11 +747,12 @@ VK_DESTROY_FUNC(DescriptorSet);
, m_swapChain(VK_NULL_HANDLE)
, m_lastImageRenderedSemaphore(VK_NULL_HANDLE)
, m_lastImageAcquiredSemaphore(VK_NULL_HANDLE)
, m_backBufferDepthStencilImageView(VK_NULL_HANDLE)
, m_backBufferColorMsaaImageView(VK_NULL_HANDLE)
{
}
VkResult create(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution, TextureFormat::Enum _depthFormat = TextureFormat::Count);
VkResult create(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution);
void destroy();
@@ -774,6 +776,8 @@ VK_DESTROY_FUNC(DescriptorSet);
void transitionImage(VkCommandBuffer _commandBuffer);
bool hasDepthStencil() const { return VK_NULL_HANDLE != m_backBufferDepthStencilImageView; }
VkQueue m_queue;
VkSwapchainCreateInfoKHR m_sci;