+2018-11-19 Justin Fan <justin_fan@apple.com>
+
+ [WebGPU] Begin implementing WebGPUTexture, WebGPUTextureView, and WebGPUTextureFormatEnum, and WebGPUSwapChain::configure upgrades
+ https://bugs.webkit.org/show_bug.cgi?id=191794
+
+ Reviewed by Dean Jackson.
+
+ Did some refactoring to better share code among tests, and added basic functionality test for
+ WebGPUTextures and WebGPUTextureView, to be fleshed out when their descriptor objects are implemented.
+
+ * webgpu/command-buffers.html: Refactored to use basic-webgpu-functions.js.
+ * webgpu/js/basic-webgpu-functions.js: Added.
+ (vertex.Vertex.vertex_main): The basic MSL code has been moved into this file.
+ (fragment.float4.fragment_main):
+ (runWebGPUTests): Creates a WebGPURenderingContext on a default canvas and runs its provided functions.
+ (async.runWebGPUTestsOnCanvas):
+ (async.setUpContexts): Tests proper creation of a basic WebGPURenderingContext.
+ (setUpModule): Creates a basic WebGPUShaderModule.
+ (setUpPipelineDescriptor): Creates a basic WebGPURenderPipelineDescriptor.
+ (setUpPipeline): Creates a basic WebGPURenderPipeline.
+ (render):
+ * webgpu/js/set-up-webgpu-contexts.js: Moved into basic-webgpu-functions.js.
+ * webgpu/render-pipelines-expected.txt:
+ * webgpu/render-pipelines.html: Refactored to use basic-webgpu-functions.js.
+ * webgpu/shader-modules.html: Refactored to use basic-webgpu-functions.js.
+ * webgpu/textures-textureviews-expected.txt: Added.
+ * webgpu/textures-textureviews.html: Added.
+ * webgpu/webgpu-basics.html: Refactored to use basic-webgpu-functions.js.
+
2018-11-19 Wenson Hsieh <wenson_hsieh@apple.com>
Dragging image with a border-image larger than the image element crashes
<!DOCTYPE html>
<html>
<script src="../resources/js-test-pre.js"></script>
-<script src="js/set-up-webgpu-contexts.js"></script>
+<script src="js/basic-webgpu-functions.js"></script>
<script>
if (window.testRunner)
window.testRunner.dumpAsText();
--- /dev/null
+let 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(-.75, -.75, 0, 1);
+ break;
+ case 1:
+ v.position = float4(.75, -.75, 0, 1);
+ break;
+ case 2:
+ v.position = float4(0, .75, 0, 1);
+ break;
+ default:
+ v.position = float4(0, 0, 0, 1);
+ }
+ return v;
+}
+
+fragment float4 fragment_main(Vertex vertexIn [[stage_in]])
+{
+ return float4(1.0, 0.0, 0.0, 1.0);
+}
+`
+
+let context, adapter, defaultDevice;
+
+function runWebGPUTests(tests) {
+ runWebGPUTestsOnCanvas(document.createElement("canvas"), tests);
+}
+
+async function runWebGPUTestsOnCanvas(canvas, tests) {
+ try {
+ await setUpContexts(canvas);
+
+ for (let test of tests)
+ test();
+
+ debug("All tests complete.");
+ } catch (error) {
+ console.error(error);
+ testFailed(`[${error}]: See console!`);
+ }
+}
+
+async function setUpContexts(canvas) {
+ context = canvas.getContext("webgpu");
+ if (!context)
+ testFailed("Could not create WebGPU context!");
+
+ shouldBeDefined(window.webgpu);
+
+ // FIXME: requestAdapter should take a WebGPUAdapterDescriptor.
+ adapter = await window.webgpu.requestAdapter({});
+ if (!adapter) {
+ testFailed("Could not create default WebGPUAdapter!")
+ return;
+ }
+
+ // FIXME: requestDevice should take a WebGPUDeviceDescriptor.
+ defaultDevice = adapter.createDevice();
+ if (!defaultDevice) {
+ testFailed("Could not create WebGPUDevice!");
+ return;
+ }
+
+ // FIXME: Implement WebGPUTextureUsageEnum.
+ context.configure({ device: defaultDevice, format:"B8G8R8A8Unorm", width: canvas.width, height: canvas.height });
+}
+
+let shaderModule, vertexStageDescriptor, fragmentStageDescriptor, pipelineDescriptor, renderPipeline;
+
+function setUpModule() {
+ shaderModule = defaultDevice.createShaderModule({ code: shaderCode });
+ if (!shaderModule) {
+ testFailed("Could not create WebGPUShaderModule!");
+ return;
+ }
+}
+
+function setUpPipelineDescriptor() {
+ vertexStageDescriptor = {
+ module: shaderModule,
+ stage: WebGPUShaderStage.VERTEX,
+ entryPoint: "vertex_main"
+ };
+
+ fragmentStageDescriptor = {
+ module: shaderModule,
+ stage: WebGPUShaderStage.FRAGMENT,
+ entryPoint: "fragment_main"
+ };
+
+ pipelineDescriptor = {
+ stages: [vertexStageDescriptor, fragmentStageDescriptor],
+ primitiveTopology: "triangleList"
+ };
+}
+
+function setUpPipeline() {
+ setUpModule();
+ setUpPipelineDescriptor();
+
+ renderPipeline = defaultDevice.createRenderPipeline(pipelineDescriptor);
+ if (!renderPipeline) {
+ testFailed("Could not create WebGPURenderPipeline!");
+ return;
+ }
+}
+
+function render() {
+ let commandBuffer = defaultDevice.createCommandBuffer();
+ if (!commandBuffer) {
+ testFailed("Could not create WebGPUCommandBuffer!");
+ return;
+ }
+
+ let texture = context.getNextTexture();
+ if (!texture) {
+ testFailed("Could not get next WebGPUTexture!");
+ return;
+ }
+
+ let textureView = texture.createDefaultTextureView();
+ if (!textureView) {
+ testFailed("Could not create WebGPUTextureView!");
+ return;
+ }
+
+ // FIXME: Rest of rendering commands to follow.
+}
\ No newline at end of file
+++ /dev/null
-'use strict';
-
-let context, adapter, defaultDevice;
-
-function runWebGPUTests(tests) {
- runWebGPUTestsOnCanvas(document.createElement("canvas"), tests);
-}
-
-async function runWebGPUTestsOnCanvas(canvas, tests) {
- try {
- await setUpContexts(canvas);
-
- for (let test of tests)
- test();
-
- debug("All tests complete.");
- } catch (error) {
- console.error(error);
- testFailed(`[${error}]: See console!`);
- }
-}
-
-async function setUpContexts(canvas) {
- context = canvas.getContext("webgpu");
- if (!context)
- testFailed("Could not create WebGPU context!");
-
- shouldBeDefined(window.webgpu);
-
- // FIXME: requestAdapter should take a WebGPUAdapterDescriptor.
- adapter = await window.webgpu.requestAdapter({});
- if (!adapter) {
- testFailed("Could not create default WebGPUAdapter!")
- return;
- }
-
- // FIXME: requestDevice should take a WebGPUDeviceDescriptor.
- defaultDevice = adapter.createDevice();
- if (!defaultDevice) {
- testFailed("Could not create WebGPUDevice!");
- return;
- }
-
- // FIXME: Default to "B8G8R8A8Unorm" format for now.
- context.configure({ device: defaultDevice, width: canvas.width, height: canvas.height });
-}
\ No newline at end of file
PASS [object WebGPU] is defined.
-PASS Successfully created WebGPURenderPipeline.
PASS WebGPURenderPipeline with invalid WebGPURenderPipelineDescriptor was not created.
PASS WebGPURenderPipeline with invalid shader module was not created.
PASS WebGPURenderPipeline with invalid vertex shader stage was not created.
<!DOCTYPE html>
<html>
<script src="../resources/js-test-pre.js"></script>
-<script src="js/set-up-webgpu-contexts.js"></script>
-<script id="library" type="x-shader/x-metal">
- #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(-.75, -.75, 0, 1);
- break;
- case 1:
- v.position = float4(.75, -.75, 0, 1);
- break;
- case 2:
- v.position = float4(0, .75, 0, 1);
- break;
- default:
- v.position = float4(0, 0, 0, 1);
- }
- return v;
- }
-
- fragment float4 fragment_main(Vertex vertexIn [[stage_in]])
- {
- return float4(1.0, 0.0, 0.0, 1.0);
- }
-</script>
+<script src="js/basic-webgpu-functions.js"></script>
<script>
-'use strict';
-
if (window.testRunner)
window.testRunner.dumpAsText();
-let shaderDescriptor, shaderModule, vertexStageDescriptor, fragmentStageDescriptor;
-
-function setUpPipeline() {
- shaderDescriptor = {
- code: document.getElementById("library").text
- };
-
- shaderModule = defaultDevice.createShaderModule(shaderDescriptor);
- if (!shaderModule) {
- testFailed("Could not create WebGPUShaderModule!");
- return;
- }
-
- vertexStageDescriptor = {
- module: shaderModule,
- stage: WebGPUShaderStage.VERTEX,
- entryPoint: "vertex_main"
- };
-
- fragmentStageDescriptor = {
- module: shaderModule,
- stage: WebGPUShaderStage.FRAGMENT,
- entryPoint: "fragment_main"
- };
-
- let pipelineDescriptor = {
- stages: [vertexStageDescriptor, fragmentStageDescriptor],
- primitiveTopology: "triangleList"
- };
-
- let renderPipeline = defaultDevice.createRenderPipeline(pipelineDescriptor);
- if (renderPipeline)
- testPassed("Successfully created WebGPURenderPipeline.")
- else
- testFailed("Could not create WebGPURenderPipeline!");
-}
-
function checkBadRenderPipeline(descriptor, testSubjectName) {
let pipeline = defaultDevice.createRenderPipeline(descriptor);
<!DOCTYPE html>
<html>
<script src="../resources/js-test-pre.js"></script>
-<script src="js/set-up-webgpu-contexts.js"></script>
-<script id="library_full" type="x-shader/x-metal">
- #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(-.75, -.75, 0, 1);
- break;
- case 1:
- v.position = float4(.75, -.75, 0, 1);
- break;
- case 2:
- v.position = float4(0, .75, 0, 1);
- break;
- default:
- v.position = float4(0, 0, 0, 1);
- }
- return v;
- }
-
- fragment float4 fragment_main(Vertex vertexIn [[stage_in]])
- {
- return float4(1.0, 0.0, 0.0, 1.0);
- }
-</script>
+<script src="js/basic-webgpu-functions.js"></script>
<script id="library_incomplete" type="x-shader/x-metal">
#include <metal_stdlib>
}
</script>
<script>
-'use strict';
-
if (window.testRunner)
window.testRunner.dumpAsText();
testFailed("Incomplete shader code created a valid module!");
let shaderDescriptor2 = {
- code : document.getElementById("library_full").text
+ code : shaderCode
};
shaderModule = defaultDevice.createShaderModule(shaderDescriptor2);
--- /dev/null
+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
+
--- /dev/null
+<!DOCTYPE html>
+<html>
+<script src="../resources/js-test-pre.js"></script>
+<script src="js/basic-webgpu-functions.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;
+</script>
+<script src="../resources/js-test-post.js"></script>
+</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<script src="../resources/js-test-pre.js"></script>
-<script src="js/set-up-webgpu-contexts.js"></script>
-<script id="library" type="x-shader/x-metal">
- #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(-.75, -.75, 0, 1);
- break;
- case 1:
- v.position = float4(.75, -.75, 0, 1);
- break;
- case 2:
- v.position = float4(0, .75, 0, 1);
- break;
- default:
- v.position = float4(0, 0, 0, 1);
- }
- return v;
- }
-
- fragment float4 fragment_main(Vertex vertexIn [[stage_in]])
- {
- return float4(1.0, 0.0, 0.0, 1.0);
- }
-</script>
+<script src="js/basic-webgpu-functions.js"></script>
<script>
-'use strict';
-
if (window.testRunner)
window.testRunner.dumpAsText();
-let renderPipeline;
-
-function setUpPipeline() {
- let shaderDescriptor = {
- code: document.getElementById("library").text
- };
- let shaderModule = defaultDevice.createShaderModule(shaderDescriptor);
- if (!shaderModule) {
- testFailed("Could not create WebGPUShaderModule!");
- return;
- }
-
- let vertexStageDescriptor = {
- module: shaderModule,
- stage: WebGPUShaderStage.VERTEX,
- entryPoint: "vertex_main"
- };
-
- let fragmentStageDescriptor = {
- module: shaderModule,
- stage: WebGPUShaderStage.FRAGMENT,
- entryPoint: "fragment_main"
- };
-
- if (!vertexStageDescriptor || !fragmentStageDescriptor) {
- testFailed("Could not create WebGPUPipelineStageDescriptor!");
- return;
- }
-
- let pipelineDescriptor = {
- stages: [vertexStageDescriptor, fragmentStageDescriptor],
- primitiveTopology: "triangleList"
- };
-
- if (!pipelineDescriptor) {
- testFailed("Could not create WebGPURenderPipelineDescriptor!");
- return;
- }
-
- renderPipeline = defaultDevice.createRenderPipeline(pipelineDescriptor);
- if (!renderPipeline) {
- testFailed("Could not create WebGPURenderPipeline!");
- return;
- }
-}
-
-function render() {
- let commandBuffer = defaultDevice.createCommandBuffer();
- if (!commandBuffer) {
- testFailed("Could not create WebGPUCommandBuffer!");
- return;
- }
-
- // FIXME: More commands to follow as they are implemented.
-}
-
runWebGPUTests([setUpPipeline, render]);
successfullyParsed = true;
Modules/webgpu/WebGPUShaderModuleDescriptor.idl
Modules/webgpu/WebGPUShaderStage.idl
Modules/webgpu/WebGPUSwapChain.idl
+ Modules/webgpu/WebGPUTexture.idl
+ Modules/webgpu/WebGPUTextureFormatEnum.idl
+ Modules/webgpu/WebGPUTextureView.idl
Modules/websockets/CloseEvent.idl
Modules/websockets/WebSocket.idl
+2018-11-19 Justin Fan <justin_fan@apple.com>
+
+ [WebGPU] Begin implementing WebGPUTexture, WebGPUTextureView, and WebGPUTextureFormatEnum, and WebGPUSwapChain::configure upgrades
+ https://bugs.webkit.org/show_bug.cgi?id=191794
+
+ Reviewed by Dean Jackson.
+
+ Test: webgpu/textures-textureviews.html
+
+ Implement basic functionality for getting the next WebGPUTexture and TextureView from the WebGPURenderingContext
+ to use as a render destination for the next draw call. Also introduce WebGPUTextureFormatEnum and the ability to
+ configure the context with a chosen texture format.
+
+ * CMakeLists.txt:
+ * DerivedSources.make:
+ * Modules/webgpu/GPUSwapChain.h: Texture/Pixel format can now be set.
+ * Modules/webgpu/GPUTexture.h: Added. Interface to a MTLTexture.
+ * Modules/webgpu/GPUTextureFormatEnum.h: Added.
+ * Modules/webgpu/WebGPUDevice.cpp:
+ (WebCore::WebGPUDevice::createRenderPipeline const): Removed now-unnecessary enum class cast.
+ * Modules/webgpu/WebGPURenderPipelineDescriptor.h: Rather than duplicate GPURenderPipelineDescriptor::PrimitiveTopology, alias to it.
+ * Modules/webgpu/WebGPUSwapChain.cpp:
+ (WebCore::WebGPUSwapChain::configure): Can now specify a specific texture format for the underlying CAMetalLayer.
+ (WebCore::WebGPUSwapChain::getNextTexture): Added. Request the next drawable texture.
+ * Modules/webgpu/WebGPUSwapChain.h: Expose getNextTexture().
+ * Modules/webgpu/WebGPUSwapChain.idl:
+ * Modules/webgpu/WebGPUTexture.cpp: Added.
+ (WebCore::WebGPUTexture::create):
+ (WebCore::WebGPUTexture::WebGPUTexture):
+ (WebCore::WebGPUTexture::createDefaultTextureView):
+ * Modules/webgpu/WebGPUTexture.h: Added.
+ * Modules/webgpu/WebGPUTexture.idl: Added.
+ * Modules/webgpu/WebGPUTextureFormatEnum.h: Added. Type alias for GPUTextureFormatEnum.
+ * Modules/webgpu/WebGPUTextureFormatEnum.idl: Added. Used to represent any texture format used by WebGPU.
+ * Modules/webgpu/WebGPUTextureView.cpp: Added.
+ (WebCore::WebGPUTextureView::create):
+ (WebCore::WebGPUTextureView::WebGPUTextureView):
+ * Modules/webgpu/WebGPUTextureView.h: Added.
+ * Modules/webgpu/WebGPUTextureView.idl: Added.
+ * Modules/webgpu/cocoa/GPUSwapChainMetal.mm:
+ (WebCore::GPUSwapChain::create):
+ (WebCore::GPUSwapChain::setFormat): Called by WebGPUSwapChain::configure().
+ (WebCore::GPUSwapChain::getNextTexture):
+ * Modules/webgpu/cocoa/GPUTextureFormatEnumMetal.mm: Added.
+ (WebCore::convertAndValidate): Convert the WebGPUTextureFormatEnum to a MTLPixelFormat.
+ * Modules/webgpu/cocoa/GPUTextureMetal.mm: Added.
+ (WebCore::GPUTexture::create):
+ (WebCore::GPUTexture::GPUTexture):
+ (WebCore::GPUTexture::createDefaultTextureView): Uses the pixelFormat of the original texture.
+ * Sources.txt:
+ * SourcesCocoa.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * bindings/js/WebCoreBuiltinNames.h:
+
2018-11-19 Joseph Pecoraro <pecoraro@apple.com>
Web Inspector: "Reload Web Inspector" button no longer partially works
$(WebCore)/Modules/webgpu/WebGPUShaderModuleDescriptor.idl \
$(WebCore)/Modules/webgpu/WebGPUShaderStage.idl \
$(WebCore)/Modules/webgpu/WebGPUSwapChain.idl \
+ $(WebCore)/Modules/webgpu/WebGPUTexture.idl \
+ $(WebCore)/Modules/webgpu/WebGPUTextureFormatEnum.idl \
+ $(WebCore)/Modules/webgpu/WebGPUTextureView.idl \
$(WebCore)/Modules/websockets/CloseEvent.idl \
$(WebCore)/Modules/websockets/WebSocket.idl \
$(WebCore)/Modules/webvr/DOMWindowWebVR.idl \
namespace WebCore {
class GPUDevice;
+class GPUTexture;
+
+enum class GPUTextureFormatEnum;
using PlatformSwapLayer = CAMetalLayer;
using PlatformSwapLayerSmartPtr = RetainPtr<CAMetalLayer>;
static RefPtr<GPUSwapChain> create();
void setDevice(const GPUDevice&);
+ void setFormat(GPUTextureFormatEnum);
void reshape(int width, int height);
+ RefPtr<GPUTexture> getNextTexture();
void present();
PlatformSwapLayer* platformLayer() const { return m_platformSwapLayer.get(); }
--- /dev/null
+/*
+ * Copyright (C) 2018 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 <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_PROTOCOL(MTLTexture);
+
+namespace WebCore {
+
+using PlatformTexture = MTLTexture;
+using PlatformTextureSmartPtr = RetainPtr<MTLTexture>;
+
+class GPUTexture : public RefCounted<GPUTexture> {
+public:
+ static Ref<GPUTexture> create(PlatformTextureSmartPtr&&);
+
+ RefPtr<GPUTexture> createDefaultTextureView();
+
+private:
+ explicit GPUTexture(PlatformTextureSmartPtr&&);
+
+ PlatformTextureSmartPtr m_platformTexture;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
--- /dev/null
+/*
+ * Copyright (C) 2018 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)
+
+namespace WebCore {
+
+enum class GPUTextureFormatEnum {
+ R8G8B8A8Unorm,
+ R8G8B8A8Uint,
+ B8G8R8A8Unorm,
+ D32FloatS8Uint
+};
+
+using PlatformTextureFormat = unsigned long;
+
+}
+
+#endif // ENABLE(WEBGPU)
return nullptr;
}
- return WebGPURenderPipeline::create(m_device->createRenderPipeline(GPURenderPipelineDescriptor { WTFMove(vertexStage), WTFMove(fragmentStage), static_cast<GPURenderPipelineDescriptor::PrimitiveTopology>(descriptor.primitiveTopology) }));
+ return WebGPURenderPipeline::create(m_device->createRenderPipeline(GPURenderPipelineDescriptor { WTFMove(vertexStage), WTFMove(fragmentStage), descriptor.primitiveTopology }));
}
RefPtr<WebGPUCommandBuffer> WebGPUDevice::createCommandBuffer() const
#if ENABLE(WEBGPU)
+#include "GPURenderPipelineDescriptor.h"
#include "WebGPUPipelineDescriptorBase.h"
namespace WebCore {
struct WebGPURenderPipelineDescriptor : WebGPUPipelineDescriptorBase {
- enum class PrimitiveTopology {
- PointList,
- LineList,
- LineStrip,
- TriangleList,
- TriangleStrip
- };
+ using PrimitiveTopology = GPURenderPipelineDescriptor::PrimitiveTopology;
PrimitiveTopology primitiveTopology;
};
#if ENABLE(WEBGPU)
-#include "WebGPUDevice.h"
+#include "GPUTextureFormatEnum.h"
namespace WebCore {
if (descriptor.device)
m_swapChain->setDevice(descriptor.device->device());
+ m_swapChain->setFormat(descriptor.format);
+
reshape(descriptor.width, descriptor.height);
}
+RefPtr<WebGPUTexture> WebGPUSwapChain::getNextTexture()
+{
+ return WebGPUTexture::create(m_swapChain->getNextTexture());
+}
+
void WebGPUSwapChain::present()
{
markLayerComposited();
#include "GPUBasedCanvasRenderingContext.h"
#include "GPUSwapChain.h"
#include "WebGPUDevice.h"
+#include "WebGPUTexture.h"
+#include "WebGPUTextureFormatEnum.h"
+
+#include <wtf/RefPtr.h>
namespace WebCore {
struct Descriptor {
const WebGPUDevice* device = nullptr;
// FIXME: More texture properties.
+ WebGPUTextureFormatEnum format;
unsigned long width;
unsigned long height;
};
virtual ~WebGPUSwapChain() = 0;
+
void configure(Descriptor&&);
- // FIXME: WebGPUTexture getNextTexture();
+ RefPtr<WebGPUTexture> getNextTexture();
void present();
protected:
SkipVTableValidation
] interface WebGPUSwapChain {
void configure(WebGPUSwapChainDescriptor descriptor);
- // WebGPUTexture getNextTexture();
+ WebGPUTexture getNextTexture();
void present();
};
] dictionary WebGPUSwapChainDescriptor {
WebGPUDevice device; // FIXME: Propose this addition to IDL.
// WebGPUTextureUsageFlags usage;
- // WebGPUTextureFormatEnum format;
+ WebGPUTextureFormatEnum format;
u32 width;
u32 height;
};
--- /dev/null
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "config.h"
+#include "WebGPUTexture.h"
+
+#if ENABLE(WEBGPU)
+
+#include "WebGPUTextureView.h"
+
+namespace WebCore {
+
+RefPtr<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture)
+{
+ if (!texture)
+ return nullptr;
+
+ return adoptRef(new WebGPUTexture(texture.releaseNonNull()));
+}
+
+WebGPUTexture::WebGPUTexture(Ref<GPUTexture>&& texture)
+ : m_texture(WTFMove(texture))
+{
+}
+
+RefPtr<WebGPUTextureView> WebGPUTexture::createDefaultTextureView()
+{
+ auto gpuTexture = m_texture->createDefaultTextureView();
+
+ if (!gpuTexture)
+ return nullptr;
+
+ return WebGPUTextureView::create(gpuTexture.releaseNonNull());
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
--- /dev/null
+/*
+ * Copyright (C) 2018 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 "GPUTexture.h"
+
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class WebGPUTextureView;
+
+class WebGPUTexture : public RefCounted<WebGPUTexture> {
+public:
+ static RefPtr<WebGPUTexture> create(RefPtr<GPUTexture>&&);
+
+ RefPtr<WebGPUTextureView> createDefaultTextureView();
+
+private:
+ explicit WebGPUTexture(Ref<GPUTexture>&&);
+
+ Ref<GPUTexture> m_texture;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
--- /dev/null
+/*
+ * Copyright (C) 2018 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.
+ */
+// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+
+[
+ Conditional=WEBGPU,
+ EnabledAtRuntime=WebGPU,
+ ImplementationLacksVTable
+] interface WebGPUTexture {
+ WebGPUTextureView createDefaultTextureView();
+/* Not Yet Implemented:
+ WebGPUTextureView createTextureView(WebGPUTextureViewDescriptor desc);
+
+ void destroy();
+*/
+};
--- /dev/null
+/*
+ * Copyright (C) 2018 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 "GPUTextureFormatEnum.h"
+
+namespace WebCore {
+
+using WebGPUTextureFormatEnum = GPUTextureFormatEnum;
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
--- /dev/null
+/*
+ * Copyright (C) 2018 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.
+ */
+
+[
+ Conditional=WEBGPU,
+ EnabledAtRuntime=WebGPU
+] enum WebGPUTextureFormatEnum {
+ "R8G8B8A8Unorm",
+ "R8G8B8A8Uint",
+ "B8G8R8A8Unorm",
+ "D32FloatS8Uint"
+};
--- /dev/null
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#include "config.h"
+#include "WebGPUTextureView.h"
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+
+Ref<WebGPUTextureView> WebGPUTextureView::create(Ref<GPUTexture>&& view)
+{
+ return adoptRef(*new WebGPUTextureView(WTFMove(view)));
+}
+
+WebGPUTextureView::WebGPUTextureView(Ref<GPUTexture>&& view)
+ : m_textureView(WTFMove(view))
+{
+ UNUSED_PARAM(m_textureView);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
+
--- /dev/null
+/*
+ * Copyright (C) 2018 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 "GPUTexture.h"
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class WebGPUTextureView : public RefCounted<WebGPUTextureView> {
+public:
+ static Ref<WebGPUTextureView> create(Ref<GPUTexture>&&);
+
+private:
+ explicit WebGPUTextureView(Ref<GPUTexture>&&);
+
+ Ref<GPUTexture> m_textureView;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
--- /dev/null
+/*
+ * Copyright (C) 2018 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.
+ */
+// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+
+[
+ Conditional=WEBGPU,
+ EnabledAtRuntime=WebGPU,
+ ImplementationLacksVTable
+] interface WebGPUTextureView {
+};
#if ENABLE(WEBGPU)
#import "GPUDevice.h"
+#import "GPUTexture.h"
+#import "GPUTextureFormatEnum.h"
#import "Logging.h"
#import <Metal/Metal.h>
[platformLayer setOpaque:0];
[platformLayer setName:@"WebGPU Layer"];
- // FIXME: For now, default to these settings.
- [platformLayer setPixelFormat:MTLPixelFormatBGRA8Unorm];
+ // FIXME: For now, default to this usage flag.
[platformLayer setFramebufferOnly:YES];
END_BLOCK_OBJC_EXCEPTIONS;
[m_platformSwapLayer setDevice:device.platformDevice()];
}
+static std::optional<PlatformTextureFormat> platformTextureFormatForGPUTextureFormat(GPUTextureFormatEnum format)
+{
+ switch (format) {
+ case GPUTextureFormatEnum::R8G8B8A8Unorm:
+ return MTLPixelFormatRGBA8Unorm;
+ case GPUTextureFormatEnum::R8G8B8A8Uint:
+ return MTLPixelFormatRGBA8Uint;
+ case GPUTextureFormatEnum::B8G8R8A8Unorm:
+ return MTLPixelFormatBGRA8Unorm;
+ case GPUTextureFormatEnum::D32FloatS8Uint:
+ return MTLPixelFormatDepth32Float_Stencil8;
+ default:
+ LOG(WebGPU, "GPUSwapChain::setFormat(): Invalid texture format specified!");
+ return std::nullopt;
+ }
+}
+
+void GPUSwapChain::setFormat(GPUTextureFormatEnum format)
+{
+ auto result = platformTextureFormatForGPUTextureFormat(format);
+ if (!result)
+ return;
+
+ auto mtlResult = static_cast<MTLPixelFormat>(result.value());
+
+ switch (mtlResult) {
+ 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];
+ return;
+ default:
+ LOG(WebGPU, "GPUSwapChain::setFormat(): Unsupported MTLPixelFormat!");
+ }
+}
+
void GPUSwapChain::reshape(int width, int height)
{
[m_platformSwapLayer setBounds:CGRectMake(0, 0, width, height)];
[m_platformSwapLayer setDrawableSize:CGSizeMake(width, height)];
}
+RefPtr<GPUTexture> GPUSwapChain::getNextTexture()
+{
+ RetainPtr<MTLTexture> mtlTexture;
+
+ if (auto drawable = retainPtr([m_platformSwapLayer nextDrawable]))
+ mtlTexture = retainPtr([drawable texture]);
+
+ if (!mtlTexture) {
+ LOG(WebGPU, "GPUSwapChain::getNextTexture(): Unable to get next MTLTexture!");
+ return nullptr;
+ }
+
+ return GPUTexture::create(WTFMove(mtlTexture));
+}
+
void GPUSwapChain::present()
{
// FIXME: Unimplemented stub.
--- /dev/null
+/*
+ * Copyright (C) 2018 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 "GPUTexture.h"
+
+#if ENABLE(WEBGPU)
+
+#import "Logging.h"
+
+#import <Metal/Metal.h>
+#import <wtf/BlockObjCExceptions.h>
+
+namespace WebCore {
+
+Ref<GPUTexture> GPUTexture::create(PlatformTextureSmartPtr&& texture)
+{
+ return adoptRef(*new GPUTexture(WTFMove(texture)));
+}
+
+GPUTexture::GPUTexture(RetainPtr<MTLTexture>&& texture)
+ : m_platformTexture(WTFMove(texture))
+{
+}
+
+RefPtr<GPUTexture> GPUTexture::createDefaultTextureView()
+{
+ RetainPtr<MTLTexture> texture;
+
+ texture = adoptNS([m_platformTexture newTextureViewWithPixelFormat:m_platformTexture.get().pixelFormat]);
+
+ if (!texture) {
+ LOG(WebGPU, "GPUTexture::createDefaultTextureView(): Unable to create MTLTexture view!");
+ return nullptr;
+ }
+
+ return GPUTexture::create(WTFMove(texture));
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)
Modules/webgpu/WebGPURenderPipeline.cpp
Modules/webgpu/WebGPUShaderModule.cpp
Modules/webgpu/WebGPUSwapChain.cpp
+Modules/webgpu/WebGPUTexture.cpp
+Modules/webgpu/WebGPUTextureView.cpp
Modules/webvr/NavigatorWebVR.cpp
Modules/webvr/VRDisplay.cpp
JSWebGPUShaderModuleDescriptor.cpp
JSWebGPUShaderStage.cpp
JSWebGPUSwapChain.cpp
+JSWebGPUTexture.cpp
+JSWebGPUTextureFormatEnum.cpp
+JSWebGPUTextureView.cpp
JSWebMetalBuffer.cpp
JSWebMetalCommandBuffer.cpp
JSWebMetalCommandQueue.cpp
Modules/webgpu/cocoa/GPURenderPipelineMetal.mm
Modules/webgpu/cocoa/GPUShaderModuleMetal.mm
Modules/webgpu/cocoa/GPUSwapChainMetal.mm
+Modules/webgpu/cocoa/GPUTextureMetal.mm
accessibility/ios/AccessibilityObjectIOS.mm
accessibility/ios/AXObjectCacheIOS.mm
D045AD2321682475000A6E9B /* WebMetalCommandQueue.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebMetalCommandQueue.cpp; sourceTree = "<group>"; };
D046FB65218D073C00CB8F62 /* GPURenderPipelineDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPURenderPipelineDescriptor.h; sourceTree = "<group>"; };
D046FB67218D180300CB8F62 /* GPUPipelineStageDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUPipelineStageDescriptor.h; sourceTree = "<group>"; };
+ D046FB68218D18CD00CB8F62 /* GPUPipelineDescriptorBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUPipelineDescriptorBase.h; sourceTree = "<group>"; };
D0573D42217EB81E00D1BE91 /* GPULegacyTextureMetal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPULegacyTextureMetal.mm; sourceTree = "<group>"; };
D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FormatBlockCommand.cpp; sourceTree = "<group>"; };
D05CED280A40BB2C00C5AF38 /* FormatBlockCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FormatBlockCommand.h; sourceTree = "<group>"; };
D0EACF7E219382B0000FA75C /* GPUCommandBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = GPUCommandBuffer.h; path = Modules/webgpu/GPUCommandBuffer.h; sourceTree = SOURCE_ROOT; };
D0EACF80219391EE000FA75C /* GPUQueueMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUQueueMetal.mm; sourceTree = "<group>"; };
D0EACF812193921A000FA75C /* GPUQueue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUQueue.h; sourceTree = "<group>"; };
+ D0EACF822193AB38000FA75C /* GPUTexture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUTexture.h; sourceTree = "<group>"; };
+ D0EACF832193AB38000FA75C /* GPUTextureMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUTextureMetal.mm; sourceTree = "<group>"; };
+ D0EACF842193B02E000FA75C /* WebGPUTexture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUTexture.h; sourceTree = "<group>"; };
+ D0EACF852193B02E000FA75C /* WebGPUTexture.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUTexture.cpp; sourceTree = "<group>"; };
+ D0EACF862193B02E000FA75C /* WebGPUTexture.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUTexture.idl; sourceTree = "<group>"; };
+ D0EACF872193EE4E000FA75C /* WebGPUTextureView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUTextureView.h; sourceTree = "<group>"; };
+ D0EACF882193EE4E000FA75C /* WebGPUTextureView.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUTextureView.cpp; sourceTree = "<group>"; };
+ D0EACF892193EE4E000FA75C /* WebGPUTextureView.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUTextureView.idl; sourceTree = "<group>"; };
+ D0EACFAD219E30FD000FA75C /* WebGPUTextureFormatEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUTextureFormatEnum.h; sourceTree = "<group>"; };
+ D0EACFAE219E30FD000FA75C /* WebGPUTextureFormatEnum.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUTextureFormatEnum.idl; sourceTree = "<group>"; };
+ D0EACFB2219E4F14000FA75C /* GPUTextureFormatEnum.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUTextureFormatEnum.h; sourceTree = "<group>"; };
D0EDA772143E303C0028E383 /* CachedRawResource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CachedRawResource.cpp; sourceTree = "<group>"; };
D0EDA773143E303C0028E383 /* CachedRawResource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedRawResource.h; sourceTree = "<group>"; };
D0FF2A5B11F8C45A007E74E0 /* PingLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PingLoader.cpp; sourceTree = "<group>"; };
D0EACF7E219382B0000FA75C /* GPUCommandBuffer.h */,
D09727CA218BD7A500942F3A /* GPUDevice.cpp */,
D0615FCF217FF185008A48A8 /* GPUDevice.h */,
+ D046FB68218D18CD00CB8F62 /* GPUPipelineDescriptorBase.h */,
D046FB67218D180300CB8F62 /* GPUPipelineStageDescriptor.h */,
D0EACF812193921A000FA75C /* GPUQueue.h */,
D0EACF7D219382B0000FA75C /* GPURenderPipeline.h */,
D060D888218280C100339318 /* GPUShaderModule.h */,
D09727C2218A472900942F3A /* GPUShaderModuleDescriptor.h */,
D0EACF7C219382AF000FA75C /* GPUSwapChain.h */,
+ D0EACF822193AB38000FA75C /* GPUTexture.h */,
+ D0EACFB2219E4F14000FA75C /* GPUTextureFormatEnum.h */,
D00F5947216EFE54000D71DB /* WebGPU.cpp */,
D00F5946216EFE54000D71DB /* WebGPU.h */,
D00F5948216EFE54000D71DB /* WebGPU.idl */,
D0DA0BE5217930E2007FE2AC /* WebGPUSwapChain.cpp */,
D0DA0BE4217930E2007FE2AC /* WebGPUSwapChain.h */,
D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */,
+ D0EACF852193B02E000FA75C /* WebGPUTexture.cpp */,
+ D0EACF842193B02E000FA75C /* WebGPUTexture.h */,
+ D0EACF862193B02E000FA75C /* WebGPUTexture.idl */,
+ D0EACFAD219E30FD000FA75C /* WebGPUTextureFormatEnum.h */,
+ D0EACFAE219E30FD000FA75C /* WebGPUTextureFormatEnum.idl */,
+ D0EACF882193EE4E000FA75C /* WebGPUTextureView.cpp */,
+ D0EACF872193EE4E000FA75C /* WebGPUTextureView.h */,
+ D0EACF892193EE4E000FA75C /* WebGPUTextureView.idl */,
);
path = webgpu;
sourceTree = "<group>";
D0C419FB21840F6C009EC1DE /* GPURenderPipelineMetal.mm */,
D060D889218280C100339318 /* GPUShaderModuleMetal.mm */,
D09727B62187F44300942F3A /* GPUSwapChainMetal.mm */,
+ D0EACF832193AB38000FA75C /* GPUTextureMetal.mm */,
);
path = cocoa;
sourceTree = "<group>";
macro(WebGPUShaderStage) \
macro(WebGPUShaderModule) \
macro(WebGPUSwapChain) \
+ macro(WebGPUTexture) \
+ macro(WebGPUTextureView) \
macro(WebMetalBuffer) \
macro(WebMetalCommandBuffer) \
macro(WebMetalCommandQueue) \