Title: [238760] trunk
Revision
238760
Author
[email protected]
Date
2018-11-30 16:11:49 -0800 (Fri, 30 Nov 2018)

Log Message

[WebGPU] WebGPUQueue::submit and WebGPURenderingContext::present() implementation
https://bugs.webkit.org/show_bug.cgi?id=192254

Reviewed by Dean Jackson.

Source/WebCore:

Final plumbing to render onto an HTMLCanvasElement with WebGPU. Also added ref-test that draws
a green square onto a canvas using WebGPU; reference uses 2D canvas.

Test: webgpu/simple-triangle-strip.html

* Modules/webgpu/WebGPUCommandBuffer.h:
* Modules/webgpu/WebGPUSwapChain.h: Needs to override platformLayer() for CanvasBasedRenderingContext.
* platform/graphics/gpu/GPUQueue.h:
* platform/graphics/gpu/GPUSwapChain.h:
(WebCore::GPUSwapChain::metalLayer const): Renamed from platformLayer.
(WebCore::GPUSwapChain::platformLayer const): Deleted.
* platform/graphics/gpu/cocoa/GPUQueueMetal.mm:
(WebCore::GPUQueue::submit):
* platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm:
(WebCore::GPUSwapChain::getNextTexture): Returns the texture of the swap layer's next drawable.
(WebCore::GPUSwapChain::present): Presents the last-returned drawable from getNextTexture, and frees it.
(WebCore::GPUSwapChain::platformLayer const):

LayoutTests:

Update webgpu-basics to render an image into canvas. Also added ref-test that draws
a green square onto a canvas using WebGPU; reference uses 2D canvas.

* webgpu/js/basic-webgpu-functions.js:
(render):
* webgpu/simple-triangle-strip-expected.html: Added.
* webgpu/simple-triangle-strip.html: Added.
* webgpu/webgpu-basics.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (238759 => 238760)


--- trunk/LayoutTests/ChangeLog	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/LayoutTests/ChangeLog	2018-12-01 00:11:49 UTC (rev 238760)
@@ -1,3 +1,19 @@
+2018-11-30  Justin Fan  <[email protected]>
+
+        [WebGPU] WebGPUQueue::submit and WebGPURenderingContext::present() implementation
+        https://bugs.webkit.org/show_bug.cgi?id=192254
+
+        Reviewed by Dean Jackson.
+
+        Update webgpu-basics to render an image into canvas. Also added ref-test that draws 
+        a green square onto a canvas using WebGPU; reference uses 2D canvas.
+
+        * webgpu/js/basic-webgpu-functions.js:
+        (render):
+        * webgpu/simple-triangle-strip-expected.html: Added.
+        * webgpu/simple-triangle-strip.html: Added.
+        * webgpu/webgpu-basics.html:
+
 2018-11-30  Zalan Bujtas  <[email protected]>
 
         Can’t use RalphLauren.com on iPad because hover menus don’t stay up

Modified: trunk/LayoutTests/webgpu/js/basic-webgpu-functions.js (238759 => 238760)


--- trunk/LayoutTests/webgpu/js/basic-webgpu-functions.js	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/LayoutTests/webgpu/js/basic-webgpu-functions.js	2018-12-01 00:11:49 UTC (rev 238760)
@@ -140,7 +140,7 @@
     // FIXME: Default a loadOp, and storeOp in the implementation for now.
     const colorAttachmentDescriptor = {
         attachment : textureView,
-        clearColor : { r:0.35, g:0.65, b:0.85, a:1.0 }
+        clearColor : { r: 0.35, g: 0.65, b: 0.85, a: 1.0 }
     }
 
     let renderPassDescriptor = {
@@ -163,5 +163,12 @@
         return;
     }
 
-    // FIXME: Rest of rendering commands to follow.
+    const queue = defaultDevice.getQueue();
+    if (!queue) {
+        testFailed("Unable to create default WebGPUQueue!");
+        return;
+    }
+    queue.submit([commandBufferEnd]);
+
+    context.present();
 }
