Bug 1883810: refactor(webgpu): subvert/targetContext/presentationContext for `CommandEncoder`s r=webgpu-reviewers,jimb

Differential Revision: https://phabricator.services.mozilla.com/D203959
This commit is contained in:
Erich Gubler 2024-03-13 16:03:11 +00:00
Родитель c35973d8c9
Коммит 1a670cacb4
4 изменённых файлов: 18 добавлений и 15 удалений

Просмотреть файл

@ -16,10 +16,13 @@ namespace mozilla::webgpu {
GPU_IMPL_CYCLE_COLLECTION(CommandBuffer, mParent) GPU_IMPL_CYCLE_COLLECTION(CommandBuffer, mParent)
GPU_IMPL_JS_WRAP(CommandBuffer) GPU_IMPL_JS_WRAP(CommandBuffer)
CommandBuffer::CommandBuffer(Device* const aParent, RawId aId, CommandBuffer::CommandBuffer(
nsTArray<WeakPtr<CanvasContext>>&& aTargetContexts, Device* const aParent, RawId aId,
nsTArray<WeakPtr<CanvasContext>>&& aPresentationContexts,
RefPtr<CommandEncoder>&& aEncoder) RefPtr<CommandEncoder>&& aEncoder)
: ChildOf(aParent), mId(aId), mTargetContexts(std::move(aTargetContexts)) { : ChildOf(aParent),
mId(aId),
mPresentationContexts(std::move(aPresentationContexts)) {
mEncoder = std::move(aEncoder); mEncoder = std::move(aEncoder);
MOZ_RELEASE_ASSERT(aId); MOZ_RELEASE_ASSERT(aId);
} }
@ -33,9 +36,9 @@ Maybe<RawId> CommandBuffer::Commit() {
return Nothing(); return Nothing();
} }
mValid = false; mValid = false;
for (const auto& targetContext : mTargetContexts) { for (const auto& presentationContext : mPresentationContexts) {
if (targetContext) { if (presentationContext) {
targetContext->MaybeQueueSwapChainPresent(); presentationContext->MaybeQueueSwapChainPresent();
} }
} }
return Some(mId); return Some(mId);

Просмотреть файл

@ -22,7 +22,7 @@ class CommandBuffer final : public ObjectBase, public ChildOf<Device> {
GPU_DECL_JS_WRAP(CommandBuffer) GPU_DECL_JS_WRAP(CommandBuffer)
CommandBuffer(Device* const aParent, RawId aId, CommandBuffer(Device* const aParent, RawId aId,
nsTArray<WeakPtr<CanvasContext>>&& aTargetContexts, nsTArray<WeakPtr<CanvasContext>>&& aPresentationContexts,
RefPtr<CommandEncoder>&& aEncoder); RefPtr<CommandEncoder>&& aEncoder);
Maybe<RawId> Commit(); Maybe<RawId> Commit();
@ -33,7 +33,7 @@ class CommandBuffer final : public ObjectBase, public ChildOf<Device> {
void Cleanup(); void Cleanup();
const RawId mId; const RawId mId;
const nsTArray<WeakPtr<CanvasContext>> mTargetContexts; const nsTArray<WeakPtr<CanvasContext>> mPresentationContexts;
// Command buffers and encoders share the same identity (this is a // Command buffers and encoders share the same identity (this is a
// simplifcation currently made by wgpu). To avoid dropping the same ID twice, // simplifcation currently made by wgpu). To avoid dropping the same ID twice,
// the wgpu resource lifetime is tied to the encoder which is held alive by // the wgpu resource lifetime is tied to the encoder which is held alive by

Просмотреть файл

@ -123,7 +123,7 @@ void CommandEncoder::CopyBufferToTexture(
const auto& targetContext = aDestination.mTexture->mTargetContext; const auto& targetContext = aDestination.mTexture->mTargetContext;
if (targetContext) { if (targetContext) {
mTargetContexts.AppendElement(targetContext); mPresentationContexts.AppendElement(targetContext);
} }
} }
void CommandEncoder::CopyTextureToBuffer( void CommandEncoder::CopyTextureToBuffer(
@ -158,7 +158,7 @@ void CommandEncoder::CopyTextureToTexture(
const auto& targetContext = aDestination.mTexture->mTargetContext; const auto& targetContext = aDestination.mTexture->mTargetContext;
if (targetContext) { if (targetContext) {
mTargetContexts.AppendElement(targetContext); mPresentationContexts.AppendElement(targetContext);
} }
} }
@ -218,11 +218,11 @@ already_AddRefed<RenderPassEncoder> CommandEncoder::BeginRenderPass(
for (const auto& at : aDesc.mColorAttachments) { for (const auto& at : aDesc.mColorAttachments) {
auto* targetContext = at.mView->GetTargetContext(); auto* targetContext = at.mView->GetTargetContext();
if (targetContext) { if (targetContext) {
mTargetContexts.AppendElement(targetContext); mPresentationContexts.AppendElement(targetContext);
} }
if (at.mResolveTarget.WasPassed()) { if (at.mResolveTarget.WasPassed()) {
targetContext = at.mResolveTarget.Value().GetTargetContext(); targetContext = at.mResolveTarget.Value().GetTargetContext();
mTargetContexts.AppendElement(targetContext); mPresentationContexts.AppendElement(targetContext);
} }
} }
@ -263,7 +263,7 @@ already_AddRefed<CommandBuffer> CommandEncoder::Finish(
RefPtr<CommandEncoder> me(this); RefPtr<CommandEncoder> me(this);
RefPtr<CommandBuffer> comb = new CommandBuffer( RefPtr<CommandBuffer> comb = new CommandBuffer(
mParent, mId, std::move(mTargetContexts), std::move(me)); mParent, mId, std::move(mPresentationContexts), std::move(me));
return comb.forget(); return comb.forget();
} }

Просмотреть файл

@ -67,7 +67,7 @@ class CommandEncoder final : public ObjectBase, public ChildOf<Device> {
void Cleanup(); void Cleanup();
RefPtr<WebGPUChild> mBridge; RefPtr<WebGPUChild> mBridge;
nsTArray<WeakPtr<CanvasContext>> mTargetContexts; nsTArray<WeakPtr<CanvasContext>> mPresentationContexts;
public: public:
const auto& GetDevice() const { return mParent; }; const auto& GetDevice() const { return mParent; };