Title: [243755] trunk
Revision
243755
Author
justin_...@apple.com
Date
2019-04-02 12:59:55 -0700 (Tue, 02 Apr 2019)

Log Message

Source/WebCore:
[Web GPU] Implement blend states and color write mask for GPUColorStateDescriptor
https://bugs.webkit.org/show_bug.cgi?id=196474

Reviewed by Myles C. Maxfield.

Blend states and color write masks must now be specified on GPUColorStateDescriptor instead of
relying on underlying MTLRenderPipelineColorAttachmentDescriptor defaults.

Test: webgpu/blend-triangle-strip.html, webgpu/color-write-mask-triangle-strip.html

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Modules/webgpu/GPUBlendDescriptor.idl:
* Modules/webgpu/GPUColorStateDescriptor.idl:
* Modules/webgpu/GPUColorWriteBits.idl:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:
* platform/graphics/gpu/GPUBlendDescriptor.h:
* platform/graphics/gpu/GPUColorStateDescriptor.h:
* platform/graphics/gpu/GPUColorWriteBits.h:
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::mtlColorWriteMaskForGPUColorWriteFlags):
(WebCore::mtlBlendOperationForGPUBlendOperation):
(WebCore::mtlBlendFactorForGPUBlendFactor):
(WebCore::setColorStatesForColorAttachmentArray):
(WebCore::tryCreateMtlRenderPipelineState):
(WebCore::trySetColorStatesForColorAttachmentArray): Deleted.

LayoutTests:
[Web GPU] Implement blend states and color write mask for  GPUColorStateDescriptor
https://bugs.webkit.org/show_bug.cgi?id=196474

Reviewed by Myles C. Maxfield.

Add blend-triangle-strip to test color blending and color-write-mask-triangle-strip.html to test color write mask.
Update other tests to specify blend states when creating a GPURenderPipeline.

* webgpu/blend-triangle-strip-expected.html: Added.
* webgpu/blend-triangle-strip.html: Added.
* webgpu/buffer-command-buffer-races.html:
* webgpu/buffer-resource-triangles.html:
* webgpu/color-write-mask-triangle-strip-expected.html: Added.
* webgpu/color-write-mask-triangle-strip.html: Added.
* webgpu/depth-enabled-triangle-strip.html:
* webgpu/js/webgpu-functions.js:
* webgpu/render-pipelines.html:
* webgpu/texture-triangle-strip.html:
* webgpu/vertex-buffer-triangle-strip.html:
* webgpu/whlsl.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (243754 => 243755)


--- trunk/LayoutTests/ChangeLog	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/ChangeLog	2019-04-02 19:59:55 UTC (rev 243755)
@@ -1,3 +1,26 @@
+2019-04-02  Justin Fan  <justin_...@apple.com>
+
+        [Web GPU] Implement blend states and color write mask for  GPUColorStateDescriptor
+        https://bugs.webkit.org/show_bug.cgi?id=196474
+
+        Reviewed by Myles C. Maxfield.
+
+        Add blend-triangle-strip to test color blending and color-write-mask-triangle-strip.html to test color write mask.
+        Update other tests to specify blend states when creating a GPURenderPipeline.
+
+        * webgpu/blend-triangle-strip-expected.html: Added.
+        * webgpu/blend-triangle-strip.html: Added.
+        * webgpu/buffer-command-buffer-races.html:
+        * webgpu/buffer-resource-triangles.html:
+        * webgpu/color-write-mask-triangle-strip-expected.html: Added.
+        * webgpu/color-write-mask-triangle-strip.html: Added.
+        * webgpu/depth-enabled-triangle-strip.html:
+        * webgpu/js/webgpu-functions.js:
+        * webgpu/render-pipelines.html:
+        * webgpu/texture-triangle-strip.html:
+        * webgpu/vertex-buffer-triangle-strip.html:
+        * webgpu/whlsl.html:
+
 2019-04-02  Zalan Bujtas  <za...@apple.com>
 
         [ContentChangeObserver] Ignore reconstructed renderers when checking for visibility change

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


--- trunk/LayoutTests/webgpu/blend-triangle-strip-expected.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/blend-triangle-strip-expected.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -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/blend-triangle-strip.html (0 => 243755)


