Browse Source

Added ability to configure backbuffer depth/stencil.

Бранимир Караџић 3 tháng trước cách đây
mục cha
commit
959cab248e

+ 2 - 1
bindings/bf/bgfx.bf

@@ -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;

+ 4 - 2
bindings/c3/bgfx.c3

@@ -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.

+ 2 - 1
bindings/cs/bgfx.cs

@@ -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;

+ 3 - 2
bindings/d/package.d

@@ -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.

+ 2 - 1
bindings/zig/bgfx.zig

@@ -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,

+ 1 - 1
examples/25-c99/helloworld.c

@@ -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);

+ 8 - 7
include/bgfx/bgfx.h

@@ -658,13 +658,14 @@ namespace bgfx
 	{
 		Resolution();
 
-		TextureFormat::Enum format; //!< Backbuffer format.
-		uint32_t width;             //!< Backbuffer width.
-		uint32_t height;            //!< Backbuffer height.
-		uint32_t reset;             //!< Reset parameters.
-		uint8_t  numBackBuffers;    //!< Number of back buffers.
-		uint8_t  maxFrameLatency;   //!< Maximum frame latency.
-		uint8_t  debugTextScale;    //!< Scale factor for debug text.
+		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.
+		uint8_t  numBackBuffers;                //!< Number of back buffers.
+		uint8_t  maxFrameLatency;               //!< Maximum frame latency.
+		uint8_t  debugTextScale;                //!< Scale factor for debug text.
 	};
 
 	/// Initialization parameters used by `bgfx::init`.

+ 2 - 1
include/bgfx/c99/bgfx.h

@@ -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.                        */

+ 1 - 1
include/bgfx/defines.h

@@ -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.

+ 9 - 8
scripts/bgfx.idl

@@ -1,7 +1,7 @@
 -- vim: syntax=lua
 -- bgfx interface
 
-version(130)
+version(131)
 
 typedef "bool"
 typedef "char"
@@ -792,13 +792,14 @@ struct.PlatformData { ctor }
 
 --- Backbuffer resolution and reset parameters.
 struct.Resolution { ctor }
-	.format          "TextureFormat::Enum" --- Backbuffer format.
-	.width           "uint32_t"            --- Backbuffer width.
-	.height          "uint32_t"            --- Backbuffer height.
-	.reset           "uint32_t"            --- Reset parameters.
-	.numBackBuffers  "uint8_t"             --- Number of back buffers.
-	.maxFrameLatency "uint8_t"             --- Maximum frame latency.
-	.debugTextScale  "uint8_t"             --- Scale factor for debug text.
+	.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.
+	.numBackBuffers     "uint8_t"             --- Number of back buffers.
+	.maxFrameLatency    "uint8_t"             --- Maximum frame latency.
+	.debugTextScale     "uint8_t"             --- Scale factor for debug text.
 
 --- Configurable runtime limits parameters.
 struct.Limits { ctor, namespace = "Init" }

+ 8 - 4
src/bgfx.cpp

@@ -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)

+ 11 - 7
src/bgfx_p.h

@@ -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.width  == _width
-			&&  m_init.resolution.height == _height
-			&&  m_init.resolution.reset  == _flags)
+			&&  m_init.resolution.formatColor == formatColor
+			&&  m_init.resolution.width       == _width
+			&&  m_init.resolution.height      == _height
+			&&  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

+ 41 - 34
src/glcontext_egl.cpp

@@ -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);
 	}

+ 3 - 3
src/glcontext_egl.h

@@ -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);

+ 32 - 24
src/glcontext_html5.cpp

@@ -64,15 +64,26 @@ 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)
 	{
-		// assert?
-		if (m_primary != NULL)
+		if (NULL != m_primary)
+		{
 			return;
+		}
+		const bimg::ImageBlockInfo& colorBlockInfo       = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatColor) );
+		const bimg::ImageBlockInfo& depthStecilBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(_resolution.formatDepthStencil) );
 
-		const char* canvas = (const char*) g_platformData.nwh;
+		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;
 
-		EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = bx::narrowCast<EMSCRIPTEN_WEBGL_CONTEXT_HANDLE>((uintptr_t) g_platformData.context);
+		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)
 		{
 			if (emscripten_webgl_get_context_attributes(context, &s_attrs) >= 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,32 +128,25 @@ 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;
+		const char* canvas = (const char*)_nwh;
 		int32_t error = 0;
 
 		for (int version = 2; version >= 1; --version)

+ 3 - 3
src/glcontext_html5.h

@@ -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);

+ 24 - 18
src/glcontext_wgl.cpp

@@ -63,19 +63,22 @@ 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.iLayerType = PFD_MAIN_PLANE;
+		pfd.dwFlags  = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+		pfd.iPixelType   = PFD_TYPE_RGBA;
+		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);
 		BGFX_FATAL(0 != pixelFormat, Fatal::UnableToInitialize, "ChoosePixelFormat failed!");
@@ -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);

+ 3 - 3
src/glcontext_wgl.h

@@ -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);

+ 23 - 12
src/renderer_d3d11.cpp