\ No newline at end of file

Added: trunk/LayoutTests/webgpu/simple-triangle-strip-expected.html (0 => 238760)


--- trunk/LayoutTests/webgpu/simple-triangle-strip-expected.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/simple-triangle-strip-expected.html	2018-12-01 00:11:49 UTC (rev 238760)
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>HTML Reference File</title>
+<p>Pass if square canvas below is completely green.</p>
+<canvas width="400" height="400"></canvas>
+<script>
+const canvas = document.querySelector("canvas");
+const context = canvas.getContext('2d');
+
+context.fillStyle = 'rgb(0, 255, 0)';
+context.fillRect(0, 0, canvas.width, canvas.height);
+</script>
\ No newline at end of file

Added: trunk/LayoutTests/webgpu/simple-triangle-strip.html (0 => 238760)


--- trunk/LayoutTests/webgpu/simple-triangle-strip.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/simple-triangle-strip.html	2018-12-01 00:11:49 UTC (rev 238760)
@@ -0,0 +1,112 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>WebGPU Hello Triangles</title>
+<meta name="assert" content="WebGPU correctly renders a green canvas.">
+<link rel="match" href=""
+<p>Pass if square canvas below is completely green.</p>
+<canvas width="400" height="400"></canvas>
+<script>
+const shaderCode = `
+#include <metal_stdlib>
+    
+using namespace metal;
+
+struct Vertex
+{
+    float4 position [[position]];
+};
+
+vertex Vertex vertex_main(uint vid [[vertex_id]])
+{
+    Vertex v;
+    switch (vid) {
+    case 0:
+        v.position = float4(-1, 1, 0, 1);
+        break;
+    case 1:
+        v.position = float4(-1, -1, 0, 1);
+        break;
+    case 2:
+        v.position = float4(1, 1, 0, 1);
+        break;
+    default:
+        v.position = float4(1, -1, 0, 1);
+    }
+    return v;
+}
+
+fragment float4 fragment_main(Vertex vertexIn [[stage_in]])
+{
+    return float4(0.0, 1.0, 0.0, 1.0);
+}
+`
+
+async function getBasicDevice() {
+    // FIXME: requestAdapter should take a WebGPUAdapterDescriptor.
+    const adapter = await window.webgpu.requestAdapter({});
+    const device = adapter.createDevice();
+    return device;
+}
+
+function createBasicContext(canvas, device) {
+    const context = canvas.getContext("webgpu");
+    // FIXME: Implement and specify a WebGPUTextureUsageEnum.
+    context.configure({ device: device, format:"B8G8R8A8Unorm", width: canvas.width, height: canvas.height });
+    return context;
+}
+
+function createBasicPipeline(shaderModule, device) {
+    vertexStageDescriptor = {
+        module: shaderModule, 
+        stage: WebGPUShaderStage.VERTEX, 
+        entryPoint: "vertex_main" 
+    };
+
+    fragmentStageDescriptor = {
+        module: shaderModule,
+        stage: WebGPUShaderStage.FRAGMENT,
+        entryPoint: "fragment_main"
+    };
+
+    pipelineDescriptor = {
+        stages: [vertexStageDescriptor, fragmentStageDescriptor],
+        primitiveTopology: "triangleStrip"
+    };
+
+    return device.createRenderPipeline(pipelineDescriptor);
+}
+
+function beginBasicRenderPass(context, commandBuffer) {
+    const basicAttachment = {
+        attachment: context.getNextTexture().createDefaultTextureView(),
+        clearColor: { r: 1.0, g: 0, b: 0, a: 1.0 }
+    }
+
+    // FIXME: Flesh out the rest of WebGPURenderPassDescriptor. 
+    return commandBuffer.beginRenderPass({ colorAttachments : [basicAttachment] });
+}
+
+function encodeBasicCommands(renderPassEncoder, renderPipeline) {
+    renderPassEncoder.setPipeline(renderPipeline);
+    renderPassEncoder.draw(4, 1, 0, 0);
+    return renderPassEncoder.endPass();
+}
+
+async function test() {
+    const device = await getBasicDevice();
+    const canvas = document.querySelector("canvas");
+    const context = createBasicContext(canvas, device);
+    // FIXME: Replace with non-MSL shaders.
+    const shaderModule = device.createShaderModule({ code: shaderCode });
+    const pipeline = createBasicPipeline(shaderModule, device);
+    const commandBuffer = device.createCommandBuffer();
+    const passEncoder = beginBasicRenderPass(context, commandBuffer);
+    const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline);
+    const queue = device.getQueue();
+
+    queue.submit([endCommandBuffer]);
+    context.present();
+}
+
+test();
+</script>
\ No newline at end of file

