Бранимир Караџић 5 år sedan
förälder
incheckning
f13e5adf4b
2 ändrade filer med 512 tillägg och 515 borttagningar
  1. 107 106
      src/renderer_webgpu.cpp
  2. 405 409
      src/renderer_webgpu.h

+ 107 - 106
src/renderer_webgpu.cpp

@@ -272,91 +272,91 @@ namespace bgfx { namespace webgpu
 
 	static TextureFormatInfo s_textureFormat[] =
 	{
-		{ wgpu::TextureFormat::BC1RGBAUnorm,            wgpu::TextureFormat::BC1RGBAUnormSrgb },  // BC1
-		{ wgpu::TextureFormat::BC2RGBAUnorm,            wgpu::TextureFormat::BC2RGBAUnormSrgb },  // BC2
-		{ wgpu::TextureFormat::BC3RGBAUnorm,            wgpu::TextureFormat::BC3RGBAUnormSrgb },  // BC3
-		{ wgpu::TextureFormat::BC4RUnorm,               wgpu::TextureFormat::Undefined                },  // BC4  //  BC4RSnorm ??
-		{ wgpu::TextureFormat::BC5RGUnorm,              wgpu::TextureFormat::Undefined                },  // BC5  //  BC5RGSnorm ??
-		{ wgpu::TextureFormat::BC6HRGBUfloat,           wgpu::TextureFormat::Undefined                },  // BC6H //  BC6HRGBSfloat ??
-		{ wgpu::TextureFormat::BC7RGBAUnorm,            wgpu::TextureFormat::BC7RGBAUnormSrgb },  // BC7
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ETC1
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ETC2
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ETC2A
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ETC2A1
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // PTC12
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // PTC14
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // PTC12A
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // PTC14A
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // PTC22
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // PTC24
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ATC
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ATCE
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ATCI
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ASTC4x4
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ASTC5x5
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ASTC6x6
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ASTC8x5
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ASTC8x6
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // ASTC10x5
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // Unknown
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // R1
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // A8
-		{ wgpu::TextureFormat::R8Unorm,                 wgpu::TextureFormat::Undefined                },  // R8
-		{ wgpu::TextureFormat::R8Sint,                  wgpu::TextureFormat::Undefined                },  // R8I
-		{ wgpu::TextureFormat::R8Uint,                  wgpu::TextureFormat::Undefined                },  // R8U
-		{ wgpu::TextureFormat::R8Snorm,                 wgpu::TextureFormat::Undefined                },  // R8S
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // R16
-		{ wgpu::TextureFormat::R16Sint,                 wgpu::TextureFormat::Undefined                },  // R16I
-		{ wgpu::TextureFormat::R16Uint,                 wgpu::TextureFormat::Undefined                },  // R16U
-		{ wgpu::TextureFormat::R16Float,                wgpu::TextureFormat::Undefined                },  // R16F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // R16S
-		{ wgpu::TextureFormat::R32Sint,                 wgpu::TextureFormat::Undefined                },  // R32I
-		{ wgpu::TextureFormat::R32Uint,                 wgpu::TextureFormat::Undefined                },  // R32U
-		{ wgpu::TextureFormat::R32Float,                wgpu::TextureFormat::Undefined                },  // R32F
-		{ wgpu::TextureFormat::RG8Unorm,                wgpu::TextureFormat::Undefined                },  // RG8
-		{ wgpu::TextureFormat::RG8Sint,                 wgpu::TextureFormat::Undefined                },  // RG8I
-		{ wgpu::TextureFormat::RG8Uint,                 wgpu::TextureFormat::Undefined                },  // RG8U
-		{ wgpu::TextureFormat::RG8Snorm,                wgpu::TextureFormat::Undefined                },  // RG8S
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RG16
-		{ wgpu::TextureFormat::RG16Sint,                wgpu::TextureFormat::Undefined                },  // RG16I
-		{ wgpu::TextureFormat::RG16Uint,                wgpu::TextureFormat::Undefined                },  // RG16U
-		{ wgpu::TextureFormat::RG16Float,               wgpu::TextureFormat::Undefined                },  // RG16F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RG16S
-		{ wgpu::TextureFormat::RG32Sint,                wgpu::TextureFormat::Undefined                },  // RG32I
-		{ wgpu::TextureFormat::RG32Uint,                wgpu::TextureFormat::Undefined                },  // RG32U
-		{ wgpu::TextureFormat::RG32Float,               wgpu::TextureFormat::Undefined                },  // RG32F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGB8
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGB8I
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGB8U
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGB8S
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGB9E5F
-		{ wgpu::TextureFormat::BGRA8Unorm,              wgpu::TextureFormat::BGRA8UnormSrgb   },  // BGRA8
-		{ wgpu::TextureFormat::RGBA8Unorm,              wgpu::TextureFormat::RGBA8UnormSrgb   },  // RGBA8
-		{ wgpu::TextureFormat::RGBA8Sint,               wgpu::TextureFormat::Undefined                },  // RGBA8I
-		{ wgpu::TextureFormat::RGBA8Uint,               wgpu::TextureFormat::Undefined                },  // RGBA8U
-		{ wgpu::TextureFormat::RGBA8Snorm,              wgpu::TextureFormat::Undefined                },  // RGBA8S
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGBA16
-		{ wgpu::TextureFormat::RGBA16Sint,              wgpu::TextureFormat::Undefined                },  // RGBA16I
-		{ wgpu::TextureFormat::RGBA16Uint,              wgpu::TextureFormat::Undefined                },  // RGBA16U
-		{ wgpu::TextureFormat::RGBA16Float,             wgpu::TextureFormat::Undefined                },  // RGBA16F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGBA16S
-		{ wgpu::TextureFormat::RGBA32Sint,              wgpu::TextureFormat::Undefined                },  // RGBA32I
-		{ wgpu::TextureFormat::RGBA32Uint,              wgpu::TextureFormat::Undefined                },  // RGBA32U
-		{ wgpu::TextureFormat::RGBA32Float,             wgpu::TextureFormat::Undefined                },  // RGBA32F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // R5G6B5
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGBA4
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // RGB5A1
-		{ wgpu::TextureFormat::RGB10A2Unorm,            wgpu::TextureFormat::Undefined                },  // RGB10A2
-		{ wgpu::TextureFormat::RG11B10Float,            wgpu::TextureFormat::Undefined                },  // RG11B10F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // UnknownDepth
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // D16
-		{ wgpu::TextureFormat::Depth24Plus,             wgpu::TextureFormat::Undefined                },  // D24
-		{ wgpu::TextureFormat::Depth24PlusStencil8,     wgpu::TextureFormat::Undefined                },  // D24S8
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // D32
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // D16F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // D24F
-		{ wgpu::TextureFormat::Depth32Float,            wgpu::TextureFormat::Undefined                },  // D32F
-		{ wgpu::TextureFormat::Undefined,                       wgpu::TextureFormat::Undefined                },  // D0S8
+		{ wgpu::TextureFormat::BC1RGBAUnorm,        wgpu::TextureFormat::BC1RGBAUnormSrgb },  // BC1
+		{ wgpu::TextureFormat::BC2RGBAUnorm,        wgpu::TextureFormat::BC2RGBAUnormSrgb },  // BC2
+		{ wgpu::TextureFormat::BC3RGBAUnorm,        wgpu::TextureFormat::BC3RGBAUnormSrgb },  // BC3
+		{ wgpu::TextureFormat::BC4RUnorm,           wgpu::TextureFormat::Undefined        },  // BC4  //  BC4RSnorm ??
+		{ wgpu::TextureFormat::BC5RGUnorm,          wgpu::TextureFormat::Undefined        },  // BC5  //  BC5RGSnorm ??
+		{ wgpu::TextureFormat::BC6HRGBUfloat,       wgpu::TextureFormat::Undefined        },  // BC6H //  BC6HRGBSfloat ??
+		{ wgpu::TextureFormat::BC7RGBAUnorm,        wgpu::TextureFormat::BC7RGBAUnormSrgb },  // BC7
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ETC1
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ETC2
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ETC2A
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ETC2A1
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // PTC12
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // PTC14
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // PTC12A
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // PTC14A
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // PTC22
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // PTC24
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ATC
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ATCE
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ATCI
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ASTC4x4
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ASTC5x5
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ASTC6x6
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ASTC8x5
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ASTC8x6
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // ASTC10x5
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // Unknown
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // R1
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // A8
+		{ wgpu::TextureFormat::R8Unorm,             wgpu::TextureFormat::Undefined        },  // R8
+		{ wgpu::TextureFormat::R8Sint,              wgpu::TextureFormat::Undefined        },  // R8I
+		{ wgpu::TextureFormat::R8Uint,              wgpu::TextureFormat::Undefined        },  // R8U
+		{ wgpu::TextureFormat::R8Snorm,             wgpu::TextureFormat::Undefined        },  // R8S
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // R16
+		{ wgpu::TextureFormat::R16Sint,             wgpu::TextureFormat::Undefined        },  // R16I
+		{ wgpu::TextureFormat::R16Uint,             wgpu::TextureFormat::Undefined        },  // R16U
+		{ wgpu::TextureFormat::R16Float,            wgpu::TextureFormat::Undefined        },  // R16F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // R16S
+		{ wgpu::TextureFormat::R32Sint,             wgpu::TextureFormat::Undefined        },  // R32I
+		{ wgpu::TextureFormat::R32Uint,             wgpu::TextureFormat::Undefined        },  // R32U
+		{ wgpu::TextureFormat::R32Float,            wgpu::TextureFormat::Undefined        },  // R32F
+		{ wgpu::TextureFormat::RG8Unorm,            wgpu::TextureFormat::Undefined        },  // RG8
+		{ wgpu::TextureFormat::RG8Sint,             wgpu::TextureFormat::Undefined        },  // RG8I
+		{ wgpu::TextureFormat::RG8Uint,             wgpu::TextureFormat::Undefined        },  // RG8U
+		{ wgpu::TextureFormat::RG8Snorm,            wgpu::TextureFormat::Undefined        },  // RG8S
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RG16
+		{ wgpu::TextureFormat::RG16Sint,            wgpu::TextureFormat::Undefined        },  // RG16I
+		{ wgpu::TextureFormat::RG16Uint,            wgpu::TextureFormat::Undefined        },  // RG16U
+		{ wgpu::TextureFormat::RG16Float,           wgpu::TextureFormat::Undefined        },  // RG16F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RG16S
+		{ wgpu::TextureFormat::RG32Sint,            wgpu::TextureFormat::Undefined        },  // RG32I
+		{ wgpu::TextureFormat::RG32Uint,            wgpu::TextureFormat::Undefined        },  // RG32U
+		{ wgpu::TextureFormat::RG32Float,           wgpu::TextureFormat::Undefined        },  // RG32F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGB8
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGB8I
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGB8U
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGB8S
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGB9E5F
+		{ wgpu::TextureFormat::BGRA8Unorm,          wgpu::TextureFormat::BGRA8UnormSrgb   },  // BGRA8
+		{ wgpu::TextureFormat::RGBA8Unorm,          wgpu::TextureFormat::RGBA8UnormSrgb   },  // RGBA8
+		{ wgpu::TextureFormat::RGBA8Sint,           wgpu::TextureFormat::Undefined        },  // RGBA8I
+		{ wgpu::TextureFormat::RGBA8Uint,           wgpu::TextureFormat::Undefined        },  // RGBA8U
+		{ wgpu::TextureFormat::RGBA8Snorm,          wgpu::TextureFormat::Undefined        },  // RGBA8S
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGBA16
+		{ wgpu::TextureFormat::RGBA16Sint,          wgpu::TextureFormat::Undefined        },  // RGBA16I
+		{ wgpu::TextureFormat::RGBA16Uint,          wgpu::TextureFormat::Undefined        },  // RGBA16U
+		{ wgpu::TextureFormat::RGBA16Float,         wgpu::TextureFormat::Undefined        },  // RGBA16F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGBA16S
+		{ wgpu::TextureFormat::RGBA32Sint,          wgpu::TextureFormat::Undefined        },  // RGBA32I
+		{ wgpu::TextureFormat::RGBA32Uint,          wgpu::TextureFormat::Undefined        },  // RGBA32U
+		{ wgpu::TextureFormat::RGBA32Float,         wgpu::TextureFormat::Undefined        },  // RGBA32F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // R5G6B5
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGBA4
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // RGB5A1
+		{ wgpu::TextureFormat::RGB10A2Unorm,        wgpu::TextureFormat::Undefined        },  // RGB10A2
+		{ wgpu::TextureFormat::RG11B10Float,        wgpu::TextureFormat::Undefined        },  // RG11B10F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // UnknownDepth
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // D16
+		{ wgpu::TextureFormat::Depth24Plus,         wgpu::TextureFormat::Undefined        },  // D24
+		{ wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureFormat::Undefined        },  // D24S8
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // D32
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // D16F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // D24F
+		{ wgpu::TextureFormat::Depth32Float,        wgpu::TextureFormat::Undefined        },  // D32F
+		{ wgpu::TextureFormat::Undefined,           wgpu::TextureFormat::Undefined        },  // D0S8
 	};
 	BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat));
 
