⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243755 in webkit


Ignore:
Timestamp:
Apr 2, 2019, 12:59:55 PM (7 years ago)
Author:
Justin Fan
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:
Location:
trunk
Files:
4 added
20 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243752 r243755  
     12019-04-02  Justin Fan  <justin_fan@apple.com>
     2
     3        [Web GPU] Implement blend states and color write mask for  GPUColorStateDescriptor
     4        https://bugs.webkit.org/show_bug.cgi?id=196474
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Add blend-triangle-strip to test color blending and color-write-mask-triangle-strip.html to test color write mask.
     9        Update other tests to specify blend states when creating a GPURenderPipeline.
     10
     11        * webgpu/blend-triangle-strip-expected.html: Added.
     12        * webgpu/blend-triangle-strip.html: Added.
     13        * webgpu/buffer-command-buffer-races.html:
     14        * webgpu/buffer-resource-triangles.html:
     15        * webgpu/color-write-mask-triangle-strip-expected.html: Added.
     16        * webgpu/color-write-mask-triangle-strip.html: Added.
     17        * webgpu/depth-enabled-triangle-strip.html:
     18        * webgpu/js/webgpu-functions.js:
     19        * webgpu/render-pipelines.html:
     20        * webgpu/texture-triangle-strip.html:
     21        * webgpu/vertex-buffer-triangle-strip.html:
     22        * webgpu/whlsl.html:
     23
    1242019-04-02  Zalan Bujtas  <zalan@apple.com>
    225
  • trunk/LayoutTests/webgpu/buffer-command-buffer-races.html

    r243089 r243755  
    9393    const shaderModule = device.createShaderModule({ code: shaderCode });
    9494    const inputStateDescriptor = createInputStateDescriptor();
    95     const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor);
     95    const pipeline = createBasicPipeline(shaderModule, device, null, null, inputStateDescriptor);
    9696
    9797    const upperLeftBuffer = createAndSetVertexBuffer(device, [-1, 1, -1, -1, 0, 1]);
  • trunk/LayoutTests/webgpu/buffer-resource-triangles.html

    r242974 r243755  
    166166    // WebGPUPipelineLayout and WebGPURenderPipeline
    167167    const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [leftTriangleBGLayout, rightTriangleBGLayout] });
    168     const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputState, null, "triangle-list");
     168    const pipeline = createBasicPipeline(shaderModule, device, null, pipelineLayout, inputState, null, "triangle-list");
    169169
    170170    // WebGPUBufferBindings
  • trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html

    r243089 r243755  
    8989    const inputStateDescriptor = createInputStateDescriptor();
    9090    const depthStateDescriptor = createBasicDepthStateDescriptor();
    91     const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor, depthStateDescriptor);
     91    const pipeline = createBasicPipeline(shaderModule, device, null, null, inputStateDescriptor, depthStateDescriptor);
    9292    const commandEncoder = device.createCommandEncoder();
    9393
  • trunk/LayoutTests/webgpu/js/webgpu-functions.js

    r243090 r243755  
    3535}
    3636
    37 function createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor, depthStateDescriptor, primitiveTopology = "triangle-strip") {
     37function createBasicPipeline(shaderModule, device, colorStates, pipelineLayout, inputStateDescriptor, depthStateDescriptor, primitiveTopology = "triangle-strip") {
    3838    const vertexStageDescriptor = {
    3939        module: shaderModule,
     
    4646    };
    4747
    48     const basicColorState = { format: "bgra8unorm" };
     48    if (!colorStates) {
     49        colorStates = [{
     50            format: "bgra8unorm",
     51            alphaBlend: {
     52                srcFactor: "one",
     53                dstFactor: "zero",
     54                operation: "add"
     55            },
     56            colorBlend: {
     57                srcFactor: "one",
     58                dstFactor: "zero",
     59                operation: "add"
     60            },
     61            writeMask: GPUColorWriteBits.ALL
     62        }];
     63    }
    4964
    5065    const pipelineDescriptor = {
     
    5267        fragmentStage: fragmentStageDescriptor,
    5368        primitiveTopology: primitiveTopology,
    54         colorStates: [basicColorState]
     69        colorStates: colorStates
    5570    };
    5671
  • trunk/LayoutTests/webgpu/render-pipelines.html

    r243456 r243755  
    4848    const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] });
    4949
    50     const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout);
     50    const pipeline = createBasicPipeline(shaderModule, device, null, pipelineLayout);
    5151    assert_true(pipeline instanceof WebGPURenderPipeline, "Successfully created WebGPURenderPipeline");
    5252}, "Create basic WebGPURenderPipeline");
  • trunk/LayoutTests/webgpu/texture-triangle-strip.html

    r243089 r243755  
    186186
    187187    // Pipeline and render
    188     const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor);
     188    const pipeline = createBasicPipeline(shaderModule, device, null, pipelineLayout, inputStateDescriptor);
    189189    const commandEncoder = device.createCommandEncoder();
    190190
  • trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html

    r242974 r243755  
    9191    const vertexBuffer = createVertexBuffer(device);
    9292    const inputStateDescriptor = createInputStateDescriptor();
    93     const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor);
     93    const pipeline = createBasicPipeline(shaderModule, device, null, null, inputStateDescriptor);
    9494    const commandEncoder = device.createCommandEncoder();
    9595    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
  • trunk/LayoutTests/webgpu/whlsl.html

    r243627 r243755  
    2424    const primitiveTopology = "triangle-strip";
    2525    const rasterizationState = {frontFace: "cw", cullMode: "none"};
    26     const alphaBlend = {srcFactor: "zero", dstFactor: "one", operation: "add"};
    27     const colorBlend = {srcFactor: "zero", dstFactor: "one", operation: "add"};
     26    const alphaBlend = {srcFactor: "one", dstFactor: "zero", operation: "add"};
     27    const colorBlend = {srcFactor: "one", dstFactor: "zero", operation: "add"};
    2828    const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL
    2929    const depthStencilState = null;
  • trunk/Source/WebCore/CMakeLists.txt

    r243666 r243755  
    466466    Modules/webgpu/GPUBindGroupLayoutBinding.idl
    467467    Modules/webgpu/GPUBindGroupLayoutDescriptor.idl
     468    Modules/webgpu/GPUBlendDescriptor.idl
    468469    Modules/webgpu/GPUBufferDescriptor.idl
    469470    Modules/webgpu/GPUBufferUsage.idl
     
    471472    Modules/webgpu/GPUColor.idl
    472473    Modules/webgpu/GPUColorStateDescriptor.idl
     474    Modules/webgpu/GPUColorWriteBits.idl
    473475    Modules/webgpu/GPUCompareFunction.idl
    474476    Modules/webgpu/GPUDepthStencilStateDescriptor.idl
  • trunk/Source/WebCore/ChangeLog

    r243752 r243755  
     12019-04-02  Justin Fan  <justin_fan@apple.com>
     2
     3        [Web GPU] Implement blend states and color write mask for GPUColorStateDescriptor
     4        https://bugs.webkit.org/show_bug.cgi?id=196474
     5
     6        Reviewed by Myles C. Maxfield.
     7
     8        Blend states and color write masks must now be specified on GPUColorStateDescriptor instead of
     9        relying on underlying MTLRenderPipelineColorAttachmentDescriptor defaults.
     10
     11        Test: webgpu/blend-triangle-strip.html, webgpu/color-write-mask-triangle-strip.html
     12
     13        * CMakeLists.txt:
     14        * DerivedSources-input.xcfilelist:
     15        * DerivedSources-output.xcfilelist:
     16        * DerivedSources.make:
     17        * Modules/webgpu/GPUBlendDescriptor.idl:
     18        * Modules/webgpu/GPUColorStateDescriptor.idl:
     19        * Modules/webgpu/GPUColorWriteBits.idl:
     20        * Sources.txt:
     21        * WebCore.xcodeproj/project.pbxproj:
     22        * bindings/js/WebCoreBuiltinNames.h:
     23        * platform/graphics/gpu/GPUBlendDescriptor.h:
     24        * platform/graphics/gpu/GPUColorStateDescriptor.h:
     25        * platform/graphics/gpu/GPUColorWriteBits.h:
     26        * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
     27        (WebCore::mtlColorWriteMaskForGPUColorWriteFlags):
     28        (WebCore::mtlBlendOperationForGPUBlendOperation):
     29        (WebCore::mtlBlendFactorForGPUBlendFactor):
     30        (WebCore::setColorStatesForColorAttachmentArray):
     31        (WebCore::tryCreateMtlRenderPipelineState):
     32        (WebCore::trySetColorStatesForColorAttachmentArray): Deleted.
     33
    1342019-04-02  Zalan Bujtas  <zalan@apple.com>
    235
  • trunk/Source/WebCore/DerivedSources-input.xcfilelist

    r243666 r243755  
    331331$(PROJECT_DIR)/Modules/webgpu/GPUBindGroupLayoutBinding.idl
    332332$(PROJECT_DIR)/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl
     333$(PROJECT_DIR)/Modules/webgpu/GPUBlendDescriptor.idl
    333334$(PROJECT_DIR)/Modules/webgpu/GPUBufferDescriptor.idl
    334335$(PROJECT_DIR)/Modules/webgpu/GPUBufferUsage.idl
     
    336337$(PROJECT_DIR)/Modules/webgpu/GPUColor.idl
    337338$(PROJECT_DIR)/Modules/webgpu/GPUColorStateDescriptor.idl
     339$(PROJECT_DIR)/Modules/webgpu/GPUColorWriteBits.idl
    338340$(PROJECT_DIR)/Modules/webgpu/GPUCompareFunction.idl
    339341$(PROJECT_DIR)/Modules/webgpu/GPUDepthStencilStateDescriptor.idl
  • trunk/Source/WebCore/DerivedSources-output.xcfilelist

    r243666 r243755  
    588588$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutDescriptor.cpp
    589589$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBindGroupLayoutDescriptor.h
     590$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBlendDescriptor.cpp
     591$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBlendDescriptor.h
    590592$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.cpp
    591593$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUBufferDescriptor.h
     
    598600$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorStateDescriptor.cpp
    599601$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorStateDescriptor.h
     602$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorWriteBits.cpp
     603$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUColorWriteBits.h
    600604$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUCompareFunction.cpp
    601605$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSGPUCompareFunction.h
  • trunk/Source/WebCore/DerivedSources.make

    r243666 r243755  
    379379    $(WebCore)/Modules/webgpu/GPUColor.idl \
    380380    $(WebCore)/Modules/webgpu/GPUColorStateDescriptor.idl \
     381    $(WebCore)/Modules/webgpu/GPUColorWriteBits.idl \
    381382    $(WebCore)/Modules/webgpu/GPUBindGroupLayoutBinding.idl \
    382383    $(WebCore)/Modules/webgpu/GPUBindGroupLayoutDescriptor.idl \
     384    $(WebCore)/Modules/webgpu/GPUBlendDescriptor.idl \
    383385    $(WebCore)/Modules/webgpu/GPUBufferDescriptor.idl \
    384386    $(WebCore)/Modules/webgpu/GPUBufferUsage.idl \
  • trunk/Source/WebCore/Modules/webgpu/GPUBlendDescriptor.idl

    r243754 r243755  
    2626
    2727[
     28    ImplementedAs=GPUBlendFactor
     29] enum GPUBlendFactor {
     30    "zero",
     31    "one",
     32    "src-color",
     33    "one-minus-src-color",
     34    "src-alpha",
     35    "one-minus-src-alpha",
     36    "dst-color",
     37    "one-minus-dst-color",
     38    "dst-alpha",
     39    "one-minus-dst-alpha",
     40    "src-alpha-saturated",
     41    "blend-color",
     42    "one-minus-blend-color"
     43};
     44
     45[
     46    ImplementedAs=GPUBlendOperation
     47] enum GPUBlendOperation {
     48    "add",
     49    "subtract",
     50    "reverse-subtract",
     51    "min",
     52    "max"
     53};
     54
     55[
    2856    Conditional=WEBGPU,
    2957    EnabledAtRuntime=WebGPU
    30 ] dictionary GPUColorStateDescriptor {
    31     GPUTextureFormat format;
    32 
    33     // Not yet implemented.
    34     // GPUBlendDescriptor alphaBlend;
    35     // GPUBlendDescriptor colorBlend;
    36     // GPUColorWriteFlags writeMask;
     58] dictionary GPUBlendDescriptor {
     59    GPUBlendFactor srcFactor;
     60    GPUBlendFactor dstFactor;
     61    GPUBlendOperation operation;
    3762};
  • trunk/Source/WebCore/Modules/webgpu/GPUColorStateDescriptor.idl

    r242839 r243755  
    2525// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
    2626
     27typedef unsigned long GPUColorWriteFlags;
     28
    2729[
    2830    Conditional=WEBGPU,
     
    3133    GPUTextureFormat format;
    3234
    33     // Not yet implemented.
    34     // GPUBlendDescriptor alphaBlend;
    35     // GPUBlendDescriptor colorBlend;
    36     // GPUColorWriteFlags writeMask;
     35    GPUBlendDescriptor alphaBlend;
     36    GPUBlendDescriptor colorBlend;
     37    GPUColorWriteFlags writeMask;
    3738};
  • trunk/Source/WebCore/Modules/webgpu/GPUColorWriteBits.idl

    r243754 r243755  
    2525// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
    2626
     27typedef unsigned long u32;
     28
    2729[
    2830    Conditional=WEBGPU,
    29     EnabledAtRuntime=WebGPU
    30 ] dictionary GPUColorStateDescriptor {
    31     GPUTextureFormat format;
    32 
    33     // Not yet implemented.
    34     // GPUBlendDescriptor alphaBlend;
    35     // GPUBlendDescriptor colorBlend;
    36     // GPUColorWriteFlags writeMask;
     31    DoNotCheckConstants,
     32    EnabledAtRuntime=WebGPU,
     33    ImplementationLacksVTable
     34] interface GPUColorWriteBits {
     35    const u32 NONE = 0;
     36    const u32 RED = 1;
     37    const u32 GREEN = 2;
     38    const u32 BLUE = 4;
     39    const u32 ALPHA = 8;
     40    const u32 ALL = 15;
    3741};
  • trunk/Source/WebCore/Sources.txt

    r243730 r243755  
    27212721JSGPUColor.cpp
    27222722JSGPUColorStateDescriptor.cpp
     2723JSGPUColorWriteBits.cpp
    27232724JSGPUBindGroupLayoutBinding.cpp
    27242725JSGPUBindGroupLayoutDescriptor.cpp
     2726JSGPUBlendDescriptor.cpp
    27252727JSGPUBufferDescriptor.cpp
    27262728JSGPUBufferUsage.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r243730 r243755  
    1395813958                D0B0556609C6700100307E43 /* CreateLinkCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CreateLinkCommand.h; sourceTree = "<group>"; };
    1395913959                D0B0556709C6700100307E43 /* CreateLinkCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CreateLinkCommand.cpp; sourceTree = "<group>"; };
     13960                D0B56EAA224EC6240061049C /* GPUBlendDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBlendDescriptor.h; sourceTree = "<group>"; };
     13961                D0B56EAB224EC6240061049C /* GPUBlendDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUBlendDescriptor.idl; sourceTree = "<group>"; };
     13962                D0B56EAD224ECE200061049C /* GPUColorWriteBits.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUColorWriteBits.h; sourceTree = "<group>"; };
     13963                D0B56EAE224ECE200061049C /* GPUColorWriteBits.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUColorWriteBits.idl; sourceTree = "<group>"; };
    1396013964                D0B8BB0121C46E78000C7681 /* GPUBindGroupLayoutBinding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayoutBinding.h; sourceTree = "<group>"; };
    1396113965                D0BC54481443AC4A00E105DA /* CachedStyleSheetClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedStyleSheetClient.h; sourceTree = "<group>"; };
     
    1821418218                                D0BE105121E6A70E00E42A89 /* GPUBindGroupDescriptor.h */,
    1821518219                                D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */,
     18220                                D0B56EAA224EC6240061049C /* GPUBlendDescriptor.h */,
    1821618221                                D084033A221CBF5400007205 /* GPUBuffer.cpp */,
    1821718222                                D0D8649221B760F2003C983C /* GPUBuffer.h */,
     
    1822118226                                D001D9AB21B0C7BF0023B9BC /* GPUColor.h */,
    1822218227                                D0ADB28B2237842E00A22935 /* GPUColorStateDescriptor.h */,
     18228                                D0B56EAD224ECE200061049C /* GPUColorWriteBits.h */,
    1822318229                                312FF8BD21A4C2F100EB199D /* GPUCommandBuffer.h */,
    1822418230                                D03C849C21FFC7FC0002227F /* GPUCompareFunction.h */,
     
    2577925785                                D0D69C9C222E00C20032927E /* GPUBindGroupLayoutDescriptor.h */,
    2578025786                                D0D69C9D222E00C20032927E /* GPUBindGroupLayoutDescriptor.idl */,
     25787                                D0B56EAB224EC6240061049C /* GPUBlendDescriptor.idl */,
    2578125788                                D01B811922135EB900627B6C /* GPUBufferDescriptor.idl */,
    2578225789                                D01B811C2213627300627B6C /* GPUBufferUsage.idl */,
     
    2578625793                                D01B811222125AFC00627B6C /* GPUColor.idl */,
    2578725794                                D0ADB28C2237842E00A22935 /* GPUColorStateDescriptor.idl */,
     25795                                D0B56EAE224ECE200061049C /* GPUColorWriteBits.idl */,
    2578825796                                D03C849E21FFCF000002227F /* GPUCompareFunction.idl */,
    2578925797                                D03C84A221FFD7230002227F /* GPUDepthStencilStateDescriptor.idl */,
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r243666 r243755  
    8484    macro(GPUBufferUsage) \
    8585    macro(GPUCanvasContext) \
    86     macro(GPUShaderModule) \
     86    macro(GPUColorWriteBits) \
    8787    macro(GPUCommandBuffer) \
    8888    macro(GPUCommandEncoder) \
    8989    macro(GPUComputePassEncoder) \
    9090    macro(GPUComputePipeline) \
     91    macro(GPUShaderModule) \
    9192    macro(GPUShaderStageBit) \
    9293    macro(GPUSwapChain) \
  • trunk/Source/WebCore/platform/graphics/gpu/GPUBlendDescriptor.h

    r243754 r243755  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "GPUTextureFormat.h"
    31 
    3230namespace WebCore {
    3331
    34 struct GPUColorStateDescriptor {
    35     GPUTextureFormat format;
     32enum class GPUBlendFactor {
     33    Zero,
     34    One,
     35    SrcColor,
     36    OneMinusSrcColor,
     37    SrcAlpha,
     38    OneMinusSrcAlpha,
     39    DstColor,
     40    OneMinusDstColor,
     41    DstAlpha,
     42    OneMinusDstAlpha,
     43    SrcAlphaSaturated,
     44    BlendColor,
     45    OneMinusBlendColor,
     46};
     47
     48enum class GPUBlendOperation {
     49    Add,
     50    Subtract,
     51    ReverseSubtract,
     52    Min,
     53    Max,
     54};
     55
     56struct GPUBlendDescriptor {
     57    GPUBlendFactor srcFactor;
     58    GPUBlendFactor dstFactor;
     59    GPUBlendOperation operation;
    3660};
    3761
  • trunk/Source/WebCore/platform/graphics/gpu/GPUColorStateDescriptor.h

    r242839 r243755  
    2828#if ENABLE(WEBGPU)
    2929
     30#include "GPUBlendDescriptor.h"
     31#include "GPUColorWriteBits.h"
    3032#include "GPUTextureFormat.h"
    3133
     
    3436struct GPUColorStateDescriptor {
    3537    GPUTextureFormat format;
     38
     39    GPUBlendDescriptor alphaBlend;
     40    GPUBlendDescriptor colorBlend;
     41    GPUColorWriteFlags writeMask;
    3642};
    3743
  • trunk/Source/WebCore/platform/graphics/gpu/GPUColorWriteBits.h

    r243754 r243755  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "GPUTextureFormat.h"
     30#include <wtf/RefCounted.h>
    3131
    3232namespace WebCore {
    3333
    34 struct GPUColorStateDescriptor {
    35     GPUTextureFormat format;
     34using GPUColorWriteFlags = unsigned;
     35
     36class GPUColorWriteBits : public RefCounted<GPUColorWriteBits> {
     37public:
     38    enum class Flags : GPUColorWriteFlags {
     39        None = 0,
     40        Red = 1 << 0,
     41        Green = 1 << 1,
     42        Blue = 1 << 2,
     43        Alpha = 1 << 3,
     44        All = (1 << 4) - 1,
     45    };
    3646};
    3747
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm

    r243636 r243755  
    3737#import <Metal/Metal.h>
    3838#import <wtf/BlockObjCExceptions.h>
     39#import <wtf/OptionSet.h>
    3940#import <wtf/Optional.h>
    4041
     
    368369}
    369370
    370 static bool trySetColorStatesForColorAttachmentArray(MTLRenderPipelineColorAttachmentDescriptorArray* array, const Vector<GPUColorStateDescriptor>& colorStates)
    371 {
    372     // FIXME: Implement and validate the rest of GPUColorStateDescriptor.
    373     for (unsigned i = 0; i < colorStates.size(); ++i)
    374         [array[i] setPixelFormat:static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(colorStates[i].format))];
    375 
    376     return true;
     371static MTLColorWriteMask mtlColorWriteMaskForGPUColorWriteFlags(GPUColorWriteFlags flags)
     372{
     373    if (flags == static_cast<GPUColorWriteFlags>(GPUColorWriteBits::Flags::All))
     374        return MTLColorWriteMaskAll;
     375
     376    auto options = OptionSet<GPUColorWriteBits::Flags>::fromRaw(flags);
     377
     378    MTLColorWriteMask mask = MTLColorWriteMaskNone;
     379    if (options & GPUColorWriteBits::Flags::Red)
     380        mask |= MTLColorWriteMaskRed;
     381    if (options & GPUColorWriteBits::Flags::Green)
     382        mask |= MTLColorWriteMaskGreen;
     383    if (options & GPUColorWriteBits::Flags::Blue)
     384        mask |= MTLColorWriteMaskBlue;
     385    if (options & GPUColorWriteBits::Flags::Alpha)
     386        mask |= MTLColorWriteMaskAlpha;
     387
     388    return mask;
     389}
     390
     391static MTLBlendOperation mtlBlendOperationForGPUBlendOperation(GPUBlendOperation op)
     392{
     393    switch (op) {
     394    case GPUBlendOperation::Add:
     395        return MTLBlendOperationAdd;
     396    case GPUBlendOperation::Subtract:
     397        return MTLBlendOperationSubtract;
     398    case GPUBlendOperation::ReverseSubtract:
     399        return MTLBlendOperationReverseSubtract;
     400    case GPUBlendOperation::Min:
     401        return MTLBlendOperationMin;
     402    case GPUBlendOperation::Max:
     403        return MTLBlendOperationMax;
     404    }
     405
     406    ASSERT_NOT_REACHED();
     407}
     408
     409static MTLBlendFactor mtlBlendFactorForGPUBlendFactor(GPUBlendFactor factor)
     410{
     411    switch (factor) {
     412    case GPUBlendFactor::Zero:
     413        return MTLBlendFactorZero;
     414    case GPUBlendFactor::One:
     415        return MTLBlendFactorOne;
     416    case GPUBlendFactor::SrcColor:
     417        return MTLBlendFactorSourceColor;
     418    case GPUBlendFactor::OneMinusSrcColor:
     419        return MTLBlendFactorOneMinusSourceColor;
     420    case GPUBlendFactor::SrcAlpha:
     421        return MTLBlendFactorSourceAlpha;
     422    case GPUBlendFactor::OneMinusSrcAlpha:
     423        return MTLBlendFactorOneMinusSourceAlpha;
     424    case GPUBlendFactor::DstColor:
     425        return MTLBlendFactorDestinationColor;
     426    case GPUBlendFactor::OneMinusDstColor:
     427        return MTLBlendFactorOneMinusDestinationColor;
     428    case GPUBlendFactor::DstAlpha:
     429        return MTLBlendFactorDestinationAlpha;
     430    case GPUBlendFactor::OneMinusDstAlpha:
     431        return MTLBlendFactorOneMinusDestinationAlpha;
     432    case GPUBlendFactor::SrcAlphaSaturated:
     433        return MTLBlendFactorSourceAlpha;
     434    case GPUBlendFactor::BlendColor:
     435        return MTLBlendFactorBlendColor;
     436    case GPUBlendFactor::OneMinusBlendColor:
     437        return MTLBlendFactorOneMinusBlendColor;
     438    }
     439
     440    ASSERT_NOT_REACHED();
     441}
     442
     443static void setColorStatesForColorAttachmentArray(MTLRenderPipelineColorAttachmentDescriptorArray* array, const Vector<GPUColorStateDescriptor>& colorStates)
     444{
     445    for (unsigned i = 0; i < colorStates.size(); ++i) {
     446        auto& state = colorStates[i];
     447        auto descriptor = retainPtr([array objectAtIndexedSubscript:i]);
     448        [descriptor setPixelFormat:static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(state.format))];
     449        [descriptor setWriteMask:mtlColorWriteMaskForGPUColorWriteFlags(state.writeMask)];
     450        [descriptor setBlendingEnabled:YES];
     451        [descriptor setAlphaBlendOperation:mtlBlendOperationForGPUBlendOperation(state.alphaBlend.operation)];
     452        [descriptor setRgbBlendOperation:mtlBlendOperationForGPUBlendOperation(state.colorBlend.operation)];
     453        [descriptor setDestinationAlphaBlendFactor:mtlBlendFactorForGPUBlendFactor(state.alphaBlend.dstFactor)];
     454        [descriptor setDestinationRGBBlendFactor:mtlBlendFactorForGPUBlendFactor(state.colorBlend.dstFactor)];
     455        [descriptor setSourceAlphaBlendFactor:mtlBlendFactorForGPUBlendFactor(state.alphaBlend.srcFactor)];
     456        [descriptor setSourceRGBBlendFactor:mtlBlendFactorForGPUBlendFactor(state.colorBlend.srcFactor)];
     457    }
    377458}
    378459
     
    392473    }
    393474
    394     bool didSetFunctions = false, didSetInputState = false, didSetColorStates = false;
     475    bool didSetFunctions = false, didSetInputState = false;
    395476
    396477    BEGIN_BLOCK_OBJC_EXCEPTIONS;
     
    398479    didSetFunctions = trySetFunctionsForPipelineDescriptor(functionName, mtlDescriptor.get(), descriptor, device);
    399480    didSetInputState = trySetInputStateForPipelineDescriptor(functionName, mtlDescriptor.get(), descriptor.inputState);
    400     didSetColorStates = trySetColorStatesForColorAttachmentArray(mtlDescriptor.get().colorAttachments, descriptor.colorStates);
     481    setColorStatesForColorAttachmentArray(mtlDescriptor.get().colorAttachments, descriptor.colorStates);
    401482
    402483    END_BLOCK_OBJC_EXCEPTIONS;
    403484
    404     if (!didSetFunctions || !didSetInputState || !didSetColorStates)
     485    if (!didSetFunctions || !didSetInputState)
    405486        return nullptr;
    406487
Note: See TracChangeset for help on using the changeset viewer.