Skip to content

Commit 71934b3

Browse files
committed
Add xr compatible instance ext
1 parent 3adba8f commit 71934b3

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

gfx/include/gfx/gfx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,7 @@ typedef struct GfxChainHeader {
992992
// Instance extensions
993993
#define GFX_INSTANCE_EXTENSION_SURFACE "gfx_surface"
994994
#define GFX_INSTANCE_EXTENSION_DEBUG "gfx_debug"
995+
#define GFX_INSTANCE_EXTENSION_XR_COMPATIBLE "gfx_xr_compatible"
995996

996997
// Device extensions
997998
#define GFX_DEVICE_EXTENSION_SWAPCHAIN "gfx_swapchain"

gfx/src/backend/webgpu/core/CoreTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class TextureView;
2323
namespace extensions {
2424
constexpr const char* SURFACE = "gfx_surface";
2525
constexpr const char* DEBUG = "gfx_debug";
26+
constexpr const char* XR_COMPATIBLE = "gfx_xr_compatible";
2627
constexpr const char* SWAPCHAIN = "gfx_swapchain";
2728
constexpr const char* TIMELINE_SEMAPHORE = "gfx_timeline_semaphore";
2829
constexpr const char* ANISOTROPIC_FILTERING = "gfx_anisotropic_filtering";

gfx/src/backend/webgpu/core/system/Instance.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace gfx::backend::webgpu::core {
1111

1212
namespace {
13-
std::vector<WGPUAdapter> discoverAdapters(WGPUInstance instance)
13+
std::vector<WGPUAdapter> discoverAdapters(WGPUInstance instance, bool xrCompatible)
1414
{
1515
std::vector<WGPUAdapter> adapters;
1616

@@ -27,6 +27,15 @@ namespace {
2727
WGPURequestAdapterOptions options = WGPU_REQUEST_ADAPTER_OPTIONS_INIT;
2828
options.powerPreference = preference;
2929
options.forceFallbackAdapter = forceFallback;
30+
#if defined(__EMSCRIPTEN__)
31+
WGPURequestAdapterWebXROptions xrOptions = WGPU_REQUEST_ADAPTER_WEBXR_OPTIONS_INIT;
32+
if (xrCompatible) {
33+
xrOptions.xrCompatible = WGPU_TRUE;
34+
options.nextInChain = &xrOptions.chain;
35+
}
36+
#else
37+
(void)xrCompatible; // Not applicable for native Dawn
38+
#endif
3039

3140
WGPUAdapter adapter = nullptr;
3241
bool completed = false;
@@ -71,8 +80,6 @@ namespace {
7180

7281
Instance::Instance(const InstanceCreateInfo& createInfo)
7382
{
74-
(void)createInfo; // Descriptor not used in current implementation
75-
7683
// Request TimedWaitAny feature for proper async callback handling
7784
// For native Dawn, also request ShaderSourceSPIRV for SPIR-V shader support
7885
static const WGPUInstanceFeatureName requiredFeatures[] = {
@@ -106,7 +113,10 @@ Instance::Instance(const InstanceCreateInfo& createInfo)
106113
throw std::runtime_error("Failed to create WebGPU instance");
107114
}
108115

109-
std::vector<WGPUAdapter> discoveredAdapters = discoverAdapters(m_instance);
116+
const bool xrCompatible = std::find(createInfo.enabledExtensions.begin(), createInfo.enabledExtensions.end(),
117+
std::string(extensions::XR_COMPATIBLE))
118+
!= createInfo.enabledExtensions.end();
119+
std::vector<WGPUAdapter> discoveredAdapters = discoverAdapters(m_instance, xrCompatible);
110120
m_adapters.reserve(discoveredAdapters.size());
111121
for (auto adapter : discoveredAdapters) {
112122
m_adapters.push_back(std::make_unique<Adapter>(adapter, this));

0 commit comments

Comments
 (0)