@@ -377,15 +377,15 @@ namespace bgfx { namespace webgpu
 #if !BX_PLATFORM_EMSCRIPTEN
 	DawnSwapChainImplementation(*createSwapChain)(wgpu::Device device, void* nwh);
 
-#ifdef DAWN_ENABLE_BACKEND_D3D12
+#	if defined(DAWN_ENABLE_BACKEND_D3D12)
 	DawnSwapChainImplementation CreateSwapChainD3D12(wgpu::Device device, void* nwh)
 	{
 		HWND win32Window = (HWND)nwh;
 		return dawn_native::d3d12::CreateNativeSwapChainImpl(device.Get(), win32Window);
 	}
-#endif
+#	endif // defined(DAWN_ENABLE_BACKEND_D3D12)
 
-#ifdef DAWN_ENABLE_BACKEND_VULKAN
+#	if defined(DAWN_ENABLE_BACKEND_VULKAN)
 	DawnSwapChainImplementation CreateSwapChainVulkan(wgpu::Device device, void* nwh)
 	{
 		VkInstance instance = dawn_native::vulkan::GetInstance(device.Get());
@@ -393,7 +393,7 @@ namespace bgfx { namespace webgpu
 		PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)dawn_native::vulkan::GetInstanceProcAddr(device.Get(), "vkCreateWin32SurfaceKHR");
 
 		VkSurfaceKHR surface;
-#if BX_PLATFORM_WINDOWS
+#		if BX_PLATFORM_WINDOWS
 		// Copied from renderer_vk.cpp -> needs refactor
 		{
 			VkWin32SurfaceCreateInfoKHR sci;
@@ -404,12 +404,12 @@ namespace bgfx { namespace webgpu
 			sci.hwnd = (HWND)nwh;
 			VkResult result = vkCreateWin32SurfaceKHR(instance, &sci, NULL, &surface);
 		}
-#endif
+#		endif // BX_PLATFORM_WINDOWS
 		return dawn_native::vulkan::CreateNativeSwapChainImpl(device.Get(), surface);
 	}
-#endif
+#	endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
 
-#endif
+#endif // !BX_PLATFORM_EMSCRIPTEN
 
 	struct RendererContextWgpu : public RendererContextI
 	{
@@ -447,17 +447,17 @@ namespace bgfx { namespace webgpu
 #if !BX_PLATFORM_EMSCRIPTEN
 			// Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on
 			// their respective platforms, and Vulkan is preferred to OpenGL
-#if defined(DAWN_ENABLE_BACKEND_D3D12)
+#	if defined(DAWN_ENABLE_BACKEND_D3D12)
 			static dawn_native::BackendType backendType = dawn_native::BackendType::D3D12;
-#elif defined(DAWN_ENABLE_BACKEND_METAL)
+#	elif defined(DAWN_ENABLE_BACKEND_METAL)
 			static dawn_native::BackendType backendType = dawn_native::BackendType::Metal;
-#elif defined(DAWN_ENABLE_BACKEND_OPENGL)
+#	elif defined(DAWN_ENABLE_BACKEND_OPENGL)
 			static dawn_native::BackendType backendType = dawn_native::BackendType::OpenGL;
-#elif defined(DAWN_ENABLE_BACKEND_VULKAN)
+#	elif defined(DAWN_ENABLE_BACKEND_VULKAN)
 			static dawn_native::BackendType backendType = dawn_native::BackendType::Vulkan;
-#else
-#error
-#endif
+#	else
+#		error "Unknown platform."
+#	endif // defined(DAWN_ENABLE_BACKEND_*)
 
 			if (BX_ENABLED(BGFX_CONFIG_DEBUG))
 			{
@@ -484,17 +484,17 @@ namespace bgfx { namespace webgpu
 
 			using CreateSwapChain = DawnSwapChainImplementation (*)(wgpu::Device device, void* nwh);
 
-#if defined(DAWN_ENABLE_BACKEND_D3D12)
+#	if defined(DAWN_ENABLE_BACKEND_D3D12)
 			createSwapChain = CreateSwapChainD3D12;
-#elif defined(DAWN_ENABLE_BACKEND_METAL)
+#	elif defined(DAWN_ENABLE_BACKEND_METAL)
 			createSwapChain = CreateSwapChainMetal;
-#elif defined(DAWN_ENABLE_BACKEND_NULL)
+#	elif defined(DAWN_ENABLE_BACKEND_NULL)
 			createSwapChain = CreateSwapChainNull;
-#elif defined(DAWN_ENABLE_BACKEND_OPENGL)
+#	elif defined(DAWN_ENABLE_BACKEND_OPENGL)
 			createSwapChain = CreateSwapChainOpenGL;
-#elif defined(DAWN_ENABLE_BACKEND_VULKAN)
+#	elif defined(DAWN_ENABLE_BACKEND_VULKAN)
 			createSwapChain = CreateSwapChainVulkan;
-#endif
+#	endif // defined(DAWN_ENABLE_BACKEND_*)
 
 			// Choose whether to use the backend procs and devices directly, or set up the wire.
 			WGPUDevice cDevice = backendDevice;
@@ -504,7 +504,7 @@ namespace bgfx { namespace webgpu
 			m_device = wgpu::Device::Acquire(cDevice);
 #else
 			m_device = wgpu::Device(emscripten_webgpu_get_device());
-#endif
+#endif // !BX_PLATFORM_EMSCRIPTEN
 
 			auto PrintDeviceError = [](WGPUErrorType errorType, const char* message, void*) {
 				BX_UNUSED(errorType);
@@ -517,6 +517,7 @@ namespace bgfx { namespace webgpu
 				{
 					BX_CHECK(false, "Device error: %s", message);
 				}
+
 				s_ignoreError = false;
 			};
 

+ 405 - 409
src/renderer_webgpu.h

@@ -35,536 +35,532 @@
 #define WEBGPU_MAX_FRAMES_IN_FLIGHT 3
 #define WEBGPU_NUM_UNIFORM_BUFFERS  8
 
-namespace bgfx
+namespace bgfx { namespace webgpu
 {
-	namespace webgpu
+	template <typename Ty>
+	class StateCacheT
 	{
-		template <typename Ty>
-		class StateCacheT
+	public:
+		void add(uint64_t _id, Ty _item)
 		{
-		public:
-			void add(uint64_t _id, Ty _item)
+			invalidate(_id);
+			m_hashMap.insert(stl::make_pair(_id, _item));
+		}
+
+		Ty find(uint64_t _id)
+		{
+			typename HashMap::iterator it = m_hashMap.find(_id);
+			if(it != m_hashMap.end())
 			{
-				invalidate(_id);
-				m_hashMap.insert(stl::make_pair(_id, _item));
+				return it->second;
 			}
 
-			Ty find(uint64_t _id)
-			{
-				typename HashMap::iterator it = m_hashMap.find(_id);
-				if(it != m_hashMap.end())
-				{
-					return it->second;
-				}
+			return NULL;
+		}
 
-				return NULL;
+		void invalidate(uint64_t _id)
+		{
+			typename HashMap::iterator it = m_hashMap.find(_id);
+			if(it != m_hashMap.end())
+			{
+				release(it->second);
+				m_hashMap.erase(it);
 			}
+		}
 
-			void invalidate(uint64_t _id)
+		void invalidate()
+		{
+			for(typename HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
 			{
-				typename HashMap::iterator it = m_hashMap.find(_id);
-				if(it != m_hashMap.end())
-				{
-					release(it->second);
-					m_hashMap.erase(it);
-				}
+				release(it->second);
 			}
 
-			void invalidate()
-			{
-				for(typename HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it)
-				{
-					release(it->second);
-				}
+			m_hashMap.clear();
+		}
 
-				m_hashMap.clear();
-			}
+		uint32_t getCount() const
+		{
+			return uint32_t(m_hashMap.size());
+		}
 
-			uint32_t getCount() const
-			{
-				return uint32_t(m_hashMap.size());
-			}
+	private:
+		typedef stl::unordered_map<uint64_t, Ty> HashMap;
+		HashMap m_hashMap;
+	};
 
-		private:
-			typedef stl::unordered_map<uint64_t, Ty> HashMap;
-			HashMap m_hashMap;
-		};
+	struct BufferWgpu
+	{
+		void create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride = 0, bool _vertex = false);
+		void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false);
 
-		struct BufferWgpu
+		void destroy()
 		{
-			void create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride = 0, bool _vertex = false);
-			void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false);
+			m_ptr.Destroy();
 
-			void destroy()
+			if(NULL != m_dynamic)
 			{
-				m_ptr.Destroy();
-
-				if(NULL != m_dynamic)
-				{
-					BX_DELETE(g_allocator, m_dynamic);
-					m_dynamic = NULL;
-				}
+				BX_DELETE(g_allocator, m_dynamic);
+				m_dynamic = NULL;
 			}
+		}
 
-			uint32_t m_size;
-			uint16_t m_flags = BGFX_BUFFER_NONE;
-			bool     m_vertex;
+		uint32_t m_size;
+		uint16_t m_flags = BGFX_BUFFER_NONE;
+		bool     m_vertex;
 
-			String       m_label;
-			wgpu::Buffer m_ptr;
-			uint8_t*     m_dynamic = NULL;
-		};
+		String       m_label;
+		wgpu::Buffer m_ptr;
+		uint8_t*     m_dynamic = NULL;
+	};
 
-		typedef BufferWgpu IndexBufferWgpu;
+	typedef BufferWgpu IndexBufferWgpu;
 
-		struct VertexBufferWgpu : public BufferWgpu
-		{
-			void create(uint32_t _size, void* _data, VertexLayoutHandle _declHandle, uint16_t _flags);
+	struct VertexBufferWgpu : public BufferWgpu
+	{
+		void create(uint32_t _size, void* _data, VertexLayoutHandle _declHandle, uint16_t _flags);
 
-			VertexLayoutHandle m_layoutHandle;
-		};
+		VertexLayoutHandle m_layoutHandle;
+	};
 
-		struct BindInfo
-		{
-			uint32_t      m_index = UINT32_MAX;
-			uint32_t      m_binding = UINT32_MAX;
-			UniformHandle m_uniform = BGFX_INVALID_HANDLE;
-		};
+	struct BindInfo
+	{
+		uint32_t      m_index = UINT32_MAX;
+		uint32_t      m_binding = UINT32_MAX;
+		UniformHandle m_uniform = BGFX_INVALID_HANDLE;
+	};
 
-		struct ShaderWgpu
+	struct ShaderWgpu
+	{
+		void create(ShaderHandle _handle, const Memory* _mem);
+		void destroy()
 		{
-			void create(ShaderHandle _handle, const Memory* _mem);
-			void destroy()
+			if (NULL != m_constantBuffer)
 			{
-				if (NULL != m_constantBuffer)
-				{
-					UniformBuffer::destroy(m_constantBuffer);
-					m_constantBuffer = NULL;
-				}
-
-				m_module = NULL;
+				UniformBuffer::destroy(m_constantBuffer);
+				m_constantBuffer = NULL;
 			}
 
-			const char* name() const { return getName(m_handle); }
-
-			ShaderHandle m_handle;
-			String m_label;
-
-			wgpu::ShaderStage m_stage;
-			wgpu::ShaderModule m_module;
+			m_module = NULL;
+		}
 
-			uint32_t* m_code = NULL;
-			size_t m_codeSize = 0;
+		const char* name() const { return getName(m_handle); }
 
-			UniformBuffer* m_constantBuffer = NULL;
+		ShaderHandle m_handle;
+		String m_label;
 
-			PredefinedUniform m_predefined[PredefinedUniform::Count];
-			uint16_t m_attrMask[Attrib::Count];
-			uint8_t m_attrRemap[Attrib::Count];
+		wgpu::ShaderStage m_stage;
+		wgpu::ShaderModule m_module;
 
-			uint32_t m_hash = 0;
-			uint16_t m_numUniforms = 0;
-			uint16_t m_size = 0;
-			uint16_t m_gpuSize = 0;
-			uint8_t m_numPredefined = 0;
-			uint8_t m_numAttrs = 0;
+		uint32_t* m_code = NULL;
+		size_t m_codeSize = 0;
 
-			BindInfo					m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			wgpu::BindGroupLayoutEntry	m_samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			wgpu::BindGroupLayoutEntry	m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			uint8_t						m_numSamplers = 0;
-			wgpu::BindGroupLayoutEntry	m_buffers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			uint32_t					m_numBuffers = 0;
-		};
+		UniformBuffer* m_constantBuffer = NULL;
 
-		struct PipelineStateWgpu;
+		PredefinedUniform m_predefined[PredefinedUniform::Count];
+		uint16_t m_attrMask[Attrib::Count];
+		uint8_t  m_attrRemap[Attrib::Count];
 
-		struct ProgramWgpu
-		{
-			void create(const ShaderWgpu* _vsh, const ShaderWgpu* _fsh);
-			void destroy();
+		uint32_t m_hash = 0;
+		uint16_t m_numUniforms = 0;
+		uint16_t m_size = 0;
+		uint16_t m_gpuSize = 0;
+		uint8_t  m_numPredefined = 0;
+		uint8_t  m_numAttrs = 0;
 
-			const ShaderWgpu* m_vsh = NULL;
-			const ShaderWgpu* m_fsh = NULL;
+		BindInfo                   m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		wgpu::BindGroupLayoutEntry m_samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		wgpu::BindGroupLayoutEntry m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		uint8_t                    m_numSamplers = 0;
+		wgpu::BindGroupLayoutEntry m_buffers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		uint32_t                   m_numBuffers = 0;
+	};
 
-			PredefinedUniform m_predefined[PredefinedUniform::Count * 2];
-			uint8_t m_numPredefined;
+	struct PipelineStateWgpu;
 
-			PipelineStateWgpu* m_computePS = NULL;
+	struct ProgramWgpu
+	{
+		void create(const ShaderWgpu* _vsh, const ShaderWgpu* _fsh);
+		void destroy();
 
-			wgpu::BindGroupLayout m_bindGroupLayout;
-			uint16_t              m_gpuSize = 0;
-			uint32_t              m_numUniforms;
-			uint32_t              m_bindGroupLayoutHash;
+		const ShaderWgpu* m_vsh = NULL;
+		const ShaderWgpu* m_fsh = NULL;
 
-			BindInfo                   m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			wgpu::BindGroupLayoutEntry m_samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			wgpu::BindGroupLayoutEntry m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			uint32_t                   m_numSamplers = 0;
-			wgpu::BindGroupLayoutEntry m_buffers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
-			uint32_t                   m_numBuffers = 0;
-		};
+		PredefinedUniform m_predefined[PredefinedUniform::Count * 2];
+		uint8_t m_numPredefined;
 
-		constexpr size_t kMaxVertexInputs = 16;
-		constexpr size_t kMaxVertexAttributes = 16;
-		constexpr size_t kMaxColorAttachments = BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS;
+		PipelineStateWgpu* m_computePS = NULL;
 
-		constexpr uint32_t kMinBufferOffsetAlignment = 256;
+		wgpu::BindGroupLayout m_bindGroupLayout;
+		uint16_t              m_gpuSize = 0;
+		uint32_t              m_numUniforms;
+		uint32_t              m_bindGroupLayoutHash;
 
-		struct RenderPassDescriptor
-		{
-			RenderPassDescriptor();
+		BindInfo                   m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		wgpu::BindGroupLayoutEntry m_samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		wgpu::BindGroupLayoutEntry m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		uint32_t                   m_numSamplers = 0;
+		wgpu::BindGroupLayoutEntry m_buffers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS];
+		uint32_t                   m_numBuffers = 0;
+	};
 
-			wgpu::RenderPassDescriptor desc;
+	constexpr size_t kMaxVertexInputs = 16;
+	constexpr size_t kMaxVertexAttributes = 16;
+	constexpr size_t kMaxColorAttachments = BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS;
 
-			wgpu::RenderPassColorAttachmentDescriptor colorAttachments[kMaxColorAttachments];
-			wgpu::RenderPassDepthStencilAttachmentDescriptor depthStencilAttachment;
-		};
+	constexpr uint32_t kMinBufferOffsetAlignment = 256;
 
-		struct VertexStateDescriptor
-		{
-			VertexStateDescriptor();
+	struct RenderPassDescriptor
+	{
+		RenderPassDescriptor();
 
-			wgpu::VertexStateDescriptor desc;
+		wgpu::RenderPassDescriptor desc;
 
-			wgpu::VertexBufferLayoutDescriptor vertexBuffers[kMaxVertexInputs];
-			wgpu::VertexAttributeDescriptor attributes[kMaxVertexAttributes];
-		};
+		wgpu::RenderPassColorAttachmentDescriptor colorAttachments[kMaxColorAttachments];
+		wgpu::RenderPassDepthStencilAttachmentDescriptor depthStencilAttachment;
+	};
 
-		struct RenderPipelineDescriptor
-		{
-			RenderPipelineDescriptor();
+	struct VertexStateDescriptor
+	{
+		VertexStateDescriptor();
 
-			wgpu::RenderPipelineDescriptor desc;
+		wgpu::VertexStateDescriptor desc;
 
-			//wgpu::ProgrammableStageDescriptor vertexStage;
-			wgpu::ProgrammableStageDescriptor fragmentStage;
+		wgpu::VertexBufferLayoutDescriptor vertexBuffers[kMaxVertexInputs];
+		wgpu::VertexAttributeDescriptor attributes[kMaxVertexAttributes];
+	};
 
-			wgpu::VertexStateDescriptor inputState;
+	struct RenderPipelineDescriptor
+	{
+		RenderPipelineDescriptor();
 
-			wgpu::RasterizationStateDescriptor rasterizationState;
-			wgpu::DepthStencilStateDescriptor depthStencilState;
-			wgpu::ColorStateDescriptor colorStates[kMaxColorAttachments];
-		};
+		wgpu::RenderPipelineDescriptor desc;
 
-		struct BindingsWgpu
-		{
-			uint32_t numEntries = 0;
-			wgpu::BindGroupEntry m_entries[2 + BGFX_CONFIG_MAX_TEXTURE_SAMPLERS*3];
-		};
+		//wgpu::ProgrammableStageDescriptor vertexStage;
+		wgpu::ProgrammableStageDescriptor fragmentStage;
 
-		struct BindStateWgpu
-		{
-			void clear();
+		wgpu::VertexStateDescriptor inputState;
 
-			uint32_t numOffset;
+		wgpu::RasterizationStateDescriptor rasterizationState;
+		wgpu::DepthStencilStateDescriptor depthStencilState;
+		wgpu::ColorStateDescriptor colorStates[kMaxColorAttachments];
+	};
 
-			wgpu::BindGroup m_bindGroup;
-		};
+	struct BindingsWgpu
+	{
+		uint32_t numEntries = 0;
+		wgpu::BindGroupEntry m_entries[2 + BGFX_CONFIG_MAX_TEXTURE_SAMPLERS*3];
+	};
 
-		struct RenderPassStateWgpu
-		{
-			RenderPassDescriptor m_rpd;
-		};
+	struct BindStateWgpu
+	{
+		void clear();
 
-		struct PipelineStateWgpu
-		{
-			RenderPipelineDescriptor m_rpd;
+		uint32_t numOffset;
 
-			wgpu::PipelineLayout m_layout;
+		wgpu::BindGroup m_bindGroup;
+	};
 
-			wgpu::RenderPipeline m_rps;
-			wgpu::ComputePipeline m_cps;
-		};
+	struct RenderPassStateWgpu
+	{
+		RenderPassDescriptor m_rpd;
+	};
 
-		void release(RenderPassStateWgpu* _ptr)
-		{
-			BX_DELETE(g_allocator, _ptr);
-		}
+	struct PipelineStateWgpu
+	{
+		RenderPipelineDescriptor m_rpd;
 
-		void release(PipelineStateWgpu* _ptr)
-		{
-			BX_DELETE(g_allocator, _ptr);
-		}
+		wgpu::PipelineLayout m_layout;
 
-		class StagingBufferWgpu
-		{
-		public:
-			void create(uint32_t _size, bool mapped);
-			void map();
-			void unmap();
-			void destroy();
+		wgpu::RenderPipeline m_rps;
+		wgpu::ComputePipeline m_cps;
+	};
 
-			void mapped(void* _data, uint64_t _size);
+	void release(RenderPassStateWgpu* _ptr)
+	{
+		BX_DELETE(g_allocator, _ptr);
+	}
 
-			wgpu::Buffer m_buffer;
-			void* m_data = NULL;
-			uint64_t m_size = 0;
-		};
+	void release(PipelineStateWgpu* _ptr)
+	{
+		BX_DELETE(g_allocator, _ptr);
+	}
 
-		class ScratchBufferWgpu
-		{
-		public:
-			void create(uint32_t _size); // , uint32_t _maxBindGroups);
-			void destroy();
-			void begin();
-			uint32_t write(void* data, uint64_t _size, uint64_t _offset);
-			uint32_t write(void* data, uint64_t _size);
-			void submit();
-			void release();
-
-			StagingBufferWgpu* m_staging = NULL;
-			wgpu::Buffer m_buffer;
-			uint32_t m_offset;
-			uint32_t m_size;
-			uint8_t m_stagingIndex = 0;
-		};
+	class StagingBufferWgpu
+	{
+	public:
+		void create(uint32_t _size, bool mapped);
+		void map();
+		void unmap();
+		void destroy();
 
-		class BindStateCacheWgpu
-		{
-		public:
-			void create(); // , uint32_t _maxBindGroups);
-			void destroy();
-			void reset();
-
-			BindStateWgpu m_bindStates[1024] = {};
-			uint32_t m_currentBindState;
-			//uint32_t m_maxBindStates;
-		};
+		void mapped(void* _data, uint64_t _size);
 
-		struct ReadbackWgpu
-		{
-			void create(TextureHandle _texture) { m_texture = _texture; }
+		wgpu::Buffer m_buffer;
+		void* m_data = NULL;
+		uint64_t m_size = 0;
+	};
 
-			void destroy()
-			{
-				m_buffer.Destroy();
-			}
+	class ScratchBufferWgpu
+	{
+	public:
+		void create(uint32_t _size); // , uint32_t _maxBindGroups);
+		void destroy();
+		void begin();
+		uint32_t write(void* data, uint64_t _size, uint64_t _offset);
+		uint32_t write(void* data, uint64_t _size);
+		void submit();
+		void release();
+
+		StagingBufferWgpu* m_staging = NULL;
+		wgpu::Buffer m_buffer;
+		uint32_t m_offset;
+		uint32_t m_size;
+		uint8_t m_stagingIndex = 0;
+	};
+
+	class BindStateCacheWgpu
+	{
+	public:
+		void create(); // , uint32_t _maxBindGroups);
+		void destroy();
+		void reset();
 
-			void readback(void const* data, uint64_t size)
-			{
-				bx::memCopy(m_data, data, m_size < size ? m_size : size);
-				m_buffer.Unmap();
-				m_mapped = false;
-			}
+		BindStateWgpu m_bindStates[1024] = {};
+		uint32_t m_currentBindState;
+		//uint32_t m_maxBindStates;
+	};
 
-			TextureHandle m_texture;
-			wgpu::Buffer m_buffer;
-			uint32_t m_mip = 0;
-			bool m_mapped = false;
-			void* m_data = NULL;
-			size_t m_size = 0;
-		};
+	struct ReadbackWgpu
+	{
+		void create(TextureHandle _texture) { m_texture = _texture; }
 
-		struct TextureWgpu
+		void destroy()
 		{
-			enum Enum
-			{
-				Texture2D,
-				Texture3D,
-				TextureCube,
-			};
-
-			void create(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip);
-
-			void destroy()
-			{
-				m_ptr.Destroy();
-			}
+			m_buffer.Destroy();
+		}
 
-			void update(
-				uint8_t _side
-				, uint8_t _mip
-				, const Rect& _rect
-				, uint16_t _z
-				, uint16_t _depth
-				, uint16_t _pitch
-				, const Memory* _mem
-			);
+		void readback(void const* data, uint64_t size)
+		{
+			bx::memCopy(m_data, data, m_size < size ? m_size : size);
+			m_buffer.Unmap();
+			m_mapped = false;
+		}
 
-			TextureHandle m_handle;
-			String m_label;
-
-			wgpu::TextureView m_view;
-			wgpu::TextureView getTextureMipLevel(int _mip);
-
-			wgpu::Texture m_ptr;
-			wgpu::Texture m_ptrMsaa;
-			wgpu::TextureView m_ptrMips[14] = {};
-			wgpu::Sampler m_sampler;
-			uint64_t m_flags = 0;
-			uint32_t m_width = 0;
-			uint32_t m_height = 0;
-			uint32_t m_depth = 0;
-			uint8_t m_type;
-			TextureFormat::Enum m_requestedFormat;
-			TextureFormat::Enum m_textureFormat;
-			uint8_t m_numMips = 0;
-			uint8_t m_numLayers;
-			uint32_t m_numSides;
-			uint8_t m_sampleCount;
-
-			ReadbackWgpu m_readback;
-		};
+		TextureHandle m_texture;
+		wgpu::Buffer m_buffer;
+		uint32_t m_mip = 0;
+		bool m_mapped = false;
+		void* m_data = NULL;
+		size_t m_size = 0;
+	};
 
-		struct SamplerStateWgpu
+	struct TextureWgpu
+	{
+		enum Enum
 		{
-			wgpu::Sampler m_sampler;
+			Texture2D,
+			Texture3D,
+			TextureCube,
 		};
 
-		void release(SamplerStateWgpu* _ptr)
+		void create(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip);
+
+		void destroy()
 		{
-			BX_DELETE(g_allocator, _ptr);
+			m_ptr.Destroy();
 		}
 
-		struct FrameBufferWgpu;
+		void update(
+			uint8_t _side
+			, uint8_t _mip
+			, const Rect& _rect
+			, uint16_t _z
+			, uint16_t _depth
+			, uint16_t _pitch
+			, const Memory* _mem
+		);
+
+		TextureHandle m_handle;
+		String m_label;
+
+		wgpu::TextureView m_view;
+		wgpu::TextureView getTextureMipLevel(int _mip);
+
+		wgpu::Texture m_ptr;
+		wgpu::Texture m_ptrMsaa;
+		wgpu::TextureView m_ptrMips[14] = {};
+		wgpu::Sampler m_sampler;
+		uint64_t m_flags = 0;
+		uint32_t m_width = 0;
+		uint32_t m_height = 0;
+		uint32_t m_depth = 0;
+		uint8_t m_type;
+		TextureFormat::Enum m_requestedFormat;
+		TextureFormat::Enum m_textureFormat;
+		uint8_t m_numMips = 0;
+		uint8_t m_numLayers;
+		uint32_t m_numSides;
+		uint8_t m_sampleCount;
+
+		ReadbackWgpu m_readback;
+	};
+
+	struct SamplerStateWgpu
+	{
+		wgpu::Sampler m_sampler;
+	};
 
-		struct SwapChainWgpu
-		{
-			void init(wgpu::Device _device, void* _nwh, uint32_t _width, uint32_t _height);
-			void resize(FrameBufferWgpu& _frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags);
+	void release(SamplerStateWgpu* _ptr)
+	{
+		BX_DELETE(g_allocator, _ptr);
+	}
+
+	struct FrameBufferWgpu;
+
+	struct SwapChainWgpu
+	{
+		void init(wgpu::Device _device, void* _nwh, uint32_t _width, uint32_t _height);
+		void resize(FrameBufferWgpu& _frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags);
 
-			void flip();
+		void flip();
 
-			wgpu::TextureView current();
+		wgpu::TextureView current();
 
 #if !BX_PLATFORM_EMSCRIPTEN
-			DawnSwapChainImplementation m_impl;
+		DawnSwapChainImplementation m_impl;
 #endif
 
-			wgpu::SwapChain m_swapChain;
+		wgpu::SwapChain m_swapChain;
 
-			wgpu::TextureView m_drawable;
+		wgpu::TextureView m_drawable;
 
-			wgpu::Texture m_backBufferColorMsaa;
-			wgpu::Texture m_backBufferDepth;
+		wgpu::Texture m_backBufferColorMsaa;
+		wgpu::Texture m_backBufferDepth;
 
-			wgpu::TextureFormat m_colorFormat;
-			wgpu::TextureFormat m_depthFormat;
+		wgpu::TextureFormat m_colorFormat;
+		wgpu::TextureFormat m_depthFormat;
 
-			uint32_t m_maxAnisotropy = 0;
-			uint8_t m_sampleCount;
-		};
+		uint32_t m_maxAnisotropy = 0;
+		uint8_t m_sampleCount;
+	};
 
-		struct FrameBufferWgpu
-		{
-			void create(uint8_t _num, const Attachment* _attachment);
-			bool create(
-				  uint16_t _denseIdx
-				, void* _nwh
-				, uint32_t _width
-				, uint32_t _height
-				, TextureFormat::Enum _format
-				, TextureFormat::Enum _depthFormat
-				);
-			void postReset();
-			uint16_t destroy();
-
-			SwapChainWgpu* m_swapChain = NULL;
-			void* m_nwh = NULL;
-			uint32_t m_width;
-			uint32_t m_height;
-			uint16_t m_denseIdx = UINT16_MAX;
-
-			uint32_t m_pixelFormatHash = 0;
-
-			TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS - 1];
-			TextureHandle m_depthHandle = { kInvalidHandle };
-			Attachment m_colorAttachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS - 1];
-			Attachment m_depthAttachment;
-			uint8_t m_num = 0; // number of color handles
-		};
+	struct FrameBufferWgpu
+	{
+		void create(uint8_t _num, const Attachment* _attachment);
+		bool create(
+				uint16_t _denseIdx
+			, void* _nwh
+			, uint32_t _width
+			, uint32_t _height
+			, TextureFormat::Enum _format
+			, TextureFormat::Enum _depthFormat
+			);
+		void postReset();
+		uint16_t destroy();
 
-		struct CommandQueueWgpu
-		{
-			void init(wgpu::Queue _queue);
-			void shutdown();
-			void beginRender();
-			void beginStaging();
-			void kick(bool _endFrame, bool _waitForFinish = false);
-			void finish(bool _finishAll = false);
-			void release(wgpu::Buffer _buffer);
-			void consume();
+		SwapChainWgpu* m_swapChain = NULL;
+		void* m_nwh = NULL;
+		uint32_t m_width;
+		uint32_t m_height;
+		uint16_t m_denseIdx = UINT16_MAX;
+
+		uint32_t m_pixelFormatHash = 0;
+
+		TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS - 1];
+		TextureHandle m_depthHandle = { kInvalidHandle };
+		Attachment m_colorAttachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS - 1];
+		Attachment m_depthAttachment;
+		uint8_t m_num = 0; // number of color handles
+	};
+
+	struct CommandQueueWgpu
+	{
+		void init(wgpu::Queue _queue);
+		void shutdown();
+		void beginRender();
+		void beginStaging();
+		void kick(bool _endFrame, bool _waitForFinish = false);
+		void finish(bool _finishAll = false);
+		void release(wgpu::Buffer _buffer);
+		void consume();
 
 #if BGFX_CONFIG_MULTITHREADED
-			//bx::Semaphore 		 m_framesSemaphore;
+		//bx::Semaphore 		 m_framesSemaphore;
 #endif
 
-			wgpu::Queue		     m_queue;
-			wgpu::CommandEncoder m_stagingEncoder;
-			wgpu::CommandEncoder m_renderEncoder;
+		wgpu::Queue		     m_queue;
+		wgpu::CommandEncoder m_stagingEncoder;
+		wgpu::CommandEncoder m_renderEncoder;
 
-			int m_releaseWriteIndex = 0;
-			int m_releaseReadIndex = 0;
+		int m_releaseWriteIndex = 0;
+		int m_releaseReadIndex = 0;
 
-			typedef stl::vector<wgpu::Buffer> ResourceArray;
-			ResourceArray m_release[WEBGPU_MAX_FRAMES_IN_FLIGHT];
-		};
+		typedef stl::vector<wgpu::Buffer> ResourceArray;
+		ResourceArray m_release[WEBGPU_MAX_FRAMES_IN_FLIGHT];
+	};
 
