From 4fe00e0322377316390da6faa2d645cae53d08f4 Mon Sep 17 00:00:00 2001 From: Sandor Molnar Date: Tue, 13 Feb 2024 09:00:38 +0200 Subject: [PATCH] Backed out 3 changesets (bug 1878308) for causing webgpu failures. CLOSED TREE Backed out changeset 2887e360adb9 (bug 1878308) Backed out changeset c5f276e2774d (bug 1878308) Backed out changeset b3fb55591aa7 (bug 1878308) --- Cargo.lock | 1 - dom/webgpu/CommandEncoder.cpp | 6 +- dom/webgpu/CommandEncoder.h | 6 +- dom/webgpu/ComputePassEncoder.cpp | 26 +- dom/webgpu/ComputePassEncoder.h | 7 +- dom/webgpu/RenderPassEncoder.cpp | 62 +- dom/webgpu/RenderPassEncoder.h | 4 +- dom/webgpu/ipc/PWebGPU.ipdl | 2 - dom/webgpu/ipc/WebGPUParent.cpp | 18 - dom/webgpu/ipc/WebGPUParent.h | 4 - gfx/wgpu_bindings/Cargo.toml | 1 - gfx/wgpu_bindings/src/client.rs | 46 +- gfx/wgpu_bindings/src/command.rs | 1079 ----------------------------- gfx/wgpu_bindings/src/lib.rs | 1 - gfx/wgpu_bindings/src/server.rs | 44 +- 15 files changed, 86 insertions(+), 1221 deletions(-) delete mode 100644 gfx/wgpu_bindings/src/command.rs diff --git a/Cargo.lock b/Cargo.lock index ceceff34012f..84b9132fddea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6540,7 +6540,6 @@ dependencies = [ name = "wgpu_bindings" version = "0.1.0" dependencies = [ - "arrayvec", "bincode", "d3d12", "log", diff --git a/dom/webgpu/CommandEncoder.cpp b/dom/webgpu/CommandEncoder.cpp index 5cf0e938653a..15d95401d41f 100644 --- a/dom/webgpu/CommandEncoder.cpp +++ b/dom/webgpu/CommandEncoder.cpp @@ -230,7 +230,7 @@ already_AddRefed CommandEncoder::BeginRenderPass( return pass.forget(); } -void CommandEncoder::EndComputePass(ffi::WGPURecordedComputePass& aPass) { +void CommandEncoder::EndComputePass(ffi::WGPUComputePass& aPass) { if (!mBridge->IsOpen()) { return; } @@ -240,14 +240,14 @@ void CommandEncoder::EndComputePass(ffi::WGPURecordedComputePass& aPass) { mBridge->SendCommandEncoderAction(mId, mParent->mId, std::move(byteBuf)); } -void CommandEncoder::EndRenderPass(ffi::WGPURecordedRenderPass& aPass) { +void CommandEncoder::EndRenderPass(ffi::WGPURenderPass& aPass) { if (!mBridge->IsOpen()) { return; } ipc::ByteBuf byteBuf; ffi::wgpu_render_pass_finish(&aPass, ToFFI(&byteBuf)); - mBridge->SendRenderPass(mId, mParent->mId, std::move(byteBuf)); + mBridge->SendCommandEncoderAction(mId, mParent->mId, std::move(byteBuf)); } already_AddRefed CommandEncoder::Finish( diff --git a/dom/webgpu/CommandEncoder.h b/dom/webgpu/CommandEncoder.h index 1a6d16ae2086..52b10a5b2ec1 100644 --- a/dom/webgpu/CommandEncoder.h +++ b/dom/webgpu/CommandEncoder.h @@ -32,7 +32,7 @@ using GPUExtent3D = RangeEnforcedUnsignedLongSequenceOrGPUExtent3DDict; namespace webgpu { namespace ffi { struct WGPUComputePass; -struct WGPURecordedRenderPass; +struct WGPURenderPass; struct WGPUImageDataLayout; struct WGPUImageCopyTexture_TextureId; struct WGPUExtent3d; @@ -72,8 +72,8 @@ class CommandEncoder final : public ObjectBase, public ChildOf { public: const auto& GetDevice() const { return mParent; }; - void EndComputePass(ffi::WGPURecordedComputePass& aPass); - void EndRenderPass(ffi::WGPURecordedRenderPass& aPass); + void EndComputePass(ffi::WGPUComputePass& aPass); + void EndRenderPass(ffi::WGPURenderPass& aPass); void CopyBufferToBuffer(const Buffer& aSource, BufferAddress aSourceOffset, const Buffer& aDestination, diff --git a/dom/webgpu/ComputePassEncoder.cpp b/dom/webgpu/ComputePassEncoder.cpp index 190bbf00a72d..2820a575e880 100644 --- a/dom/webgpu/ComputePassEncoder.cpp +++ b/dom/webgpu/ComputePassEncoder.cpp @@ -17,13 +17,13 @@ GPU_IMPL_CYCLE_COLLECTION(ComputePassEncoder, mParent, mUsedBindGroups, mUsedPipelines) GPU_IMPL_JS_WRAP(ComputePassEncoder) -void ffiWGPUComputePassDeleter::operator()(ffi::WGPURecordedComputePass* raw) { +void ffiWGPUComputePassDeleter::operator()(ffi::WGPUComputePass* raw) { if (raw) { ffi::wgpu_compute_pass_destroy(raw); } } -ffi::WGPURecordedComputePass* BeginComputePass( +ffi::WGPUComputePass* BeginComputePass( RawId aEncoderId, const dom::GPUComputePassDescriptor& aDesc) { MOZ_RELEASE_ASSERT(aEncoderId); ffi::WGPUComputePassDescriptor desc = {}; @@ -31,7 +31,7 @@ ffi::WGPURecordedComputePass* BeginComputePass( webgpu::StringHelper label(aDesc.mLabel); desc.label = label.Get(); - return ffi::wgpu_command_encoder_begin_compute_pass(&desc); + return ffi::wgpu_command_encoder_begin_compute_pass(aEncoderId, &desc); } ComputePassEncoder::ComputePassEncoder( @@ -49,16 +49,16 @@ void ComputePassEncoder::SetBindGroup( const dom::Sequence& aDynamicOffsets) { if (mValid) { mUsedBindGroups.AppendElement(&aBindGroup); - ffi::wgpu_recorded_compute_pass_set_bind_group( - mPass.get(), aSlot, aBindGroup.mId, aDynamicOffsets.Elements(), - aDynamicOffsets.Length()); + ffi::wgpu_compute_pass_set_bind_group(mPass.get(), aSlot, aBindGroup.mId, + aDynamicOffsets.Elements(), + aDynamicOffsets.Length()); } } void ComputePassEncoder::SetPipeline(const ComputePipeline& aPipeline) { if (mValid) { mUsedPipelines.AppendElement(&aPipeline); - ffi::wgpu_recorded_compute_pass_set_pipeline(mPass.get(), aPipeline.mId); + ffi::wgpu_compute_pass_set_pipeline(mPass.get(), aPipeline.mId); } } @@ -66,7 +66,7 @@ void ComputePassEncoder::DispatchWorkgroups(uint32_t workgroupCountX, uint32_t workgroupCountY, uint32_t workgroupCountZ) { if (mValid) { - ffi::wgpu_recorded_compute_pass_dispatch_workgroups( + ffi::wgpu_compute_pass_dispatch_workgroups( mPass.get(), workgroupCountX, workgroupCountY, workgroupCountZ); } } @@ -74,7 +74,7 @@ void ComputePassEncoder::DispatchWorkgroups(uint32_t workgroupCountX, void ComputePassEncoder::DispatchWorkgroupsIndirect( const Buffer& aIndirectBuffer, uint64_t aIndirectOffset) { if (mValid) { - ffi::wgpu_recorded_compute_pass_dispatch_workgroups_indirect( + ffi::wgpu_compute_pass_dispatch_workgroups_indirect( mPass.get(), aIndirectBuffer.mId, aIndirectOffset); } } @@ -82,20 +82,18 @@ void ComputePassEncoder::DispatchWorkgroupsIndirect( void ComputePassEncoder::PushDebugGroup(const nsAString& aString) { if (mValid) { const NS_ConvertUTF16toUTF8 utf8(aString); - ffi::wgpu_recorded_compute_pass_push_debug_group(mPass.get(), utf8.get(), - 0); + ffi::wgpu_compute_pass_push_debug_group(mPass.get(), utf8.get(), 0); } } void ComputePassEncoder::PopDebugGroup() { if (mValid) { - ffi::wgpu_recorded_compute_pass_pop_debug_group(mPass.get()); + ffi::wgpu_compute_pass_pop_debug_group(mPass.get()); } } void ComputePassEncoder::InsertDebugMarker(const nsAString& aString) { if (mValid) { const NS_ConvertUTF16toUTF8 utf8(aString); - ffi::wgpu_recorded_compute_pass_insert_debug_marker(mPass.get(), utf8.get(), - 0); + ffi::wgpu_compute_pass_insert_debug_marker(mPass.get(), utf8.get(), 0); } } diff --git a/dom/webgpu/ComputePassEncoder.h b/dom/webgpu/ComputePassEncoder.h index 2455822f790d..8160a09e2ec2 100644 --- a/dom/webgpu/ComputePassEncoder.h +++ b/dom/webgpu/ComputePassEncoder.h @@ -18,7 +18,7 @@ struct GPUComputePassDescriptor; namespace webgpu { namespace ffi { -struct WGPURecordedComputePass; +struct WGPUComputePass; } // namespace ffi class BindGroup; @@ -27,7 +27,7 @@ class CommandEncoder; class ComputePipeline; struct ffiWGPUComputePassDeleter { - void operator()(ffi::WGPURecordedComputePass*); + void operator()(ffi::WGPUComputePass*); }; class ComputePassEncoder final : public ObjectBase, @@ -43,8 +43,7 @@ class ComputePassEncoder final : public ObjectBase, virtual ~ComputePassEncoder(); void Cleanup() {} - std::unique_ptr - mPass; + std::unique_ptr mPass; // keep all the used objects alive while the pass is recorded nsTArray> mUsedBindGroups; nsTArray> mUsedPipelines; diff --git a/dom/webgpu/RenderPassEncoder.cpp b/dom/webgpu/RenderPassEncoder.cpp index bd3503ea772a..c5cb19ce151b 100644 --- a/dom/webgpu/RenderPassEncoder.cpp +++ b/dom/webgpu/RenderPassEncoder.cpp @@ -18,7 +18,7 @@ GPU_IMPL_CYCLE_COLLECTION(RenderPassEncoder, mParent, mUsedBindGroups, mUsedRenderBundles) GPU_IMPL_JS_WRAP(RenderPassEncoder) -void ffiWGPURenderPassDeleter::operator()(ffi::WGPURecordedRenderPass* raw) { +void ffiWGPURenderPassDeleter::operator()(ffi::WGPURenderPass* raw) { if (raw) { ffi::wgpu_render_pass_destroy(raw); } @@ -87,7 +87,7 @@ static ffi::WGPUColor ConvertColor( return ffi::WGPUColor(); } -ffi::WGPURecordedRenderPass* BeginRenderPass( +ffi::WGPURenderPass* BeginRenderPass( CommandEncoder* const aParent, const dom::GPURenderPassDescriptor& aDesc) { ffi::WGPURenderPassDescriptor desc = {}; @@ -155,7 +155,7 @@ ffi::WGPURecordedRenderPass* BeginRenderPass( } } - return ffi::wgpu_command_encoder_begin_render_pass(&desc); + return ffi::wgpu_command_encoder_begin_render_pass(aParent->mId, &desc); } RenderPassEncoder::RenderPassEncoder(CommandEncoder* const aParent, @@ -186,16 +186,16 @@ void RenderPassEncoder::SetBindGroup( const dom::Sequence& aDynamicOffsets) { if (mValid) { mUsedBindGroups.AppendElement(&aBindGroup); - ffi::wgpu_recorded_render_pass_set_bind_group( - mPass.get(), aSlot, aBindGroup.mId, aDynamicOffsets.Elements(), - aDynamicOffsets.Length()); + ffi::wgpu_render_pass_set_bind_group(mPass.get(), aSlot, aBindGroup.mId, + aDynamicOffsets.Elements(), + aDynamicOffsets.Length()); } } void RenderPassEncoder::SetPipeline(const RenderPipeline& aPipeline) { if (mValid) { mUsedPipelines.AppendElement(&aPipeline); - ffi::wgpu_recorded_render_pass_set_pipeline(mPass.get(), aPipeline.mId); + ffi::wgpu_render_pass_set_pipeline(mPass.get(), aPipeline.mId); } } @@ -207,8 +207,8 @@ void RenderPassEncoder::SetIndexBuffer(const Buffer& aBuffer, const auto iformat = aIndexFormat == dom::GPUIndexFormat::Uint32 ? ffi::WGPUIndexFormat_Uint32 : ffi::WGPUIndexFormat_Uint16; - ffi::wgpu_recorded_render_pass_set_index_buffer(mPass.get(), aBuffer.mId, - iformat, aOffset, aSize); + ffi::wgpu_render_pass_set_index_buffer(mPass.get(), aBuffer.mId, iformat, + aOffset, aSize); } } @@ -216,17 +216,16 @@ void RenderPassEncoder::SetVertexBuffer(uint32_t aSlot, const Buffer& aBuffer, uint64_t aOffset, uint64_t aSize) { if (mValid) { mUsedBuffers.AppendElement(&aBuffer); - ffi::wgpu_recorded_render_pass_set_vertex_buffer( - mPass.get(), aSlot, aBuffer.mId, aOffset, aSize); + ffi::wgpu_render_pass_set_vertex_buffer(mPass.get(), aSlot, aBuffer.mId, + aOffset, aSize); } } void RenderPassEncoder::Draw(uint32_t aVertexCount, uint32_t aInstanceCount, uint32_t aFirstVertex, uint32_t aFirstInstance) { if (mValid) { - ffi::wgpu_recorded_render_pass_draw(mPass.get(), aVertexCount, - aInstanceCount, aFirstVertex, - aFirstInstance); + ffi::wgpu_render_pass_draw(mPass.get(), aVertexCount, aInstanceCount, + aFirstVertex, aFirstInstance); } } @@ -235,24 +234,24 @@ void RenderPassEncoder::DrawIndexed(uint32_t aIndexCount, uint32_t aFirstIndex, int32_t aBaseVertex, uint32_t aFirstInstance) { if (mValid) { - ffi::wgpu_recorded_render_pass_draw_indexed(mPass.get(), aIndexCount, - aInstanceCount, aFirstIndex, - aBaseVertex, aFirstInstance); + ffi::wgpu_render_pass_draw_indexed(mPass.get(), aIndexCount, aInstanceCount, + aFirstIndex, aBaseVertex, + aFirstInstance); } } void RenderPassEncoder::DrawIndirect(const Buffer& aIndirectBuffer, uint64_t aIndirectOffset) { if (mValid) { - ffi::wgpu_recorded_render_pass_draw_indirect( - mPass.get(), aIndirectBuffer.mId, aIndirectOffset); + ffi::wgpu_render_pass_draw_indirect(mPass.get(), aIndirectBuffer.mId, + aIndirectOffset); } } void RenderPassEncoder::DrawIndexedIndirect(const Buffer& aIndirectBuffer, uint64_t aIndirectOffset) { if (mValid) { - ffi::wgpu_recorded_render_pass_draw_indexed_indirect( + ffi::wgpu_render_pass_draw_indexed_indirect( mPass.get(), aIndirectBuffer.mId, aIndirectOffset); } } @@ -260,16 +259,15 @@ void RenderPassEncoder::DrawIndexedIndirect(const Buffer& aIndirectBuffer, void RenderPassEncoder::SetViewport(float x, float y, float width, float height, float minDepth, float maxDepth) { if (mValid) { - ffi::wgpu_recorded_render_pass_set_viewport(mPass.get(), x, y, width, - height, minDepth, maxDepth); + ffi::wgpu_render_pass_set_viewport(mPass.get(), x, y, width, height, + minDepth, maxDepth); } } void RenderPassEncoder::SetScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { if (mValid) { - ffi::wgpu_recorded_render_pass_set_scissor_rect(mPass.get(), x, y, width, - height); + ffi::wgpu_render_pass_set_scissor_rect(mPass.get(), x, y, width, height); } } @@ -277,14 +275,13 @@ void RenderPassEncoder::SetBlendConstant( const dom::DoubleSequenceOrGPUColorDict& color) { if (mValid) { ffi::WGPUColor aColor = ConvertColor(color); - ffi::wgpu_recorded_render_pass_set_blend_constant(mPass.get(), &aColor); + ffi::wgpu_render_pass_set_blend_constant(mPass.get(), &aColor); } } void RenderPassEncoder::SetStencilReference(uint32_t reference) { if (mValid) { - ffi::wgpu_recorded_render_pass_set_stencil_reference(mPass.get(), - reference); + ffi::wgpu_render_pass_set_stencil_reference(mPass.get(), reference); } } @@ -296,27 +293,26 @@ void RenderPassEncoder::ExecuteBundles( mUsedRenderBundles.AppendElement(bundle); renderBundles.AppendElement(bundle->mId); } - ffi::wgpu_recorded_render_pass_execute_bundles( - mPass.get(), renderBundles.Elements(), renderBundles.Length()); + ffi::wgpu_render_pass_execute_bundles(mPass.get(), renderBundles.Elements(), + renderBundles.Length()); } } void RenderPassEncoder::PushDebugGroup(const nsAString& aString) { if (mValid) { const NS_ConvertUTF16toUTF8 utf8(aString); - ffi::wgpu_recorded_render_pass_push_debug_group(mPass.get(), utf8.get(), 0); + ffi::wgpu_render_pass_push_debug_group(mPass.get(), utf8.get(), 0); } } void RenderPassEncoder::PopDebugGroup() { if (mValid) { - ffi::wgpu_recorded_render_pass_pop_debug_group(mPass.get()); + ffi::wgpu_render_pass_pop_debug_group(mPass.get()); } } void RenderPassEncoder::InsertDebugMarker(const nsAString& aString) { if (mValid) { const NS_ConvertUTF16toUTF8 utf8(aString); - ffi::wgpu_recorded_render_pass_insert_debug_marker(mPass.get(), utf8.get(), - 0); + ffi::wgpu_render_pass_insert_debug_marker(mPass.get(), utf8.get(), 0); } } diff --git a/dom/webgpu/RenderPassEncoder.h b/dom/webgpu/RenderPassEncoder.h index 875535bdce72..5ca414b4ea37 100644 --- a/dom/webgpu/RenderPassEncoder.h +++ b/dom/webgpu/RenderPassEncoder.h @@ -35,7 +35,7 @@ class RenderPipeline; class TextureView; struct ffiWGPURenderPassDeleter { - void operator()(ffi::WGPURecordedRenderPass*); + void operator()(ffi::WGPURenderPass*); }; class RenderPassEncoder final : public ObjectBase, @@ -51,7 +51,7 @@ class RenderPassEncoder final : public ObjectBase, virtual ~RenderPassEncoder(); void Cleanup() {} - std::unique_ptr mPass; + std::unique_ptr mPass; // keep all the used objects alive while the pass is recorded nsTArray> mUsedBindGroups; nsTArray> mUsedBuffers; diff --git a/dom/webgpu/ipc/PWebGPU.ipdl b/dom/webgpu/ipc/PWebGPU.ipdl index 451480a1c39d..5146dd68265b 100644 --- a/dom/webgpu/ipc/PWebGPU.ipdl +++ b/dom/webgpu/ipc/PWebGPU.ipdl @@ -44,8 +44,6 @@ parent: async DeviceActionWithAck(RawId selfId, ByteBuf buf) returns (bool dummy); async TextureAction(RawId selfId, RawId aDeviceId, ByteBuf buf); async CommandEncoderAction(RawId selfId, RawId aDeviceId, ByteBuf buf); - async RenderPass(RawId selfId, RawId aDeviceId, ByteBuf buf); - async ComputePass(RawId selfId, RawId aDeviceId, ByteBuf buf); async BumpImplicitBindGroupLayout(RawId pipelineId, bool isCompute, uint32_t index, RawId assignId); async DeviceCreateBuffer(RawId deviceId, RawId bufferId, GPUBufferDescriptor desc, UnsafeSharedMemoryHandle shm); diff --git a/dom/webgpu/ipc/WebGPUParent.cpp b/dom/webgpu/ipc/WebGPUParent.cpp index dceed2cef6f2..6603343b91c3 100644 --- a/dom/webgpu/ipc/WebGPUParent.cpp +++ b/dom/webgpu/ipc/WebGPUParent.cpp @@ -1341,24 +1341,6 @@ ipc::IPCResult WebGPUParent::RecvCommandEncoderAction( return IPC_OK(); } -ipc::IPCResult WebGPUParent::RecvRenderPass(RawId aEncoderId, RawId aDeviceId, - const ipc::ByteBuf& aByteBuf) { - ErrorBuffer error; - ffi::wgpu_server_render_pass(mContext.get(), aEncoderId, ToFFI(&aByteBuf), - error.ToFFI()); - ForwardError(aDeviceId, error); - return IPC_OK(); -} - -ipc::IPCResult WebGPUParent::RecvComputePass(RawId aEncoderId, RawId aDeviceId, - const ipc::ByteBuf& aByteBuf) { - ErrorBuffer error; - ffi::wgpu_server_compute_pass(mContext.get(), aEncoderId, ToFFI(&aByteBuf), - error.ToFFI()); - ForwardError(aDeviceId, error); - return IPC_OK(); -} - ipc::IPCResult WebGPUParent::RecvBumpImplicitBindGroupLayout(RawId aPipelineId, bool aIsCompute, uint32_t aIndex, diff --git a/dom/webgpu/ipc/WebGPUParent.h b/dom/webgpu/ipc/WebGPUParent.h index 457079807fe0..b83d9d496a3e 100644 --- a/dom/webgpu/ipc/WebGPUParent.h +++ b/dom/webgpu/ipc/WebGPUParent.h @@ -118,10 +118,6 @@ class WebGPUParent final : public PWebGPUParent, public SupportsWeakPtr { const ipc::ByteBuf& aByteBuf); ipc::IPCResult RecvCommandEncoderAction(RawId aEncoderId, RawId aDeviceId, const ipc::ByteBuf& aByteBuf); - ipc::IPCResult RecvRenderPass(RawId aEncoderId, RawId aDeviceId, - const ipc::ByteBuf& aByteBuf); - ipc::IPCResult RecvComputePass(RawId aEncoderId, RawId aDeviceId, - const ipc::ByteBuf& aByteBuf); ipc::IPCResult RecvBumpImplicitBindGroupLayout(RawId aPipelineId, bool aIsCompute, uint32_t aIndex, diff --git a/gfx/wgpu_bindings/Cargo.toml b/gfx/wgpu_bindings/Cargo.toml index fcb79ea62b5b..b24d09a95558 100644 --- a/gfx/wgpu_bindings/Cargo.toml +++ b/gfx/wgpu_bindings/Cargo.toml @@ -68,4 +68,3 @@ parking_lot = "0.12" serde = "1" nsstring = { path = "../../xpcom/rust/nsstring" } static_prefs = { path = "../../modules/libpref/init/static_prefs" } -arrayvec = "0.7" diff --git a/gfx/wgpu_bindings/src/client.rs b/gfx/wgpu_bindings/src/client.rs index cafa6ce90ae9..bf53a8c87162 100644 --- a/gfx/wgpu_bindings/src/client.rs +++ b/gfx/wgpu_bindings/src/client.rs @@ -769,8 +769,9 @@ pub struct ComputePassTimestampWrites<'a> { #[no_mangle] pub unsafe extern "C" fn wgpu_command_encoder_begin_compute_pass( + encoder_id: id::CommandEncoderId, desc: &ComputePassDescriptor, -) -> *mut crate::command::RecordedComputePass { +) -> *mut wgc::command::ComputePass { let &ComputePassDescriptor { label, timestamp_writes, @@ -794,24 +795,27 @@ pub unsafe extern "C" fn wgpu_command_encoder_begin_compute_pass( }); let timestamp_writes = timestamp_writes.as_ref(); - let pass = crate::command::RecordedComputePass::new(&wgc::command::ComputePassDescriptor { - label, - timestamp_writes, - }); + let pass = wgc::command::ComputePass::new( + encoder_id, + &wgc::command::ComputePassDescriptor { + label, + timestamp_writes, + }, + ); Box::into_raw(Box::new(pass)) } #[no_mangle] pub unsafe extern "C" fn wgpu_compute_pass_finish( - pass: *mut crate::command::RecordedComputePass, + pass: *mut wgc::command::ComputePass, output: &mut ByteBuf, ) { - let command = Box::from_raw(pass); + let command = Box::from_raw(pass).into_command(); *output = make_byte_buf(&command); } #[no_mangle] -pub unsafe extern "C" fn wgpu_compute_pass_destroy(pass: *mut crate::command::RecordedComputePass) { +pub unsafe extern "C" fn wgpu_compute_pass_destroy(pass: *mut wgc::command::ComputePass) { let _ = Box::from_raw(pass); } @@ -834,8 +838,9 @@ pub struct RenderPassTimestampWrites<'a> { #[no_mangle] pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass( + encoder_id: id::CommandEncoderId, desc: &RenderPassDescriptor, -) -> *mut crate::command::RecordedRenderPass { +) -> *mut wgc::command::RenderPass { let &RenderPassDescriptor { label, color_attachments, @@ -868,27 +873,30 @@ pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass( .iter() .map(|format| Some(format.clone())) .collect(); - let pass = crate::command::RecordedRenderPass::new(&wgc::command::RenderPassDescriptor { - label, - color_attachments: Cow::Owned(color_attachments), - depth_stencil_attachment: depth_stencil_attachment.as_ref(), - timestamp_writes, - occlusion_query_set, - }); + let pass = wgc::command::RenderPass::new( + encoder_id, + &wgc::command::RenderPassDescriptor { + label, + color_attachments: Cow::Owned(color_attachments), + depth_stencil_attachment: depth_stencil_attachment.as_ref(), + timestamp_writes, + occlusion_query_set, + }, + ); Box::into_raw(Box::new(pass)) } #[no_mangle] pub unsafe extern "C" fn wgpu_render_pass_finish( - pass: *mut crate::command::RecordedRenderPass, + pass: *mut wgc::command::RenderPass, output: &mut ByteBuf, ) { - let command = Box::from_raw(pass); + let command = Box::from_raw(pass).into_command(); *output = make_byte_buf(&command); } #[no_mangle] -pub unsafe extern "C" fn wgpu_render_pass_destroy(pass: *mut crate::command::RecordedRenderPass) { +pub unsafe extern "C" fn wgpu_render_pass_destroy(pass: *mut wgc::command::RenderPass) { let _ = Box::from_raw(pass); } diff --git a/gfx/wgpu_bindings/src/command.rs b/gfx/wgpu_bindings/src/command.rs deleted file mode 100644 index 9b664283ecd7..000000000000 --- a/gfx/wgpu_bindings/src/command.rs +++ /dev/null @@ -1,1079 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use crate::{id, RawString}; -use std::{borrow::Cow, ffi, slice}; -use wgc::{ - command::{ - compute_ffi, render_ffi, ComputePassDescriptor, ComputePassTimestampWrites, - RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor, - RenderPassTimestampWrites, - }, - id::CommandEncoderId, -}; -use wgt::{BufferAddress, BufferSize, Color, DynamicOffset, IndexFormat}; - -use arrayvec::ArrayVec; -use serde::{Deserialize, Serialize}; - -/// A stream of commands for a render pass or compute pass. -/// -/// This also contains side tables referred to by certain commands, -/// like dynamic offsets for [`SetBindGroup`] or string data for -/// [`InsertDebugMarker`]. -/// -/// Render passes use `BasePass`, whereas compute -/// passes use `BasePass`. -/// -/// [`SetBindGroup`]: RenderCommand::SetBindGroup -/// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker -#[doc(hidden)] -#[derive(Debug, serde::Serialize, serde::Deserialize)] -pub struct BasePass { - pub label: Option, - - /// The stream of commands. - pub commands: Vec, - - /// Dynamic offsets consumed by [`SetBindGroup`] commands in `commands`. - /// - /// Each successive `SetBindGroup` consumes the next - /// [`num_dynamic_offsets`] values from this list. - pub dynamic_offsets: Vec, - - /// Strings used by debug instructions. - /// - /// Each successive [`PushDebugGroup`] or [`InsertDebugMarker`] - /// instruction consumes the next `len` bytes from this vector. - pub string_data: Vec, -} - -#[derive(Deserialize, Serialize)] -pub struct RecordedRenderPass { - base: BasePass, - color_attachments: ArrayVec, { wgh::MAX_COLOR_ATTACHMENTS }>, - depth_stencil_attachment: Option, - timestamp_writes: Option, - occlusion_query_set_id: Option, -} - -impl RecordedRenderPass { - pub fn new(desc: &RenderPassDescriptor) -> Self { - Self { - base: BasePass { - label: desc.label.as_ref().map(|cow| cow.to_string()), - commands: Vec::new(), - dynamic_offsets: Vec::new(), - string_data: Vec::new(), - }, - color_attachments: desc.color_attachments.iter().cloned().collect(), - depth_stencil_attachment: desc.depth_stencil_attachment.cloned(), - timestamp_writes: desc.timestamp_writes.cloned(), - occlusion_query_set_id: desc.occlusion_query_set, - } - } -} - -#[derive(serde::Deserialize, serde::Serialize)] -pub struct RecordedComputePass { - base: BasePass, - timestamp_writes: Option, -} - -impl RecordedComputePass { - pub fn new(desc: &ComputePassDescriptor) -> Self { - Self { - base: BasePass { - label: desc.label.as_ref().map(|cow| cow.to_string()), - commands: Vec::new(), - dynamic_offsets: Vec::new(), - string_data: Vec::new(), - }, - timestamp_writes: desc.timestamp_writes.cloned(), - } - } -} - -#[doc(hidden)] -#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] -pub enum RenderCommand { - SetBindGroup { - index: u32, - num_dynamic_offsets: usize, - bind_group_id: id::BindGroupId, - }, - SetPipeline(id::RenderPipelineId), - SetIndexBuffer { - buffer_id: id::BufferId, - index_format: wgt::IndexFormat, - offset: BufferAddress, - size: Option, - }, - SetVertexBuffer { - slot: u32, - buffer_id: id::BufferId, - offset: BufferAddress, - size: Option, - }, - SetBlendConstant(Color), - SetStencilReference(u32), - SetViewport { - x: f32, - y: f32, - w: f32, - h: f32, - depth_min: f32, - depth_max: f32, - }, - SetScissor { - x: u32, - y: u32, - w: u32, - h: u32, - }, - Draw { - vertex_count: u32, - instance_count: u32, - first_vertex: u32, - first_instance: u32, - }, - DrawIndexed { - index_count: u32, - instance_count: u32, - first_index: u32, - base_vertex: i32, - first_instance: u32, - }, - MultiDrawIndirect { - buffer_id: id::BufferId, - offset: BufferAddress, - /// Count of `None` represents a non-multi call. - count: Option, - indexed: bool, - }, - MultiDrawIndirectCount { - buffer_id: id::BufferId, - offset: BufferAddress, - count_buffer_id: id::BufferId, - count_buffer_offset: BufferAddress, - max_count: u32, - indexed: bool, - }, - PushDebugGroup { - color: u32, - len: usize, - }, - PopDebugGroup, - InsertDebugMarker { - color: u32, - len: usize, - }, - WriteTimestamp { - query_set_id: id::QuerySetId, - query_index: u32, - }, - BeginOcclusionQuery { - query_index: u32, - }, - EndOcclusionQuery, - BeginPipelineStatisticsQuery { - query_set_id: id::QuerySetId, - query_index: u32, - }, - EndPipelineStatisticsQuery, - ExecuteBundle(id::RenderBundleId), -} - -#[doc(hidden)] -#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] -pub enum ComputeCommand { - SetBindGroup { - index: u32, - num_dynamic_offsets: usize, - bind_group_id: id::BindGroupId, - }, - SetPipeline(id::ComputePipelineId), - Dispatch([u32; 3]), - DispatchIndirect { - buffer_id: id::BufferId, - offset: wgt::BufferAddress, - }, - PushDebugGroup { - color: u32, - len: usize, - }, - PopDebugGroup, - InsertDebugMarker { - color: u32, - len: usize, - }, - WriteTimestamp { - query_set_id: id::QuerySetId, - query_index: u32, - }, - BeginPipelineStatisticsQuery { - query_set_id: id::QuerySetId, - query_index: u32, - }, - EndPipelineStatisticsQuery, -} - -/// # Safety -/// -/// This function is unsafe as there is no guarantee that the given pointer is -/// valid for `offset_length` elements. -#[no_mangle] -pub unsafe extern "C" fn wgpu_recorded_render_pass_set_bind_group( - pass: &mut RecordedRenderPass, - index: u32, - bind_group_id: id::BindGroupId, - offsets: *const DynamicOffset, - offset_length: usize, -) { - pass.base - .dynamic_offsets - .extend_from_slice(unsafe { slice::from_raw_parts(offsets, offset_length) }); - - pass.base.commands.push(RenderCommand::SetBindGroup { - index, - num_dynamic_offsets: offset_length, - bind_group_id, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_pipeline( - pass: &mut RecordedRenderPass, - pipeline_id: id::RenderPipelineId, -) { - pass.base - .commands - .push(RenderCommand::SetPipeline(pipeline_id)); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_vertex_buffer( - pass: &mut RecordedRenderPass, - slot: u32, - buffer_id: id::BufferId, - offset: BufferAddress, - size: Option, -) { - pass.base.commands.push(RenderCommand::SetVertexBuffer { - slot, - buffer_id, - offset, - size, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_index_buffer( - pass: &mut RecordedRenderPass, - buffer_id: id::BufferId, - index_format: IndexFormat, - offset: BufferAddress, - size: Option, -) { - pass.base.commands.push(RenderCommand::SetIndexBuffer { - buffer_id, - index_format, - offset, - size, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_blend_constant( - pass: &mut RecordedRenderPass, - color: &Color, -) { - pass.base - .commands - .push(RenderCommand::SetBlendConstant(*color)); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_stencil_reference( - pass: &mut RecordedRenderPass, - value: u32, -) { - pass.base - .commands - .push(RenderCommand::SetStencilReference(value)); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_viewport( - pass: &mut RecordedRenderPass, - x: f32, - y: f32, - w: f32, - h: f32, - depth_min: f32, - depth_max: f32, -) { - pass.base.commands.push(RenderCommand::SetViewport { - x, - y, - w, - h, - depth_min, - depth_max, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_scissor_rect( - pass: &mut RecordedRenderPass, - x: u32, - y: u32, - w: u32, - h: u32, -) { - pass.base - .commands - .push(RenderCommand::SetScissor { x, y, w, h }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_draw( - pass: &mut RecordedRenderPass, - vertex_count: u32, - instance_count: u32, - first_vertex: u32, - first_instance: u32, -) { - pass.base.commands.push(RenderCommand::Draw { - vertex_count, - instance_count, - first_vertex, - first_instance, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_draw_indexed( - pass: &mut RecordedRenderPass, - index_count: u32, - instance_count: u32, - first_index: u32, - base_vertex: i32, - first_instance: u32, -) { - pass.base.commands.push(RenderCommand::DrawIndexed { - index_count, - instance_count, - first_index, - base_vertex, - first_instance, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_draw_indirect( - pass: &mut RecordedRenderPass, - buffer_id: id::BufferId, - offset: BufferAddress, -) { - pass.base.commands.push(RenderCommand::MultiDrawIndirect { - buffer_id, - offset, - count: None, - indexed: false, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_draw_indexed_indirect( - pass: &mut RecordedRenderPass, - buffer_id: id::BufferId, - offset: BufferAddress, -) { - pass.base.commands.push(RenderCommand::MultiDrawIndirect { - buffer_id, - offset, - count: None, - indexed: true, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_multi_draw_indirect( - pass: &mut RecordedRenderPass, - buffer_id: id::BufferId, - offset: BufferAddress, - count: u32, -) { - pass.base.commands.push(RenderCommand::MultiDrawIndirect { - buffer_id, - offset, - count: Some(count), - indexed: false, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_multi_draw_indexed_indirect( - pass: &mut RecordedRenderPass, - buffer_id: id::BufferId, - offset: BufferAddress, - count: u32, -) { - pass.base.commands.push(RenderCommand::MultiDrawIndirect { - buffer_id, - offset, - count: Some(count), - indexed: true, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_multi_draw_indirect_count( - pass: &mut RecordedRenderPass, - buffer_id: id::BufferId, - offset: BufferAddress, - count_buffer_id: id::BufferId, - count_buffer_offset: BufferAddress, - max_count: u32, -) { - pass.base - .commands - .push(RenderCommand::MultiDrawIndirectCount { - buffer_id, - offset, - count_buffer_id, - count_buffer_offset, - max_count, - indexed: false, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_multi_draw_indexed_indirect_count( - pass: &mut RecordedRenderPass, - buffer_id: id::BufferId, - offset: BufferAddress, - count_buffer_id: id::BufferId, - count_buffer_offset: BufferAddress, - max_count: u32, -) { - pass.base - .commands - .push(RenderCommand::MultiDrawIndirectCount { - buffer_id, - offset, - count_buffer_id, - count_buffer_offset, - max_count, - indexed: true, - }); -} - -/// # Safety -/// -/// This function is unsafe as there is no guarantee that the given `label` -/// is a valid null-terminated string. -#[no_mangle] -pub unsafe extern "C" fn wgpu_recorded_render_pass_push_debug_group( - pass: &mut RecordedRenderPass, - label: RawString, - color: u32, -) { - let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes(); - pass.base.string_data.extend_from_slice(bytes); - - pass.base.commands.push(RenderCommand::PushDebugGroup { - color, - len: bytes.len(), - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_pop_debug_group(pass: &mut RecordedRenderPass) { - pass.base.commands.push(RenderCommand::PopDebugGroup); -} - -/// # Safety -/// -/// This function is unsafe as there is no guarantee that the given `label` -/// is a valid null-terminated string. -#[no_mangle] -pub unsafe extern "C" fn wgpu_recorded_render_pass_insert_debug_marker( - pass: &mut RecordedRenderPass, - label: RawString, - color: u32, -) { - let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes(); - pass.base.string_data.extend_from_slice(bytes); - - pass.base.commands.push(RenderCommand::InsertDebugMarker { - color, - len: bytes.len(), - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_write_timestamp( - pass: &mut RecordedRenderPass, - query_set_id: id::QuerySetId, - query_index: u32, -) { - pass.base.commands.push(RenderCommand::WriteTimestamp { - query_set_id, - query_index, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_begin_occlusion_query( - pass: &mut RecordedRenderPass, - query_index: u32, -) { - pass.base - .commands - .push(RenderCommand::BeginOcclusionQuery { query_index }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_end_occlusion_query(pass: &mut RecordedRenderPass) { - pass.base.commands.push(RenderCommand::EndOcclusionQuery); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_begin_pipeline_statistics_query( - pass: &mut RecordedRenderPass, - query_set_id: id::QuerySetId, - query_index: u32, -) { - pass.base - .commands - .push(RenderCommand::BeginPipelineStatisticsQuery { - query_set_id, - query_index, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_end_pipeline_statistics_query( - pass: &mut RecordedRenderPass, -) { - pass.base - .commands - .push(RenderCommand::EndPipelineStatisticsQuery); -} - -/// # Safety -/// -/// This function is unsafe as there is no guarantee that the given pointer is -/// valid for `render_bundle_ids_length` elements. -#[no_mangle] -pub unsafe extern "C" fn wgpu_recorded_render_pass_execute_bundles( - pass: &mut RecordedRenderPass, - render_bundle_ids: *const id::RenderBundleId, - render_bundle_ids_length: usize, -) { - for &bundle_id in unsafe { slice::from_raw_parts(render_bundle_ids, render_bundle_ids_length) } - { - pass.base - .commands - .push(RenderCommand::ExecuteBundle(bundle_id)); - } -} - -/// # Safety -/// -/// This function is unsafe as there is no guarantee that the given pointer is -/// valid for `offset_length` elements. -#[no_mangle] -pub unsafe extern "C" fn wgpu_recorded_compute_pass_set_bind_group( - pass: &mut RecordedComputePass, - index: u32, - bind_group_id: id::BindGroupId, - offsets: *const DynamicOffset, - offset_length: usize, -) { - pass.base - .dynamic_offsets - .extend_from_slice(unsafe { slice::from_raw_parts(offsets, offset_length) }); - - pass.base.commands.push(ComputeCommand::SetBindGroup { - index, - num_dynamic_offsets: offset_length, - bind_group_id, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_set_pipeline( - pass: &mut RecordedComputePass, - pipeline_id: id::ComputePipelineId, -) { - pass.base - .commands - .push(ComputeCommand::SetPipeline(pipeline_id)); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_dispatch_workgroups( - pass: &mut RecordedComputePass, - groups_x: u32, - groups_y: u32, - groups_z: u32, -) { - pass.base - .commands - .push(ComputeCommand::Dispatch([groups_x, groups_y, groups_z])); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_dispatch_workgroups_indirect( - pass: &mut RecordedComputePass, - buffer_id: id::BufferId, - offset: BufferAddress, -) { - pass.base - .commands - .push(ComputeCommand::DispatchIndirect { buffer_id, offset }); -} - -/// # Safety -/// -/// This function is unsafe as there is no guarantee that the given `label` -/// is a valid null-terminated string. -#[no_mangle] -pub unsafe extern "C" fn wgpu_recorded_compute_pass_push_debug_group( - pass: &mut RecordedComputePass, - label: RawString, - color: u32, -) { - let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes(); - pass.base.string_data.extend_from_slice(bytes); - - pass.base.commands.push(ComputeCommand::PushDebugGroup { - color, - len: bytes.len(), - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_pop_debug_group(pass: &mut RecordedComputePass) { - pass.base.commands.push(ComputeCommand::PopDebugGroup); -} - -/// # Safety -/// -/// This function is unsafe as there is no guarantee that the given `label` -/// is a valid null-terminated string. -#[no_mangle] -pub unsafe extern "C" fn wgpu_recorded_compute_pass_insert_debug_marker( - pass: &mut RecordedComputePass, - label: RawString, - color: u32, -) { - let bytes = unsafe { ffi::CStr::from_ptr(label) }.to_bytes(); - pass.base.string_data.extend_from_slice(bytes); - - pass.base.commands.push(ComputeCommand::InsertDebugMarker { - color, - len: bytes.len(), - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_write_timestamp( - pass: &mut RecordedComputePass, - query_set_id: id::QuerySetId, - query_index: u32, -) { - pass.base.commands.push(ComputeCommand::WriteTimestamp { - query_set_id, - query_index, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_begin_pipeline_statistics_query( - pass: &mut RecordedComputePass, - query_set_id: id::QuerySetId, - query_index: u32, -) { - pass.base - .commands - .push(ComputeCommand::BeginPipelineStatisticsQuery { - query_set_id, - query_index, - }); -} - -#[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_end_pipeline_statistics_query( - pass: &mut RecordedComputePass, -) { - pass.base - .commands - .push(ComputeCommand::EndPipelineStatisticsQuery); -} - -pub fn replay_render_pass( - id: CommandEncoderId, - src_pass: &RecordedRenderPass, -) -> wgc::command::RenderPass { - let mut dst_pass = wgc::command::RenderPass::new( - id, - &wgc::command::RenderPassDescriptor { - label: src_pass.base.label.as_ref().map(|s| s.as_str().into()), - color_attachments: Cow::Borrowed(&src_pass.color_attachments), - depth_stencil_attachment: src_pass.depth_stencil_attachment.as_ref(), - timestamp_writes: src_pass.timestamp_writes.as_ref(), - occlusion_query_set: src_pass.occlusion_query_set_id, - }, - ); - - let mut dynamic_offsets = src_pass.base.dynamic_offsets.as_slice(); - let mut dynamic_offsets = |len| { - let offsets; - (offsets, dynamic_offsets) = dynamic_offsets.split_at(len); - offsets - }; - let mut strings = src_pass.base.string_data.as_slice(); - let mut strings = |len| { - let label; - (label, strings) = strings.split_at(len); - label - }; - for command in &src_pass.base.commands { - match *command { - RenderCommand::SetBindGroup { - index, - num_dynamic_offsets, - bind_group_id, - } => { - let offsets = dynamic_offsets(num_dynamic_offsets); - unsafe { - render_ffi::wgpu_render_pass_set_bind_group( - &mut dst_pass, - index, - bind_group_id, - offsets.as_ptr(), - offsets.len(), - ); - } - } - RenderCommand::SetPipeline(pipeline_id) => { - render_ffi::wgpu_render_pass_set_pipeline(&mut dst_pass, pipeline_id); - } - RenderCommand::SetIndexBuffer { - buffer_id, - index_format, - offset, - size, - } => { - render_ffi::wgpu_render_pass_set_index_buffer( - &mut dst_pass, - buffer_id, - index_format, - offset, - size, - ); - } - RenderCommand::SetVertexBuffer { - slot, - buffer_id, - offset, - size, - } => render_ffi::wgpu_render_pass_set_vertex_buffer( - &mut dst_pass, - slot, - buffer_id, - offset, - size, - ), - RenderCommand::SetBlendConstant(ref color) => { - render_ffi::wgpu_render_pass_set_blend_constant(&mut dst_pass, color); - } - RenderCommand::SetStencilReference(value) => { - render_ffi::wgpu_render_pass_set_stencil_reference(&mut dst_pass, value); - } - RenderCommand::SetViewport { - x, - y, - w, - h, - depth_min, - depth_max, - } => { - render_ffi::wgpu_render_pass_set_viewport( - &mut dst_pass, - x, - y, - w, - h, - depth_min, - depth_max, - ); - } - RenderCommand::SetScissor { x, y, w, h } => { - render_ffi::wgpu_render_pass_set_scissor_rect(&mut dst_pass, x, y, w, h); - } - RenderCommand::Draw { - vertex_count, - instance_count, - first_vertex, - first_instance, - } => { - render_ffi::wgpu_render_pass_draw( - &mut dst_pass, - vertex_count, - instance_count, - first_vertex, - first_instance, - ); - } - RenderCommand::DrawIndexed { - index_count, - instance_count, - first_index, - base_vertex, - first_instance, - } => { - render_ffi::wgpu_render_pass_draw_indexed( - &mut dst_pass, - index_count, - instance_count, - first_index, - base_vertex, - first_instance, - ); - } - RenderCommand::MultiDrawIndirect { - buffer_id, - offset, - count, - indexed, - } => { - match (indexed, count) { - (false, Some(count)) => render_ffi::wgpu_render_pass_multi_draw_indirect( - &mut dst_pass, - buffer_id, - offset, - count, - ), - (false, None) => { - render_ffi::wgpu_render_pass_draw_indirect(&mut dst_pass, buffer_id, offset) - } - (true, Some(count)) => { - render_ffi::wgpu_render_pass_multi_draw_indexed_indirect( - &mut dst_pass, - buffer_id, - offset, - count, - ) - } - (true, None) => render_ffi::wgpu_render_pass_draw_indexed_indirect( - &mut dst_pass, - buffer_id, - offset, - ), - }; - } - RenderCommand::MultiDrawIndirectCount { - buffer_id, - offset, - count_buffer_id, - count_buffer_offset, - max_count, - indexed, - } => { - if indexed { - render_ffi::wgpu_render_pass_multi_draw_indexed_indirect_count( - &mut dst_pass, - buffer_id, - offset, - count_buffer_id, - count_buffer_offset, - max_count, - ); - } else { - render_ffi::wgpu_render_pass_multi_draw_indirect_count( - &mut dst_pass, - buffer_id, - offset, - count_buffer_id, - count_buffer_offset, - max_count, - ); - } - } - RenderCommand::PushDebugGroup { color, len } => { - let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - render_ffi::wgpu_render_pass_push_debug_group( - &mut dst_pass, - label.as_ptr(), - color, - ); - } - } - RenderCommand::PopDebugGroup => { - render_ffi::wgpu_render_pass_pop_debug_group(&mut dst_pass); - } - RenderCommand::InsertDebugMarker { color, len } => { - let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - render_ffi::wgpu_render_pass_insert_debug_marker( - &mut dst_pass, - label.as_ptr(), - color, - ); - } - } - RenderCommand::WriteTimestamp { - query_set_id, - query_index, - } => { - render_ffi::wgpu_render_pass_write_timestamp( - &mut dst_pass, - query_set_id, - query_index, - ); - } - RenderCommand::BeginOcclusionQuery { query_index } => { - render_ffi::wgpu_render_pass_begin_occlusion_query(&mut dst_pass, query_index); - } - RenderCommand::EndOcclusionQuery => { - render_ffi::wgpu_render_pass_end_occlusion_query(&mut dst_pass); - } - RenderCommand::BeginPipelineStatisticsQuery { - query_set_id, - query_index, - } => { - render_ffi::wgpu_render_pass_begin_pipeline_statistics_query( - &mut dst_pass, - query_set_id, - query_index, - ); - } - RenderCommand::EndPipelineStatisticsQuery => { - render_ffi::wgpu_render_pass_end_pipeline_statistics_query(&mut dst_pass); - } - RenderCommand::ExecuteBundle(bundle_id) => unsafe { - render_ffi::wgpu_render_pass_execute_bundles(&mut dst_pass, &bundle_id, 1); - }, - } - } - - dst_pass -} - -pub fn replay_compute_pass( - id: CommandEncoderId, - src_pass: &RecordedComputePass, -) -> wgc::command::ComputePass { - let mut dst_pass = wgc::command::ComputePass::new( - id, - &wgc::command::ComputePassDescriptor { - label: src_pass.base.label.as_ref().map(|s| s.as_str().into()), - timestamp_writes: src_pass.timestamp_writes.as_ref(), - }, - ); - - let mut dynamic_offsets = src_pass.base.dynamic_offsets.as_slice(); - let mut dynamic_offsets = |len| { - let offsets; - (offsets, dynamic_offsets) = dynamic_offsets.split_at(len); - offsets - }; - let mut strings = src_pass.base.string_data.as_slice(); - let mut strings = |len| { - let label; - (label, strings) = strings.split_at(len); - label - }; - for command in &src_pass.base.commands { - match *command { - ComputeCommand::SetBindGroup { - index, - num_dynamic_offsets, - bind_group_id, - } => { - let offsets = dynamic_offsets(num_dynamic_offsets); - unsafe { - compute_ffi::wgpu_compute_pass_set_bind_group( - &mut dst_pass, - index, - bind_group_id, - offsets.as_ptr(), - offsets.len(), - ); - } - } - ComputeCommand::SetPipeline(pipeline_id) => { - compute_ffi::wgpu_compute_pass_set_pipeline(&mut dst_pass, pipeline_id) - } - ComputeCommand::Dispatch([x, y, z]) => { - compute_ffi::wgpu_compute_pass_dispatch_workgroups(&mut dst_pass, x, y, z); - } - ComputeCommand::DispatchIndirect { buffer_id, offset } => { - compute_ffi::wgpu_compute_pass_dispatch_workgroups_indirect( - &mut dst_pass, - buffer_id, - offset, - ); - } - ComputeCommand::PushDebugGroup { color, len } => { - let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - compute_ffi::wgpu_compute_pass_push_debug_group( - &mut dst_pass, - label.as_ptr(), - color, - ); - } - } - ComputeCommand::PopDebugGroup => { - compute_ffi::wgpu_compute_pass_pop_debug_group(&mut dst_pass); - } - ComputeCommand::InsertDebugMarker { color, len } => { - let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - compute_ffi::wgpu_compute_pass_insert_debug_marker( - &mut dst_pass, - label.as_ptr(), - color, - ); - } - } - ComputeCommand::WriteTimestamp { - query_set_id, - query_index, - } => { - compute_ffi::wgpu_compute_pass_write_timestamp( - &mut dst_pass, - query_set_id, - query_index, - ); - } - ComputeCommand::BeginPipelineStatisticsQuery { - query_set_id, - query_index, - } => { - compute_ffi::wgpu_compute_pass_begin_pipeline_statistics_query( - &mut dst_pass, - query_set_id, - query_index, - ); - } - ComputeCommand::EndPipelineStatisticsQuery => { - compute_ffi::wgpu_compute_pass_end_pipeline_statistics_query(&mut dst_pass); - } - } - } - - dst_pass -} diff --git a/gfx/wgpu_bindings/src/lib.rs b/gfx/wgpu_bindings/src/lib.rs index 73e03425c01e..3299234182e6 100644 --- a/gfx/wgpu_bindings/src/lib.rs +++ b/gfx/wgpu_bindings/src/lib.rs @@ -8,7 +8,6 @@ use wgc::id; pub use wgc::command::{compute_ffi::*, render_ffi::*}; pub mod client; -pub mod command; pub mod error; pub mod server; diff --git a/gfx/wgpu_bindings/src/server.rs b/gfx/wgpu_bindings/src/server.rs index c92bd3126714..8c496cd0d6e9 100644 --- a/gfx/wgpu_bindings/src/server.rs +++ b/gfx/wgpu_bindings/src/server.rs @@ -395,9 +395,7 @@ pub extern "C" fn wgpu_server_device_create_shader_module( if let Some(err) = error { out_message.set_error(&err, &source_str[..]); let err_type = match &err { - CreateShaderModuleError::Device(DeviceError::OutOfMemory) => { - ErrorBufferType::OutOfMemory - } + CreateShaderModuleError::Device(DeviceError::OutOfMemory) => ErrorBufferType::OutOfMemory, CreateShaderModuleError::Device(DeviceError::Lost) => ErrorBufferType::DeviceLost, _ => ErrorBufferType::Validation, }; @@ -567,10 +565,9 @@ pub extern "C" fn wgpu_server_get_device_fence_handle( if device_id.backend() == wgt::Backend::Dx12 { let mut handle = ptr::null_mut(); let dx12_device = unsafe { - global.device_as_hal::>( - device_id, - |hal_device| hal_device.map(|device| device.raw_device().clone()), - ) + global.device_as_hal::>(device_id, |hal_device| { + hal_device.map(|device| device.raw_device().clone()) + }) }; let dx12_device = match dx12_device { Some(device) => device, @@ -580,10 +577,9 @@ pub extern "C" fn wgpu_server_get_device_fence_handle( }; let dx12_fence = unsafe { - global.device_fence_as_hal::>( - device_id, - |hal_fence| hal_fence.map(|fence| fence.raw_fence().clone()), - ) + global.device_fence_as_hal::>(device_id, |hal_fence| { + hal_fence.map(|fence| fence.raw_fence().clone()) + }) }; let dx12_fence = match dx12_fence { Some(fence) => fence, @@ -1042,32 +1038,6 @@ pub unsafe extern "C" fn wgpu_server_command_encoder_action( gfx_select!(self_id => global.command_encoder_action(self_id, action, error_buf)); } -#[no_mangle] -pub unsafe extern "C" fn wgpu_server_render_pass( - global: &Global, - encoder_id: id::CommandEncoderId, - byte_buf: &ByteBuf, - error_buf: ErrorBuffer, -) { - let pass = bincode::deserialize(byte_buf.as_slice()).unwrap(); - let action = crate::command::replay_render_pass(encoder_id, &pass).into_command(); - - gfx_select!(encoder_id => global.command_encoder_action(encoder_id, action, error_buf)); -} - -#[no_mangle] -pub unsafe extern "C" fn wgpu_server_compute_pass( - global: &Global, - encoder_id: id::CommandEncoderId, - byte_buf: &ByteBuf, - error_buf: ErrorBuffer, -) { - let pass = bincode::deserialize(byte_buf.as_slice()).unwrap(); - let action = crate::command::replay_compute_pass(encoder_id, &pass).into_command(); - - gfx_select!(encoder_id => global.command_encoder_action(encoder_id, action, error_buf)); -} - #[no_mangle] pub extern "C" fn wgpu_server_device_create_encoder( global: &Global,