Modified: trunk/LayoutTests/webgpu/webgpu-basics.html (238759 => 238760)


--- trunk/LayoutTests/webgpu/webgpu-basics.html	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/LayoutTests/webgpu/webgpu-basics.html	2018-12-01 00:11:49 UTC (rev 238760)
@@ -1,14 +1,18 @@
 <!DOCTYPE html>
 <html>
+<head>
 <script src=""
 <script src=""
+<body>
+<canvas width="420" height="420"></canvas>
 <script>
 if (window.testRunner)
     window.testRunner.dumpAsText();
 
-runWebGPUTests([setUpPipeline, render]);
+runWebGPUTestsOnCanvas(document.querySelector("canvas"), [setUpPipeline, render]);
 
 successfullyParsed = true;
 </script>
 <script src=""
+</body>
 </html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (238759 => 238760)


--- trunk/Source/WebCore/ChangeLog	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/Source/WebCore/ChangeLog	2018-12-01 00:11:49 UTC (rev 238760)
@@ -1,3 +1,28 @@
+2018-11-30  Justin Fan  <[email protected]>
+
+        [WebGPU] WebGPUQueue::submit and WebGPURenderingContext::present() implementation
+        https://bugs.webkit.org/show_bug.cgi?id=192254
+
+        Reviewed by Dean Jackson.
+
+        Final plumbing to render onto an HTMLCanvasElement with WebGPU. Also added ref-test that draws 
+        a green square onto a canvas using WebGPU; reference uses 2D canvas.
+
+        Test: webgpu/simple-triangle-strip.html
+
+        * Modules/webgpu/WebGPUCommandBuffer.h:
+        * Modules/webgpu/WebGPUSwapChain.h: Needs to override platformLayer() for CanvasBasedRenderingContext.
+        * platform/graphics/gpu/GPUQueue.h:
+        * platform/graphics/gpu/GPUSwapChain.h:
+        (WebCore::GPUSwapChain::metalLayer const): Renamed from platformLayer. 
+        (WebCore::GPUSwapChain::platformLayer const): Deleted.
+        * platform/graphics/gpu/cocoa/GPUQueueMetal.mm:
+        (WebCore::GPUQueue::submit):
+        * platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm:
+        (WebCore::GPUSwapChain::getNextTexture): Returns the texture of the swap layer's next drawable. 
+        (WebCore::GPUSwapChain::present): Presents the last-returned drawable from getNextTexture, and frees it.
+        (WebCore::GPUSwapChain::platformLayer const):
+
 2018-11-30  Zalan Bujtas  <[email protected]>
 
         Can’t use RalphLauren.com on iPad because hover menus don’t stay up

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h (238759 => 238760)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h	2018-12-01 00:11:49 UTC (rev 238760)
@@ -27,6 +27,8 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPUCommandBuffer.h"
+
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -33,7 +35,6 @@
 
 namespace WebCore {
 
-class GPUCommandBuffer;
 class WebGPURenderPassEncoder;
 
 struct WebGPURenderPassDescriptor;
@@ -43,6 +44,7 @@
     static RefPtr<WebGPUCommandBuffer> create(RefPtr<GPUCommandBuffer>&&);
 
     const GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
+
     RefPtr<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
 
 private:

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.h (238759 => 238760)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.h	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.h	2018-12-01 00:11:49 UTC (rev 238760)
@@ -61,6 +61,7 @@
     }
 
     const char* activeDOMObjectName() const override { return "WebGPUSwapChain"; }
+    PlatformLayer* platformLayer() const final { return m_swapChain->platformLayer(); };
 
 private:
     // GPUBasedRenderingContext

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUQueue.h (238759 => 238760)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUQueue.h	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUQueue.h	2018-12-01 00:11:49 UTC (rev 238760)
@@ -30,6 +30,7 @@
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
+#include <wtf/Vector.h>
 
 OBJC_PROTOCOL(MTLCommandQueue);
 

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h (238759 => 238760)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h	2018-12-01 00:11:49 UTC (rev 238760)
@@ -30,7 +30,9 @@
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
 
+OBJC_CLASS CALayer;
 OBJC_CLASS CAMetalLayer;
+OBJC_PROTOCOL(CAMetalDrawable);
 
 namespace WebCore {
 
@@ -39,7 +41,8 @@
 
 enum class GPUTextureFormatEnum;
 
-using PlatformSwapLayer = CAMetalLayer;
+using PlatformDrawableSmartPtr = RetainPtr<CAMetalDrawable>;
+using PlatformLayer = CALayer;
 using PlatformSwapLayerSmartPtr = RetainPtr<CAMetalLayer>;
 
 class GPUSwapChain : public RefCounted<GPUSwapChain> {
@@ -52,12 +55,13 @@
     RefPtr<GPUTexture> getNextTexture();
     void present();
 
-    PlatformSwapLayer* platformLayer() const { return m_platformSwapLayer.get(); }
+    PlatformLayer* platformLayer() const;
 
 private:
     GPUSwapChain(PlatformSwapLayerSmartPtr&&);
 
     PlatformSwapLayerSmartPtr m_platformSwapLayer;
+    PlatformDrawableSmartPtr m_currentDrawable;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm (238759 => 238760)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm	2018-12-01 00:11:49 UTC (rev 238760)
@@ -28,6 +28,7 @@
 
 #if ENABLE(WEBGPU)
 
+#import "GPUCommandBuffer.h"
 #import "GPUDevice.h"
 #import "Logging.h"
 
@@ -69,9 +70,10 @@
 {
 }
 
-void GPUQueue::submit(Vector<Ref<const GPUCommandBuffer>>&&)
+void GPUQueue::submit(Vector<Ref<const GPUCommandBuffer>>&& buffers)
 {
-    // FIXME: Missing implementation.
+    for (auto& buffer : buffers)
+        [buffer->platformCommandBuffer() commit];
 }
 
 String GPUQueue::label() const

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm (238759 => 238760)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm	2018-12-01 00:08:50 UTC (rev 238759)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm	2018-12-01 00:11:49 UTC (rev 238760)
@@ -124,9 +124,13 @@
 {
     RetainPtr<MTLTexture> mtlTexture;
 
-    if (auto drawable = retainPtr([m_platformSwapLayer nextDrawable]))
-        mtlTexture = retainPtr([drawable texture]);
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
+    m_currentDrawable = retainPtr([m_platformSwapLayer nextDrawable]);
+    mtlTexture = retainPtr([m_currentDrawable texture]);
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+
     if (!mtlTexture) {
         LOG(WebGPU, "GPUSwapChain::getNextTexture(): Unable to get next MTLTexture!");
         return nullptr;
@@ -137,9 +141,15 @@
 
 void GPUSwapChain::present()
 {
-    // FIXME: Unimplemented stub.
+    [m_currentDrawable present];
+    m_currentDrawable = nullptr;
 }
 
+PlatformLayer* GPUSwapChain::platformLayer() const
+{
+    return m_platformSwapLayer.get();
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGPU)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to