Skip to content

Commit 4b54071

Browse files
committed
Bug 1873503 - Replace Scoped with std::unique_ptr in dom/webgpu. r=webgpu-reviewers,ErichDonGubler
Differential Revision: https://phabricator.services.mozilla.com/D198088 UltraBlame original commit: e838d654d7b583da5a04bd39314c5c700cc4d47c
1 parent 1d30821 commit 4b54071

6 files changed

+49
-64
lines changed

dom/webgpu/ComputePassEncoder.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ GPU_IMPL_CYCLE_COLLECTION(ComputePassEncoder, mParent, mUsedBindGroups,
1717
mUsedPipelines)
1818
GPU_IMPL_JS_WRAP(ComputePassEncoder)
1919

20-
ffi::WGPUComputePass* ScopedFfiComputeTraits::empty() { return nullptr; }
21-
22-
void ScopedFfiComputeTraits::release(ffi::WGPUComputePass* raw) {
20+
void ffiWGPUComputePassDeleter::operator()(ffi::WGPUComputePass* raw) {
2321
if (raw) {
2422
ffi::wgpu_compute_pass_destroy(raw);
2523
}
@@ -51,7 +49,7 @@ void ComputePassEncoder::SetBindGroup(
5149
const dom::Sequence<uint32_t>& aDynamicOffsets) {
5250
if (mValid) {
5351
mUsedBindGroups.AppendElement(&aBindGroup);
54-
ffi::wgpu_compute_pass_set_bind_group(mPass, aSlot, aBindGroup.mId,
52+
ffi::wgpu_compute_pass_set_bind_group(mPass.get(), aSlot, aBindGroup.mId,
5553
aDynamicOffsets.Elements(),
5654
aDynamicOffsets.Length());
5755
}
@@ -60,7 +58,7 @@ void ComputePassEncoder::SetBindGroup(
6058
void ComputePassEncoder::SetPipeline(const ComputePipeline& aPipeline) {
6159
if (mValid) {
6260
mUsedPipelines.AppendElement(&aPipeline);
63-
ffi::wgpu_compute_pass_set_pipeline(mPass, aPipeline.mId);
61+
ffi::wgpu_compute_pass_set_pipeline(mPass.get(), aPipeline.mId);
6462
}
6563
}
6664

@@ -69,40 +67,40 @@ void ComputePassEncoder::DispatchWorkgroups(uint32_t workgroupCountX,
6967
uint32_t workgroupCountZ) {
7068
if (mValid) {
7169
ffi::wgpu_compute_pass_dispatch_workgroups(
72-
mPass, workgroupCountX, workgroupCountY, workgroupCountZ);
70+
mPass.get(), workgroupCountX, workgroupCountY, workgroupCountZ);
7371
}
7472
}
7573

7674
void ComputePassEncoder::DispatchWorkgroupsIndirect(
7775
const Buffer& aIndirectBuffer, uint64_t aIndirectOffset) {
7876
if (mValid) {
7977
ffi::wgpu_compute_pass_dispatch_workgroups_indirect(
80-
mPass, aIndirectBuffer.mId, aIndirectOffset);
78+
mPass.get(), aIndirectBuffer.mId, aIndirectOffset);
8179
}
8280
}
8381

8482
void ComputePassEncoder::PushDebugGroup(const nsAString& aString) {
8583
if (mValid) {
8684
const NS_ConvertUTF16toUTF8 utf8(aString);
87-
ffi::wgpu_compute_pass_push_debug_group(mPass, utf8.get(), 0);
85+
ffi::wgpu_compute_pass_push_debug_group(mPass.get(), utf8.get(), 0);
8886
}
8987
}
9088
void ComputePassEncoder::PopDebugGroup() {
9189
if (mValid) {
92-
ffi::wgpu_compute_pass_pop_debug_group(mPass);
90+
ffi::wgpu_compute_pass_pop_debug_group(mPass.get());
9391
}
9492
}
9593
void ComputePassEncoder::InsertDebugMarker(const nsAString& aString) {
9694
if (mValid) {
9795
const NS_ConvertUTF16toUTF8 utf8(aString);
98-
ffi::wgpu_compute_pass_insert_debug_marker(mPass, utf8.get(), 0);
96+
ffi::wgpu_compute_pass_insert_debug_marker(mPass.get(), utf8.get(), 0);
9997
}
10098
}
10199

102100
void ComputePassEncoder::End() {
103101
if (mValid) {
104102
mValid = false;
105-
auto* pass = mPass.forget();
103+
auto* pass = mPass.release();
106104
MOZ_ASSERT(pass);
107105
mParent->EndComputePass(*pass);
108106
}

dom/webgpu/ComputePassEncoder.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef GPU_ComputePassEncoder_H_
77
#define GPU_ComputePassEncoder_H_
88

9-
#include "mozilla/Scoped.h"
109
#include "mozilla/dom/TypedArray.h"
1110
#include "ObjectModel.h"
1211

@@ -27,10 +26,8 @@ class Buffer;
2726
class CommandEncoder;
2827
class ComputePipeline;
2928

30-
struct ScopedFfiComputeTraits {
31-
using type = ffi::WGPUComputePass*;
32-
static type empty();
33-
static void release(type raw);
29+
struct ffiWGPUComputePassDeleter {
30+
void operator()(ffi::WGPUComputePass*);
3431
};
3532

3633
class ComputePassEncoder final : public ObjectBase,
@@ -46,7 +43,7 @@ class ComputePassEncoder final : public ObjectBase,
4643
virtual ~ComputePassEncoder();
4744
void Cleanup() {}
4845

49-
Scoped<ScopedFfiComputeTraits> mPass;
46+
std::unique_ptr<ffi::WGPUComputePass, ffiWGPUComputePassDeleter> mPass;
5047

5148
nsTArray<RefPtr<const BindGroup>> mUsedBindGroups;
5249
nsTArray<RefPtr<const ComputePipeline>> mUsedPipelines;

dom/webgpu/RenderBundleEncoder.cpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ GPU_IMPL_CYCLE_COLLECTION(RenderBundleEncoder, mParent, mUsedBindGroups,
1919
mUsedBuffers, mUsedPipelines, mUsedTextureViews)
2020
GPU_IMPL_JS_WRAP(RenderBundleEncoder)
2121

22-
ffi::WGPURenderBundleEncoder* ScopedFfiBundleTraits::empty() { return nullptr; }
23-
24-
void ScopedFfiBundleTraits::release(ffi::WGPURenderBundleEncoder* raw) {
22+
void ffiWGPURenderBundleEncoderDeleter::operator()(ffi::WGPURenderBundleEncoder* raw) {
2523
if (raw) {
2624
ffi::wgpu_render_bundle_encoder_destroy(raw);
2725
}
@@ -89,7 +87,7 @@ void RenderBundleEncoder::SetBindGroup(
8987
const dom::Sequence<uint32_t>& aDynamicOffsets) {
9088
if (mValid) {
9189
mUsedBindGroups.AppendElement(&aBindGroup);
92-
ffi::wgpu_render_bundle_set_bind_group(mEncoder, aSlot, aBindGroup.mId,
90+
ffi::wgpu_render_bundle_set_bind_group(mEncoder.get(), aSlot, aBindGroup.mId,
9391
aDynamicOffsets.Elements(),
9492
aDynamicOffsets.Length());
9593
}
@@ -98,7 +96,7 @@ void RenderBundleEncoder::SetBindGroup(
9896
void RenderBundleEncoder::SetPipeline(const RenderPipeline& aPipeline) {
9997
if (mValid) {
10098
mUsedPipelines.AppendElement(&aPipeline);
101-
ffi::wgpu_render_bundle_set_pipeline(mEncoder, aPipeline.mId);
99+
ffi::wgpu_render_bundle_set_pipeline(mEncoder.get(), aPipeline.mId);
102100
}
103101
}
104102

@@ -110,7 +108,7 @@ void RenderBundleEncoder::SetIndexBuffer(
110108
const auto iformat = aIndexFormat == dom::GPUIndexFormat::Uint32
111109
? ffi::WGPUIndexFormat_Uint32
112110
: ffi::WGPUIndexFormat_Uint16;
113-
ffi::wgpu_render_bundle_set_index_buffer(mEncoder, aBuffer.mId, iformat,
111+
ffi::wgpu_render_bundle_set_index_buffer(mEncoder.get(), aBuffer.mId, iformat,
114112
aOffset, aSize);
115113
}
116114
}
@@ -119,15 +117,15 @@ void RenderBundleEncoder::SetVertexBuffer(uint32_t aSlot, const Buffer& aBuffer,
119117
uint64_t aOffset, uint64_t aSize) {
120118
if (mValid) {
121119
mUsedBuffers.AppendElement(&aBuffer);
122-
ffi::wgpu_render_bundle_set_vertex_buffer(mEncoder, aSlot, aBuffer.mId,
120+
ffi::wgpu_render_bundle_set_vertex_buffer(mEncoder.get(), aSlot, aBuffer.mId,
123121
aOffset, aSize);
124122
}
125123
}
126124

127125
void RenderBundleEncoder::Draw(uint32_t aVertexCount, uint32_t aInstanceCount,
128126
uint32_t aFirstVertex, uint32_t aFirstInstance) {
129127
if (mValid) {
130-
ffi::wgpu_render_bundle_draw(mEncoder, aVertexCount, aInstanceCount,
128+
ffi::wgpu_render_bundle_draw(mEncoder.get(), aVertexCount, aInstanceCount,
131129
aFirstVertex, aFirstInstance);
132130
}
133131
}
@@ -137,7 +135,7 @@ void RenderBundleEncoder::DrawIndexed(uint32_t aIndexCount,
137135
uint32_t aFirstIndex, int32_t aBaseVertex,
138136
uint32_t aFirstInstance) {
139137
if (mValid) {
140-
ffi::wgpu_render_bundle_draw_indexed(mEncoder, aIndexCount, aInstanceCount,
138+
ffi::wgpu_render_bundle_draw_indexed(mEncoder.get(), aIndexCount, aInstanceCount,
141139
aFirstIndex, aBaseVertex,
142140
aFirstInstance);
143141
}
@@ -146,34 +144,34 @@ void RenderBundleEncoder::DrawIndexed(uint32_t aIndexCount,
146144
void RenderBundleEncoder::DrawIndirect(const Buffer& aIndirectBuffer,
147145
uint64_t aIndirectOffset) {
148146
if (mValid) {
149-
ffi::wgpu_render_bundle_draw_indirect(mEncoder, aIndirectBuffer.mId,
147+
ffi::wgpu_render_bundle_draw_indirect(mEncoder.get(), aIndirectBuffer.mId,
150148
aIndirectOffset);
151149
}
152150
}
153151

154152
void RenderBundleEncoder::DrawIndexedIndirect(const Buffer& aIndirectBuffer,
155153
uint64_t aIndirectOffset) {
156154
if (mValid) {
157-
ffi::wgpu_render_bundle_draw_indexed_indirect(mEncoder, aIndirectBuffer.mId,
155+
ffi::wgpu_render_bundle_draw_indexed_indirect(mEncoder.get(), aIndirectBuffer.mId,
158156
aIndirectOffset);
159157
}
160158
}
161159

162160
void RenderBundleEncoder::PushDebugGroup(const nsAString& aString) {
163161
if (mValid) {
164162
const NS_ConvertUTF16toUTF8 utf8(aString);
165-
ffi::wgpu_render_bundle_push_debug_group(mEncoder, utf8.get());
163+
ffi::wgpu_render_bundle_push_debug_group(mEncoder.get(), utf8.get());
166164
}
167165
}
168166
void RenderBundleEncoder::PopDebugGroup() {
169167
if (mValid) {
170-
ffi::wgpu_render_bundle_pop_debug_group(mEncoder);
168+
ffi::wgpu_render_bundle_pop_debug_group(mEncoder.get());
171169
}
172170
}
173171
void RenderBundleEncoder::InsertDebugMarker(const nsAString& aString) {
174172
if (mValid) {
175173
const NS_ConvertUTF16toUTF8 utf8(aString);
176-
ffi::wgpu_render_bundle_insert_debug_marker(mEncoder, utf8.get());
174+
ffi::wgpu_render_bundle_insert_debug_marker(mEncoder.get(), utf8.get());
177175
}
178176
}
179177

@@ -184,7 +182,7 @@ already_AddRefed<RenderBundle> RenderBundleEncoder::Finish(
184182
mValid = false;
185183
auto bridge = mParent->GetBridge();
186184
if (bridge && bridge->CanSend()) {
187-
auto* encoder = mEncoder.forget();
185+
auto* encoder = mEncoder.release();
188186
MOZ_ASSERT(encoder);
189187
id = bridge->RenderBundleEncoderFinish(*encoder, mParent->mId, aDesc);
190188
}

dom/webgpu/RenderBundleEncoder.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef GPU_RenderBundleEncoder_H_
77
#define GPU_RenderBundleEncoder_H_
88

9-
#include "mozilla/Scoped.h"
109
#include "mozilla/dom/TypedArray.h"
1110
#include "ObjectModel.h"
1211

@@ -18,10 +17,8 @@ struct WGPURenderBundleEncoder;
1817
class Device;
1918
class RenderBundle;
2019

21-
struct ScopedFfiBundleTraits {
22-
using type = ffi::WGPURenderBundleEncoder*;
23-
static type empty();
24-
static void release(type raw);
20+
struct ffiWGPURenderBundleEncoderDeleter {
21+
void operator()(ffi::WGPURenderBundleEncoder*);
2522
};
2623

2724
class RenderBundleEncoder final : public ObjectBase, public ChildOf<Device> {
@@ -36,7 +33,7 @@ class RenderBundleEncoder final : public ObjectBase, public ChildOf<Device> {
3633
~RenderBundleEncoder();
3734
void Cleanup();
3835

39-
Scoped<ScopedFfiBundleTraits> mEncoder;
36+
std::unique_ptr<ffi::WGPURenderBundleEncoder, ffiWGPURenderBundleEncoderDeleter> mEncoder;
4037

4138
nsTArray<RefPtr<const BindGroup>> mUsedBindGroups;
4239
nsTArray<RefPtr<const Buffer>> mUsedBuffers;

0 commit comments

Comments
 (0)