Skip to content

Commit 8fbe756

Browse files
committed
Revert "Bug 1979100 - Add infrastructure for importing video frames into wgpu textures. r=webgpu-reviewers,webidl,teoxoy,smaug" for causing build bustages on ExternalTexture.h
This reverts commit 8c62114. Revert "Bug 1979100 - Move ErrorBuffer declaration to WebGPUParent.h. r=webgpu-reviewers,teoxoy" This reverts commit 02e5b2a.
1 parent e5e7b59 commit 8fbe756

10 files changed

Lines changed: 97 additions & 910 deletions

File tree

dom/webgpu/ExternalTexture.cpp

Lines changed: 0 additions & 430 deletions
Large diffs are not rendered by default.

dom/webgpu/ExternalTexture.h

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,10 @@
66
#ifndef ExternalTexture_H_
77
#define ExternalTexture_H_
88

9-
#include <array>
10-
119
#include "ObjectModel.h"
12-
#include "mozilla/Span.h"
13-
#include "mozilla/gfx/Types.h"
14-
#include "mozilla/webgpu/WebGPUTypes.h"
1510
#include "nsIGlobalObject.h"
16-
#include "nsTArrayForwardDeclare.h"
17-
18-
namespace mozilla {
19-
namespace dom {
20-
class OwningHTMLVideoElementOrVideoFrame;
21-
}
22-
namespace layers {
23-
class BufferDescriptor;
24-
class Image;
25-
} // namespace layers
26-
27-
namespace webgpu {
2811

29-
class Device;
30-
class WebGPUParent;
12+
namespace mozilla::webgpu {
3113

3214
// NOTE: Incomplete. Follow-up to complete implementation is at
3315
// <https://bugzilla.mozilla.org/show_bug.cgi?id=1827116>.
@@ -47,96 +29,6 @@ class ExternalTexture : public ObjectBase {
4729
void Cleanup() {}
4830
};
4931

50-
// The client side of an imported external texture source. This gets imported
51-
// from either an HTMLVideoElement or a VideoFrame. ExternalTextures can then
52-
// be created from a source. It is important to separate the source from the
53-
// external texture as multiple external textures can be created from the same
54-
// source.
55-
// The client side is responsible for creating and destroying the host side.
56-
// Any external texture created from this source must ensure the source remains
57-
// alive as long as it is required by the external texture, by holding a strong
58-
// reference.
59-
class ExternalTextureSourceClient {
60-
NS_INLINE_DECL_REFCOUNTING(ExternalTextureSourceClient)
61-
62-
public:
63-
// Creates an ExternalTextureSourceClient from a video element or video frame.
64-
// Returns nullptr on failure. Throws security error if the source is not
65-
// origin-clean.
66-
static already_AddRefed<ExternalTextureSourceClient> Create(
67-
Device* aDevice, const dom::OwningHTMLVideoElementOrVideoFrame& aSource,
68-
ErrorResult& aRv);
69-
70-
const RawId mId;
71-
72-
// External texture sources can consist of up to 3 planes of texture data, but
73-
// on the client side we do not know how many planes will actually be
74-
// required. We therefore unconditionally make IDs for 3 textures and 3
75-
// texture views, and the host side will only use the IDs that it requires.
76-
const std::array<RawId, 3> mTextureIds;
77-
const std::array<RawId, 3> mViewIds;
78-
79-
private:
80-
ExternalTextureSourceClient(WebGPUChild* aBridge, RawId aId,
81-
const std::array<RawId, 3>& aTextureIds,
82-
const std::array<RawId, 3>& aViewIds);
83-
~ExternalTextureSourceClient();
84-
85-
// Used to free resources on the host side when we are destroyed, if the
86-
// bridge is still valid.
87-
const WeakPtr<WebGPUChild> mBridge;
88-
};
89-
90-
// Host side of an external texture source. This is responsible for creating
91-
// and managing the lifecycle of the wgpu textures and texture views created
92-
// from the provided SurfaceDescriptor.
93-
class ExternalTextureSourceHost {
94-
public:
95-
// Creates an external texture source from a descriptor. If this fails it
96-
// will create an external texture source in an error state, which will be
97-
// propagated to any external textures created from it.
98-
static ExternalTextureSourceHost Create(
99-
WebGPUParent* aParent, RawId aDeviceId, RawId aQueueId,
100-
const ExternalTextureSourceDescriptor& aDesc);
101-
102-
// Texture and TextureView IDs used by the source. These will be a subset of
103-
// the IDs provided by the client in the descriptor.
104-
Span<const RawId> TextureIds() const { return mTextureIds; }
105-
Span<const RawId> ViewIds() const { return mViewIds; }
106-
107-
private:
108-
ExternalTextureSourceHost(Span<const RawId> aTextureIds,
109-
Span<const RawId> aViewIds, gfx::IntSize aSize,
110-
gfx::SurfaceFormat aFormat,
111-
gfx::YUVRangedColorSpace aColorSpace,
112-
const std::array<float, 6>& aSampleTransform,
113-
const std::array<float, 6>& aLoadTransform);
114-
115-
static ExternalTextureSourceHost CreateFromBufferDesc(
116-
WebGPUParent* aParent, RawId aDeviceId, RawId aQueueId,
117-
const ExternalTextureSourceDescriptor& aDesc,
118-
const layers::BufferDescriptor& aSd, uint8_t* aBuffer);
119-
120-
// Creates an external texture source in an error state that will be
121-
// propagated to any external textures created from it.
122-
static ExternalTextureSourceHost CreateError();
123-
124-
// These should be const but can't be else we wouldn't be move constructible.
125-
// While we are always provided with 3 texture IDs and 3 view IDs by the
126-
// client, we only store here the IDs that are actually used. For example an
127-
// RGBA format source will only require 1 texture and 1 view. NV12 will
128-
// require 2 views, and either 1 or 2 textures depending on whether the
129-
// platform natively supports NV12 format textures.
130-
AutoTArray<RawId, 3> mTextureIds;
131-
AutoTArray<RawId, 3> mViewIds;
132-
const gfx::IntSize mSize;
133-
MOZ_MAYBE_UNUSED const gfx::SurfaceFormat mFormat;
134-
MOZ_MAYBE_UNUSED const gfx::YUVRangedColorSpace mColorSpace;
135-
MOZ_MAYBE_UNUSED const std::array<float, 6> mSampleTransform;
136-
MOZ_MAYBE_UNUSED const std::array<float, 6> mLoadTransform;
137-
};
138-
139-
} // namespace webgpu
140-
} // namespace mozilla
32+
} // namespace mozilla::webgpu
14133

