From cf13b9b5111a3be0bce132811d8281f89f5ae6ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Wed, 4 Dec 2024 12:52:27 +0100 Subject: [PATCH 1/2] Add WebXR support in misc section --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.js b/index.js index 9a4c46f..ea16675 100644 --- a/index.js +++ b/index.js @@ -479,6 +479,22 @@ async function checkMisc(parent, {haveFallback}) { if (!haveFallback) { obj['fallback adapter'] = 'not supported'; } + + let xrCompatibleAccessed = false; + const xrAdapterOptions = { + get xrCompatible() { + xrCompatibleAccessed = true; + return true; + } + }; + try { + const adapter = await navigator.gpu.requestAdapter(xrAdapterOptions); + obj['WebXR support'] = (adapter && xrCompatibleAccessed) ? 'supported' : 'not supported'; + } + catch(error) { + obj['WebXR support'] = 'unknown'; + } + try { const adapter = await navigator.gpu.requestAdapter(); const device = await adapter.requestDevice(); @@ -700,6 +716,7 @@ async function main() { { powerPreference: "low-power", }, { powerPreference: "low-power", forceFallbackAdapter: true, }, { compatibilityMode: true, featureLevel: "compatibility" }, + { xrCompatible: true }, ]; const adapterIds = new Map(); From 7707476f2883f203385142e5fe64b3486b937834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Beaufort?= Date: Thu, 12 Dec 2024 10:07:40 +0100 Subject: [PATCH 2/2] Address feedback --- index.js | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index ea16675..be9b169 100644 --- a/index.js +++ b/index.js @@ -472,6 +472,43 @@ function checkWGSLLanguageFeatures(parent) { ])); } +async function checkWebXRSupport() { + // If XRGPUBinding is not available, WebXR is not supported. + if (!('XRGPUBinding' in window)) { + return 'not supported'; + } + + try { + // Check if immersive VR or AR sessions are supported. + const [isImmersiveVrSupported, isImmersiveArSupported] = await Promise.all([ + navigator.xr?.isSessionSupported('immersive-vr'), + navigator.xr?.isSessionSupported('immersive-ar'), + ]); + + // If no immersive sessions are supported, WebXR is not supported. + if (!(isImmersiveVrSupported || isImmersiveArSupported)) { + return 'not supported'; + } + + let xrCompatibleAccessed = false; + const xrAdapterOptions = { + get xrCompatible() { + xrCompatibleAccessed = true; + return true; + } + }; + + // Otherwise, request an adapter with XR compatible options. + const adapter = await navigator.gpu.requestAdapter(xrAdapterOptions); + + // If an adapter is found and it's XR compatible, WebXR is supported. + return adapter && xrCompatibleAccessed ? 'likely supported' : 'not supported'; + } catch (error) { + // If an error occurs during adapter request, WebXR support is unknown. + return 'unknown'; + } +} + async function checkMisc(parent, {haveFallback}) { const obj = {}; const presentationFormat = navigator.gpu.getPreferredCanvasFormat(); @@ -480,20 +517,7 @@ async function checkMisc(parent, {haveFallback}) { obj['fallback adapter'] = 'not supported'; } - let xrCompatibleAccessed = false; - const xrAdapterOptions = { - get xrCompatible() { - xrCompatibleAccessed = true; - return true; - } - }; - try { - const adapter = await navigator.gpu.requestAdapter(xrAdapterOptions); - obj['WebXR support'] = (adapter && xrCompatibleAccessed) ? 'supported' : 'not supported'; - } - catch(error) { - obj['WebXR support'] = 'unknown'; - } + obj['WebXR support'] = await checkWebXRSupport(); try { const adapter = await navigator.gpu.requestAdapter();