Diff
Modified: trunk/Source/WebGPU/ChangeLog (292566 => 292567)
--- trunk/Source/WebGPU/ChangeLog 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/ChangeLog 2022-04-07 21:44:00 UTC (rev 292567)
@@ -1,5 +1,130 @@
2022-04-07 Myles C. Maxfield <[email protected]>
+ [WebGPU] Give objects a notion of invalidity
+ https://bugs.webkit.org/show_bug.cgi?id=238720
+
+ Reviewed by Kimmo Kinnunen.
+
+ This is the biggest blocker for running the WebGPU conformance test suite. WebGPU is designed
+ such that creation routines don't return undefined if the object couldn't be created; instead,
+ in "invalid" object is returned. This patch is a step on the path to making creation routines
+ never return nullptr.
+
+ Some objects have destroy() methods which makes the object invalid. Those will be implemented
+ in a forthcoming patch.
+
+ * WebGPU/Adapter.h:
+ (WebGPU::Adapter::createInvalid):
+ (WebGPU::Adapter::isValid const):
+ * WebGPU/Adapter.mm:
+ (WebGPU::Adapter::Adapter):
+ * WebGPU/BindGroup.h:
+ (WebGPU::BindGroup::createInvalid):
+ (WebGPU::BindGroup::isValid const):
+ * WebGPU/BindGroup.mm:
+ (WebGPU::BindGroup::BindGroup):
+ * WebGPU/BindGroupLayout.h:
+ (WebGPU::BindGroupLayout::createInvalid):
+ (WebGPU::BindGroupLayout::isValid const):
+ * WebGPU/BindGroupLayout.mm:
+ (WebGPU::BindGroupLayout::BindGroupLayout):
+ * WebGPU/Buffer.h:
+ (WebGPU::Buffer::createInvalid):
+ (WebGPU::Buffer::isValid const):
+ * WebGPU/Buffer.mm:
+ (WebGPU::Buffer::Buffer):
+ * WebGPU/CommandBuffer.h:
+ (WebGPU::CommandBuffer::createInvalid):
+ (WebGPU::CommandBuffer::isValid const):
+ * WebGPU/CommandBuffer.mm:
+ (WebGPU::CommandBuffer::CommandBuffer):
+ * WebGPU/CommandEncoder.h:
+ (WebGPU::CommandEncoder::createInvalid):
+ (WebGPU::CommandEncoder::isValid const):
+ * WebGPU/CommandEncoder.mm:
+ (WebGPU::CommandEncoder::CommandEncoder):
+ * WebGPU/ComputePassEncoder.h:
+ (WebGPU::ComputePassEncoder::createInvalid):
+ (WebGPU::ComputePassEncoder::isValid const):
+ * WebGPU/ComputePassEncoder.mm:
+ (WebGPU::ComputePassEncoder::ComputePassEncoder):
+ * WebGPU/ComputePipeline.h:
+ (WebGPU::ComputePipeline::createInvalid):
+ (WebGPU::ComputePipeline::isValid const):
+ * WebGPU/ComputePipeline.mm:
+ (WebGPU::ComputePipeline::ComputePipeline):
+ * WebGPU/Device.h:
+ (WebGPU::Device::createInvalid):
+ (WebGPU::Device::isValid const):
+ * WebGPU/Device.mm:
+ (WebGPU::Device::Device):
+ * WebGPU/Instance.h:
+ (WebGPU::Instance::createInvalid):
+ (WebGPU::Instance::isValid const):
+ * WebGPU/Instance.mm:
+ (WebGPU::Instance::Instance):
+ (WebGPU::m_isValid):
+ * WebGPU/PipelineLayout.h:
+ (WebGPU::PipelineLayout::createInvalid):
+ (WebGPU::PipelineLayout::isValid const):
+ * WebGPU/PipelineLayout.mm:
+ (WebGPU::PipelineLayout::PipelineLayout):
+ * WebGPU/QuerySet.h:
+ (WebGPU::QuerySet::createInvalid):
+ (WebGPU::QuerySet::isValid const):
+ * WebGPU/QuerySet.mm:
+ (WebGPU::QuerySet::QuerySet):
+ * WebGPU/Queue.h:
+ (WebGPU::Queue::createInvalid):
+ (WebGPU::Queue::isValid const):
+ * WebGPU/Queue.mm:
+ (WebGPU::Queue::Queue):
+ * WebGPU/RenderBundle.h:
+ (WebGPU::RenderBundle::createInvalid):
+ (WebGPU::RenderBundle::isValid const):
+ * WebGPU/RenderBundle.mm:
+ (WebGPU::RenderBundle::RenderBundle):
+ * WebGPU/RenderBundleEncoder.h:
+ (WebGPU::RenderBundleEncoder::createInvalid):
+ (WebGPU::RenderBundleEncoder::isValid const):
+ * WebGPU/RenderBundleEncoder.mm:
+ (WebGPU::RenderBundleEncoder::RenderBundleEncoder):
+ * WebGPU/RenderPassEncoder.h:
+ (WebGPU::RenderPassEncoder::createInvalid):
+ (WebGPU::RenderPassEncoder::isValid const):
+ * WebGPU/RenderPassEncoder.mm:
+ (WebGPU::RenderPassEncoder::RenderPassEncoder):
+ * WebGPU/RenderPipeline.h:
+ (WebGPU::RenderPipeline::createInvalid):
+ (WebGPU::RenderPipeline::isValid const):
+ * WebGPU/RenderPipeline.mm:
+ (WebGPU::RenderPipeline::RenderPipeline):
+ * WebGPU/Sampler.h:
+ (WebGPU::Sampler::createInvalid):
+ (WebGPU::Sampler::isValid const):
+ * WebGPU/Sampler.mm:
+ (WebGPU::Sampler::Sampler):
+ * WebGPU/ShaderModule.h:
+ (WebGPU::ShaderModule::createInvalid):
+ (WebGPU::ShaderModule::isValid const):
+ * WebGPU/ShaderModule.mm:
+ (WebGPU::ShaderModule::convertCheckResult):
+ (WebGPU::ShaderModule::ShaderModule):
+ (WebGPU::ShaderModule::getCompilationInfo):
+ (WebGPU::ShaderModule::ast const):
+ * WebGPU/Texture.h:
+ (WebGPU::Texture::createInvalid):
+ (WebGPU::Texture::isValid const):
+ * WebGPU/Texture.mm:
+ (WebGPU::Texture::Texture):
+ * WebGPU/TextureView.h:
+ (WebGPU::TextureView::createInvalid):
+ (WebGPU::TextureView::isValid const):
+ * WebGPU/TextureView.mm:
+ (WebGPU::TextureView::TextureView):
+
+2022-04-07 Myles C. Maxfield <[email protected]>
+
[WebGPU] Add support for the "is valid to use with" operation to WebGPU objects
https://bugs.webkit.org/show_bug.cgi?id=238719
Modified: trunk/Source/WebGPU/WebGPU/Adapter.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Adapter.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Adapter.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -47,6 +47,10 @@
{
return adoptRef(*new Adapter(device, instance));
}
+ static Ref<Adapter> createInvalid(Instance& instance)
+ {
+ return adoptRef(*new Adapter(instance));
+ }
~Adapter();
@@ -56,8 +60,11 @@
bool hasFeature(WGPUFeatureName);
void requestDevice(const WGPUDeviceDescriptor&, CompletionHandler<void(WGPURequestDeviceStatus, RefPtr<Device>&&, String&&)>&& callback);
+ bool isValid() const { return m_device; }
+
private:
Adapter(id<MTLDevice>, Instance&);
+ Adapter(Instance&);
const id<MTLDevice> m_device { nil };
const Ref<Instance> m_instance;
Modified: trunk/Source/WebGPU/WebGPU/Adapter.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -39,6 +39,11 @@
{
}
+Adapter::Adapter(Instance& instance)
+ : m_instance(instance)
+{
+}
+
Adapter::~Adapter() = default;
size_t Adapter::enumerateFeatures(WGPUFeatureName*)
Modified: trunk/Source/WebGPU/WebGPU/BindGroup.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/BindGroup.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/BindGroup.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -44,11 +44,17 @@
{
return adoptRef(*new BindGroup(vertexArgumentBuffer, fragmentArgumentBuffer, computeArgumentBuffer, device));
}
+ static Ref<BindGroup> createInvalid(Device& device)
+ {
+ return adoptRef(*new BindGroup(device));
+ }
~BindGroup();
void setLabel(String&&);
+ bool isValid() const { return m_vertexArgumentBuffer || m_fragmentArgumentBuffer || m_computeArgumentBuffer; }
+
id<MTLBuffer> vertexArgumentBuffer() const { return m_vertexArgumentBuffer; }
id<MTLBuffer> fragmentArgumentBuffer() const { return m_fragmentArgumentBuffer; }
id<MTLBuffer> computeArgumentBuffer() const { return m_computeArgumentBuffer; }
@@ -57,6 +63,7 @@
private:
BindGroup(id<MTLBuffer> vertexArgumentBuffer, id<MTLBuffer> fragmentArgumentBuffer, id<MTLBuffer> computeArgumentBuffer, Device&);
+ BindGroup(Device&);
const id<MTLBuffer> m_vertexArgumentBuffer { nil };
const id<MTLBuffer> m_fragmentArgumentBuffer { nil };
Modified: trunk/Source/WebGPU/WebGPU/BindGroup.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/BindGroup.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/BindGroup.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -122,6 +122,11 @@
{
}
+BindGroup::BindGroup(Device& device)
+ : m_device(device)
+{
+}
+
BindGroup::~BindGroup() = default;
void BindGroup::setLabel(String&& label)
Modified: trunk/Source/WebGPU/WebGPU/BindGroupLayout.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/BindGroupLayout.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/BindGroupLayout.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -44,11 +44,17 @@
{
return adoptRef(*new BindGroupLayout(vertexArgumentEncoder, fragmentArgumentEncoder, computeArgumentEncoder, device));
}
+ static Ref<BindGroupLayout> createInvalid(Device& device)
+ {
+ return adoptRef(*new BindGroupLayout(device));
+ }
~BindGroupLayout();
void setLabel(String&&);
+ bool isValid() const { return m_vertexArgumentEncoder || m_fragmentArgumentEncoder || m_computeArgumentEncoder; }
+
NSUInteger encodedLength() const;
id<MTLArgumentEncoder> vertexArgumentEncoder() const { return m_vertexArgumentEncoder; }
@@ -59,6 +65,7 @@
private:
BindGroupLayout(id<MTLArgumentEncoder> vertexArgumentEncoder, id<MTLArgumentEncoder> fragmentArgumentEncoder, id<MTLArgumentEncoder> computeArgumentEncoder, Device&);
+ BindGroupLayout(Device&);
const id<MTLArgumentEncoder> m_vertexArgumentEncoder { nil };
const id<MTLArgumentEncoder> m_fragmentArgumentEncoder { nil };
Modified: trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -224,6 +224,11 @@
{
}
+BindGroupLayout::BindGroupLayout(Device& device)
+ : m_device(device)
+{
+}
+
BindGroupLayout::~BindGroupLayout() = default;
void BindGroupLayout::setLabel(String&& label)
Modified: trunk/Source/WebGPU/WebGPU/Buffer.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Buffer.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Buffer.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -54,6 +54,10 @@
{
return adoptRef(*new Buffer(buffer, size, usage, initialState, initialMappingRange, device));
}
+ static Ref<Buffer> createInvalid(Device& device)
+ {
+ return adoptRef(*new Buffer(device));
+ }
~Buffer();
@@ -64,6 +68,8 @@
void unmap();
void setLabel(String&&);
+ bool isValid() const { return m_buffer; }
+
// https://gpuweb.github.io/gpuweb/#buffer-state
// Each GPUBuffer has a current buffer state on the Content timeline which is one of the following:
enum class State : uint8_t {
@@ -83,6 +89,7 @@
private:
Buffer(id<MTLBuffer>, uint64_t size, WGPUBufferUsageFlags, State initialState, MappingRange initialMappingRange, Device&);
+ Buffer(Device&);
bool validateGetMappedRange(size_t offset, size_t rangeSize) const;
bool validateMapAsync(WGPUMapModeFlags, size_t offset, size_t rangeSize) const;
Modified: trunk/Source/WebGPU/WebGPU/Buffer.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -134,6 +134,11 @@
{
}
+Buffer::Buffer(Device& device)
+ : m_device(device)
+{
+}
+
Buffer::~Buffer() = default;
void Buffer::destroy()
Modified: trunk/Source/WebGPU/WebGPU/CommandBuffer.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/CommandBuffer.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/CommandBuffer.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -44,11 +44,17 @@
{
return adoptRef(*new CommandBuffer(commandBuffer, device));
}
+ static Ref<CommandBuffer> createInvalid(Device& device)
+ {
+ return adoptRef(*new CommandBuffer(device));
+ }
~CommandBuffer();
void setLabel(String&&);
+ bool isValid() const { return m_commandBuffer; }
+
id<MTLCommandBuffer> commandBuffer() const { return m_commandBuffer; }
Device& device() const { return m_device; }
@@ -55,6 +61,7 @@
private:
CommandBuffer(id<MTLCommandBuffer>, Device&);
+ CommandBuffer(Device&);
const id<MTLCommandBuffer> m_commandBuffer { nil };
Modified: trunk/Source/WebGPU/WebGPU/CommandBuffer.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/CommandBuffer.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/CommandBuffer.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -36,6 +36,11 @@
{
}
+CommandBuffer::CommandBuffer(Device& device)
+ : m_device(device)
+{
+}
+
CommandBuffer::~CommandBuffer() = default;
void CommandBuffer::setLabel(String&& label)
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -51,6 +51,10 @@
{
return adoptRef(*new CommandEncoder(commandBuffer, device));
}
+ static Ref<CommandEncoder> createInvalid(Device& device)
+ {
+ return adoptRef(*new CommandEncoder(device));
+ }
~CommandEncoder();
@@ -71,8 +75,11 @@
Device& device() const { return m_device; }
+ bool isValid() const { return m_commandBuffer; }
+
private:
CommandEncoder(id<MTLCommandBuffer>, Device&);
+ CommandEncoder(Device&);
bool validateFinish() const;
bool validatePopDebugGroup() const;
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -61,6 +61,11 @@
{
}
+CommandEncoder::CommandEncoder(Device& device)
+ : m_device(device)
+{
+}
+
CommandEncoder::~CommandEncoder()
{
finalizeBlitCommandEncoder();
Modified: trunk/Source/WebGPU/WebGPU/ComputePassEncoder.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/ComputePassEncoder.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/ComputePassEncoder.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -49,6 +49,10 @@
{
return adoptRef(*new ComputePassEncoder(computeCommandEncoder, device));
}
+ static Ref<ComputePassEncoder> createInvalid(Device& device)
+ {
+ return adoptRef(*new ComputePassEncoder(device));
+ }
~ComputePassEncoder();
@@ -66,8 +70,11 @@
Device& device() const { return m_device; }
+ bool isValid() const { return m_computeCommandEncoder; }
+
private:
ComputePassEncoder(id<MTLComputeCommandEncoder>, Device&);
+ ComputePassEncoder(Device&);
bool validatePopDebugGroup() const;
Modified: trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/ComputePassEncoder.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -40,6 +40,11 @@
{
}
+ComputePassEncoder::ComputePassEncoder(Device& device)
+ : m_device(device)
+{
+}
+
ComputePassEncoder::~ComputePassEncoder() = default;
void ComputePassEncoder::beginPipelineStatisticsQuery(const QuerySet& querySet, uint32_t queryIndex)
Modified: trunk/Source/WebGPU/WebGPU/ComputePipeline.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/ComputePipeline.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/ComputePipeline.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -45,6 +45,10 @@
{
return adoptRef(*new ComputePipeline(computePipelineState, device));
}
+ static Ref<ComputePipeline> createInvalid(Device& device)
+ {
+ return adoptRef(*new ComputePipeline(device));
+ }
~ComputePipeline();
@@ -51,6 +55,8 @@
BindGroupLayout* getBindGroupLayout(uint32_t groupIndex);
void setLabel(String&&);
+ bool isValid() const { return m_computePipelineState; }
+
id<MTLComputePipelineState> computePipelineState() const { return m_computePipelineState; }
Device& device() const { return m_device; }
@@ -57,6 +63,7 @@
private:
ComputePipeline(id<MTLComputePipelineState>, Device&);
+ ComputePipeline(Device&);
const id<MTLComputePipelineState> m_computePipelineState { nil };
Modified: trunk/Source/WebGPU/WebGPU/ComputePipeline.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/ComputePipeline.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/ComputePipeline.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -181,6 +181,11 @@
{
}
+ComputePipeline::ComputePipeline(Device& device)
+ : m_device(device)
+{
+}
+
ComputePipeline::~ComputePipeline() = default;
BindGroupLayout* ComputePipeline::getBindGroupLayout(uint32_t groupIndex)
Modified: trunk/Source/WebGPU/WebGPU/Device.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Device.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Device.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -30,8 +30,8 @@
#import <wtf/FastMalloc.h>
#import <wtf/Function.h>
#import <wtf/Ref.h>
+#import <wtf/ThreadSafeRefCounted.h>
#import <wtf/RefPtr.h>
-#import <wtf/ThreadSafeRefCounted.h>
#import <wtf/Vector.h>
#import <wtf/text/WTFString.h>
@@ -61,6 +61,10 @@
WTF_MAKE_FAST_ALLOCATED;
public:
static RefPtr<Device> create(id<MTLDevice>, String&& deviceLabel, Instance&);
+ static Ref<Device> createInvalid(Instance& instance)
+ {
+ return adoptRef(*new Device(instance));
+ }
~Device();
@@ -90,6 +94,8 @@
void setUncapturedErrorCallback(Function<void(WGPUErrorType, String&&)>&&);
void setLabel(String&&);
+ bool isValid() const { return m_device; }
+
id<MTLDevice> device() const { return m_device; }
void generateAValidationError(String&& message);
@@ -99,6 +105,7 @@
private:
Device(id<MTLDevice>, id<MTLCommandQueue> defaultQueue, Instance&);
+ Device(Instance&);
struct ErrorScope;
ErrorScope* currentErrorScope(WGPUErrorFilter);
Modified: trunk/Source/WebGPU/WebGPU/Device.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Device.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Device.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -68,6 +68,12 @@
{
}
+Device::Device(Instance& instance)
+ : m_defaultQueue(Queue::createInvalid(*this))
+ , m_instance(instance)
+{
+}
+
Device::~Device() = default;
void Device::destroy()
Modified: trunk/Source/WebGPU/WebGPU/Instance.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Instance.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Instance.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -46,6 +46,10 @@
WTF_MAKE_FAST_ALLOCATED;
public:
static RefPtr<Instance> create(const WGPUInstanceDescriptor&);
+ static Ref<Instance> createInvalid()
+ {
+ return adoptRef(*new Instance());
+ }
~Instance();
@@ -53,6 +57,8 @@
void processEvents();
void requestAdapter(const WGPURequestAdapterOptions&, CompletionHandler<void(WGPURequestAdapterStatus, RefPtr<Adapter>&&, String&&)>&& callback);
+ bool isValid() const { return m_isValid; }
+
// This can be called on a background thread.
using WorkItem = CompletionHandler<void(void)>;
void scheduleWork(WorkItem&&);
@@ -59,6 +65,7 @@
private:
Instance(WGPUScheduleWorkBlock);
+ Instance();
// This can be called on a background thread.
void defaultScheduleWork(WGPUWorkItem&&);
@@ -67,6 +74,7 @@
Deque<WGPUWorkItem> m_pendingWork WTF_GUARDED_BY_LOCK(m_lock);
const WGPUScheduleWorkBlock m_scheduleWorkBlock;
Lock m_lock;
+ bool m_isValid { true };
};
} // namespace WebGPU
Modified: trunk/Source/WebGPU/WebGPU/Instance.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Instance.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Instance.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -56,6 +56,12 @@
{
}
+Instance::Instance()
+ : m_scheduleWorkBlock(^(WGPUWorkItem workItem) { defaultScheduleWork(WTFMove(workItem)); })
+ , m_isValid(false)
+{
+}
+
Instance::~Instance() = default;
RefPtr<Surface> Instance::createSurface(const WGPUSurfaceDescriptor& descriptor)
Modified: trunk/Source/WebGPU/WebGPU/PipelineLayout.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/PipelineLayout.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/PipelineLayout.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -46,11 +46,18 @@
{
return adoptRef(*new PipelineLayout(WTFMove(bindGroupLayouts), device));
}
+ static Ref<PipelineLayout> createInvalid(Device& device)
+ {
+ return adoptRef(*new PipelineLayout(device));
+ }
~PipelineLayout();
void setLabel(String&&);
+ // FIXME: Is it impossible to legitimately have no bind group layouts in a valid object?
+ bool isValid() const { return !m_bindGroupLayouts.isEmpty(); }
+
bool operator==(const PipelineLayout&) const;
bool operator!=(const PipelineLayout&) const;
@@ -61,6 +68,7 @@
private:
PipelineLayout(Vector<Ref<BindGroupLayout>>&&, Device&);
+ PipelineLayout(Device&);
const Vector<Ref<BindGroupLayout>> m_bindGroupLayouts;
Modified: trunk/Source/WebGPU/WebGPU/PipelineLayout.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/PipelineLayout.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/PipelineLayout.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -52,6 +52,11 @@
{
}
+PipelineLayout::PipelineLayout(Device& device)
+ : m_device(device)
+{
+}
+
PipelineLayout::~PipelineLayout() = default;
void PipelineLayout::setLabel(String&&)
Modified: trunk/Source/WebGPU/WebGPU/QuerySet.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/QuerySet.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/QuerySet.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -44,6 +44,10 @@
{
return adoptRef(*new QuerySet(counterSampleBuffer, device));
}
+ static Ref<QuerySet> createInvalid(Device& device)
+ {
+ return adoptRef(*new QuerySet(device));
+ }
~QuerySet();
@@ -50,6 +54,8 @@
void destroy();
void setLabel(String&&);
+ bool isValid() const { return m_counterSampleBuffer; }
+
id<MTLCounterSampleBuffer> counterSampleBuffer() const { return m_counterSampleBuffer; }
Device& device() const { return m_device; }
@@ -56,6 +62,7 @@
private:
QuerySet(id<MTLCounterSampleBuffer>, Device&);
+ QuerySet(Device&);
const id<MTLCounterSampleBuffer> m_counterSampleBuffer { nil };
Modified: trunk/Source/WebGPU/WebGPU/QuerySet.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/QuerySet.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/QuerySet.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -43,6 +43,11 @@
{
}
+QuerySet::QuerySet(Device& device)
+ : m_device(device)
+{
+}
+
QuerySet::~QuerySet() = default;
void QuerySet::destroy()
Modified: trunk/Source/WebGPU/WebGPU/Queue.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Queue.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Queue.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -51,6 +51,10 @@
{
return adoptRef(*new Queue(commandQueue, device));
}
+ static Ref<Queue> createInvalid(Device& device)
+ {
+ return adoptRef(*new Queue(device));
+ }
~Queue();
@@ -60,10 +64,13 @@
void writeTexture(const WGPUImageCopyTexture& destination, const void* data, size_t dataSize, const WGPUTextureDataLayout&, const WGPUExtent3D& writeSize);
void setLabel(String&&);
+ bool isValid() const { return m_commandQueue; }
+
id<MTLCommandQueue> commandQueue() const { return m_commandQueue; }
private:
Queue(id<MTLCommandQueue>, Device&);
+ Queue(Device&);
bool validateSubmit() const;
bool validateWriteBuffer(const Buffer&, uint64_t bufferOffset, size_t) const;
Modified: trunk/Source/WebGPU/WebGPU/Queue.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Queue.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -40,6 +40,11 @@
{
}
+Queue::Queue(Device& device)
+ : m_device(device)
+{
+}
+
Queue::~Queue()
{
// If we're not idle, then there's a pending completed handler to be run,
Modified: trunk/Source/WebGPU/WebGPU/RenderBundle.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderBundle.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderBundle.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -44,11 +44,17 @@
{
return adoptRef(*new RenderBundle(indirectCommandBuffer, device));
}
+ static Ref<RenderBundle> createInvalid(Device& device)
+ {
+ return adoptRef(*new RenderBundle(device));
+ }
~RenderBundle();
void setLabel(String&&);
+ bool isValid() const { return m_indirectCommandBuffer; }
+
id<MTLIndirectCommandBuffer> indirectCommandBuffer() const { return m_indirectCommandBuffer; }
Device& device() const { return m_device; }
@@ -55,6 +61,7 @@
private:
RenderBundle(id<MTLIndirectCommandBuffer>, Device&);
+ RenderBundle(Device&);
const id<MTLIndirectCommandBuffer> m_indirectCommandBuffer { nil };
Modified: trunk/Source/WebGPU/WebGPU/RenderBundle.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderBundle.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderBundle.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -36,6 +36,11 @@
{
}
+RenderBundle::RenderBundle(Device& device)
+ : m_device(device)
+{
+}
+
RenderBundle::~RenderBundle() = default;
void RenderBundle::setLabel(String&& label)
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -50,6 +50,10 @@
{
return adoptRef(*new RenderBundleEncoder(indirectCommandBuffer, device));
}
+ static Ref<RenderBundleEncoder> createInvalid(Device& device)
+ {
+ return adoptRef(*new RenderBundleEncoder(device));
+ }
~RenderBundleEncoder();
@@ -69,8 +73,11 @@
Device& device() const { return m_device; }
+ bool isValid() const { return m_indirectCommandBuffer; }
+
private:
RenderBundleEncoder(id<MTLIndirectCommandBuffer>, Device&);
+ RenderBundleEncoder(Device&);
bool validatePopDebugGroup() const;
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -47,6 +47,11 @@
{
}
+RenderBundleEncoder::RenderBundleEncoder(Device& device)
+ : m_device(device)
+{
+}
+
RenderBundleEncoder::~RenderBundleEncoder() = default;
void RenderBundleEncoder::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
Modified: trunk/Source/WebGPU/WebGPU/RenderPassEncoder.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderPassEncoder.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderPassEncoder.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -51,6 +51,10 @@
{
return adoptRef(*new RenderPassEncoder(renderCommandEncoder, device));
}
+ static Ref<RenderPassEncoder> createInvalid(Device& device)
+ {
+ return adoptRef(*new RenderPassEncoder(device));
+ }
~RenderPassEncoder();
@@ -79,8 +83,11 @@
Device& device() const { return m_device; }
+ bool isValid() const { return m_renderCommandEncoder; }
+
private:
RenderPassEncoder(id<MTLRenderCommandEncoder>, Device&);
+ RenderPassEncoder(Device&);
bool validatePopDebugGroup() const;
Modified: trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderPassEncoder.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -41,6 +41,11 @@
{
}
+RenderPassEncoder::RenderPassEncoder(Device& device)
+ : m_device(device)
+{
+}
+
RenderPassEncoder::~RenderPassEncoder() = default;
void RenderPassEncoder::beginOcclusionQuery(uint32_t queryIndex)
Modified: trunk/Source/WebGPU/WebGPU/RenderPipeline.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderPipeline.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderPipeline.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -45,6 +45,10 @@
{
return adoptRef(*new RenderPipeline(renderPipelineState, device));
}
+ static Ref<RenderPipeline> createInvalid(Device& device)
+ {
+ return adoptRef(*new RenderPipeline(device));
+ }
~RenderPipeline();
@@ -51,6 +55,8 @@
BindGroupLayout* getBindGroupLayout(uint32_t groupIndex);
void setLabel(String&&);
+ bool isValid() const { return m_renderPipelineState; }
+
id<MTLRenderPipelineState> renderPipelineState() const { return m_renderPipelineState; }
Device& device() const { return m_device; }
@@ -57,6 +63,7 @@
private:
RenderPipeline(id<MTLRenderPipelineState>, Device&);
+ RenderPipeline(Device&);
const id<MTLRenderPipelineState> m_renderPipelineState { nil };
Modified: trunk/Source/WebGPU/WebGPU/RenderPipeline.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/RenderPipeline.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/RenderPipeline.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -50,6 +50,11 @@
{
}
+RenderPipeline::RenderPipeline(Device& device)
+ : m_device(device)
+{
+}
+
RenderPipeline::~RenderPipeline() = default;
BindGroupLayout* RenderPipeline::getBindGroupLayout(uint32_t groupIndex)
Modified: trunk/Source/WebGPU/WebGPU/Sampler.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Sampler.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Sampler.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -44,11 +44,17 @@
{
return adoptRef(*new Sampler(samplerState, descriptor, device));
}
+ static Ref<Sampler> createInvalid(Device& device)
+ {
+ return adoptRef(*new Sampler(device));
+ }
~Sampler();
void setLabel(String&&);
+ bool isValid() const { return m_samplerState; }
+
id<MTLSamplerState> samplerState() const { return m_samplerState; }
const WGPUSamplerDescriptor& descriptor() const { return m_descriptor; }
bool isComparison() const { return descriptor().compare != WGPUCompareFunction_Undefined; }
@@ -58,6 +64,7 @@
private:
Sampler(id<MTLSamplerState>, const WGPUSamplerDescriptor&, Device&);
+ Sampler(Device&);
const id<MTLSamplerState> m_samplerState { nil };
Modified: trunk/Source/WebGPU/WebGPU/Sampler.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -169,6 +169,11 @@
{
}
+Sampler::Sampler(Device& device)
+ : m_device(device)
+{
+}
+
Sampler::~Sampler() = default;
void Sampler::setLabel(String&&)
Modified: trunk/Source/WebGPU/WebGPU/ShaderModule.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/ShaderModule.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/ShaderModule.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -48,6 +48,10 @@
{
return adoptRef(*new ShaderModule(WTFMove(checkResult), WTFMove(pipelineLayoutHints), WTFMove(entryPointInformation), library, device));
}
+ static Ref<ShaderModule> createInvalid(Device& device)
+ {
+ return adoptRef(*new ShaderModule(device));
+ }
~ShaderModule();
@@ -54,6 +58,8 @@
void getCompilationInfo(CompletionHandler<void(WGPUCompilationInfoRequestStatus, const WGPUCompilationInfo&)>&& callback);
void setLabel(String&&);
+ bool isValid() const { return !std::holds_alternative<std::monostate>(m_checkResult); }
+
static WGSL::PipelineLayout convertPipelineLayout(const PipelineLayout&);
static id<MTLLibrary> createLibrary(id<MTLDevice>, const String& msl, String&& label);
@@ -67,8 +73,12 @@
private:
ShaderModule(std::variant<WGSL::SuccessfulCheck, WGSL::FailedCheck>&&, HashMap<String, Ref<PipelineLayout>>&&, HashMap<String, WGSL::Reflection::EntryPointInformation>&&, id<MTLLibrary>, Device&);
+ ShaderModule(Device&);
- const std::variant<WGSL::SuccessfulCheck, WGSL::FailedCheck> m_checkResult;
+ using CheckResult = std::variant<WGSL::SuccessfulCheck, WGSL::FailedCheck, std::monostate>;
+ CheckResult convertCheckResult(std::variant<WGSL::SuccessfulCheck, WGSL::FailedCheck>&&);
+
+ const CheckResult m_checkResult;
const HashMap<String, Ref<PipelineLayout>> m_pipelineLayoutHints;
const HashMap<String, WGSL::Reflection::EntryPointInformation> m_entryPointInformation;
const id<MTLLibrary> m_library { nil }; // This is only non-null if we could compile the module early.
Modified: trunk/Source/WebGPU/WebGPU/ShaderModule.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/ShaderModule.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/ShaderModule.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -119,8 +119,15 @@
return ShaderModule::create(WTFMove(checkResult), { }, { }, nil, *this);
}
+auto ShaderModule::convertCheckResult(std::variant<WGSL::SuccessfulCheck, WGSL::FailedCheck>&& checkResult) -> CheckResult
+{
+ return WTF::switchOn(WTFMove(checkResult), [](auto&& check) -> CheckResult {
+ return WTFMove(check);
+ });
+}
+
ShaderModule::ShaderModule(std::variant<WGSL::SuccessfulCheck, WGSL::FailedCheck>&& checkResult, HashMap<String, Ref<PipelineLayout>>&& pipelineLayoutHints, HashMap<String, WGSL::Reflection::EntryPointInformation>&& entryPointInformation, id<MTLLibrary> library, Device& device)
- : m_checkResult(WTFMove(checkResult))
+ : m_checkResult(convertCheckResult(WTFMove(checkResult)))
, m_pipelineLayoutHints(WTFMove(pipelineLayoutHints))
, m_entryPointInformation(WTFMove(entryPointInformation))
, m_library(library)
@@ -128,6 +135,12 @@
{
}
+ShaderModule::ShaderModule(Device& device)
+ : m_checkResult(std::monostate { })
+ , m_device(device)
+{
+}
+
ShaderModule::~ShaderModule() = default;
struct Messages {
@@ -205,6 +218,8 @@
compilationMessageData.compilationMessages.data(),
};
callback(WGPUCompilationInfoRequestStatus_Error, compilationInfo);
+ }, [](std::monostate) {
+ ASSERT_NOT_REACHED();
});
}
@@ -227,6 +242,9 @@
return successfulCheck.ast.ptr();
}, [&](const WGSL::FailedCheck&) -> const WGSL::AST::ShaderModule* {
return nullptr;
+ }, [](std::monostate) -> const WGSL::AST::ShaderModule* {
+ ASSERT_NOT_REACHED();
+ return nullptr;
});
}
Modified: trunk/Source/WebGPU/WebGPU/Texture.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -47,6 +47,10 @@
{
return adoptRef(*new Texture(texture, descriptor, WTFMove(viewFormats), device));
}
+ static Ref<Texture> createInvalid(Device& device)
+ {
+ return adoptRef(*new Texture(device));
+ }
~Texture();
@@ -54,6 +58,8 @@
void destroy();
void setLabel(String&&);
+ bool isValid() const { return m_texture; }
+
static uint32_t texelBlockWidth(WGPUTextureFormat); // Texels
static uint32_t texelBlockHeight(WGPUTextureFormat); // Texels
// For depth-stencil textures, the input value to texelBlockSize()
@@ -81,6 +87,7 @@
private:
Texture(id<MTLTexture>, const WGPUTextureDescriptor&, Vector<WGPUTextureFormat>&& viewFormats, Device&);
+ Texture(Device&);
WGPUTextureViewDescriptor resolveTextureViewDescriptorDefaults(const WGPUTextureViewDescriptor&) const;
uint32_t arrayLayerCount() const;
Modified: trunk/Source/WebGPU/WebGPU/Texture.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -2061,6 +2061,11 @@
{
}
+Texture::Texture(Device& device)
+ : m_device(device)
+{
+}
+
Texture::~Texture() = default;
WGPUTextureViewDescriptor Texture::resolveTextureViewDescriptorDefaults(const WGPUTextureViewDescriptor& descriptor) const
Modified: trunk/Source/WebGPU/WebGPU/TextureView.h (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/TextureView.h 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/TextureView.h 2022-04-07 21:44:00 UTC (rev 292567)
@@ -45,11 +45,17 @@
{
return adoptRef(*new TextureView(texture, descriptor, renderExtent, device));
}
+ static Ref<TextureView> createInvalid(Device& device)
+ {
+ return adoptRef(*new TextureView(device));
+ }
~TextureView();
void setLabel(String&&);
+ bool isValid() const { return m_texture; }
+
id<MTLTexture> texture() const { return m_texture; }
const WGPUTextureViewDescriptor& descriptor() const { return m_descriptor; }
const std::optional<WGPUExtent3D>& renderExtent() const { return m_renderExtent; }
@@ -58,6 +64,7 @@
private:
TextureView(id<MTLTexture>, const WGPUTextureViewDescriptor&, const std::optional<WGPUExtent3D>&, Device&);
+ TextureView(Device&);
const id<MTLTexture> m_texture { nil };
Modified: trunk/Source/WebGPU/WebGPU/TextureView.mm (292566 => 292567)
--- trunk/Source/WebGPU/WebGPU/TextureView.mm 2022-04-07 21:15:43 UTC (rev 292566)
+++ trunk/Source/WebGPU/WebGPU/TextureView.mm 2022-04-07 21:44:00 UTC (rev 292567)
@@ -38,6 +38,12 @@
{
}
+TextureView::TextureView(Device& device)
+ : m_descriptor { }
+ , m_device(device)
+{
+}
+
TextureView::~TextureView() = default;
void TextureView::setLabel(String&& label)