Toast Engine
Loading...
Searching...
No Matches
vulkan_resource_base.hpp
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "vulkan_common.hpp"
8#include "vulkan_core.hpp"
9
10namespace renderer {
11
13public:
14 enum class UploadState : std::uint8_t {
15 uploading,
16 ready,
17 failed_load,
18 failed_gpu
19 };
20
21 virtual ~IVulkanResource() = default;
22
23 void markUploading() { m_state = UploadState::uploading; }
24
25 void markReady() { m_state = UploadState::ready; }
26
27 void markFailed(UploadState reason) { m_state = reason; }
28
29 [[nodiscard]]
30 auto isReady() const -> bool {
31 return m_state == UploadState::ready;
32 }
33
34 [[nodiscard]]
35 auto hasFailed() const -> bool {
36 return m_state == UploadState::failed_load || m_state == UploadState::failed_gpu;
37 }
38
39 [[nodiscard]]
40 auto state() const -> UploadState {
41 return m_state;
42 }
43
44private:
45 UploadState m_state = UploadState::uploading;
46};
47
49public:
50 virtual ~PendingResourceUpload() = default;
51
52 virtual auto resource() -> IVulkanResource* = 0;
53
54 virtual void build(const VulkanCore& core) = 0;
55
56 virtual void record(vk::CommandBuffer cmd) = 0;
57
59 [[nodiscard]]
60 virtual auto canRecord() const -> bool {
61 return true;
62 }
63
64 virtual void finished() {
65 if (!resource()->hasFailed()) {
66 resource()->markReady();
67 }
68 }
69
71 void setQueueHandoff(const sync::QueueHandoff& handoff) noexcept { m_handoff = handoff; }
72
74 virtual void recordAcquire(sync::BarrierBatch& batch) { (void)batch; }
75
76 vk::DeviceSize host_bytes = 0;
77
78protected:
79 sync::QueueHandoff m_handoff;
80};
81
82}
Definition vulkan_resource_base.hpp:12
Definition vulkan_resource_base.hpp:48
virtual auto canRecord() const -> bool
False while another upload has to be recorded first.
Definition vulkan_resource_base.hpp:60
virtual void recordAcquire(sync::BarrierBatch &batch)
On the consuming queue after the upload fence signalled. No op for an upload that stayed on one queue...
Definition vulkan_resource_base.hpp:74
void setQueueHandoff(const sync::QueueHandoff &handoff) noexcept
Before record(). The default keeps one queue and record() ends in a plain barrier.
Definition vulkan_resource_base.hpp:71
Definition vulkan_core.hpp:48
Skips a barrier only when neither side writes and the layout and next read stages are already covered...
Definition gpu_sync.hpp:105
Definition gpu_sync.hpp:92