Open3D (C++ API)  0.20.0
Loading...
Searching...
No Matches
GaussianSplatVulkanContext.h
Go to the documentation of this file.
1// ----------------------------------------------------------------------------
2// - Open3D: www.open3d.org -
3// ----------------------------------------------------------------------------
4// Copyright (c) 2018-2026 www.open3d.org
5// SPDX-License-Identifier: MIT
6// ----------------------------------------------------------------------------
7//
8// Headless Vulkan context for Gaussian splatting compute (Linux/Windows).
9//
10// Owns the VkInstance, VkPhysicalDevice, VkDevice and compute queue used both
11// by the GS compute pipeline and by Filament's Vulkan backend. The same
12// VkDevice is shared with Filament via VulkanPlatform::VulkanSharedContext
13// (passed as Engine::create()'s sharedContext argument). This eliminates the
14// old GL-Vulkan interop path entirely: GS output images are plain VkImages
15// imported into Filament through VulkanDriver::importTextureR().
16//
17// Key relationships:
18// - FilamentEngine.cpp calls Initialize() before Engine::create() and
19// Shutdown() after Engine::destroy() so the shared device outlives
20// Filament.
21// - GaussianSplatVulkanBackend uses GetDevice() / GetComputeQueue() for
22// compute dispatch and creates plain VkImages for depth/colour sharing.
23// - GetVulkanSharedContext() returns a VulkanSharedContext struct for
24// Engine::create(). The struct must stay alive for the engine's lifetime.
25//
26// Uses vulkan-hpp (Vulkan-Headers) for Vulkan loading and RAII handle
27// lifetime management, and VMA (vk_mem_alloc.h from the pinned 3rdparty
28// download) for suballocated internal-only buffer allocations.
29//
30// Thread-safety: not thread-safe. All calls must be made from the render
31// thread.
32
33#pragma once
34
35#if !defined(__APPLE__)
36
37#include <cstddef>
38#include <cstdint>
39#include <string>
40
41// Suppress C function-prototype declarations in vulkan.h: all Vulkan entry
42// points are resolved at runtime through vulkan-hpp's per-object RAII
43// dispatchers (ContextDispatcher / InstanceDispatcher / DeviceDispatcher),
44// not as statically-linked symbols.
45//
46// NOTE: BlueVK (used by Filament) also defines VK_NO_PROTOTYPES before
47// including vulkan.h, so the two includes are mutually compatible when
48// this header is included after Filament headers.
49#ifndef VK_NO_PROTOTYPES
50#define VK_NO_PROTOTYPES
51#endif
52#include <vulkan/vulkan_raii.hpp>
53
54namespace open3d {
55namespace visualization {
56namespace rendering {
57
65 VkInstance instance = VK_NULL_HANDLE;
66 VkPhysicalDevice physical_device = VK_NULL_HANDLE;
67 VkDevice logical_device = VK_NULL_HANDLE;
68 std::uint32_t graphics_queue_family_index = 0xFFFFFFFFu;
69 std::uint32_t graphics_queue_index = 0xFFFFFFFFu;
70 bool debug_utils_enabled = false;
72 bool multiview_supported = false;
73};
74
79 VkImage vk_image = VK_NULL_HANDLE;
80 VkDeviceMemory vk_memory = VK_NULL_HANDLE;
81
82 bool IsValid() const { return vk_image != VK_NULL_HANDLE; }
83};
84
85// ---------------------------------------------------------------------------
86// GaussianSplatVulkanContext — headless Vulkan context
87// ---------------------------------------------------------------------------
88
93public:
95
104 bool Initialize();
105
110 void Shutdown();
111
112 bool IsValid() const { return initialized_; }
113
115 bool IsSoftwareDevice() const;
116
118 const std::string& GetLastError() const { return last_error_; }
119
120 // --- Filament integration ---------------------------------------------
121
124 void* GetVulkanSharedContext() { return &shared_context_; }
125
126 // --- Device accessors (used by VulkanBackend and ComputeGPUVulkan) -----
127
128 VkInstance GetVkInstance() const {
129 return static_cast<vk::Instance::CType>(*instance_);
130 }
131 VkDevice GetDevice() const {
132 return static_cast<vk::Device::CType>(*device_);
133 }
134 VkPhysicalDevice GetPhysicalDevice() const {
135 return static_cast<vk::PhysicalDevice::CType>(*physical_device_);
136 }
138 VkQueue GetComputeQueue() const {
139 return static_cast<vk::Queue::CType>(*compute_queue_);
140 }
141 std::uint32_t GetComputeQueueFamily() const {
142 return graphics_queue_family_;
143 }
146 bool GetDebugUtilsEnabled() const { return debug_utils_enabled_; }
147
148 // RAII accessor used by ComputeGPUVulkan to create sub-objects.
149 const vk::raii::Device& GetRaiiDevice() const { return device_; }
150
151 // --- Image lifecycle --------------------------------------------------
152
154 VkImageDesc CreateImage(std::uint32_t width,
155 std::uint32_t height,
156 VkFormat vk_format,
157 VkImageUsageFlags usage,
158 const char* label = nullptr);
159
160 bool SupportsOptimalStorageImage(VkFormat vk_format) const;
161
163 void DestroyImage(VkImageDesc& desc);
164
165 // --- Vulkan device memory type helpers --------------------------------
166
170 std::uint32_t FindMemoryType(std::uint32_t type_filter,
171 VkMemoryPropertyFlags props) const;
172
173private:
174 GaussianSplatVulkanContext() = default;
176
179 delete;
180
181 // --- State ------------------------------------------------------------
182 bool initialized_ = false;
183 bool debug_utils_enabled_ = false;
184 std::string last_error_;
185
186 // Queue indices within the graphics queue family; index 0 = GS compute.
187 std::uint32_t graphics_queue_family_ = UINT32_MAX;
188 std::uint32_t filament_queue_index_ = 1;
189
190 // Shared-context record held alive for Filament's lifetime.
191 FilamentVulkanSharedContext shared_context_{};
192
193 // RAII handles. Destruction order is reverse of declaration order:
194 // compute_queue_ → device_ → physical_device_ → instance_ → context_.
195 vk::raii::Context context_;
196 vk::raii::Instance instance_{nullptr};
197 vk::raii::PhysicalDevice physical_device_{nullptr};
198 vk::raii::Device device_{nullptr};
199 vk::raii::Queue compute_queue_{nullptr};
200
201 VkPhysicalDeviceMemoryProperties memory_props_{};
202};
203
204} // namespace rendering
205} // namespace visualization
206} // namespace open3d
207
208#endif // !defined(__APPLE__)
Definition GaussianSplatVulkanContext.h:92
bool Initialize()
Definition GaussianSplatVulkanContext.cpp:187
VkDevice GetDevice() const
Definition GaussianSplatVulkanContext.h:131
VkPhysicalDevice GetPhysicalDevice() const
Definition GaussianSplatVulkanContext.h:134
VkQueue GetComputeQueue() const
Compute queue at index 0 in the graphics family. Used for GS dispatch.
Definition GaussianSplatVulkanContext.h:138
std::uint32_t FindMemoryType(std::uint32_t type_filter, VkMemoryPropertyFlags props) const
Definition GaussianSplatVulkanContext.cpp:356
bool IsValid() const
Definition GaussianSplatVulkanContext.h:112
void Shutdown()
Definition GaussianSplatVulkanContext.cpp:333
const vk::raii::Device & GetRaiiDevice() const
Definition GaussianSplatVulkanContext.h:149
std::uint32_t GetComputeQueueFamily() const
Definition GaussianSplatVulkanContext.h:141
const std::string & GetLastError() const
Human-readable description of the last failure.
Definition GaussianSplatVulkanContext.h:118
void * GetVulkanSharedContext()
Definition GaussianSplatVulkanContext.h:124
bool GetDebugUtilsEnabled() const
Definition GaussianSplatVulkanContext.h:146
static GaussianSplatVulkanContext & GetInstance()
Definition GaussianSplatVulkanContext.cpp:173
VkInstance GetVkInstance() const
Definition GaussianSplatVulkanContext.h:128
bool IsSoftwareDevice() const
True when the selected device is a CPU/software Vulkan implementation.
Definition GaussianSplatVulkanContext.cpp:327
VkImageDesc CreateImage(std::uint32_t width, std::uint32_t height, VkFormat vk_format, VkImageUsageFlags usage, const char *label=nullptr)
Allocate a VkImage for sharing with Filament.
Definition GaussianSplatVulkanContext.cpp:380
bool SupportsOptimalStorageImage(VkFormat vk_format) const
Definition GaussianSplatVulkanContext.cpp:367
void DestroyImage(VkImageDesc &desc)
Destroy an image previously created by CreateImage().
Definition GaussianSplatVulkanContext.cpp:424
int width
Definition FilePCD.cpp:53
int height
Definition FilePCD.cpp:54
Definition PinholeCameraIntrinsic.cpp:16
Definition GaussianSplatVulkanContext.h:64
std::uint32_t graphics_queue_family_index
Definition GaussianSplatVulkanContext.h:68
bool debug_markers_supported
Definition GaussianSplatVulkanContext.h:71
VkDevice logical_device
Definition GaussianSplatVulkanContext.h:67
std::uint32_t graphics_queue_index
Definition GaussianSplatVulkanContext.h:69
VkPhysicalDevice physical_device
Definition GaussianSplatVulkanContext.h:66
bool debug_utils_enabled
Definition GaussianSplatVulkanContext.h:70
bool multiview_supported
Definition GaussianSplatVulkanContext.h:72
VkInstance instance
Definition GaussianSplatVulkanContext.h:65
Definition GaussianSplatVulkanContext.h:78
VkDeviceMemory vk_memory
Definition GaussianSplatVulkanContext.h:80
bool IsValid() const
Definition GaussianSplatVulkanContext.h:82
VkImage vk_image
Definition GaussianSplatVulkanContext.h:79