TachyonUI 0.1.0
High-performance UI for building tools.
Loading...
Searching...
No Matches
vk_upload_worker.h
Go to the documentation of this file.
1#pragma once
2
3#include <condition_variable>
4#include <cstddef>
5#include <deque>
6#include <functional>
7#include <mutex>
8#include <thread>
9#include <vector>
10
11namespace tachyon::vulkan
12{
15
20 {
21 public:
23 static constexpr size_t kInlineBytes = 32 * 1024;
24
27 UploadWorker(const UploadWorker&) = delete;
29
32 void Copy(void* destination, const void* source, size_t size);
34 void Copy(void* destination, std::vector<std::byte>&& source);
37 void Then(std::function<void()> job);
39 void Wait();
41 bool Busy() const;
42
43 private:
44 struct Job
45 {
46 void* destination = nullptr;
47 const void* source = nullptr;
48 size_t size = 0;
49 std::vector<std::byte> owned;
50 std::function<void()> then;
51 };
52 void Push(Job&& job);
53 void Run();
54
55 mutable std::mutex m_mutex;
56 std::condition_variable m_wake;
57 std::condition_variable m_done;
58 std::deque<Job> m_jobs;
59 bool m_running = false;
60 bool m_stop = false;
61 std::thread m_thread;
62 };
63
64}
UploadWorker & operator=(const UploadWorker &)=delete
void Copy(void *destination, const void *source, size_t size)
Copies size bytes from source to destination; a null source zeroes them.
static constexpr size_t kInlineBytes
Copies this small run on the calling thread: handing them over costs more.
Definition vk_upload_worker.h:23
void Then(std::function< void()> job)
Runs job on the worker after every copy queued before it (flushing what they wrote),...
UploadWorker(const UploadWorker &)=delete
bool Busy() const
Whether anything queued isn't done yet.
void Wait()
Returns once every copy and job queued so far is done.
void Copy(void *destination, std::vector< std::byte > &&source)
As Copy, from bytes the worker keeps until it has copied them.
Definition vk_defaults.h:4