WebGPU wrapper wip: add compute pipeline object
This commit is contained in:
parent
ea71e1878e
commit
e0281cd13f
6 changed files with 106 additions and 1 deletions
|
|
@ -20,6 +20,7 @@ namespace psemek::wgpu
|
|||
|
||||
friend struct device;
|
||||
friend struct render_pipeline;
|
||||
friend struct compute_pipeline;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
51
libs/wgpu/include/psemek/wgpu/compute_pipeline.hpp
Normal file
51
libs/wgpu/include/psemek/wgpu/compute_pipeline.hpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/wgpu/detail/object.hpp>
|
||||
#include <psemek/wgpu/chained_struct.hpp>
|
||||
#include <psemek/wgpu/pipeline_layout.hpp>
|
||||
#include <psemek/wgpu/bind_group_layout.hpp>
|
||||
#include <psemek/wgpu/shader_module.hpp>
|
||||
#include <psemek/wgpu/render_pipeline.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
namespace psemek::wgpu
|
||||
{
|
||||
|
||||
struct programmable_stage_descriptor
|
||||
{
|
||||
std::vector<chained_struct> chain = {};
|
||||
shader_module module;
|
||||
std::string entry_point;
|
||||
std::vector<constant_entry> constants = {};
|
||||
};
|
||||
|
||||
struct compute_pipeline
|
||||
: detail::object<compute_pipeline>
|
||||
{
|
||||
using detail::object<compute_pipeline>::object;
|
||||
|
||||
struct descriptor
|
||||
{
|
||||
std::vector<chained_struct> chain = {};
|
||||
std::string label = {};
|
||||
pipeline_layout layout;
|
||||
programmable_stage_descriptor compute;
|
||||
};
|
||||
|
||||
bind_group_layout get_bind_group_layout(std::uint32_t index);
|
||||
void set_label(std::string const & label);
|
||||
|
||||
static void reference(void * ptr);
|
||||
static void release(void * ptr);
|
||||
|
||||
private:
|
||||
explicit compute_pipeline(void * ptr)
|
||||
: detail::object<compute_pipeline>(ptr)
|
||||
{}
|
||||
|
||||
friend struct device;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include <psemek/wgpu/queue.hpp>
|
||||
#include <psemek/wgpu/buffer.hpp>
|
||||
#include <psemek/wgpu/command_encoder.hpp>
|
||||
#include <psemek/wgpu/compute_pipeline.hpp>
|
||||
#include <psemek/wgpu/query_set.hpp>
|
||||
#include <psemek/wgpu/render_pipeline.hpp>
|
||||
#include <psemek/wgpu/sampler.hpp>
|
||||
|
|
@ -110,6 +111,7 @@ namespace psemek::wgpu
|
|||
queue get_queue();
|
||||
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);
|
||||
query_set create_query_set(query_set::descriptor const & desc);
|
||||
render_pipeline create_render_pipeline(render_pipeline::descriptor const & desc);
|
||||
sampler create_sampler(sampler::descriptor const & desc);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
+ WGPUCommandBuffer
|
||||
- WGPUCommandEncoder
|
||||
WGPUComputePassEncoder
|
||||
WGPUComputePipeline
|
||||
+ WGPUComputePipeline
|
||||
- WGPUDevice
|
||||
+ WGPUInstance
|
||||
- WGPUPipelineLayout
|
||||
|
|
|
|||
27
libs/wgpu/source/compute_pipeline.cpp
Normal file
27
libs/wgpu/source/compute_pipeline.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include <psemek/wgpu/compute_pipeline.hpp>
|
||||
#include <psemek/wgpu/external/webgpu.h>
|
||||
|
||||
namespace psemek::wgpu
|
||||
{
|
||||
|
||||
bind_group_layout compute_pipeline::get_bind_group_layout(std::uint32_t index)
|
||||
{
|
||||
return bind_group_layout(wgpuComputePipelineGetBindGroupLayout((WGPUComputePipeline)get(), index));
|
||||
}
|
||||
|
||||
void compute_pipeline::set_label(std::string const & label)
|
||||
{
|
||||
wgpuComputePipelineSetLabel((WGPUComputePipeline)get(), label.data());
|
||||
}
|
||||
|
||||
void compute_pipeline::reference(void * ptr)
|
||||
{
|
||||
wgpuComputePipelineReference((WGPUComputePipeline)ptr);
|
||||
}
|
||||
|
||||
void compute_pipeline::release(void * ptr)
|
||||
{
|
||||
wgpuComputePipelineRelease((WGPUComputePipeline)ptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -32,6 +32,30 @@ namespace psemek::wgpu
|
|||
return command_encoder(wgpuDeviceCreateCommandEncoder((WGPUDevice)get(), &descriptor));
|
||||
}
|
||||
|
||||
compute_pipeline device::create_compute_pipeline(compute_pipeline::descriptor const & desc)
|
||||
{
|
||||
std::vector<WGPUConstantEntry> constants;
|
||||
for (auto const & constant_in : desc.compute.constants)
|
||||
{
|
||||
auto & constant_out = constants.emplace_back();
|
||||
constant_out.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(constant_in.chain);
|
||||
constant_out.key = constant_in.key.data();
|
||||
constant_out.value = constant_in.value;
|
||||
}
|
||||
|
||||
WGPUComputePipelineDescriptor descriptor = {};
|
||||
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
|
||||
descriptor.label = desc.label.data();
|
||||
descriptor.layout = (WGPUPipelineLayout)desc.layout.get();
|
||||
descriptor.compute.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.compute.chain);
|
||||
descriptor.compute.module = (WGPUShaderModule)desc.compute.module.get();
|
||||
descriptor.compute.entryPoint = desc.compute.entry_point.data();
|
||||
descriptor.compute.constantCount = constants.size();
|
||||
descriptor.compute.constants = constants.data();
|
||||
|
||||
return compute_pipeline(wgpuDeviceCreateComputePipeline((WGPUDevice)get(), &descriptor));
|
||||
}
|
||||
|
||||
query_set device::create_query_set(query_set::descriptor const & desc)
|
||||
{
|
||||
WGPUQuerySetDescriptor descriptor = {};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue