File src/compute/compute.cpp changed (mode: 100644) (index ec0e748..11623f5) |
... |
... |
create_bindings(BindingCreateInfos infos, BindingBuffer *p_dst) { |
33 |
33 |
res = p_dst[i].init(p_device, infos[i]); |
res = p_dst[i].init(p_device, infos[i]); |
34 |
34 |
if (res != VK_SUCCESS) { |
if (res != VK_SUCCESS) { |
35 |
35 |
while (i > 0) |
while (i > 0) |
36 |
|
p_dst->destroy(p_device); |
|
|
36 |
|
p_dst[i].destroy(p_device); |
37 |
37 |
return res; |
return res; |
38 |
38 |
} |
} |
39 |
39 |
} |
} |
|
... |
... |
create_bindings(BindingCreateInfos infos, VkFormat *p_formats, |
44 |
44 |
BindingBufferView *p_dst) { |
BindingBufferView *p_dst) { |
45 |
45 |
Result res; |
Result res; |
46 |
46 |
for (uint32_t i = 0; i < infos.count32(); ++i) { |
for (uint32_t i = 0; i < infos.count32(); ++i) { |
47 |
|
res = p_dst->init(p_device, infos[i], p_formats[i]); |
|
|
47 |
|
res = p_dst[i].init(p_device, infos[i], p_formats[i]); |
48 |
48 |
if (res != VK_SUCCESS) { |
if (res != VK_SUCCESS) { |
49 |
49 |
while (i > 0) |
while (i > 0) |
50 |
|
p_dst->destroy(p_device); |
|
|
50 |
|
p_dst[i].destroy(p_device); |
|
51 |
|
return res; |
|
52 |
|
} |
|
53 |
|
} |
|
54 |
|
return VK_SUCCESS; |
|
55 |
|
} |
|
56 |
|
|
|
57 |
|
[[nodiscard]] jen::vk::Result jen::vk::ModuleCompute:: |
|
58 |
|
create_images(ImageCreateInfos infos, Image *p_dst) { |
|
59 |
|
Result res; |
|
60 |
|
for (uint32_t i = 0; i < infos.count32(); ++i) { |
|
61 |
|
res = p_dst[i].init(p_device, infos[i]); |
|
62 |
|
if (res != VK_SUCCESS) { |
|
63 |
|
while (i > 0) |
|
64 |
|
p_dst[i].destroy(p_device); |
51 |
65 |
return res; |
return res; |
52 |
66 |
} |
} |
53 |
67 |
} |
} |
|
... |
... |
create_bindingSet(const ComputePipeline &pipeline, const Bindings &bindings, |
60 |
74 |
} |
} |
61 |
75 |
|
|
62 |
76 |
void check_transfer(const jen::vk::DeviceBufferPart &part, |
void check_transfer(const jen::vk::DeviceBufferPart &part, |
63 |
|
const jen::vk::BufferTransfer &info) { |
|
64 |
|
jassert(info.offset + info.size <= part.size(), |
|
65 |
|
"region exceeds buffer"); |
|
|
77 |
|
vkw::DeviceSize offset, vkw::DeviceSize size) { |
|
78 |
|
jassert(offset + size <= part.size(), "region exceeds buffer"); |
66 |
79 |
jassert(part.is_mapped(), "cannot access memory"); |
jassert(part.is_mapped(), "cannot access memory"); |
67 |
80 |
jassert(not part.is_flush_needed(), "flush not supported"); |
jassert(not part.is_flush_needed(), "flush not supported"); |
68 |
81 |
} |
} |
69 |
82 |
|
|
70 |
83 |
void |
void |
71 |
|
write_to_allocation(jen::vk::DeviceBufferPart *p_part, |
|
72 |
|
const jen::vk::BufferTransfer &info) { |
|
73 |
|
check_transfer(*p_part, info); |
|
74 |
|
memcpy(p_part->p_data() + info.offset, info.p_data, info.size); |
|
|
84 |
|
write_to_allocation(void *p_src, jen::vk::DeviceBufferPart *p_dst, |
|
85 |
|
vkw::DeviceSize dst_offset, vkw::DeviceSize size) { |
|
86 |
|
check_transfer(*p_dst, dst_offset, size); |
|
87 |
|
memcpy(p_dst->p_data() + dst_offset, p_src, size); |
75 |
88 |
} |
} |
76 |
89 |
|
|
77 |
90 |
void |
void |
78 |
|
read_from_allocation(const jen::vk::DeviceBufferPart &part, |
|
79 |
|
const jen::vk::BufferTransfer &info) { |
|
80 |
|
check_transfer(part, info); |
|
81 |
|
memcpy(info.p_data, part.p_data() + info.offset, info.size); |
|
|
91 |
|
read_from_allocation(jen::vk::DeviceBufferPart *p_src, void *p_dst, |
|
92 |
|
vkw::DeviceSize src_offset, vkw::DeviceSize size) { |
|
93 |
|
check_transfer(*p_src, src_offset, size); |
|
94 |
|
memcpy(p_dst, p_src->p_data() + src_offset, size); |
82 |
95 |
} |
} |
83 |
96 |
|
|
84 |
97 |
[[nodiscard]] jen::vk::Result |
[[nodiscard]] jen::vk::Result |
85 |
|
proceed_writes(jen::vk::Device *p_device, |
|
86 |
|
jen::vk::ComputeCmdUnit *p_cmdUnit, |
|
87 |
|
const jen::vk::Transfers &writes) |
|
|
98 |
|
proceed_writes(jen::vk::Device *p_device, |
|
99 |
|
jen::vk::ComputeCmdUnit *p_cmdUnit, |
|
100 |
|
jen::vk::BufferTransfers buffer_writes, |
|
101 |
|
jen::vk::ImagesTransfers images_writes) |
88 |
102 |
{ |
{ |
89 |
|
for (uint32_t i = 0; i < writes.count; ++i) { |
|
90 |
|
auto &write = writes.p[i]; |
|
|
103 |
|
auto &cmd = p_cmdUnit->transfer_cmds.primary[0]; |
|
104 |
|
|
|
105 |
|
auto begin = [&cmd, &p_cmdUnit]() -> jen::vk::Result { |
|
106 |
|
if (not p_cmdUnit->wait_transfer_write) { |
|
107 |
|
jen::vk::Result res; |
|
108 |
|
res = cmd.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
|
109 |
|
if (res != VK_SUCCESS) |
|
110 |
|
return res; |
|
111 |
|
p_cmdUnit->wait_transfer_write = true; |
|
112 |
|
} |
|
113 |
|
return VK_SUCCESS; |
|
114 |
|
}; |
|
115 |
|
|
|
116 |
|
for (uint32_t i = 0; i < buffer_writes.count(); ++i) { |
|
117 |
|
auto &write = buffer_writes[i]; |
91 |
118 |
auto &buffer = *write.p_buffer; |
auto &buffer = *write.p_buffer; |
92 |
119 |
|
|
93 |
120 |
jen::vk::DeviceBufferPart *p_part; |
jen::vk::DeviceBufferPart *p_part; |
|
... |
... |
proceed_writes(jen::vk::Device *p_device, |
96 |
123 |
else |
else |
97 |
124 |
p_part = &buffer.part; |
p_part = &buffer.part; |
98 |
125 |
|
|
99 |
|
write_to_allocation(p_part, write); |
|
|
126 |
|
write_to_allocation(write.p_data, p_part, write.offset, write.size); |
100 |
127 |
|
|
101 |
128 |
if (buffer.use_staging) { |
if (buffer.use_staging) { |
102 |
129 |
vkw::BufferChange bs; |
vkw::BufferChange bs; |
|
... |
... |
proceed_writes(jen::vk::Device *p_device, |
106 |
133 |
region.offsets.src = buffer.staging.offset(); |
region.offsets.src = buffer.staging.offset(); |
107 |
134 |
region.offsets.dst = buffer.part.offset(); |
region.offsets.dst = buffer.part.offset(); |
108 |
135 |
region.size = write.size; |
region.size = write.size; |
109 |
|
if (not p_cmdUnit->wait_transfer_write) { |
|
110 |
|
jen::vk::Result res; |
|
111 |
|
res = p_cmdUnit->transfer_cmds.primary[0] |
|
112 |
|
.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
|
113 |
|
if (res != VK_SUCCESS) |
|
114 |
|
return res; |
|
115 |
|
p_cmdUnit->wait_transfer_write = true; |
|
|
136 |
|
auto res = begin(); |
|
137 |
|
if (res != VK_SUCCESS) |
|
138 |
|
return res; |
|
139 |
|
cmd.cmd_cp_buffer(bs, region); |
|
140 |
|
} |
|
141 |
|
} |
|
142 |
|
|
|
143 |
|
for (uint32_t i = 0; i < images_writes.count(); ++i) { |
|
144 |
|
auto res = begin(); |
|
145 |
|
if (res != VK_SUCCESS) |
|
146 |
|
return res; |
|
147 |
|
|
|
148 |
|
auto &w = images_writes[i]; |
|
149 |
|
auto &im = *w.p_image; |
|
150 |
|
|
|
151 |
|
if (im.layout != vkw::ImLayout::TRANSFER_DST) { |
|
152 |
|
vkw::StageMaskChange stages; |
|
153 |
|
stages.src = vkw::StageFlag::TOP_OF_PIPE; |
|
154 |
|
stages.dst = vkw::StageFlag::TRANSFER; |
|
155 |
|
im.transitionLayout(&cmd, vkw::ImLayout::TRANSFER_DST, stages); |
|
156 |
|
} |
|
157 |
|
|
|
158 |
|
vkw::DeviceSize offset = 0; |
|
159 |
|
for (auto &r : w.transfers) { |
|
160 |
|
auto size = r.extent.volume() * vkw::format_size(im.format) |
|
161 |
|
* r.layer_count; |
|
162 |
|
write_to_allocation(r.p_data, &im.staging, offset, size); |
|
163 |
|
|
|
164 |
|
vkw::BufferAndImageRegion region; { |
|
165 |
|
region.bufferOffset = im.staging.offset() + offset; |
|
166 |
|
region.bufferRowLength = region.bufferImageHeight = 0; |
|
167 |
|
region.imageSubresource = { |
|
168 |
|
vkw::ImAspect::COLOR, |
|
169 |
|
r.mip_level, |
|
170 |
|
r.layer_offset, |
|
171 |
|
r.layer_count |
|
172 |
|
}; |
|
173 |
|
region.imageOffset.x = int32_t(r.offset.x); |
|
174 |
|
region.imageOffset.y = int32_t(r.offset.y); |
|
175 |
|
region.imageOffset.z = int32_t(r.offset.z); |
|
176 |
|
region.imageExtent.width = r.extent.x; |
|
177 |
|
region.imageExtent.height = r.extent.y; |
|
178 |
|
region.imageExtent.depth = r.extent.z; |
116 |
179 |
} |
} |
117 |
|
p_cmdUnit->transfer_cmds.primary[0].cmd_cp_buffer(bs, region); |
|
|
180 |
|
cmd.cmd_cp_buffer_to_image({im.staging.buffer, im.image.image}, |
|
181 |
|
region, vkw::ImLayout::TRANSFER_DST); |
|
182 |
|
|
|
183 |
|
offset += size; |
118 |
184 |
} |
} |
119 |
185 |
} |
} |
120 |
186 |
|
|
121 |
187 |
if (p_cmdUnit->wait_transfer_write) { |
if (p_cmdUnit->wait_transfer_write) { |
122 |
188 |
jen::vk::Result res; |
jen::vk::Result res; |
123 |
|
res = p_cmdUnit->transfer_cmds.primary[0].end(); |
|
|
189 |
|
res = cmd.end(); |
124 |
190 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
125 |
191 |
return res; |
return res; |
126 |
192 |
vkw::QueueSignal signal(p_cmdUnit->syncs.semaphores[0].p_vk); |
vkw::QueueSignal signal(p_cmdUnit->syncs.semaphores[0].p_vk); |
127 |
|
vkw::QueueSubmit submit(p_cmdUnit->transfer_cmds.primary[0], {}, signal); |
|
128 |
|
return p_device->queues.transfer.submit_locked(submit); |
|
|
193 |
|
vkw::QueueSubmit submit(cmd, {}, signal); |
|
194 |
|
res = p_device->queues.transfer.submit_locked(submit); |
|
195 |
|
if (res != VK_SUCCESS) |
|
196 |
|
return res; |
|
197 |
|
|
|
198 |
|
for (uint32_t i = 0; i < images_writes.count(); ++i) |
|
199 |
|
images_writes[i].p_image->layout = vkw::ImLayout::TRANSFER_DST; |
129 |
200 |
} |
} |
130 |
201 |
|
|
131 |
202 |
return VK_SUCCESS; |
return VK_SUCCESS; |
|
... |
... |
proceed_writes(jen::vk::Device *p_device, |
134 |
205 |
[[nodiscard]] jen::vk::Result |
[[nodiscard]] jen::vk::Result |
135 |
206 |
proceed_staging_reads(jen::vk::Device *p_device, |
proceed_staging_reads(jen::vk::Device *p_device, |
136 |
207 |
jen::vk::ComputeCmdUnit *p_cmdUnit, |
jen::vk::ComputeCmdUnit *p_cmdUnit, |
137 |
|
const jen::vk::Transfers &reads) { |
|
138 |
|
for (uint32_t i = 0; i < reads.count; ++i) { |
|
139 |
|
auto &read = reads.p[i]; |
|
|
208 |
|
jen::vk::BufferTransfers buffer_reads, |
|
209 |
|
jen::vk::ImagesTransfers images_reads) |
|
210 |
|
{ |
|
211 |
|
auto &cmd = p_cmdUnit->transfer_cmds.primary[1]; |
|
212 |
|
auto begin = [&cmd, &p_cmdUnit]() -> jen::vk::Result { |
|
213 |
|
if (not p_cmdUnit->wait_transfer_read) { |
|
214 |
|
jen::vk::Result res; |
|
215 |
|
res = cmd.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
|
216 |
|
if (res != VK_SUCCESS) |
|
217 |
|
return res; |
|
218 |
|
p_cmdUnit->wait_transfer_read = true; |
|
219 |
|
} |
|
220 |
|
return VK_SUCCESS; |
|
221 |
|
}; |
|
222 |
|
|
|
223 |
|
for (uint32_t i = 0; i < buffer_reads.count(); ++i) { |
|
224 |
|
auto &read = buffer_reads[i]; |
140 |
225 |
auto &buffer = *read.p_buffer; |
auto &buffer = *read.p_buffer; |
141 |
226 |
|
|
142 |
227 |
if (buffer.use_staging) { |
if (buffer.use_staging) { |
|
... |
... |
proceed_staging_reads(jen::vk::Device *p_device, |
147 |
232 |
region.offsets.src = buffer.part.offset(); |
region.offsets.src = buffer.part.offset(); |
148 |
233 |
region.offsets.dst = buffer.staging.offset(); |
region.offsets.dst = buffer.staging.offset(); |
149 |
234 |
region.size = read.size; |
region.size = read.size; |
150 |
|
if (not p_cmdUnit->wait_transfer_read) { |
|
151 |
|
jen::vk::Result res; |
|
152 |
|
res = p_cmdUnit->transfer_cmds.primary[1] |
|
153 |
|
.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
|
154 |
|
if (res != VK_SUCCESS) |
|
155 |
|
return res; |
|
156 |
|
p_cmdUnit->wait_transfer_read = true; |
|
|
235 |
|
auto res = begin(); |
|
236 |
|
if (res != VK_SUCCESS) |
|
237 |
|
return res; |
|
238 |
|
cmd.cmd_cp_buffer(bs, region); |
|
239 |
|
} |
|
240 |
|
} |
|
241 |
|
|
|
242 |
|
for (uint32_t i = 0; i < images_reads.count(); ++i) { |
|
243 |
|
auto res = begin(); |
|
244 |
|
if (res != VK_SUCCESS) |
|
245 |
|
return res; |
|
246 |
|
|
|
247 |
|
auto &w = images_reads[i]; |
|
248 |
|
auto &im = *w.p_image; |
|
249 |
|
|
|
250 |
|
if (im.layout != vkw::ImLayout::TRANSFER_SRC) { |
|
251 |
|
vkw::StageMaskChange stages; |
|
252 |
|
stages.src = vkw::StageFlag::TOP_OF_PIPE; |
|
253 |
|
stages.dst = vkw::StageFlag::TRANSFER; |
|
254 |
|
im.transitionLayout(&cmd, vkw::ImLayout::TRANSFER_SRC, stages); |
|
255 |
|
} |
|
256 |
|
|
|
257 |
|
vkw::DeviceSize offset = 0; |
|
258 |
|
for (auto &r : w.transfers) { |
|
259 |
|
vkw::BufferAndImageRegion region; { |
|
260 |
|
region.bufferOffset = im.staging.offset() + offset; |
|
261 |
|
region.bufferRowLength = region.bufferImageHeight = 0; |
|
262 |
|
region.imageSubresource = { |
|
263 |
|
vkw::ImAspect::COLOR, |
|
264 |
|
r.mip_level, |
|
265 |
|
r.layer_offset, |
|
266 |
|
r.layer_count |
|
267 |
|
}; |
|
268 |
|
region.imageOffset.x = int32_t(r.offset.x); |
|
269 |
|
region.imageOffset.y = int32_t(r.offset.y); |
|
270 |
|
region.imageOffset.z = int32_t(r.offset.z); |
|
271 |
|
region.imageExtent.width = r.extent.x; |
|
272 |
|
region.imageExtent.height = r.extent.y; |
|
273 |
|
region.imageExtent.depth = r.extent.z; |
157 |
274 |
} |
} |
158 |
|
p_cmdUnit->transfer_cmds.primary[1].cmd_cp_buffer(bs, region); |
|
|
275 |
|
cmd.cmd_cp_image_to_buffer({im.image.image, im.staging.buffer}, |
|
276 |
|
region, vkw::ImLayout::TRANSFER_SRC); |
|
277 |
|
|
|
278 |
|
offset += r.extent.volume() * vkw::format_size(im.format) * r.layer_count; |
159 |
279 |
} |
} |
160 |
280 |
} |
} |
161 |
281 |
|
|
|
... |
... |
proceed_staging_reads(jen::vk::Device *p_device, |
168 |
288 |
vkw::QueueWait wait; |
vkw::QueueWait wait; |
169 |
289 |
wait.semaphores = p_cmdUnit->syncs.semaphores[1].p_vk; |
wait.semaphores = p_cmdUnit->syncs.semaphores[1].p_vk; |
170 |
290 |
wait.stage_masks = vkw::StageFlag::COMPUTE_SHADER; |
wait.stage_masks = vkw::StageFlag::COMPUTE_SHADER; |
171 |
|
vkw::QueueSubmit submit(p_cmdUnit->transfer_cmds.primary[1], wait); |
|
172 |
|
return p_device->queues.transfer |
|
173 |
|
.submit_locked(submit, p_cmdUnit->syncs.fences[1]); |
|
|
291 |
|
vkw::QueueSubmit submit(cmd, wait); |
|
292 |
|
res = p_device->queues.transfer |
|
293 |
|
.submit_locked(submit, p_cmdUnit->syncs.fences[1]); |
|
294 |
|
if (res != VK_SUCCESS) |
|
295 |
|
return res; |
|
296 |
|
|
|
297 |
|
for (uint32_t i = 0; i < images_reads.count(); ++i) |
|
298 |
|
images_reads[i].p_image->layout = vkw::ImLayout::TRANSFER_SRC; |
174 |
299 |
} |
} |
175 |
300 |
|
|
176 |
301 |
return VK_SUCCESS; |
return VK_SUCCESS; |
|
... |
... |
compute(const ComputeInfo &info) |
238 |
363 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
239 |
364 |
return res; |
return res; |
240 |
365 |
|
|
241 |
|
res = proceed_writes(p_device, info.p_cmdUnit, info.writes); |
|
|
366 |
|
res = proceed_writes(p_device, info.p_cmdUnit, |
|
367 |
|
info.buffer_writes, info.images_writes); |
242 |
368 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
243 |
369 |
return res; |
return res; |
244 |
370 |
|
|
|
... |
... |
compute(const ComputeInfo &info) |
252 |
378 |
res = cmd.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
res = cmd.begin(vkw::CmdUsage::ONE_TIME_SUBMIT); |
253 |
379 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
254 |
380 |
return res; |
return res; |
|
381 |
|
|
|
382 |
|
for (auto &im : info.p_bindings->storage_image) { |
|
383 |
|
auto l = vkw::ImLayout::GENERAL; |
|
384 |
|
if (im.p_image->layout == l) |
|
385 |
|
continue; |
|
386 |
|
vkw::StageMaskChange stages; |
|
387 |
|
stages.src = vkw::StageFlag::TOP_OF_PIPE; |
|
388 |
|
stages.dst = vkw::StageFlag::COMPUTE_SHADER; |
|
389 |
|
im.p_image->transitionLayout(&cmd, l, stages); |
|
390 |
|
} |
|
391 |
|
|
255 |
392 |
cmd.cmd_set_pipeline(pipeline, vkw::BindPoint::COMPUTE); |
cmd.cmd_set_pipeline(pipeline, vkw::BindPoint::COMPUTE); |
256 |
393 |
|
|
257 |
394 |
cmd.cmd_set_descr_sets(vkw::BindPoint::COMPUTE, pipelineLayout, set, 0); |
cmd.cmd_set_descr_sets(vkw::BindPoint::COMPUTE, pipelineLayout, set, 0); |
|
... |
... |
compute(const ComputeInfo &info) |
262 |
399 |
return res; |
return res; |
263 |
400 |
|
|
264 |
401 |
bool use_read_semaphore = false; |
bool use_read_semaphore = false; |
265 |
|
for (uint32_t i = 0; i < info.reads.count; ++i) { |
|
266 |
|
if (info.reads.p[i].p_buffer->use_staging) { |
|
|
402 |
|
if (info.images_reads.count() > 0) |
|
403 |
|
use_read_semaphore = true; |
|
404 |
|
else for (uint32_t i = 0; i < info.buffer_reads.count(); ++i) { |
|
405 |
|
if (info.buffer_reads[i].p_buffer->use_staging) { |
267 |
406 |
use_read_semaphore = true; |
use_read_semaphore = true; |
268 |
407 |
break; |
break; |
269 |
408 |
} |
} |
270 |
409 |
} |
} |
|
410 |
|
|
271 |
411 |
vkw::QueueWait wait; |
vkw::QueueWait wait; |
272 |
412 |
if (info.p_cmdUnit->wait_transfer_write) { |
if (info.p_cmdUnit->wait_transfer_write) { |
273 |
413 |
wait.semaphores = syncs.semaphores[0].p_vk; |
wait.semaphores = syncs.semaphores[0].p_vk; |
|
... |
... |
compute(const ComputeInfo &info) |
285 |
425 |
res = p_device->queues.compute.submit_locked(submit, syncs.fences[0]); |
res = p_device->queues.compute.submit_locked(submit, syncs.fences[0]); |
286 |
426 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
287 |
427 |
return res; |
return res; |
|
428 |
|
|
|
429 |
|
for (auto &im : info.p_bindings->storage_image) { |
|
430 |
|
auto l = vkw::ImLayout::GENERAL; |
|
431 |
|
im.p_image->layout = l; |
|
432 |
|
} |
|
433 |
|
|
288 |
434 |
info.p_cmdUnit->wait_compute = true; |
info.p_cmdUnit->wait_compute = true; |
289 |
435 |
|
|
290 |
|
res = proceed_staging_reads(p_device, info.p_cmdUnit, info.reads); |
|
|
436 |
|
res = proceed_staging_reads(p_device, info.p_cmdUnit, |
|
437 |
|
info.buffer_reads, info.images_reads); |
291 |
438 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
292 |
439 |
return res; |
return res; |
293 |
440 |
|
|
|
... |
... |
compute(const ComputeInfo &info) |
295 |
442 |
} |
} |
296 |
443 |
|
|
297 |
444 |
[[nodiscard]] jen::vk::Result jen::vk::ModuleCompute:: |
[[nodiscard]] jen::vk::Result jen::vk::ModuleCompute:: |
298 |
|
read(ComputeCmdUnit *p_cmdUnit, jen::vk::Transfers reads) |
|
|
445 |
|
read(ComputeCmdUnit *p_cmdUnit, |
|
446 |
|
BufferTransfers buffer_reads, |
|
447 |
|
ImagesTransfers images_reads) |
299 |
448 |
{ |
{ |
300 |
449 |
Result res; |
Result res; |
301 |
450 |
res = wait_unit(p_device, p_cmdUnit); |
res = wait_unit(p_device, p_cmdUnit); |
302 |
451 |
if (res != VK_SUCCESS) |
if (res != VK_SUCCESS) |
303 |
452 |
return res; |
return res; |
304 |
453 |
|
|
305 |
|
for (uint32_t i = 0; i < reads.count; ++i) { |
|
306 |
|
auto &read = reads.p[i]; |
|
|
454 |
|
for (uint32_t i = 0; i < buffer_reads.count(); ++i) { |
|
455 |
|
auto &read = buffer_reads[i]; |
307 |
456 |
auto &buffer = *read.p_buffer; |
auto &buffer = *read.p_buffer; |
308 |
457 |
|
|
309 |
458 |
jen::vk::DeviceBufferPart *p_part; |
jen::vk::DeviceBufferPart *p_part; |
|
... |
... |
read(ComputeCmdUnit *p_cmdUnit, jen::vk::Transfers reads) |
312 |
461 |
else |
else |
313 |
462 |
p_part = &buffer.part; |
p_part = &buffer.part; |
314 |
463 |
|
|
315 |
|
read_from_allocation(*p_part, read); |
|
|
464 |
|
read_from_allocation(p_part, read.p_data, read.offset, read.size); |
316 |
465 |
} |
} |
|
466 |
|
|
|
467 |
|
for (uint32_t i = 0; i < images_reads.count(); ++i) { |
|
468 |
|
auto &read = images_reads[i]; |
|
469 |
|
auto &im = *read.p_image; |
|
470 |
|
auto p_part = &im.staging; |
|
471 |
|
|
|
472 |
|
vkw::DeviceSize offset = 0; |
|
473 |
|
for (auto &r : read.transfers) { |
|
474 |
|
auto size = r.extent.volume() * vkw::format_size(im.format) |
|
475 |
|
* r.layer_count; |
|
476 |
|
read_from_allocation(p_part, r.p_data, offset, size); |
|
477 |
|
offset += size; |
|
478 |
|
} |
|
479 |
|
} |
|
480 |
|
|
317 |
481 |
return VK_SUCCESS; |
return VK_SUCCESS; |
318 |
482 |
} |
} |
319 |
483 |
|
|
|
... |
... |
destroy_bindings(BindingBufferView *p_bs, uint32_t count) { |
337 |
501 |
p_bs[i].destroy(p_device); |
p_bs[i].destroy(p_device); |
338 |
502 |
} |
} |
339 |
503 |
void jen::vk::ModuleCompute:: |
void jen::vk::ModuleCompute:: |
|
504 |
|
destroy_images(Image *p_ims, uint32_t count) { |
|
505 |
|
for (uint32_t i = 0; i < count; ++i) |
|
506 |
|
p_ims[i].destroy(p_device); |
|
507 |
|
} |
|
508 |
|
void jen::vk::ModuleCompute:: |
340 |
509 |
destroy_pipeline(ComputePipeline *p_pl) { |
destroy_pipeline(ComputePipeline *p_pl) { |
341 |
510 |
p_pl->destroy(p_device->device); |
p_pl->destroy(p_device->device); |
342 |
511 |
} |
} |