WebKit Bugzilla
Attachment 361441 Details for
Bug 194409
: [Web GPU] GPUDevice::createTexture implementation prototype
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-194409-20190207141037.patch (text/plain), 30.01 KB, created by
Justin Fan
on 2019-02-07 14:10:38 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Justin Fan
Created:
2019-02-07 14:10:38 PST
Size:
30.01 KB
patch
obsolete
>Subversion Revision: 241049 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 20840c60dafa706d51455081fc61894f90fcfc79..488634270be1ed5b9776d64c62ae72cd9b00dcea 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,46 @@ >+2019-02-07 Justin Fan <justin_fan@apple.com> >+ >+ [Web GPU] GPUDevice::createTexture implementation prototype >+ https://bugs.webkit.org/show_bug.cgi?id=194409 >+ <rdar://problem/47894312> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-06 John Wilander <wilander@apple.com> > > Forward Ad Click Attribution data from HTMLAnchorElement::handleClick() to WebKit::NavigationActionData >diff --git a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp b/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >index 4dd0a9420dbb76d63332a1e8302d05046cd7ec12..3c680284a48f0ae0e808ac448fea8d10805c392b 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >@@ -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 @@ RefPtr<WebGPUBuffer> WebGPUDevice::createBuffer(WebGPUBufferDescriptor&& descrip > 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 }); >diff --git a/Source/WebCore/Modules/webgpu/WebGPUDevice.h b/Source/WebCore/Modules/webgpu/WebGPUDevice.h >index 8998ad63cd0f9baad06e324f5605c4e9a1bad321..9cae3ae986266cc6f0c9984b784993a69ad6f051 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUDevice.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUDevice.h >@@ -47,7 +47,9 @@ class WebGPUCommandBuffer; > class WebGPUPipelineLayout; > class WebGPURenderPipeline; > class WebGPUShaderModule; >+class WebGPUTexture; > >+struct GPUTextureDescriptor; > struct WebGPUBindGroupDescriptor; > struct WebGPUPipelineLayoutDescriptor; > struct WebGPURenderPipelineDescriptor; >@@ -61,6 +63,7 @@ public: > 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; >diff --git a/Source/WebCore/Modules/webgpu/WebGPUDevice.idl b/Source/WebCore/Modules/webgpu/WebGPUDevice.idl >index 2c86b3c80b0b1b28495db49a8efaf9fa1dc0d714..8342a5d0abb5c5180c23c4a518b4ce6f918a8685 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUDevice.idl >+++ b/Source/WebCore/Modules/webgpu/WebGPUDevice.idl >@@ -32,6 +32,7 @@ > readonly attribute WebGPUAdapter adapter; > > WebGPUBuffer createBuffer(WebGPUBufferDescriptor descriptor); >+ WebGPUTexture createTexture(GPUTextureDescriptor descriptor); > > WebGPUBindGroupLayout createBindGroupLayout(WebGPUBindGroupLayoutDescriptor descriptor); > WebGPUPipelineLayout createPipelineLayout(WebGPUPipelineLayoutDescriptor descriptor); >diff --git a/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp b/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp >index 9d9d7f963bd2e9157d85cdd37c18309e2636cad1..d5d3be6ca93635edb2274913a7cc1a8c4743aabd 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp >@@ -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)) > { > } >diff --git a/Source/WebCore/Modules/webgpu/WebGPUTexture.h b/Source/WebCore/Modules/webgpu/WebGPUTexture.h >index 11c08de4d25dc2cbded9418b55ac725b91367e55..c590bdf6942d7b9bfffd1e72b61289bd80d39b32 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUTexture.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUTexture.h >@@ -38,14 +38,14 @@ class WebGPUTextureView; > > 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 >diff --git a/Source/WebCore/SourcesCocoa.txt b/Source/WebCore/SourcesCocoa.txt >index 0722288da1c8935a78f7e192096a7ad8572e8043..853b18a911c4ff456cb0f3f33a18059b0ce89e3c 100644 >--- a/Source/WebCore/SourcesCocoa.txt >+++ b/Source/WebCore/SourcesCocoa.txt >@@ -331,6 +331,7 @@ platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm > 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 > >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 01dcd9670b99d2ef8338f829b294471e27f85a5f..4dc469182bd90451c67c627da81884013e78ebd5 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -14058,6 +14058,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>"; }; >@@ -18490,6 +18492,7 @@ > D026F486220A505900AC5F49 /* GPUTextureDimension.h */, > 312FF8C321A4C2F300EB199D /* GPUTextureFormat.h */, > D026F485220A477200AC5F49 /* GPUTextureUsage.h */, >+ D06EF552220BA26A0018724E /* GPUUtils.h */, > D0D8649B21BA1C2D003C983C /* GPUVertexAttributeDescriptor.h */, > D0D8649C21BA1CE8003C983C /* GPUVertexInputDescriptor.h */, > 498770D71242C535002226BA /* Texture.cpp */, >@@ -26175,6 +26178,7 @@ > D087CE4021ACA94200BDE174 /* GPUShaderModuleMetal.mm */, > D087CE3E21ACA94200BDE174 /* GPUSwapChainMetal.mm */, > D087CE3F21ACA94200BDE174 /* GPUTextureMetal.mm */, >+ D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */, > ); > path = cocoa; > sourceTree = "<group>"; >diff --git a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp b/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >index 41524a587dac1e8aaf407c8b92764e2ffb6ee335..16351e80fe7cdcad4abd434f16d9665a24690335 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >+++ b/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >@@ -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 @@ RefPtr<GPUBuffer> GPUDevice::createBuffer(GPUBufferDescriptor&& descriptor) cons > 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)); >diff --git a/Source/WebCore/platform/graphics/gpu/GPUDevice.h b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >index 9c9b5977a4a02b176191ae73dec5e1537d57510a..456eb8455dd4e564c4532bd3b2c3fd6271b59b49 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUDevice.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >@@ -46,6 +46,7 @@ class GPUCommandBuffer; > class GPUPipelineLayout; > class GPURenderPipeline; > class GPUShaderModule; >+class GPUTexture; > > struct GPUBindGroupLayoutDescriptor; > struct GPUBufferDescriptor; >@@ -53,12 +54,14 @@ struct GPUPipelineLayoutDescriptor; > struct GPURenderPipelineDescriptor; > struct GPURequestAdapterOptions; > struct GPUShaderModuleDescriptor; >+struct GPUTextureDescriptor; > > class GPUDevice : public RefCounted<GPUDevice> { > public: > 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; >diff --git a/Source/WebCore/platform/graphics/gpu/GPUTexture.h b/Source/WebCore/platform/graphics/gpu/GPUTexture.h >index 6953155a7a2b8912cf189cde62b8fee34295ad29..502b12bb8797705619936ab20d1fef778f5a4c32 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUTexture.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUTexture.h >@@ -35,11 +35,16 @@ OBJC_PROTOCOL(MTLTexture); > > 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(); } >diff --git a/Source/WebCore/platform/graphics/gpu/GPUUtils.h b/Source/WebCore/platform/graphics/gpu/GPUUtils.h >new file mode 100644 >index 0000000000000000000000000000000000000000..4705ab5a8d39425cd220f5814764c5e8dbb2f57f >--- /dev/null >+++ b/Source/WebCore/platform/graphics/gpu/GPUUtils.h >@@ -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) >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >index f48df41ad5ad5f169e740d14e3845ed2e88a3c63..15502e9cd6b6c53870ec6b3dadf2f88cc6300b9d 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >@@ -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 @@ void GPUSwapChain::setDevice(const GPUDevice& device) > [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 mtlResult = static_cast<MTLPixelFormat>(result.value()); >+ auto mtlFormat = static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(format)); > >- 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!"); >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >index 5cbc1f95b696416f2d63cd30c45d74ede45e1e6d..97e0084a2274290f356fb1ace0d33a261e11cbe8 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >@@ -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 (usage & MTLTextureUsageShaderWrite) >+ 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!"); >+ 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 @@ RefPtr<GPUTexture> GPUTexture::createDefaultTextureView() > { > 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; >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..e4b37021a39499beac831c80d43a235c29565413 >--- /dev/null >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm >@@ -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) >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index d8a3974fa6e6fe7036db860646699e9480f28fb3..21f6de6847a5407d437bb056d371b2406d6fe4c3 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,16 @@ >+2019-02-07 Justin Fan <justin_fan@apple.com> >+ >+ [Web GPU] GPUDevice::createTexture implementation prototype >+ https://bugs.webkit.org/show_bug.cgi?id=194409 >+ <rdar://problem/47894312> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-06 Justin Fan <justin_fan@apple.com> > > [Web GPU] Implement supporting dictionaries for GPUTexture >diff --git a/LayoutTests/webgpu/textures-textureviews-expected.txt b/LayoutTests/webgpu/textures-textureviews-expected.txt >index 6203cc181bd8e3862afa2dd78d550969457316a7..82e70d811865fb1d9ba7b0f80d5d87ca657c50fa 100644 >--- a/LayoutTests/webgpu/textures-textureviews-expected.txt >+++ b/LayoutTests/webgpu/textures-textureviews-expected.txt >@@ -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. > >diff --git a/LayoutTests/webgpu/textures-textureviews.html b/LayoutTests/webgpu/textures-textureviews.html >index 7ddb4ac964083b20653ad1f7dd909a540fd3d7b1..9726cb661321be19c853bb00745ef9971ef6ddea 100644 >--- a/LayoutTests/webgpu/textures-textureviews.html >+++ b/LayoutTests/webgpu/textures-textureviews.html >@@ -1,34 +1,66 @@ >-<!DOCTYPE html> >-<html> >-<script src="../resources/js-test-pre.js"></script> >-<script src="js/basic-webgpu-functions.js"></script> >+<!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="js/webgpu-functions.js"></script> >+<script src="../resources/testharness.js"></script> >+<script src="../resources/testharnessreport.js"></script> > <script> >-if (window.testRunner) >- window.testRunner.dumpAsText(); >- >-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 textureView = texture.createDefaultTextureView(); >- if (textureView) >- testPassed("Created default WebGPUTextureView from a WebGPUTexture"); >- else { >- testFailed("Could not create default WebGPUTextureView!"); >- return; >- } >-} >- >-// FIXME: Add tests for device.createTexture, WebGPUTextureDescriptor, and WebGPUTextureViewDescriptor. >- >-runWebGPUTests([setUpNextTextureView]); >- >-successfullyParsed = true; >+const canvas = document.querySelector("canvas"); >+let device, context; >+ >+let texSize = { >+ width: canvas.width, >+ height: canvas.height, >+ depth: 1 >+}; >+ >+let texDescriptor = { >+ size: texSize, >+ arrayLayerCount: 1, >+ mipLevelCount: 1, >+ sampleCount: 1, >+ dimension: "2d", >+ format: "d32-float-s8-uint", >+ usage: GPUTextureUsage.OUTPUT_ATTACHMENT >+}; >+ >+promise_test(async () => { >+ device = await getBasicDevice(); >+ context = createBasicContext(canvas, device); >+ >+ const texture = context.getNextTexture(); >+ assert_true(texture instanceof WebGPUTexture, "Successfully acquired next texture."); >+ >+ 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="../resources/js-test-post.js"></script> >+</body> > </html> >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 194409
:
361432
|
361438
|
361441
|
361474