File src/compute/cmd_unit.h added (mode: 100644) (index 0000000..15f3760) |
|
1 |
|
#pragma once |
|
2 |
|
|
|
3 |
|
#include "../device/cmd_container.h" |
|
4 |
|
|
|
5 |
|
namespace jen::vk |
|
6 |
|
{ |
|
7 |
|
struct ComputeCmdUnit { |
|
8 |
|
[[nodiscard]] Result init(Device *p_dev) { |
|
9 |
|
Result res; |
|
10 |
|
res = compute_cmds.init(*p_dev, p_dev->queue_indices.compute.family, |
|
11 |
|
vkw::CmdPoolFlag::MANUAL_CMD_RESET); |
|
12 |
|
if (res != VK_SUCCESS) |
|
13 |
|
return res; |
|
14 |
|
res = syncs.init(*p_dev); |
|
15 |
|
if (res != VK_SUCCESS) { |
|
16 |
|
compute_cmds.destroy(*p_dev); |
|
17 |
|
return res; |
|
18 |
|
} |
|
19 |
|
return VK_SUCCESS; |
|
20 |
|
} |
|
21 |
|
void destroy(Device *p_dev) { |
|
22 |
|
compute_cmds.destroy(*p_dev); |
|
23 |
|
syncs.destroy(*p_dev); |
|
24 |
|
} |
|
25 |
|
|
|
26 |
|
struct SyncCounts : SyncContainerCounts { |
|
27 |
|
constexpr static const uint32_t FENCES = 1; |
|
28 |
|
}; |
|
29 |
|
struct SyncValues : SyncContainerValues<SyncCounts> { |
|
30 |
|
constexpr static const A<vkw::Fence::Mask, SyncCounts::FENCES> FENCES { |
|
31 |
|
vkw::Fence::Flag::SIGNALED |
|
32 |
|
}; |
|
33 |
|
}; |
|
34 |
|
|
|
35 |
|
constexpr static const uint32_t PRIMARY_CMD_COUNT = 1; |
|
36 |
|
constexpr static const uint32_t FENCE_S_COUNT = 1; |
|
37 |
|
CmdPoolContainer<PRIMARY_CMD_COUNT, 0> compute_cmds; |
|
38 |
|
SyncContainer<SyncCounts, SyncValues> syncs; |
|
39 |
|
}; |
|
40 |
|
} |
File src/compute/compute.h changed (mode: 100644) (index 1e8af63..2148214) |
2 |
2 |
|
|
3 |
3 |
#include "binding_set.h" |
#include "binding_set.h" |
4 |
4 |
#include "pipeline.h" |
#include "pipeline.h" |
5 |
|
#include "../device/cmd_container.h" |
|
|
5 |
|
#include "cmd_unit.h" |
6 |
6 |
|
|
7 |
7 |
namespace jen::vk |
namespace jen::vk |
8 |
8 |
{ |
{ |
9 |
9 |
struct ModuleCompute { |
struct ModuleCompute { |
10 |
10 |
[[nodiscard]] Result init(Device *p_dev) { |
[[nodiscard]] Result init(Device *p_dev) { |
11 |
|
Result res; |
|
12 |
|
res = compute_cmds.init(*p_dev, p_dev->queue_indices.compute.family, |
|
13 |
|
vkw::CmdPoolFlag::MANUAL_CMD_RESET); |
|
14 |
|
if (res != VK_SUCCESS) |
|
15 |
|
return res; |
|
16 |
|
res = syncs.init(*p_dev); |
|
17 |
|
if (res != VK_SUCCESS) { |
|
18 |
|
compute_cmds.destroy(*p_dev); |
|
19 |
|
return res; |
|
20 |
|
} |
|
21 |
11 |
p_device = p_dev; |
p_device = p_dev; |
22 |
|
return VK_SUCCESS; |
|
|
12 |
|
return cmd_unit.init(p_dev); |
23 |
13 |
} |
} |
24 |
14 |
void destroy() { |
void destroy() { |
25 |
|
compute_cmds.destroy(*p_device); |
|
26 |
|
syncs.destroy(*p_device); |
|
|
15 |
|
cmd_unit.destroy(p_device); |
27 |
16 |
} |
} |
28 |
17 |
[[nodiscard]] Result |
[[nodiscard]] Result |
29 |
18 |
create_pipeline(const Bindings &bi, const char *p_shader_file_path, |
create_pipeline(const Bindings &bi, const char *p_shader_file_path, |
|
... |
... |
namespace jen::vk |
67 |
56 |
math::v3u32 group_count) |
math::v3u32 group_count) |
68 |
57 |
{ |
{ |
69 |
58 |
Result res; |
Result res; |
70 |
|
res = syncs.fences[0].wait_and_reset(*p_device, vkw::TIMEOUT_INFINITE); |
|
|
59 |
|
res = cmd_unit.syncs |
|
60 |
|
.fences[0].wait_and_reset(*p_device, vkw::TIMEOUT_INFINITE); |
71 |
61 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
72 |
62 |
return res; |
return res; |
73 |
63 |
|
|
74 |
|
auto &cmd = compute_cmds.primary[0]; |
|
|
64 |
|
auto &cmd = cmd_unit.compute_cmds.primary[0]; |
75 |
65 |
res = cmd.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
res = cmd.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
76 |
66 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
77 |
67 |
return res; |
return res; |
|
... |
... |
namespace jen::vk |
85 |
75 |
return res; |
return res; |
86 |
76 |
|
|
87 |
77 |
vkw::QueueSubmit submit(cmd); |
vkw::QueueSubmit submit(cmd); |
88 |
|
return p_device->queues.compute.submit_locked(submit, syncs.fences[0]); |
|
|
78 |
|
return p_device->queues.compute |
|
79 |
|
.submit_locked(submit, cmd_unit.syncs.fences[0]); |
89 |
80 |
} |
} |
90 |
81 |
|
|
91 |
82 |
[[nodiscard]] Result |
[[nodiscard]] Result |
|
... |
... |
namespace jen::vk |
94 |
85 |
void *p_dst) { |
void *p_dst) { |
95 |
86 |
jassert(offset + size <= buffer.size(), "region exceeds buffer"); |
jassert(offset + size <= buffer.size(), "region exceeds buffer"); |
96 |
87 |
Result res; |
Result res; |
97 |
|
res = syncs.fences[0].wait(*p_device, vkw::TIMEOUT_INFINITE); |
|
|
88 |
|
res = cmd_unit.syncs.fences[0].wait(*p_device, vkw::TIMEOUT_INFINITE); |
98 |
89 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
99 |
90 |
return res; |
return res; |
100 |
91 |
jassert(buffer.is_mapped() and not buffer.is_flush_needed(), |
jassert(buffer.is_mapped() and not buffer.is_flush_needed(), |
|
... |
... |
namespace jen::vk |
117 |
108 |
p_pl->destroy(p_device->device); |
p_pl->destroy(p_device->device); |
118 |
109 |
} |
} |
119 |
110 |
|
|
120 |
|
struct SyncCounts : SyncContainerCounts { |
|
121 |
|
constexpr static const uint32_t FENCES = 1; |
|
122 |
|
}; |
|
123 |
|
struct SyncValues : SyncContainerValues<SyncCounts> { |
|
124 |
|
constexpr static const A<vkw::Fence::Mask, SyncCounts::FENCES> FENCES { |
|
125 |
|
vkw::Fence::Flag::SIGNALED |
|
126 |
|
}; |
|
127 |
|
}; |
|
128 |
|
|
|
129 |
|
constexpr static const uint32_t PRIMARY_CMD_COUNT = 1; |
|
130 |
|
constexpr static const uint32_t FENCE_S_COUNT = 1; |
|
131 |
|
CmdPoolContainer<PRIMARY_CMD_COUNT, 0> compute_cmds; |
|
132 |
|
SyncContainer<SyncCounts, SyncValues> syncs; |
|
133 |
|
Device *p_device; |
|
|
111 |
|
ComputeCmdUnit cmd_unit; |
|
112 |
|
Device *p_device; |
134 |
113 |
}; |
}; |
135 |
114 |
} |
} |