@@ -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;
@@ -2465,10 +2472,12 @@ namespace bgfx { namespace d3d11
 				| BGFX_RESET_SUSPEND
 				);
 
-			if (m_resolution.width            !=  _resolution.width
-			||  m_resolution.height           !=  _resolution.height
-			||  m_resolution.format           !=  _resolution.format
-			|| (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) )
+			if (m_resolution.width              != _resolution.width
+			||  m_resolution.height             != _resolution.height
+			||  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;

+ 58 - 41
src/renderer_d3d12.cpp

@@ -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,33 +2458,36 @@ namespace bgfx { namespace d3d12
 				}
 			}
 
-			D3D12_RESOURCE_DESC resourceDesc;
-			resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
-			resourceDesc.Alignment = 1 < m_scd.sampleDesc.Count ? D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT : 0;
-			resourceDesc.Width     = bx::uint32_max(m_resolution.width,  1);
-			resourceDesc.Height    = bx::uint32_max(m_resolution.height, 1);
-			resourceDesc.DepthOrArraySize = 1;
-			resourceDesc.MipLevels        = 1;
-			resourceDesc.Format           = DXGI_FORMAT_D24_UNORM_S8_UINT;
-			resourceDesc.SampleDesc       = m_scd.sampleDesc;
-			resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
-			resourceDesc.Flags  = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
-
-			D3D12_CLEAR_VALUE clearValue;
-			clearValue.Format = resourceDesc.Format;
-			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) );
+			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;
+				resourceDesc.Width     = bx::uint32_max(m_resolution.width,  1);
+				resourceDesc.Height    = bx::uint32_max(m_resolution.height, 1);
+				resourceDesc.DepthOrArraySize = 1;
+				resourceDesc.MipLevels        = 1;
+				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;
+
+				D3D12_CLEAR_VALUE clearValue;
+				clearValue.Format = resourceDesc.Format;
+				clearValue.DepthStencil.Depth   = 1.0f;
+				clearValue.DepthStencil.Stencil = 0;
+
+				m_backBufferDepthStencil = createCommittedResource(m_device, HeapProperty::Default, &resourceDesc, &clearValue);
+				m_device->CreateDepthStencilView(m_backBufferDepthStencil, NULL, getCPUHandleHeapStart(m_dsvDescriptorHeap) );
 
-			setResourceBarrier(m_commandList
-				, m_backBufferDepthStencil
-				, D3D12_RESOURCE_STATE_COMMON
-				, D3D12_RESOURCE_STATE_DEPTH_WRITE
-				);
+				setResourceBarrier(m_commandList
+					, m_backBufferDepthStencil
+					, D3D12_RESOURCE_STATE_COMMON
+					, D3D12_RESOURCE_STATE_DEPTH_WRITE
+					);
+			}
 
 			for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii)
 			{
@@ -2564,10 +2575,11 @@ namespace bgfx { namespace d3d12
 				| BGFX_RESET_SUSPEND
 				);
 
-			if (m_resolution.width            !=  _resolution.width
-			||  m_resolution.height           !=  _resolution.height
-			||  m_resolution.format           !=  _resolution.format
-			|| (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) )
+			if (m_resolution.width              !=  _resolution.width
+			||  m_resolution.height             !=  _resolution.height
+			||  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);
 				}
 			}

+ 12 - 14
src/renderer_gl.cpp

@@ -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;

+ 1 - 1
src/renderer_gl.h

@@ -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();

+ 36 - 20
src/renderer_mtl.h

@@ -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
  */
 
@@ -19,8 +19,8 @@
 #endif // BX_PLATFORM_*
 
 #if BX_PLATFORM_VISIONOS
-#import <CompositorServices/CompositorServices.h>
-#endif
+#	import <CompositorServices/CompositorServices.h>
+#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(
@@ -58,12 +58,13 @@ 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;
+		return  (v.majorVersion<<16) + (v.minorVersion<<8) + v.patchVersion >=
+				( _majorVersion<<16) + ( _minorVersion<<8) +  _patchVersion
+				;
 #else
 		BX_UNUSED(_majorVersion, _minorVersion, _patchVersion);
 		return false;
-#endif
+#endif // BX_PLATFORM_OSX
 	}
 
 	// c++ wrapper
@@ -747,10 +748,13 @@ namespace bgfx { namespace mtl
 		return [_str UTF8String];
 	}
 
-#define MTL_RELEASE(_obj) \
-	BX_MACRO_BLOCK_BEGIN  \
-		[_obj release];   \
-		_obj = NULL;      \
+#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,9 +1075,14 @@ 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();
+		id<MTLTexture> currentDrawableTexture();
 
 		CAMetalLayer* m_metalLayer;
 #if BX_PLATFORM_VISIONOS
@@ -1080,10 +1091,10 @@ 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;
+		id <MTLTexture> m_drawableTexture;
 		Texture m_backBufferColorMsaa;
 		Texture m_backBufferDepth;
 		Texture m_backBufferStencil;
@@ -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];

+ 232 - 187
src/renderer_mtl.mm