--- trunk/LayoutTests/webgpu/blend-triangle-strip.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/blend-triangle-strip.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -0,0 +1,118 @@
+<!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 src=""
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+const positionAttributeNum = 0;
+
+const shaderCode = `
+#include <metal_stdlib>
+    
+using namespace metal;
+
+struct VertexIn
+{
+    float4 position [[attribute(${positionAttributeNum})]];
+};
+
+struct VertexOut
+{
+    float4 position [[position]];
+    float4 color;
+};
+
+vertex VertexOut vertex_main(VertexIn vertexIn [[stage_in]])
+{
+    VertexOut vOut;
+    vOut.position = vertexIn.position;
+    vOut.color = float4(0, 0.5, 0, 0.5);
+    return vOut;
+}
+
+fragment float4 fragment_main(VertexOut v [[stage_in]])
+{
+    return v.color;
+}
+`;
+
+window.addEventListener("load", test, false);
+
+async function test() {
+    const device = await getBasicDevice();
+    const canvas = document.querySelector("canvas");
+
+    const shaderModule = device.createShaderModule({ code: shaderCode });
+
+    const colorStates = [{
+        format: "bgra8unorm",
+        alphaBlend: {
+            srcFactor: "one",
+            dstFactor: "one",
+            operation: "add"
+        },
+        colorBlend: {
+            srcFactor: "one",
+            dstFactor: "one",
+            operation: "add"
+        },
+        writeMask: GPUColorWriteBits.ALL
+    }];
+
+    const inputStateDescriptor = {
+        indexFormat: "uint32",
+        attributes: [{
+            shaderLocation: positionAttributeNum,
+            inputSlot: 0,
+            offset: 0,
+            format: "float4"
+        }],
+        inputs: [{
+            inputSlot: 0,
+            stride: 4 * 4,
+            stepMode: "vertex"
+        }]
+    };
+
+    const pipeline = createBasicPipeline(shaderModule, device, colorStates, null, inputStateDescriptor);
+
+    const vertexData = new Float32Array([
+        -1, 1, 0, 1,
+        -1, -1, 0, 1,
+        1, 1, 0, 1,
+        1, -1, 0, 1
+    ]);
+    const vertexBuffer = device.createBuffer({ size: vertexData.byteLength, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
+    vertexBuffer.setSubData(0, vertexData.buffer);
+
+    const context = canvas.getContext("gpu");
+    const swapChain = device.createSwapChain({ context: context, format: "bgra8unorm" });
+    const colorAttachment = {
+        attachment: swapChain.getCurrentTexture().createDefaultView(),
+        loadOp: "clear",
+        storeOp: "store",
+        clearColor: { r: 0, g: 0, b: 0, a: 0 }
+    };
+
+    const commandEncoder = device.createCommandEncoder();
+    const passEncoder = commandEncoder.beginRenderPass({ colorAttachments: [colorAttachment] });
+    passEncoder.setPipeline(pipeline);
+    passEncoder.setVertexBuffers(0, [vertexBuffer], [0]);
+    passEncoder.draw(4, 1, 0, 0);
+    passEncoder.draw(4, 1, 0, 0);
+    passEncoder.endPass();
+
+    device.getQueue().submit([commandEncoder.finish()]);
+
+    requestAnimationFrame(() => { 
+        if (window.testRunner)
+            testRunner.notifyDone();
+    });
+}
+</script>
\ No newline at end of file

Modified: trunk/LayoutTests/webgpu/buffer-command-buffer-races.html (243754 => 243755)


--- trunk/LayoutTests/webgpu/buffer-command-buffer-races.html	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/buffer-command-buffer-races.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -92,7 +92,7 @@
     // FIXME: Replace with non-MSL shaders.
     const shaderModule = device.createShaderModule({ code: shaderCode });
     const inputStateDescriptor = createInputStateDescriptor();
-    const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor);
+    const pipeline = createBasicPipeline(shaderModule, device, null, null, inputStateDescriptor);
 
     const upperLeftBuffer = createAndSetVertexBuffer(device, [-1, 1, -1, -1, 0, 1]);
     const middleBuffer = createAndSetVertexBuffer(device, [0, 1, -1, -1, 1, -1]);

Modified: trunk/LayoutTests/webgpu/buffer-resource-triangles.html (243754 => 243755)


--- trunk/LayoutTests/webgpu/buffer-resource-triangles.html	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/buffer-resource-triangles.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -165,7 +165,7 @@
 
     // WebGPUPipelineLayout and WebGPURenderPipeline
     const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [leftTriangleBGLayout, rightTriangleBGLayout] });
-    const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputState, null, "triangle-list");
+    const pipeline = createBasicPipeline(shaderModule, device, null, pipelineLayout, inputState, null, "triangle-list");
 
     // WebGPUBufferBindings
     const bindingUL = createBufferBinding(upperLeft);

Added: trunk/LayoutTests/webgpu/color-write-mask-triangle-strip-expected.html (0 => 243755)


--- trunk/LayoutTests/webgpu/color-write-mask-triangle-strip-expected.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/color-write-mask-triangle-strip-expected.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -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/color-write-mask-triangle-strip.html (0 => 243755)


