WebGPU wrapper wip: add bind group layout object
This commit is contained in:
parent
4370bf608f
commit
20b584b5e0
8 changed files with 155 additions and 8 deletions
|
|
@ -1,15 +1,96 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/wgpu/detail/object.hpp>
|
#include <psemek/wgpu/detail/object.hpp>
|
||||||
|
#include <psemek/wgpu/chained_struct.hpp>
|
||||||
|
#include <psemek/wgpu/shader_stage.hpp>
|
||||||
|
#include <psemek/wgpu/texture_view.hpp>
|
||||||
|
#include <psemek/wgpu/texture.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace psemek::wgpu
|
namespace psemek::wgpu
|
||||||
{
|
{
|
||||||
|
|
||||||
|
enum class buffer_binding_type : std::uint32_t
|
||||||
|
{
|
||||||
|
undefined = 0x00000000,
|
||||||
|
uniform = 0x00000001,
|
||||||
|
storage = 0x00000002,
|
||||||
|
read_only_storage = 0x00000003,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct buffer_binding_layout
|
||||||
|
{
|
||||||
|
std::vector<chained_struct> chain = {};
|
||||||
|
buffer_binding_type type = buffer_binding_type::undefined;
|
||||||
|
bool has_dynamic_offset = false;
|
||||||
|
std::uint64_t min_binding_size = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class sampler_binding_type : std::uint32_t
|
||||||
|
{
|
||||||
|
undefined = 0x00000000,
|
||||||
|
filtering = 0x00000001,
|
||||||
|
nonfiltering = 0x00000002,
|
||||||
|
comparison = 0x00000003,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sampler_binding_layout
|
||||||
|
{
|
||||||
|
std::vector<chained_struct> chain = {};
|
||||||
|
sampler_binding_type type = sampler_binding_type::undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct texture_binding_layout
|
||||||
|
{
|
||||||
|
std::vector<chained_struct> chain = {};
|
||||||
|
texture::sample_type sample_type = texture::sample_type::undefined;
|
||||||
|
texture_view::dimension view_dimension = texture_view::dimension::undefined;
|
||||||
|
bool multisampled = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class storage_texture_access : std::uint32_t
|
||||||
|
{
|
||||||
|
undefined = 0x00000000,
|
||||||
|
write_only = 0x00000001,
|
||||||
|
read_only = 0x00000002,
|
||||||
|
read_write = 0x00000003,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct storage_texture_binding_layout
|
||||||
|
{
|
||||||
|
std::vector<chained_struct> chain = {};
|
||||||
|
storage_texture_access access = storage_texture_access::undefined;
|
||||||
|
texture::format format = texture::format::undefined;
|
||||||
|
texture_view::dimension view_dimension = texture_view::dimension::undefined;
|
||||||
|
};
|
||||||
|
|
||||||
struct bind_group_layout
|
struct bind_group_layout
|
||||||
: detail::object<bind_group_layout>
|
: detail::object<bind_group_layout>
|
||||||
{
|
{
|
||||||
using detail::object<bind_group_layout>::object;
|
using detail::object<bind_group_layout>::object;
|
||||||
|
|
||||||
|
struct entry
|
||||||
|
{
|
||||||
|
std::vector<chained_struct> chain = {};
|
||||||
|
std::uint32_t binding;
|
||||||
|
shader_stage visibility;
|
||||||
|
buffer_binding_layout buffer = {};
|
||||||
|
sampler_binding_layout sampler = {};
|
||||||
|
texture_binding_layout texture = {};
|
||||||
|
storage_texture_binding_layout storage_texture = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct descriptor
|
||||||
|
{
|
||||||
|
std::vector<chained_struct> chain = {};
|
||||||
|
std::string label = {};
|
||||||
|
std::vector<entry> entries;
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_label(std::string const & label);
|
||||||
|
|
||||||
static void reference(void * ptr);
|
static void reference(void * ptr);
|
||||||
static void release(void * ptr);
|
static void release(void * ptr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <psemek/wgpu/chained_struct.hpp>
|
#include <psemek/wgpu/chained_struct.hpp>
|
||||||
#include <psemek/wgpu/queue.hpp>
|
#include <psemek/wgpu/queue.hpp>
|
||||||
#include <psemek/wgpu/bind_group.hpp>
|
#include <psemek/wgpu/bind_group.hpp>
|
||||||
|
#include <psemek/wgpu/bind_group_layout.hpp>
|
||||||
#include <psemek/wgpu/buffer.hpp>
|
#include <psemek/wgpu/buffer.hpp>
|
||||||
#include <psemek/wgpu/command_encoder.hpp>
|
#include <psemek/wgpu/command_encoder.hpp>
|
||||||
#include <psemek/wgpu/compute_pipeline.hpp>
|
#include <psemek/wgpu/compute_pipeline.hpp>
|
||||||
|
|
@ -111,6 +112,7 @@ namespace psemek::wgpu
|
||||||
|
|
||||||
queue get_queue();
|
queue get_queue();
|
||||||
bind_group create_bind_group(bind_group::descriptor const & desc);
|
bind_group create_bind_group(bind_group::descriptor const & desc);
|
||||||
|
bind_group_layout create_bind_group_layout(bind_group_layout::descriptor const & desc);
|
||||||
buffer create_buffer(buffer::descriptor const & desc);
|
buffer create_buffer(buffer::descriptor const & desc);
|
||||||
command_encoder create_command_encoder(command_encoder::descriptor const & desc);
|
command_encoder create_command_encoder(command_encoder::descriptor const & desc);
|
||||||
compute_pipeline create_compute_pipeline(compute_pipeline::descriptor const & desc);
|
compute_pipeline create_compute_pipeline(compute_pipeline::descriptor const & desc);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <psemek/wgpu/shader_stage.hpp>
|
||||||
#include <psemek/wgpu/chained_struct.hpp>
|
#include <psemek/wgpu/chained_struct.hpp>
|
||||||
#include <psemek/wgpu/pipeline_layout.hpp>
|
#include <psemek/wgpu/pipeline_layout.hpp>
|
||||||
#include <psemek/wgpu/detail/object.hpp>
|
#include <psemek/wgpu/detail/object.hpp>
|
||||||
|
|
@ -13,13 +14,6 @@
|
||||||
namespace psemek::wgpu
|
namespace psemek::wgpu
|
||||||
{
|
{
|
||||||
|
|
||||||
enum class shader_stage {
|
|
||||||
none = 0x00000000,
|
|
||||||
vertex = 0x00000001,
|
|
||||||
fragment = 0x00000002,
|
|
||||||
compute = 0x00000004,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct shader_module
|
struct shader_module
|
||||||
: detail::object<shader_module>
|
: detail::object<shader_module>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
21
libs/wgpu/include/psemek/wgpu/shader_stage.hpp
Normal file
21
libs/wgpu/include/psemek/wgpu/shader_stage.hpp
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace psemek::wgpu
|
||||||
|
{
|
||||||
|
|
||||||
|
enum class shader_stage : std::uint32_t
|
||||||
|
{
|
||||||
|
none = 0x00000000,
|
||||||
|
vertex = 0x00000001,
|
||||||
|
fragment = 0x00000002,
|
||||||
|
compute = 0x00000004,
|
||||||
|
};
|
||||||
|
|
||||||
|
inline shader_stage operator | (shader_stage s1, shader_stage s2)
|
||||||
|
{
|
||||||
|
return static_cast<shader_stage>(static_cast<std::uint32_t>(s1) | static_cast<std::uint32_t>(s2));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -141,6 +141,16 @@ namespace psemek::wgpu
|
||||||
depth_only = 0x00000002,
|
depth_only = 0x00000002,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class sample_type : std::uint32_t
|
||||||
|
{
|
||||||
|
undefined = 0x00000000,
|
||||||
|
_float = 0x00000001,
|
||||||
|
unfilterable_float = 0x00000002,
|
||||||
|
depth = 0x00000003,
|
||||||
|
sint = 0x00000004,
|
||||||
|
uint = 0x00000005,
|
||||||
|
};
|
||||||
|
|
||||||
struct descriptor
|
struct descriptor
|
||||||
{
|
{
|
||||||
std::vector<chained_struct> chain = {};
|
std::vector<chained_struct> chain = {};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
+ WGPUAdapter
|
+ WGPUAdapter
|
||||||
+ WGPUBindGroup
|
+ WGPUBindGroup
|
||||||
- WGPUBindGroupLayout
|
+ WGPUBindGroupLayout
|
||||||
+ WGPUBuffer
|
+ WGPUBuffer
|
||||||
+ WGPUCommandBuffer
|
+ WGPUCommandBuffer
|
||||||
- WGPUCommandEncoder
|
- WGPUCommandEncoder
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,11 @@
|
||||||
namespace psemek::wgpu
|
namespace psemek::wgpu
|
||||||
{
|
{
|
||||||
|
|
||||||
|
void bind_group_layout::set_label(std::string const & label)
|
||||||
|
{
|
||||||
|
wgpuBindGroupLayoutSetLabel((WGPUBindGroupLayout)get(), label.data());
|
||||||
|
}
|
||||||
|
|
||||||
void bind_group_layout::reference(void * ptr)
|
void bind_group_layout::reference(void * ptr)
|
||||||
{
|
{
|
||||||
wgpuBindGroupLayoutReference((WGPUBindGroupLayout)ptr);
|
wgpuBindGroupLayoutReference((WGPUBindGroupLayout)ptr);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,40 @@ namespace psemek::wgpu
|
||||||
return bind_group(wgpuDeviceCreateBindGroup((WGPUDevice)get(), &descriptor));
|
return bind_group(wgpuDeviceCreateBindGroup((WGPUDevice)get(), &descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bind_group_layout device::create_bind_group_layout(bind_group_layout::descriptor const & desc)
|
||||||
|
{
|
||||||
|
std::vector<WGPUBindGroupLayoutEntry> 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.visibility = (WGPUShaderStageFlags)entry_in.visibility;
|
||||||
|
entry_out.buffer.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(entry_in.buffer.chain);
|
||||||
|
entry_out.buffer.type = (WGPUBufferBindingType)entry_in.buffer.type;
|
||||||
|
entry_out.buffer.hasDynamicOffset = entry_in.buffer.has_dynamic_offset;
|
||||||
|
entry_out.buffer.minBindingSize = entry_in.buffer.min_binding_size;
|
||||||
|
entry_out.sampler.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(entry_in.sampler.chain);
|
||||||
|
entry_out.sampler.type = (WGPUSamplerBindingType)entry_in.sampler.type;
|
||||||
|
entry_out.texture.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(entry_in.texture.chain);
|
||||||
|
entry_out.texture.sampleType = (WGPUTextureSampleType)entry_in.texture.sample_type;
|
||||||
|
entry_out.texture.viewDimension = (WGPUTextureViewDimension)entry_in.texture.view_dimension;
|
||||||
|
entry_out.texture.multisampled = entry_in.texture.multisampled;
|
||||||
|
entry_out.storageTexture.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(entry_in.storage_texture.chain);
|
||||||
|
entry_out.storageTexture.access = (WGPUStorageTextureAccess)entry_in.storage_texture.access;
|
||||||
|
entry_out.storageTexture.format = (WGPUTextureFormat)entry_in.storage_texture.format;
|
||||||
|
entry_out.storageTexture.viewDimension = (WGPUTextureViewDimension)entry_in.storage_texture.view_dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
WGPUBindGroupLayoutDescriptor descriptor = {};
|
||||||
|
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
|
||||||
|
descriptor.label = desc.label.data();
|
||||||
|
descriptor.entryCount = entries.size();
|
||||||
|
descriptor.entries = entries.data();
|
||||||
|
|
||||||
|
return bind_group_layout(wgpuDeviceCreateBindGroupLayout((WGPUDevice)get(), &descriptor));
|
||||||
|
}
|
||||||
|
|
||||||
buffer device::create_buffer(buffer::descriptor const & desc)
|
buffer device::create_buffer(buffer::descriptor const & desc)
|
||||||
{
|
{
|
||||||
WGPUBufferDescriptor descriptor = {};
|
WGPUBufferDescriptor descriptor = {};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue