WebKit Bugzilla
Attachment 356238 Details for
Bug 192254
: [WebGPU] WebGPUQueue::submit and WebGPURenderingContext::present() implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-192254-20181130142618.patch (text/plain), 13.93 KB, created by
Justin Fan
on 2018-11-30 14:26:19 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Justin Fan
Created:
2018-11-30 14:26:19 PST
Size:
13.93 KB
patch
obsolete
>Subversion Revision: 238749 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 6d0e66e4ce457d358d791534ccf6eda63deba239..a58486e9a5148300d8ac47c9c7460ae969c9e82c 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,28 @@ >+2018-11-30 Justin Fan <justin_fan@apple.com> >+ >+ [WebGPU] WebGPUQueue::submit and WebGPURenderingContext::present() implementation >+ https://bugs.webkit.org/show_bug.cgi?id=192254 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-29 Ryosuke Niwa <rniwa@webkit.org> > > Add CEReactions=NotNeeded on all the relevant IDL files >diff --git a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h b/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h >index 48d63eeaf0c6f2c8ddb1fd26772ee521d0f46dc4..6d26aeaee23063efd87cc54dfac1b10aafef4816 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h >@@ -27,13 +27,14 @@ > > #if ENABLE(WEBGPU) > >+#include "GPUCommandBuffer.h" >+ > #include <wtf/Ref.h> > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> > > namespace WebCore { > >-class GPUCommandBuffer; > class WebGPURenderPassEncoder; > > struct WebGPURenderPassDescriptor; >@@ -43,6 +44,7 @@ public: > static RefPtr<WebGPUCommandBuffer> create(RefPtr<GPUCommandBuffer>&&); > > const GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); } >+ > RefPtr<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&); > > private: >diff --git a/Source/WebCore/Modules/webgpu/WebGPUSwapChain.h b/Source/WebCore/Modules/webgpu/WebGPUSwapChain.h >index b4724a4b16e8977b825af791003ecc727d0e4027..ccae75e55dca8488fbbe2ca7509615ee88e9e164 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUSwapChain.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUSwapChain.h >@@ -61,6 +61,7 @@ protected: > } > > const char* activeDOMObjectName() const override { return "WebGPUSwapChain"; } >+ PlatformLayer* platformLayer() const final { return m_swapChain->platformLayer(); }; > > private: > // GPUBasedRenderingContext >diff --git a/Source/WebCore/platform/graphics/gpu/GPUQueue.h b/Source/WebCore/platform/graphics/gpu/GPUQueue.h >index cafcfc7a96334c037bd47fdd1c4e27c6552f4e0a..a314b0af1c24437c0dafdd44e21e4945216437ce 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUQueue.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUQueue.h >@@ -30,6 +30,7 @@ > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> > #include <wtf/RetainPtr.h> >+#include <wtf/Vector.h> > > OBJC_PROTOCOL(MTLCommandQueue); > >diff --git a/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h b/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h >index c48c101442596808602cc92ade216b6bc1fd4662..ad1893d1690e90b74b9a8881e6676dd15d9d01ba 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUSwapChain.h >@@ -31,6 +31,7 @@ > #include <wtf/RetainPtr.h> > > OBJC_CLASS CAMetalLayer; >+OBJC_PROTOCOL(CAMetalDrawable); > > namespace WebCore { > >@@ -39,7 +40,7 @@ class GPUTexture; > > enum class GPUTextureFormatEnum; > >-using PlatformSwapLayer = CAMetalLayer; >+using PlatformDrawableSmartPtr = RetainPtr<CAMetalDrawable>; > using PlatformSwapLayerSmartPtr = RetainPtr<CAMetalLayer>; > > class GPUSwapChain : public RefCounted<GPUSwapChain> { >@@ -52,12 +53,14 @@ public: > RefPtr<GPUTexture> getNextTexture(); > void present(); > >- PlatformSwapLayer* platformLayer() const { return m_platformSwapLayer.get(); } >+ CAMetalLayer *metalLayer() const { return m_platformSwapLayer.get(); } >+ CALayer *platformLayer() const; > > private: > GPUSwapChain(PlatformSwapLayerSmartPtr&&); > > PlatformSwapLayerSmartPtr m_platformSwapLayer; >+ PlatformDrawableSmartPtr m_currentDrawable; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >index a75a67739105480ae384f301acbf755bb5494c85..d030a34d74364383ec3af0f4efe2a400fdafa324 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >@@ -28,6 +28,7 @@ > > #if ENABLE(WEBGPU) > >+#import "GPUCommandBuffer.h" > #import "GPUDevice.h" > #import "Logging.h" > >@@ -69,9 +70,10 @@ GPUQueue::GPUQueue(PlatformQueueSmartPtr&& queue) > { > } > >-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 >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >index 9bbc0c7aced47054ea432f9fe73960a24a480154..f8cb0d934cf865d2126ed8c7aa400976bff07a6d 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >@@ -124,8 +124,12 @@ RefPtr<GPUTexture> GPUSwapChain::getNextTexture() > { > 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!"); >@@ -137,7 +141,13 @@ RefPtr<GPUTexture> GPUSwapChain::getNextTexture() > > void GPUSwapChain::present() > { >- // FIXME: Unimplemented stub. >+ [m_currentDrawable present]; >+ m_currentDrawable = nullptr; >+} >+ >+CALayer *GPUSwapChain::platformLayer() const >+{ >+ return m_platformSwapLayer.get(); > } > > } // namespace WebCore >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 5bd3cfc9e44e636ad554deb4b6680bc97c134aef..48e334d331bfe9e166adcd27f8b6aaccd6df5bdb 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,19 @@ >+2018-11-30 Justin Fan <justin_fan@apple.com> >+ >+ [WebGPU] WebGPUQueue::submit and WebGPURenderingContext::present() implementation >+ https://bugs.webkit.org/show_bug.cgi?id=192254 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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 Devin Rousso <drousso@apple.com> > > Web Inspector: replace all unicode characters with the escaped character code >diff --git a/LayoutTests/webgpu/js/basic-webgpu-functions.js b/LayoutTests/webgpu/js/basic-webgpu-functions.js >index a996212d306e250c43d14f22c56858a661580acb..b3cbbc21bd49c281e2a0a9f0f11d5a3a20470141 100644 >--- a/LayoutTests/webgpu/js/basic-webgpu-functions.js >+++ b/LayoutTests/webgpu/js/basic-webgpu-functions.js >@@ -140,7 +140,7 @@ function render() { > // 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 @@ function render() { > 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 >diff --git a/LayoutTests/webgpu/simple-triangle-strip-expected.html b/LayoutTests/webgpu/simple-triangle-strip-expected.html >new file mode 100644 >index 0000000000000000000000000000000000000000..886f13e8120397a5cc6336c9e2a485e778ba9932 >--- /dev/null >+++ b/LayoutTests/webgpu/simple-triangle-strip-expected.html >@@ -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 >diff --git a/LayoutTests/webgpu/simple-triangle-strip.html b/LayoutTests/webgpu/simple-triangle-strip.html >new file mode 100644 >index 0000000000000000000000000000000000000000..d76ffddd9a54f572f0250ec74d0f6173b5c57d6b >--- /dev/null >+++ b/LayoutTests/webgpu/simple-triangle-strip.html >@@ -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="simple-triangle-strip-expected.html"> >+<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 >diff --git a/LayoutTests/webgpu/webgpu-basics.html b/LayoutTests/webgpu/webgpu-basics.html >index d547c829c63114306cf2d37c858f972e12012a27..c1f666b7ab984f85ec2c54aa5da0b51f35a628b1 100644 >--- a/LayoutTests/webgpu/webgpu-basics.html >+++ b/LayoutTests/webgpu/webgpu-basics.html >@@ -1,14 +1,18 @@ > <!DOCTYPE html> > <html> >+<head> > <script src="../resources/js-test-pre.js"></script> > <script src="js/basic-webgpu-functions.js"></script> >+<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="../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 192254
:
356238
|
356248