From d4e4ae35a506f7128f60bec13aa027751f130b27 Mon Sep 17 00:00:00 2001 From: Cristian Tuns Date: Thu, 7 Jul 2022 10:51:38 -0400 Subject: [PATCH] Backed out 2 changesets (bug 1750576) for causing lint failures and build bustages. CLOSED TREE Backed out changeset 21ede22c4113 (bug 1750576) Backed out changeset be7493c6f3cb (bug 1750576) --- Cargo.lock | 1 - dom/webgpu/CommandEncoder.cpp | 8 +- dom/webgpu/CompilationInfo.cpp | 15 ---- dom/webgpu/CompilationInfo.h | 12 +-- dom/webgpu/CompilationMessage.cpp | 10 +-- dom/webgpu/CompilationMessage.h | 10 +-- dom/webgpu/ComputePassEncoder.cpp | 5 +- dom/webgpu/Device.cpp | 16 ++-- dom/webgpu/RenderBundleEncoder.cpp | 7 +- dom/webgpu/RenderPassEncoder.cpp | 3 - dom/webgpu/ShaderModule.cpp | 12 +-- dom/webgpu/ShaderModule.h | 11 +-- dom/webgpu/ipc/PWebGPU.ipdl | 3 - dom/webgpu/ipc/WebGPUChild.cpp | 115 +++++++++++++------------ dom/webgpu/ipc/WebGPUChild.h | 6 +- dom/webgpu/ipc/WebGPUParent.cpp | 49 ++--------- dom/webgpu/ipc/WebGPUParent.h | 4 - dom/webgpu/ipc/WebGPUSerialize.h | 3 - dom/webgpu/ipc/WebGPUTypes.h | 36 -------- dom/webidl/WebGPU.webidl | 9 +- gfx/wgpu_bindings/Cargo.toml | 1 - gfx/wgpu_bindings/cbindgen.toml | 21 ++--- gfx/wgpu_bindings/src/client.rs | 130 ++++++++++++++--------------- gfx/wgpu_bindings/src/lib.rs | 8 -- gfx/wgpu_bindings/src/server.rs | 105 ++--------------------- 25 files changed, 173 insertions(+), 427 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f9cb16f2886b..8b630c49fd81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6180,7 +6180,6 @@ version = "0.1.0" dependencies = [ "bincode", "log", - "nsstring", "parking_lot 0.11.2", "serde", "wgpu-core", diff --git a/dom/webgpu/CommandEncoder.cpp b/dom/webgpu/CommandEncoder.cpp index fb6d3c07b62b..c3dc63bbaaf9 100644 --- a/dom/webgpu/CommandEncoder.cpp +++ b/dom/webgpu/CommandEncoder.cpp @@ -171,8 +171,8 @@ void CommandEncoder::CopyTextureToTexture( void CommandEncoder::PushDebugGroup(const nsAString& aString) { if (mValid && mBridge->IsOpen()) { ipc::ByteBuf bb; - NS_ConvertUTF16toUTF8 marker(aString); - ffi::wgpu_command_encoder_push_debug_group(&marker, ToFFI(&bb)); + const NS_ConvertUTF16toUTF8 utf8(aString); + ffi::wgpu_command_encoder_push_debug_group(utf8.get(), ToFFI(&bb)); mBridge->SendCommandEncoderAction(mId, mParent->mId, std::move(bb)); } } @@ -186,8 +186,8 @@ void CommandEncoder::PopDebugGroup() { void CommandEncoder::InsertDebugMarker(const nsAString& aString) { if (mValid && mBridge->IsOpen()) { ipc::ByteBuf bb; - NS_ConvertUTF16toUTF8 marker(aString); - ffi::wgpu_command_encoder_insert_debug_marker(&marker, ToFFI(&bb)); + const NS_ConvertUTF16toUTF8 utf8(aString); + ffi::wgpu_command_encoder_insert_debug_marker(utf8.get(), ToFFI(&bb)); mBridge->SendCommandEncoderAction(mId, mParent->mId, std::move(bb)); } } diff --git a/dom/webgpu/CompilationInfo.cpp b/dom/webgpu/CompilationInfo.cpp index 6f8ebf54904c..c817c6a7ccac 100644 --- a/dom/webgpu/CompilationInfo.cpp +++ b/dom/webgpu/CompilationInfo.cpp @@ -16,19 +16,4 @@ GPU_IMPL_JS_WRAP(CompilationInfo) CompilationInfo::CompilationInfo(ShaderModule* const aParent) : ChildOf(aParent) {} -void CompilationInfo::SetMessages( - nsTArray& aMessages) { - for (auto& msg : aMessages) { - mMessages.AppendElement(MakeAndAddRef( - this, msg.lineNum, msg.linePos, msg.offset, std::move(msg.message))); - } -} - -void CompilationInfo::GetMessages( - nsTArray>& aMessages) { - for (auto& msg : mMessages) { - aMessages.AppendElement(msg); - } -} - } // namespace mozilla::webgpu diff --git a/dom/webgpu/CompilationInfo.h b/dom/webgpu/CompilationInfo.h index 38d687cf256f..b5677bdd69c6 100644 --- a/dom/webgpu/CompilationInfo.h +++ b/dom/webgpu/CompilationInfo.h @@ -8,7 +8,6 @@ #include "nsWrapperCache.h" #include "ObjectModel.h" -#include "CompilationMessage.h" namespace mozilla::webgpu { class ShaderModule; @@ -19,19 +18,10 @@ class CompilationInfo final : public nsWrapperCache, GPU_DECL_CYCLE_COLLECTION(CompilationInfo) GPU_DECL_JS_WRAP(CompilationInfo) - explicit CompilationInfo(ShaderModule* const aParent); - - void SetMessages( - nsTArray& aMessages); - - void GetMessages( - nsTArray>& aMessages); - private: + explicit CompilationInfo(ShaderModule* const aParent); ~CompilationInfo() = default; void Cleanup() {} - - nsTArray> mMessages; }; } // namespace mozilla::webgpu diff --git a/dom/webgpu/CompilationMessage.cpp b/dom/webgpu/CompilationMessage.cpp index f0df8c1db1ee..48eeecfc528f 100644 --- a/dom/webgpu/CompilationMessage.cpp +++ b/dom/webgpu/CompilationMessage.cpp @@ -12,13 +12,7 @@ namespace mozilla::webgpu { GPU_IMPL_CYCLE_COLLECTION(CompilationMessage, mParent) GPU_IMPL_JS_WRAP(CompilationMessage) -CompilationMessage::CompilationMessage(CompilationInfo* const aParent, - uint64_t aLineNum, uint64_t aLinePos, - uint64_t aOffset, nsString&& aMessage) - : ChildOf(aParent), - mLineNum(aLineNum), - mLinePos(aLinePos), - mOffset(aOffset), - mMessage(std::move(aMessage)) {} +CompilationMessage::CompilationMessage(CompilationInfo* const aParent) + : ChildOf(aParent) {} } // namespace mozilla::webgpu diff --git a/dom/webgpu/CompilationMessage.h b/dom/webgpu/CompilationMessage.h index 685a41f68e1e..b5c41c3d494f 100644 --- a/dom/webgpu/CompilationMessage.h +++ b/dom/webgpu/CompilationMessage.h @@ -24,19 +24,12 @@ class CompilationMessage final : public nsWrapperCache, uint64_t mLinePos = 0; uint64_t mOffset = 0; uint64_t mLength = 0; - nsString mMessage; public: GPU_DECL_CYCLE_COLLECTION(CompilationMessage) GPU_DECL_JS_WRAP(CompilationMessage) - explicit CompilationMessage(CompilationInfo* const aParent, uint64_t aLineNum, - uint64_t aLinePos, uint64_t aOffset, - nsString&& aMessage); - - void GetMessage(dom::DOMString& aMessage) { - aMessage.AsAString().Assign(mMessage); - } + void GetMessage(dom::DOMString& aMessage) {} dom::GPUCompilationMessageType Type() const { return mType; } uint64_t LineNum() const { return mLineNum; } uint64_t LinePos() const { return mLinePos; } @@ -44,6 +37,7 @@ class CompilationMessage final : public nsWrapperCache, uint64_t Length() const { return mLength; } private: + explicit CompilationMessage(CompilationInfo* const aParent); ~CompilationMessage() = default; void Cleanup() {} }; diff --git a/dom/webgpu/ComputePassEncoder.cpp b/dom/webgpu/ComputePassEncoder.cpp index 8172874c224e..0cbbb4e9a0f5 100644 --- a/dom/webgpu/ComputePassEncoder.cpp +++ b/dom/webgpu/ComputePassEncoder.cpp @@ -28,10 +28,7 @@ void ScopedFfiComputeTraits::release(ffi::WGPUComputePass* raw) { ffi::WGPUComputePass* BeginComputePass( RawId aEncoderId, const dom::GPUComputePassDescriptor& aDesc) { ffi::WGPUComputePassDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); - + Unused << aDesc; // no useful fields return ffi::wgpu_command_encoder_begin_compute_pass(aEncoderId, &desc); } diff --git a/dom/webgpu/Device.cpp b/dom/webgpu/Device.cpp index d9d69ef39c48..3f9e7b53d13b 100644 --- a/dom/webgpu/Device.cpp +++ b/dom/webgpu/Device.cpp @@ -266,18 +266,12 @@ already_AddRefed Device::CreateBindGroup( already_AddRefed Device::CreateShaderModule( JSContext* aCx, const dom::GPUShaderModuleDescriptor& aDesc) { Unused << aCx; - - if (!mBridge->CanSend()) { - return nullptr; + RawId id = 0; + if (mBridge->CanSend()) { + id = mBridge->DeviceCreateShaderModule(mId, aDesc); } - - ErrorResult err; - RefPtr promise = dom::Promise::Create(GetParentObject(), err); - if (NS_WARN_IF(err.Failed())) { - return nullptr; - } - - return mBridge->DeviceCreateShaderModule(this, aDesc, promise); + RefPtr object = new ShaderModule(this, id); + return object.forget(); } already_AddRefed Device::CreateComputePipeline( diff --git a/dom/webgpu/RenderBundleEncoder.cpp b/dom/webgpu/RenderBundleEncoder.cpp index cb14db1dd08e..523248968353 100644 --- a/dom/webgpu/RenderBundleEncoder.cpp +++ b/dom/webgpu/RenderBundleEncoder.cpp @@ -37,8 +37,11 @@ ffi::WGPURenderBundleEncoder* CreateRenderBundleEncoder( ffi::WGPURenderBundleEncoderDescriptor desc = {}; desc.sample_count = aDesc.mSampleCount; - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } ffi::WGPUTextureFormat depthStencilFormat = {ffi::WGPUTextureFormat_Sentinel}; if (aDesc.mDepthStencilFormat.WasPassed()) { diff --git a/dom/webgpu/RenderPassEncoder.cpp b/dom/webgpu/RenderPassEncoder.cpp index 4cc2b9fbf392..c8612f0f87f2 100644 --- a/dom/webgpu/RenderPassEncoder.cpp +++ b/dom/webgpu/RenderPassEncoder.cpp @@ -55,9 +55,6 @@ ffi::WGPURenderPass* BeginRenderPass( CommandEncoder* const aParent, const dom::GPURenderPassDescriptor& aDesc) { ffi::WGPURenderPassDescriptor desc = {}; - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); - ffi::WGPURenderPassDepthStencilAttachment dsDesc = {}; if (aDesc.mDepthStencilAttachment.WasPassed()) { const auto& dsa = aDesc.mDepthStencilAttachment.Value(); diff --git a/dom/webgpu/ShaderModule.cpp b/dom/webgpu/ShaderModule.cpp index c415fa732a97..f40130fea188 100644 --- a/dom/webgpu/ShaderModule.cpp +++ b/dom/webgpu/ShaderModule.cpp @@ -4,9 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/WebGPUBinding.h" -#include "mozilla/dom/Promise.h" #include "ShaderModule.h" -#include "CompilationInfo.h" #include "ipc/WebGPUChild.h" #include "Device.h" @@ -16,9 +14,8 @@ namespace mozilla::webgpu { GPU_IMPL_CYCLE_COLLECTION(ShaderModule, mParent) GPU_IMPL_JS_WRAP(ShaderModule) -ShaderModule::ShaderModule(Device* const aParent, RawId aId, - const RefPtr& aCompilationInfo) - : ChildOf(aParent), mId(aId), mCompilationInfo(aCompilationInfo) {} +ShaderModule::ShaderModule(Device* const aParent, RawId aId) + : ChildOf(aParent), mId(aId) {} ShaderModule::~ShaderModule() { Cleanup(); } @@ -32,9 +29,4 @@ void ShaderModule::Cleanup() { } } -already_AddRefed ShaderModule::CompilationInfo(ErrorResult& aRv) { - RefPtr tmp = mCompilationInfo; - return tmp.forget(); -} - } // namespace mozilla::webgpu diff --git a/dom/webgpu/ShaderModule.h b/dom/webgpu/ShaderModule.h index 08eaf2b804d7..3fdb9ca1c245 100644 --- a/dom/webgpu/ShaderModule.h +++ b/dom/webgpu/ShaderModule.h @@ -12,27 +12,20 @@ namespace mozilla::webgpu { -class CompilationInfo; class Device; class ShaderModule final : public ObjectBase, public ChildOf { public: - GPU_DECL_CYCLE_COLLECTION( - ShaderModule) // TODO: kvark's WIP patch was passing CompilationInfo as a - // second argument here. + GPU_DECL_CYCLE_COLLECTION(ShaderModule) GPU_DECL_JS_WRAP(ShaderModule) - ShaderModule(Device* const aParent, RawId aId, - const RefPtr& aCompilationInfo); - already_AddRefed CompilationInfo(ErrorResult& aRv); + ShaderModule(Device* const aParent, RawId aId); const RawId mId; private: virtual ~ShaderModule(); void Cleanup(); - - RefPtr mCompilationInfo; }; } // namespace mozilla::webgpu diff --git a/dom/webgpu/ipc/PWebGPU.ipdl b/dom/webgpu/ipc/PWebGPU.ipdl index 07ad950cee4f..ed480a244fdf 100644 --- a/dom/webgpu/ipc/PWebGPU.ipdl +++ b/dom/webgpu/ipc/PWebGPU.ipdl @@ -13,7 +13,6 @@ using dom::GPUCommandBufferDescriptor from "mozilla/dom/WebGPUBinding.h"; using dom::GPUBufferDescriptor from "mozilla/dom/WebGPUBinding.h"; using webgpu::ffi::WGPUHostMap from "mozilla/webgpu/ffi/wgpu.h"; using MaybeScopedError from "mozilla/webgpu/WebGPUTypes.h"; -using WebGPUCompilationMessage from "mozilla/webgpu/WebGPUTypes.h"; include "mozilla/ipc/ByteBufUtils.h"; include "mozilla/layers/LayersMessageUtils.h"; @@ -45,8 +44,6 @@ parent: async InstanceRequestAdapter(GPURequestAdapterOptions options, RawId[] ids) returns (ByteBuf byteBuf); async AdapterRequestDevice(RawId selfId, ByteBuf buf, RawId newId) returns (bool success); async AdapterDestroy(RawId selfId); - // TODO: We want to return an array of compilation messages. - async DeviceCreateShaderModule(RawId selfId, RawId bufferId, nsString label, nsCString code) returns (WebGPUCompilationMessage[] messages); async BufferReturnShmem(RawId selfId, Shmem shmem); async BufferMap(RawId selfId, WGPUHostMap hostMap, uint64_t offset, uint64_t size) returns (Shmem sm); async BufferUnmap(RawId selfId, Shmem shmem, bool flush, bool keepShmem); diff --git a/dom/webgpu/ipc/WebGPUChild.cpp b/dom/webgpu/ipc/WebGPUChild.cpp index f6d7c225fa3c..cc60188d3c53 100644 --- a/dom/webgpu/ipc/WebGPUChild.cpp +++ b/dom/webgpu/ipc/WebGPUChild.cpp @@ -15,7 +15,6 @@ #include "Adapter.h" #include "DeviceLostInfo.h" #include "Sampler.h" -#include "CompilationInfo.h" namespace mozilla::webgpu { @@ -265,9 +264,6 @@ Maybe WebGPUChild::AdapterRequestDevice( ffi::WGPUDeviceDescriptor desc = {}; ffi::wgpu_client_fill_default_limits(&desc.limits); - // webgpu::StringHelper label(aDesc.mLabel); - // desc.label = label.Get(); - const auto featureBits = Adapter::MakeFeatureBits(aDesc.mRequiredFeatures); if (!featureBits) { return Nothing(); @@ -366,10 +362,11 @@ RawId WebGPUChild::DeviceCreateBuffer(RawId aSelfId, RawId WebGPUChild::DeviceCreateTexture(RawId aSelfId, const dom::GPUTextureDescriptor& aDesc) { ffi::WGPUTextureDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); - + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } if (aDesc.mSize.IsRangeEnforcedUnsignedLongSequence()) { const auto& seq = aDesc.mSize.GetAsRangeEnforcedUnsignedLongSequence(); desc.size.width = seq.Length() > 0 ? seq[0] : 1; @@ -402,9 +399,11 @@ RawId WebGPUChild::TextureCreateView( RawId aSelfId, RawId aDeviceId, const dom::GPUTextureViewDescriptor& aDesc) { ffi::WGPUTextureViewDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } ffi::WGPUTextureFormat format = {ffi::WGPUTextureFormat_Sentinel}; if (aDesc.mFormat.WasPassed()) { @@ -438,9 +437,12 @@ RawId WebGPUChild::TextureCreateView( RawId WebGPUChild::DeviceCreateSampler(RawId aSelfId, const dom::GPUSamplerDescriptor& aDesc) { ffi::WGPUSamplerDescriptor desc = {}; + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); desc.address_modes[0] = ffi::WGPUAddressMode(aDesc.mAddressModeU); desc.address_modes[1] = ffi::WGPUAddressMode(aDesc.mAddressModeV); desc.address_modes[2] = ffi::WGPUAddressMode(aDesc.mAddressModeW); @@ -468,9 +470,11 @@ RawId WebGPUChild::DeviceCreateSampler(RawId aSelfId, RawId WebGPUChild::DeviceCreateCommandEncoder( RawId aSelfId, const dom::GPUCommandEncoderDescriptor& aDesc) { ffi::WGPUCommandEncoderDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } ByteBuf bb; RawId id = ffi::wgpu_client_create_command_encoder(mClient.get(), aSelfId, @@ -498,9 +502,11 @@ RawId WebGPUChild::RenderBundleEncoderFinish( ffi::WGPURenderBundleEncoder& aEncoder, RawId aDeviceId, const dom::GPURenderBundleDescriptor& aDesc) { ffi::WGPURenderBundleDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } ipc::ByteBuf bb; RawId id = ffi::wgpu_client_create_render_bundle( @@ -609,9 +615,11 @@ RawId WebGPUChild::DeviceCreateBindGroupLayout( } ffi::WGPUBindGroupLayoutDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } desc.entries = entries.Elements(); desc.entries_length = entries.Length(); @@ -636,9 +644,11 @@ RawId WebGPUChild::DeviceCreatePipelineLayout( } ffi::WGPUPipelineLayoutDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } desc.bind_group_layouts = bindGroupLayouts.Elements(); desc.bind_group_layouts_length = bindGroupLayouts.Length(); @@ -677,9 +687,11 @@ RawId WebGPUChild::DeviceCreateBindGroup( } ffi::WGPUBindGroupDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); + nsCString label; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } desc.layout = aDesc.mLayout->mId; desc.entries = entries.Elements(); desc.entries_length = entries.Length(); @@ -693,34 +705,20 @@ RawId WebGPUChild::DeviceCreateBindGroup( return id; } -already_AddRefed WebGPUChild::DeviceCreateShaderModule( - Device* aDevice, const dom::GPUShaderModuleDescriptor& aDesc, - RefPtr aPromise) { - RawId deviceId = aDevice->mId; - RawId moduleId = - ffi::wgpu_client_make_shader_module_id(mClient.get(), deviceId); +RawId WebGPUChild::DeviceCreateShaderModule( + RawId aSelfId, const dom::GPUShaderModuleDescriptor& aDesc) { + ffi::WGPUShaderModuleDescriptor desc = {}; - RefPtr shaderModule = - new ShaderModule(aDevice, moduleId, aPromise); + desc.code = reinterpret_cast(aDesc.mCode.get()); + desc.code_length = aDesc.mCode.Length(); - nsString noLabel; - const nsString& label = - aDesc.mLabel.WasPassed() ? aDesc.mLabel.Value() : noLabel; - SendDeviceCreateShaderModule(deviceId, moduleId, label, aDesc.mCode) - ->Then( - GetCurrentSerialEventTarget(), __func__, - [aPromise, - shaderModule](nsTArray&& messages) { - RefPtr infoObject( - new CompilationInfo(shaderModule)); - infoObject->SetMessages(messages); - aPromise->MaybeResolve(infoObject); - }, - [aPromise](const ipc::ResponseRejectReason& aReason) { - aPromise->MaybeRejectWithNotSupportedError("IPC error"); - }); - - return shaderModule.forget(); + ByteBuf bb; + RawId id = ffi::wgpu_client_create_shader_module(mClient.get(), aSelfId, + &desc, ToFFI(&bb)); + if (!SendDeviceAction(aSelfId, std::move(bb))) { + MOZ_CRASH("IPC failure"); + } + return id; } RawId WebGPUChild::DeviceCreateComputePipelineImpl( @@ -833,7 +831,7 @@ RawId WebGPUChild::DeviceCreateRenderPipelineImpl( nsTArray vertexBuffers; nsTArray vertexAttributes; ffi::WGPURenderPipelineDescriptor desc = {}; - nsCString vsEntry, fsEntry; + nsCString label, vsEntry, fsEntry; ffi::WGPUIndexFormat stripIndexFormat = ffi::WGPUIndexFormat_Uint16; ffi::WGPUFace cullFace = ffi::WGPUFace_Front; ffi::WGPUVertexState vertexState = {}; @@ -841,9 +839,10 @@ RawId WebGPUChild::DeviceCreateRenderPipelineImpl( nsTArray colorStates; nsTArray blendStates; - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); - + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + desc.label = label.get(); + } if (aDesc.mLayout.WasPassed()) { desc.layout = aDesc.mLayout.Value().mId; } diff --git a/dom/webgpu/ipc/WebGPUChild.h b/dom/webgpu/ipc/WebGPUChild.h index b0d2742de953..0fa90e1438bf 100644 --- a/dom/webgpu/ipc/WebGPUChild.h +++ b/dom/webgpu/ipc/WebGPUChild.h @@ -83,6 +83,9 @@ class WebGPUChild final : public PWebGPUChild, public SupportsWeakPtr { RawId aSelfId, const dom::GPUPipelineLayoutDescriptor& aDesc); RawId DeviceCreateBindGroup(RawId aSelfId, const dom::GPUBindGroupDescriptor& aDesc); + RawId DeviceCreateShaderModule(RawId aSelfId, + const dom::GPUShaderModuleDescriptor& aDesc); + RawId DeviceCreateComputePipeline( PipelineCreationContext* const aContext, const dom::GPUComputePipelineDescriptor& aDesc); @@ -95,9 +98,6 @@ class WebGPUChild final : public PWebGPUChild, public SupportsWeakPtr { RefPtr DeviceCreateRenderPipelineAsync( PipelineCreationContext* const aContext, const dom::GPURenderPipelineDescriptor& aDesc); - already_AddRefed DeviceCreateShaderModule( - Device* aDevice, const dom::GPUShaderModuleDescriptor& aDesc, - RefPtr aPromise); void DeviceCreateSwapChain(RawId aSelfId, const RGBDescriptor& aRgbDesc, size_t maxBufferCount, diff --git a/dom/webgpu/ipc/WebGPUParent.cpp b/dom/webgpu/ipc/WebGPUParent.cpp index 8ccd4b41a7dc..b1a4605c9326 100644 --- a/dom/webgpu/ipc/WebGPUParent.cpp +++ b/dom/webgpu/ipc/WebGPUParent.cpp @@ -336,11 +336,15 @@ ipc::IPCResult WebGPUParent::RecvDeviceDestroy(RawId aSelfId) { ipc::IPCResult WebGPUParent::RecvCreateBuffer( RawId aSelfId, RawId aBufferId, dom::GPUBufferDescriptor&& aDesc) { - webgpu::StringHelper label(aDesc.mLabel); - + nsCString label; + const char* labelOrNull = nullptr; + if (aDesc.mLabel.WasPassed()) { + LossyCopyUTF16toASCII(aDesc.mLabel.Value(), label); + labelOrNull = label.get(); + } ErrorBuffer error; ffi::wgpu_server_device_create_buffer(mContext.get(), aSelfId, aBufferId, - label.Get(), aDesc.mSize, aDesc.mUsage, + labelOrNull, aDesc.mSize, aDesc.mUsage, aDesc.mMappedAtCreation, error.ToFFI()); ForwardError(aSelfId, error); return IPC_OK(); @@ -469,10 +473,6 @@ ipc::IPCResult WebGPUParent::RecvCommandEncoderFinish( const dom::GPUCommandBufferDescriptor& aDesc) { Unused << aDesc; ffi::WGPUCommandBufferDescriptor desc = {}; - - webgpu::StringHelper label(aDesc.mLabel); - desc.label = label.Get(); - ErrorBuffer error; ffi::wgpu_server_encoder_finish(mContext.get(), aSelfId, &desc, error.ToFFI()); @@ -633,41 +633,6 @@ ipc::IPCResult WebGPUParent::RecvDeviceCreateSwapChain( return IPC_OK(); } -ipc::IPCResult WebGPUParent::RecvDeviceCreateShaderModule( - RawId aSelfId, RawId aBufferId, const nsString& aLabel, - const nsCString& aCode, DeviceCreateShaderModuleResolver&& aOutMessage) { - // TODO: this should probably be an optional label in the IPC message. - const nsACString* label = nullptr; - NS_ConvertUTF16toUTF8 utf8Label(aLabel); - if (!utf8Label.IsEmpty()) { - label = &utf8Label; - } - - ffi::WGPUShaderModuleCompilationMessage message; - - bool ok = ffi::wgpu_server_device_create_shader_module( - mContext.get(), aSelfId, aBufferId, label, &aCode, &message); - - nsTArray messages; - - if (!ok) { - WebGPUCompilationMessage msg; - msg.lineNum = message.line_number; - msg.linePos = message.line_pos; - msg.offset = message.utf16_offset; - msg.length = message.utf16_length; - msg.message = message.message; - // wgpu currently only returns errors. - msg.messageType = WebGPUCompilationMessageType::Error; - - messages.AppendElement(msg); - } - - aOutMessage(messages); - - return IPC_OK(); -} - struct PresentRequest { const ffi::WGPUGlobal* mContext; RefPtr mData; diff --git a/dom/webgpu/ipc/WebGPUParent.h b/dom/webgpu/ipc/WebGPUParent.h index 36b8b33688b7..09d7c83d0e9e 100644 --- a/dom/webgpu/ipc/WebGPUParent.h +++ b/dom/webgpu/ipc/WebGPUParent.h @@ -69,10 +69,6 @@ class WebGPUParent final : public PWebGPUParent { const layers::RGBDescriptor& aDesc, const nsTArray& aBufferIds, const CompositableHandle& aHandle); - ipc::IPCResult RecvDeviceCreateShaderModule( - RawId aSelfId, RawId aModuleId, const nsString& aLabel, - const nsCString& aCode, DeviceCreateShaderModuleResolver&& aOutMessage); - ipc::IPCResult RecvSwapChainPresent(const CompositableHandle& aHandle, RawId aTextureId, RawId aCommandEncoderId); diff --git a/dom/webgpu/ipc/WebGPUSerialize.h b/dom/webgpu/ipc/WebGPUSerialize.h index b130fc992ec1..b1052332365f 100644 --- a/dom/webgpu/ipc/WebGPUSerialize.h +++ b/dom/webgpu/ipc/WebGPUSerialize.h @@ -39,9 +39,6 @@ DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::GPUBufferDescriptor, mSize, DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ScopedError, operationError, validationMessage); -DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::WebGPUCompilationMessage, - message, lineNum, linePos); - #undef DEFINE_IPC_SERIALIZER_FFI_ENUM #undef DEFINE_IPC_SERIALIZER_DOM_ENUM #undef DEFINE_IPC_SERIALIZER_ENUM_GUARD diff --git a/dom/webgpu/ipc/WebGPUTypes.h b/dom/webgpu/ipc/WebGPUTypes.h index ced73ad6a579..a78c57232b9e 100644 --- a/dom/webgpu/ipc/WebGPUTypes.h +++ b/dom/webgpu/ipc/WebGPUTypes.h @@ -9,7 +9,6 @@ #include #include "mozilla/Maybe.h" #include "nsString.h" -#include "mozilla/dom/BindingDeclarations.h" namespace mozilla::webgpu { @@ -27,41 +26,6 @@ struct ScopedError { }; using MaybeScopedError = Maybe; -enum class WebGPUCompilationMessageType { Error, Warning, Info }; - -// TODO: Better name? CompilationMessage alread taken by the dom object. -/// The serializable counterpart of the dom object CompilationMessage. -struct WebGPUCompilationMessage { - nsString message; - uint64_t lineNum = 0; - uint64_t linePos = 0; - // In utf16 code units. - uint64_t offset = 0; - // In utf16 code units. - uint64_t length = 0; - WebGPUCompilationMessageType messageType = - WebGPUCompilationMessageType::Error; -}; - -class StringHelper { - public: - StringHelper(const dom::Optional& aWide) { - if (aWide.WasPassed()) { - mNarrow = Some(NS_ConvertUTF16toUTF8(aWide.Value())); - } - } - - const nsACString* Get() const { - if (mNarrow.isSome()) { - return mNarrow.ptr(); - } - return nullptr; - } - - private: - Maybe mNarrow; -}; - } // namespace mozilla::webgpu #endif // WEBGPU_TYPES_H_ diff --git a/dom/webidl/WebGPU.webidl b/dom/webidl/WebGPU.webidl index f020c0614fad..63d14add0d57 100644 --- a/dom/webidl/WebGPU.webidl +++ b/dom/webidl/WebGPU.webidl @@ -627,8 +627,9 @@ interface GPUCompilationMessage { [Pref="dom.webgpu.enabled", Exposed=(Window,DedicatedWorker)] interface GPUCompilationInfo { - [Cached, Frozen, Pure] - readonly attribute sequence messages; + //TODO: + //[Cached, Frozen, Pure] + //readonly attribute sequence messages; }; // ShaderModule @@ -642,8 +643,8 @@ dictionary GPUShaderModuleDescriptor : GPUObjectDescriptorBase { [Pref="dom.webgpu.enabled", Exposed=(Window,DedicatedWorker)] interface GPUShaderModule { - [Throws] - Promise compilationInfo(); + //TODO: + //Promise compilationInfo(); }; GPUShaderModule includes GPUObjectBase; diff --git a/gfx/wgpu_bindings/Cargo.toml b/gfx/wgpu_bindings/Cargo.toml index 99ad59f64591..79af91f4b2d1 100644 --- a/gfx/wgpu_bindings/Cargo.toml +++ b/gfx/wgpu_bindings/Cargo.toml @@ -37,4 +37,3 @@ bincode = "1" log = "0.4" parking_lot = "0.11" serde = "1" -nsstring = { path = "../../xpcom/rust/nsstring" } diff --git a/gfx/wgpu_bindings/cbindgen.toml b/gfx/wgpu_bindings/cbindgen.toml index 79271aab14fc..beda4228946b 100644 --- a/gfx/wgpu_bindings/cbindgen.toml +++ b/gfx/wgpu_bindings/cbindgen.toml @@ -15,8 +15,6 @@ autogen_warning = """/* DO NOT MODIFY THIS MANUALLY! This file was generated usi * - $CBINDGEN is the path to the cbindgen executable provided by mozbuild (the exact version often matters) */ -#include "nsString.h" - struct WGPUByteBuf; typedef uint64_t WGPUNonZeroU64; typedef uint64_t WGPUOption_BufferSize; @@ -39,7 +37,6 @@ style = "tag" [export] prefix = "WGPU" -renaming_overrides_prefixing = true exclude = [ "Option_AdapterId", "Option_BufferId", "Option_PipelineLayoutId", "Option_BindGroupLayoutId", "Option_SamplerId", "Option_SurfaceId", "Option_TextureViewId", @@ -49,17 +46,13 @@ exclude = [ include = ["BufferUsages"] [export.rename] -"nsString" = "nsString" -"nsCString" = "nsCString" -"nsAString" = "nsAString" -"nsACString" = "nsACString" -"BufferDescriptor______nsACString" = "WGPUBufferDescriptor" -"CommandBufferDescriptor______nsACString" = "WGPUCommandBufferDescriptor" -"CommandEncoderDescriptor______nsACString" = "WGPUCommandEncoderDescriptor" -"RenderBundleDescriptor______nsACString" = "WGPURenderBundleDescriptor" -"DeviceDescriptor______nsACString" = "WGPUDeviceDescriptor" -"TextureDescriptor______nsACString" = "WGPUTextureDescriptor" -"SamplerDescriptor______nsACString" = "WGPUSamplerDescriptor" +"BufferDescriptor_RawString" = "BufferDescriptor" +"CommandBufferDescriptor_RawString" = "CommandBufferDescriptor" +"CommandEncoderDescriptor_RawString" = "CommandEncoderDescriptor" +"RenderBundleDescriptor_RawString" = "RenderBundleDescriptor" +"DeviceDescriptor_RawString" = "DeviceDescriptor" +"TextureDescriptor_RawString" = "TextureDescriptor" +"SamplerDescriptor_RawString" = "SamplerDescriptor" [parse] parse_deps = true diff --git a/gfx/wgpu_bindings/src/client.rs b/gfx/wgpu_bindings/src/client.rs index c817ee070d32..b221c23aa3ca 100644 --- a/gfx/wgpu_bindings/src/client.rs +++ b/gfx/wgpu_bindings/src/client.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::{ - wgpu_string, cow_label, AdapterInformation, ByteBuf, CommandEncoderAction, DeviceAction, DropAction, + cow_label, AdapterInformation, ByteBuf, CommandEncoderAction, DeviceAction, DropAction, ImplicitLayout, QueueWriteAction, RawString, TextureAction, }; @@ -14,8 +14,6 @@ pub use wgc::command::{compute_ffi::*, render_ffi::*}; use parking_lot::Mutex; -use nsstring::nsACString; - use std::{ borrow::Cow, num::{NonZeroU32, NonZeroU8}, @@ -37,6 +35,13 @@ fn make_byte_buf(data: &T) -> ByteBuf { ByteBuf::from_vec(vec) } +#[repr(C)] +pub struct ShaderModuleDescriptor { + label: RawString, + code: *const u8, + code_length: usize, +} + #[repr(C)] pub struct ProgrammableStageDescriptor { module: id::ShaderModuleId, @@ -148,7 +153,7 @@ impl PrimitiveState<'_> { #[repr(C)] pub struct RenderPipelineDescriptor<'a> { - label: Option<&'a nsACString>, + label: RawString, layout: Option, vertex: &'a VertexState, primitive: PrimitiveState<'a>, @@ -194,7 +199,7 @@ pub struct BindGroupLayoutEntry<'a> { #[repr(C)] pub struct BindGroupLayoutDescriptor<'a> { - label: Option<&'a nsACString>, + label: RawString, entries: *const BindGroupLayoutEntry<'a>, entries_length: usize, } @@ -211,23 +216,23 @@ pub struct BindGroupEntry { } #[repr(C)] -pub struct BindGroupDescriptor<'a> { - label: Option<&'a nsACString>, +pub struct BindGroupDescriptor { + label: RawString, layout: id::BindGroupLayoutId, entries: *const BindGroupEntry, entries_length: usize, } #[repr(C)] -pub struct PipelineLayoutDescriptor<'a> { - label: Option<&'a nsACString>, +pub struct PipelineLayoutDescriptor { + label: RawString, bind_group_layouts: *const id::BindGroupLayoutId, bind_group_layouts_length: usize, } #[repr(C)] pub struct SamplerDescriptor<'a> { - label: Option<&'a nsACString>, + label: RawString, address_modes: [wgt::AddressMode; 3], mag_filter: wgt::FilterMode, min_filter: wgt::FilterMode, @@ -240,7 +245,7 @@ pub struct SamplerDescriptor<'a> { #[repr(C)] pub struct TextureViewDescriptor<'a> { - label: Option<&'a nsACString>, + label: RawString, format: Option<&'a wgt::TextureFormat>, dimension: Option<&'a wgt::TextureViewDimension>, aspect: wgt::TextureAspect, @@ -252,7 +257,7 @@ pub struct TextureViewDescriptor<'a> { #[repr(C)] pub struct RenderBundleEncoderDescriptor<'a> { - label: Option<&'a nsACString>, + label: RawString, color_formats: *const wgt::TextureFormat, color_formats_length: usize, depth_stencil_format: Option<&'a wgt::TextureFormat>, @@ -436,11 +441,10 @@ pub extern "C" fn wgpu_client_adapter_extract_info( #[no_mangle] pub extern "C" fn wgpu_client_serialize_device_descriptor( - desc: &wgt::DeviceDescriptor>, + desc: &wgt::DeviceDescriptor, bb: &mut ByteBuf, ) { - let label = wgpu_string(desc.label); - *bb = make_byte_buf(&desc.map_label(|_| label)); + *bb = make_byte_buf(&desc.map_label(cow_label)); } #[no_mangle] @@ -475,11 +479,9 @@ pub extern "C" fn wgpu_client_make_buffer_id( pub extern "C" fn wgpu_client_create_texture( client: &Client, device_id: id::DeviceId, - desc: &wgt::TextureDescriptor>, + desc: &wgt::TextureDescriptor, bb: &mut ByteBuf, ) -> id::TextureId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -488,7 +490,7 @@ pub extern "C" fn wgpu_client_create_texture( .textures .alloc(backend); - let action = DeviceAction::CreateTexture(id, desc.map_label(|_| label)); + let action = DeviceAction::CreateTexture(id, desc.map_label(cow_label)); *bb = make_byte_buf(&action); id } @@ -500,8 +502,6 @@ pub extern "C" fn wgpu_client_create_texture_view( desc: &TextureViewDescriptor, bb: &mut ByteBuf, ) -> id::TextureViewId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -511,7 +511,7 @@ pub extern "C" fn wgpu_client_create_texture_view( .alloc(backend); let wgpu_desc = wgc::resource::TextureViewDescriptor { - label: label, + label: cow_label(&desc.label), format: desc.format.cloned(), dimension: desc.dimension.cloned(), range: wgt::ImageSubresourceRange { @@ -535,8 +535,6 @@ pub extern "C" fn wgpu_client_create_sampler( desc: &SamplerDescriptor, bb: &mut ByteBuf, ) -> id::SamplerId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -544,9 +542,9 @@ pub extern "C" fn wgpu_client_create_sampler( .select(backend) .samplers .alloc(backend); - + let wgpu_desc = wgc::resource::SamplerDescriptor { - label: label, + label: cow_label(&desc.label), address_modes: desc.address_modes, mag_filter: desc.mag_filter, min_filter: desc.min_filter, @@ -580,11 +578,9 @@ pub extern "C" fn wgpu_client_make_encoder_id( pub extern "C" fn wgpu_client_create_command_encoder( client: &Client, device_id: id::DeviceId, - desc: &wgt::CommandEncoderDescriptor>, + desc: &wgt::CommandEncoderDescriptor, bb: &mut ByteBuf, ) -> id::CommandEncoderId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -593,7 +589,7 @@ pub extern "C" fn wgpu_client_create_command_encoder( .command_buffers .alloc(backend); - let action = DeviceAction::CreateCommandEncoder(id, desc.map_label(|_| label)); + let action = DeviceAction::CreateCommandEncoder(id, desc.map_label(cow_label)); *bb = make_byte_buf(&action); id } @@ -604,14 +600,12 @@ pub extern "C" fn wgpu_device_create_render_bundle_encoder( desc: &RenderBundleEncoderDescriptor, bb: &mut ByteBuf, ) -> *mut wgc::command::RenderBundleEncoder { - let label = wgpu_string(desc.label); - let color_formats: Vec<_> = make_slice(desc.color_formats, desc.color_formats_length) .iter() .map(|format| Some(format.clone())) .collect(); let descriptor = wgc::command::RenderBundleEncoderDescriptor { - label: label, + label: cow_label(&desc.label), color_formats: Cow::Owned(color_formats), depth_stencil: desc .depth_stencil_format @@ -648,11 +642,9 @@ pub unsafe extern "C" fn wgpu_client_create_render_bundle( client: &Client, encoder: *mut wgc::command::RenderBundleEncoder, device_id: id::DeviceId, - desc: &wgt::RenderBundleDescriptor>, + desc: &wgt::RenderBundleDescriptor, bb: &mut ByteBuf, ) -> id::RenderBundleId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -662,14 +654,14 @@ pub unsafe extern "C" fn wgpu_client_create_render_bundle( .alloc(backend); let action = - DeviceAction::CreateRenderBundle(id, *Box::from_raw(encoder), desc.map_label(|_| label)); + DeviceAction::CreateRenderBundle(id, *Box::from_raw(encoder), desc.map_label(cow_label)); *bb = make_byte_buf(&action); id } #[repr(C)] -pub struct ComputePassDescriptor<'a> { - pub label: Option<&'a nsACString>, +pub struct ComputePassDescriptor { + pub label: RawString, } #[no_mangle] @@ -677,12 +669,10 @@ pub unsafe extern "C" fn wgpu_command_encoder_begin_compute_pass( encoder_id: id::CommandEncoderId, desc: &ComputePassDescriptor, ) -> *mut wgc::command::ComputePass { - let label = wgpu_string(desc.label); - let pass = wgc::command::ComputePass::new( encoder_id, &wgc::command::ComputePassDescriptor { - label: label, + label: cow_label(&desc.label), }, ); Box::into_raw(Box::new(pass)) @@ -703,8 +693,8 @@ pub unsafe extern "C" fn wgpu_compute_pass_destroy(pass: *mut wgc::command::Comp } #[repr(C)] -pub struct RenderPassDescriptor<'a> { - pub label: Option<&'a nsACString>, +pub struct RenderPassDescriptor { + pub label: RawString, pub color_attachments: *const wgc::command::RenderPassColorAttachment, pub color_attachments_length: usize, pub depth_stencil_attachment: *const wgc::command::RenderPassDepthStencilAttachment, @@ -715,8 +705,6 @@ pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass( encoder_id: id::CommandEncoderId, desc: &RenderPassDescriptor, ) -> *mut wgc::command::RenderPass { - let label = wgpu_string(desc.label); - let color_attachments: Vec<_> = make_slice(desc.color_attachments, desc.color_attachments_length) .iter() .map(|format| Some(format.clone())) @@ -724,7 +712,7 @@ pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass( let pass = wgc::command::RenderPass::new( encoder_id, &wgc::command::RenderPassDescriptor { - label: label, + label: cow_label(&desc.label), color_attachments: Cow::Owned(color_attachments), depth_stencil_attachment: desc.depth_stencil_attachment.as_ref(), }, @@ -753,8 +741,6 @@ pub unsafe extern "C" fn wgpu_client_create_bind_group_layout( desc: &BindGroupLayoutDescriptor, bb: &mut ByteBuf, ) -> id::BindGroupLayoutId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -824,7 +810,7 @@ pub unsafe extern "C" fn wgpu_client_create_bind_group_layout( }); } let wgpu_desc = wgc::binding_model::BindGroupLayoutDescriptor { - label: label, + label: cow_label(&desc.label), entries: Cow::Owned(entries), }; @@ -840,8 +826,6 @@ pub unsafe extern "C" fn wgpu_client_create_pipeline_layout( desc: &PipelineLayoutDescriptor, bb: &mut ByteBuf, ) -> id::PipelineLayoutId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -851,7 +835,7 @@ pub unsafe extern "C" fn wgpu_client_create_pipeline_layout( .alloc(backend); let wgpu_desc = wgc::binding_model::PipelineLayoutDescriptor { - label: label, + label: cow_label(&desc.label), bind_group_layouts: Cow::Borrowed(make_slice( desc.bind_group_layouts, desc.bind_group_layouts_length, @@ -871,8 +855,6 @@ pub unsafe extern "C" fn wgpu_client_create_bind_group( desc: &BindGroupDescriptor, bb: &mut ByteBuf, ) -> id::BindGroupId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let id = client .identities @@ -901,7 +883,7 @@ pub unsafe extern "C" fn wgpu_client_create_bind_group( }); } let wgpu_desc = wgc::binding_model::BindGroupDescriptor { - label: label, + label: cow_label(&desc.label), layout: desc.layout, entries: Cow::Owned(entries), }; @@ -912,17 +894,30 @@ pub unsafe extern "C" fn wgpu_client_create_bind_group( } #[no_mangle] -pub extern "C" fn wgpu_client_make_shader_module_id( +pub unsafe extern "C" fn wgpu_client_create_shader_module( client: &Client, device_id: id::DeviceId, + desc: &ShaderModuleDescriptor, + bb: &mut ByteBuf, ) -> id::ShaderModuleId { let backend = device_id.backend(); - client + let id = client .identities .lock() .select(backend) .shader_modules - .alloc(backend) + .alloc(backend); + + let code = + std::str::from_utf8_unchecked(std::slice::from_raw_parts(desc.code, desc.code_length)); + let desc = wgc::pipeline::ShaderModuleDescriptor { + label: cow_label(&desc.label), + shader_bound_checks: wgt::ShaderBoundChecks::new(), + }; + + let action = DeviceAction::CreateShaderModule(id, desc, Cow::Borrowed(code)); + *bb = make_byte_buf(&action); + id } #[no_mangle] @@ -970,14 +965,12 @@ pub unsafe extern "C" fn wgpu_client_create_render_pipeline( implicit_pipeline_layout_id: *mut Option, implicit_bind_group_layout_ids: *mut Option, ) -> id::RenderPipelineId { - let label = wgpu_string(desc.label); - let backend = device_id.backend(); let mut identities = client.identities.lock(); let id = identities.select(backend).render_pipelines.alloc(backend); let wgpu_desc = wgc::pipeline::RenderPipelineDescriptor { - label: label, + label: cow_label(&desc.label), layout: desc.layout, vertex: desc.vertex.to_wgpu(), fragment: desc.fragment.map(FragmentState::to_wgpu), @@ -1057,12 +1050,12 @@ pub unsafe extern "C" fn wgpu_command_encoder_copy_texture_to_texture( } #[no_mangle] -pub extern "C" fn wgpu_command_encoder_push_debug_group( - marker: &nsACString, +pub unsafe extern "C" fn wgpu_command_encoder_push_debug_group( + marker: RawString, bb: &mut ByteBuf, ) { - - let string = marker.to_string(); + let cstr = std::ffi::CStr::from_ptr(marker); + let string = cstr.to_str().unwrap_or_default().to_string(); let action = CommandEncoderAction::PushDebugGroup(string); *bb = make_byte_buf(&action); } @@ -1075,10 +1068,11 @@ pub unsafe extern "C" fn wgpu_command_encoder_pop_debug_group(bb: &mut ByteBuf) #[no_mangle] pub unsafe extern "C" fn wgpu_command_encoder_insert_debug_marker( - marker: &nsACString, + marker: RawString, bb: &mut ByteBuf, ) { - let string = marker.to_string(); + let cstr = std::ffi::CStr::from_ptr(marker); + let string = cstr.to_str().unwrap_or_default().to_string(); let action = CommandEncoderAction::InsertDebugMarker(string); *bb = make_byte_buf(&action); } diff --git a/gfx/wgpu_bindings/src/lib.rs b/gfx/wgpu_bindings/src/lib.rs index 877cfe9f287f..71e587566189 100644 --- a/gfx/wgpu_bindings/src/lib.rs +++ b/gfx/wgpu_bindings/src/lib.rs @@ -14,8 +14,6 @@ pub use wgc::device::trace::Command as CommandEncoderAction; use std::{borrow::Cow, mem, slice}; -use nsstring::nsACString; - type RawString = *const std::os::raw::c_char; //TODO: figure out why 'a and 'b have to be different here @@ -29,12 +27,6 @@ fn cow_label<'a, 'b>(raw: &'a RawString) -> Option> { } } -// Hides the repeated boilerplate of turning a `Option<&nsACString>` into a `Option`. -pub fn wgpu_string(gecko_string: Option<&nsACString>) -> Option> { - gecko_string.map(|s| s.to_utf8()) -} - - #[repr(C)] pub struct ByteBuf { data: *const u8, diff --git a/gfx/wgpu_bindings/src/server.rs b/gfx/wgpu_bindings/src/server.rs index dad035911886..5bc04c4398e9 100644 --- a/gfx/wgpu_bindings/src/server.rs +++ b/gfx/wgpu_bindings/src/server.rs @@ -3,18 +3,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use crate::{ - wgpu_string, identity::IdentityRecyclerFactory, AdapterInformation, ByteBuf, - CommandEncoderAction, DeviceAction, DropAction, QueueWriteAction, TextureAction, + cow_label, identity::IdentityRecyclerFactory, AdapterInformation, ByteBuf, + CommandEncoderAction, DeviceAction, DropAction, QueueWriteAction, RawString, TextureAction, }; -use nsstring::{nsString, nsACString, nsCString}; - use wgc::{gfx_select, id}; -use wgc::pipeline::CreateShaderModuleError; use std::sync::atomic::{AtomicU32, Ordering}; use std::{error::Error, os::raw::c_char, ptr, slice}; -use std::borrow::Cow; /// A fixed-capacity, null-terminated error buffer owned by C++. /// @@ -211,99 +207,18 @@ pub extern "C" fn wgpu_server_device_drop(global: &Global, self_id: id::DeviceId gfx_select!(self_id => global.device_drop(self_id)) } -impl ShaderModuleCompilationMessage { - fn set_error(&mut self, error: &CreateShaderModuleError, source: &str) { - // The WebGPU spec says that if the message doesn't point to a particular position in - // the source, the line number, position, offset and lengths should be zero. - self.line_number = 0; - self.line_pos = 0; - self.utf16_offset = 0; - self.utf16_length = 0; - - if let Some(location) = error.location(source) { - self.line_number = location.line_number as u64; - self.line_pos = location.line_position as u64; - - let start = location.offset as usize; - let end = start + location.length as usize; - self.utf16_offset = source[0..start].chars().map(|c| c.len_utf16() as u64).sum(); - self.utf16_length = source[start..end].chars().map(|c| c.len_utf16() as u64).sum(); - } - - let error_string = error.to_string(); - - if !error_string.is_empty() { - self.message = nsString::from(&error_string[..]); - } - } -} - -/// A compilation message representation for the ffi boundary. -/// the message is immediately copied into an equivalent C++ -/// structure that owns its strings. -#[repr(C)] -#[derive(Clone)] -pub struct ShaderModuleCompilationMessage { - pub line_number: u64, - pub line_pos: u64, - pub utf16_offset: u64, - pub utf16_length: u64, - pub message: nsString, -} - -/// Creates a shader module and returns an object describing the errors if any. -/// -/// If there was no error, the returned pointer is nil. -#[no_mangle] -pub extern "C" fn wgpu_server_device_create_shader_module( - global: &Global, - self_id: id::DeviceId, - module_id: id::ShaderModuleId, - label: Option<&nsACString>, - code: &nsCString, - out_message: &mut ShaderModuleCompilationMessage -) -> bool { - let utf8_label = label.map(|utf16| utf16.to_string()); - let label = utf8_label.as_ref().map(|s| Cow::from(&s[..])); - - let source_str = code.to_utf8(); - - let source = wgc::pipeline::ShaderModuleSource::Wgsl(Cow::from(&source_str[..])); - - let desc = wgc::pipeline::ShaderModuleDescriptor { - label, - shader_bound_checks: wgt::ShaderBoundChecks::new(), - }; - - let (_, error) = gfx_select!( - self_id => global.device_create_shader_module( - self_id, &desc, source, module_id - ) - ); - - if let Some(err) = error { - out_message.set_error(&err, &source_str[..]); - return false; - } - - // Avoid allocating the structure that holds errors in the common case (no errors). - return true; -} - #[no_mangle] pub extern "C" fn wgpu_server_device_create_buffer( global: &Global, self_id: id::DeviceId, buffer_id: id::BufferId, - label: Option<&nsACString>, + label_or_null: RawString, size: wgt::BufferAddress, usage: u32, mapped_at_creation: bool, mut error_buf: ErrorBuffer, ) { - let utf8_label = label.map(|utf16| utf16.to_string()); - let label = utf8_label.as_ref().map(|s| Cow::from(&s[..])); - + let label = cow_label(&label_or_null); let usage = match wgt::BufferUsages::from_bits(usage) { Some(usage) => usage, None => { @@ -649,14 +564,11 @@ pub unsafe extern "C" fn wgpu_server_command_encoder_action( pub extern "C" fn wgpu_server_device_create_encoder( global: &Global, self_id: id::DeviceId, - desc: &wgt::CommandEncoderDescriptor>, + desc: &wgt::CommandEncoderDescriptor, new_id: id::CommandEncoderId, mut error_buf: ErrorBuffer, ) { - let utf8_label = desc.label.map(|utf16| utf16.to_string()); - let label = utf8_label.as_ref().map(|s| Cow::from(&s[..])); - - let desc = desc.map_label(|_| label); + let desc = desc.map_label(cow_label); let (_, error) = gfx_select!(self_id => global.device_create_command_encoder(self_id, &desc, new_id)); if let Some(err) = error { @@ -668,11 +580,10 @@ pub extern "C" fn wgpu_server_device_create_encoder( pub extern "C" fn wgpu_server_encoder_finish( global: &Global, self_id: id::CommandEncoderId, - desc: &wgt::CommandBufferDescriptor>, + desc: &wgt::CommandBufferDescriptor, mut error_buf: ErrorBuffer, ) { - let label = wgpu_string(desc.label); - let desc = desc.map_label(|_| label); + let desc = desc.map_label(cow_label); let (_, error) = gfx_select!(self_id => global.command_encoder_finish(self_id, &desc)); if let Some(err) = error { error_buf.init(err);