--- trunk/LayoutTests/webgpu/color-write-mask-triangle-strip.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/color-write-mask-triangle-strip.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -0,0 +1,88 @@
+<!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 src=""
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+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()
+{
+    return float4(1, 1, 1, 1);
+}
+`
+
+async function test() {
+    const device = await getBasicDevice();
+    const canvas = document.querySelector("canvas");
+    const swapChain = createBasicSwapChain(canvas, device);
+    const shaderModule = device.createShaderModule({ code: shaderCode });
+    const colorStates = [{
+        format: "bgra8unorm",
+        alphaBlend: {
+            srcFactor: "one",
+            dstFactor: "zero",
+            operation: "add"
+        },
+        colorBlend: {
+            srcFactor: "one",
+            dstFactor: "zero",
+            operation: "add"
+        },
+        writeMask: GPUColorWriteBits.GREEN | GPUColorWriteBits.ALPHA
+    }];
+    const pipeline = createBasicPipeline(shaderModule, device, colorStates);
+    const commandEncoder = device.createCommandEncoder();
+    const colorAttachment = {
+        attachment: swapChain.getCurrentTexture().createDefaultView(),
+        loadOp: "clear",
+        storeOp: "store",
+        clearColor: { r: 0, g: 0, b: 0, a: 0 }
+    };
+    const passEncoder = commandEncoder.beginRenderPass({ colorAttachments: [colorAttachment] });
+    encodeBasicCommands(passEncoder, pipeline);
+    const queue = device.getQueue();
+
+    queue.submit([commandEncoder.finish()]);
+
+    requestAnimationFrame(() => { 
+        if (window.testRunner)
+            testRunner.notifyDone();
+    });
+}
+
+test();
+</script>
\ No newline at end of file

Modified: trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html (243754 => 243755)


--- trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -88,7 +88,7 @@
     const vertexBuffer = createVertexBuffer(device);
     const inputStateDescriptor = createInputStateDescriptor();
     const depthStateDescriptor = createBasicDepthStateDescriptor();
-    const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor, depthStateDescriptor);
+    const pipeline = createBasicPipeline(shaderModule, device, null, null, inputStateDescriptor, depthStateDescriptor);
     const commandEncoder = device.createCommandEncoder();
 
     const basicAttachment = {

Modified: trunk/LayoutTests/webgpu/js/webgpu-functions.js (243754 => 243755)


--- trunk/LayoutTests/webgpu/js/webgpu-functions.js	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/js/webgpu-functions.js	2019-04-02 19:59:55 UTC (rev 243755)
@@ -34,7 +34,7 @@
     });
 }
 
-function createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor, depthStateDescriptor, primitiveTopology = "triangle-strip") {
+function createBasicPipeline(shaderModule, device, colorStates, pipelineLayout, inputStateDescriptor, depthStateDescriptor, primitiveTopology = "triangle-strip") {
     const vertexStageDescriptor = {
         module: shaderModule,
         entryPoint: "vertex_main" 
@@ -45,13 +45,28 @@
         entryPoint: "fragment_main"
     };
 
-    const basicColorState = { format: "bgra8unorm" };
+    if (!colorStates) {
+        colorStates = [{ 
+            format: "bgra8unorm",
+            alphaBlend: {
+                srcFactor: "one",
+                dstFactor: "zero",
+                operation: "add"
+            },
+            colorBlend: {
+                srcFactor: "one",
+                dstFactor: "zero",
+                operation: "add"
+            },
+            writeMask: GPUColorWriteBits.ALL
+        }];
+    }
 
     const pipelineDescriptor = {
         vertexStage: vertexStageDescriptor,
         fragmentStage: fragmentStageDescriptor,
         primitiveTopology: primitiveTopology,
-        colorStates: [basicColorState]
+        colorStates: colorStates
     };
 
     if (pipelineLayout)

Modified: trunk/LayoutTests/webgpu/render-pipelines.html (243754 => 243755)


--- trunk/LayoutTests/webgpu/render-pipelines.html	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/render-pipelines.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -47,7 +47,7 @@
     const bindGroupLayout = device.createBindGroupLayout({ bindings: [layoutBinding] });
     const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] });
 
-    const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout);
+    const pipeline = createBasicPipeline(shaderModule, device, null, pipelineLayout);
     assert_true(pipeline instanceof WebGPURenderPipeline, "Successfully created WebGPURenderPipeline");
 }, "Create basic WebGPURenderPipeline");
 </script>

Modified: trunk/LayoutTests/webgpu/texture-triangle-strip.html (243754 => 243755)


--- trunk/LayoutTests/webgpu/texture-triangle-strip.html	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/texture-triangle-strip.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -185,7 +185,7 @@
     const bindGroup = device.createBindGroup(bindGroupDescriptor);
 
     // Pipeline and render
-    const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor);
+    const pipeline = createBasicPipeline(shaderModule, device, null, pipelineLayout, inputStateDescriptor);
     const commandEncoder = device.createCommandEncoder();
 
     const bufferCopyView = {

Modified: trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html (243754 => 243755)


--- trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -90,7 +90,7 @@
     const shaderModule = device.createShaderModule({ code: shaderCode });
     const vertexBuffer = createVertexBuffer(device);
     const inputStateDescriptor = createInputStateDescriptor();
-    const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor);
+    const pipeline = createBasicPipeline(shaderModule, device, null, null, inputStateDescriptor);
     const commandEncoder = device.createCommandEncoder();
     const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
     encodeBasicCommands(passEncoder, pipeline, vertexBuffer);

Modified: trunk/LayoutTests/webgpu/whlsl.html (243754 => 243755)


--- trunk/LayoutTests/webgpu/whlsl.html	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/LayoutTests/webgpu/whlsl.html	2019-04-02 19:59:55 UTC (rev 243755)
@@ -23,8 +23,8 @@
     const fragmentStage = {module: shaderModule, entryPoint: "fragmentShader"};
     const primitiveTopology = "triangle-strip";
     const rasterizationState = {frontFace: "cw", cullMode: "none"};
-    const alphaBlend = {srcFactor: "zero", dstFactor: "one", operation: "add"};
-    const colorBlend = {srcFactor: "zero", dstFactor: "one", operation: "add"};
+    const alphaBlend = {srcFactor: "one", dstFactor: "zero", operation: "add"};
+    const colorBlend = {srcFactor: "one", dstFactor: "zero", operation: "add"};
     const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL
     const depthStencilState = null;
     

Modified: trunk/Source/WebCore/CMakeLists.txt (243754 => 243755)


--- trunk/Source/WebCore/CMakeLists.txt	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/CMakeLists.txt	2019-04-02 19:59:55 UTC (rev 243755)
@@ -465,11 +465,13 @@
     Modules/webgpu/DOMWindowWebGPU.idl
     Modules/webgpu/GPUBindGroupLayoutBinding.idl
     Modules/webgpu/GPUBindGroupLayoutDescriptor.idl
+    Modules/webgpu/GPUBlendDescriptor.idl
     Modules/webgpu/GPUBufferDescriptor.idl
     Modules/webgpu/GPUBufferUsage.idl
     Modules/webgpu/GPUCanvasContext.idl
     Modules/webgpu/GPUColor.idl
     Modules/webgpu/GPUColorStateDescriptor.idl
+    Modules/webgpu/GPUColorWriteBits.idl
     Modules/webgpu/GPUCompareFunction.idl
     Modules/webgpu/GPUDepthStencilStateDescriptor.idl
     Modules/webgpu/GPUExtent3D.idl

Modified: trunk/Source/WebCore/ChangeLog (243754 => 243755)


--- trunk/Source/WebCore/ChangeLog	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/ChangeLog	2019-04-02 19:59:55 UTC (rev 243755)
@@ -1,3 +1,36 @@
+2019-04-02  Justin Fan  <justin_...@apple.com>
+
+        [Web GPU] Implement blend states and color write mask for GPUColorStateDescriptor
+        https://bugs.webkit.org/show_bug.cgi?id=196474
+
+        Reviewed by Myles C. Maxfield.
+
+        Blend states and color write masks must now be specified on GPUColorStateDescriptor instead of 
+        relying on underlying MTLRenderPipelineColorAttachmentDescriptor defaults.
+
+        Test: webgpu/blend-triangle-strip.html, webgpu/color-write-mask-triangle-strip.html
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Modules/webgpu/GPUBlendDescriptor.idl: 
+        * Modules/webgpu/GPUColorStateDescriptor.idl:
+        * Modules/webgpu/GPUColorWriteBits.idl: 
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreBuiltinNames.h:
+        * platform/graphics/gpu/GPUBlendDescriptor.h:
+        * platform/graphics/gpu/GPUColorStateDescriptor.h:
+        * platform/graphics/gpu/GPUColorWriteBits.h:
+        * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
+        (WebCore::mtlColorWriteMaskForGPUColorWriteFlags):
+        (WebCore::mtlBlendOperationForGPUBlendOperation):
+        (WebCore::mtlBlendFactorForGPUBlendFactor):
+        (WebCore::setColorStatesForColorAttachmentArray):
+        (WebCore::tryCreateMtlRenderPipelineState):
+        (WebCore::trySetColorStatesForColorAttachmentArray): Deleted.
+
 2019-04-02  Zalan Bujtas  <za...@apple.com>
 
         [ContentChangeObserver] Ignore reconstructed renderers when checking for visibility change

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (243754 => 243755)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2019-04-02 19:59:55 UTC (rev 243755)
@@ -330,11 +330,13 @@
 $(PROJECT_DIR)/Modules/webgpu/DOMWindowWebGPU.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUBindGroupLayoutBinding.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl
+$(PROJECT_DIR)/Modules/webgpu/GPUBlendDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUBufferDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUBufferUsage.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUCanvasContext.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUColor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUColorStateDescriptor.idl
+$(PROJECT_DIR)/Modules/webgpu/GPUColorWriteBits.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUCompareFunction.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUDepthStencilStateDescriptor.idl
 $(PROJECT_DIR)/Modules/webgpu/GPUExtent3D.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (243754 => 243755)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2019-04-02 19:59:55 UTC (rev 243755)
@@ -587,6 +587,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutBinding.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutDescriptor.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutDescriptor.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBlendDescriptor.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBlendDescriptor.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferUsage.cpp
@@ -597,6 +599,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColor.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorStateDescriptor.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorStateDescriptor.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorWriteBits.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorWriteBits.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUCompareFunction.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUCompareFunction.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUDepthStencilStateDescriptor.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (243754 => 243755)


--- trunk/Source/WebCore/DerivedSources.make	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/DerivedSources.make	2019-04-02 19:59:55 UTC (rev 243755)
@@ -378,8 +378,10 @@
     $(WebCore)/Modules/webgpu/GPUCanvasContext.idl \
     $(WebCore)/Modules/webgpu/GPUColor.idl \
     $(WebCore)/Modules/webgpu/GPUColorStateDescriptor.idl \
+    $(WebCore)/Modules/webgpu/GPUColorWriteBits.idl \
     $(WebCore)/Modules/webgpu/GPUBindGroupLayoutBinding.idl \
     $(WebCore)/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl \
+    $(WebCore)/Modules/webgpu/GPUBlendDescriptor.idl \
     $(WebCore)/Modules/webgpu/GPUBufferDescriptor.idl \
     $(WebCore)/Modules/webgpu/GPUBufferUsage.idl \
     $(WebCore)/Modules/webgpu/GPUCompareFunction.idl \

Copied: trunk/Source/WebCore/Modules/webgpu/GPUBlendDescriptor.idl (from rev 243754, trunk/Source/WebCore/Modules/webgpu/GPUColorStateDescriptor.idl) (0 => 243755)


--- trunk/Source/WebCore/Modules/webgpu/GPUBlendDescriptor.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/GPUBlendDescriptor.idl	2019-04-02 19:59:55 UTC (rev 243755)
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+
+[
+    ImplementedAs=GPUBlendFactor
+] enum GPUBlendFactor {
+    "zero",
+    "one",
+    "src-color",
+    "one-minus-src-color",
+    "src-alpha",
+    "one-minus-src-alpha",
+    "dst-color",
+    "one-minus-dst-color",
+    "dst-alpha",
+    "one-minus-dst-alpha",
+    "src-alpha-saturated",
+    "blend-color",
+    "one-minus-blend-color"
+};
+
+[
+    ImplementedAs=GPUBlendOperation
+] enum GPUBlendOperation {
+    "add",
+    "subtract",
+    "reverse-subtract",
+    "min",
+    "max"
+};
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU
+] dictionary GPUBlendDescriptor {
+    GPUBlendFactor srcFactor;
+    GPUBlendFactor dstFactor;
+    GPUBlendOperation operation;
+};

Modified: trunk/Source/WebCore/Modules/webgpu/GPUColorStateDescriptor.idl (243754 => 243755)


--- trunk/Source/WebCore/Modules/webgpu/GPUColorStateDescriptor.idl	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/Modules/webgpu/GPUColorStateDescriptor.idl	2019-04-02 19:59:55 UTC (rev 243755)
@@ -24,6 +24,8 @@
  */
 // https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
 
+typedef unsigned long GPUColorWriteFlags;
+
 [
     Conditional=WEBGPU,
     EnabledAtRuntime=WebGPU
@@ -30,8 +32,7 @@
 ] dictionary GPUColorStateDescriptor {
     GPUTextureFormat format;
 
-    // Not yet implemented.
-    // GPUBlendDescriptor alphaBlend;
-    // GPUBlendDescriptor colorBlend;
-    // GPUColorWriteFlags writeMask;
+    GPUBlendDescriptor alphaBlend;
+    GPUBlendDescriptor colorBlend;
+    GPUColorWriteFlags writeMask;
 };

Copied: trunk/Source/WebCore/Modules/webgpu/GPUColorWriteBits.idl (from rev 243754, trunk/Source/WebCore/Modules/webgpu/GPUColorStateDescriptor.idl) (0 => 243755)


--- trunk/Source/WebCore/Modules/webgpu/GPUColorWriteBits.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/GPUColorWriteBits.idl	2019-04-02 19:59:55 UTC (rev 243755)
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+
+typedef unsigned long u32;
+
+[
+    Conditional=WEBGPU,
+    DoNotCheckConstants,
+    EnabledAtRuntime=WebGPU,
+    ImplementationLacksVTable
+] interface GPUColorWriteBits {
+    const u32 NONE = 0;
+    const u32 RED = 1;
+    const u32 GREEN = 2;
+    const u32 BLUE = 4;
+    const u32 ALPHA = 8;
+    const u32 ALL = 15;
+};

Modified: trunk/Source/WebCore/Sources.txt (243754 => 243755)


--- trunk/Source/WebCore/Sources.txt	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/Sources.txt	2019-04-02 19:59:55 UTC (rev 243755)
@@ -2720,8 +2720,10 @@
 JSGPUCanvasContext.cpp
 JSGPUColor.cpp
 JSGPUColorStateDescriptor.cpp
+JSGPUColorWriteBits.cpp
 JSGPUBindGroupLayoutBinding.cpp
 JSGPUBindGroupLayoutDescriptor.cpp
+JSGPUBlendDescriptor.cpp
 JSGPUBufferDescriptor.cpp
 JSGPUBufferUsage.cpp
 JSGPUCompareFunction.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (243754 => 243755)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-04-02 19:59:55 UTC (rev 243755)
@@ -13957,6 +13957,10 @@
 		D0ADB28C2237842E00A22935 /* GPUColorStateDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUColorStateDescriptor.idl; sourceTree = "<group>"; };
 		D0B0556609C6700100307E43 /* CreateLinkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateLinkCommand.h; sourceTree = "<group>"; };
 		D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CreateLinkCommand.cpp; sourceTree = "<group>"; };
+		D0B56EAA224EC6240061049C /* GPUBlendDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBlendDescriptor.h; sourceTree = "<group>"; };
+		D0B56EAB224EC6240061049C /* GPUBlendDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUBlendDescriptor.idl; sourceTree = "<group>"; };
+		D0B56EAD224ECE200061049C /* GPUColorWriteBits.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUColorWriteBits.h; sourceTree = "<group>"; };
+		D0B56EAE224ECE200061049C /* GPUColorWriteBits.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUColorWriteBits.idl; sourceTree = "<group>"; };
 		D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutBinding.h; sourceTree = "<group>"; };
 		D0BC54481443AC4A00E105DA /* CachedStyleSheetClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedStyleSheetClient.h; sourceTree = "<group>"; };
 		D0BD4F5A1408850F006839B6 /* DictationCommandIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DictationCommandIOS.cpp; sourceTree = "<group>"; };
@@ -18213,6 +18217,7 @@
 				D0BE104E21E695E200E42A89 /* GPUBindGroupBinding.h */,
 				D0BE105121E6A70E00E42A89 /* GPUBindGroupDescriptor.h */,
 				D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */,
+				D0B56EAA224EC6240061049C /* GPUBlendDescriptor.h */,
 				D084033A221CBF5400007205 /* GPUBuffer.cpp */,
 				D0D8649221B760F2003C983C /* GPUBuffer.h */,
 				D0BE104A21E6872F00E42A89 /* GPUBufferBinding.h */,
@@ -18220,6 +18225,7 @@
 				D01B811D2213636E00627B6C /* GPUBufferUsage.h */,
 				D001D9AB21B0C7BF0023B9BC /* GPUColor.h */,
 				D0ADB28B2237842E00A22935 /* GPUColorStateDescriptor.h */,
+				D0B56EAD224ECE200061049C /* GPUColorWriteBits.h */,
 				312FF8BD21A4C2F100EB199D /* GPUCommandBuffer.h */,
 				D03C849C21FFC7FC0002227F /* GPUCompareFunction.h */,
 				D089033F2241CE4600F3F440 /* GPUComputePassEncoder.h */,
@@ -25778,6 +25784,7 @@
 				D0D69C9F222E015E0032927E /* GPUBindGroupLayoutBinding.idl */,
 				D0D69C9C222E00C20032927E /* GPUBindGroupLayoutDescriptor.h */,
 				D0D69C9D222E00C20032927E /* GPUBindGroupLayoutDescriptor.idl */,
+				D0B56EAB224EC6240061049C /* GPUBlendDescriptor.idl */,
 				D01B811922135EB900627B6C /* GPUBufferDescriptor.idl */,
 				D01B811C2213627300627B6C /* GPUBufferUsage.idl */,
 				D093D2292179541600329217 /* GPUCanvasContext.cpp */,
@@ -25785,6 +25792,7 @@
 				D093D227217951D400329217 /* GPUCanvasContext.idl */,
 				D01B811222125AFC00627B6C /* GPUColor.idl */,
 				D0ADB28C2237842E00A22935 /* GPUColorStateDescriptor.idl */,
+				D0B56EAE224ECE200061049C /* GPUColorWriteBits.idl */,
 				D03C849E21FFCF000002227F /* GPUCompareFunction.idl */,
 				D03C84A221FFD7230002227F /* GPUDepthStencilStateDescriptor.idl */,
 				D026F480220A2B7000AC5F49 /* GPUExtent3D.idl */,

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (243754 => 243755)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2019-04-02 19:59:55 UTC (rev 243755)
@@ -83,11 +83,12 @@
     macro(GamepadEvent) \
     macro(GPUBufferUsage) \
     macro(GPUCanvasContext) \
-    macro(GPUShaderModule) \
+    macro(GPUColorWriteBits) \
     macro(GPUCommandBuffer) \
     macro(GPUCommandEncoder) \
     macro(GPUComputePassEncoder) \
     macro(GPUComputePipeline) \
+    macro(GPUShaderModule) \
     macro(GPUShaderStageBit) \
     macro(GPUSwapChain) \
     macro(GPUTextureUsage) \

Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUBlendDescriptor.h (from rev 243754, trunk/Source/WebCore/platform/graphics/gpu/GPUColorStateDescriptor.h) (0 => 243755)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUBlendDescriptor.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUBlendDescriptor.h	2019-04-02 19:59:55 UTC (rev 243755)
@@ -0,0 +1,64 @@
+/*
+ * 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)
+
+namespace WebCore {
+
+enum class GPUBlendFactor {
+    Zero,
+    One,
+    SrcColor,
+    OneMinusSrcColor,
+    SrcAlpha,
+    OneMinusSrcAlpha,
+    DstColor,
+    OneMinusDstColor,
+    DstAlpha,
+    OneMinusDstAlpha,
+    SrcAlphaSaturated,
+    BlendColor,
+    OneMinusBlendColor,
+};
+
+enum class GPUBlendOperation {
+    Add,
+    Subtract,
+    ReverseSubtract,
+    Min,
+    Max,
+};
+
+struct GPUBlendDescriptor {
+    GPUBlendFactor srcFactor;
+    GPUBlendFactor dstFactor;
+    GPUBlendOperation operation;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUColorStateDescriptor.h (243754 => 243755)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUColorStateDescriptor.h	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUColorStateDescriptor.h	2019-04-02 19:59:55 UTC (rev 243755)
@@ -27,6 +27,8 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPUBlendDescriptor.h"
+#include "GPUColorWriteBits.h"
 #include "GPUTextureFormat.h"
 
 namespace WebCore {
@@ -33,6 +35,10 @@
 
 struct GPUColorStateDescriptor {
     GPUTextureFormat format;
+
+    GPUBlendDescriptor alphaBlend;
+    GPUBlendDescriptor colorBlend;
+    GPUColorWriteFlags writeMask;
 };
 
 } // namespace WebCore

Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUColorWriteBits.h (from rev 243754, trunk/Source/WebCore/platform/graphics/gpu/GPUColorStateDescriptor.h) (0 => 243755)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUColorWriteBits.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUColorWriteBits.h	2019-04-02 19:59:55 UTC (rev 243755)
@@ -0,0 +1,50 @@
+/*
+ * 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 <wtf/RefCounted.h>
+
+namespace WebCore {
+
+using GPUColorWriteFlags = unsigned;
+
+class GPUColorWriteBits : public RefCounted<GPUColorWriteBits> {
+public:
+    enum class Flags : GPUColorWriteFlags {
+        None = 0,
+        Red = 1 << 0,
+        Green = 1 << 1,
+        Blue = 1 << 2,
+        Alpha = 1 << 3,
+        All = (1 << 4) - 1,
+    };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm (243754 => 243755)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm	2019-04-02 19:56:58 UTC (rev 243754)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm	2019-04-02 19:59:55 UTC (rev 243755)
@@ -36,6 +36,7 @@
 #import "WHLSLVertexBufferIndexCalculator.h"
 #import <Metal/Metal.h>
 #import <wtf/BlockObjCExceptions.h>
+#import <wtf/OptionSet.h>
 #import <wtf/Optional.h>
 
 namespace WebCore {
@@ -367,15 +368,95 @@
     return true;
 }
 
-static bool trySetColorStatesForColorAttachmentArray(MTLRenderPipelineColorAttachmentDescriptorArray* array, const Vector<GPUColorStateDescriptor>& colorStates)
+static MTLColorWriteMask mtlColorWriteMaskForGPUColorWriteFlags(GPUColorWriteFlags flags)
 {
-    // FIXME: Implement and validate the rest of GPUColorStateDescriptor.
-    for (unsigned i = 0; i < colorStates.size(); ++i)
-        [array[i] setPixelFormat:static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(colorStates[i].format))];
+    if (flags == static_cast<GPUColorWriteFlags>(GPUColorWriteBits::Flags::All))
+        return MTLColorWriteMaskAll;
 
-    return true;
+    auto options = OptionSet<GPUColorWriteBits::Flags>::fromRaw(flags);
+
+    MTLColorWriteMask mask = MTLColorWriteMaskNone;
+    if (options & GPUColorWriteBits::Flags::Red)
+        mask |= MTLColorWriteMaskRed;
+    if (options & GPUColorWriteBits::Flags::Green)
+        mask |= MTLColorWriteMaskGreen;
+    if (options & GPUColorWriteBits::Flags::Blue)
+        mask |= MTLColorWriteMaskBlue;
+    if (options & GPUColorWriteBits::Flags::Alpha)
+        mask |= MTLColorWriteMaskAlpha;
+
+    return mask;
 }
 
+static MTLBlendOperation mtlBlendOperationForGPUBlendOperation(GPUBlendOperation op)
+{
+    switch (op) {
+    case GPUBlendOperation::Add:
+        return MTLBlendOperationAdd;
+    case GPUBlendOperation::Subtract:
+        return MTLBlendOperationSubtract;
+    case GPUBlendOperation::ReverseSubtract:
+        return MTLBlendOperationReverseSubtract;
+    case GPUBlendOperation::Min:
+        return MTLBlendOperationMin;
+    case GPUBlendOperation::Max:
+        return MTLBlendOperationMax;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+static MTLBlendFactor mtlBlendFactorForGPUBlendFactor(GPUBlendFactor factor)
+{
+    switch (factor) {
+    case GPUBlendFactor::Zero:
+        return MTLBlendFactorZero;
+    case GPUBlendFactor::One:
+        return MTLBlendFactorOne;
+    case GPUBlendFactor::SrcColor:
+        return MTLBlendFactorSourceColor;
+    case GPUBlendFactor::OneMinusSrcColor:
+        return MTLBlendFactorOneMinusSourceColor;
+    case GPUBlendFactor::SrcAlpha:
+        return MTLBlendFactorSourceAlpha;
+    case GPUBlendFactor::OneMinusSrcAlpha:
+        return MTLBlendFactorOneMinusSourceAlpha;
+    case GPUBlendFactor::DstColor:
+        return MTLBlendFactorDestinationColor;
+    case GPUBlendFactor::OneMinusDstColor:
+        return MTLBlendFactorOneMinusDestinationColor;
+    case GPUBlendFactor::DstAlpha:
+        return MTLBlendFactorDestinationAlpha;
+    case GPUBlendFactor::OneMinusDstAlpha:
+        return MTLBlendFactorOneMinusDestinationAlpha;
+    case GPUBlendFactor::SrcAlphaSaturated:
+        return MTLBlendFactorSourceAlpha;
+    case GPUBlendFactor::BlendColor:
+        return MTLBlendFactorBlendColor;
+    case GPUBlendFactor::OneMinusBlendColor:
+        return MTLBlendFactorOneMinusBlendColor;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+static void setColorStatesForColorAttachmentArray(MTLRenderPipelineColorAttachmentDescriptorArray* array, const Vector<GPUColorStateDescriptor>& colorStates)
+{
+    for (unsigned i = 0; i < colorStates.size(); ++i) {
+        auto& state = colorStates[i];
+        auto descriptor = retainPtr([array objectAtIndexedSubscript:i]);
+        [descriptor setPixelFormat:static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(state.format))];
+        [descriptor setWriteMask:mtlColorWriteMaskForGPUColorWriteFlags(state.writeMask)];
+        [descriptor setBlendingEnabled:YES];
+        [descriptor setAlphaBlendOperation:mtlBlendOperationForGPUBlendOperation(state.alphaBlend.operation)];
+        [descriptor setRgbBlendOperation:mtlBlendOperationForGPUBlendOperation(state.colorBlend.operation)];
+        [descriptor setDestinationAlphaBlendFactor:mtlBlendFactorForGPUBlendFactor(state.alphaBlend.dstFactor)];
+        [descriptor setDestinationRGBBlendFactor:mtlBlendFactorForGPUBlendFactor(state.colorBlend.dstFactor)];
+        [descriptor setSourceAlphaBlendFactor:mtlBlendFactorForGPUBlendFactor(state.alphaBlend.srcFactor)];
+        [descriptor setSourceRGBBlendFactor:mtlBlendFactorForGPUBlendFactor(state.colorBlend.srcFactor)];
+    }
+}
+
 static RetainPtr<MTLRenderPipelineState> tryCreateMtlRenderPipelineState(const char* const functionName, const GPURenderPipelineDescriptor& descriptor, const GPUDevice& device)
 {
     RetainPtr<MTLRenderPipelineDescriptor> mtlDescriptor;
@@ -391,17 +472,17 @@
         return nullptr;
     }
 
-    bool didSetFunctions = false, didSetInputState = false, didSetColorStates = false;
+    bool didSetFunctions = false, didSetInputState = false;
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     didSetFunctions = trySetFunctionsForPipelineDescriptor(functionName, mtlDescriptor.get(), descriptor, device);
     didSetInputState = trySetInputStateForPipelineDescriptor(functionName, mtlDescriptor.get(), descriptor.inputState);
-    didSetColorStates = trySetColorStatesForColorAttachmentArray(mtlDescriptor.get().colorAttachments, descriptor.colorStates);
+    setColorStatesForColorAttachmentArray(mtlDescriptor.get().colorAttachments, descriptor.colorStates);
 
     END_BLOCK_OBJC_EXCEPTIONS;
 
-    if (!didSetFunctions || !didSetInputState || !didSetColorStates)
+    if (!didSetFunctions || !didSetInputState)
         return nullptr;
 
     RetainPtr<MTLRenderPipelineState> pipeline;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to