Skip to content

Commit

Permalink
Forward declarations to access incomplete type IDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
corporateshark committed Jul 15, 2023
1 parent 313f9b7 commit e9ee05c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
18 changes: 18 additions & 0 deletions lvk/LVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,21 @@ bool lvk::Assert(bool cond, const char* file, int line, const char* format, ...)
}
return cond;
}

void lvk::destroy(igl::IDevice* device, lvk::ComputePipelineHandle handle) {
if (device) {
device->destroy(handle);
}
}

void lvk::destroy(igl::IDevice* device, lvk::RenderPipelineHandle handle) {
if (device) {
device->destroy(handle);
}
}

void lvk::destroy(igl::IDevice* device, lvk::ShaderModuleHandle handle) {
if (device) {
device->destroy(handle);
}
}
23 changes: 12 additions & 11 deletions lvk/LVK.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,23 @@ class Handle final {

static_assert(sizeof(Handle<class Foo>) == sizeof(uint64_t));

// specialized with dummy structs for type safety
using ComputePipelineHandle = lvk::Handle<struct ComputePipeline>;
using RenderPipelineHandle = lvk::Handle<struct RenderPipeline>;
using ShaderModuleHandle = lvk::Handle<struct ShaderModule>;

// forward declarations to access incomplete type IDevice
void destroy(igl::IDevice* device, lvk::ComputePipelineHandle handle);
void destroy(igl::IDevice* device, lvk::RenderPipelineHandle handle);
void destroy(igl::IDevice* device, lvk::ShaderModuleHandle handle);

template<typename HandleType>
class Holder final {
public:
Holder() = default;
Holder(igl::IDevice* device, HandleType handle) : device_(device), handle_(handle) {}
~Holder() {
if (device_) {
device_->destroy(handle_);
}
lvk::destroy(device_, handle_);
}
Holder(const Holder&) = delete;
Holder(Holder&& other) : device_(other.device_), handle_(other.handle_) {
Expand Down Expand Up @@ -132,9 +140,7 @@ class Holder final {
}

void reset() {
if (device_) {
device_->destroy(handle_);
}
lvk::destroy(device_, handle_);
device_ = nullptr;
handle_ = HandleType{};
}
Expand All @@ -149,11 +155,6 @@ class Holder final {
HandleType handle_;
};

// specialized with dummy structs for type safety
using ComputePipelineHandle = lvk::Handle<struct ComputePipeline>;
using RenderPipelineHandle = lvk::Handle<struct RenderPipeline>;
using ShaderModuleHandle = lvk::Handle<struct ShaderModule>;

} // namespace lvk

// clang-format off
Expand Down

0 comments on commit e9ee05c

Please sign in to comment.