chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
11 / 36
30.6%
Branches:
1 / 18
5.6%
Functions:
2 / 8
25.0%

device/vulkan/native.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/device/vulkan/native.h"
3
4 #include "chrono_batch_render/device/buffer.h"
5 #include "chrono_batch_render/device/queue.h"
6 #include "chrono_batch_render/device/vulkan/device.h"
7 #include "chrono_batch_render/util/error.h"
8
9 namespace chrono::batch_render::device::vulkan {
10 namespace {
11
12 2 VulkanDevice& Checked(Device& device) {
13
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (device.Adapter().backend != Backend::Vulkan) {
14 ✗ throw UnsupportedError("{} is a {} device, not a Vulkan one", device.Adapter().alias,
15
0/2
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ BackendName(device.Adapter().backend));
16 }
17 2 return static_cast<VulkanDevice&>(device);
18 }
19
20 ✗ Queue& RoleQueue(VulkanDevice& vulkan, QueueRole role) {
21
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ return role == QueueRole::Display ? vulkan.DisplayQueue() : vulkan.GetQueue();
22 }
23
24 }
25
26 2 Native NativeHandles(Device& device) {
27 2 VulkanDevice& vulkan = Checked(device);
28 2 return {.getInstanceProcAddr = vkGetInstanceProcAddr,
29 2 .instance = vulkan.InstanceHandle(),
30 2 .physicalDevice = vulkan.PhysicalDevice(),
31 2 .device = vulkan.Handle(),
32 .apiVersion = VK_API_VERSION_1_3,
33 2 .queueFamily = vulkan.QueueFamily(),
34 2 .displaySharesRender = vulkan.SharesDisplayQueue()};
35 }
36
37 ✗ VkBuffer NativeBuffer(const Tensor& tensor) {
38
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (tensor.Empty()) {
39
0/2
✗ Branch 2 not taken.
✗ Branch 5 not taken.
✗ throw Error("an empty tensor has no Vulkan buffer");
40 }
41 ✗ Buffer& buffer = tensor.GetBuffer();
42 ✗ Checked(buffer.GetDevice());
43 ✗ return static_cast<VulkanBuffer&>(buffer).Handle();
44 }
45
46 ✗ Operation Submit(Device& device, const NativeSubmit& submit, QueueRole role) {
47 ✗ Queue& queue = RoleQueue(Checked(device), role);
48
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ for (const Operation& operation : submit.after) {
49 ✗ queue.Follow(operation);
50 }
51 ✗ return SubmitNative(queue, submit);
52 }
53
54 ✗ VkResult Present(Device& device, const VkPresentInfoKHR& present) {
55
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Queue& queue = Checked(device).DisplayQueue();
56
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (!device.Presents()) {
57 ✗ throw UnsupportedError("{} wasn't created with presentation, so it presents nothing",
58
0/1
✗ Branch 2 not taken.
✗ device.Adapter().alias);
59 }
60 ✗ return PresentNative(queue, present);
61 }
62
63 ✗ void Exclusive(Device& device, const std::function<void(VkQueue queue)>& use, QueueRole role) {
64 ✗ Queue& queue = RoleQueue(Checked(device), role);
65
0/1
✗ Branch 1 not taken.
✗ queue.Exclusive([&] { use(NativeQueue(queue)); });
66 ✗ }
67
68 }
69