-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebxr-linux-vulkan-2copy.patch
859 lines (833 loc) · 35.5 KB
/
webxr-linux-vulkan-2copy.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
diff --git a/DEPS b/DEPS
index c24c48a3d2..a0f3bee2ae 100644
--- a/DEPS
+++ b/DEPS
@@ -173,7 +173,7 @@ vars = {
# By default checkout the OpenXR loader library only on Windows and Android.
# The OpenXR backend for VR in Chromium is currently only supported for these
# platforms, but support for other platforms may be added in the future.
- 'checkout_openxr' : 'checkout_win or checkout_android',
+ 'checkout_openxr' : 'checkout_win or checkout_linux or checkout_android',
'checkout_instrumented_libraries': 'checkout_linux and checkout_configuration != "small"',
diff --git a/content/services/isolated_xr_device/xr_runtime_provider.cc b/content/services/isolated_xr_device/xr_runtime_provider.cc
index 27c89a1464..1c6f6e4d1b 100644
--- a/content/services/isolated_xr_device/xr_runtime_provider.cc
+++ b/content/services/isolated_xr_device/xr_runtime_provider.cc
@@ -13,10 +13,14 @@
#include "device/vr/buildflags/buildflags.h"
#include "device/vr/public/cpp/features.h"
-#if BUILDFLAG(ENABLE_OPENXR) && BUILDFLAG(IS_WIN)
+#if BUILDFLAG(ENABLE_OPENXR) && (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX))
#include "content/public/common/gpu_stream_constants.h"
#include "device/vr/openxr/openxr_device.h"
+#if BUILDFLAG(IS_WIN)
#include "device/vr/openxr/windows/openxr_platform_helper_windows.h"
+#else
+#include "device/vr/openxr/linux/openxr_platform_helper_linux.h"
+#endif
#include "services/viz/public/cpp/gpu/context_provider_command_buffer.h"
#endif
@@ -97,7 +101,7 @@ void IsolatedXRRuntimeProvider::PollForDeviceChanges() {
// 'preferred_device_enabled' being unused, thus [[maybe_unused]].
[[maybe_unused]] bool preferred_device_enabled = false;
-#if BUILDFLAG(ENABLE_OPENXR) && BUILDFLAG(IS_WIN)
+#if BUILDFLAG(ENABLE_OPENXR) && (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX))
if (!preferred_device_enabled && IsOpenXrHardwareAvailable()) {
SetOpenXrRuntimeStatus(RuntimeStatus::kEnable);
preferred_device_enabled = true;
@@ -121,11 +125,16 @@ void IsolatedXRRuntimeProvider::SetupPollingForDeviceChanges() {
// If none of the following runtimes are enabled, we'll get an error for
// 'command_line' being unused, thus [[maybe_unused]].
-#if BUILDFLAG(ENABLE_OPENXR) && BUILDFLAG(IS_WIN)
+#if BUILDFLAG(ENABLE_OPENXR) && (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX))
if (IsEnabled(command_line, device::features::kOpenXR,
switches::kWebXrRuntimeOpenXr)) {
+ #if BUILDFLAG(IS_WIN)
openxr_platform_helper_ =
std::make_unique<device::OpenXrPlatformHelperWindows>();
+ #else
+ openxr_platform_helper_ =
+ std::make_unique<device::OpenXrPlatformHelperLinux>();
+ #endif
should_check_openxr_ = openxr_platform_helper_->EnsureInitialized() &&
openxr_platform_helper_->IsApiAvailable();
any_runtimes_available |= should_check_openxr_;
@@ -147,7 +156,7 @@ void IsolatedXRRuntimeProvider::RequestDevices(
client_->OnDevicesEnumerated();
}
-#if BUILDFLAG(ENABLE_OPENXR) && BUILDFLAG(IS_WIN)
+#if BUILDFLAG(ENABLE_OPENXR) && (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX))
bool IsolatedXRRuntimeProvider::IsOpenXrHardwareAvailable() {
return should_check_openxr_ && openxr_platform_helper_->IsHardwareAvailable();
}
diff --git a/content/services/isolated_xr_device/xr_runtime_provider.h b/content/services/isolated_xr_device/xr_runtime_provider.h
index 0e7880f97e..323b21c7ec 100644
--- a/content/services/isolated_xr_device/xr_runtime_provider.h
+++ b/content/services/isolated_xr_device/xr_runtime_provider.h
@@ -21,6 +21,13 @@
#include "services/viz/public/cpp/gpu/gpu.h"
#endif
+#if BUILDFLAG(ENABLE_OPENXR) && BUILDFLAG(IS_LINUX)
+#include "components/viz/common/gpu/context_provider.h"
+#include "device/vr/openxr/context_provider_callbacks.h"
+#include "device/vr/openxr/linux/openxr_platform_helper_linux.h"
+#include "services/viz/public/cpp/gpu/gpu.h"
+#endif
+
namespace device {
class OpenXrDevice;
} // namespace device
@@ -48,7 +55,7 @@ class IsolatedXRRuntimeProvider final
void PollForDeviceChanges();
void SetupPollingForDeviceChanges();
-#if BUILDFLAG(ENABLE_OPENXR) && BUILDFLAG(IS_WIN)
+#if BUILDFLAG(ENABLE_OPENXR) && (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX))
bool IsOpenXrHardwareAvailable();
void SetOpenXrRuntimeStatus(RuntimeStatus status);
void CreateContextProviderAsync(
@@ -57,7 +64,11 @@ class IsolatedXRRuntimeProvider final
bool should_check_openxr_ = false;
// Must outlive OpenXrDevice
+ #if BUILDFLAG(IS_WIN)
std::unique_ptr<device::OpenXrPlatformHelperWindows> openxr_platform_helper_;
+ #else
+ std::unique_ptr<device::OpenXrPlatformHelperLinux> openxr_platform_helper_;
+ #endif
std::unique_ptr<device::OpenXrDevice> openxr_device_;
diff --git a/device/vr/BUILD.gn b/device/vr/BUILD.gn
index 7893093074..98494902b6 100644
--- a/device/vr/BUILD.gn
+++ b/device/vr/BUILD.gn
@@ -244,6 +244,19 @@ if (enable_vr) {
deps += [ ":directx_helpers" ]
}
+ if (is_linux) {
+ libs = [ ]
+
+ sources += [
+ "openxr/linux/openxr_graphics_binding_vulkan.cc",
+ "openxr/linux/openxr_graphics_binding_vulkan.h",
+ "openxr/linux/openxr_platform_helper_linux.cc",
+ "openxr/linux/openxr_platform_helper_linux.h",
+ ]
+
+ configs += [ "//gpu/vulkan:vulkan_config" ]
+ }
+
if (is_android) {
sources += [
"openxr/android/openxr_graphics_binding_open_gles.cc",
diff --git a/device/vr/buildflags/buildflags.gni b/device/vr/buildflags/buildflags.gni
index 6f69f9ee24..78ad912411 100644
--- a/device/vr/buildflags/buildflags.gni
+++ b/device/vr/buildflags/buildflags.gni
@@ -26,7 +26,7 @@ declare_args() {
# To build with OpenXR support, the OpenXR Loader needs to be pulled to
# third_party/openxr.
- enable_openxr = checkout_openxr && (is_win || _is_xr_supported_android)
+ enable_openxr = checkout_openxr && (is_win || is_linux || _is_xr_supported_android)
}
declare_args() {
diff --git a/device/vr/openxr/linux/openxr_graphics_binding_vulkan.cc b/device/vr/openxr/linux/openxr_graphics_binding_vulkan.cc
new file mode 100644
index 0000000000..0285bbac23
--- /dev/null
+++ b/device/vr/openxr/linux/openxr_graphics_binding_vulkan.cc
@@ -0,0 +1,343 @@
+#include "device/vr/openxr/linux/openxr_graphics_binding_vulkan.h"
+#include "base/containers/contains.h"
+#include "base/native_library.h"
+#include "device/vr/openxr/openxr_util.h"
+#include "gpu/command_buffer/common/shared_image_usage.h"
+#include "gpu/ipc/common/gpu_memory_buffer_support.h"
+#include "gpu/vulkan/vulkan_function_pointers.h"
+#include "ui/gfx/color_space.h"
+
+namespace device {
+
+namespace {
+ [[maybe_unused]] int next_memory_buffer_id = 0;
+}
+
+void OpenXrGraphicsBinding::GetRequiredExtensions(std::vector<const char*>& extensions) {
+ extensions.push_back(XR_KHR_VULKAN_ENABLE2_EXTENSION_NAME);
+}
+
+OpenXrGraphicsBindingVulkan::OpenXrGraphicsBindingVulkan() = default;
+OpenXrGraphicsBindingVulkan::~OpenXrGraphicsBindingVulkan() {
+ if (initialized_)
+ vkDeviceWaitIdle(binding_.device);
+ if (gpuTransferImage_)
+ gpuTransferImage_->Destroy();
+ gpuTransferImage_.reset();
+ if (commandBuffer_)
+ commandBuffer_->Destroy();
+ commandBuffer_.reset();
+ if (commandPool_)
+ commandPool_->Destroy();
+ commandPool_.reset();
+ if (copyQueue_)
+ copyQueue_->Destroy();
+ copyQueue_.reset();
+ if (binding_.device)
+ vkDestroyDevice(binding_.device, nullptr);
+}
+
+struct StaticLibrary {
+ base::NativeLibrary handle;
+ StaticLibrary(base::NativeLibrary library) : handle(library) {}
+ ~StaticLibrary() {base::UnloadNativeLibrary(handle);}
+ operator base::NativeLibrary() const {return handle;}
+};
+
+static base::NativeLibrary LoadNativeLibrary(std::string_view filePath) {
+ base::NativeLibraryLoadError error;
+ base::NativeLibrary library = base::LoadNativeLibrary(base::FilePath(filePath), &error);
+ if (!library)
+ LOG(ERROR) << "Failed to load '" << filePath << "': " << error.ToString();
+ return library;
+}
+
+XrResult OpenXrGraphicsBindingVulkan::SetupBinding(XrInstance instance, XrSystemId system) {
+ static StaticLibrary libvulkan = LoadNativeLibrary("libvulkan.so.1");
+ gpu::VulkanFunctionPointers *const vulkan_function_pointers = gpu::GetVulkanFunctionPointers();
+ vulkan_function_pointers->ResetForTesting();
+ if (!vulkan_function_pointers->BindUnassociatedFunctionPointersFromLoaderLib(libvulkan))
+ return XR_ERROR_RUNTIME_FAILURE;
+
+ PFN_xrGetVulkanGraphicsRequirements2KHR pfn_xrGetVulkanGraphicsRequirements2KHR = nullptr;
+ RETURN_IF_XR_FAILED(xrGetInstanceProcAddr(instance, "xrGetVulkanGraphicsRequirements2KHR", (PFN_xrVoidFunction*)(&pfn_xrGetVulkanGraphicsRequirements2KHR)));
+ PFN_xrCreateVulkanInstanceKHR pfn_xrCreateVulkanInstanceKHR = nullptr;
+ RETURN_IF_XR_FAILED(xrGetInstanceProcAddr(instance, "xrCreateVulkanInstanceKHR", (PFN_xrVoidFunction*)(&pfn_xrCreateVulkanInstanceKHR)));
+ PFN_xrGetVulkanGraphicsDevice2KHR pfn_xrGetVulkanGraphicsDevice2KHR = nullptr;
+ RETURN_IF_XR_FAILED(xrGetInstanceProcAddr(instance, "xrGetVulkanGraphicsDevice2KHR", (PFN_xrVoidFunction*)(&pfn_xrGetVulkanGraphicsDevice2KHR)));
+ PFN_xrCreateVulkanDeviceKHR pfn_xrCreateVulkanDeviceKHR = nullptr;
+ RETURN_IF_XR_FAILED(xrGetInstanceProcAddr(instance, "xrCreateVulkanDeviceKHR", (PFN_xrVoidFunction*)(&pfn_xrCreateVulkanDeviceKHR)));
+
+ XrGraphicsRequirementsVulkan2KHR requirements = {XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN2_KHR};
+ RETURN_IF_XR_FAILED(pfn_xrGetVulkanGraphicsRequirements2KHR(instance, system, &requirements));
+ VkResult result;
+ RETURN_IF_XR_FAILED(pfn_xrCreateVulkanInstanceKHR(instance, (const XrVulkanInstanceCreateInfoKHR[1]){{
+ .type = XR_TYPE_VULKAN_INSTANCE_CREATE_INFO_KHR,
+ .systemId = system,
+ .pfnGetInstanceProcAddr = vulkan_function_pointers->vkGetInstanceProcAddr.get(),
+ .vulkanCreateInfo = (const VkInstanceCreateInfo[1]){{
+ .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
+ .pApplicationInfo = (const VkApplicationInfo[1]){{
+ .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
+ .pApplicationName = "Chromium",
+ .apiVersion = gpu::kVulkanRequiredApiVersion,
+ }},
+ /*.enabledLayerCount = 1,
+ .ppEnabledLayerNames = (const char *const[1]){
+ "VK_LAYER_KHRONOS_validation",
+ },*/
+ }},
+ }}, &binding_.instance, &result));
+ RETURN_IF(result < VK_SUCCESS, XR_ERROR_RUNTIME_FAILURE, "xrCreateVulkanInstanceKHR() failed");
+
+ std::vector<const char*> extensions = {
+ VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
+ VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,
+ VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
+ VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME,
+ VK_EXT_EXTERNAL_MEMORY_DMA_BUF_EXTENSION_NAME,
+ };
+ if (haveDrmFormatModifiers_) // TODO: set `haveDrmFormatModifiers_` if supported
+ extensions.push_back(VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME);
+ gfx::ExtensionSet extension_set(std::begin(extensions), std::end(extensions));
+
+ if (!vulkan_function_pointers->BindInstanceFunctionPointers(binding_.instance, gpu::kVulkanRequiredApiVersion, extension_set))
+ return XR_ERROR_RUNTIME_FAILURE;
+
+ RETURN_IF_XR_FAILED(pfn_xrGetVulkanGraphicsDevice2KHR(instance, (const XrVulkanGraphicsDeviceGetInfoKHR[1]){{
+ .type = XR_TYPE_VULKAN_GRAPHICS_DEVICE_GET_INFO_KHR,
+ .systemId = system,
+ .vulkanInstance = binding_.instance,
+ }}, &binding_.physicalDevice));
+
+ const float queuePriority = 0;
+ VkDeviceQueueCreateInfo queueInfo = {
+ .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
+ .queueCount = 1,
+ .pQueuePriorities = &queuePriority,
+ };
+ uint32_t queueFamilyCount = 0;
+ vkGetPhysicalDeviceQueueFamilyProperties(binding_.physicalDevice, &queueFamilyCount, nullptr);
+ std::vector<VkQueueFamilyProperties> queueFamilyProps(queueFamilyCount);
+ vkGetPhysicalDeviceQueueFamilyProperties(binding_.physicalDevice, &queueFamilyCount, &queueFamilyProps[0]);
+
+ for (uint32_t i = 0; i < queueFamilyCount; ++i) {
+ if (queueFamilyProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
+ binding_.queueFamilyIndex = i;
+ break;
+ }
+ }
+ queueInfo.queueFamilyIndex = binding_.queueFamilyIndex;
+
+ RETURN_IF_XR_FAILED(pfn_xrCreateVulkanDeviceKHR(instance, (const XrVulkanDeviceCreateInfoKHR[1]){{
+ .type = XR_TYPE_VULKAN_DEVICE_CREATE_INFO_KHR,
+ .systemId = system,
+ .pfnGetInstanceProcAddr = vulkan_function_pointers->vkGetInstanceProcAddr.get(),
+ .vulkanPhysicalDevice = binding_.physicalDevice,
+ .vulkanCreateInfo = (const VkDeviceCreateInfo[1]){{
+ .sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
+ .queueCreateInfoCount = 1,
+ .pQueueCreateInfos = &queueInfo,
+ .enabledExtensionCount = (uint32_t)extensions.size(),
+ .ppEnabledExtensionNames = &extensions[0],
+ .pEnabledFeatures = (const VkPhysicalDeviceFeatures[1]){},
+ }},
+ }}, &binding_.device, &result));
+ RETURN_IF(result < VK_SUCCESS, XR_ERROR_RUNTIME_FAILURE, "xrCreateVulkanDeviceKHR() failed");
+ if (!vulkan_function_pointers->BindDeviceFunctionPointers(binding_.device, gpu::kVulkanRequiredApiVersion, extension_set))
+ return XR_ERROR_RUNTIME_FAILURE;
+ vkCmdCopyImage_ = reinterpret_cast<PFN_vkCmdCopyImage>(vkGetDeviceProcAddr(binding_.device, "vkCmdCopyImage"));
+ if (!vkCmdCopyImage_) {
+ DLOG(WARNING) << "Failed to bind vulkan entrypoint: vkCmdCopyImage";
+ return XR_ERROR_RUNTIME_FAILURE;
+ }
+
+ binding_.queueIndex = 0;
+ VkQueue queue = VK_NULL_HANDLE;
+ vkGetDeviceQueue(binding_.device, binding_.queueFamilyIndex, binding_.queueIndex, &queue);
+ copyQueue_ = std::make_unique<gpu::VulkanDeviceQueue>(binding_.instance);
+ if (!copyQueue_->InitializeForWebView(binding_.physicalDevice, binding_.device, queue, binding_.queueFamilyIndex, std::move(extension_set)))
+ return XR_ERROR_RUNTIME_FAILURE;
+ commandPool_ = std::make_unique<gpu::VulkanCommandPool>(copyQueue_.get());
+ if (!commandPool_->Initialize()) // vkCreateCommandPool
+ return XR_ERROR_RUNTIME_FAILURE;
+ commandBuffer_ = commandPool_->CreatePrimaryCommandBuffer(); // vkAllocateCommandBuffers
+ if (!commandBuffer_)
+ return XR_ERROR_RUNTIME_FAILURE;
+ return XR_SUCCESS;
+}
+
+bool OpenXrGraphicsBindingVulkan::Initialize(XrInstance instance, XrSystemId system) {
+ if (initialized_) {
+ return true;
+ }
+
+ if (XR_FAILED(SetupBinding(instance, system)))
+ return false;
+ initialized_ = true;
+ OnSwapchainImageSizeChanged();
+ return true;
+}
+
+const void* OpenXrGraphicsBindingVulkan::GetSessionCreateInfo() const {
+ CHECK(initialized_);
+ return &binding_;
+}
+
+int64_t OpenXrGraphicsBindingVulkan::GetSwapchainFormat(XrSession session) const {
+ uint32_t format_length = 0;
+ RETURN_IF_XR_FAILED(xrEnumerateSwapchainFormats(session, 0, &format_length, nullptr));
+ std::vector<int64_t> swapchain_formats(format_length);
+ RETURN_IF_XR_FAILED(xrEnumerateSwapchainFormats(session, (uint32_t)swapchain_formats.size(), &format_length, swapchain_formats.data()));
+ DCHECK(!swapchain_formats.empty());
+
+ if (base::Contains(swapchain_formats, VK_FORMAT_R8G8B8A8_SRGB))
+ return VK_FORMAT_R8G8B8A8_SRGB;
+
+ if (!base::Contains(swapchain_formats, VK_FORMAT_R8G8B8A8_UNORM)) {
+ LOG(ERROR) << "No matching supported swapchain formats with OpenXr Runtime:";
+ for(int64_t format : swapchain_formats)
+ LOG(ERROR) << " " << format;
+ }
+
+ return VK_FORMAT_R8G8B8A8_UNORM;
+}
+
+XrResult OpenXrGraphicsBindingVulkan::EnumerateSwapchainImages(const XrSwapchain& color_swapchain) {
+ CHECK(color_swapchain != XR_NULL_HANDLE);
+ CHECK(color_swapchain_images_.empty());
+
+ uint32_t chain_length;
+ RETURN_IF_XR_FAILED(xrEnumerateSwapchainImages(color_swapchain, 0, &chain_length, nullptr));
+ std::vector<XrSwapchainImageVulkan2KHR> xr_swapchain_images(chain_length, {XR_TYPE_SWAPCHAIN_IMAGE_VULKAN2_KHR});
+
+ RETURN_IF_XR_FAILED(xrEnumerateSwapchainImages(color_swapchain, xr_swapchain_images.size(), &chain_length, reinterpret_cast<XrSwapchainImageBaseHeader*>(xr_swapchain_images.data())));
+
+ color_swapchain_images_.reserve(xr_swapchain_images.size());
+ for (const XrSwapchainImageVulkan2KHR& swapchain_image : xr_swapchain_images) {
+ color_swapchain_images_.emplace_back(swapchain_image.image);
+ }
+
+ return XR_SUCCESS;
+}
+
+void OpenXrGraphicsBindingVulkan::ClearSwapChainImages() {
+ color_swapchain_images_.clear();
+}
+
+base::span<SwapChainInfo> OpenXrGraphicsBindingVulkan::GetSwapChainImages() {
+ return color_swapchain_images_;
+}
+
+bool OpenXrGraphicsBindingVulkan::CanUseSharedImages() const {
+ return false;
+}
+
+void OpenXrGraphicsBindingVulkan::CreateSharedImages(gpu::SharedImageInterface* sii) {}
+
+const SwapChainInfo& OpenXrGraphicsBindingVulkan::GetActiveSwapchainImage() {
+ CHECK(has_active_swapchain_image());
+ CHECK(active_swapchain_index() < color_swapchain_images_.size());
+ return color_swapchain_images_[active_swapchain_index()];
+}
+
+bool OpenXrGraphicsBindingVulkan::WaitOnFence(gfx::GpuFence& gpu_fence) {
+ return false;
+}
+
+void OpenXrGraphicsBindingVulkan::OnSwapchainImageSizeChanged() {
+ gpuTransferMailbox_ = {};
+ gpuTransferBuffer_ = nullptr;
+ if (!initialized_)
+ return;
+
+ const gfx::Size size = GetSwapchainImageSize(); // TODO: return early if size hasn't changed
+
+ vkDeviceWaitIdle(binding_.device);
+ if (gpuTransferImage_)
+ gpuTransferImage_->Destroy();
+ gpuTransferImage_.reset();
+
+ const VkExternalMemoryImageCreateInfo extra_image_create_info = {
+ .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
+ .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
+ };
+ const VkExportMemoryAllocateInfo extra_memory_allocation_info = {
+ .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
+ .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
+ };
+ gpuTransferImage_ = gpu::VulkanImage::Create(copyQueue_.get(), size, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
+ haveDrmFormatModifiers_ ? VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT : VK_IMAGE_TILING_OPTIMAL, &extra_image_create_info, &extra_memory_allocation_info);
+ if (!gpuTransferImage_)
+ return;
+
+ base::ScopedFD fd = gpuTransferImage_->GetMemoryFd(VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
+ if (!fd.is_valid()) {
+ LOG(ERROR) << "vkGetMemoryFdKHR() failed";
+ return;
+ }
+
+ VkImageDrmFormatModifierPropertiesEXT modifier_props = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
+ .drmFormatModifier = gfx::NativePixmapHandle::kNoModifier,
+ };
+ if (haveDrmFormatModifiers_) {
+ const VkResult result = vkGetImageDrmFormatModifierPropertiesEXT(binding_.device, gpuTransferImage_->image(), &modifier_props);
+ if (result != VK_SUCCESS) {
+ LOG(ERROR) << "vkGetImageDrmFormatModifierPropertiesEXT failed result:" << result;
+ return;
+ }
+ }
+
+ gfx::GpuMemoryBufferHandle handle;
+ handle.id = gfx::GpuMemoryBufferId(next_memory_buffer_id++);
+ handle.type = gfx::GpuMemoryBufferType::NATIVE_PIXMAP;
+ handle.native_pixmap_handle.planes.emplace_back(0, 0, gpuTransferImage_->device_size(), std::move(fd));
+ handle.native_pixmap_handle.modifier = modifier_props.drmFormatModifier;
+ gpu::GpuMemoryBufferSupport support;
+ gpuTransferBuffer_ = support.CreateGpuMemoryBufferImplFromHandle(std::move(handle), size, gfx::BufferFormat::BGRA_8888, gfx::BufferUsage::SCANOUT, base::NullCallback());
+}
+
+void OpenXrGraphicsBindingVulkan::BlitFrom(const gpu::MailboxHolder& holder, gpu::gles2::GLES2Interface *gl, gpu::SharedImageInterface *sii) {
+ const gfx::Size imageSize = GetTransferSize();
+ if (imageSize != GetSwapchainImageSize() || !gpuTransferBuffer_)
+ return;
+
+ commandBuffer_->Wait(UINT64_MAX);
+ if (gpuTransferMailbox_.mailbox.IsZero()) {
+ gpuTransferMailbox_.mailbox = sii->CreateSharedImage(viz::SinglePlaneFormat::kBGRA_8888, gpuTransferBuffer_->GetSize(), gfx::ColorSpace(), kBottomLeft_GrSurfaceOrigin, kPremul_SkAlphaType, gpu::SHARED_IMAGE_USAGE_GLES2, "OpenXrGraphicsBindingVulkan", gpuTransferBuffer_->CloneHandle());
+ gpuTransferMailbox_.sync_token = sii->GenVerifiedSyncToken();
+ gpuTransferMailbox_.texture_target = GL_TEXTURE_2D;
+ gl->WaitSyncTokenCHROMIUM(sii->GenUnverifiedSyncToken().GetConstData());
+ }
+
+ gpu::Mailbox::Name mailboxes[2];
+ memcpy(mailboxes[0], holder.mailbox.name, sizeof(gpu::Mailbox::Name));
+ memcpy(mailboxes[1], gpuTransferMailbox_.mailbox.name, sizeof(gpu::Mailbox::Name));
+ gl->WaitSyncTokenCHROMIUM(holder.sync_token.GetConstData());
+ gl->CopySharedImageINTERNAL(0, 0, 0, 0, imageSize.width(), imageSize.height(), true, *mailboxes);
+ gl->Finish(); // CHROMIUM_gpu_fence isn't available on Linux and I'm not sure how else to synchronize this
+
+ SwapChainInfo &image = color_swapchain_images_[active_swapchain_index()];
+ {
+ gpu::ScopedSingleUseCommandBufferRecorder recorder(*commandBuffer_); // vkBeginCommandBuffer
+ commandBuffer_->TransitionImageLayout(gpuTransferImage_->image(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
+ commandBuffer_->TransitionImageLayout(image.openxr_image, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
+ vkCmdCopyImage_(recorder.handle(), gpuTransferImage_->image(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, image.openxr_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, (const VkImageCopy[1]){{
+ .srcSubresource = {
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .layerCount = 1,
+ },
+ .dstSubresource = {
+ .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
+ .layerCount = 1,
+ },
+ .extent = {(uint32_t)imageSize.width(), (uint32_t)imageSize.height(), 1},
+ }});
+ commandBuffer_->TransitionImageLayout(gpuTransferImage_->image(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
+ commandBuffer_->TransitionImageLayout(image.openxr_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
+ } // ~CommandBufferRecorderBase() - vkEndCommandBuffer
+ commandBuffer_->Submit(0, nullptr, 0, nullptr);
+}
+
+} // namespace device
diff --git a/device/vr/openxr/linux/openxr_graphics_binding_vulkan.h b/device/vr/openxr/linux/openxr_graphics_binding_vulkan.h
new file mode 100644
index 0000000000..a17ae30605
--- /dev/null
+++ b/device/vr/openxr/linux/openxr_graphics_binding_vulkan.h
@@ -0,0 +1,54 @@
+#pragma once
+#include <vector>
+
+#include "device/vr/openxr/openxr_graphics_binding.h"
+#include "device/vr/openxr/openxr_platform.h"
+#include "device/vr/vr_export.h"
+#include "gpu/command_buffer/client/gles2_interface.h"
+#include "gpu/command_buffer/client/shared_image_interface.h"
+#include "gpu/vulkan/vulkan_command_buffer.h"
+#include "gpu/vulkan/vulkan_command_pool.h"
+#include "gpu/vulkan/vulkan_device_queue.h"
+#include "gpu/vulkan/vulkan_image.h"
+#include "ui/gfx/gpu_memory_buffer.h"
+
+namespace device {
+
+class DEVICE_VR_EXPORT OpenXrGraphicsBindingVulkan : public OpenXrGraphicsBinding {
+ public:
+ OpenXrGraphicsBindingVulkan();
+ ~OpenXrGraphicsBindingVulkan() override;
+
+ bool Initialize(XrInstance instance, XrSystemId system) override;
+ const void* GetSessionCreateInfo() const override;
+ int64_t GetSwapchainFormat(XrSession session) const override;
+ XrResult EnumerateSwapchainImages(
+ const XrSwapchain& color_swapchain) override;
+ void ClearSwapChainImages() override;
+ base::span<SwapChainInfo> GetSwapChainImages() override;
+ bool CanUseSharedImages() const override;
+ void CreateSharedImages(gpu::SharedImageInterface* sii) override;
+ const SwapChainInfo& GetActiveSwapchainImage() override;
+ bool WaitOnFence(gfx::GpuFence& gpu_fence) override;
+ void BlitFrom(const gpu::MailboxHolder& holder, gpu::gles2::GLES2Interface *gl, gpu::SharedImageInterface *sii);
+
+private:
+ XrResult SetupBinding(XrInstance instance, XrSystemId system);
+ void OnSwapchainImageSizeChanged() override;
+ bool initialized_ = false;
+ bool haveDrmFormatModifiers_ = false;
+ XrGraphicsBindingVulkan2KHR binding_{XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR, nullptr};
+ std::vector<SwapChainInfo> color_swapchain_images_;
+
+ std::unique_ptr<gpu::VulkanDeviceQueue> copyQueue_ = nullptr;
+ std::unique_ptr<gpu::VulkanCommandPool> commandPool_ = nullptr;
+ std::unique_ptr<gpu::VulkanCommandBuffer> commandBuffer_ = nullptr;
+
+ std::unique_ptr<gpu::VulkanImage> gpuTransferImage_ = nullptr;
+ std::unique_ptr<gfx::GpuMemoryBuffer> gpuTransferBuffer_ = nullptr;
+ gpu::MailboxHolder gpuTransferMailbox_;
+
+ PFN_vkCmdCopyImage vkCmdCopyImage_ = nullptr;
+};
+
+} // namespace device
diff --git a/device/vr/openxr/linux/openxr_platform_helper_linux.cc b/device/vr/openxr/linux/openxr_platform_helper_linux.cc
new file mode 100644
index 0000000000..6edd66879d
--- /dev/null
+++ b/device/vr/openxr/linux/openxr_platform_helper_linux.cc
@@ -0,0 +1,63 @@
+#include "device/vr/openxr/linux/openxr_platform_helper_linux.h"
+#include "device/vr/openxr/openxr_api_wrapper.h"
+#include "device/vr/openxr/linux/openxr_graphics_binding_vulkan.h"
+#include "device/vr/public/mojom/isolated_xr_service.mojom.h"
+
+namespace device {
+
+void OpenXrPlatformHelper::GetRequiredExtensions(std::vector<const char*>& extensions) {}
+std::vector<const char*> OpenXrPlatformHelper::GetOptionalExtensions() {return {};}
+
+OpenXrPlatformHelperLinux::OpenXrPlatformHelperLinux() {}
+OpenXrPlatformHelperLinux::~OpenXrPlatformHelperLinux() = default;
+
+std::unique_ptr<OpenXrGraphicsBinding> OpenXrPlatformHelperLinux::GetGraphicsBinding() {
+ return std::make_unique<OpenXrGraphicsBindingVulkan>();
+}
+
+void OpenXrPlatformHelperLinux::GetPlatformCreateInfo(const device::OpenXrCreateInfo& create_info, PlatformCreateInfoReadyCallback callback) {
+ std::move(callback).Run(nullptr);
+}
+
+device::mojom::XRDeviceData OpenXrPlatformHelperLinux::GetXRDeviceData() {
+ return {};
+}
+
+bool OpenXrPlatformHelperLinux::IsHardwareAvailable() {
+ XrInstance instance = GetOrCreateXrInstance();
+ if (instance == XR_NULL_HANDLE) {
+ return false;
+ }
+
+ XrSystemId system;
+ return XR_SUCCEEDED(OpenXrApiWrapper::GetSystem(instance, &system));
+}
+
+bool OpenXrPlatformHelperLinux::IsApiAvailable() {
+ return GetOrCreateXrInstance() != XR_NULL_HANDLE;
+}
+
+bool OpenXrPlatformHelperLinux::Initialize() {
+ return true;
+}
+
+XrInstance OpenXrPlatformHelperLinux::GetOrCreateXrInstance() {
+ XrInstance instance = XR_NULL_HANDLE;
+ (void)CreateInstance(&instance, nullptr);
+ return instance;
+}
+
+XrResult OpenXrPlatformHelperLinux::CreateInstance(XrInstance* instance, void* create_info) {
+ CHECK(instance);
+ if (xr_instance_ != XR_NULL_HANDLE) {
+ *instance = xr_instance_;
+ return XR_SUCCESS;
+ }
+ return OpenXrPlatformHelper::CreateInstance(instance, create_info);
+}
+
+XrResult OpenXrPlatformHelperLinux::DestroyInstance(XrInstance& instance) {
+ return OpenXrPlatformHelper::DestroyInstance(instance);
+}
+
+} // namespace device
diff --git a/device/vr/openxr/linux/openxr_platform_helper_linux.h b/device/vr/openxr/linux/openxr_platform_helper_linux.h
new file mode 100644
index 0000000000..a922dbf431
--- /dev/null
+++ b/device/vr/openxr/linux/openxr_platform_helper_linux.h
@@ -0,0 +1,27 @@
+#pragma once
+#include "device/vr/openxr/openxr_platform_helper.h"
+#include "device/vr/openxr/openxr_platform.h"
+
+namespace device {
+
+class DEVICE_VR_EXPORT OpenXrPlatformHelperLinux : public OpenXrPlatformHelper {
+ public:
+ OpenXrPlatformHelperLinux();
+ ~OpenXrPlatformHelperLinux() override;
+
+ std::unique_ptr<OpenXrGraphicsBinding> GetGraphicsBinding() override;
+ void GetPlatformCreateInfo(const device::OpenXrCreateInfo& create_info, PlatformCreateInfoReadyCallback) override;
+ device::mojom::XRDeviceData GetXRDeviceData() override;
+ bool Initialize() override;
+
+ XrResult CreateInstance(XrInstance* instance, void* create_info) override;
+ XrResult DestroyInstance(XrInstance& instance) override;
+
+ bool IsHardwareAvailable();
+ bool IsApiAvailable();
+
+private:
+ XrInstance GetOrCreateXrInstance();
+};
+
+}
diff --git a/device/vr/openxr/openxr_graphics_binding.cc b/device/vr/openxr/openxr_graphics_binding.cc
index df54dce45a..f2c996aeba 100644
--- a/device/vr/openxr/openxr_graphics_binding.cc
+++ b/device/vr/openxr/openxr_graphics_binding.cc
@@ -11,6 +11,8 @@ namespace device {
#if BUILDFLAG(IS_WIN)
SwapChainInfo::SwapChainInfo(ID3D11Texture2D* d3d11_texture)
: d3d11_texture(d3d11_texture) {}
+#elif BUILDFLAG(IS_LINUX)
+SwapChainInfo::SwapChainInfo(VkImage image) : openxr_image(image) {}
#elif BUILDFLAG(IS_ANDROID)
SwapChainInfo::SwapChainInfo(uint32_t texture) : openxr_texture(texture) {}
#endif
diff --git a/device/vr/openxr/openxr_graphics_binding.h b/device/vr/openxr/openxr_graphics_binding.h
index 39e8062136..a40265c8a8 100644
--- a/device/vr/openxr/openxr_graphics_binding.h
+++ b/device/vr/openxr/openxr_graphics_binding.h
@@ -19,6 +19,10 @@
#include <wrl.h>
#endif
+#if BUILDFLAG(IS_LINUX)
+#include <vulkan/vulkan_core.h>
+#endif
+
#if BUILDFLAG(IS_ANDROID)
#include "gpu/ipc/common/gpu_memory_buffer_impl_android_hardware_buffer.h"
#include "ui/gl/scoped_egl_image.h"
@@ -39,6 +43,8 @@ struct SwapChainInfo {
public:
#if BUILDFLAG(IS_WIN)
explicit SwapChainInfo(ID3D11Texture2D*);
+#elif BUILDFLAG(IS_LINUX)
+ explicit SwapChainInfo(VkImage image);
#elif BUILDFLAG(IS_ANDROID)
explicit SwapChainInfo(uint32_t texture);
#endif
@@ -56,6 +62,8 @@ struct SwapChainInfo {
// and D3D11Fence for each D3D11 texture in the vector.
raw_ptr<ID3D11Texture2D> d3d11_texture = nullptr;
Microsoft::WRL::ComPtr<ID3D11Fence> d3d11_fence;
+#elif BUILDFLAG(IS_LINUX)
+ VkImage openxr_image;
#elif BUILDFLAG(IS_ANDROID)
// Ideally this would be a gluint, but there are conflicting headers for GL
// depending on *how* you want to use it; so we can't use it at the moment.
diff --git a/device/vr/openxr/openxr_platform.h b/device/vr/openxr/openxr_platform.h
index a0158be7f9..65f0f32df7 100644
--- a/device/vr/openxr/openxr_platform.h
+++ b/device/vr/openxr/openxr_platform.h
@@ -18,6 +18,8 @@
#if BUILDFLAG(IS_WIN)
#include <d3d11.h>
+#elif BUILDFLAG(IS_LINUX)
+#include <vulkan/vulkan_core.h>
#elif BUILDFLAG(IS_ANDROID)
#include <EGL/egl.h>
#include <jni.h>
diff --git a/device/vr/openxr/openxr_render_loop.cc b/device/vr/openxr/openxr_render_loop.cc
index 31e956c757..358ef492df 100644
--- a/device/vr/openxr/openxr_render_loop.cc
+++ b/device/vr/openxr/openxr_render_loop.cc
@@ -26,6 +26,10 @@
#include <d3d11_4.h>
#endif
+#if BUILDFLAG(IS_LINUX)
+#include "device/vr/openxr/linux/openxr_graphics_binding_vulkan.h"
+#endif
+
namespace device {
OpenXrRenderLoop::OpenXrRenderLoop(
@@ -125,7 +129,7 @@ void OpenXrRenderLoop::StartRuntime(
// texture helper rather than need it passed in.
#if BUILDFLAG(IS_WIN)
graphics_binding_ = platform_helper_->GetGraphicsBinding(&texture_helper_);
-#elif BUILDFLAG(IS_ANDROID)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
graphics_binding_ = platform_helper_->GetGraphicsBinding();
#endif
@@ -312,9 +316,15 @@ void OpenXrRenderLoop::SubmitFrame(int16_t frame_index,
base::TimeDelta time_waited) {
DVLOG(3) << __func__ << " frame_index=" << frame_index;
CHECK(!IsUsingSharedImages());
+ #if BUILDFLAG(IS_LINUX)
+ static_cast<OpenXrGraphicsBindingVulkan*>(graphics_binding_.get())->BlitFrom(mailbox, context_provider_->ContextGL(), context_provider_->SharedImageInterface());
+ MarkFrameSubmitted(frame_index);
+ MaybeCompositeAndSubmit();
+ #else
DCHECK(BUILDFLAG(IS_ANDROID));
// TODO(https://crbug.com/1454942): Support non-shared buffer mode.
SubmitFrameMissing(frame_index, mailbox.sync_token);
+ #endif
}
void OpenXrRenderLoop::SubmitFrameDrawnIntoTexture(
@@ -349,7 +359,7 @@ void OpenXrRenderLoop::OnWebXrTokenSignaled(
#if BUILDFLAG(IS_WIN)
SubmitFrameWithTextureHandle(frame_index, mojo::PlatformHandle(),
gpu::SyncToken());
-#elif BUILDFLAG(IS_ANDROID)
+#elif BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
MarkFrameSubmitted(frame_index);
graphics_binding_->Render();
MaybeCompositeAndSubmit();
diff --git a/device/vr/public/cpp/features.cc b/device/vr/public/cpp/features.cc
index d1230c3f38..3fdcac0d92 100644
--- a/device/vr/public/cpp/features.cc
+++ b/device/vr/public/cpp/features.cc
@@ -54,8 +54,8 @@ BASE_FEATURE(kEnableCardboard,
// Controls WebXR support for the OpenXR Runtime.
BASE_FEATURE(kOpenXR,
"OpenXR",
- BUILDFLAG(IS_WIN) ? base::FEATURE_ENABLED_BY_DEFAULT
- : base::FEATURE_DISABLED_BY_DEFAULT);
+ (BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX)) ? base::FEATURE_ENABLED_BY_DEFAULT
+ : base::FEATURE_DISABLED_BY_DEFAULT);
// Some WebXR features may have been enabled for ARCore, but are not yet ready
// to be plumbed up from the OpenXR backend. This feature provides a mechanism
diff --git a/device/vr/windows/compositor_base.cc b/device/vr/windows/compositor_base.cc
index 198a8b0d28..3d1c4f85e6 100644
--- a/device/vr/windows/compositor_base.cc
+++ b/device/vr/windows/compositor_base.cc
@@ -623,7 +623,7 @@ void XRCompositorCommon::MaybeCompositeAndSubmit() {
} else {
texture_helper_.CleanupNoSubmit();
}
-#elif BUILDFLAG(IS_ANDROID)
+#elif BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_ANDROID)
bool copy_successful = true;
#endif
diff --git a/gpu/command_buffer/service/shared_image/external_vk_image_gl_representation.cc b/gpu/command_buffer/service/shared_image/external_vk_image_gl_representation.cc
index 4d17707c2f..df8ea50208 100644
--- a/gpu/command_buffer/service/shared_image/external_vk_image_gl_representation.cc
+++ b/gpu/command_buffer/service/shared_image/external_vk_image_gl_representation.cc
@@ -7,6 +7,7 @@
#include <vector>
#include "base/logging.h"
+#include "gpu/command_buffer/service/skia_utils.h"
#include "gpu/vulkan/vulkan_util.h"
#include "ui/gl/gl_bindings.h"
@@ -146,6 +147,13 @@ void ExternalVkImageGLRepresentationShared::EndAccess() {
backing_impl()->context_state()->MarkContextLost();
return;
}
+
+ { // HACK: prevents FD exhaustion due to WebXR semaphores not getting cleaned up in some cases
+ GrFlushInfo flush_info = {};
+ gpu::AddVulkanCleanupTaskForSkiaFlush(context_provider(), &flush_info);
+ backing_impl()->context_state()->gr_context()->flush(flush_info);
+ backing_impl()->context_state()->gr_context()->submit();
+ }
}
backing_impl()->EndAccess(readonly, std::move(external_semaphore),
/*is_gl=*/true);
diff --git a/third_party/openxr/BUILD.gn b/third_party/openxr/BUILD.gn
index ed731bd432..b7c3568c68 100644
--- a/third_party/openxr/BUILD.gn
+++ b/third_party/openxr/BUILD.gn
@@ -166,6 +166,13 @@ if (enable_openxr) {
"XR_USE_PLATFORM_WIN32",
"XR_USE_GRAPHICS_API_D3D11",
]
+ } else if (is_linux) {
+ defines = [
+ "XRLOADER_DISABLE_EXCEPTION_HANDLING",
+ "XR_OS_LINUX",
+ "XR_USE_GRAPHICS_API_VULKAN",
+ "HAVE_SECURE_GETENV",
+ ]
} else {
defines = [
"XRLOADER_DISABLE_EXCEPTION_HANDLING",
diff --git a/ui/gfx/linux/gbm_wrapper.cc b/ui/gfx/linux/gbm_wrapper.cc
index c1bf39fc53..70b70d0b44 100644
--- a/ui/gfx/linux/gbm_wrapper.cc
+++ b/ui/gfx/linux/gbm_wrapper.cc
@@ -392,8 +392,16 @@ class Device final : public ui::GbmDevice {
struct gbm_bo* bo =
gbm_bo_import(device_, GBM_BO_IMPORT_FD_MODIFIER, &fd_data, gbm_flags);
if (!bo) {
- LOG(ERROR) << "nullptr returned from gbm_bo_import";
- return nullptr;
+ if (gbm_flags & GBM_BO_USE_SCANOUT) {
+ gbm_flags &= ~GBM_BO_USE_SCANOUT;
+ bo = gbm_bo_import(device_, GBM_BO_IMPORT_FD_MODIFIER, &fd_data,
+ gbm_flags);
+ }
+
+ if (!bo) {
+ LOG(ERROR) << "nullptr returned from gbm_bo_import";
+ return nullptr;
+ }
}
return std::make_unique<Buffer>(bo, format, gbm_flags, handle.modifier,