@@ -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"
@@ -498,10 +483,10 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 			BX_UNUSED(_init);
 			BX_TRACE("Init.");
 
-#define CHECK_FEATURE_AVAILABLE(feature, ...) \
-	BX_MACRO_BLOCK_BEGIN \
-		if (@available(__VA_ARGS__)) { feature = true; } else { feature = false; } \
-		BX_TRACE("[MTL] OS feature %s: %d", (#feature) + 2, feature); \
+#define CHECK_FEATURE_AVAILABLE(feature, ...)                                       \
+	BX_MACRO_BLOCK_BEGIN                                                            \
+		if (@available(__VA_ARGS__) ) { feature = true; } else { feature = false; } \
+		BX_TRACE("[MTL] OS feature %s: %d", (#feature) + 2, feature);               \
 	BX_MACRO_BLOCK_END
 
 			CHECK_FEATURE_AVAILABLE(m_usesMTLBindings, macOS 13.0, iOS 16.0, tvOS 16.0, macCatalyst 16.0, VISION_OS_MINIMUM *);
@@ -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,27 +517,29 @@ 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
 			if (m_mainFrameBuffer.m_swapChain->m_useLayerRenderer)
 			{
 				m_deviceAnchor = ar_device_anchor_create();
-				m_worldTracking = ar_world_tracking_provider_create(ar_world_tracking_configuration_create());
+				m_worldTracking = ar_world_tracking_provider_create(ar_world_tracking_configuration_create() );
 				m_arSession = ar_session_create();
-				ar_session_run(m_arSession, ar_data_providers_create_with_data_providers(m_worldTracking, nil));
+				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))
+
+			if ( (useLayerRenderer && NULL == m_mainFrameBuffer.m_swapChain->m_layerRenderer)
+			||  (!useLayerRenderer && NULL == m_mainFrameBuffer.m_swapChain->m_metalLayer)
+			   )
 #else
 			if (NULL == m_mainFrameBuffer.m_swapChain->m_metalLayer)
 #endif // BX_PLATFORM_VISIONOS
@@ -735,17 +722,39 @@ 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))
+			if (BX_ENABLED(BX_PLATFORM_OSX) )
 			{
-				s_textureFormat[TextureFormat::R8].m_fmtSrgb  = MTLPixelFormatInvalid;
+				s_textureFormat[TextureFormat::R8 ].m_fmtSrgb = MTLPixelFormatInvalid;
 				s_textureFormat[TextureFormat::RG8].m_fmtSrgb = MTLPixelFormatInvalid;
 			}
 
 			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;
@@ -755,8 +764,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 			{
 				s_textureFormat[bgfx::TextureFormat::R5G6B5].m_fmt = MTLPixelFormatInvalid;
 				s_textureFormat[bgfx::TextureFormat::B5G6R5].m_fmt = MTLPixelFormatInvalid;
-				s_textureFormat[bgfx::TextureFormat::BGRA4].m_fmt = MTLPixelFormatInvalid;
-				s_textureFormat[bgfx::TextureFormat::RGBA4].m_fmt = MTLPixelFormatInvalid;
+				s_textureFormat[bgfx::TextureFormat::BGRA4 ].m_fmt = MTLPixelFormatInvalid;
+				s_textureFormat[bgfx::TextureFormat::RGBA4 ].m_fmt = MTLPixelFormatInvalid;
 			}
 
 			const MTLReadWriteTextureTier rwTier = [m_device readWriteTextureSupport];
@@ -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;
@@ -822,7 +839,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 			g_caps.formats[TextureFormat::RGBA32I] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA);
 			g_caps.formats[TextureFormat::RGBA32U] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA);
 
-			if (BX_ENABLED(BX_PLATFORM_IOS) || BX_ENABLED(BX_PLATFORM_VISIONOS))
+			if (BX_ENABLED(BX_PLATFORM_IOS) || BX_ENABLED(BX_PLATFORM_VISIONOS) )
 			{
 				s_textureFormat[TextureFormat::D24S8].m_fmt = MTLPixelFormatDepth32Float_Stencil8;
 
@@ -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,9 +1120,9 @@ 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 uint8_t bpp  = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(texture.m_textureFormat) );
+			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,10 +1560,12 @@ 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);
-						MTL_RELEASE(frameBuffer.m_swapChain->m_drawable);
+						if (NULL != frameBuffer.m_swapChain->m_drawable)
+						{
+							m_commandBuffer.presentDrawable(frameBuffer.m_swapChain->m_drawable);
+							MTL_RELEASE(frameBuffer.m_swapChain->m_drawable);
+						}
 					}
 				}
 			}
@@ -1574,13 +1595,14 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 				m_resolution = _resolution;
 
 				if (m_resolution.reset & BGFX_RESET_INTERNAL_FORCE
-				&& m_mainFrameBuffer.m_swapChain->m_nwh != g_platformData.nwh)
+				&&  m_mainFrameBuffer.m_swapChain->m_nwh != g_platformData.nwh)
 				{
 					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,8 +1614,7 @@ 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))
