WebGPU wrapper wip: add command encoder methods
This commit is contained in:
parent
97ee3c1134
commit
d943f14185
6 changed files with 164 additions and 33 deletions
|
|
@ -2,8 +2,13 @@
|
|||
|
||||
#include <psemek/wgpu/detail/object.hpp>
|
||||
#include <psemek/wgpu/chained_struct.hpp>
|
||||
#include <psemek/wgpu/compute_pass_encoder.hpp>
|
||||
#include <psemek/wgpu/render_pass_encoder.hpp>
|
||||
#include <psemek/wgpu/command_buffer.hpp>
|
||||
#include <psemek/wgpu/buffer.hpp>
|
||||
#include <psemek/wgpu/query_set.hpp>
|
||||
#include <psemek/wgpu/image_copy.hpp>
|
||||
#include <psemek/geom/vector.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
|
@ -22,8 +27,20 @@ namespace psemek::wgpu
|
|||
std::string label = {};
|
||||
};
|
||||
|
||||
compute_pass_encoder begin_compute_pass(compute_pass_encoder::descriptor const & desc);
|
||||
render_pass_encoder begin_render_pass(render_pass_encoder::descriptor const & desc);
|
||||
void clear_buffer(buffer const & buffer, std::uint64_t offset, std::uint64_t size);
|
||||
void copy_buffer_to_buffer(buffer const & source, std::uint64_t source_offset, buffer const & destination, std::uint64_t destination_offset, std::uint64_t size);
|
||||
void copy_buffer_to_texture(image_copy_buffer const & source, image_copy_texture const & destination, geom::vector<std::uint32_t, 3> const & extent);
|
||||
void copy_texture_to_buffer(image_copy_texture const & source, image_copy_buffer const & destination, geom::vector<std::uint32_t, 3> const & extent);
|
||||
void copy_texture_to_texture(image_copy_texture const & source, image_copy_texture const & destination, geom::vector<std::uint32_t, 3> const & extent);
|
||||
void insert_debug_marker(std::string const & marker_label);
|
||||
void push_debug_group(std::string const & group_label);
|
||||
void pop_debug_group();
|
||||
void resolve_query_set(query_set const & query_set, std::uint32_t first_query, std::uint32_t query_count, buffer const & destination, std::uint64_t destination_offset);
|
||||
void write_timestamp(query_set const & query_set, std::uint32_t query_index);
|
||||
command_buffer finish(command_buffer::descriptor const & desc);
|
||||
void set_label(std::string const & label);
|
||||
|
||||
static void reference(void * ptr);
|
||||
static void release(void * ptr);
|
||||
|
|
|
|||
28
libs/wgpu/include/psemek/wgpu/image_copy.hpp
Normal file
28
libs/wgpu/include/psemek/wgpu/image_copy.hpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <psemek/wgpu/texture.hpp>
|
||||
#include <psemek/wgpu/buffer.hpp>
|
||||
#include <psemek/geom/point.hpp>
|
||||
#include <psemek/wgpu/chained_struct.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace psemek::wgpu
|
||||
{
|
||||
|
||||
struct image_copy_texture
|
||||
{
|
||||
std::vector<chained_struct> chain = {};
|
||||
struct texture texture;
|
||||
std::uint32_t mip_level = 0;
|
||||
geom::point<std::uint32_t, 3> origin = {0, 0, 0};
|
||||
texture::aspect aspect = texture::aspect::all;
|
||||
};
|
||||
|
||||
struct image_copy_buffer {
|
||||
std::vector<chained_struct> chain = {};
|
||||
texture::data_layout layout;
|
||||
struct buffer buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -4,8 +4,8 @@
|
|||
#include <psemek/wgpu/command_buffer.hpp>
|
||||
#include <psemek/wgpu/buffer.hpp>
|
||||
#include <psemek/wgpu/texture.hpp>
|
||||
#include <psemek/wgpu/image_copy.hpp>
|
||||
#include <psemek/wgpu/detail/object.hpp>
|
||||
#include <psemek/geom/point.hpp>
|
||||
#include <psemek/util/span.hpp>
|
||||
|
||||
#include <string>
|
||||
|
|
@ -16,15 +16,6 @@
|
|||
namespace psemek::wgpu
|
||||
{
|
||||
|
||||
struct image_copy_texture
|
||||
{
|
||||
std::vector<chained_struct> chain = {};
|
||||
struct texture texture;
|
||||
std::uint32_t mipLevel = 0;
|
||||
geom::point<std::uint32_t, 3> origin = {0, 0, 0};
|
||||
texture::aspect aspect = texture::aspect::all;
|
||||
};
|
||||
|
||||
struct queue
|
||||
: detail::object<queue>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
+ WGPUAdapter
|
||||
+ WGPUBindGroup
|
||||
+ WGPUBindGroupLayout
|
||||
+ WGPUBuffer
|
||||
+ WGPUCommandBuffer
|
||||
- WGPUCommandEncoder
|
||||
+ WGPUComputePassEncoder
|
||||
+ WGPUComputePipeline
|
||||
+ WGPUDevice
|
||||
+ WGPUInstance
|
||||
+ WGPUPipelineLayout
|
||||
+ WGPUQuerySet
|
||||
+ WGPUQueue
|
||||
+ WGPURenderBundle
|
||||
+ WGPURenderBundleEncoder
|
||||
+ WGPURenderPassEncoder
|
||||
+ WGPURenderPipeline
|
||||
+ WGPUSampler
|
||||
+ WGPUShaderModule
|
||||
+ WGPUSurface
|
||||
+ WGPUTexture
|
||||
+ WGPUTextureView
|
||||
|
|
@ -4,6 +4,24 @@
|
|||
namespace psemek::wgpu
|
||||
{
|
||||
|
||||
compute_pass_encoder command_encoder::begin_compute_pass(compute_pass_encoder::descriptor const & desc)
|
||||
{
|
||||
WGPUComputePassTimestampWrites timestamp_writes = {};
|
||||
if (desc.timestamp_writes)
|
||||
{
|
||||
timestamp_writes.querySet = (WGPUQuerySet)desc.timestamp_writes->query_set.get();
|
||||
timestamp_writes.beginningOfPassWriteIndex = desc.timestamp_writes->begin_index;
|
||||
timestamp_writes.endOfPassWriteIndex = desc.timestamp_writes->end_index;
|
||||
}
|
||||
|
||||
WGPUComputePassDescriptor descriptor = {};
|
||||
descriptor.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(desc.chain);
|
||||
descriptor.label = desc.label.data();
|
||||
descriptor.timestampWrites = desc.timestamp_writes ? ×tamp_writes : nullptr;
|
||||
|
||||
return compute_pass_encoder(wgpuCommandEncoderBeginComputePass((WGPUCommandEncoder)get(), &descriptor));
|
||||
}
|
||||
|
||||
render_pass_encoder command_encoder::begin_render_pass(render_pass_encoder::descriptor const & desc)
|
||||
{
|
||||
std::vector<WGPURenderPassColorAttachment> color_attachments;
|
||||
|
|
@ -37,6 +55,100 @@ namespace psemek::wgpu
|
|||
return render_pass_encoder(wgpuCommandEncoderBeginRenderPass((WGPUCommandEncoder)get(), &descriptor));
|
||||
}
|
||||
|
||||
void command_encoder::clear_buffer(buffer const & buffer, std::uint64_t offset, std::uint64_t size)
|
||||
{
|
||||
wgpuCommandEncoderClearBuffer((WGPUCommandEncoder)get(), (WGPUBuffer)buffer.get(), offset, size);
|
||||
}
|
||||
|
||||
void command_encoder::copy_buffer_to_buffer(buffer const & source, std::uint64_t source_offset, buffer const & destination, std::uint64_t destination_offset, std::uint64_t size)
|
||||
{
|
||||
wgpuCommandEncoderCopyBufferToBuffer((WGPUCommandEncoder)get(), (WGPUBuffer)source.get(), source_offset, (WGPUBuffer)destination.get(), destination_offset, size);
|
||||
}
|
||||
|
||||
void command_encoder::copy_buffer_to_texture(image_copy_buffer const & source, image_copy_texture const & destination, geom::vector<std::uint32_t, 3> const & extent)
|
||||
{
|
||||
WGPUImageCopyBuffer image_copy_src = {};
|
||||
image_copy_src.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.chain);
|
||||
image_copy_src.layout.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.layout.chain);
|
||||
image_copy_src.layout.offset = source.layout.offset;
|
||||
image_copy_src.layout.bytesPerRow = source.layout.bytes_per_row;
|
||||
image_copy_src.layout.rowsPerImage = source.layout.rows_per_image;
|
||||
image_copy_src.buffer = (WGPUBuffer)source.buffer.get();
|
||||
|
||||
WGPUImageCopyTexture image_copy_dst = {};
|
||||
image_copy_dst.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.chain);
|
||||
image_copy_dst.texture = (WGPUTexture)destination.texture.get();
|
||||
image_copy_dst.mipLevel = destination.mip_level;
|
||||
image_copy_dst.origin = {destination.origin[0], destination.origin[1], destination.origin[2]};
|
||||
image_copy_dst.aspect = (WGPUTextureAspect)destination.aspect;
|
||||
|
||||
wgpuCommandEncoderCopyBufferToTexture((WGPUCommandEncoder)get(), &image_copy_src, &image_copy_dst, (WGPUExtent3D const *)(&extent));
|
||||
}
|
||||
|
||||
void command_encoder::copy_texture_to_buffer(image_copy_texture const & source, image_copy_buffer const & destination, geom::vector<std::uint32_t, 3> const & extent)
|
||||
{
|
||||
WGPUImageCopyTexture image_copy_src = {};
|
||||
image_copy_src.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.chain);
|
||||
image_copy_src.texture = (WGPUTexture)source.texture.get();
|
||||
image_copy_src.mipLevel = source.mip_level;
|
||||
image_copy_src.origin = {source.origin[0], source.origin[1], source.origin[2]};
|
||||
image_copy_src.aspect = (WGPUTextureAspect)source.aspect;
|
||||
|
||||
WGPUImageCopyBuffer image_copy_dst = {};
|
||||
image_copy_dst.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.chain);
|
||||
image_copy_dst.layout.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.layout.chain);
|
||||
image_copy_dst.layout.offset = destination.layout.offset;
|
||||
image_copy_dst.layout.bytesPerRow = destination.layout.bytes_per_row;
|
||||
image_copy_dst.layout.rowsPerImage = destination.layout.rows_per_image;
|
||||
image_copy_dst.buffer = (WGPUBuffer)destination.buffer.get();
|
||||
|
||||
wgpuCommandEncoderCopyTextureToBuffer((WGPUCommandEncoder)get(), &image_copy_src, &image_copy_dst, (WGPUExtent3D const *)(&extent));
|
||||
}
|
||||
|
||||
void command_encoder::copy_texture_to_texture(image_copy_texture const & source, image_copy_texture const & destination, geom::vector<std::uint32_t, 3> const & extent)
|
||||
{
|
||||
WGPUImageCopyTexture image_copy_src = {};
|
||||
image_copy_src.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(source.chain);
|
||||
image_copy_src.texture = (WGPUTexture)source.texture.get();
|
||||
image_copy_src.mipLevel = source.mip_level;
|
||||
image_copy_src.origin = {source.origin[0], source.origin[1], source.origin[2]};
|
||||
image_copy_src.aspect = (WGPUTextureAspect)source.aspect;
|
||||
|
||||
WGPUImageCopyTexture image_copy_dst = {};
|
||||
image_copy_dst.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(destination.chain);
|
||||
image_copy_dst.texture = (WGPUTexture)destination.texture.get();
|
||||
image_copy_dst.mipLevel = destination.mip_level;
|
||||
image_copy_dst.origin = {destination.origin[0], destination.origin[1], destination.origin[2]};
|
||||
image_copy_dst.aspect = (WGPUTextureAspect)destination.aspect;
|
||||
|
||||
wgpuCommandEncoderCopyTextureToTexture((WGPUCommandEncoder)get(), &image_copy_src, &image_copy_dst, (WGPUExtent3D const *)(&extent));
|
||||
}
|
||||
|
||||
void command_encoder::insert_debug_marker(std::string const & marker_label)
|
||||
{
|
||||
wgpuCommandEncoderInsertDebugMarker((WGPUCommandEncoder)get(), marker_label.data());
|
||||
}
|
||||
|
||||
void command_encoder::push_debug_group(std::string const & group_label)
|
||||
{
|
||||
wgpuCommandEncoderPushDebugGroup((WGPUCommandEncoder)get(), group_label.data());
|
||||
}
|
||||
|
||||
void command_encoder::pop_debug_group()
|
||||
{
|
||||
wgpuCommandEncoderPopDebugGroup((WGPUCommandEncoder)get());
|
||||
}
|
||||
|
||||
void command_encoder::resolve_query_set(query_set const & query_set, std::uint32_t first_query, std::uint32_t query_count, buffer const & destination, std::uint64_t destination_offset)
|
||||
{
|
||||
wgpuCommandEncoderResolveQuerySet((WGPUCommandEncoder)get(), (WGPUQuerySet)query_set.get(), first_query, query_count, (WGPUBuffer)destination.get(), destination_offset);
|
||||
}
|
||||
|
||||
void command_encoder::write_timestamp(query_set const & query_set, std::uint32_t query_index)
|
||||
{
|
||||
wgpuCommandEncoderWriteTimestamp((WGPUCommandEncoder)get(), (WGPUQuerySet)query_set.get(), query_index);
|
||||
}
|
||||
|
||||
command_buffer command_encoder::finish(command_buffer::descriptor const & desc)
|
||||
{
|
||||
WGPUCommandBufferDescriptor descriptor = {};
|
||||
|
|
@ -45,6 +157,11 @@ namespace psemek::wgpu
|
|||
return command_buffer(wgpuCommandEncoderFinish((WGPUCommandEncoder)get(), &descriptor));
|
||||
}
|
||||
|
||||
void command_encoder::set_label(std::string const & label)
|
||||
{
|
||||
wgpuCommandEncoderSetLabel((WGPUCommandEncoder)get(), label.data());
|
||||
}
|
||||
|
||||
void command_encoder::reference(void * ptr)
|
||||
{
|
||||
wgpuCommandEncoderReference((WGPUCommandEncoder)ptr);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ namespace psemek::wgpu
|
|||
WGPUImageCopyTexture image_copy_texture = {};
|
||||
image_copy_texture.nextInChain = (WGPUChainedStruct const *)detail::fill_chain(dest.chain);
|
||||
image_copy_texture.texture = (WGPUTexture)dest.texture.get();
|
||||
image_copy_texture.mipLevel = dest.mipLevel;
|
||||
image_copy_texture.mipLevel = dest.mip_level;
|
||||
image_copy_texture.origin = {dest.origin[0], dest.origin[1], dest.origin[2]};
|
||||
image_copy_texture.aspect = (WGPUTextureAspect)dest.aspect;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue