diff --git a/libs/wgpu/include/psemek/wgpu/bind_group.hpp b/libs/wgpu/include/psemek/wgpu/bind_group.hpp new file mode 100644 index 00000000..7034859b --- /dev/null +++ b/libs/wgpu/include/psemek/wgpu/bind_group.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace psemek::wgpu +{ + + struct bind_group + : detail::object + { + using detail::object::object; + + struct entry + { + std::vector chain = {}; + std::uint32_t binding; + struct buffer buffer = {}; + std::uint64_t offset = 0; + std::uint64_t size = 0; + struct sampler sampler = {}; + struct texture_view texture_view = {}; + }; + + struct descriptor + { + std::vector chain = {}; + std::string label = {}; + bind_group_layout layout; + std::vector entries; + }; + + void set_label(std::string const & label); + + static void reference(void * ptr); + static void release(void * ptr); + + private: + explicit bind_group(void * ptr) + : detail::object(ptr) + {} + + friend struct device; + }; + +} diff --git a/libs/wgpu/include/psemek/wgpu/device.hpp b/libs/wgpu/include/psemek/wgpu/device.hpp index 33843910..8ee3589c 100644 --- a/libs/wgpu/include/psemek/wgpu/device.hpp +++ b/libs/wgpu/include/psemek/wgpu/device.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -109,6 +110,7 @@ namespace psemek::wgpu using request_callback = std::function; queue get_queue(); + bind_group create_bind_group(bind_group::descriptor const & desc); buffer create_buffer(buffer::descriptor const & desc); command_encoder create_command_encoder(command_encoder::descriptor const & desc); compute_pipeline create_compute_pipeline(compute_pipeline::descriptor const & desc); diff --git a/libs/wgpu/objects-todo b/libs/wgpu/objects-todo index 8ff8d899..73721b40 100644 --- a/libs/wgpu/objects-todo +++ b/libs/wgpu/objects-todo @@ -1,5 +1,5 @@ + WGPUAdapter - WGPUBindGroup ++ WGPUBindGroup - WGPUBindGroupLayout + WGPUBuffer + WGPUCommandBuffer diff --git a/libs/wgpu/source/bind_group.cpp b/libs/wgpu/source/bind_group.cpp new file mode 100644 index 00000000..0e51baf5 --- /dev/null +++ b/libs/wgpu/source/bind_group.cpp @@ -0,0 +1,22 @@ +#include +#include + +namespace psemek::wgpu +{ + + void bind_group::set_label(std::string const & label) + { + wgpuBindGroupSetLabel((WGPUBindGroup)get(), label.data()); + } + + void bind_group::reference(void * ptr) + { + wgpuBindGroupReference((WGPUBindGroup)ptr); + } + + void bind_group::release(void * ptr) + { + wgpuBindGroupRelease((WGPUBindGroup)ptr); + } + +} diff --git a/libs/wgpu/source/device.cpp b/libs/wgpu/source/device.cpp index 728adb1e..3f1129ea 100644 --- a/libs/wgpu/source/device.cpp +++ b/libs/wgpu/source/device.cpp @@ -13,6 +13,31 @@ namespace psemek::wgpu return queue(ptr); } + bind_group device::create_bind_group(bind_group::descriptor const & desc) + { + std::vector entries; + for (auto const & entry_in : desc.entries) + { + auto & entry_out = entries.emplace_back(); + entry_out.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(entry_in.chain); + entry_out.binding = entry_in.binding; + entry_out.buffer = (WGPUBuffer)entry_in.buffer.get(); + entry_out.offset = entry_in.offset; + entry_out.size = entry_in.size; + entry_out.sampler = (WGPUSampler)entry_in.sampler.get(); + entry_out.textureView = (WGPUTextureView)entry_in.texture_view.get(); + } + + WGPUBindGroupDescriptor descriptor = {}; + descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain); + descriptor.label = desc.label.data(); + descriptor.layout = (WGPUBindGroupLayout)desc.layout.get(); + descriptor.entryCount = entries.size(); + descriptor.entries = entries.data(); + + return bind_group(wgpuDeviceCreateBindGroup((WGPUDevice)get(), &descriptor)); + } + buffer device::create_buffer(buffer::descriptor const & desc) { WGPUBufferDescriptor descriptor = {};