+				if (prevMetalLayerPixelFormat != getSwapChainPixelFormat(m_mainFrameBuffer.m_swapChain) )
 				{
 					MTL_RELEASE(m_screenshotBlitRenderPipelineState);
 					reset(m_renderPipelineDescriptor);
@@ -2155,7 +2176,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 				{
 					BX_TRACE("arg: %s type:%d", utf8String(arg.name), arg.type);
 
-					if ((!m_usesMTLBindings && [(MTLArgument*)arg isActive]) || (m_usesMTLBindings && arg.used))
+					if ( (!m_usesMTLBindings && [(MTLArgument*)arg isActive]) || (m_usesMTLBindings && arg.used) )
 					{
 						if (arg.type == MTLBindingTypeBuffer)
 						{
@@ -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])
 			{
@@ -3450,8 +3476,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 					m_ptrMips[_mip] = m_ptr.newTextureViewWithPixelFormat(
 						  m_ptr.pixelFormat()
 						, MTLTextureType2DArray
-						, NSMakeRange(_mip,1)
-						, NSMakeRange(0,m_ptr.arrayLength() * 6)
+						, NSMakeRange(_mip, 1)
+						, NSMakeRange(0, m_ptr.arrayLength() * 6)
 						);
 				}
 				else
@@ -3459,8 +3485,8 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 					m_ptrMips[_mip] = m_ptr.newTextureViewWithPixelFormat(
 						  m_ptr.pixelFormat()
 						, m_ptr.textureType()
-						, NSMakeRange(_mip,1)
-						, NSMakeRange(0,m_ptr.arrayLength() )
+						, NSMakeRange(_mip, 1)
+						, NSMakeRange(0, m_ptr.arrayLength() )
 						);
 				}
 			}
@@ -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,11 +3511,7 @@ 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);
-		}
-
+		MTL_RELEASE(m_backBufferColorMsaa);
 	}
 
 	void SwapChainMtl::init(void* _nwh)
@@ -3497,6 +3519,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 #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;
@@ -3514,10 +3537,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 		else
 #endif // BX_PLATFORM_VISIONOS
 		{
-			if (NULL != m_metalLayer)
-			{
-				MTL_RELEASE(m_metalLayer);
-			}
+			MTL_RELEASE(m_metalLayer);
 
 #if !BX_PLATFORM_VISIONOS
 			if (NULL != NSClassFromString(@"MTKView") )
@@ -3539,7 +3559,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 				{
 					CAMetalLayer* metalLayer = (CAMetalLayer*)_nwh;
 					if (NULL == metalLayer
-						|| ![metalLayer isKindOfClass:NSClassFromString(@"CAMetalLayer")])
+					|| ![metalLayer isKindOfClass:NSClassFromString(@"CAMetalLayer")])
 					{
 						BX_WARN(false, "Unable to create Metal device. Please set platform data window to a CAMetalLayer");
 						return;
@@ -3574,15 +3594,17 @@ 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;
 							}
 							else
 							{
-								[contentView setWantsLayer:YES];
+								[contentView setWantsLayer: YES];
 								m_metalLayer = [CAMetalLayer layer];
 								[contentView setLayer:m_metalLayer];
 							}
@@ -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();
 						}
 					}
@@ -3616,30 +3638,67 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 				return;
 			}
 
-			m_metalLayer.device      = s_renderMtl->m_device;
-			m_metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm;
+			m_metalLayer.device              = s_renderMtl->m_device;
 			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,58 +3739,41 @@ 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)
-		{
-			if (m_layerRendererDrawable)
+			if (m_useLayerRenderer)
 			{
-				m_backBufferDepth = cp_drawable_get_depth_texture(m_layerRendererDrawable, 0);
+				if (m_layerRendererDrawable)
+				{
+					m_backBufferDepth = cp_drawable_get_depth_texture(m_layerRendererDrawable, 0);
+				}
 			}
-		}
-		else
+			else
 #endif // BX_PLATFORM_VISIONOS
-		{
-			m_backBufferDepth = s_renderMtl->m_device.newTextureWithDescriptor(desc);
-		}
-		if (NULL != m_backBufferStencil)
-		{
-			release(m_backBufferStencil);
-		}
-
-		if (s_renderMtl->m_hasPixelFormatDepth32Float_Stencil8)
-		{
-			m_backBufferStencil = m_backBufferDepth;
-			retain(m_backBufferStencil);
-		}
-		else
-		{
-			desc.pixelFormat = MTLPixelFormatStencil8;
-			m_backBufferStencil = s_renderMtl->m_device.newTextureWithDescriptor(desc);
-		}
-
-		if (NULL != m_backBufferColorMsaa)
-		{
-			release(m_backBufferColorMsaa);
-			m_backBufferColorMsaa = NULL;
-		}
+			{
+				desc.pixelFormat = depthFormat;
+				m_backBufferDepth = s_renderMtl->m_device.newTextureWithDescriptor(desc);
+			}
 