-		struct TimerQueryWgpu
+	struct TimerQueryWgpu
+	{
+		TimerQueryWgpu()
+			: m_control(4)
 		{
-			TimerQueryWgpu()
-				: m_control(4)
-			{
-			}
+		}
 
-			void init();
-			void shutdown();
-			uint32_t begin(uint32_t _resultIdx);
-			void end(uint32_t _idx);
-			void addHandlers(wgpu::CommandBuffer& _commandBuffer);
-			bool get();
+		void init();
+		void shutdown();
+		uint32_t begin(uint32_t _resultIdx);
+		void end(uint32_t _idx);
+		void addHandlers(wgpu::CommandBuffer& _commandBuffer);
+		bool get();
 
-			struct Result
+		struct Result
+		{
+			void reset()
 			{
-				void reset()
-				{
-					m_begin = 0;
-					m_end = 0;
-					m_pending = 0;
-				}
-
-				uint64_t m_begin;
-				uint64_t m_end;
-				uint32_t m_pending;
-			};
+				m_begin = 0;
+				m_end = 0;
+				m_pending = 0;
+			}
 
 			uint64_t m_begin;
 			uint64_t m_end;
-			uint64_t m_elapsed;
-			uint64_t m_frequency;
-
-			Result m_result[4 * 2];
-			bx::RingBufferControl m_control;
+			uint32_t m_pending;
 		};
 
