Skip to content

Commit 8447590

Browse files
committed
Guide: remove outdated ScopedWaiter from Device
1 parent 29c92a6 commit 8447590

File tree

1 file changed

+0
-35
lines changed

1 file changed

+0
-35
lines changed

guide/src/initialization/device.md

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,3 @@ Declare a `vk::Queue` member (order doesn't matter since it's just a handle, the
5757
static constexpr std::uint32_t queue_index_v{0};
5858
m_queue = m_device->getQueue(m_gpu.queue_family, queue_index_v);
5959
```
60-
61-
## ScopedWaiter
62-
63-
A useful abstraction to have is an object that in its destructor waits/blocks until the Device is idle. Being able to do arbitary things on scope exit is useful in general too, but it requires some custom class template like `UniqueResource<Type, Deleter>`. We shall "abuse" `std::unique_ptr<Type, Deleter>` instead: it will not manage the pointer (`Type*`) at all, but instead `Deleter` will call a member function on it (if it isn't null).
64-
65-
Adding this to a new header `scoped_waiter.hpp`:
66-
67-
```cpp
68-
class ScopedWaiter {
69-
public:
70-
ScopedWaiter() = default;
71-
72-
explicit ScopedWaiter(vk::Device const* device) : m_device(device) {}
73-
74-
private:
75-
struct Deleter {
76-
void operator()(vk::Device const* device) const noexcept {
77-
if (device == nullptr) { return; }
78-
device->waitIdle();
79-
}
80-
};
81-
std::unique_ptr<vk::Device const, Deleter> m_device{};
82-
};
83-
```
84-
85-
This requires the passed `vk::Device*` to outlive itself, so to be defensive we make `App` be non-moveable and non-copiable, and create a member factory function for waiters:
86-
87-
```cpp
88-
auto operator=(App&&) = delete;
89-
// ...
90-
91-
[[nodiscard]] auto create_waiter() const -> ScopedWaiter {
92-
return ScopedWaiter{&*m_device};
93-
}
94-
```

0 commit comments

Comments
 (0)