Changeset 213650 in webkit


Ignore:
Timestamp:
Mar 9, 2017 11:02:11 AM (7 years ago)
Author:
dino@apple.com
Message:

WebGPU: Backend - Library and Functions
https://bugs.webkit.org/show_bug.cgi?id=169371
<rdar://problem/30928792>

Reviewed by Tim Horton.

Source/WebCore:

Implement the backends for GPULibrary and GPUFunction.
A GPULibrary is created from a GPUDevice, given some
shader source code. You can then extract the GPUFunctions
from the library.

WebKitAPITests: GPULibrary and GPUFunction.

  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/cocoa/GPUFunctionMetal.mm:

(WebCore::GPUFunction::GPUFunction):
(WebCore::GPUFunction::name):
(WebCore::GPUFunction::platformFunction):

  • platform/graphics/cocoa/GPULibraryMetal.mm:

(WebCore::GPULibrary::GPULibrary):
(WebCore::GPULibrary::label):
(WebCore::GPULibrary::setLabel):
(WebCore::GPULibrary::functionNames):
(WebCore::GPULibrary::platformLibrary):

  • platform/graphics/gpu/GPUDevice.cpp:

(WebCore::GPUDevice::createLibrary):

  • platform/graphics/gpu/GPUDevice.h:
  • platform/graphics/gpu/GPUFunction.cpp:

(WebCore::GPUFunction::create):
(WebCore::GPUFunction::~GPUFunction):
(WebCore::GPUFunction::GPUFunction):
(WebCore::GPUFunction::name):

  • platform/graphics/gpu/GPUFunction.h:
  • platform/graphics/gpu/GPULibrary.cpp:

(WebCore::GPULibrary::create):
(WebCore::GPULibrary::~GPULibrary):
(WebCore::GPULibrary::label):
(WebCore::GPULibrary::setLabel):
(WebCore::GPULibrary::functionNames):
(WebCore::GPULibrary::functionWithName):

  • platform/graphics/gpu/GPULibrary.h:

Tools:

Add tests for GPULibrary and GPUFunction.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm:

(TestWebKitAPI::TEST_F):
(TestWebKitAPI::TEST): Deleted.

  • TestWebKitAPI/Tests/WebCore/mac/GPUFunction.mm: Copied from Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm.

(TestWebKitAPI::TEST_F):

  • TestWebKitAPI/Tests/WebCore/mac/GPULibrary.mm: Copied from Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm.

(TestWebKitAPI::TEST_F):

  • TestWebKitAPI/Tests/WebCore/mac/GPUTest.h: Copied from Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm.

(TestWebKitAPI::GPU::librarySourceCode):

