Skip to content

Commit

Permalink
Use smart pointers in Modules/WebGPU
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270378
rdar://123810573

Reviewed by Mike Wyrzykowski.

* Source/WebCore/Modules/WebGPU/GPUBindGroupDescriptor.h:
(): Deleted.
* Source/WebCore/Modules/WebGPU/GPUBindGroupLayout.h:
* Source/WebCore/Modules/WebGPU/GPUBuffer.cpp:
(WebCore::makeArrayBuffer):
(WebCore::GPUBuffer::unmap):
* Source/WebCore/Modules/WebGPU/GPUBuffer.h:
* Source/WebCore/Modules/WebGPU/GPUBufferBinding.h:
* Source/WebCore/Modules/WebGPU/GPUCanvasConfiguration.h:
* Source/WebCore/Modules/WebGPU/GPUComputePassTimestampWrites.h:
* Source/WebCore/Modules/WebGPU/GPUImageCopyBuffer.h:
(): Deleted.
* Source/WebCore/Modules/WebGPU/GPUImageCopyTexture.h:
* Source/WebCore/Modules/WebGPU/GPUPresentationContext.cpp:
(WebCore::GPUPresentationContext::configure):
* Source/WebCore/Modules/WebGPU/GPUProgrammableStage.h:
(): Deleted.
* Source/WebCore/Modules/WebGPU/GPUQuerySet.h:
* Source/WebCore/Modules/WebGPU/GPURenderPassColorAttachment.h:
* Source/WebCore/Modules/WebGPU/GPURenderPassDepthStencilAttachment.h:
* Source/WebCore/Modules/WebGPU/GPURenderPassDescriptor.h:
(): Deleted.
* Source/WebCore/Modules/WebGPU/GPURenderPassTimestampWrites.h:
* Source/WebCore/Modules/WebGPU/GPUShaderModule.h:
* Source/WebCore/Modules/WebGPU/GPUTexture.h:
* Source/WebCore/Modules/WebGPU/GPUTextureView.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUComputePassTimestampWrites.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUPipelineDescriptorBase.h:
(): Deleted.
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUPipelineLayout.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUQuerySet.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPURenderPassColorAttachment.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPURenderPassDescriptor.h:
(): Deleted.
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPURenderPassTimestampWrites.h:
* Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUTextureView.h:

Canonical link: https://commits.webkit.org/275584@main
  • Loading branch information
achristensen07 committed Mar 2, 2024
1 parent 43475b5 commit 067f08a
Show file tree
Hide file tree
Showing 49 changed files with 82 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUBindGroupDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct GPUBindGroupDescriptor : public GPUObjectDescriptorBase {
};
}

GPUBindGroupLayout* layout { nullptr };
WeakPtr<GPUBindGroupLayout> layout;
Vector<GPUBindGroupEntry> entries;
};

Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/GPUBindGroupLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
#include "WebGPUBindGroupLayout.h"
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

class GPUBindGroupLayout : public RefCounted<GPUBindGroupLayout> {
class GPUBindGroupLayout : public RefCounted<GPUBindGroupLayout>, public CanMakeWeakPtr<GPUBindGroupLayout> {
public:
static Ref<GPUBindGroupLayout> create(Ref<WebGPU::BindGroupLayout>&& backing)
{
Expand Down
6 changes: 4 additions & 2 deletions Source/WebCore/Modules/WebGPU/GPUBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ static auto makeArrayBuffer(auto source, auto byteLength, auto& cachedArrayBuffe
auto arrayBuffer = ArrayBuffer::create(source, byteLength);
cachedArrayBuffer = arrayBuffer.ptr();
cachedArrayBuffer->pin();
device.addBufferToUnmap(buffer);
if (device)
device->addBufferToUnmap(buffer);
return arrayBuffer;
}

Expand Down Expand Up @@ -185,7 +186,8 @@ ExceptionOr<Ref<JSC::ArrayBuffer>> GPUBuffer::getMappedRange(std::optional<GPUSi
void GPUBuffer::unmap(ScriptExecutionContext& scriptExecutionContext)
{
internalUnmap(scriptExecutionContext);
m_device.removeBufferToUnmap(*this);
if (m_device)
m_device->removeBufferToUnmap(*this);
}

void GPUBuffer::internalUnmap(ScriptExecutionContext& scriptExecutionContext)
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/WebGPU/GPUBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ class GPUBuffer : public RefCounted<GPUBuffer>, public CanMakeWeakPtr<GPUBuffer>

Ref<WebGPU::Buffer> m_backing;
WebGPU::Buffer::MappedRange m_mappedRange;
JSC::ArrayBuffer* m_arrayBuffer { nullptr };
RefPtr<JSC::ArrayBuffer> m_arrayBuffer;
size_t m_bufferSize { 0 };
size_t m_mappedRangeOffset { 0 };
size_t m_mappedRangeSize { 0 };
const GPUBufferUsageFlags m_usage { 0 };
GPUBufferMapState m_mapState { GPUBufferMapState::Unmapped };
std::optional<MapAsyncPromise> m_pendingMapPromise;
GPUDevice& m_device;
WeakPtr<GPUDevice, WeakPtrImplWithEventTargetData> m_device;
using MappedRanges = WTF::RangeSet<WTF::Range<size_t>>;
MappedRanges m_mappedRanges;
HashSet<size_t, DefaultHash<size_t>, WTF::UnsignedWithZeroKeyHashTraits<size_t>> m_mappedPoints;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUBufferBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct GPUBufferBinding {
};
}

GPUBuffer* buffer { nullptr };
WeakPtr<GPUBuffer> buffer;
GPUSize64 offset { 0 };
std::optional<GPUSize64> size;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUCanvasConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct GPUCanvasConfiguration {
};
}

GPUDevice* device { nullptr };
WeakPtr<GPUDevice, WeakPtrImplWithEventTargetData> device;
GPUTextureFormat format { GPUTextureFormat::R8unorm };
GPUTextureUsageFlags usage { GPUTextureUsage::RENDER_ATTACHMENT };
Vector<GPUTextureFormat> viewFormats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct GPUComputePassTimestampWrites {
};
}

GPUQuerySet* querySet { nullptr };
WeakPtr<GPUQuerySet> querySet;
GPUSize32 beginningOfPassWriteIndex { UINT32_MAX };
GPUSize32 endOfPassWriteIndex { UINT32_MAX };
};
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUImageCopyBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct GPUImageCopyBuffer : public GPUImageDataLayout {
};
}

