WebGPU wrapper wip: add bind group object
This commit is contained in:
parent
e0281cd13f
commit
e34b187235
5 changed files with 104 additions and 1 deletions
54
libs/wgpu/include/psemek/wgpu/bind_group.hpp
Normal file
54
libs/wgpu/include/psemek/wgpu/bind_group.hpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/wgpu/bind_group_layout.hpp>
|
||||
#include <psemek/wgpu/buffer.hpp>
|
||||
#include <psemek/wgpu/sampler.hpp>
|
||||
#include <psemek/wgpu/texture_view.hpp>
|
||||
#include <psemek/wgpu/chained_struct.hpp>
|
||||
#include <psemek/wgpu/detail/object.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace psemek::wgpu
|
||||
{
|
||||
|
||||
struct bind_group
|
||||
: detail::object<bind_group>
|
||||
{
|
||||
using detail::object<bind_group>::object;
|
||||
|
||||
struct entry
|
||||
{
|
||||
std::vector<chained_struct> 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<chained_struct> chain = {};
|
||||
std::string label = {};
|
||||
bind_group_layout layout;
|
||||
std::vector<entry> 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<bind_group>(ptr)
|
||||
{}
|
||||
|
||||
friend struct device;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <psemek/wgpu/chained_struct.hpp>
|
||||
#include <psemek/wgpu/queue.hpp>
|
||||
#include <psemek/wgpu/bind_group.hpp>
|
||||
#include <psemek/wgpu/buffer.hpp>
|
||||
#include <psemek/wgpu/command_encoder.hpp>
|
||||
#include <psemek/wgpu/compute_pipeline.hpp>
|
||||
|
|
@ -109,6 +110,7 @@ namespace psemek::wgpu
|
|||
using request_callback = std::function<void(request_status, device, std::string const & message)>;
|
||||
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
+ WGPUAdapter
|
||||
WGPUBindGroup
|
||||
+ WGPUBindGroup
|
||||
- WGPUBindGroupLayout
|
||||
+ WGPUBuffer
|
||||
+ WGPUCommandBuffer
|
||||
|
|
|
|||
22
libs/wgpu/source/bind_group.cpp
Normal file
22
libs/wgpu/source/bind_group.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include <psemek/wgpu/bind_group.hpp>
|
||||
#include <psemek/wgpu/external/webgpu.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -13,6 +13,31 @@ namespace psemek::wgpu
|
|||
return queue(ptr);
|
||||
}
|
||||
|
||||
bind_group device::create_bind_group(bind_group::descriptor const & desc)
|
||||
{
|
||||
std::vector<WGPUBindGroupEntry> 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 = {};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue