Diff
Modified: trunk/Source/WebCore/ChangeLog (239514 => 239515)
--- trunk/Source/WebCore/ChangeLog 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/ChangeLog 2018-12-21 20:46:03 UTC (rev 239515)
@@ -1,3 +1,40 @@
+2018-12-21 Justin Fan <justin_...@apple.com>
+
+ [WebGPU] GPUBindGroupLayout refactoring: no HashMap, and failure logging
+ https://bugs.webkit.org/show_bug.cgi?id=192990
+
+ Reviewed by Myles C. Maxfield.
+
+ Refactor away the unnecessary HashMaps when creating MTLArgumentEncoders in GPUBindGroupLayout creation.
+ Also update GPUBindGroupLayout::create -> tryCreate, in order to better handle Objective-C exceptions.
+
+ No new tests; no change in behavior.
+
+ * Modules/webgpu/WebGPUBindGroupLayout.cpp:
+ (WebCore::WebGPUBindGroupLayout::create):
+ (WebCore::WebGPUBindGroupLayout::WebGPUBindGroupLayout):
+ * Modules/webgpu/WebGPUBindGroupLayout.h:
+ (WebCore::WebGPUBindGroupLayout::bindGroupLayout const):
+ * Modules/webgpu/WebGPUDevice.cpp:
+ (WebCore::WebGPUDevice::createBindGroupLayout const):
+ * platform/graphics/gpu/GPUBindGroupLayout.h:
+ * platform/graphics/gpu/GPUDevice.cpp:
+ (WebCore::GPUDevice::tryCreateBindGroupLayout const): Renamed from ::create*. Now returning a RefPtr.
+ (WebCore::GPUDevice::createBindGroupLayout const): Deleted.
+ * platform/graphics/gpu/GPUDevice.h:
+ * platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm:
+ (WebCore::appendArgumentToArray):
+ (WebCore::newEncoder):
+ (WebCore::GPUBindGroupLayout::tryCreate): Renamed from ::create. Now returning a RefPtr.
+ (WebCore::GPUBindGroupLayout::GPUBindGroupLayout):
+ (WebCore::appendArgumentToArrayInMap): Deleted.
+ (WebCore::GPUBindGroupLayout::create): Deleted.
+
+ Deleted unneeded GPUBindGroupLayout.cpp:
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/gpu/GPUBindGroupLayout.cpp: Removed.
+
2018-12-21 Alejandro G. Castro <a...@igalia.com>
[GTK][WPE] Add DeviceIdHashSaltStorage disk persistence
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayout.cpp (239514 => 239515)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayout.cpp 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayout.cpp 2018-12-21 20:46:03 UTC (rev 239515)
@@ -30,12 +30,12 @@
namespace WebCore {
-Ref<WebGPUBindGroupLayout> WebGPUBindGroupLayout::create(Ref<GPUBindGroupLayout>&& layout)
+Ref<WebGPUBindGroupLayout> WebGPUBindGroupLayout::create(RefPtr<GPUBindGroupLayout>&& layout)
{
return adoptRef(*new WebGPUBindGroupLayout(WTFMove(layout)));
}
-WebGPUBindGroupLayout::WebGPUBindGroupLayout(Ref<GPUBindGroupLayout>&& layout)
+WebGPUBindGroupLayout::WebGPUBindGroupLayout(RefPtr<GPUBindGroupLayout>&& layout)
: m_bindGroupLayout(WTFMove(layout))
{
}
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayout.h (239514 => 239515)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayout.h 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBindGroupLayout.h 2018-12-21 20:46:03 UTC (rev 239515)
@@ -36,14 +36,14 @@
class WebGPUBindGroupLayout : public RefCounted<WebGPUBindGroupLayout> {
public:
- static Ref<WebGPUBindGroupLayout> create(Ref<GPUBindGroupLayout>&&);
+ static Ref<WebGPUBindGroupLayout> create(RefPtr<GPUBindGroupLayout>&&);
- RefPtr<GPUBindGroupLayout> bindGroupLayout() const { return m_bindGroupLayout.copyRef(); }
+ RefPtr<GPUBindGroupLayout> bindGroupLayout() const { return m_bindGroupLayout; }
private:
- explicit WebGPUBindGroupLayout(Ref<GPUBindGroupLayout>&&);
+ explicit WebGPUBindGroupLayout(RefPtr<GPUBindGroupLayout>&&);
- Ref<GPUBindGroupLayout> m_bindGroupLayout;
+ RefPtr<GPUBindGroupLayout> m_bindGroupLayout;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (239514 => 239515)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp 2018-12-21 20:46:03 UTC (rev 239515)
@@ -69,7 +69,7 @@
Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&& descriptor) const
{
- auto layout = m_device->createBindGroupLayout(GPUBindGroupLayoutDescriptor { descriptor.bindings });
+ auto layout = m_device->tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor { descriptor.bindings });
return WebGPUBindGroupLayout::create(WTFMove(layout));
}
Modified: trunk/Source/WebCore/Sources.txt (239514 => 239515)
--- trunk/Source/WebCore/Sources.txt 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/Sources.txt 2018-12-21 20:46:03 UTC (rev 239515)
@@ -1743,7 +1743,6 @@
platform/graphics/filters/SourceGraphic.cpp
platform/graphics/filters/SpotLightSource.cpp
-platform/graphics/gpu/GPUBindGroupLayout.cpp
platform/graphics/gpu/GPUDevice.cpp
platform/graphics/gpu/GPUPipelineLayout.cpp
platform/graphics/gpu/legacy/GPULegacyBuffer.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (239514 => 239515)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2018-12-21 20:46:03 UTC (rev 239515)
@@ -13738,7 +13738,6 @@
D01A27AC10C9BFD800026A42 /* SpaceSplitString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpaceSplitString.h; sourceTree = "<group>"; };
D0232B5821CB49B7009483B9 /* GPUBindGroupLayoutMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUBindGroupLayoutMetal.mm; sourceTree = "<group>"; };
D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayout.h; sourceTree = "<group>"; };
- D02454D121C4A41C00B73628 /* GPUBindGroupLayout.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUBindGroupLayout.cpp; sourceTree = "<group>"; };
D02B83ED21C8397A00F85473 /* WebGPUBindGroupLayoutDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBindGroupLayoutDescriptor.idl; sourceTree = "<group>"; };
D02C26912181416D00D818E4 /* WebGPUAdapterDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUAdapterDescriptor.h; sourceTree = "<group>"; };
D02C26922181416D00D818E4 /* WebGPUAdapterDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUAdapterDescriptor.idl; sourceTree = "<group>"; };
@@ -18064,7 +18063,6 @@
children = (
D087CE3721ACA94200BDE174 /* cocoa */,
312FF8CE21A4C33F00EB199D /* legacy */,
- D02454D121C4A41C00B73628 /* GPUBindGroupLayout.cpp */,
D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */,
D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */,
D083D98421C48050008E8EFF /* GPUBindGroupLayoutDescriptor.h */,
Deleted: trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.cpp (239514 => 239515)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.cpp 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.cpp 2018-12-21 20:46:03 UTC (rev 239515)
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "GPUBindGroupLayout.h"
-
-#if ENABLE(WEBGPU)
-
-namespace WebCore {
-
-} // namespace WebCore
-
-#endif // ENABLE(WEBGPU)
-
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h (239514 => 239515)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h 2018-12-21 20:46:03 UTC (rev 239515)
@@ -29,11 +29,9 @@
#include "GPUBindGroupLayoutDescriptor.h"
-#include <wtf/HashMap.h>
-#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
#include <wtf/RetainPtr.h>
-#include <wtf/Vector.h>
OBJC_PROTOCOL(MTLArgumentEncoder);
@@ -43,14 +41,18 @@
class GPUBindGroupLayout : public RefCounted<GPUBindGroupLayout> {
public:
- using ArgumentsMap = HashMap<GPUShaderStageFlags, RetainPtr<MTLArgumentEncoder>>;
+ struct ArgumentEncoders {
+ RetainPtr<MTLArgumentEncoder> vertex;
+ RetainPtr<MTLArgumentEncoder> fragment;
+ RetainPtr<MTLArgumentEncoder> compute;
+ };
- static Ref<GPUBindGroupLayout> create(const GPUDevice&, GPUBindGroupLayoutDescriptor&&);
+ static RefPtr<GPUBindGroupLayout> tryCreate(const GPUDevice&, GPUBindGroupLayoutDescriptor&&);
private:
- GPUBindGroupLayout(ArgumentsMap&&);
+ GPUBindGroupLayout(ArgumentEncoders&&);
- ArgumentsMap m_argumentsMap;
+ ArgumentEncoders m_argumentEncoders;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp (239514 => 239515)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp 2018-12-21 20:46:03 UTC (rev 239515)
@@ -46,9 +46,9 @@
return GPUBuffer::create(*this, WTFMove(descriptor));
}
-Ref<GPUBindGroupLayout> GPUDevice::createBindGroupLayout(GPUBindGroupLayoutDescriptor&& descriptor) const
+RefPtr<GPUBindGroupLayout> GPUDevice::tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&& descriptor) const
{
- return GPUBindGroupLayout::create(*this, WTFMove(descriptor));
+ return GPUBindGroupLayout::tryCreate(*this, WTFMove(descriptor));
}
Ref<GPUPipelineLayout> GPUDevice::createPipelineLayout(GPUPipelineLayoutDescriptor&& descriptor) const
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h (239514 => 239515)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h 2018-12-21 20:46:03 UTC (rev 239515)
@@ -59,7 +59,7 @@
RefPtr<GPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
- Ref<GPUBindGroupLayout> createBindGroupLayout(GPUBindGroupLayoutDescriptor&&) const;
+ RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&&) const;
Ref<GPUPipelineLayout> createPipelineLayout(GPUPipelineLayoutDescriptor&&) const;
RefPtr<GPUShaderModule> createShaderModule(GPUShaderModuleDescriptor&&) const;
Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm (239514 => 239515)
--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm 2018-12-21 20:25:23 UTC (rev 239514)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm 2018-12-21 20:46:03 UTC (rev 239515)
@@ -29,7 +29,9 @@
#if ENABLE(WEBGPU)
#import "GPUDevice.h"
+#import "Logging.h"
+#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
#import <wtf/BlockObjCExceptions.h>
@@ -48,24 +50,34 @@
}
}
-using ArgumentArraysMap = HashMap<GPUShaderStageFlags, RetainPtr<NSMutableArray<MTLArgumentDescriptor *>>>;
-static void appendArgumentToArrayInMap(ArgumentArraysMap& map, GPUShaderStageFlags stage, RetainPtr<MTLArgumentDescriptor> argument)
+using ArgumentArray = RetainPtr<NSMutableArray<MTLArgumentDescriptor *>>;
+static void appendArgumentToArray(ArgumentArray array, RetainPtr<MTLArgumentDescriptor> argument)
{
- auto iterator = map.find(stage);
- if (iterator == map.end()) {
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- map.set(stage, [[NSMutableArray alloc] initWithObjects:argument.get(), nil]);
- END_BLOCK_OBJC_EXCEPTIONS;
- } else
- [iterator->value addObject:argument.get()];
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+ if (!array)
+ array = [[NSMutableArray alloc] initWithObjects:argument.get(), nil];
+ else
+ [array addObject:argument.get()];
+ END_BLOCK_OBJC_EXCEPTIONS;
}
-Ref<GPUBindGroupLayout> GPUBindGroupLayout::create(const GPUDevice& device, GPUBindGroupLayoutDescriptor&& descriptor)
+static RetainPtr<MTLArgumentEncoder> newEncoder(const GPUDevice& device, ArgumentArray array)
{
- ArgumentArraysMap argumentArraysMap;
+ RetainPtr<MTLArgumentEncoder> encoder;
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+ encoder = adoptNS([device.platformDevice() newArgumentEncoderWithArguments:array.get()]);
+ END_BLOCK_OBJC_EXCEPTIONS;
+ if (!encoder)
+ LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Unable to create MTLArgumentEncoder!");
+ return encoder;
+};
+
+RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device, GPUBindGroupLayoutDescriptor&& descriptor)
+{
+ ArgumentArray vertexArguments, fragmentArguments, computeArguments;
+
for (const auto& binding : descriptor.bindings) {
-
RetainPtr<MTLArgumentDescriptor> mtlArgument;
BEGIN_BLOCK_OBJC_EXCEPTIONS;
@@ -72,33 +84,42 @@
mtlArgument = adoptNS([MTLArgumentDescriptor new]);
END_BLOCK_OBJC_EXCEPTIONS;
+ if (!mtlArgument) {
+ LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Unable to create MTLArgumentDescriptor!");
+ return nullptr;
+ }
+
mtlArgument.get().dataType = MTLDataTypeForBindingType(binding.type);
mtlArgument.get().index = binding.binding;
if (binding.visibility & GPUShaderStageBit::VERTEX)
- appendArgumentToArrayInMap(argumentArraysMap, GPUShaderStageBit::VERTEX, mtlArgument);
+ appendArgumentToArray(vertexArguments, mtlArgument);
if (binding.visibility & GPUShaderStageBit::FRAGMENT)
- appendArgumentToArrayInMap(argumentArraysMap, GPUShaderStageBit::FRAGMENT, mtlArgument);
+ appendArgumentToArray(fragmentArguments, mtlArgument);
if (binding.visibility & GPUShaderStageBit::COMPUTE)
- appendArgumentToArrayInMap(argumentArraysMap, GPUShaderStageBit::COMPUTE, mtlArgument);
+ appendArgumentToArray(computeArguments, mtlArgument);
}
- ArgumentsMap argumentsMap;
+ ArgumentEncoders encoders;
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
- for (const auto& argumentArrayPair : argumentArraysMap) {
- auto mtlArgumentEncoder = adoptNS([device.platformDevice() newArgumentEncoderWithArguments:argumentArrayPair.value.get()]);
- argumentsMap.set(argumentArrayPair.key, mtlArgumentEncoder);
+ if (vertexArguments) {
+ if (!(encoders.vertex = newEncoder(device, vertexArguments)))
+ return nullptr;
}
+ if (fragmentArguments) {
+ if (!(encoders.fragment = newEncoder(device, fragmentArguments)))
+ return nullptr;
+ }
+ if (computeArguments) {
+ if (!(encoders.compute = newEncoder(device, computeArguments)))
+ return nullptr;
+ }
- END_BLOCK_OBJC_EXCEPTIONS;
-
- return adoptRef(*new GPUBindGroupLayout(WTFMove(argumentsMap)));
+ return adoptRef(new GPUBindGroupLayout(WTFMove(encoders)));
}
-GPUBindGroupLayout::GPUBindGroupLayout(ArgumentsMap&& map)
- : m_argumentsMap(map)
+GPUBindGroupLayout::GPUBindGroupLayout(ArgumentEncoders&& encoders)
+ : m_argumentEncoders(WTFMove(encoders))
{
}