14234
#endif // GPU_ExternalTexture_H_

dom/webgpu/ipc/PWebGPU.ipdl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ using mozilla::dom::GPUErrorFilter from "mozilla/dom/WebGPUBinding.h";
1515
using mozilla::dom::GPURequestAdapterOptions from "mozilla/dom/WebGPUBinding.h";
1616
using mozilla::dom::GPUCommandBufferDescriptor from "mozilla/dom/WebGPUBinding.h";
1717
using mozilla::dom::GPUBufferDescriptor from "mozilla/dom/WebGPUBinding.h";
18-
using mozilla::webgpu::ExternalTextureSourceDescriptor from "mozilla/webgpu/WebGPUTypes.h";
1918
using mozilla::webgpu::PopErrorScopeResult from "mozilla/webgpu/WebGPUTypes.h";
2019
using mozilla::webgpu::WebGPUCompilationMessage from "mozilla/webgpu/WebGPUTypes.h";
2120
[MoveOnly] using mozilla::ipc::MutableSharedMemoryHandle from "mozilla/ipc/SharedMemoryHandle.h";
@@ -43,16 +42,6 @@ async protocol PWebGPU
4342
parent:
4443
async Messages(uint32_t nrOfMessages, ByteBuf serializedMessages, ByteBuf[] dataBuffers, MutableSharedMemoryHandle[] shmems);
4544