-		if (sampleCount > 1)
-		{
-#if BX_PLATFORM_VISIONOS
-			if (m_useLayerRenderer)
+			if (MTLPixelFormatDepth24Unorm_Stencil8 == depthFormat
+			||  MTLPixelFormatDepth32Float_Stencil8 == depthFormat)
 			{
-				desc.pixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;
+				m_backBufferStencil = m_backBufferDepth;
+				retain(m_backBufferStencil);
 			}
 			else
-#endif // BX_PLATFORM_VISIONOS
 			{
-				desc.pixelFormat = m_metalLayer.pixelFormat;
+				desc.pixelFormat = MTLPixelFormatStencil8;
+				m_backBufferStencil = s_renderMtl->m_device.newTextureWithDescriptor(desc);
 			}
+		}
+
+		if (sampleCount > 1)
+		{
+			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()
@@ -3773,7 +3810,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 
 					cp_frame_end_update(m_frame);
 
-					cp_time_wait_until(cp_frame_timing_get_optimal_input_time(timing));
+					cp_time_wait_until(cp_frame_timing_get_optimal_input_time(timing) );
 					cp_frame_start_submission(m_frame);
 					m_layerRendererDrawable = cp_frame_query_drawable(m_frame);
 				}
@@ -3916,13 +3953,14 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 	{
 		BX_UNUSED(_format, _depthFormat);
 		m_swapChain = BX_NEW(g_allocator, SwapChainMtl);
-		m_num = 0;
+		m_num       = 0;
 		m_width     = _width;
 		m_height    = _height;
 		m_nwh       = _nwh;
 		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;
@@ -3951,7 +3989,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 	{
 		for (uint32_t ii = 0; ii < m_num; ++ii)
 		{
-			if (0 != (m_colorAttachment[ii].resolve & BGFX_RESOLVE_AUTO_GEN_MIPS))
+			if (0 != (m_colorAttachment[ii].resolve & BGFX_RESOLVE_AUTO_GEN_MIPS) )
 			{
 				const TextureMtl& texture = s_renderMtl->m_textures[m_colorHandle[ii].idx];
 				const bool isRenderTarget = !!(texture.m_flags & BGFX_TEXTURE_RT_MASK);
@@ -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();
@@ -4202,7 +4245,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 			const TextureMtl& dst = m_textures[blit.m_dst.idx];
 
 #if BX_PLATFORM_OSX
-			bool     readBack  = !!(dst.m_flags & BGFX_TEXTURE_READ_BACK);
+			bool readBack = !!(dst.m_flags & BGFX_TEXTURE_READ_BACK);
 #endif  // BX_PLATFORM_OSX
 
 			if (MTLTextureType3D == src.m_ptr.textureType() )
@@ -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
@@ -5127,7 +5172,7 @@ static_assert(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames
 								{
 								case Binding::Image:
 								{
-									if (bind.m_access == Access::ReadWrite && 0 == (g_caps.supported & BGFX_CAPS_IMAGE_RW))
+									if (bind.m_access == Access::ReadWrite && 0 == (g_caps.supported & BGFX_CAPS_IMAGE_RW) )
 									{
 										BGFX_FATAL(
 											  false
@@ -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)
 		{

+ 162 - 123
src/renderer_vk.cpp

@@ -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
 				);
 
@@ -2554,10 +2560,10 @@ VK_IMPORT_DEVICE
 				dul.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
 				dul.pNext = NULL;
 				dul.pLabelName = _marker;
-				dul.color[0] = ((abgr >> 24) & 0xff) / 255.0f;
-				dul.color[1] = ((abgr >> 16) & 0xff) / 255.0f;
-				dul.color[2] = ((abgr >> 8)  & 0xff) / 255.0f;
-				dul.color[3] = ((abgr >> 0)  & 0xff) / 255.0f;
+				dul.color[0] = ( (abgr >> 24) & 0xff) / 255.0f;
+				dul.color[1] = ( (abgr >> 16) & 0xff) / 255.0f;
+				dul.color[2] = ( (abgr >> 8)  & 0xff) / 255.0f;
+				dul.color[3] = ( (abgr >> 0)  & 0xff) / 255.0f;
 
 				vkCmdInsertDebugUtilsLabelEXT(m_commandBuffer, &dul);
 			}
@@ -2815,10 +2821,11 @@ VK_IMPORT_DEVICE
 				);
 
 			if (false
-			||  m_resolution.format != _resolution.format
-			||  m_resolution.width  != _resolution.width
-			||  m_resolution.height != _resolution.height
-			||  m_resolution.reset  != flags
+			||  m_resolution.formatColor        != _resolution.formatColor
+			||  m_resolution.formatDepthStencil != _resolution.formatDepthStencil
+			||  m_resolution.width              != _resolution.width
+			||  m_resolution.height             != _resolution.height
+			||  m_resolution.reset              != flags
 			||  m_backBuffer.m_swapChain.m_needToRecreateSurface
 			||  m_backBuffer.m_swapChain.m_needToRecreateSwapchain)
 			{
@@ -3261,7 +3268,7 @@ VK_IMPORT_DEVICE
 					colorAr[numColorAr].attachment = ii;
 					ad[numColorAr].loadOp = 0 != (_clearFlags & BGFX_CLEAR_COLOR) ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
 
-					if (BGFX_CLEAR_NONE != (_clearFlags & (BGFX_CLEAR_DISCARD_COLOR_0 << ii)))
+					if (BGFX_CLEAR_NONE != (_clearFlags & (BGFX_CLEAR_DISCARD_COLOR_0 << ii) ) )
 					{
 						ad[numColorAr].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
 					}
@@ -3285,9 +3292,9 @@ VK_IMPORT_DEVICE
 				}
 				else if (_aspects[ii] & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) )
 				{
-					ad[ii].loadOp = 0 != (_clearFlags & BGFX_CLEAR_DEPTH) ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
-					ad[ii].storeOp = 0 != (_clearFlags & BGFX_CLEAR_DISCARD_DEPTH) ? VK_ATTACHMENT_STORE_OP_DONT_CARE : VK_ATTACHMENT_STORE_OP_STORE;
-					ad[ii].stencilLoadOp = 0 != (_clearFlags & BGFX_CLEAR_STENCIL) ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
+					ad[ii].loadOp         = 0 != (_clearFlags & BGFX_CLEAR_DEPTH)           ? VK_ATTACHMENT_LOAD_OP_CLEAR      : VK_ATTACHMENT_LOAD_OP_LOAD;
+					ad[ii].storeOp        = 0 != (_clearFlags & BGFX_CLEAR_DISCARD_DEPTH)   ? VK_ATTACHMENT_STORE_OP_DONT_CARE : VK_ATTACHMENT_STORE_OP_STORE;
+					ad[ii].stencilLoadOp  = 0 != (_clearFlags & BGFX_CLEAR_STENCIL)         ? VK_ATTACHMENT_LOAD_OP_CLEAR      : VK_ATTACHMENT_LOAD_OP_LOAD;
 					ad[ii].stencilStoreOp = 0 != (_clearFlags & BGFX_CLEAR_DISCARD_STENCIL) ? VK_ATTACHMENT_STORE_OP_DONT_CARE : VK_ATTACHMENT_STORE_OP_STORE;
 					ad[ii].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
 					ad[ii].initialLayout  = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
@@ -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,24 +3400,32 @@ 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])
 		{
-			uint32_t index = ((_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT);
+			uint32_t index = ( (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT);
 			index = bx::min<uint32_t>(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, index);
 
 			_flags &= BGFX_SAMPLER_BITS_MASK;
@@ -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;
+				mrtFormat[0]    = fb.m_swapChain.m_colorFormat;
+				depthAspectMask = fb.m_swapChain.m_backBufferDepthStencil.m_aspectFlags;
 			}
 
 			VkClearAttachment attachments[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS + 1];
@@ -4534,7 +4549,7 @@ VK_IMPORT_DEVICE
 			}
 
 			// Not enough space or too big, we will create a new staging buffer on the spot.
-			VK_CHECK(createStagingBuffer(_size, &result.m_buffer, &result.m_deviceMem, _data));
+			VK_CHECK(createStagingBuffer(_size, &result.m_buffer, &result.m_deviceMem, _data) );
 
 			result.m_isFromScratch = false;
 			result.m_offset        = 0;
@@ -4717,7 +4732,7 @@ VK_DESTROY
 
 	void MemoryLruVK::recycle(DeviceMemoryAllocationVK &_alloc)
 	{
-		if (MAX_ENTRIES == lru.getNumHandles())
+		if (MAX_ENTRIES == lru.getNumHandles() )
 		{
 			// Evict LRU
 			uint16_t handle = lru.getBack();
@@ -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;
@@ -6367,7 +6383,7 @@ VK_DESTROY
 			if (totalMemSize > 0)
 			{
 				const VkDevice device = s_renderVK->m_device;
-				const bimg::ImageBlockInfo &dstBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat));
+				const bimg::ImageBlockInfo &dstBlockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) );
 
 				StagingBufferVK stagingBuffer = s_renderVK->allocFromScratchStagingBuffer(totalMemSize, dstBlockInfo.blockSize);
 
@@ -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;
@@ -6492,7 +6509,7 @@ VK_DESTROY
 		if (convert)
 		{
 			temp = (uint8_t*)bx::alloc(g_allocator, slicepitch);
-			bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat));
+			bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat) );
 			data = temp;
 
 			region.imageExtent =
@@ -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"
 			);
 		}