GPUBuffer* buffer { nullptr };
WeakPtr<GPUBuffer> buffer;
};

}
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUImageCopyTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct GPUImageCopyTexture {
};
}

GPUTexture* texture { nullptr };
WeakPtr<GPUTexture> texture;
GPUIntegerCoordinate mipLevel { 0 };
std::optional<GPUOrigin3D> origin;
GPUTextureAspect aspect { GPUTextureAspect::All };
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPUPresentationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace WebCore {

void GPUPresentationContext::configure(const GPUCanvasConfiguration& canvasConfiguration, GPUIntegerCoordinate width, GPUIntegerCoordinate height)
{
m_device = canvasConfiguration.device;
m_device = canvasConfiguration.device.get();
m_backing->configure(canvasConfiguration.convertToBacking());
m_textureDescriptor = GPUTextureDescriptor {
{ "canvas backing"_s },
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/GPUProgrammableStage.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <wtf/KeyValuePair.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
#include <wtf/WeakPtr.h>

namespace WebCore {

Expand All @@ -46,7 +47,7 @@ struct GPUProgrammableStage {
};
}

GPUShaderModule* module { nullptr };
WeakPtr<GPUShaderModule> module;
std::optional<String> entryPoint;
Vector<KeyValuePair<String, GPUPipelineConstantValue>> constants;
};
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/GPUQuerySet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
#include "WebGPUQuerySet.h"
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

class GPUQuerySet : public RefCounted<GPUQuerySet> {
class GPUQuerySet : public RefCounted<GPUQuerySet>, public CanMakeWeakPtr<GPUQuerySet> {
public:
static Ref<GPUQuerySet> create(Ref<WebGPU::QuerySet>&& backing, const GPUQuerySetDescriptor& descriptor)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/WebGPU/GPURenderPassColorAttachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ struct GPURenderPassColorAttachment {
};
}

GPUTextureView* view { nullptr };
WeakPtr<GPUTextureView> view;
std::optional<GPUIntegerCoordinate> depthSlice;
GPUTextureView* resolveTarget { nullptr };
WeakPtr<GPUTextureView> resolveTarget;

std::optional<GPUColor> clearValue;
GPULoadOp loadOp { GPULoadOp::Load };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct GPURenderPassDepthStencilAttachment {
};
}

GPUTextureView* view { nullptr };
WeakPtr<GPUTextureView> view;

std::optional<float> depthClearValue;
std::optional<GPULoadOp> depthLoadOp;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/WebGPU/GPURenderPassDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct GPURenderPassDescriptor : public GPUObjectDescriptorBase {

Vector<std::optional<GPURenderPassColorAttachment>> colorAttachments;
std::optional<GPURenderPassDepthStencilAttachment> depthStencilAttachment;
GPUQuerySet* occlusionQuerySet { nullptr };
WeakPtr<GPUQuerySet> occlusionQuerySet;
GPURenderPassTimestampWrites timestampWrites;
std::optional<GPUSize64> maxDrawCount;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct GPURenderPassTimestampWrites {
};
}

GPUQuerySet* querySet { nullptr };
WeakPtr<GPUQuerySet> querySet;
GPUSize32 beginningOfPassWriteIndex { UINT32_MAX };
GPUSize32 endOfPassWriteIndex { UINT32_MAX };
};
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/GPUShaderModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
#include "WebGPUShaderModule.h"
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

class DeferredPromise;

class GPUShaderModule : public RefCounted<GPUShaderModule> {
class GPUShaderModule : public RefCounted<GPUShaderModule>, public CanMakeWeakPtr<GPUShaderModule> {
public:
static Ref<GPUShaderModule> create(Ref<WebGPU::ShaderModule>&& backing)
{
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/GPUTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <optional>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore {
Expand All @@ -43,7 +44,7 @@ class GPUTextureView;
struct GPUTextureDescriptor;
struct GPUTextureViewDescriptor;

class GPUTexture : public RefCounted<GPUTexture> {
class GPUTexture : public RefCounted<GPUTexture>, public CanMakeWeakPtr<GPUTexture> {
public:
static Ref<GPUTexture> create(Ref<WebGPU::Texture>&& backing, const GPUTextureDescriptor& descriptor, const GPUDevice& device)
{
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/GPUTextureView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
#include "WebGPUTextureView.h"
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore {

class GPUTextureView : public RefCounted<GPUTextureView> {
class GPUTextureView : public RefCounted<GPUTextureView>, public CanMakeWeakPtr<GPUTextureView> {
public:
static Ref<GPUTextureView> create(Ref<WebGPU::TextureView>&& backing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
#include "WebGPUBindGroupEntry.h"
#include "WebGPUObjectDescriptorBase.h"
#include <wtf/Vector.h>
#include <wtf/WeakRef.h>

namespace WebCore::WebGPU {

class BindGroupLayout;

struct BindGroupDescriptor : public ObjectDescriptorBase {
BindGroupLayout& layout;
WeakRef<BindGroupLayout> layout;
Vector<BindGroupEntry> entries;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
#include <wtf/DebugHeap.h>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore::WebGPU {

class BindGroupLayout : public RefCounted<BindGroupLayout> {
class BindGroupLayout : public RefCounted<BindGroupLayout>, public CanMakeWeakPtr<BindGroupLayout> {
public:
virtual ~BindGroupLayout() = default;

Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
#include <wtf/CompletionHandler.h>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore::WebGPU {

class Buffer : public RefCounted<Buffer> {
class Buffer : public RefCounted<Buffer>, public CanMakeWeakPtr<Buffer> {
public:
virtual ~Buffer() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
#include "WebGPUIntegralTypes.h"
#include <optional>
#include <wtf/Ref.h>
#include <wtf/WeakRef.h>

namespace WebCore::WebGPU {

class Buffer;

struct BufferBinding {
Buffer& buffer;
WeakRef<Buffer> buffer;
Size64 offset { 0 };
std::optional<Size64> size;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
#include "WebGPUTextureFormat.h"
#include "WebGPUTextureUsage.h"
#include <wtf/Vector.h>
#include <wtf/WeakRef.h>

namespace WebCore::WebGPU {

class Device;

struct CanvasConfiguration {
Device& device;
WeakRef<Device> device;
TextureFormat format { TextureFormat::R8unorm };
TextureUsageFlags usage { TextureUsage::RenderAttachment };
Vector<TextureFormat> viewFormats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@
#include "WebGPUIntegralTypes.h"
#include <wtf/Ref.h>
#include <wtf/Vector.h>
#include <wtf/WeakPtr.h>

namespace WebCore::WebGPU {

class QuerySet;

struct ComputePassTimestampWrites {
QuerySet* querySet { nullptr };
WeakPtr<QuerySet> querySet;
Size32 beginningOfPassWriteIndex { 0 };
Size32 endOfPassWriteIndex { 0 };
};
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/WebGPU/InternalAPI/WebGPUDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <wtf/CompletionHandler.h>
#include <wtf/HashSet.h>
#include <wtf/Ref.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/WTFString.h>

#if HAVE(IOSURFACE)
Expand Down Expand Up @@ -76,7 +77,7 @@ class Surface;
class Texture;
struct TextureDescriptor;

class Device : public RefCounted<Device> {
class Device : public RefCounted<Device>, public CanMakeWeakPtr<Device> {
public:
virtual ~Device() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@

#include "WebGPUImageDataLayout.h"
#include <wtf/Ref.h>
#include <wtf/WeakRef.h>

namespace WebCore::WebGPU {

class Buffer;

struct ImageCopyBuffer : public ImageDataLayout {
Buffer& buffer;
WeakRef<Buffer> buffer;
};

} // namespace WebCore::WebGPU
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
#include "WebGPUTextureAspect.h"
#include <optional>
#include <wtf/Ref.h>
#include <wtf/WeakRef.h>

namespace WebCore::WebGPU {

class Texture;

struct ImageCopyTexture {
Texture& texture;
WeakRef<Texture> texture;
IntegerCoordinate mipLevel { 0 };
std::optional<Origin3D> origin;
TextureAspect aspect { TextureAspect::All };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
#pragma once

#include "WebGPUObjectDescriptorBase.h"
#include <wtf/WeakPtr.h>

namespace WebCore::WebGPU {

class PipelineLayout;

struct PipelineDescriptorBase : public ObjectDescriptorBase {
PipelineLayout* layout { nullptr };
WeakPtr<PipelineLayout> layout;
};

} // namespace WebCore::WebGPU
Loading

0 comments on commit 067f08a

Please sign in to comment.