46-
// Ideally this would be sent in Messages(), but we need to implement
47-
// SurfaceDescriptor serialization first.
48-
async CreateExternalTextureSource(
49-
RawId deviceId,
50-
RawId queueId,
51-
RawId externalTextureSourceId,
52-
ExternalTextureSourceDescriptor aDesc
53-
);
54-
55-
5645
child:
5746
async ServerMessage(ByteBuf buf);
5847

dom/webgpu/ipc/WebGPUParent.cpp

Lines changed: 81 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <unordered_set>
99

10-
#include "ExternalTexture.h"
1110
#include "mozilla/PodOperations.h"
1211
#include "mozilla/ScopeExit.h"
1312
#include "mozilla/dom/WebGPUBinding.h"
@@ -172,18 +171,6 @@ extern void wgpu_server_remove_shared_texture(WGPUWebGPUParentPtr aParent,
172171
parent->RemoveSharedTexture(aId);
173172
}
174173

175-
extern void wgpu_parent_destroy_external_texture_source(
176-
WGPUWebGPUParentPtr aParent, WGPUExternalTextureSourceId aId) {
177-
auto* const parent = static_cast<WebGPUParent*>(aParent);
178-
parent->DestroyExternalTextureSource(aId);
179-
}
180-
181-
extern void wgpu_parent_drop_external_texture_source(
182-
WGPUWebGPUParentPtr aParent, WGPUExternalTextureSourceId aId) {
183-
auto* const parent = static_cast<WebGPUParent*>(aParent);
184-
parent->DropExternalTextureSource(aId);
185-
}
186-
187174
extern void wgpu_server_dealloc_buffer_shmem(WGPUWebGPUParentPtr aParent,
188175
WGPUBufferId aId) {
189176
auto* parent = static_cast<WebGPUParent*>(aParent);
@@ -371,60 +358,95 @@ extern void wgpu_parent_send_server_message(WGPUWebGPUParentPtr aParent,
371358

372359
} // namespace ffi
373360

374-
ErrorBuffer::ErrorBuffer() { mMessageUtf8[0] = 0; }
361+
// A fixed-capacity buffer for receiving textual error messages from
362+
// `wgpu_bindings`.
363+
//
364+
// The `ToFFI` method returns an `ffi::WGPUErrorBuffer` pointing to our
365+
// buffer, for you to pass to fallible FFI-visible `wgpu_bindings`
366+
// functions. These indicate failure by storing an error message in the
367+
// buffer, which you can retrieve by calling `GetError`.
368+
//
369+
// If you call `ToFFI` on this type, you must also call `GetError` to check for
370+
// an error. Otherwise, the destructor asserts.
371+
//
372+
// TODO: refactor this to avoid stack-allocating the buffer all the time.
373+
class ErrorBuffer {
374+
// if the message doesn't fit, it will be truncated
375+
static constexpr unsigned BUFFER_SIZE = 512;
376+
ffi::WGPUErrorBufferType mType = ffi::WGPUErrorBufferType_None;
377+
char mMessageUtf8[BUFFER_SIZE] = {};
378+
bool mAwaitingGetError = false;
379+
RawId mDeviceId = 0;
375380

376-
ErrorBuffer::~ErrorBuffer() { MOZ_ASSERT(!mAwaitingGetError); }
381+
public:
382+
ErrorBuffer() { mMessageUtf8[0] = 0; }
383+
ErrorBuffer(const ErrorBuffer&) = delete;
384+
~ErrorBuffer() { MOZ_ASSERT(!mAwaitingGetError); }
385+
386+
ffi::WGPUErrorBuffer ToFFI() {
387+
mAwaitingGetError = true;
388+
ffi::WGPUErrorBuffer errorBuf = {&mType, mMessageUtf8, BUFFER_SIZE,
389+
&mDeviceId};
390+
return errorBuf;
391+
}
392+
393+
ffi::WGPUErrorBufferType GetType() { return mType; }
394+
395+
static Maybe<dom::GPUErrorFilter> ErrorTypeToFilterType(
396+
ffi::WGPUErrorBufferType aType) {
397+
switch (aType) {
398+
case ffi::WGPUErrorBufferType_None:
399+
case ffi::WGPUErrorBufferType_DeviceLost:
400+
return {};
401+
case ffi::WGPUErrorBufferType_Internal:
402+
return Some(dom::GPUErrorFilter::Internal);
403+
case ffi::WGPUErrorBufferType_Validation:
404+
return Some(dom::GPUErrorFilter::Validation);
405+
case ffi::WGPUErrorBufferType_OutOfMemory:
406+
return Some(dom::GPUErrorFilter::Out_of_memory);
407+
case ffi::WGPUErrorBufferType_Sentinel:
408+
break;
409+
}
377410

378-
ffi::WGPUErrorBuffer ErrorBuffer::ToFFI() {
379-
mAwaitingGetError = true;
380-
ffi::WGPUErrorBuffer errorBuf = {&mType, mMessageUtf8, BUFFER_SIZE,
381-
&mDeviceId};
382-
return errorBuf;
383-
}
411+
MOZ_CRASH("invalid `ErrorBufferType`");
412+
}
384413

385-
ffi::WGPUErrorBufferType ErrorBuffer::GetType() { return mType; }
414+
struct Error {
415+
dom::GPUErrorFilter type;
416+
bool isDeviceLost;
417+
nsCString message;
418+
RawId deviceId;
419+
};
386420

387-
Maybe<dom::GPUErrorFilter> ErrorBuffer::ErrorTypeToFilterType(
388-
ffi::WGPUErrorBufferType aType) {
389-
switch (aType) {
390-
case ffi::WGPUErrorBufferType_None:
391-
case ffi::WGPUErrorBufferType_DeviceLost:
421+
// Retrieve the error message was stored in this buffer. Asserts that
422+
// this instance actually contains an error (viz., that `GetType() !=
423+
// ffi::WGPUErrorBufferType_None`).
424+
//
425+
// Mark this `ErrorBuffer` as having been handled, so its destructor
426+
// won't assert.
427+
Maybe<Error> GetError() {
428+
mAwaitingGetError = false;
429+
if (mType == ffi::WGPUErrorBufferType_DeviceLost) {
430+
// This error is for a lost device, so we return an Error struct
431+
// with the isDeviceLost bool set to true. It doesn't matter what
432+
// GPUErrorFilter type we use, so we just use Validation. The error
433+
// will not be reported.
434+
return Some(Error{dom::GPUErrorFilter::Validation, true,
435+
nsCString{mMessageUtf8}, mDeviceId});
436+
}
437+
auto filterType = ErrorTypeToFilterType(mType);
438+
if (!filterType) {
392439
return {};
393-
case ffi::WGPUErrorBufferType_Internal:
394-
return Some(dom::GPUErrorFilter::Internal);
395-
case ffi::WGPUErrorBufferType_Validation:
396-
return Some(dom::GPUErrorFilter::Validation);
397-
case ffi::WGPUErrorBufferType_OutOfMemory:
398-
return Some(dom::GPUErrorFilter::Out_of_memory);
399-
case ffi::WGPUErrorBufferType_Sentinel:
400-
break;
440+
}
441+
return Some(Error{*filterType, false, nsCString{mMessageUtf8}, mDeviceId});
401442
}
402443

403-
MOZ_CRASH("invalid `ErrorBufferType`");
404-
}
405-
406-
Maybe<ErrorBuffer::Error> ErrorBuffer::GetError() {
407-
mAwaitingGetError = false;
408-
if (mType == ffi::WGPUErrorBufferType_DeviceLost) {
409-
// This error is for a lost device, so we return an Error struct
410-
// with the isDeviceLost bool set to true. It doesn't matter what
411-
// GPUErrorFilter type we use, so we just use Validation. The error
412-
// will not be reported.
413-
return Some(Error{dom::GPUErrorFilter::Validation, true,
414-
nsCString{mMessageUtf8}, mDeviceId});
415-
}
416-
auto filterType = ErrorTypeToFilterType(mType);
417-
if (!filterType) {
418-
return {};
419-
}
420-
return Some(Error{*filterType, false, nsCString{mMessageUtf8}, mDeviceId});
421-
}
422-
423-
void ErrorBuffer::CoerceValidationToInternal() {
424-
if (mType == ffi::WGPUErrorBufferType_Validation) {
425-
mType = ffi::WGPUErrorBufferType_Internal;
444+
void CoerceValidationToInternal() {
445+
if (mType == ffi::WGPUErrorBufferType_Validation) {
446+
mType = ffi::WGPUErrorBufferType_Internal;
447+
}
426448
}
427-
}
449+
};
428450

429451
struct PendingSwapChainDrop {
430452
layers::RemoteTextureTxnType mTxnType;
@@ -792,28 +814,6 @@ void WebGPUParent::RemoveSharedTexture(RawId aTextureId) {
792814
}
793815
}
794816

795-
void WebGPUParent::DestroyExternalTextureSource(RawId aSourceId) {
796-
auto it = mExternalTextureSources.find(aSourceId);
797-
if (it != mExternalTextureSources.end()) {
798-
for (const auto textureId : it->second.TextureIds()) {
799-
ffi::wgpu_server_texture_destroy(mContext.get(), textureId);
800-
}
801-
}
802-
}
803-
804-
void WebGPUParent::DropExternalTextureSource(RawId aSourceId) {
805-
auto it = mExternalTextureSources.find(aSourceId);
806-
if (it != mExternalTextureSources.end()) {
807-
for (const auto viewId : it->second.ViewIds()) {
808-
ffi::wgpu_server_texture_view_drop(mContext.get(), viewId);
809-
}
810-
for (const auto textureId : it->second.TextureIds()) {
811-
ffi::wgpu_server_texture_drop(mContext.get(), textureId);
812-
}
813-
mExternalTextureSources.erase(it);
814-
}
815-
}
816-
817817
void WebGPUParent::QueueSubmit(RawId aQueueId, RawId aDeviceId,
818818
Span<const RawId> aCommandBuffers,
819819
Span<const RawId> aTextureIds) {
@@ -1564,18 +1564,6 @@ ipc::IPCResult WebGPUParent::RecvMessages(
15641564
return IPC_OK();
15651565
}
15661566

1567-
ipc::IPCResult WebGPUParent::RecvCreateExternalTextureSource(
1568-
RawId aDeviceId, RawId aQueueId, RawId aExternalTextureSourceId,
1569-
const ExternalTextureSourceDescriptor& aDesc) {
1570-
MOZ_RELEASE_ASSERT(mExternalTextureSources.find(aExternalTextureSourceId) ==
1571-
mExternalTextureSources.end());
1572-
mExternalTextureSources.emplace(
1573-
aExternalTextureSourceId,
1574-
ExternalTextureSourceHost::Create(this, aDeviceId, aQueueId, aDesc));
1575-
1576-
return IPC_OK();
1577-
}
1578-
15791567
void WebGPUParent::DevicePushErrorScope(RawId aDeviceId,
15801568
const dom::GPUErrorFilter aFilter) {
15811569
const auto& itr = mErrorScopeStackByDevice.find(aDeviceId);

0 commit comments

Comments
 (0)