diff --git a/libs/wgpu/include/psemek/wgpu/command_encoder.hpp b/libs/wgpu/include/psemek/wgpu/command_encoder.hpp index 45249ba1..60c3ef32 100644 --- a/libs/wgpu/include/psemek/wgpu/command_encoder.hpp +++ b/libs/wgpu/include/psemek/wgpu/command_encoder.hpp @@ -2,8 +2,13 @@ #include #include +#include #include #include +#include +#include +#include +#include #include #include @@ -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 const & extent); + void copy_texture_to_buffer(image_copy_texture const & source, image_copy_buffer const & destination, geom::vector const & extent); + void copy_texture_to_texture(image_copy_texture const & source, image_copy_texture const & destination, geom::vector 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); diff --git a/libs/wgpu/include/psemek/wgpu/image_copy.hpp b/libs/wgpu/include/psemek/wgpu/image_copy.hpp new file mode 100644 index 00000000..7b0e6003 --- /dev/null +++ b/libs/wgpu/include/psemek/wgpu/image_copy.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +#include + +namespace psemek::wgpu +{ + + struct image_copy_texture + { + std::vector chain = {}; + struct texture texture; + std::uint32_t mip_level = 0; + geom::point origin = {0, 0, 0}; + texture::aspect aspect = texture::aspect::all; + }; + + struct image_copy_buffer { + std::vector chain = {}; + texture::data_layout layout; + struct buffer buffer; + }; + +} diff --git a/libs/wgpu/include/psemek/wgpu/queue.hpp b/libs/wgpu/include/psemek/wgpu/queue.hpp index fe825341..17accdb0 100644 --- a/libs/wgpu/include/psemek/wgpu/queue.hpp +++ b/libs/wgpu/include/psemek/wgpu/queue.hpp @@ -4,8 +4,8 @@ #include #include #include +#include #include -#include #include #include @@ -16,15 +16,6 @@ namespace psemek::wgpu { - struct image_copy_texture - { - std::vector chain = {}; - struct texture texture; - std::uint32_t mipLevel = 0; - geom::point origin = {0, 0, 0}; - texture::aspect aspect = texture::aspect::all; - }; - struct queue : detail::object { diff --git a/libs/wgpu/objects-todo b/libs/wgpu/objects-todo deleted file mode 100644 index cfea79cf..00000000 --- a/libs/wgpu/objects-todo +++ /dev/null @@ -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 diff --git a/libs/wgpu/source/command_encoder.cpp b/libs/wgpu/source/command_encoder.cpp index 142e4eb4..2b2a959a 100644 --- a/libs/wgpu/source/command_encoder.cpp +++ b/libs/wgpu/source/command_encoder.cpp @@ -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 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 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 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 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); diff --git a/libs/wgpu/source/queue.cpp b/libs/wgpu/source/queue.cpp index 71b274d7..39eb7979 100644 --- a/libs/wgpu/source/queue.cpp +++ b/libs/wgpu/source/queue.cpp @@ -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;