@@ -6776,14 +6793,14 @@ VK_DESTROY
 		viewInfo.sType      = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
 		viewInfo.pNext      = NULL;
 		viewInfo.flags      = 0;
-		viewInfo.image      = ((VK_NULL_HANDLE != m_singleMsaaImage) && !_renderTarget)
+		viewInfo.image      = ( (VK_NULL_HANDLE != m_singleMsaaImage) && !_renderTarget)
 			? m_singleMsaaImage
 			: m_textureImage
 			;
 		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,9 +7019,10 @@ VK_DESTROY
 
 		const bool recreateSwapchain = false
 			|| m_needToRecreateSwapchain
-			|| m_resolution.format != _resolution.format
-			|| m_resolution.width  != _resolution.width
-			|| m_resolution.height != _resolution.height
+			|| 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)
 			|| recreateSurface
 			;
@@ -7273,7 +7291,7 @@ VK_DESTROY
 		//  - https://github.com/mpv-player/mpv/issues/8360
 		//  - https://github.com/bkaradzic/bgfx/issues/3227
 		result = vkDeviceWaitIdle(device);
-		BX_WARN(VK_SUCCESS == result, "Create swapchain error: vkDeviceWaitIdle() failed: %d: %s", result, getName(result));
+		BX_WARN(VK_SUCCESS == result, "Create swapchain error: vkDeviceWaitIdle() failed: %d: %s", result, getName(result) );
 
 		VkSurfaceCapabilitiesKHR surfaceCapabilities;
 		result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, &surfaceCapabilities);
@@ -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,63 +7553,76 @@ VK_DESTROY
 			: BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER
 			;
 
-		// 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 (bimg::isDepth(bimg::TextureFormat::Enum(m_resolution.formatDepthStencil) ) )
 		{
-			depthFormat = s_textureFormat[m_depthFormat].m_fmtDsv;
-		}
-		else if (g_caps.formats[TextureFormat::D24S8] & requiredCaps)
-		{
-			depthFormat = s_textureFormat[TextureFormat::D24S8].m_fmtDsv;
-		}
+			// the spec guarantees that at least one of D24S8 and D32FS8 is supported
+			VkFormat depthFormat = VK_FORMAT_D32_SFLOAT_S8_UINT;
 
-		result = m_backBufferDepthStencil.create(
-			  _commandBuffer
-			, m_sci.imageExtent.width
-			, m_sci.imageExtent.height
-			, textureFlags
-			, depthFormat
-			);
-
-		if (VK_SUCCESS != result)
-		{
-			BX_TRACE("Create swapchain error: creating depth stencil image failed %d: %s.", result, getName(result) );
-			return result;
-		}
-
-		result = m_backBufferDepthStencil.createView(0, 1, 0, 1, VK_IMAGE_VIEW_TYPE_2D, m_backBufferDepthStencil.m_aspectMask, true, &m_backBufferDepthStencilImageView);
-
-		if (VK_SUCCESS != result)
-		{
-			BX_TRACE("Create swapchain error: creating depth stencil image view failed %d: %s.", result, getName(result) );
-			return result;
-		}
+			if (g_caps.formats[m_resolution.formatDepthStencil] & requiredCaps)
+			{
+				depthFormat = s_textureFormat[m_resolution.formatDepthStencil].m_fmtDsv;
+			}
+			else if (g_caps.formats[TextureFormat::D24S8] & requiredCaps)
+			{
+				depthFormat = s_textureFormat[TextureFormat::D24S8].m_fmtDsv;
+			}
 
-		if (m_sampler.Count > 1)
-		{
-			result = m_backBufferColorMsaa.create(
+			result = m_backBufferDepthStencil.create(
 				  _commandBuffer
 				, m_sci.imageExtent.width
 				, m_sci.imageExtent.height
 				, textureFlags
-				, m_sci.imageFormat
+				, depthFormat
 				);
 
 			if (VK_SUCCESS != result)
 			{
-				BX_TRACE("Create swapchain error: creating MSAA color image failed %d: %s.", result, getName(result) );
+				BX_TRACE("Create swapchain error: creating depth stencil image failed %d: %s.", result, getName(result) );
 				return result;
 			}
 
-			result = m_backBufferColorMsaa.createView(0, 1, 0, 1, VK_IMAGE_VIEW_TYPE_2D, m_backBufferColorMsaa.m_aspectMask, true, &m_backBufferColorMsaaImageView);
+			result = m_backBufferDepthStencil.createView(0, 1, 0, 1
+				, VK_IMAGE_VIEW_TYPE_2D
+				, m_backBufferDepthStencil.m_aspectFlags
+				, true
+				, &m_backBufferDepthStencilImageView
+			);
 
 			if (VK_SUCCESS != result)
 			{
-				BX_TRACE("Create swapchain error: creating MSAA color image view failed %d: %s.", result, getName(result) );
+				BX_TRACE("Create swapchain error: creating depth stencil image view failed %d: %s.", result, getName(result) );
 				return result;
 			}
+
+			if (m_sampler.Count > 1)
+			{
+				result = m_backBufferColorMsaa.create(
+					  _commandBuffer
+					, m_sci.imageExtent.width
+					, m_sci.imageExtent.height
+					, textureFlags
+					, m_sci.imageFormat
+					);
+
+				if (VK_SUCCESS != result)
+				{
+					BX_TRACE("Create swapchain error: creating MSAA color image failed %d: %s.", result, getName(result) );
+					return result;
+				}
+
+				result = m_backBufferColorMsaa.createView(0, 1, 0, 1
+					, VK_IMAGE_VIEW_TYPE_2D
+					, m_backBufferColorMsaa.m_aspectFlags
+					, true
+					, &m_backBufferColorMsaaImageView
+				);
+
+				if (VK_SUCCESS != result)
+				{
+					BX_TRACE("Create swapchain error: creating MSAA color image view failed %d: %s.", result, getName(result) );
+					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] =
+			uint32_t numAttachments = 0;
+			::VkImageView attachments[3];
+
+			attachments[numAttachments++] = m_sampler.Count > 1
+				? m_backBufferColorMsaaImageView
+				: m_backBufferColorImageView[ii]
+				;
+
+			if (NULL != m_backBufferDepthStencilImageView)
 			{
-				m_sampler.Count > 1
-					? m_backBufferColorMsaaImageView
-					: m_backBufferColorImageView[ii],
-				m_backBufferDepthStencilImageView,
-			};
+				attachments[numAttachments++] = m_backBufferDepthStencilImageView;
+			}
 
 			if (m_sampler.Count > 1 && !m_supportsManualResolve)
 			{
@@ -7843,7 +7879,7 @@ VK_DESTROY
 
 			if (result != VK_SUCCESS)
 			{
-				BX_TRACE("vkAcquireNextImageKHR(...): result = %s", getName(result));
+				BX_TRACE("vkAcquireNextImageKHR(...): result = %s", getName(result) );
 			}
 
 			switch (result)
@@ -7912,7 +7948,7 @@ VK_DESTROY
 
 			if (result != VK_SUCCESS)
 			{
-				BX_TRACE("vkQueuePresentKHR(...): result = %s", getName(result));
+				BX_TRACE("vkQueuePresentKHR(...): result = %s", getName(result) );
 			}
 
 			switch (result)
@@ -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,18 +8047,17 @@ VK_DESTROY
 		return result;
 	}
 
-
 	VkRenderPass FrameBufferVK::getRenderPass(uint16_t _clearFlags) const
 	{
 		VkRenderPass renderPass;
 
 		if (m_numTh > 0)
 		{
-			VK_CHECK(s_renderVK->getRenderPass(m_numTh, m_attachment, &renderPass, _clearFlags));
+			VK_CHECK(s_renderVK->getRenderPass(m_numTh, m_attachment, &renderPass, _clearFlags) );
 		}
 		else
 		{
-			VK_CHECK(s_renderVK->getRenderPass(m_swapChain, &renderPass, _clearFlags));
+			VK_CHECK(s_renderVK->getRenderPass(m_swapChain, &renderPass, _clearFlags) );
 		}
 
 		return 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;
@@ -8796,7 +8833,7 @@ VK_DESTROY
 					}
 				}
 
-				if(!isCompute && (viewChanged || wasCompute))
+				if(!isCompute && (viewChanged || wasCompute) )
 				{
 					if (wasCompute)
 					{
@@ -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;
@@ -8820,7 +8858,7 @@ VK_DESTROY
 						profiler.end();
 					}
 
-					if (beginRenderPass && bs.hasItem(view))
+					if (beginRenderPass && bs.hasItem(view) )
 					{
 						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;
+								mrtFormat[0]    = fb.m_swapChain.m_colorFormat;
+								depthAspectMask = fb.m_swapChain.m_backBufferDepthStencil.m_aspectFlags;
 							}
 
 							VkClearValue clearValues[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS + 1];
@@ -8922,7 +8961,7 @@ VK_DESTROY
 								{
 									VkClearColorValue& clearValue = clearValues[mrt].color;
 
-									const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(mrtFormat[ii]));
+									const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(mrtFormat[ii]) );
 									const bx::EncodingType::Enum type = bx::EncodingType::Enum(blockInfo.encoding);
 
 									if (BGFX_CLEAR_COLOR_USE_PALETTE & clr.m_flags)
@@ -8940,7 +8979,7 @@ VK_DESTROY
 											clearValue.int32[3] = int32_t(rgba[3]);
 											break;
 										default:
-											bx::memCopy(&clearValue.float32, rgba, sizeof(clearValue.float32));
+											bx::memCopy(&clearValue.float32, rgba, sizeof(clearValue.float32) );
 											break;
 										}
 									}
@@ -8965,7 +9004,7 @@ VK_DESTROY
 							}
 
 							depthAspectMask &= 0
-								| (clr.m_flags & BGFX_CLEAR_DEPTH ? VK_IMAGE_ASPECT_DEPTH_BIT : 0)
+								| (clr.m_flags & BGFX_CLEAR_DEPTH   ? VK_IMAGE_ASPECT_DEPTH_BIT   : 0)
 								| (clr.m_flags & BGFX_CLEAR_STENCIL ? VK_IMAGE_ASPECT_STENCIL_BIT : 0)
 								;
 
@@ -9430,7 +9469,7 @@ VK_DESTROY
 						m_occlusionQuery.begin(draw.m_occlusionQuery);
 					}
 
-					const uint8_t primIndex = uint8_t((draw.m_stateFlags & BGFX_STATE_PT_MASK) >> BGFX_STATE_PT_SHIFT);
+					const uint8_t primIndex = uint8_t( (draw.m_stateFlags & BGFX_STATE_PT_MASK) >> BGFX_STATE_PT_SHIFT);
 					const PrimInfo& prim = s_primInfo[primIndex];
 
 					uint32_t numPrimsSubmitted = 0;

+ 6 - 2
src/renderer_vk.h

@@ -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;