Diff
Modified: trunk/LayoutTests/ChangeLog (241180 => 241181)
--- trunk/LayoutTests/ChangeLog 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/LayoutTests/ChangeLog 2019-02-08 02:01:39 UTC (rev 241181)
@@ -1,3 +1,16 @@
+2019-02-07 Justin Fan <justin_...@apple.com>
+
+ [Web GPU] GPUDevice::createTexture implementation prototype
+ https://bugs.webkit.org/show_bug.cgi?id=194409
+ <rdar://problem/47894312>
+
+ Reviewed by Myles C. Maxfield.
+
+ Update textures-textureviews.html to WPT format and to test creation of textures via the GPUDevice.
+
+ * webgpu/textures-textureviews-expected.txt:
+ * webgpu/textures-textureviews.html:
+
2019-02-07 Shawn Roberts <srobe...@apple.com>
fast/hidpi/hidpi-long-page-with-inset-element.html is a flaky image failure
Modified: trunk/LayoutTests/webgpu/textures-textureviews-expected.txt (241180 => 241181)
--- trunk/LayoutTests/webgpu/textures-textureviews-expected.txt 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/LayoutTests/webgpu/textures-textureviews-expected.txt 2019-02-08 02:01:39 UTC (rev 241181)
@@ -1,8 +1,6 @@
-PASS [object WebGPU] is defined.
-PASS Acquired next WebGPUTexture from WebGPURenderingContext.
-PASS Created default WebGPUTextureView from a WebGPUTexture
-All tests complete.
-PASS successfullyParsed is true
-TEST COMPLETE
+PASS Create texture view from swap chain.
+PASS Create basic depth texture from device.
+PASS Create basic 4x multisampled texture.
+PASS Create basic 3D texture from device.
Modified: trunk/LayoutTests/webgpu/textures-textureviews.html (241180 => 241181)
--- trunk/LayoutTests/webgpu/textures-textureviews.html 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/LayoutTests/webgpu/textures-textureviews.html 2019-02-08 02:01:39 UTC (rev 241181)
@@ -1,34 +1,66 @@
-<!DOCTYPE html>
-<html>
-<script src=""
-<script src=""
+<!DOCTYPE html><!-- webkit-test-runner [ experimental:WebGPUEnabled=true ] -->
+<meta charset=utf-8>
+<title>Basic GPUTexture Tests.</title>
+<body>
+<canvas width="400" height="400"></canvas>
+<script src=""
+<script src=""
+<script src=""
<script>
-if (window.testRunner)
- window.testRunner.dumpAsText();
+const canvas = document.querySelector("canvas");
+let device, context;
-function setUpNextTextureView() {
- let texture = context.getNextTexture();
- if (texture)
- testPassed("Acquired next WebGPUTexture from WebGPURenderingContext.");
- else {
- testFailed("Could not get next WebGPUTexture from WebGPURenderingContext!");
- return;
- }
+let texSize = {
+ width: canvas.width,
+ height: canvas.height,
+ depth: 1
+};
- let textureView = texture.createDefaultTextureView();
- if (textureView)
- testPassed("Created default WebGPUTextureView from a WebGPUTexture");
- else {
- testFailed("Could not create default WebGPUTextureView!");
- return;
- }
-}
+let texDescriptor = {
+ size: texSize,
+ arrayLayerCount: 1,
+ mipLevelCount: 1,
+ sampleCount: 1,
+ dimension: "2d",
+ format: "d32-float-s8-uint",
+ usage: GPUTextureUsage.OUTPUT_ATTACHMENT
+};
-// FIXME: Add tests for device.createTexture, WebGPUTextureDescriptor, and WebGPUTextureViewDescriptor.
+promise_test(async () => {
+ device = await getBasicDevice();
+ context = createBasicContext(canvas, device);
-runWebGPUTests([setUpNextTextureView]);
+ const texture = context.getNextTexture();
+ assert_true(texture instanceof WebGPUTexture, "Successfully acquired next texture.");
-successfullyParsed = true;
+ const textureView = texture.createDefaultTextureView();
+ assert_true(textureView instanceof WebGPUTextureView, "Successfully created texture view from next texture.");
+}, "Create texture view from swap chain.");
+
+promise_test(async () => {
+ const depthTexture = device.createTexture(texDescriptor);
+ assert_true(depthTexture instanceof WebGPUTexture, "Successfully created depth texture.");
+}, "Create basic depth texture from device.");
+
+promise_test(async () => {
+ texDescriptor.sampleCount = 4;
+ texDescriptor.format = "r8g8b8a8-unorm";
+ texDescriptor.usage = GPUTextureUsage.SAMPLED | GPUTextureUsage.TRANSFER_SRC
+
+ const multisampledTexture = device.createTexture(texDescriptor);
+ assert_true(multisampledTexture instanceof WebGPUTexture, "Successfully created multisampled texture.");
+}, "Create basic 4x multisampled texture.");
+
+promise_test(async () => {
+ texDescriptor.size.depth = 3;
+ texDescriptor.sampleCount = 1;
+ texDescriptor.dimension = "3d";
+
+ const texture3d = device.createTexture(texDescriptor);
+ assert_true(texture3d instanceof WebGPUTexture, "Successfully created basic 3D texture.");
+}, "Create basic 3D texture from device.");
+
+// FIXME: Add tests for 1D textures, textureArrays, and WebGPUTextureViews.
</script>
-<script src=""
+</body>
</html>
\ No newline at end of file
Modified: trunk/Source/WebCore/ChangeLog (241180 => 241181)
--- trunk/Source/WebCore/ChangeLog 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/ChangeLog 2019-02-08 02:01:39 UTC (rev 241181)
@@ -1,3 +1,46 @@
+2019-02-07 Justin Fan <justin_...@apple.com>
+
+ [Web GPU] GPUDevice::createTexture implementation prototype
+ https://bugs.webkit.org/show_bug.cgi?id=194409
+ <rdar://problem/47894312>
+
+ Reviewed by Myles C. Maxfield.
+
+ Test: textures-textureviews.html updated to test new functionality.
+
+ Implement GPUDevice::createTexture():
+ * Modules/webgpu/WebGPUDevice.cpp:
+ (WebCore::WebGPUDevice::createTexture const):
+ * Modules/webgpu/WebGPUDevice.h:
+ * Modules/webgpu/WebGPUDevice.idl:
+ * Modules/webgpu/WebGPUTexture.cpp:
+ (WebCore::WebGPUTexture::create): Modified to return non-nullable to match direction of API.
+ (WebCore::WebGPUTexture::WebGPUTexture):
+ * Modules/webgpu/WebGPUTexture.h:
+
+ Metal backend MTLTextureDescriptor and MTLTexture creation:
+ * platform/graphics/gpu/GPUDevice.cpp:
+ (WebCore::GPUDevice::tryCreateTexture const):
+ * platform/graphics/gpu/GPUDevice.h:
+ * platform/graphics/gpu/GPUTexture.h:
+ * platform/graphics/gpu/cocoa/GPUTextureMetal.mm:
+ (WebCore::mtlTextureTypeForGPUTextureDescriptor):
+ (WebCore::mtlTextureUsageForGPUTextureUsageFlags):
+ (WebCore::storageModeForPixelFormatAndSampleCount):
+ (WebCore::tryCreateMtlTextureDescriptor):
+ (WebCore::GPUTexture::tryCreate):
+ (WebCore::GPUTexture::createDefaultTextureView): Add ObjC try/catch guards.
+
+ Add GPUUtils.h/cpp for shared utility functions:
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/gpu/GPUUtils.h: Added. Moved platformTextureFormatForGPUTextureFormat here.
+ * platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm:
+ (WebCore::GPUSwapChain::setFormat):
+ (WebCore::platformTextureFormatForGPUTextureFormat): Moved to GPUUtils.
+ * platform/graphics/gpu/cocoa/GPUUtilsMetal.mm: Added.
+ (WebCore::platformTextureFormatForGPUTextureFormat): Moved here to be referenced by multiple files.
+
2019-02-07 Sihui Liu <sihui_...@apple.com>
REGRESSION(r239887): Crash under IDBConnectionToClient::didDeleteDatabase(WebCore::IDBResultData const&)
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (241180 => 241181)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp 2019-02-08 02:01:39 UTC (rev 241181)
@@ -36,6 +36,7 @@
#include "GPUPipelineStageDescriptor.h"
#include "GPURenderPipelineDescriptor.h"
#include "GPUShaderModuleDescriptor.h"
+#include "GPUTextureDescriptor.h"
#include "Logging.h"
#include "WebGPUBindGroup.h"
#include "WebGPUBindGroupBinding.h"
@@ -52,6 +53,7 @@
#include "WebGPURenderPipelineDescriptor.h"
#include "WebGPUShaderModule.h"
#include "WebGPUShaderModuleDescriptor.h"
+#include "WebGPUTexture.h"
#include <wtf/Variant.h>
namespace WebCore {
@@ -78,6 +80,12 @@
return nullptr;
}
+Ref<WebGPUTexture> WebGPUDevice::createTexture(GPUTextureDescriptor&& descriptor) const
+{
+ auto texture = m_device->tryCreateTexture(WTFMove(descriptor));
+ return WebGPUTexture::create(WTFMove(texture));
+}
+
Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&& descriptor) const
{
auto layout = m_device->tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor { descriptor.bindings });
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h (241180 => 241181)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h 2019-02-08 02:01:39 UTC (rev 241181)
@@ -47,7 +47,9 @@
class WebGPUPipelineLayout;
class WebGPURenderPipeline;
class WebGPUShaderModule;
+class WebGPUTexture;
+struct GPUTextureDescriptor;
struct WebGPUBindGroupDescriptor;
struct WebGPUPipelineLayoutDescriptor;
struct WebGPURenderPipelineDescriptor;
@@ -61,6 +63,7 @@
const GPUDevice& device() const { return m_device.get(); }
RefPtr<WebGPUBuffer> createBuffer(WebGPUBufferDescriptor&&) const;
+ Ref<WebGPUTexture> createTexture(GPUTextureDescriptor&&) const;
Ref<WebGPUBindGroupLayout> createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&&) const;
Ref<WebGPUPipelineLayout> createPipelineLayout(WebGPUPipelineLayoutDescriptor&&) const;
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl (241180 => 241181)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl 2019-02-08 02:01:39 UTC (rev 241181)
@@ -32,6 +32,7 @@
readonly attribute WebGPUAdapter adapter;
WebGPUBuffer createBuffer(WebGPUBufferDescriptor descriptor);
+ WebGPUTexture createTexture(GPUTextureDescriptor descriptor);
WebGPUBindGroupLayout createBindGroupLayout(WebGPUBindGroupLayoutDescriptor descriptor);
WebGPUPipelineLayout createPipelineLayout(WebGPUPipelineLayoutDescriptor descriptor);
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp (241180 => 241181)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp 2019-02-08 02:01:39 UTC (rev 241181)
@@ -32,12 +32,12 @@
namespace WebCore {
-RefPtr<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture)
+Ref<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture)
{
- return texture ? adoptRef(new WebGPUTexture(texture.releaseNonNull())) : nullptr;
+ return adoptRef(*new WebGPUTexture(WTFMove(texture)));
}
-WebGPUTexture::WebGPUTexture(Ref<GPUTexture>&& texture)
+WebGPUTexture::WebGPUTexture(RefPtr<GPUTexture>&& texture)
: m_texture(WTFMove(texture))
{
}
Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h (241180 => 241181)
--- trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h 2019-02-08 02:01:39 UTC (rev 241181)
@@ -38,14 +38,14 @@
class WebGPUTexture : public RefCounted<WebGPUTexture> {
public:
- static RefPtr<WebGPUTexture> create(RefPtr<GPUTexture>&&);
+ static Ref<WebGPUTexture> create(RefPtr<GPUTexture>&&);
RefPtr<WebGPUTextureView> createDefaultTextureView();
private:
- explicit WebGPUTexture(Ref<GPUTexture>&&);
+ explicit WebGPUTexture(RefPtr<GPUTexture>&&);
- Ref<GPUTexture> m_texture;
+ RefPtr<GPUTexture> m_texture;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/SourcesCocoa.txt (241180 => 241181)
--- trunk/Source/WebCore/SourcesCocoa.txt 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2019-02-08 02:01:39 UTC (rev 241181)
@@ -331,6 +331,7 @@
platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm
platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm
platform/graphics/gpu/cocoa/GPUTextureMetal.mm
+platform/graphics/gpu/cocoa/GPUUtilsMetal.mm
platform/graphics/gpu/Texture.cpp
platform/graphics/gpu/TilingData.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (241180 => 241181)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2019-02-08 02:01:39 UTC (rev 241181)
@@ -14066,6 +14066,8 @@
D06A9A2122026C7A0083C662 /* GPURequestAdapterOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPURequestAdapterOptions.h; sourceTree = "<group>"; };
D06C0D8D0CFD11460065F43F /* RemoveFormatCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoveFormatCommand.h; sourceTree = "<group>"; };
D06C0D8E0CFD11460065F43F /* RemoveFormatCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoveFormatCommand.cpp; sourceTree = "<group>"; };
+ D06EF552220BA26A0018724E /* GPUUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUUtils.h; sourceTree = "<group>"; };
+ D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUUtilsMetal.mm; sourceTree = "<group>"; };
D07DEAB70A36554A00CA30F8 /* InsertListCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InsertListCommand.cpp; sourceTree = "<group>"; };
D07DEAB80A36554A00CA30F8 /* InsertListCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InsertListCommand.h; sourceTree = "<group>"; };
D083D98421C48050008E8EFF /* GPUBindGroupLayoutDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutDescriptor.h; sourceTree = "<group>"; };
@@ -18503,6 +18505,7 @@
D026F486220A505900AC5F49 /* GPUTextureDimension.h */,
312FF8C321A4C2F300EB199D /* GPUTextureFormat.h */,
D026F485220A477200AC5F49 /* GPUTextureUsage.h */,
+ D06EF552220BA26A0018724E /* GPUUtils.h */,
D0D8649B21BA1C2D003C983C /* GPUVertexAttributeDescriptor.h */,
D0D8649C21BA1CE8003C983C /* GPUVertexInputDescriptor.h */,
498770D71242C535002226BA /* Texture.cpp */,
@@ -26188,6 +26191,7 @@
D087CE4021ACA94200BDE174 /* GPUShaderModuleMetal.mm */,
D087CE3E21ACA94200BDE174 /* GPUSwapChainMetal.mm */,
D087CE3F21ACA94200BDE174 /* GPUTextureMetal.mm */,
+ D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */,
);
path = cocoa;
sourceTree = "<group>";
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp (241180 => 241181)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp 2019-02-08 02:01:39 UTC (rev 241181)
@@ -39,6 +39,8 @@
#include "GPURenderPipelineDescriptor.h"
#include "GPUShaderModule.h"
#include "GPUShaderModuleDescriptor.h"
+#include "GPUTexture.h"
+#include "GPUTextureDescriptor.h"
namespace WebCore {
@@ -47,6 +49,11 @@
return GPUBuffer::create(*this, WTFMove(descriptor));
}
+RefPtr<GPUTexture> GPUDevice::tryCreateTexture(GPUTextureDescriptor&& descriptor) const
+{
+ return GPUTexture::tryCreate(*this, WTFMove(descriptor));
+}
+
RefPtr<GPUBindGroupLayout> GPUDevice::tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&& descriptor) const
{
return GPUBindGroupLayout::tryCreate(*this, WTFMove(descriptor));
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h (241180 => 241181)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h 2019-02-08 02:01:39 UTC (rev 241181)
@@ -46,6 +46,7 @@
class GPUPipelineLayout;
class GPURenderPipeline;
class GPUShaderModule;
+class GPUTexture;
struct GPUBindGroupLayoutDescriptor;
struct GPUBufferDescriptor;
@@ -53,6 +54,7 @@
struct GPURenderPipelineDescriptor;
struct GPURequestAdapterOptions;
struct GPUShaderModuleDescriptor;
+struct GPUTextureDescriptor;
class GPUDevice : public RefCounted<GPUDevice> {
public:
@@ -59,6 +61,7 @@
static RefPtr<GPUDevice> create(Optional<GPURequestAdapterOptions>&&);
RefPtr<GPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
+ RefPtr<GPUTexture> tryCreateTexture(GPUTextureDescriptor&&) const;
RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&&) const;
Ref<GPUPipelineLayout> createPipelineLayout(GPUPipelineLayoutDescriptor&&) const;
Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUTexture.h (241180 => 241181)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUTexture.h 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUTexture.h 2019-02-08 02:01:39 UTC (rev 241181)
@@ -35,11 +35,16 @@
namespace WebCore {
+class GPUDevice;
+
+struct GPUTextureDescriptor;
+
using PlatformTexture = MTLTexture;
using PlatformTextureSmartPtr = RetainPtr<MTLTexture>;
class GPUTexture : public RefCounted<GPUTexture> {
public:
+ static RefPtr<GPUTexture> tryCreate(const GPUDevice&, GPUTextureDescriptor&&);
static Ref<GPUTexture> create(PlatformTextureSmartPtr&&);
PlatformTexture *platformTexture() const { return m_platformTexture.get(); }
Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h (from rev 241180, trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h) (0 => 241181)
--- trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h 2019-02-08 02:01:39 UTC (rev 241181)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+#include "GPUTextureFormat.h"
+
+namespace WebCore {
+
+PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat);
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm (241180 => 241181)
--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm 2019-02-08 02:01:39 UTC (rev 241181)
@@ -31,9 +31,9 @@
#import "GPUDevice.h"
#import "GPUTexture.h"
#import "GPUTextureFormat.h"
+#import "GPUUtils.h"
#import "Logging.h"
#import "WebGPULayer.h"
-
#import <Metal/Metal.h>
#import <QuartzCore/QuartzCore.h>
#import <wtf/BlockObjCExceptions.h>
@@ -80,36 +80,15 @@
[m_platformSwapLayer setDevice:device.platformDevice()];
}
-static Optional<PlatformTextureFormat> platformTextureFormatForGPUTextureFormat(GPUTextureFormat format)
-{
- switch (format) {
- case GPUTextureFormat::R8g8b8a8Unorm:
- return MTLPixelFormatRGBA8Unorm;
- case GPUTextureFormat::R8g8b8a8Uint:
- return MTLPixelFormatRGBA8Uint;
- case GPUTextureFormat::B8g8r8a8Unorm:
- return MTLPixelFormatBGRA8Unorm;
- case GPUTextureFormat::D32FloatS8Uint:
- return MTLPixelFormatDepth32Float_Stencil8;
- default:
- LOG(WebGPU, "GPUSwapChain::setFormat(): Invalid texture format specified!");
- return WTF::nullopt;
- }
-}
-
void GPUSwapChain::setFormat(GPUTextureFormat format)
{
- auto result = platformTextureFormatForGPUTextureFormat(format);
- if (!result)
- return;
+ auto mtlFormat = static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(format));
- auto mtlResult = static_cast<MTLPixelFormat>(result.value());
-
- switch (mtlResult) {
+ switch (mtlFormat) {
case MTLPixelFormatBGRA8Unorm:
// FIXME: Add the other supported swap layer formats as they are added to GPU spec.
// MTLPixelFormatBGRA8Unorm_sRGB, MTLPixelFormatRGBA16Float, MTLPixelFormatBGRA10_XR, and MTLPixelFormatBGRA10_XR_sRGB.
- [m_platformSwapLayer setPixelFormat:mtlResult];
+ [m_platformSwapLayer setPixelFormat:mtlFormat];
return;
default:
LOG(WebGPU, "GPUSwapChain::setFormat(): Unsupported MTLPixelFormat!");
Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm (241180 => 241181)
--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm 2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm 2019-02-08 02:01:39 UTC (rev 241181)
@@ -28,13 +28,140 @@
#if ENABLE(WEBGPU)
+#import "GPUDevice.h"
+#import "GPUTextureDescriptor.h"
+#import "GPUUtils.h"
#import "Logging.h"
-
#import <Metal/Metal.h>
#import <wtf/BlockObjCExceptions.h>
+#import <wtf/Optional.h>
namespace WebCore {
+static MTLTextureType mtlTextureTypeForGPUTextureDescriptor(const GPUTextureDescriptor& descriptor)
+{
+ switch (descriptor.dimension) {
+ case GPUTextureDimension::_1d:
+ return (descriptor.arrayLayerCount == 1) ? MTLTextureType1D : MTLTextureType1DArray;
+ case GPUTextureDimension::_2d: {
+ if (descriptor.arrayLayerCount == 1)
+ return (descriptor.sampleCount == 1) ? MTLTextureType2D : MTLTextureType2DMultisample;
+
+ return MTLTextureType2DArray;
+ }
+ case GPUTextureDimension::_3d:
+ return MTLTextureType3D;
+ }
+}
+
+static Optional<MTLTextureUsage> mtlTextureUsageForGPUTextureUsageFlags(GPUTextureUsageFlags flags)
+{
+ MTLTextureUsage usage = MTLTextureUsageUnknown;
+
+ if (flags & GPUTextureUsage::Storage)
+ usage |= MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView;
+
+ if (flags & GPUTextureUsage::Sampled) {
+ // SAMPLED is a read-only usage.
+ if (flags & GPUTextureUsage::Storage)
+ return WTF::nullopt;
+
+ usage |= MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView;
+ }
+
+ if (flags & GPUTextureUsage::OutputAttachment)
+ usage |= MTLTextureUsageRenderTarget;
+
+ return usage;
+}
+
+static MTLStorageMode storageModeForPixelFormatAndSampleCount(MTLPixelFormat format, unsigned long samples)
+{
+ // Depth, Stencil, DepthStencil, and Multisample textures must be allocated with the MTLStorageModePrivate resource option.
+ if (format == MTLPixelFormatDepth32Float_Stencil8 || samples > 1)
+ return MTLStorageModePrivate;
+
+ return MTLStorageModeManaged;
+}
+
+static RetainPtr<MTLTextureDescriptor> tryCreateMtlTextureDescriptor(const char* const functionName, const GPUTextureDescriptor&& descriptor)
+{
+#if LOG_DISABLED
+ UNUSED_PARAM(functionName);
+#endif
+
+ RetainPtr<MTLTextureDescriptor> mtlDescriptor;
+
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ mtlDescriptor = adoptNS([MTLTextureDescriptor new]);
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ if (!mtlDescriptor) {
+ LOG(WebGPU, "%s: Unable to create new MTLTextureDescriptor!", functionName);
+ return nullptr;
+ }
+
+ // FIXME: Add more validation as constraints are added to spec.
+ auto pixelFormat = static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(descriptor.format));
+
+ auto usage = mtlTextureUsageForGPUTextureUsageFlags(descriptor.usage);
+ if (!usage) {
+ LOG(WebGPU, "%s: Invalid GPUTextureUsageFlags!", functionName);
+ return nullptr;
+ }
+
+ auto storageMode = storageModeForPixelFormatAndSampleCount(pixelFormat, descriptor.sampleCount);
+
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ [mtlDescriptor setWidth:descriptor.size.width];
+ [mtlDescriptor setHeight:descriptor.size.height];
+ [mtlDescriptor setDepth:descriptor.size.depth];
+ [mtlDescriptor setArrayLength:descriptor.arrayLayerCount];
+ [mtlDescriptor setMipmapLevelCount:descriptor.mipLevelCount];
+ [mtlDescriptor setSampleCount:descriptor.sampleCount];
+ [mtlDescriptor setTextureType:mtlTextureTypeForGPUTextureDescriptor(descriptor)];
+ [mtlDescriptor setPixelFormat:pixelFormat];
+ [mtlDescriptor setUsage:*usage];
+
+ [mtlDescriptor setStorageMode:storageMode];
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ return mtlDescriptor;
+}
+
+RefPtr<GPUTexture> GPUTexture::tryCreate(const GPUDevice& device, GPUTextureDescriptor&& descriptor)
+{
+ const char* const functionName = "GPUTexture::tryCreate()";
+
+ if (!device.platformDevice()) {
+ LOG(WebGPU, "%s: Invalid GPUDevice!", functionName);
+ return nullptr;
+ }
+
+ auto mtlDescriptor = tryCreateMtlTextureDescriptor(functionName, WTFMove(descriptor));
+ if (!mtlDescriptor)
+ return nullptr;
+
+ RetainPtr<MTLTexture> mtlTexture;
+
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+ mtlTexture = adoptNS([device.platformDevice() newTextureWithDescriptor:mtlDescriptor.get()]);
+
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ if (!mtlTexture) {
+ LOG(WebGPU, "%s: Unable to create MTLTexture!", functionName);
+ return nullptr;
+ }
+
+ return adoptRef(new GPUTexture(WTFMove(mtlTexture)));
+}
+
Ref<GPUTexture> GPUTexture::create(PlatformTextureSmartPtr&& texture)
{
return adoptRef(*new GPUTexture(WTFMove(texture)));
@@ -49,8 +176,12 @@
{
RetainPtr<MTLTexture> texture;
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
texture = adoptNS([m_platformTexture newTextureViewWithPixelFormat:m_platformTexture.get().pixelFormat]);
+ END_BLOCK_OBJC_EXCEPTIONS;
+
if (!texture) {
LOG(WebGPU, "GPUTexture::createDefaultTextureView(): Unable to create MTLTexture view!");
return nullptr;
Copied: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm (from rev 241180, trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h) (0 => 241181)
--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm 2019-02-08 02:01:39 UTC (rev 241181)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#import "config.h"
+#import "GPUUtils.h"
+
+#if ENABLE(WEBGPU)
+
+#import <Metal/Metal.h>
+
+namespace WebCore {
+
+PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat format)
+{
+ switch (format) {
+ case GPUTextureFormat::R8g8b8a8Unorm:
+ return MTLPixelFormatRGBA8Unorm;
+ case GPUTextureFormat::R8g8b8a8Uint:
+ return MTLPixelFormatRGBA8Uint;
+ case GPUTextureFormat::B8g8r8a8Unorm:
+ return MTLPixelFormatBGRA8Unorm;
+ case GPUTextureFormat::D32FloatS8Uint:
+ return MTLPixelFormatDepth32Float_Stencil8;
+ }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)