Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Jan 27, 2025
1 parent 4e6e554 commit 2f40efc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
12 changes: 10 additions & 2 deletions include/merian/vk/sync/semaphore_binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
#include "merian/vk/sync/semaphore.hpp"

namespace merian {

class BinarySemaphore;
using BinarySemaphoreHandle = std::shared_ptr<BinarySemaphore>;

class BinarySemaphore : public Semaphore {
public:
private:
BinarySemaphore(const ContextHandle& context)
: Semaphore(context, {vk::SemaphoreType::eBinary, 0}) {}

public:
static BinarySemaphoreHandle create(const ContextHandle& context) {
return std::shared_ptr<BinarySemaphore>(new BinarySemaphore(context));
}
};

using BinarySemaphoreHandle = std::shared_ptr<BinarySemaphore>;
} // namespace merian
14 changes: 12 additions & 2 deletions include/merian/vk/sync/semaphore_timeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
#include "merian/vk/sync/semaphore.hpp"

namespace merian {

class TimelineSemaphore;
using TimelineSemaphoreHandle = std::shared_ptr<TimelineSemaphore>;

class TimelineSemaphore : public Semaphore {
public:
private:
TimelineSemaphore(const ContextHandle& context, const uint64_t initial_value = 0);

public:
uint64_t get_counter_value() const;

// Waits until the semaphore holds a value that is >= the supplied value.
Expand All @@ -16,7 +21,12 @@ class TimelineSemaphore : public Semaphore {
bool wait(const uint64_t value, const uint64_t timeout_nanos = UINT64_MAX);

void signal(const uint64_t value);

public:
static TimelineSemaphoreHandle create(const ContextHandle& context,
const uint64_t initial_value = 0) {
return std::shared_ptr<TimelineSemaphore>(new TimelineSemaphore(context, initial_value));
}
};

using TimelineSemaphoreHandle = std::shared_ptr<TimelineSemaphore>;
} // namespace merian
40 changes: 40 additions & 0 deletions include/merian/vk/sync/sync_dispatcher.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include "merian/vk/sync/semaphore_timeline.hpp"

namespace merian {

/* A Dispatches callbacks after dependent on a semaphore value.
*
* The callbacks run on the contexts' thread pool.
*/
class SyncDispatcher {

public:
SyncDispatcher(const ContextHandle& context) : context(context), interrupt_semaphore(TimelineSemaphore::create(context)) {
dispatcher_thread = std::thread([](){
SPDLOG_DEBUG("dispatcher thread started");

SPDLOG_DEBUG("dispatcher thread quitting");

});


}

~SyncDispatcher() {
SPDLOG_DEBUG("stopping dispatcher thread.");
stop.store(true);
interrupt_semaphore->signal(interrupt_wait_value);
dispatcher_thread.join();
}

private:
const ContextHandle context;
const TimelineSemaphoreHandle interrupt_semaphore;
std::thread dispatcher_thread;
std::atomic_bool stop = false;
std::atomic<uint64_t> interrupt_wait_value = 1;
};

} // namespace merian
4 changes: 2 additions & 2 deletions src/merian/vk/window/swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ vk::Extent2D Swapchain::create_swapchain(const uint32_t width, const uint32_t he
for (std::size_t i = 0; i < info->images.size(); i++) {
SyncGroup& sync_group = sync_groups[i];

sync_group.read_semaphore = std::make_shared<BinarySemaphore>(context);
sync_group.written_semaphore = std::make_shared<BinarySemaphore>(context);
sync_group.read_semaphore = BinarySemaphore::create(context);
sync_group.written_semaphore = BinarySemaphore::create(context);
sync_group.acquire_finished = Fence::create(context);
}

Expand Down

0 comments on commit 2f40efc

Please sign in to comment.