Location:
trunk
Files:
8 edited
9 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r213646 r213650  
     12017-03-08  Dean Jackson  <dino@apple.com>
     2
     3        WebGPU: Backend - Library and Functions
     4        https://bugs.webkit.org/show_bug.cgi?id=169371
     5        <rdar://problem/30928792>
     6
     7        Reviewed by Tim Horton.
     8
     9        Implement the backends for GPULibrary and GPUFunction.
     10        A GPULibrary is created from a GPUDevice, given some
     11        shader source code. You can then extract the GPUFunctions
     12        from the library.
     13
     14        WebKitAPITests: GPULibrary and GPUFunction.
     15
     16        * WebCore.xcodeproj/project.pbxproj:
     17        * platform/graphics/cocoa/GPUFunctionMetal.mm:
     18        (WebCore::GPUFunction::GPUFunction):
     19        (WebCore::GPUFunction::name):
     20        (WebCore::GPUFunction::platformFunction):
     21        * platform/graphics/cocoa/GPULibraryMetal.mm:
     22        (WebCore::GPULibrary::GPULibrary):
     23        (WebCore::GPULibrary::label):
     24        (WebCore::GPULibrary::setLabel):
     25        (WebCore::GPULibrary::functionNames):
     26        (WebCore::GPULibrary::platformLibrary):
     27        * platform/graphics/gpu/GPUDevice.cpp:
     28        (WebCore::GPUDevice::createLibrary):
     29        * platform/graphics/gpu/GPUDevice.h:
     30        * platform/graphics/gpu/GPUFunction.cpp:
     31        (WebCore::GPUFunction::create):
     32        (WebCore::GPUFunction::~GPUFunction):
     33        (WebCore::GPUFunction::GPUFunction):
     34        (WebCore::GPUFunction::name):
     35        * platform/graphics/gpu/GPUFunction.h:
     36        * platform/graphics/gpu/GPULibrary.cpp:
     37        (WebCore::GPULibrary::create):
     38        (WebCore::GPULibrary::~GPULibrary):
     39        (WebCore::GPULibrary::label):
     40        (WebCore::GPULibrary::setLabel):
     41        (WebCore::GPULibrary::functionNames):
     42        (WebCore::GPULibrary::functionWithName):
     43        * platform/graphics/gpu/GPULibrary.h:
     44
    1452017-03-09  Chris Dumez  <cdumez@apple.com>
    246
  • trunk/Source/WebCore/PlatformMac.cmake

    r213624 r213650  
    418418
    419419    platform/graphics/cocoa/GPUDeviceMetal.mm
     420    platform/graphics/cocoa/GPUFunctionMetal.mm
     421    platform/graphics/cocoa/GPULibraryMetal.mm
    420422    platform/graphics/cocoa/FontCacheCoreText.cpp
    421423    platform/graphics/cocoa/FontCascadeCocoa.mm
     
    432434
    433435    platform/graphics/gpu/GPUDevice.cpp
     436    platform/graphics/gpu/GPUFunction.cpp
     437    platform/graphics/gpu/GPULibrary.cpp
    434438
    435439    platform/graphics/mac/ColorMac.mm
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r213628 r213650  
    13601360                316BDB8C1E6E153000DE0D5A /* WebGPULayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDB8A1E6E153000DE0D5A /* WebGPULayer.h */; };
    13611361                316BDB8D1E6E189800DE0D5A /* GPUDeviceMetal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 316BDB881E6E141C00DE0D5A /* GPUDeviceMetal.mm */; };
     1362                316BDB941E70C89700DE0D5A /* GPUFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316BDB921E70C89700DE0D5A /* GPUFunction.cpp */; };
     1363                316BDB951E70C89700DE0D5A /* GPUFunction.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDB931E70C89700DE0D5A /* GPUFunction.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1364                316BDB971E70CA2400DE0D5A /* GPUFunctionMetal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 316BDB961E70CA2400DE0D5A /* GPUFunctionMetal.mm */; };
     1365                316BDB9A1E70CBBF00DE0D5A /* GPULibrary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316BDB981E70CBBF00DE0D5A /* GPULibrary.cpp */; };
     1366                316BDB9B1E70CBBF00DE0D5A /* GPULibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDB991E70CBBF00DE0D5A /* GPULibrary.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1367                316BDB9E1E70CD9000DE0D5A /* GPULibraryMetal.mm in Sources */ = {isa = PBXBuildFile; fileRef = 316BDB9C1E70CD9000DE0D5A /* GPULibraryMetal.mm */; };
    13621368                316FE0710E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316FE06D0E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp */; };
    13631369                316FE0720E6CCBEE00BF6088 /* JSCSSKeyframeRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 316FE06E0E6CCBEE00BF6088 /* JSCSSKeyframeRule.h */; };
     
    86878693                316BDB891E6E153000DE0D5A /* WebGPULayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebGPULayer.mm; sourceTree = "<group>"; };
    86888694                316BDB8A1E6E153000DE0D5A /* WebGPULayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebGPULayer.h; sourceTree = "<group>"; };
     8695                316BDB921E70C89700DE0D5A /* GPUFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GPUFunction.cpp; sourceTree = "<group>"; };
     8696                316BDB931E70C89700DE0D5A /* GPUFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUFunction.h; sourceTree = "<group>"; };
     8697                316BDB961E70CA2400DE0D5A /* GPUFunctionMetal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUFunctionMetal.mm; sourceTree = "<group>"; };
     8698                316BDB981E70CBBF00DE0D5A /* GPULibrary.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GPULibrary.cpp; sourceTree = "<group>"; };
     8699                316BDB991E70CBBF00DE0D5A /* GPULibrary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPULibrary.h; sourceTree = "<group>"; };
     8700                316BDB9C1E70CD9000DE0D5A /* GPULibraryMetal.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPULibraryMetal.mm; sourceTree = "<group>"; };
    86898701                316FE06D0E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSKeyframeRule.cpp; sourceTree = "<group>"; };
    86908702                316FE06E0E6CCBEE00BF6088 /* JSCSSKeyframeRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCSSKeyframeRule.h; sourceTree = "<group>"; };
     
    1747517487                                316BDB841E6E0A2100DE0D5A /* GPUDevice.cpp */,
    1747617488                                316BDB851E6E0A2100DE0D5A /* GPUDevice.h */,
     17489                                316BDB921E70C89700DE0D5A /* GPUFunction.cpp */,
     17490                                316BDB931E70C89700DE0D5A /* GPUFunction.h */,
     17491                                316BDB981E70CBBF00DE0D5A /* GPULibrary.cpp */,
     17492                                316BDB991E70CBBF00DE0D5A /* GPULibrary.h */,
    1747717493                                498770D71242C535002226BA /* Texture.cpp */,
    1747817494                                498770D81242C535002226BA /* Texture.h */,
     
    2256722583                                B5320D6A122A24E9002D1440 /* FontPlatformDataCocoa.mm */,
    2256822584                                316BDB881E6E141C00DE0D5A /* GPUDeviceMetal.mm */,
     22585                                316BDB961E70CA2400DE0D5A /* GPUFunctionMetal.mm */,
     22586                                316BDB9C1E70CD9000DE0D5A /* GPULibraryMetal.mm */,
    2256922587                                2D0B4AA918DA1CCD00434DE1 /* IOSurface.h */,
    2257022588                                2D0B4AAA18DA1CCD00434DE1 /* IOSurface.mm */,
     
    2620526223                                4F1534DE11B532EC0021FD86 /* EditingBehavior.h in Headers */,
    2620626224                                4F1534E011B533020021FD86 /* EditingBehaviorTypes.h in Headers */,
     26225                                316BDB9B1E70CBBF00DE0D5A /* GPULibrary.h in Headers */,
    2620726226                                3AC648B2129E146500C3EB25 /* EditingBoundary.h in Headers */,
    2620826227                                9BAB6C6C12550631001626D4 /* EditingStyle.h in Headers */,
     
    2800628025                                B56579B51824D12A00E79F23 /* RenderChildIterator.h in Headers */,
    2800728026                                BCE4413412F748E2009B84B8 /* RenderCombineText.h in Headers */,
     28027                                316BDB951E70C89700DE0D5A /* GPUFunction.h in Headers */,
    2800828028                                9392F1420AD185F400691BD4 /* RenderCounter.h in Headers */,
    2800928029                                BCEA486E097D93020094C9E4 /* RenderDeprecatedFlexibleBox.h in Headers */,
     
    3043030450                                0707568B142262D600414161 /* HTMLTrackElement.cpp in Sources */,
    3043130451                                977B37251228721700B81FF8 /* HTMLTreeBuilder.cpp in Sources */,
     30452                                316BDB941E70C89700DE0D5A /* GPUFunction.cpp in Sources */,
    3043230453                                A8EA79F30A1916DF00A8EF5F /* HTMLUListElement.cpp in Sources */,
    3043330454                                E44613AA0CD6331000FADA75 /* HTMLVideoElement.cpp in Sources */,
     
    3194931970                                073BE34F17D18183002BD431 /* RTCIceCandidateDescriptor.cpp in Sources */,
    3195031971                                078E090A17D14CEE00420AA1 /* RTCIceCandidateEvent.cpp in Sources */,
     31972                                316BDB9E1E70CD9000DE0D5A /* GPULibraryMetal.mm in Sources */,
    3195131973                                073794FD19F5864E00E5A045 /* RTCNotifiersMock.cpp in Sources */,
    3195231974                                078E090B17D14CEE00420AA1 /* RTCPeerConnection.cpp in Sources */,
     
    3231632338                                8419D2A8120D92D000141F8F /* SVGPathByteStreamBuilder.cpp in Sources */,
    3231732339                                8419D2AC120D92FC00141F8F /* SVGPathByteStreamSource.cpp in Sources */,
     32340                                316BDB9A1E70CBBF00DE0D5A /* GPULibrary.cpp in Sources */,
    3231832341                                B2227A580D00BF220071B782 /* SVGPathElement.cpp in Sources */,
    3231932342                                8476C9EF11DF6A5800555B02 /* SVGPathParser.cpp in Sources */,
     
    3261432637                                49C7B9E51042D32F0009D447 /* WebGLTexture.cpp in Sources */,
    3261532638                                6F995A231A7078B100A735F4 /* WebGLTransformFeedback.cpp in Sources */,
     32639                                316BDB971E70CA2400DE0D5A /* GPUFunctionMetal.mm in Sources */,
    3261632640                                0C3F1F5A10C8871200D72CE1 /* WebGLUniformLocation.cpp in Sources */,
    3261732641                                6F995A251A7078B100A735F4 /* WebGLVertexArrayObject.cpp in Sources */,
  • trunk/Source/WebCore/platform/graphics/cocoa/GPUFunctionMetal.mm

    r213649 r213650  
    2424 */
    2525
    26 #import "config.h"
    27 #import "GPUDevice.h"
     26#include "config.h"
     27#include "GPUFunction.h"
    2828
    2929#if ENABLE(WEBGPU)
    3030
     31#import "GPULibrary.h"
    3132#import "Logging.h"
     33#import <Metal/Metal.h>
    3234
    3335namespace WebCore {
    3436
    35 RefPtr<GPUDevice> GPUDevice::create()
     37GPUFunction::GPUFunction(GPULibrary* library, const String& name)
    3638{
    37     RefPtr<GPUDevice> device = adoptRef(new GPUDevice());
     39    LOG(WebGPU, "GPUFunction::GPUFunction()");
    3840
    39 #if PLATFORM(COCOA)
    40     if (!device->platformDevice()) {
    41         LOG(WebGPU, "GPUDevice::create() was unable to create the low-level device");
    42         return nullptr;
    43     }
    44 #endif
     41    if (!library || !library->platformLibrary())
     42        return;
    4543
    46     LOG(WebGPU, "GPUDevice::create() device is %p", device.get());
    47     return device;
     44    m_function = (MTLFunction*)[library->platformLibrary() newFunctionWithName:name];
    4845}
    4946
    50 GPUDevice::~GPUDevice()
     47String GPUFunction::name() const
    5148{
    52     LOG(WebGPU, "GPUDevice::~GPUDevice()");
     49    if (!m_function)
     50        return emptyString();
     51   
     52    return [m_function name];
    5353}
    5454
    55 #if !PLATFORM(COCOA)
    56 
    57 GPUDevice::GPUDevice()
     55MTLFunction* GPUFunction::platformFunction()
    5856{
    59 
     57    return m_function.get();
    6058}
    61 
    62 void GPUDevice::reshape(int, int)
    63 {
    64 }
    65 
    66 #endif
    6759
    6860} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/cocoa/GPULibraryMetal.mm

    r213649 r213650  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "config.h"
    27 #import "GPUDevice.h"
     26#include "config.h"
     27#include "GPULibrary.h"
    2828
    2929#if ENABLE(WEBGPU)
    3030
     31#import "GPUDevice.h"
    3132#import "Logging.h"
     33
     34#import <Metal/Metal.h>
    3235
    3336namespace WebCore {
    3437
    35 RefPtr<GPUDevice> GPUDevice::create()
     38GPULibrary::GPULibrary(GPUDevice* device, const String& sourceCode)
    3639{
    37     RefPtr<GPUDevice> device = adoptRef(new GPUDevice());
     40    LOG(WebGPU, "GPULibrary::GPULibrary()");
    3841
    39 #if PLATFORM(COCOA)
    40     if (!device->platformDevice()) {
    41         LOG(WebGPU, "GPUDevice::create() was unable to create the low-level device");
    42         return nullptr;
    43     }
    44 #endif
     42    if (!device || !device->platformDevice())
     43        return;
    4544
    46     LOG(WebGPU, "GPUDevice::create() device is %p", device.get());
    47     return device;
     45    NSError *error = [NSError errorWithDomain:@"com.apple.WebKit.GPU" code:1 userInfo:nil];
     46    m_library = (MTLLibrary*)[device->platformDevice() newLibraryWithSource:sourceCode options:nil error:&error];
     47    if (!m_library)
     48        LOG(WebGPU, "Compilation error: %s", [[error localizedDescription] UTF8String]);
    4849}
    4950
    50 GPUDevice::~GPUDevice()
     51String GPULibrary::label() const
    5152{
    52     LOG(WebGPU, "GPUDevice::~GPUDevice()");
     53    if (!m_library)
     54        return emptyString();
     55
     56    return [m_library label];
    5357}
    5458
    55 #if !PLATFORM(COCOA)
     59void GPULibrary::setLabel(const String& label)
     60{
     61    if (!m_library)
     62        return;
    5663
    57 GPUDevice::GPUDevice()
    58 {
    59 
     64    [m_library setLabel:label];
    6065}
    6166
    62 void GPUDevice::reshape(int, int)
     67Vector<String> GPULibrary::functionNames()
    6368{
     69    if (!m_library)
     70        return Vector<String>();
     71
     72    Vector<String> names;
     73
     74    NSArray<NSString*> *functionNames = [m_library functionNames];
     75    for (NSString *string in functionNames)
     76        names.append(string);
     77   
     78    return names;
    6479}
    6580
    66 #endif
     81MTLLibrary* GPULibrary::platformLibrary()
     82{
     83    return m_library.get();
     84}
    6785
    6886} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp

    r213549 r213650  
    2424 */
    2525
    26 #import "config.h"
    27 #import "GPUDevice.h"
     26#include "config.h"
     27#include "GPUDevice.h"
    2828
    2929#if ENABLE(WEBGPU)
    3030
    31 #import "Logging.h"
     31#include "GPULibrary.h"
     32#include "Logging.h"
    3233
    3334namespace WebCore {
     
    5354}
    5455
     56RefPtr<GPULibrary> GPUDevice::createLibrary(const String& sourceCode)
     57{
     58    return GPULibrary::create(this, sourceCode);
     59}
     60
    5561#if !PLATFORM(COCOA)
    5662
  • trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h

    r213556 r213650  
    4747namespace WebCore {
    4848
     49class GPULibrary;
     50
    4951class GPUDevice : public RefCounted<GPUDevice> {
    5052public:
    51 
    5253    WEBCORE_EXPORT static RefPtr<GPUDevice> create();
    5354    WEBCORE_EXPORT ~GPUDevice();
     
    6162
    6263    WebGPULayer* layer() { return m_layer.get(); }
     64
     65    WEBCORE_EXPORT RefPtr<GPULibrary> createLibrary(const String& sourceCode);
    6366
    6467private:
  • trunk/Source/WebCore/platform/graphics/gpu/GPUFunction.cpp

    r213649 r213650  
    2424 */
    2525
    26 #import "config.h"
    27 #import "GPUDevice.h"
     26#include "config.h"
     27#include "GPUFunction.h"
    2828
    2929#if ENABLE(WEBGPU)
    3030
    31 #import "Logging.h"
     31#include "GPULibrary.h"
     32#include "Logging.h"
    3233
    3334namespace WebCore {
    3435
    35 RefPtr<GPUDevice> GPUDevice::create()
     36RefPtr<GPUFunction> GPUFunction::create(GPULibrary* library, const String& name)
    3637{
    37     RefPtr<GPUDevice> device = adoptRef(new GPUDevice());
    38 
     38    RefPtr<GPUFunction> function = adoptRef(new GPUFunction(library, name));
    3939#if PLATFORM(COCOA)
    40     if (!device->platformDevice()) {
    41         LOG(WebGPU, "GPUDevice::create() was unable to create the low-level device");
     40    if (!function->platformFunction())
    4241        return nullptr;
    43     }
    4442#endif
    45 
    46     LOG(WebGPU, "GPUDevice::create() device is %p", device.get());
    47     return device;
     43    return function;
    4844}
    4945
    50 GPUDevice::~GPUDevice()
     46GPUFunction::~GPUFunction()
    5147{
    52     LOG(WebGPU, "GPUDevice::~GPUDevice()");
     48    LOG(WebGPU, "GPUFunction::~GPUFunction()");
    5349}
    5450
    5551#if !PLATFORM(COCOA)
     52GPUFunction::GPUFunction(GPULibrary* library, const String& name)
     53{
     54    LOG(WebGPU, "GPUFunction::GPUFunction()");
    5655
    57 GPUDevice::GPUDevice()
    58 {
    59 
     56    if (!library || !library->library())
     57        return;
    6058}
    6159
    62 void GPUDevice::reshape(int, int)
     60String GPUFunction::name() const
    6361{
     62    return emptyString();
    6463}
     64#endif
     65
     66   
     67} // namespace WebCore
    6568
    6669#endif
    6770
    68 } // namespace WebCore
    69 
    70 #endif
  • trunk/Source/WebCore/platform/graphics/gpu/GPUFunction.h

    r213649 r213650  
    2424 */
    2525
    26 #import "config.h"
    27 #import "GPUDevice.h"
     26#pragma once
    2827
    2928#if ENABLE(WEBGPU)
    3029
    31 #import "Logging.h"
     30#include <wtf/RefCounted.h>
     31#include <wtf/RefPtr.h>
     32#include <wtf/Vector.h>
     33#include <wtf/text/WTFString.h>
     34
     35#if PLATFORM(COCOA)
     36OBJC_CLASS MTLFunction;
     37#endif
    3238
    3339namespace WebCore {
    3440
    35 RefPtr<GPUDevice> GPUDevice::create()
    36 {
    37     RefPtr<GPUDevice> device = adoptRef(new GPUDevice());
     41class GPULibrary;
     42
     43class GPUFunction : public RefCounted<GPUFunction> {
     44public:
     45    static RefPtr<GPUFunction> create(GPULibrary*, const String& name);
     46    WEBCORE_EXPORT ~GPUFunction();
     47
     48    WEBCORE_EXPORT String name() const;
    3849
    3950#if PLATFORM(COCOA)
    40     if (!device->platformDevice()) {
    41         LOG(WebGPU, "GPUDevice::create() was unable to create the low-level device");
    42         return nullptr;
    43     }
     51    WEBCORE_EXPORT MTLFunction* platformFunction();
    4452#endif
    4553
    46     LOG(WebGPU, "GPUDevice::create() device is %p", device.get());
    47     return device;
    48 }
     54private:
     55    GPUFunction(GPULibrary*, const String& name);
    4956
    50 GPUDevice::~GPUDevice()
    51 {
    52     LOG(WebGPU, "GPUDevice::~GPUDevice()");
    53 }
    54 
    55 #if !PLATFORM(COCOA)
    56 
    57 GPUDevice::GPUDevice()
    58 {
    59 
    60 }
    61 
    62 void GPUDevice::reshape(int, int)
    63 {
    64 }
    65 
     57#if PLATFORM(COCOA)
     58    RetainPtr<MTLFunction> m_function;
    6659#endif
    67 
     60};
     61   
    6862} // namespace WebCore
    6963
  • trunk/Source/WebCore/platform/graphics/gpu/GPULibrary.cpp

    r213649 r213650  
    2424 */
    2525
    26 #import "config.h"
    27 #import "GPUDevice.h"
     26#include "config.h"
     27#include "GPULibrary.h"
    2828
    2929#if ENABLE(WEBGPU)
    3030
     31#import "GPUDevice.h"
     32#import "GPUFunction.h"
    3133#import "Logging.h"
    3234
    3335namespace WebCore {
    3436
    35 RefPtr<GPUDevice> GPUDevice::create()
     37RefPtr<GPULibrary> GPULibrary::create(GPUDevice* device, const String& sourceCode)
    3638{
    37     RefPtr<GPUDevice> device = adoptRef(new GPUDevice());
    38 
    39 #if PLATFORM(COCOA)
    40     if (!device->platformDevice()) {
    41         LOG(WebGPU, "GPUDevice::create() was unable to create the low-level device");
    42         return nullptr;
    43     }
    44 #endif
    45 
    46     LOG(WebGPU, "GPUDevice::create() device is %p", device.get());
    47     return device;
     39    RefPtr<GPULibrary> library = adoptRef(new GPULibrary(device, sourceCode));
     40    return library;
    4841}
    4942
    50 GPUDevice::~GPUDevice()
     43GPULibrary::~GPULibrary()
    5144{
    52     LOG(WebGPU, "GPUDevice::~GPUDevice()");
     45    LOG(WebGPU, "GPULibrary::~GPULibrary()");
    5346}
    5447
    5548#if !PLATFORM(COCOA)
    5649
    57 GPUDevice::GPUDevice()
     50String GPULibrary::label() const
    5851{
    59 
     52    return emptyString();
    6053}
    6154
    62 void GPUDevice::reshape(int, int)
     55void GPULibrary::setLabel(const String&)
    6356{
     57}
     58
     59Vector<String> GPULibrary::functionNames()
     60{
     61    return { };
    6462}
    6563
    6664#endif
    6765
     66RefPtr<GPUFunction> GPULibrary::functionWithName(const String& name)
     67{
     68    return GPUFunction::create(this, name);
     69}
     70   
    6871} // namespace WebCore
    6972
  • trunk/Source/WebCore/platform/graphics/gpu/GPULibrary.h

    r213649 r213650  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "PlatformLayer.h"
    31 #include <runtime/ArrayBufferView.h>
    3230#include <wtf/RefCounted.h>
    33 
    34 #if USE(CA)
    35 #include "PlatformCALayer.h"
    36 #endif
     31#include <wtf/RefPtr.h>
     32#include <wtf/Vector.h>
     33#include <wtf/text/WTFString.h>
    3734
    3835#if PLATFORM(COCOA)
    39 typedef struct objc_object* id;
    40 OBJC_CLASS CALayer;
    41 OBJC_CLASS WebGPULayer;
    42 #else
    43 class WebGPULayer;
    44 typedef void PlatformGPUDevice;
     36OBJC_CLASS MTLLibrary;
    4537#endif
    4638
    4739namespace WebCore {
    4840
    49 class GPUDevice : public RefCounted<GPUDevice> {
     41class GPUDevice;
     42class GPUFunction;
     43
     44class GPULibrary : public RefCounted<GPULibrary> {
    5045public:
     46    static RefPtr<GPULibrary> create(GPUDevice*, const String& sourceCode);
     47    WEBCORE_EXPORT ~GPULibrary();
    5148
    52     WEBCORE_EXPORT static RefPtr<GPUDevice> create();
    53     WEBCORE_EXPORT ~GPUDevice();
     49    WEBCORE_EXPORT String label() const;
     50    WEBCORE_EXPORT void setLabel(const String&);
    5451
    55     void reshape(int width, int height);
     52    WEBCORE_EXPORT Vector<String> functionNames();
     53
     54    WEBCORE_EXPORT RefPtr<GPUFunction> functionWithName(const String&);
    5655
    5756#if PLATFORM(COCOA)
    58     CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_layer.get()); }
    59     WEBCORE_EXPORT id platformDevice();
     57    WEBCORE_EXPORT MTLLibrary* platformLibrary();
    6058#endif
    6159
    62     WebGPULayer* layer() { return m_layer.get(); }
    63 
    6460private:
    65     GPUDevice();
    66 
    67     RetainPtr<WebGPULayer> m_layer;
     61    GPULibrary(GPUDevice*, const String& sourceCode);
     62   
    6863#if PLATFORM(COCOA)
    69     RetainPtr<id> m_device;
     64    RetainPtr<MTLLibrary> m_library;
    7065#endif
    7166};
    72 
     67   
    7368} // namespace WebCore
    74 
    7569#endif
  • trunk/Tools/ChangeLog

    r213645 r213650  
     12017-03-08  Dean Jackson  <dino@apple.com>
     2
     3        WebGPU: Backend - Library and Functions
     4        https://bugs.webkit.org/show_bug.cgi?id=169371
     5        <rdar://problem/30928792>
     6
     7        Reviewed by Tim Horton.
     8
     9        Add tests for GPULibrary and GPUFunction.
     10
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm:
     13        (TestWebKitAPI::TEST_F):
     14        (TestWebKitAPI::TEST): Deleted.
     15        * TestWebKitAPI/Tests/WebCore/mac/GPUFunction.mm: Copied from Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm.
     16        (TestWebKitAPI::TEST_F):
     17        * TestWebKitAPI/Tests/WebCore/mac/GPULibrary.mm: Copied from Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm.
     18        (TestWebKitAPI::TEST_F):
     19        * TestWebKitAPI/Tests/WebCore/mac/GPUTest.h: Copied from Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm.
     20        (TestWebKitAPI::GPU::librarySourceCode):
     21
    1222017-03-08  Filip Pizlo  <fpizlo@apple.com>
    223
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r213645 r213650  
    9595                315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; };
    9696                3162AE9C1E6F2FF5000E4DBC /* GPUDevice.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3162AE9B1E6F2FCE000E4DBC /* GPUDevice.mm */; };
     97                316BDBA11E70D71B00DE0D5A /* GPULibrary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 316BDBA01E70D6D800DE0D5A /* GPULibrary.mm */; };
     98                316BDBA41E70EF6800DE0D5A /* GPUFunction.mm in Sources */ = {isa = PBXBuildFile; fileRef = 316BDBA31E70EF5D00DE0D5A /* GPUFunction.mm */; };
    9799                33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; };
    98100                33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; };
     
    949951                3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; };
    950952                3162AE9B1E6F2FCE000E4DBC /* GPUDevice.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUDevice.mm; sourceTree = "<group>"; };
     953                316BDBA01E70D6D800DE0D5A /* GPULibrary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPULibrary.mm; sourceTree = "<group>"; };
     954                316BDBA21E70DEE500DE0D5A /* GPUTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUTest.h; sourceTree = "<group>"; };
     955                316BDBA31E70EF5D00DE0D5A /* GPUFunction.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUFunction.mm; sourceTree = "<group>"; };
    951956                333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; };
    952957                33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; };
     
    16671672                        children = (
    16681673                                3162AE9B1E6F2FCE000E4DBC /* GPUDevice.mm */,
     1674                                316BDBA31E70EF5D00DE0D5A /* GPUFunction.mm */,
     1675                                316BDBA01E70D6D800DE0D5A /* GPULibrary.mm */,
     1676                                316BDBA21E70DEE500DE0D5A /* GPUTest.h */,
    16691677                        );
    16701678                        path = mac;
     
    27512759                                7CCE7EFE1A411AE600447C4C /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */,
    27522760                                5C0BF8941DD599C900B00328 /* MenuTypesForMouseEvents.mm in Sources */,
     2761                                316BDBA11E70D71B00DE0D5A /* GPULibrary.mm in Sources */,
    27532762                                5C0BF8931DD599BD00B00328 /* IsNavigationActionTrusted.mm in Sources */,
    27542763                                7CCE7EFF1A411AE600447C4C /* LoadCanceledNoServerRedirectCallback.cpp in Sources */,
     
    28812890                                7CCE7F1C1A411AE600447C4C /* WillSendSubmitEvent.cpp in Sources */,
    28822891                                7CCE7ED81A411A7E00447C4C /* WillSendSubmitEvent.mm in Sources */,
     2892                                316BDBA41E70EF6800DE0D5A /* GPUFunction.mm in Sources */,
    28832893                                7CCE7ED91A411A7E00447C4C /* WindowlessWebViewWithMedia.mm in Sources */,
    28842894                                1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm

    r213549 r213650  
    2424 */
    2525
    26 #ifdef ENABLE_WEBGPU
     26#import "config.h"
    2727
    28 #include "config.h"
    29 #import "Test.h"
     28#if ENABLE(WEBGPU)
     29
     30#import "GPUTest.h"
    3031#import <Metal/Metal.h>
    3132#import <WebCore/GPUDevice.h>
     
    3536namespace TestWebKitAPI {
    3637
    37 TEST(GPU, Basic)
     38TEST_F(GPU, DeviceCreate)
    3839{
    3940    auto device = GPUDevice::create();
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPUFunction.mm

    r213649 r213650  
    2424 */
    2525
    26 #ifdef ENABLE_WEBGPU
    2726
    28 #include "config.h"
    29 #import "Test.h"
     27#import "config.h"
     28
     29#if ENABLE(WEBGPU)
     30
     31#import "GPUTest.h"
    3032#import <Metal/Metal.h>
    3133#import <WebCore/GPUDevice.h>
     34#import <WebCore/GPUFunction.h>
     35#import <WebCore/GPULibrary.h>
     36#import <wtf/MainThread.h>
    3237
    3338using namespace WebCore;
     
    3540namespace TestWebKitAPI {
    3641
    37 TEST(GPU, Basic)
     42TEST_F(GPU, FunctionAccessByName)
    3843{
    3944    auto device = GPUDevice::create();
     
    4449        return;
    4550
    46     EXPECT_NOT_NULL(device->layer());
    47     EXPECT_NOT_NULL(device->platformLayer());
    48 
    4951    id<MTLDevice> mtlDevice = (id<MTLDevice>)device->platformDevice();
    5052    EXPECT_NOT_NULL(mtlDevice);
    5153
    52     NSString *deviceName = mtlDevice.name;
    53     EXPECT_GT(deviceName.length, static_cast<unsigned long>(0));
     54    auto library = device->createLibrary(librarySourceCode());
     55    EXPECT_NOT_NULL(library);
     56
     57    auto vertexFunction = library->functionWithName("vertex_main");
     58    EXPECT_NOT_NULL(vertexFunction);
     59    EXPECT_TRUE(vertexFunction->name() == "vertex_main");
     60
     61    auto fragmentFunction = library->functionWithName("fragment_main");
     62    EXPECT_NOT_NULL(fragmentFunction);
     63    EXPECT_TRUE(fragmentFunction->name() == "fragment_main");
     64
     65    auto nonExistentFunction = library->functionWithName("name_that_is_not_in_library");
     66    EXPECT_NULL(nonExistentFunction);
    5467}
    5568
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPULibrary.mm

    r213649 r213650  
    2424 */
    2525
    26 #ifdef ENABLE_WEBGPU
     26#import "config.h"
    2727
    28 #include "config.h"
    29 #import "Test.h"
     28#if ENABLE(WEBGPU)
     29
     30#import "GPUTest.h"
    3031#import <Metal/Metal.h>
    3132#import <WebCore/GPUDevice.h>
     33#import <WebCore/GPULibrary.h>
     34#import <wtf/MainThread.h>
    3235
    3336using namespace WebCore;
     
    3538namespace TestWebKitAPI {
    3639
    37 TEST(GPU, Basic)
     40TEST_F(GPU, LibraryCreate)
    3841{
    3942    auto device = GPUDevice::create();
     
    4447        return;
    4548
    46     EXPECT_NOT_NULL(device->layer());
    47     EXPECT_NOT_NULL(device->platformLayer());
    48 
    4949    id<MTLDevice> mtlDevice = (id<MTLDevice>)device->platformDevice();
    5050    EXPECT_NOT_NULL(mtlDevice);
    5151
    52     NSString *deviceName = mtlDevice.name;
    53     EXPECT_GT(deviceName.length, static_cast<unsigned long>(0));
     52    auto library = device->createLibrary(librarySourceCode());
     53    EXPECT_NOT_NULL(library);
     54}
     55
     56TEST_F(GPU, LibrarySetLabel)
     57{
     58    auto device = GPUDevice::create();
     59    if (!device)
     60        return;
     61
     62    auto library = device->createLibrary(librarySourceCode());
     63    EXPECT_NOT_NULL(library);
     64
     65    library->setLabel("TestLabel");
     66    EXPECT_TRUE(library->label() == "TestLabel");
     67}
     68
     69TEST_F(GPU, LibraryFunctionNames)
     70{
     71    auto device = GPUDevice::create();
     72    if (!device)
     73        return;
     74
     75    auto library = device->createLibrary(librarySourceCode());
     76    EXPECT_NOT_NULL(library);
     77
     78    auto functionNames = library->functionNames();
     79    EXPECT_EQ(functionNames.size(), static_cast<unsigned long>(2));
     80    EXPECT_TRUE(functionNames[0] == "vertex_main");
     81    EXPECT_TRUE(functionNames[1] == "fragment_main");
    5482}
    5583
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPUTest.h

    r213649 r213650  
    2424 */
    2525
    26 #ifdef ENABLE_WEBGPU
     26#pragma once
    2727
    28 #include "config.h"
    2928#import "Test.h"
    30 #import <Metal/Metal.h>
    31 #import <WebCore/GPUDevice.h>
    32 
    33 using namespace WebCore;
     29#import "WTFStringUtilities.h"
     30#import <wtf/MainThread.h>
    3431
    3532namespace TestWebKitAPI {
    3633
    37 TEST(GPU, Basic)
    38 {
    39     auto device = GPUDevice::create();
    40     // Not all hardware supports Metal, so it is possible
    41     // that we were unable to create the MTLDevice object.
    42     // In that case, the device should be null.
    43     if (!device)
    44         return;
     34class GPU : public testing::Test {
     35public:
     36    void SetUp() final
     37    {
     38        WTF::initializeMainThread();
    4539
    46     EXPECT_NOT_NULL(device->layer());
    47     EXPECT_NOT_NULL(device->platformLayer());
     40        m_librarySourceCode = ASCIILiteral("using namespace metal;\n\
     41            struct Vertex\n\
     42            {\n\
     43            float4 position [[position]];\n\
     44            float4 color;\n\
     45            };\n\
     46            vertex Vertex vertex_main(device Vertex *vertices [[buffer(0)]],\n\
     47            uint vid [[vertex_id]])\n\
     48            {\n\
     49            return vertices[vid];\n\
     50            }\n\
     51            fragment float4 fragment_main(Vertex inVertex [[stage_in]])\n\
     52            {\n\
     53            return inVertex.color;\n\
     54            }");
     55    }
    4856
    49     id<MTLDevice> mtlDevice = (id<MTLDevice>)device->platformDevice();
    50     EXPECT_NOT_NULL(mtlDevice);
     57    const String& librarySourceCode() { return m_librarySourceCode; }
    5158
    52     NSString *deviceName = mtlDevice.name;
    53     EXPECT_GT(deviceName.length, static_cast<unsigned long>(0));
     59private:
     60    String m_librarySourceCode;
     61};
     62
    5463}
    55 
    56 } // namespace TestWebKitAPI
    57 
    58 #endif
Note: See TracChangeset for help on using the changeset viewer.