<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[241181] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/241181">241181</a></dd>
<dt>Author</dt> <dd>justin_fan@apple.com</dd>
<dt>Date</dt> <dd>2019-02-07 18:01:39 -0800 (Thu, 07 Feb 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Web GPU] GPUDevice::createTexture implementation prototype
https://bugs.webkit.org/show_bug.cgi?id=194409
<rdar://problem/47894312>

Reviewed by Myles C. Maxfield.

Source/WebCore:

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.

LayoutTests:

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:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestswebgputexturestextureviewsexpectedtxt">trunk/LayoutTests/webgpu/textures-textureviews-expected.txt</a></li>
<li><a href="#trunkLayoutTestswebgputexturestextureviewshtml">trunk/LayoutTests/webgpu/textures-textureviews.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModuleswebgpuWebGPUDevicecpp">trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebgpuWebGPUDeviceh">trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h</a></li>
<li><a href="#trunkSourceWebCoreModuleswebgpuWebGPUDeviceidl">trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl</a></li>
<li><a href="#trunkSourceWebCoreModuleswebgpuWebGPUTexturecpp">trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp</a></li>
<li><a href="#trunkSourceWebCoreModuleswebgpuWebGPUTextureh">trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h</a></li>
<li><a href="#trunkSourceWebCoreSourcesCocoatxt">trunk/Source/WebCore/SourcesCocoa.txt</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgpuGPUDevicecpp">trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgpuGPUDeviceh">trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgpuGPUTextureh">trunk/Source/WebCore/platform/graphics/gpu/GPUTexture.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgpucocoaGPUSwapChainMetalmm">trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgpucocoaGPUTextureMetalmm">trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgraphicsgpuGPUUtilsh">trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgpucocoaGPUUtilsMetalmm">trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2019-02-08 01:45:42 UTC (rev 241180)
+++ trunk/LayoutTests/ChangeLog 2019-02-08 02:01:39 UTC (rev 241181)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+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 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:
+
</ins><span class="cx"> 2019-02-07  Shawn Roberts  <sroberts@apple.com>
</span><span class="cx"> 
</span><span class="cx">         fast/hidpi/hidpi-long-page-with-inset-element.html is a flaky image failure
</span></span></pre></div>
<a id="trunkLayoutTestswebgputexturestextureviewsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/webgpu/textures-textureviews-expected.txt (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,8 +1,6 @@
</span><del>-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
</del><span class="cx"> 
</span><del>-TEST COMPLETE
</del><ins>+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. 
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestswebgputexturestextureviewshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/webgpu/textures-textureviews.html (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,34 +1,66 @@
</span><del>-<!DOCTYPE html>
-<html>
-<script src="../resources/js-test-pre.js"></script>
-<script src="js/basic-webgpu-functions.js"></script>
</del><ins>+<!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>
</ins><span class="cx"> <script>
</span><del>-if (window.testRunner)
-    window.testRunner.dumpAsText();
</del><ins>+const canvas = document.querySelector("canvas");    
+let device, context;
</ins><span class="cx"> 
</span><del>-function setUpNextTextureView() {
-    let texture = context.getNextTexture();
-    if (texture)
-        testPassed("Acquired next WebGPUTexture from WebGPURenderingContext.");
-    else {
-        testFailed("Could not get next WebGPUTexture from WebGPURenderingContext!");
-        return;
-    }
</del><ins>+let texSize = {
+    width: canvas.width,
+    height: canvas.height,
+    depth: 1
+};
</ins><span class="cx"> 
</span><del>-    let textureView = texture.createDefaultTextureView();
-    if (textureView) 
-        testPassed("Created default WebGPUTextureView from a WebGPUTexture");
-    else {
-        testFailed("Could not create default WebGPUTextureView!");
-        return;
-    }
-}
</del><ins>+let texDescriptor = {
+    size: texSize,
+    arrayLayerCount: 1,
+    mipLevelCount: 1,
+    sampleCount: 1,
+    dimension: "2d",
+    format: "d32-float-s8-uint",
+    usage: GPUTextureUsage.OUTPUT_ATTACHMENT
+};
</ins><span class="cx"> 
</span><del>-// FIXME: Add tests for device.createTexture, WebGPUTextureDescriptor, and WebGPUTextureViewDescriptor.
</del><ins>+promise_test(async () => {
+    device = await getBasicDevice();
+    context = createBasicContext(canvas, device);
</ins><span class="cx"> 
</span><del>-runWebGPUTests([setUpNextTextureView]);
</del><ins>+    const texture = context.getNextTexture();
+    assert_true(texture instanceof WebGPUTexture, "Successfully acquired next texture.");
</ins><span class="cx"> 
</span><del>-successfullyParsed = true;
</del><ins>+    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.
</ins><span class="cx"> </script>
</span><del>-<script src="../resources/js-test-post.js"></script>
</del><ins>+</body>
</ins><span class="cx"> </html>
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,46 @@
</span><ins>+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 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.
+
</ins><span class="cx"> 2019-02-07  Sihui Liu  <sihui_liu@apple.com>
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r239887): Crash under IDBConnectionToClient::didDeleteDatabase(WebCore::IDBResultData const&)
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebgpuWebGPUDevicecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> #include "GPUPipelineStageDescriptor.h"
</span><span class="cx"> #include "GPURenderPipelineDescriptor.h"
</span><span class="cx"> #include "GPUShaderModuleDescriptor.h"
</span><ins>+#include "GPUTextureDescriptor.h"
</ins><span class="cx"> #include "Logging.h"
</span><span class="cx"> #include "WebGPUBindGroup.h"
</span><span class="cx"> #include "WebGPUBindGroupBinding.h"
</span><span class="lines">@@ -52,6 +53,7 @@
</span><span class="cx"> #include "WebGPURenderPipelineDescriptor.h"
</span><span class="cx"> #include "WebGPUShaderModule.h"
</span><span class="cx"> #include "WebGPUShaderModuleDescriptor.h"
</span><ins>+#include "WebGPUTexture.h"
</ins><span class="cx"> #include <wtf/Variant.h>
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -78,6 +80,12 @@
</span><span class="cx">     return nullptr;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Ref<WebGPUTexture> WebGPUDevice::createTexture(GPUTextureDescriptor&& descriptor) const
+{
+    auto texture = m_device->tryCreateTexture(WTFMove(descriptor));
+    return WebGPUTexture::create(WTFMove(texture));
+}
+
</ins><span class="cx"> Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&& descriptor) const
</span><span class="cx"> {
</span><span class="cx">     auto layout = m_device->tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor { descriptor.bindings });
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebgpuWebGPUDeviceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -47,7 +47,9 @@
</span><span class="cx"> class WebGPUPipelineLayout;
</span><span class="cx"> class WebGPURenderPipeline;
</span><span class="cx"> class WebGPUShaderModule;
</span><ins>+class WebGPUTexture;
</ins><span class="cx"> 
</span><ins>+struct GPUTextureDescriptor;
</ins><span class="cx"> struct WebGPUBindGroupDescriptor;
</span><span class="cx"> struct WebGPUPipelineLayoutDescriptor;
</span><span class="cx"> struct WebGPURenderPipelineDescriptor;
</span><span class="lines">@@ -61,6 +63,7 @@
</span><span class="cx">     const GPUDevice& device() const { return m_device.get(); }
</span><span class="cx"> 
</span><span class="cx">     RefPtr<WebGPUBuffer> createBuffer(WebGPUBufferDescriptor&&) const;
</span><ins>+    Ref<WebGPUTexture> createTexture(GPUTextureDescriptor&&) const;
</ins><span class="cx"> 
</span><span class="cx">     Ref<WebGPUBindGroupLayout> createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&&) const;
</span><span class="cx">     Ref<WebGPUPipelineLayout> createPipelineLayout(WebGPUPipelineLayoutDescriptor&&) const;
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebgpuWebGPUDeviceidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx">     readonly attribute WebGPUAdapter adapter;
</span><span class="cx"> 
</span><span class="cx">     WebGPUBuffer createBuffer(WebGPUBufferDescriptor descriptor);
</span><ins>+    WebGPUTexture createTexture(GPUTextureDescriptor descriptor);
</ins><span class="cx"> 
</span><span class="cx">     WebGPUBindGroupLayout createBindGroupLayout(WebGPUBindGroupLayoutDescriptor descriptor);
</span><span class="cx">     WebGPUPipelineLayout createPipelineLayout(WebGPUPipelineLayoutDescriptor descriptor);
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebgpuWebGPUTexturecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -32,12 +32,12 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-RefPtr<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture)
</del><ins>+Ref<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture)
</ins><span class="cx"> {
</span><del>-    return texture ? adoptRef(new WebGPUTexture(texture.releaseNonNull())) : nullptr;
</del><ins>+    return adoptRef(*new WebGPUTexture(WTFMove(texture)));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-WebGPUTexture::WebGPUTexture(Ref<GPUTexture>&& texture)
</del><ins>+WebGPUTexture::WebGPUTexture(RefPtr<GPUTexture>&& texture)
</ins><span class="cx">     : m_texture(WTFMove(texture))
</span><span class="cx"> {
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreModuleswebgpuWebGPUTextureh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -38,14 +38,14 @@
</span><span class="cx"> 
</span><span class="cx"> class WebGPUTexture : public RefCounted<WebGPUTexture> {
</span><span class="cx"> public:
</span><del>-    static RefPtr<WebGPUTexture> create(RefPtr<GPUTexture>&&);
</del><ins>+    static Ref<WebGPUTexture> create(RefPtr<GPUTexture>&&);
</ins><span class="cx"> 
</span><span class="cx">     RefPtr<WebGPUTextureView> createDefaultTextureView();
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    explicit WebGPUTexture(Ref<GPUTexture>&&);
</del><ins>+    explicit WebGPUTexture(RefPtr<GPUTexture>&&);
</ins><span class="cx"> 
</span><del>-    Ref<GPUTexture> m_texture;
</del><ins>+    RefPtr<GPUTexture> m_texture;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreSourcesCocoatxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/SourcesCocoa.txt (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -331,6 +331,7 @@
</span><span class="cx"> platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm
</span><span class="cx"> platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm
</span><span class="cx"> platform/graphics/gpu/cocoa/GPUTextureMetal.mm
</span><ins>+platform/graphics/gpu/cocoa/GPUUtilsMetal.mm
</ins><span class="cx"> platform/graphics/gpu/Texture.cpp
</span><span class="cx"> platform/graphics/gpu/TilingData.cpp
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -14066,6 +14066,8 @@
</span><span class="cx">          D06A9A2122026C7A0083C662 /* GPURequestAdapterOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPURequestAdapterOptions.h; sourceTree = "<group>"; };
</span><span class="cx">          D06C0D8D0CFD11460065F43F /* RemoveFormatCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoveFormatCommand.h; sourceTree = "<group>"; };
</span><span class="cx">          D06C0D8E0CFD11460065F43F /* RemoveFormatCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoveFormatCommand.cpp; sourceTree = "<group>"; };
</span><ins>+               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>"; };
</ins><span class="cx">           D07DEAB70A36554A00CA30F8 /* InsertListCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InsertListCommand.cpp; sourceTree = "<group>"; };
</span><span class="cx">          D07DEAB80A36554A00CA30F8 /* InsertListCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InsertListCommand.h; sourceTree = "<group>"; };
</span><span class="cx">          D083D98421C48050008E8EFF /* GPUBindGroupLayoutDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutDescriptor.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -18503,6 +18505,7 @@
</span><span class="cx">                          D026F486220A505900AC5F49 /* GPUTextureDimension.h */,
</span><span class="cx">                          312FF8C321A4C2F300EB199D /* GPUTextureFormat.h */,
</span><span class="cx">                          D026F485220A477200AC5F49 /* GPUTextureUsage.h */,
</span><ins>+                               D06EF552220BA26A0018724E /* GPUUtils.h */,
</ins><span class="cx">                           D0D8649B21BA1C2D003C983C /* GPUVertexAttributeDescriptor.h */,
</span><span class="cx">                          D0D8649C21BA1CE8003C983C /* GPUVertexInputDescriptor.h */,
</span><span class="cx">                          498770D71242C535002226BA /* Texture.cpp */,
</span><span class="lines">@@ -26188,6 +26191,7 @@
</span><span class="cx">                          D087CE4021ACA94200BDE174 /* GPUShaderModuleMetal.mm */,
</span><span class="cx">                          D087CE3E21ACA94200BDE174 /* GPUSwapChainMetal.mm */,
</span><span class="cx">                          D087CE3F21ACA94200BDE174 /* GPUTextureMetal.mm */,
</span><ins>+                               D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */,
</ins><span class="cx">                   );
</span><span class="cx">                  path = cocoa;
</span><span class="cx">                  sourceTree = "<group>";
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgpuGPUDevicecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -39,6 +39,8 @@
</span><span class="cx"> #include "GPURenderPipelineDescriptor.h"
</span><span class="cx"> #include "GPUShaderModule.h"
</span><span class="cx"> #include "GPUShaderModuleDescriptor.h"
</span><ins>+#include "GPUTexture.h"
+#include "GPUTextureDescriptor.h"
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -47,6 +49,11 @@
</span><span class="cx">     return GPUBuffer::create(*this, WTFMove(descriptor));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr<GPUTexture> GPUDevice::tryCreateTexture(GPUTextureDescriptor&& descriptor) const
+{
+    return GPUTexture::tryCreate(*this, WTFMove(descriptor));
+}
+
</ins><span class="cx"> RefPtr<GPUBindGroupLayout> GPUDevice::tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&& descriptor) const
</span><span class="cx"> {
</span><span class="cx">     return GPUBindGroupLayout::tryCreate(*this, WTFMove(descriptor));
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgpuGPUDeviceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx"> class GPUPipelineLayout;
</span><span class="cx"> class GPURenderPipeline;
</span><span class="cx"> class GPUShaderModule;
</span><ins>+class GPUTexture;
</ins><span class="cx"> 
</span><span class="cx"> struct GPUBindGroupLayoutDescriptor;
</span><span class="cx"> struct GPUBufferDescriptor;
</span><span class="lines">@@ -53,6 +54,7 @@
</span><span class="cx"> struct GPURenderPipelineDescriptor;
</span><span class="cx"> struct GPURequestAdapterOptions;
</span><span class="cx"> struct GPUShaderModuleDescriptor;
</span><ins>+struct GPUTextureDescriptor;
</ins><span class="cx"> 
</span><span class="cx"> class GPUDevice : public RefCounted<GPUDevice> {
</span><span class="cx"> public:
</span><span class="lines">@@ -59,6 +61,7 @@
</span><span class="cx">     static RefPtr<GPUDevice> create(Optional<GPURequestAdapterOptions>&&);
</span><span class="cx"> 
</span><span class="cx">     RefPtr<GPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
</span><ins>+    RefPtr<GPUTexture> tryCreateTexture(GPUTextureDescriptor&&) const;
</ins><span class="cx"> 
</span><span class="cx">     RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&&) const;
</span><span class="cx">     Ref<GPUPipelineLayout> createPipelineLayout(GPUPipelineLayoutDescriptor&&) const;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgpuGPUTextureh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUTexture.h (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -35,11 +35,16 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+class GPUDevice;
+
+struct GPUTextureDescriptor;
+
</ins><span class="cx"> using PlatformTexture = MTLTexture;
</span><span class="cx"> using PlatformTextureSmartPtr = RetainPtr<MTLTexture>;
</span><span class="cx"> 
</span><span class="cx"> class GPUTexture : public RefCounted<GPUTexture> {
</span><span class="cx"> public:
</span><ins>+    static RefPtr<GPUTexture> tryCreate(const GPUDevice&, GPUTextureDescriptor&&);
</ins><span class="cx">     static Ref<GPUTexture> create(PlatformTextureSmartPtr&&);
</span><span class="cx"> 
</span><span class="cx">     PlatformTexture *platformTexture() const { return m_platformTexture.get(); }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgpuGPUUtilshfromrev241180trunkSourceWebCoreModuleswebgpuWebGPUTextureh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h (from rev 241180, trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h) (0 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,38 @@
</span><ins>+/*
+ * 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)
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgpucocoaGPUSwapChainMetalmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -31,9 +31,9 @@
</span><span class="cx"> #import "GPUDevice.h"
</span><span class="cx"> #import "GPUTexture.h"
</span><span class="cx"> #import "GPUTextureFormat.h"
</span><ins>+#import "GPUUtils.h"
</ins><span class="cx"> #import "Logging.h"
</span><span class="cx"> #import "WebGPULayer.h"
</span><del>-
</del><span class="cx"> #import <Metal/Metal.h>
</span><span class="cx"> #import <QuartzCore/QuartzCore.h>
</span><span class="cx"> #import <wtf/BlockObjCExceptions.h>
</span><span class="lines">@@ -80,36 +80,15 @@
</span><span class="cx">     [m_platformSwapLayer setDevice:device.platformDevice()];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-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;
-    }
-}
-
</del><span class="cx"> void GPUSwapChain::setFormat(GPUTextureFormat format)
</span><span class="cx"> {
</span><del>-    auto result = platformTextureFormatForGPUTextureFormat(format);
-    if (!result)
-        return;
</del><ins>+    auto mtlFormat = static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(format));
</ins><span class="cx"> 
</span><del>-    auto mtlResult = static_cast<MTLPixelFormat>(result.value());
-
-    switch (mtlResult) {
</del><ins>+    switch (mtlFormat) {
</ins><span class="cx">     case MTLPixelFormatBGRA8Unorm:
</span><span class="cx">     // FIXME: Add the other supported swap layer formats as they are added to GPU spec.
</span><span class="cx">     //  MTLPixelFormatBGRA8Unorm_sRGB, MTLPixelFormatRGBA16Float, MTLPixelFormatBGRA10_XR, and MTLPixelFormatBGRA10_XR_sRGB.
</span><del>-        [m_platformSwapLayer setPixelFormat:mtlResult];
</del><ins>+        [m_platformSwapLayer setPixelFormat:mtlFormat];
</ins><span class="cx">         return;
</span><span class="cx">     default:
</span><span class="cx">         LOG(WebGPU, "GPUSwapChain::setFormat(): Unsupported MTLPixelFormat!");
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgpucocoaGPUTextureMetalmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm (241180 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -28,13 +28,140 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WEBGPU)
</span><span class="cx"> 
</span><ins>+#import "GPUDevice.h"
+#import "GPUTextureDescriptor.h"
+#import "GPUUtils.h"
</ins><span class="cx"> #import "Logging.h"
</span><del>-
</del><span class="cx"> #import <Metal/Metal.h>
</span><span class="cx"> #import <wtf/BlockObjCExceptions.h>
</span><ins>+#import <wtf/Optional.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+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)));
+}
+
</ins><span class="cx"> Ref<GPUTexture> GPUTexture::create(PlatformTextureSmartPtr&& texture)
</span><span class="cx"> {
</span><span class="cx">     return adoptRef(*new GPUTexture(WTFMove(texture)));
</span><span class="lines">@@ -49,8 +176,12 @@
</span><span class="cx"> {
</span><span class="cx">     RetainPtr<MTLTexture> texture;
</span><span class="cx"> 
</span><ins>+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
</ins><span class="cx">     texture = adoptNS([m_platformTexture newTextureViewWithPixelFormat:m_platformTexture.get().pixelFormat]);
</span><span class="cx"> 
</span><ins>+    END_BLOCK_OBJC_EXCEPTIONS;
+
</ins><span class="cx">     if (!texture) {
</span><span class="cx">         LOG(WebGPU, "GPUTexture::createDefaultTextureView(): Unable to create MTLTexture view!");
</span><span class="cx">         return nullptr;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsgpucocoaGPUUtilsMetalmmfromrev241180trunkSourceWebCoreModuleswebgpuWebGPUTextureh"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm (from rev 241180, trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h) (0 => 241181)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,51 @@
</span><ins>+/*
+ * 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)
</ins></span></pre>
</div>
</div>

</body>
</html>