-		struct OcclusionQueryWgpu
-		{
-			OcclusionQueryWgpu()
-				: m_control(BX_COUNTOF(m_query))
-			{
-			}
+		uint64_t m_begin;
+		uint64_t m_end;
+		uint64_t m_elapsed;
+		uint64_t m_frequency;
 
-			void postReset();
-			void preReset();
-			void begin(wgpu::RenderPassEncoder& _rce, Frame* _render, OcclusionQueryHandle _handle);
-			void end(wgpu::RenderPassEncoder& _rce);
-			void resolve(Frame* _render, bool _wait = false);
-			void invalidate(OcclusionQueryHandle _handle);
+		Result m_result[4 * 2];
+		bx::RingBufferControl m_control;
+	};
 
-			struct Query
-			{
-				OcclusionQueryHandle m_handle;
-			};
+	struct OcclusionQueryWgpu
+	{
+		OcclusionQueryWgpu()
+			: m_control(BX_COUNTOF(m_query))
+		{
+		}
+
+		void postReset();
+		void preReset();
+		void begin(wgpu::RenderPassEncoder& _rce, Frame* _render, OcclusionQueryHandle _handle);
+		void end(wgpu::RenderPassEncoder& _rce);
+		void resolve(Frame* _render, bool _wait = false);
+		void invalidate(OcclusionQueryHandle _handle);
 
-			wgpu::Buffer m_buffer;
-			Query m_query[BGFX_CONFIG_MAX_OCCLUSION_QUERIES];
-			bx::RingBufferControl m_control;
+		struct Query
+		{
+			OcclusionQueryHandle m_handle;
 		};
 
-	} // namespace webgpu
+		wgpu::Buffer m_buffer;
+		Query m_query[BGFX_CONFIG_MAX_OCCLUSION_QUERIES];
+		bx::RingBufferControl m_control;
+	};
 
-} // namespace bgfx
+} /* namespace webgpu */ } // namespace bgfx
 
 #endif // BGFX_CONFIG_RENDERER_WEBGPU