Skip to content

Commit 5b2baf0

Browse files
committed
Vulkan external device
1 parent b8a15d7 commit 5b2baf0

6 files changed

Lines changed: 182 additions & 131 deletions

File tree

include/luisa/backends/ext/vk_config_ext.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@ namespace luisa::compute {
88

99
class VulkanDeviceConfigExt : public DeviceConfigExt {
1010
public:
11+
struct ExternalDevice {
12+
VkInstance instance{};
13+
VkPhysicalDevice physical_device{};
14+
VkDevice device{};
15+
VkQueue graphics_queue{};
16+
VkQueue compute_queue{};
17+
VkQueue copy_queue{};
18+
};
1119
VulkanDeviceConfigExt() = default;
1220
~VulkanDeviceConfigExt() = default;
21+
[[nodiscard]] virtual ExternalDevice create_external_device() {
22+
return {};
23+
}
1324
[[nodiscard]] virtual bool enable_fallback() const {
1425
return false;
1526
}
27+
1628
virtual VkCommandBuffer borrow_command_buffer(
1729
StreamTag stream_tag) noexcept { return nullptr; }
1830
virtual bool execute_command_buffer(VkCommandBuffer cmd_buffer) noexcept { return false; }

src/backends/vk/VulkanDevice.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,17 @@ VkResult VulkanDevice::createLogicalDevice(VkPhysicalDeviceFeatures &enabledFeat
279279
}
280280

281281
this->enabledFeatures = enabledFeatures;
282+
if (!logicalDevice) {
283+
VkResult result = vkCreateDevice(physicalDevice, &deviceCreateInfo, lc::vk::Device::alloc_callbacks(), &logicalDevice);
284+
if (result != VK_SUCCESS) {
285+
return result;
286+
}
287+
288+
// Create a default command pool for graphics command buffers
282289

283-
VkResult result = vkCreateDevice(physicalDevice, &deviceCreateInfo, lc::vk::Device::alloc_callbacks(), &logicalDevice);
284-
if (result != VK_SUCCESS) {
285290
return result;
286291
}
287-
288-
// Create a default command pool for graphics command buffers
289-
290-
return result;
292+
return VK_SUCCESS;
291293
}
292294

293295
bool VulkanDevice::extensionSupported(vstd::string_view extension) {

0 commit comments

Comments
 (0)