Diff
Modified: trunk/Source/WebGPU/ChangeLog (292669 => 292670)
--- trunk/Source/WebGPU/ChangeLog 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/ChangeLog 2022-04-09 01:45:07 UTC (rev 292670)
@@ -1,3 +1,74 @@
+2022-04-08 Myles C. Maxfield <[email protected]>
+
+ [WebGPU] Represent failure by invalidity rather than nullptr
+ https://bugs.webkit.org/show_bug.cgi?id=238724
+
+ Reviewed by Dean Jackson.
+
+ 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. Now that objects have the notion of invalidity, this patch
+ migrates from creation functions returning RefPtr to creation functions returning Ref. All
+ the places where we previously returned nullptr now return invalid objects.
+
+ * WebGPU/APIConversions.h:
+ (WebGPU::releaseToAPI):
+ * WebGPU/Adapter.h:
+ * WebGPU/Adapter.mm:
+ (WebGPU::Adapter::requestDevice):
+ (wgpuAdapterRequestDevice):
+ (wgpuAdapterRequestDeviceWithBlock):
+ * WebGPU/BindGroup.mm:
+ (WebGPU::Device::createBindGroup):
+ * WebGPU/BindGroupLayout.mm:
+ (WebGPU::Device::createBindGroupLayout):
+ * WebGPU/Buffer.mm:
+ (WebGPU::Device::createBuffer):
+ * WebGPU/CommandEncoder.h:
+ * WebGPU/CommandEncoder.mm:
+ (WebGPU::Device::createCommandEncoder):
+ (WebGPU::CommandEncoder::beginComputePass):
+ (WebGPU::CommandEncoder::beginRenderPass):
+ (WebGPU::CommandEncoder::finish):
+ * WebGPU/ComputePipeline.mm:
+ (WebGPU::Device::createComputePipeline):
+ (WebGPU::Device::createComputePipelineAsync):
+ * WebGPU/Device.h:
+ * WebGPU/Device.mm:
+ (WebGPU::Device::create):
+ (wgpuDeviceCreateComputePipelineAsync):
+ (wgpuDeviceCreateComputePipelineAsyncWithBlock):
+ (wgpuDeviceCreateRenderPipelineAsync):
+ (wgpuDeviceCreateRenderPipelineAsyncWithBlock):
+ * WebGPU/Instance.h:
+ * WebGPU/Instance.mm:
+ (WebGPU::Instance::create):
+ (WebGPU::Instance::createSurface):
+ (WebGPU::Instance::requestAdapter):
+ (wgpuInstanceRequestAdapter):
+ (wgpuInstanceRequestAdapterWithBlock):
+ * WebGPU/PipelineLayout.mm:
+ (WebGPU::Device::createPipelineLayout):
+ * WebGPU/QuerySet.mm:
+ (WebGPU::Device::createQuerySet):
+ * WebGPU/RenderBundleEncoder.h:
+ * WebGPU/RenderBundleEncoder.mm:
+ (WebGPU::Device::createRenderBundleEncoder):
+ (WebGPU::RenderBundleEncoder::finish):
+ * WebGPU/RenderPipeline.mm:
+ (WebGPU::Device::createRenderPipeline):
+ (WebGPU::Device::createRenderPipelineAsync):
+ * WebGPU/Sampler.mm:
+ (WebGPU::Device::createSampler):
+ * WebGPU/ShaderModule.mm:
+ (WebGPU::Device::createShaderModule):
+ * WebGPU/SwapChain.mm:
+ (WebGPU::Device::createSwapChain):
+ * WebGPU/Texture.h:
+ * WebGPU/Texture.mm:
+ (WebGPU::Device::createTexture):
+ (WebGPU::Texture::createView):
+
2022-04-08 Elliott Williams <[email protected]>
[Xcode] Avoid targeting 32-bit iOS and Mac architectures
Modified: trunk/Source/WebGPU/WebGPU/APIConversions.h (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/APIConversions.h 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/APIConversions.h 2022-04-09 01:45:07 UTC (rev 292670)
@@ -175,9 +175,9 @@
}
template <typename T>
-inline T* releaseToAPI(RefPtr<T>&& pointer)
+inline T* releaseToAPI(Ref<T>&& pointer)
{
- return pointer.leakRef();
+ return &pointer.leakRef();
}
} // namespace WebGPU
Modified: trunk/Source/WebGPU/WebGPU/Adapter.h (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Adapter.h 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Adapter.h 2022-04-09 01:45:07 UTC (rev 292670)
@@ -29,7 +29,6 @@
#import <wtf/FastMalloc.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
-#import <wtf/RefPtr.h>
struct WGPUAdapterImpl {
};
@@ -58,7 +57,7 @@
bool getLimits(WGPUSupportedLimits&);
void getProperties(WGPUAdapterProperties&);
bool hasFeature(WGPUFeatureName);
- void requestDevice(const WGPUDeviceDescriptor&, CompletionHandler<void(WGPURequestDeviceStatus, RefPtr<Device>&&, String&&)>&& callback);
+ void requestDevice(const WGPUDeviceDescriptor&, CompletionHandler<void(WGPURequestDeviceStatus, Ref<Device>&&, String&&)>&& callback);
bool isValid() const { return m_device; }
void makeInvalid() { m_device = nil; }
Modified: trunk/Source/WebGPU/WebGPU/Adapter.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -111,20 +111,20 @@
&& !requiredLimits.limits.maxComputeWorkgroupsPerDimension;
}
-void Adapter::requestDevice(const WGPUDeviceDescriptor& descriptor, CompletionHandler<void(WGPURequestDeviceStatus, RefPtr<Device>&&, String&&)>&& callback)
+void Adapter::requestDevice(const WGPUDeviceDescriptor& descriptor, CompletionHandler<void(WGPURequestDeviceStatus, Ref<Device>&&, String&&)>&& callback)
{
if (descriptor.nextInChain) {
- callback(WGPURequestDeviceStatus_Error, nullptr, "Unknown descriptor type"_s);
+ callback(WGPURequestDeviceStatus_Error, Device::createInvalid(*this), "Unknown descriptor type"_s);
return;
}
if (descriptor.requiredFeaturesCount) {
- callback(WGPURequestDeviceStatus_Error, nullptr, "Device does not support requested features"_s);
+ callback(WGPURequestDeviceStatus_Error, Device::createInvalid(*this), "Device does not support requested features"_s);
return;
}
if (descriptor.requiredLimits && !deviceMeetsRequiredLimits(m_device, *descriptor.requiredLimits)) {
- callback(WGPURequestDeviceStatus_Error, nullptr, "Device does not support requested limits"_s);
+ callback(WGPURequestDeviceStatus_Error, Device::createInvalid(*this), "Device does not support requested limits"_s);
return;
}
@@ -162,7 +162,7 @@
void wgpuAdapterRequestDevice(WGPUAdapter adapter, const WGPUDeviceDescriptor* descriptor, WGPURequestDeviceCallback callback, void* userdata)
{
- WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback, userdata](WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, String&& message) {
+ WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback, userdata](WGPURequestDeviceStatus status, Ref<WebGPU::Device>&& device, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(device)), message.utf8().data(), userdata);
});
}
@@ -169,7 +169,7 @@
void wgpuAdapterRequestDeviceWithBlock(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceBlockCallback callback)
{
- WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback = WTFMove(callback)](WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, String&& message) {
+ WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback = WTFMove(callback)](WGPURequestDeviceStatus status, Ref<WebGPU::Device>&& device, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(device)), message.utf8().data());
});
}
Modified: trunk/Source/WebGPU/WebGPU/BindGroup.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/BindGroup.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/BindGroup.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -50,10 +50,10 @@
return entry.textureView;
}
-RefPtr<BindGroup> Device::createBindGroup(const WGPUBindGroupDescriptor& descriptor)
+Ref<BindGroup> Device::createBindGroup(const WGPUBindGroupDescriptor& descriptor)
{
if (descriptor.nextInChain)
- return nullptr;
+ return BindGroup::createInvalid(*this);
const BindGroupLayout& bindGroupLayout = WebGPU::fromAPI(descriptor.layout);
@@ -63,7 +63,7 @@
id<MTLBuffer> fragmentArgumentBuffer = safeCreateBuffer(bindGroupLayout.encodedLength(), MTLStorageModeShared);
id<MTLBuffer> computeArgumentBuffer = safeCreateBuffer(bindGroupLayout.encodedLength(), MTLStorageModeShared);
if (!vertexArgumentBuffer || !fragmentArgumentBuffer || !computeArgumentBuffer)
- return nullptr;
+ return BindGroup::createInvalid(*this);
auto label = fromAPI(descriptor.label);
vertexArgumentBuffer.label = label;
@@ -81,13 +81,13 @@
const WGPUBindGroupEntry& entry = descriptor.entries[i];
if (entry.nextInChain)
- return nullptr;
+ return BindGroup::createInvalid(*this);
bool bufferIsPresent = WebGPU::bufferIsPresent(entry);
bool samplerIsPresent = WebGPU::samplerIsPresent(entry);
bool textureViewIsPresent = WebGPU::textureViewIsPresent(entry);
if (static_cast<int>(bufferIsPresent) + static_cast<int>(samplerIsPresent) + static_cast<int>(textureViewIsPresent) != 1)
- return nullptr;
+ return BindGroup::createInvalid(*this);
if (bufferIsPresent) {
id<MTLBuffer> buffer = WebGPU::fromAPI(entry.buffer).buffer();
@@ -107,7 +107,7 @@
[computeArgumentEncoder setTexture:texture atIndex:entry.binding];
} else {
ASSERT_NOT_REACHED();
- return nullptr;
+ return BindGroup::createInvalid(*this);
}
}
Modified: trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/BindGroupLayout.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -115,21 +115,21 @@
return descriptor;
}
-RefPtr<BindGroupLayout> Device::createBindGroupLayout(const WGPUBindGroupLayoutDescriptor& descriptor)
+Ref<BindGroupLayout> Device::createBindGroupLayout(const WGPUBindGroupLayoutDescriptor& descriptor)
{
if (descriptor.nextInChain)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
NSMutableArray<MTLArgumentDescriptor *> *vertexArguments = [NSMutableArray arrayWithCapacity:descriptor.entryCount];
NSMutableArray<MTLArgumentDescriptor *> *fragmentArguments = [NSMutableArray arrayWithCapacity:descriptor.entryCount];
NSMutableArray<MTLArgumentDescriptor *> *computeArguments = [NSMutableArray arrayWithCapacity:descriptor.entryCount];
if (!vertexArguments || !fragmentArguments || !computeArguments)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
for (uint32_t i = 0; i < descriptor.entryCount; ++i) {
const WGPUBindGroupLayoutEntry& entry = descriptor.entries[i];
if (entry.nextInChain)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
// https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry
// "Only one [of buffer, sampler, texture, storageTexture, or externalTexture] may be defined for any given GPUBindGroupLayoutEntry."
@@ -147,38 +147,38 @@
if (isPresent(buffer)) {
if (i != vertexArguments.count)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
descriptor = createArgumentDescriptor(buffer);
if (!descriptor)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
}
if (isPresent(sampler)) {
if (i != vertexArguments.count)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
descriptor = createArgumentDescriptor(sampler);
if (!descriptor)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
}
if (isPresent(texture)) {
if (i != vertexArguments.count)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
descriptor = createArgumentDescriptor(texture);
if (!descriptor)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
}
if (isPresent(storageTexture)) {
if (i != vertexArguments.count)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
descriptor = createArgumentDescriptor(storageTexture);
if (!descriptor)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
}
// FIXME: This needs coordination with the shader compiler.
@@ -188,7 +188,7 @@
MTLArgumentDescriptor *fragmentDescriptor = [descriptor copy];
MTLArgumentDescriptor *computeDescriptor = [descriptor copy];
if (!fragmentDescriptor || !computeDescriptor)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
if (!(entry.visibility & WGPUShaderStage_Vertex))
vertexDescriptor.access = MTLArgumentAccessReadOnly;
@@ -206,7 +206,7 @@
id<MTLArgumentEncoder> fragmentArgumentEncoder = [m_device newArgumentEncoderWithArguments:fragmentArguments];
id<MTLArgumentEncoder> computeArgumentEncoder = [m_device newArgumentEncoderWithArguments:computeArguments];
if (!vertexArgumentEncoder || !fragmentArgumentEncoder || !computeArgumentEncoder)
- return nullptr;
+ return BindGroupLayout::createInvalid(*this);
auto label = fromAPI(descriptor.label);
vertexArgumentEncoder.label = label;
Modified: trunk/Source/WebGPU/WebGPU/Buffer.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -99,15 +99,15 @@
return [m_device newBufferWithLength:std::max(static_cast<NSUInteger>(1), length) options:resourceOptions];
}
-RefPtr<Buffer> Device::createBuffer(const WGPUBufferDescriptor& descriptor)
+Ref<Buffer> Device::createBuffer(const WGPUBufferDescriptor& descriptor)
{
if (descriptor.nextInChain)
- return nullptr;
+ return Buffer::createInvalid(*this);
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer
if (!validateCreateBuffer(*this, descriptor))
- return nullptr;
+ return Buffer::createInvalid(*this);
// FIXME(PERFORMANCE): Consider write-combining CPU cache mode.
// FIXME(PERFORMANCE): Consider implementing hazard tracking ourself.
@@ -114,7 +114,7 @@
MTLStorageMode storageMode = WebGPU::storageMode(hasUnifiedMemory(), descriptor.usage, descriptor.mappedAtCreation);
auto buffer = safeCreateBuffer(static_cast<NSUInteger>(descriptor.size), storageMode);
if (!buffer)
- return nullptr;
+ return Buffer::createInvalid(*this);
buffer.label = fromAPI(descriptor.label);
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.h (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-04-09 01:45:07 UTC (rev 292670)
@@ -29,7 +29,6 @@
#import <wtf/FastMalloc.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
-#import <wtf/RefPtr.h>
struct WGPUCommandEncoderImpl {
};
@@ -58,14 +57,14 @@
~CommandEncoder();
- RefPtr<ComputePassEncoder> beginComputePass(const WGPUComputePassDescriptor&);
- RefPtr<RenderPassEncoder> beginRenderPass(const WGPURenderPassDescriptor&);
+ Ref<ComputePassEncoder> beginComputePass(const WGPUComputePassDescriptor&);
+ Ref<RenderPassEncoder> beginRenderPass(const WGPURenderPassDescriptor&);
void copyBufferToBuffer(const Buffer& source, uint64_t sourceOffset, const Buffer& destination, uint64_t destinationOffset, uint64_t size);
void copyBufferToTexture(const WGPUImageCopyBuffer& source, const WGPUImageCopyTexture& destination, const WGPUExtent3D& copySize);
void copyTextureToBuffer(const WGPUImageCopyTexture& source, const WGPUImageCopyBuffer& destination, const WGPUExtent3D& copySize);
void copyTextureToTexture(const WGPUImageCopyTexture& source, const WGPUImageCopyTexture& destination, const WGPUExtent3D& copySize);
void clearBuffer(const Buffer&, uint64_t offset, uint64_t size);
- RefPtr<CommandBuffer> finish(const WGPUCommandBufferDescriptor&);
+ Ref<CommandBuffer> finish(const WGPUCommandBufferDescriptor&);
void insertDebugMarker(String&& markerLabel);
void popDebugGroup();
void pushDebugGroup(String&& groupLabel);
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -37,10 +37,10 @@
namespace WebGPU {
-RefPtr<CommandEncoder> Device::createCommandEncoder(const WGPUCommandEncoderDescriptor& descriptor)
+Ref<CommandEncoder> Device::createCommandEncoder(const WGPUCommandEncoderDescriptor& descriptor)
{
if (descriptor.nextInChain)
- return nullptr;
+ return CommandEncoder::createInvalid(*this);
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createcommandencoder
@@ -48,7 +48,7 @@
commandBufferDescriptor.errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
id<MTLCommandBuffer> commandBuffer = [getQueue().commandQueue() commandBufferWithDescriptor:commandBufferDescriptor];
if (!commandBuffer)
- return nullptr;
+ return CommandEncoder::createInvalid(*this);
commandBuffer.label = fromAPI(descriptor.label);
@@ -85,16 +85,16 @@
}
}
-RefPtr<ComputePassEncoder> CommandEncoder::beginComputePass(const WGPUComputePassDescriptor& descriptor)
+Ref<ComputePassEncoder> CommandEncoder::beginComputePass(const WGPUComputePassDescriptor& descriptor)
{
UNUSED_PARAM(descriptor);
- return ComputePassEncoder::create(nil, m_device);
+ return ComputePassEncoder::createInvalid(m_device);
}
-RefPtr<RenderPassEncoder> CommandEncoder::beginRenderPass(const WGPURenderPassDescriptor& descriptor)
+Ref<RenderPassEncoder> CommandEncoder::beginRenderPass(const WGPURenderPassDescriptor& descriptor)
{
UNUSED_PARAM(descriptor);
- return RenderPassEncoder::create(nil, m_device);
+ return RenderPassEncoder::createInvalid(m_device);
}
static bool validateCopyBufferToBuffer(const Buffer& source, uint64_t sourceOffset, const Buffer& destination, uint64_t destinationOffset, uint64_t size)
@@ -730,10 +730,10 @@
return true;
}
-RefPtr<CommandBuffer> CommandEncoder::finish(const WGPUCommandBufferDescriptor& descriptor)
+Ref<CommandBuffer> CommandEncoder::finish(const WGPUCommandBufferDescriptor& descriptor)
{
if (descriptor.nextInChain)
- return nullptr;
+ return CommandBuffer::createInvalid(m_device);
// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-finish
@@ -743,9 +743,7 @@
if (validationFailed) {
m_device->generateAValidationError("Validation failure."_s);
-
- // FIXME: "Return a new invalid GPUCommandBuffer."
- return nullptr;
+ return CommandBuffer::createInvalid(m_device);
}
finalizeBlitCommandEncoder();
Modified: trunk/Source/WebGPU/WebGPU/ComputePipeline.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/ComputePipeline.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/ComputePipeline.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -141,10 +141,10 @@
return computePipelineState;
}
-RefPtr<ComputePipeline> Device::createComputePipeline(const WGPUComputePipelineDescriptor& descriptor)
+Ref<ComputePipeline> Device::createComputePipeline(const WGPUComputePipelineDescriptor& descriptor)
{
if (descriptor.nextInChain || descriptor.compute.nextInChain)
- return nullptr;
+ return ComputePipeline::createInvalid(*this);
const ShaderModule& shaderModule = WebGPU::fromAPI(descriptor.compute.module);
const PipelineLayout& pipelineLayout = WebGPU::fromAPI(descriptor.layout);
@@ -152,13 +152,13 @@
auto libraryCreationResult = createLibrary(m_device, shaderModule, pipelineLayout, String::fromLatin1(descriptor.compute.entryPoint), label);
if (!libraryCreationResult)
- return nullptr;
+ return ComputePipeline::createInvalid(*this);
auto library = libraryCreationResult->library;
const auto& entryPointInformation = libraryCreationResult->entryPointInformation;
if (!std::holds_alternative<WGSL::Reflection::Compute>(entryPointInformation.typedEntryPoint))
- return nullptr;
+ return ComputePipeline::createInvalid(*this);
const auto& computeInformation = std::get<WGSL::Reflection::Compute>(entryPointInformation.typedEntryPoint);
auto function = createFunction(library, entryPointInformation, descriptor.compute, label);
@@ -168,7 +168,7 @@
return ComputePipeline::create(computePipelineState, *this);
}
-void Device::createComputePipelineAsync(const WGPUComputePipelineDescriptor& descriptor, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, RefPtr<ComputePipeline>&&, String&& message)>&& callback)
+void Device::createComputePipelineAsync(const WGPUComputePipelineDescriptor& descriptor, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, Ref<ComputePipeline>&&, String&& message)>&& callback)
{
// FIXME: Implement this
UNUSED_PARAM(descriptor);
Modified: trunk/Source/WebGPU/WebGPU/Device.h (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Device.h 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Device.h 2022-04-09 01:45:07 UTC (rev 292670)
@@ -32,7 +32,6 @@
#import <wtf/Function.h>
#import <wtf/Ref.h>
#import <wtf/ThreadSafeRefCounted.h>
-#import <wtf/RefPtr.h>
#import <wtf/Vector.h>
#import <wtf/text/WTFString.h>
@@ -61,7 +60,7 @@
class Device : public WGPUDeviceImpl, public ThreadSafeRefCounted<Device> {
WTF_MAKE_FAST_ALLOCATED;
public:
- static RefPtr<Device> create(id<MTLDevice>, String&& deviceLabel, Adapter&);
+ static Ref<Device> create(id<MTLDevice>, String&& deviceLabel, Adapter&);
static Ref<Device> createInvalid(Adapter& adapter)
{
return adoptRef(*new Device(adapter));
@@ -69,21 +68,21 @@
~Device();
- RefPtr<BindGroup> createBindGroup(const WGPUBindGroupDescriptor&);
- RefPtr<BindGroupLayout> createBindGroupLayout(const WGPUBindGroupLayoutDescriptor&);
- RefPtr<Buffer> createBuffer(const WGPUBufferDescriptor&);
- RefPtr<CommandEncoder> createCommandEncoder(const WGPUCommandEncoderDescriptor&);
- RefPtr<ComputePipeline> createComputePipeline(const WGPUComputePipelineDescriptor&);
- void createComputePipelineAsync(const WGPUComputePipelineDescriptor&, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, RefPtr<ComputePipeline>&&, String&& message)>&& callback);
- RefPtr<PipelineLayout> createPipelineLayout(const WGPUPipelineLayoutDescriptor&);
- RefPtr<QuerySet> createQuerySet(const WGPUQuerySetDescriptor&);
- RefPtr<RenderBundleEncoder> createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor&);
- RefPtr<RenderPipeline> createRenderPipeline(const WGPURenderPipelineDescriptor&);
- void createRenderPipelineAsync(const WGPURenderPipelineDescriptor&, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, RefPtr<RenderPipeline>&&, String&& message)>&& callback);
- RefPtr<Sampler> createSampler(const WGPUSamplerDescriptor&);
- RefPtr<ShaderModule> createShaderModule(const WGPUShaderModuleDescriptor&);
- RefPtr<SwapChain> createSwapChain(const Surface&, const WGPUSwapChainDescriptor&);
- RefPtr<Texture> createTexture(const WGPUTextureDescriptor&);
+ Ref<BindGroup> createBindGroup(const WGPUBindGroupDescriptor&);
+ Ref<BindGroupLayout> createBindGroupLayout(const WGPUBindGroupLayoutDescriptor&);
+ Ref<Buffer> createBuffer(const WGPUBufferDescriptor&);
+ Ref<CommandEncoder> createCommandEncoder(const WGPUCommandEncoderDescriptor&);
+ Ref<ComputePipeline> createComputePipeline(const WGPUComputePipelineDescriptor&);
+ void createComputePipelineAsync(const WGPUComputePipelineDescriptor&, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, Ref<ComputePipeline>&&, String&& message)>&& callback);
+ Ref<PipelineLayout> createPipelineLayout(const WGPUPipelineLayoutDescriptor&);
+ Ref<QuerySet> createQuerySet(const WGPUQuerySetDescriptor&);
+ Ref<RenderBundleEncoder> createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor&);
+ Ref<RenderPipeline> createRenderPipeline(const WGPURenderPipelineDescriptor&);
+ void createRenderPipelineAsync(const WGPURenderPipelineDescriptor&, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, Ref<RenderPipeline>&&, String&& message)>&& callback);
+ Ref<Sampler> createSampler(const WGPUSamplerDescriptor&);
+ Ref<ShaderModule> createShaderModule(const WGPUShaderModuleDescriptor&);
+ Ref<SwapChain> createSwapChain(const Surface&, const WGPUSwapChainDescriptor&);
+ Ref<Texture> createTexture(const WGPUTextureDescriptor&);
void destroy();
size_t enumerateFeatures(WGPUFeatureName* features);
bool getLimits(WGPUSupportedLimits&);
Modified: trunk/Source/WebGPU/WebGPU/Device.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Device.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Device.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -46,11 +46,11 @@
namespace WebGPU {
-RefPtr<Device> Device::create(id<MTLDevice> device, String&& deviceLabel, Adapter& adapter)
+Ref<Device> Device::create(id<MTLDevice> device, String&& deviceLabel, Adapter& adapter)
{
id<MTLCommandQueue> commandQueue = [device newCommandQueue];
if (!commandQueue)
- return nullptr;
+ return Device::createInvalid(adapter);
// See the comment in Device::setLabel() about why we're not setting the label on the MTLDevice here.
@@ -249,7 +249,7 @@
void wgpuDeviceCreateComputePipelineAsync(WGPUDevice device, const WGPUComputePipelineDescriptor* descriptor, WGPUCreateComputePipelineAsyncCallback callback, void* userdata)
{
- WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback, userdata](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::ComputePipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback, userdata](WGPUCreatePipelineAsyncStatus status, Ref<WebGPU::ComputePipeline>&& pipeline, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(pipeline)), message.utf8().data(), userdata);
});
}
@@ -256,7 +256,7 @@
void wgpuDeviceCreateComputePipelineAsyncWithBlock(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateComputePipelineAsyncBlockCallback callback)
{
- WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::ComputePipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus status, Ref<WebGPU::ComputePipeline>&& pipeline, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(pipeline)), message.utf8().data());
});
}
@@ -283,7 +283,7 @@
void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, const WGPURenderPipelineDescriptor* descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata)
{
- WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback, userdata](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::RenderPipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback, userdata](WGPUCreatePipelineAsyncStatus status, Ref<WebGPU::RenderPipeline>&& pipeline, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(pipeline)), message.utf8().data(), userdata);
});
}
@@ -290,7 +290,7 @@
void wgpuDeviceCreateRenderPipelineAsyncWithBlock(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncBlockCallback callback)
{
- WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::RenderPipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus status, Ref<WebGPU::RenderPipeline>&& pipeline, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(pipeline)), message.utf8().data());
});
}
Modified: trunk/Source/WebGPU/WebGPU/Instance.h (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Instance.h 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Instance.h 2022-04-09 01:45:07 UTC (rev 292670)
@@ -30,7 +30,6 @@
#import <wtf/FastMalloc.h>
#import <wtf/Lock.h>
#import <wtf/Ref.h>
-#import <wtf/RefPtr.h>
#import <wtf/ThreadSafeRefCounted.h>
struct WGPUInstanceImpl {
@@ -45,7 +44,7 @@
class Instance : public WGPUInstanceImpl, public ThreadSafeRefCounted<Instance> {
WTF_MAKE_FAST_ALLOCATED;
public:
- static RefPtr<Instance> create(const WGPUInstanceDescriptor&);
+ static Ref<Instance> create(const WGPUInstanceDescriptor&);
static Ref<Instance> createInvalid()
{
return adoptRef(*new Instance());
@@ -53,9 +52,9 @@
~Instance();
- RefPtr<Surface> createSurface(const WGPUSurfaceDescriptor&);
+ Ref<Surface> createSurface(const WGPUSurfaceDescriptor&);
void processEvents();
- void requestAdapter(const WGPURequestAdapterOptions&, CompletionHandler<void(WGPURequestAdapterStatus, RefPtr<Adapter>&&, String&&)>&& callback);
+ void requestAdapter(const WGPURequestAdapterOptions&, CompletionHandler<void(WGPURequestAdapterStatus, Ref<Adapter>&&, String&&)>&& callback);
bool isValid() const { return m_isValid; }
Modified: trunk/Source/WebGPU/WebGPU/Instance.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Instance.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Instance.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -35,18 +35,18 @@
namespace WebGPU {
-RefPtr<Instance> Instance::create(const WGPUInstanceDescriptor& descriptor)
+Ref<Instance> Instance::create(const WGPUInstanceDescriptor& descriptor)
{
if (!descriptor.nextInChain)
return adoptRef(*new Instance(nullptr));
if (descriptor.nextInChain->sType != static_cast<WGPUSType>(WGPUSTypeExtended_InstanceCocoaDescriptor))
- return nullptr;
+ return Instance::createInvalid();
const WGPUInstanceCocoaDescriptor& cocoaDescriptor = reinterpret_cast<const WGPUInstanceCocoaDescriptor&>(*descriptor.nextInChain);
if (cocoaDescriptor.chain.next)
- return nullptr;
+ return Instance::createInvalid();
return adoptRef(*new Instance(cocoaDescriptor.scheduleWorkBlock));
}
@@ -64,7 +64,7 @@
Instance::~Instance() = default;
-RefPtr<Surface> Instance::createSurface(const WGPUSurfaceDescriptor& descriptor)
+Ref<Surface> Instance::createSurface(const WGPUSurfaceDescriptor& descriptor)
{
// FIXME: Implement this.
UNUSED_PARAM(descriptor);
@@ -134,7 +134,7 @@
}
}
-void Instance::requestAdapter(const WGPURequestAdapterOptions& options, CompletionHandler<void(WGPURequestAdapterStatus, RefPtr<Adapter>&&, String&&)>&& callback)
+void Instance::requestAdapter(const WGPURequestAdapterOptions& options, CompletionHandler<void(WGPURequestAdapterStatus, Ref<Adapter>&&, String&&)>&& callback)
{
#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
NSArray<id<MTLDevice>> *devices = MTLCopyAllDevices();
@@ -149,27 +149,27 @@
auto sortedDevices = WebGPU::sortedDevices(devices, options.powerPreference);
if (options.nextInChain) {
- callback(WGPURequestAdapterStatus_Error, nullptr, "Unknown descriptor type"_s);
+ callback(WGPURequestAdapterStatus_Error, Adapter::createInvalid(*this), "Unknown descriptor type"_s);
return;
}
if (options.forceFallbackAdapter) {
- callback(WGPURequestAdapterStatus_Unavailable, nullptr, "No adapters present"_s);
+ callback(WGPURequestAdapterStatus_Unavailable, Adapter::createInvalid(*this), "No adapters present"_s);
return;
}
if (!sortedDevices) {
- callback(WGPURequestAdapterStatus_Error, nullptr, "Unknown power preference"_s);
+ callback(WGPURequestAdapterStatus_Error, Adapter::createInvalid(*this), "Unknown power preference"_s);
return;
}
if (!sortedDevices.count) {
- callback(WGPURequestAdapterStatus_Unavailable, nullptr, "No adapters present"_s);
+ callback(WGPURequestAdapterStatus_Unavailable, Adapter::createInvalid(*this), "No adapters present"_s);
return;
}
if (!sortedDevices[0]) {
- callback(WGPURequestAdapterStatus_Error, nullptr, "Adapter is internally null"_s);
+ callback(WGPURequestAdapterStatus_Error, Adapter::createInvalid(*this), "Adapter is internally null"_s);
return;
}
@@ -451,7 +451,7 @@
void wgpuInstanceRequestAdapter(WGPUInstance instance, const WGPURequestAdapterOptions* options, WGPURequestAdapterCallback callback, void* userdata)
{
- WebGPU::fromAPI(instance).requestAdapter(*options, [callback, userdata](WGPURequestAdapterStatus status, RefPtr<WebGPU::Adapter>&& adapter, String&& message) {
+ WebGPU::fromAPI(instance).requestAdapter(*options, [callback, userdata](WGPURequestAdapterStatus status, Ref<WebGPU::Adapter>&& adapter, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(adapter)), message.utf8().data(), userdata);
});
}
@@ -458,7 +458,7 @@
void wgpuInstanceRequestAdapterWithBlock(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPURequestAdapterBlockCallback callback)
{
- WebGPU::fromAPI(instance).requestAdapter(*options, [callback = WTFMove(callback)](WGPURequestAdapterStatus status, RefPtr<WebGPU::Adapter>&& adapter, String&& message) {
+ WebGPU::fromAPI(instance).requestAdapter(*options, [callback = WTFMove(callback)](WGPURequestAdapterStatus status, Ref<WebGPU::Adapter>&& adapter, String&& message) {
callback(status, WebGPU::releaseToAPI(WTFMove(adapter)), message.utf8().data());
});
}
Modified: trunk/Source/WebGPU/WebGPU/PipelineLayout.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/PipelineLayout.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/PipelineLayout.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -32,10 +32,10 @@
namespace WebGPU {
-RefPtr<PipelineLayout> Device::createPipelineLayout(const WGPUPipelineLayoutDescriptor& descriptor)
+Ref<PipelineLayout> Device::createPipelineLayout(const WGPUPipelineLayoutDescriptor& descriptor)
{
if (descriptor.nextInChain)
- return nullptr;
+ return PipelineLayout::createInvalid(*this);
Vector<Ref<BindGroupLayout>> bindGroupLayouts;
bindGroupLayouts.reserveInitialCapacity(descriptor.bindGroupLayoutCount);
Modified: trunk/Source/WebGPU/WebGPU/QuerySet.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/QuerySet.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/QuerySet.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -31,10 +31,10 @@
namespace WebGPU {
-RefPtr<QuerySet> Device::createQuerySet(const WGPUQuerySetDescriptor& descriptor)
+Ref<QuerySet> Device::createQuerySet(const WGPUQuerySetDescriptor& descriptor)
{
UNUSED_PARAM(descriptor);
- return QuerySet::create(nil, *this);
+ return QuerySet::createInvalid(*this);
}
QuerySet::QuerySet(id<MTLCounterSampleBuffer> counterSampleBuffer, Device& device)
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-04-09 01:45:07 UTC (rev 292670)
@@ -29,7 +29,6 @@
#import <wtf/FastMalloc.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
-#import <wtf/RefPtr.h>
struct WGPURenderBundleEncoderImpl {
};
@@ -61,7 +60,7 @@
void drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance);
void drawIndexedIndirect(const Buffer& indirectBuffer, uint64_t indirectOffset);
void drawIndirect(const Buffer& indirectBuffer, uint64_t indirectOffset);
- RefPtr<RenderBundle> finish(const WGPURenderBundleDescriptor&);
+ Ref<RenderBundle> finish(const WGPURenderBundleDescriptor&);
void insertDebugMarker(String&& markerLabel);
void popDebugGroup();
void pushDebugGroup(String&& groupLabel);
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -35,10 +35,10 @@
namespace WebGPU {
-RefPtr<RenderBundleEncoder> Device::createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor& descriptor)
+Ref<RenderBundleEncoder> Device::createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor& descriptor)
{
UNUSED_PARAM(descriptor);
- return RenderBundleEncoder::create(nil, *this);
+ return RenderBundleEncoder::createInvalid(*this);
}
RenderBundleEncoder::RenderBundleEncoder(id<MTLIndirectCommandBuffer> indirectCommandBuffer, Device& device)
@@ -83,10 +83,10 @@
UNUSED_PARAM(indirectOffset);
}
-RefPtr<RenderBundle> RenderBundleEncoder::finish(const WGPURenderBundleDescriptor& descriptor)
+Ref<RenderBundle> RenderBundleEncoder::finish(const WGPURenderBundleDescriptor& descriptor)
{
UNUSED_PARAM(descriptor);
- return RenderBundle::create(nil, m_device);
+ return RenderBundle::createInvalid(m_device);
}
void RenderBundleEncoder::insertDebugMarker(String&&)
Modified: trunk/Source/WebGPU/WebGPU/RenderPipeline.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/RenderPipeline.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/RenderPipeline.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -32,13 +32,13 @@
namespace WebGPU {
-RefPtr<RenderPipeline> Device::createRenderPipeline(const WGPURenderPipelineDescriptor& descriptor)
+Ref<RenderPipeline> Device::createRenderPipeline(const WGPURenderPipelineDescriptor& descriptor)
{
UNUSED_PARAM(descriptor);
- return RenderPipeline::create(nil, *this);
+ return RenderPipeline::createInvalid(*this);
}
-void Device::createRenderPipelineAsync(const WGPURenderPipelineDescriptor& descriptor, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, RefPtr<RenderPipeline>&&, String&& message)>&& callback)
+void Device::createRenderPipelineAsync(const WGPURenderPipelineDescriptor& descriptor, CompletionHandler<void(WGPUCreatePipelineAsyncStatus, Ref<RenderPipeline>&&, String&& message)>&& callback)
{
UNUSED_PARAM(descriptor);
UNUSED_PARAM(callback);
Modified: trunk/Source/WebGPU/WebGPU/Sampler.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Sampler.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -124,17 +124,16 @@
}
}
-RefPtr<Sampler> Device::createSampler(const WGPUSamplerDescriptor& descriptor)
+Ref<Sampler> Device::createSampler(const WGPUSamplerDescriptor& descriptor)
{
if (descriptor.nextInChain)
- return nullptr;
+ return Sampler::createInvalid(*this);
// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createsampler
if (!validateCreateSampler(*this, descriptor)) {
generateAValidationError("Validation failure."_s);
-
- return nullptr;
+ return Sampler::createInvalid(*this);
}
MTLSamplerDescriptor *samplerDescriptor = [MTLSamplerDescriptor new];
@@ -157,7 +156,7 @@
id<MTLSamplerState> samplerState = [m_device newSamplerStateWithDescriptor:samplerDescriptor];
if (!samplerState)
- return nullptr;
+ return Sampler::createInvalid(*this);
return Sampler::create(samplerState, descriptor, *this);
}
Modified: trunk/Source/WebGPU/WebGPU/ShaderModule.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/ShaderModule.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/ShaderModule.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -100,20 +100,20 @@
return ShaderModule::create(WTFMove(checkResult), WTFMove(hints), WTFMove(prepareResult.entryPoints), library, device);
}
-RefPtr<ShaderModule> Device::createShaderModule(const WGPUShaderModuleDescriptor& descriptor)
+Ref<ShaderModule> Device::createShaderModule(const WGPUShaderModuleDescriptor& descriptor)
{
if (!descriptor.nextInChain)
- return nullptr;
+ return ShaderModule::createInvalid(*this);
auto shaderModuleParameters = findShaderModuleParameters(descriptor);
if (!shaderModuleParameters)
- return nullptr;
+ return ShaderModule::createInvalid(*this);
auto checkResult = WGSL::staticCheck(String::fromLatin1(shaderModuleParameters->wgsl.code), std::nullopt);
if (std::holds_alternative<WGSL::SuccessfulCheck>(checkResult) && shaderModuleParameters->hints && shaderModuleParameters->hints->hintsCount) {
if (auto result = earlyCompileShaderModule(*this, WTFMove(checkResult), *shaderModuleParameters->hints, fromAPI(descriptor.label)))
- return result;
+ return result.releaseNonNull();
}
return ShaderModule::create(WTFMove(checkResult), { }, { }, nil, *this);
Modified: trunk/Source/WebGPU/WebGPU/SwapChain.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/SwapChain.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/SwapChain.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -32,7 +32,7 @@
namespace WebGPU {
-RefPtr<SwapChain> Device::createSwapChain(const Surface& surface, const WGPUSwapChainDescriptor& descriptor)
+Ref<SwapChain> Device::createSwapChain(const Surface& surface, const WGPUSwapChainDescriptor& descriptor)
{
UNUSED_PARAM(surface);
UNUSED_PARAM(descriptor);
Modified: trunk/Source/WebGPU/WebGPU/Texture.h (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Texture.h 2022-04-09 01:45:07 UTC (rev 292670)
@@ -28,7 +28,6 @@
#import <wtf/FastMalloc.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
-#import <wtf/RefPtr.h>
#import <wtf/Vector.h>
struct WGPUTextureImpl {
@@ -54,7 +53,7 @@
~Texture();
- RefPtr<TextureView> createView(const WGPUTextureViewDescriptor&);
+ Ref<TextureView> createView(const WGPUTextureViewDescriptor&);
void destroy();
void setLabel(String&&);
Modified: trunk/Source/WebGPU/WebGPU/Texture.mm (292669 => 292670)
--- trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-09 00:31:14 UTC (rev 292669)
+++ trunk/Source/WebGPU/WebGPU/Texture.mm 2022-04-09 01:45:07 UTC (rev 292670)
@@ -1963,15 +1963,15 @@
#endif
}
-RefPtr<Texture> Device::createTexture(const WGPUTextureDescriptor& descriptor)
+Ref<Texture> Device::createTexture(const WGPUTextureDescriptor& descriptor)
{
Vector<WGPUTextureFormat> viewFormats;
if (descriptor.nextInChain) {
if (descriptor.nextInChain->sType != static_cast<WGPUSType>(WGPUSTypeExtended_TextureDescriptorViewFormats))
- return nullptr;
+ return Texture::createInvalid(*this);
const auto& descriptorViewFormats = reinterpret_cast<const WGPUTextureDescriptorViewFormats&>(*descriptor.nextInChain);
if (descriptor.nextInChain->next != nullptr)
- return nullptr;
+ return Texture::createInvalid(*this);
// This copy is temporary, just until WGPUTextureDescriptorViewFormats gets folded into WGPUTextureDescriptor.
viewFormats = Vector { descriptorViewFormats.viewFormats, descriptorViewFormats.viewFormatsCount };
}
@@ -1980,13 +1980,13 @@
if (featureRequirementForFormat(descriptor.format)) {
// FIXME: "but this.[[device]].[[features]] does not contain the feature, throw a TypeError."
- return nullptr;
+ return Texture::createInvalid(*this);
}
if (!validateCreateTexture(descriptor, viewFormats)) {
generateAValidationError("Validation failure."_s);
// FIXME: "Return a new invalid GPUTexture."
- return nullptr;
+ return Texture::createInvalid(*this);
}
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor new];
@@ -2009,7 +2009,7 @@
textureDescriptor.arrayLength = descriptor.size.depthOrArrayLayers;
if (descriptor.sampleCount > 1) {
#if PLATFORM(WATCHOS) || PLATFORM(TVOS)
- return nullptr;
+ return Texture::createInvalid(*this);
#else
textureDescriptor.textureType = MTLTextureType2DMultisampleArray;
#endif
@@ -2030,7 +2030,7 @@
break;
case WGPUTextureDimension_Force32:
ASSERT_NOT_REACHED();
- return nullptr;
+ return Texture::createInvalid(*this);
}
textureDescriptor.pixelFormat = pixelFormat(descriptor.format);
@@ -2046,7 +2046,7 @@
id<MTLTexture> texture = [m_device newTextureWithDescriptor:textureDescriptor];
if (!texture)
- return nullptr;
+ return Texture::createInvalid(*this);
texture.label = fromAPI(descriptor.label);
@@ -2251,10 +2251,10 @@
return extent;
}
-RefPtr<TextureView> Texture::createView(const WGPUTextureViewDescriptor& inputDescriptor)
+Ref<TextureView> Texture::createView(const WGPUTextureViewDescriptor& inputDescriptor)
{
if (inputDescriptor.nextInChain)
- return nullptr;
+ return TextureView::createInvalid(m_device);
// https://gpuweb.github.io/gpuweb/#dom-gputexture-createview
@@ -2264,7 +2264,7 @@
m_device->generateAValidationError("Validation failure."_s);
// FIXME: "Return a new invalid GPUTextureView."
- return nullptr;
+ return TextureView::createInvalid(m_device);
}
std::optional<MTLPixelFormat> pixelFormat;
@@ -2281,11 +2281,11 @@
break;
case WGPUTextureAspect_Force32:
ASSERT_NOT_REACHED();
- return nullptr;
+ return TextureView::createInvalid(m_device);
}
}
if (!pixelFormat)
- return nullptr;
+ return TextureView::createInvalid(m_device);
ASSERT(*pixelFormat != MTLPixelFormatInvalid);
MTLTextureType textureType;
@@ -2292,7 +2292,7 @@
switch (descriptor.dimension) {
case WGPUTextureViewDimension_Undefined:
ASSERT_NOT_REACHED();
- return nullptr;
+ return TextureView::createInvalid(m_device);
case WGPUTextureViewDimension_1D:
if (descriptor.arrayLayerCount == 1)
textureType = MTLTextureType1D;
@@ -2308,7 +2308,7 @@
case WGPUTextureViewDimension_2DArray:
if (m_descriptor.sampleCount > 1) {
#if PLATFORM(WATCHOS) || PLATFORM(TVOS)
- return nullptr;
+ return TextureView::createInvalid(m_device);
#else
textureType = MTLTextureType2DMultisampleArray;
#endif
@@ -2326,7 +2326,7 @@
break;
case WGPUTextureViewDimension_Force32:
ASSERT_NOT_REACHED();
- return nullptr;
+ return TextureView::createInvalid(m_device);
}
auto levels = NSMakeRange(descriptor.baseMipLevel, descriptor.mipLevelCount);
@@ -2335,7 +2335,7 @@
id<MTLTexture> texture = [m_texture newTextureViewWithPixelFormat:*pixelFormat textureType:textureType levels:levels slices:slices];
if (!texture)
- return nullptr;
+ return TextureView::createInvalid(m_device);
texture.label = fromAPI(descriptor.label);