Skip to content

Commit

Permalink
add support for breaking cross-stream deps; fix usage bug in ex9
Browse files Browse the repository at this point in the history
  • Loading branch information
martty committed Feb 11, 2024
1 parent 0162ae3 commit 9085b4c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/09_persistent_descriptorset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace {
// Similarly to buffers, we allocate the image and enqueue the upload
texture_of_doge = vuk::ImageAttachment::from_preset(
vuk::ImageAttachment::Preset::eMap2D, vuk::Format::eR8G8B8A8Srgb, vuk::Extent3D{ (unsigned)x, (unsigned)y, 1u }, vuk::Samples::e1);
texture_of_doge.usage |= vuk::ImageUsageFlagBits::eTransferSrc;
texture_of_doge.level_count = 1;
auto [image, view, doge_src] = vuk::create_image_and_view_with_data(allocator, vuk::DomainFlagBits::eTransferOnTransfer, texture_of_doge, doge_image);
image_of_doge = std::move(image);
Expand Down
48 changes: 48 additions & 0 deletions src/ExecutableRenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ namespace vuk {
std::shared_ptr<RG> cg_module;

std::unordered_map<DomainFlagBits, std::unique_ptr<Stream>> streams;
std::unordered_map<void*, Stream*> pending_syncs;

// start recording if needed
// all dependant domains flushed
Expand Down Expand Up @@ -1108,6 +1109,7 @@ namespace vuk {
bool has_both = has_src && has_dst;
bool cross = has_both && (src_stream != dst_stream);
bool only_src = has_src && !has_dst;
bool only_dst = !has_src && has_dst;

if (cross) {
dst_stream->add_dependency(src_stream);
Expand All @@ -1116,17 +1118,41 @@ namespace vuk {
if (base_ty == cg_module->builtin_image) {
auto& img_att = *reinterpret_cast<ImageAttachment*>(value);
if (has_dst) {
if (only_dst) {
auto it = pending_syncs.find(value);
if (it != pending_syncs.end()) {
if (it->second != dst_stream) {
it->second->synch_image(img_att, src_use, dst_use, value);
}
pending_syncs.erase(it);
}
}
dst_stream->synch_image(img_att, src_use, dst_use, value);
}
if (only_src || cross) {
src_stream->synch_image(img_att, src_use, dst_use, value);
if (only_src) {
pending_syncs.emplace(value, src_stream);
}
}
} else if (base_ty == cg_module->builtin_buffer) {
// buffer needs no cross
if (has_dst) {
if (only_dst) {
auto it = pending_syncs.find(value);
if (it != pending_syncs.end()) {
if (it->second != dst_stream) {
it->second->synch_memory(src_use, dst_use, value);
}
pending_syncs.erase(it);
}
}
dst_stream->synch_memory(src_use, dst_use, value);
} else if (has_src) {
src_stream->synch_memory(src_use, dst_use, value);
if (only_src) {
pending_syncs.emplace(value, src_stream);
}
}
} else if (base_ty->kind == Type::ARRAY_TY) {
auto elem_ty = base_ty->array.T;
Expand All @@ -1135,20 +1161,42 @@ namespace vuk {
auto img_atts = reinterpret_cast<ImageAttachment*>(value);
for (int i = 0; i < size; i++) {
if (has_dst) {
if (only_dst) {
auto it = pending_syncs.find(value);
if (it != pending_syncs.end()) {
if (it->second != dst_stream) {
it->second->synch_image(img_atts[i], src_use, dst_use, value);
}
pending_syncs.erase(it);
}
}
dst_stream->synch_image(img_atts[i], src_use, dst_use, &img_atts[i]);
}
if (only_src || cross) {
src_stream->synch_image(img_atts[i], src_use, dst_use, &img_atts[i]);
if (only_src) {
pending_syncs.emplace(&img_atts[i], src_stream);
}
}
}
} else if (elem_ty == cg_module->builtin_buffer) {
for (int i = 0; i < size; i++) {
// buffer needs no cross
auto bufs = reinterpret_cast<Buffer*>(value);
if (has_dst) {
auto it = pending_syncs.find(value);
if (it != pending_syncs.end()) {
if (it->second != dst_stream) {
it->second->synch_memory(src_use, dst_use, &bufs[i]);
}
pending_syncs.erase(it);
}
dst_stream->synch_memory(src_use, dst_use, &bufs[i]);
} else if (has_src) {
src_stream->synch_memory(src_use, dst_use, &bufs[i]);
if (only_src) {
pending_syncs.emplace(&bufs[i], src_stream);
}
}
}
} else {
Expand Down

0 comments on commit 9085b4c

Please sign in to comment.