Changeset 213650 in webkit
- Timestamp:
- Mar 9, 2017 11:02:11 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 8 edited
- 9 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r213646 r213650 1 2017-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 1 45 2017-03-09 Chris Dumez <cdumez@apple.com> 2 46 -
trunk/Source/WebCore/PlatformMac.cmake
r213624 r213650 418 418 419 419 platform/graphics/cocoa/GPUDeviceMetal.mm 420 platform/graphics/cocoa/GPUFunctionMetal.mm 421 platform/graphics/cocoa/GPULibraryMetal.mm 420 422 platform/graphics/cocoa/FontCacheCoreText.cpp 421 423 platform/graphics/cocoa/FontCascadeCocoa.mm … … 432 434 433 435 platform/graphics/gpu/GPUDevice.cpp 436 platform/graphics/gpu/GPUFunction.cpp 437 platform/graphics/gpu/GPULibrary.cpp 434 438 435 439 platform/graphics/mac/ColorMac.mm -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r213628 r213650 1360 1360 316BDB8C1E6E153000DE0D5A /* WebGPULayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 316BDB8A1E6E153000DE0D5A /* WebGPULayer.h */; }; 1361 1361 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 */; }; 1362 1368 316FE0710E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 316FE06D0E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp */; }; 1363 1369 316FE0720E6CCBEE00BF6088 /* JSCSSKeyframeRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 316FE06E0E6CCBEE00BF6088 /* JSCSSKeyframeRule.h */; }; … … 8687 8693 316BDB891E6E153000DE0D5A /* WebGPULayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebGPULayer.mm; sourceTree = "<group>"; }; 8688 8694 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>"; }; 8689 8701 316FE06D0E6CCBEE00BF6088 /* JSCSSKeyframeRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSKeyframeRule.cpp; sourceTree = "<group>"; }; 8690 8702 316FE06E0E6CCBEE00BF6088 /* JSCSSKeyframeRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCSSKeyframeRule.h; sourceTree = "<group>"; }; … … 17475 17487 316BDB841E6E0A2100DE0D5A /* GPUDevice.cpp */, 17476 17488 316BDB851E6E0A2100DE0D5A /* GPUDevice.h */, 17489 316BDB921E70C89700DE0D5A /* GPUFunction.cpp */, 17490 316BDB931E70C89700DE0D5A /* GPUFunction.h */, 17491 316BDB981E70CBBF00DE0D5A /* GPULibrary.cpp */, 17492 316BDB991E70CBBF00DE0D5A /* GPULibrary.h */, 17477 17493 498770D71242C535002226BA /* Texture.cpp */, 17478 17494 498770D81242C535002226BA /* Texture.h */, … … 22567 22583 B5320D6A122A24E9002D1440 /* FontPlatformDataCocoa.mm */, 22568 22584 316BDB881E6E141C00DE0D5A /* GPUDeviceMetal.mm */, 22585 316BDB961E70CA2400DE0D5A /* GPUFunctionMetal.mm */, 22586 316BDB9C1E70CD9000DE0D5A /* GPULibraryMetal.mm */, 22569 22587 2D0B4AA918DA1CCD00434DE1 /* IOSurface.h */, 22570 22588 2D0B4AAA18DA1CCD00434DE1 /* IOSurface.mm */, … … 26205 26223 4F1534DE11B532EC0021FD86 /* EditingBehavior.h in Headers */, 26206 26224 4F1534E011B533020021FD86 /* EditingBehaviorTypes.h in Headers */, 26225 316BDB9B1E70CBBF00DE0D5A /* GPULibrary.h in Headers */, 26207 26226 3AC648B2129E146500C3EB25 /* EditingBoundary.h in Headers */, 26208 26227 9BAB6C6C12550631001626D4 /* EditingStyle.h in Headers */, … … 28006 28025 B56579B51824D12A00E79F23 /* RenderChildIterator.h in Headers */, 28007 28026 BCE4413412F748E2009B84B8 /* RenderCombineText.h in Headers */, 28027 316BDB951E70C89700DE0D5A /* GPUFunction.h in Headers */, 28008 28028 9392F1420AD185F400691BD4 /* RenderCounter.h in Headers */, 28009 28029 BCEA486E097D93020094C9E4 /* RenderDeprecatedFlexibleBox.h in Headers */, … … 30430 30450 0707568B142262D600414161 /* HTMLTrackElement.cpp in Sources */, 30431 30451 977B37251228721700B81FF8 /* HTMLTreeBuilder.cpp in Sources */, 30452 316BDB941E70C89700DE0D5A /* GPUFunction.cpp in Sources */, 30432 30453 A8EA79F30A1916DF00A8EF5F /* HTMLUListElement.cpp in Sources */, 30433 30454 E44613AA0CD6331000FADA75 /* HTMLVideoElement.cpp in Sources */, … … 31949 31970 073BE34F17D18183002BD431 /* RTCIceCandidateDescriptor.cpp in Sources */, 31950 31971 078E090A17D14CEE00420AA1 /* RTCIceCandidateEvent.cpp in Sources */, 31972 316BDB9E1E70CD9000DE0D5A /* GPULibraryMetal.mm in Sources */, 31951 31973 073794FD19F5864E00E5A045 /* RTCNotifiersMock.cpp in Sources */, 31952 31974 078E090B17D14CEE00420AA1 /* RTCPeerConnection.cpp in Sources */, … … 32316 32338 8419D2A8120D92D000141F8F /* SVGPathByteStreamBuilder.cpp in Sources */, 32317 32339 8419D2AC120D92FC00141F8F /* SVGPathByteStreamSource.cpp in Sources */, 32340 316BDB9A1E70CBBF00DE0D5A /* GPULibrary.cpp in Sources */, 32318 32341 B2227A580D00BF220071B782 /* SVGPathElement.cpp in Sources */, 32319 32342 8476C9EF11DF6A5800555B02 /* SVGPathParser.cpp in Sources */, … … 32614 32637 49C7B9E51042D32F0009D447 /* WebGLTexture.cpp in Sources */, 32615 32638 6F995A231A7078B100A735F4 /* WebGLTransformFeedback.cpp in Sources */, 32639 316BDB971E70CA2400DE0D5A /* GPUFunctionMetal.mm in Sources */, 32616 32640 0C3F1F5A10C8871200D72CE1 /* WebGLUniformLocation.cpp in Sources */, 32617 32641 6F995A251A7078B100A735F4 /* WebGLVertexArrayObject.cpp in Sources */, -
trunk/Source/WebCore/platform/graphics/cocoa/GPUFunctionMetal.mm
r213649 r213650 24 24 */ 25 25 26 #i mport"config.h"27 #i mport "GPUDevice.h"26 #include "config.h" 27 #include "GPUFunction.h" 28 28 29 29 #if ENABLE(WEBGPU) 30 30 31 #import "GPULibrary.h" 31 32 #import "Logging.h" 33 #import <Metal/Metal.h> 32 34 33 35 namespace WebCore { 34 36 35 RefPtr<GPUDevice> GPUDevice::create()37 GPUFunction::GPUFunction(GPULibrary* library, const String& name) 36 38 { 37 RefPtr<GPUDevice> device = adoptRef(new GPUDevice());39 LOG(WebGPU, "GPUFunction::GPUFunction()"); 38 40 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; 45 43 46 LOG(WebGPU, "GPUDevice::create() device is %p", device.get()); 47 return device; 44 m_function = (MTLFunction*)[library->platformLibrary() newFunctionWithName:name]; 48 45 } 49 46 50 GPUDevice::~GPUDevice() 47 String GPUFunction::name() const 51 48 { 52 LOG(WebGPU, "GPUDevice::~GPUDevice()"); 49 if (!m_function) 50 return emptyString(); 51 52 return [m_function name]; 53 53 } 54 54 55 #if !PLATFORM(COCOA) 56 57 GPUDevice::GPUDevice() 55 MTLFunction* GPUFunction::platformFunction() 58 56 { 59 57 return m_function.get(); 60 58 } 61 62 void GPUDevice::reshape(int, int)63 {64 }65 66 #endif67 59 68 60 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/cocoa/GPULibraryMetal.mm
r213649 r213650 1 1 /* 2 * Copyright (C) 201 7Apple Inc. All rights reserved.2 * Copyright (C) 2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #i mport"config.h"27 #i mport "GPUDevice.h"26 #include "config.h" 27 #include "GPULibrary.h" 28 28 29 29 #if ENABLE(WEBGPU) 30 30 31 #import "GPUDevice.h" 31 32 #import "Logging.h" 33 34 #import <Metal/Metal.h> 32 35 33 36 namespace WebCore { 34 37 35 RefPtr<GPUDevice> GPUDevice::create()38 GPULibrary::GPULibrary(GPUDevice* device, const String& sourceCode) 36 39 { 37 RefPtr<GPUDevice> device = adoptRef(new GPUDevice());40 LOG(WebGPU, "GPULibrary::GPULibrary()"); 38 41 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; 45 44 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]); 48 49 } 49 50 50 GPUDevice::~GPUDevice() 51 String GPULibrary::label() const 51 52 { 52 LOG(WebGPU, "GPUDevice::~GPUDevice()"); 53 if (!m_library) 54 return emptyString(); 55 56 return [m_library label]; 53 57 } 54 58 55 #if !PLATFORM(COCOA) 59 void GPULibrary::setLabel(const String& label) 60 { 61 if (!m_library) 62 return; 56 63 57 GPUDevice::GPUDevice() 58 { 59 64 [m_library setLabel:label]; 60 65 } 61 66 62 void GPUDevice::reshape(int, int)67 Vector<String> GPULibrary::functionNames() 63 68 { 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; 64 79 } 65 80 66 #endif 81 MTLLibrary* GPULibrary::platformLibrary() 82 { 83 return m_library.get(); 84 } 67 85 68 86 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
r213549 r213650 24 24 */ 25 25 26 #i mport"config.h"27 #i mport"GPUDevice.h"26 #include "config.h" 27 #include "GPUDevice.h" 28 28 29 29 #if ENABLE(WEBGPU) 30 30 31 #import "Logging.h" 31 #include "GPULibrary.h" 32 #include "Logging.h" 32 33 33 34 namespace WebCore { … … 53 54 } 54 55 56 RefPtr<GPULibrary> GPUDevice::createLibrary(const String& sourceCode) 57 { 58 return GPULibrary::create(this, sourceCode); 59 } 60 55 61 #if !PLATFORM(COCOA) 56 62 -
trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h
r213556 r213650 47 47 namespace WebCore { 48 48 49 class GPULibrary; 50 49 51 class GPUDevice : public RefCounted<GPUDevice> { 50 52 public: 51 52 53 WEBCORE_EXPORT static RefPtr<GPUDevice> create(); 53 54 WEBCORE_EXPORT ~GPUDevice(); … … 61 62 62 63 WebGPULayer* layer() { return m_layer.get(); } 64 65 WEBCORE_EXPORT RefPtr<GPULibrary> createLibrary(const String& sourceCode); 63 66 64 67 private: -
trunk/Source/WebCore/platform/graphics/gpu/GPUFunction.cpp
r213649 r213650 24 24 */ 25 25 26 #i mport"config.h"27 #i mport "GPUDevice.h"26 #include "config.h" 27 #include "GPUFunction.h" 28 28 29 29 #if ENABLE(WEBGPU) 30 30 31 #import "Logging.h" 31 #include "GPULibrary.h" 32 #include "Logging.h" 32 33 33 34 namespace WebCore { 34 35 35 RefPtr<GPU Device> GPUDevice::create()36 RefPtr<GPUFunction> GPUFunction::create(GPULibrary* library, const String& name) 36 37 { 37 RefPtr<GPUDevice> device = adoptRef(new GPUDevice()); 38 38 RefPtr<GPUFunction> function = adoptRef(new GPUFunction(library, name)); 39 39 #if PLATFORM(COCOA) 40 if (!device->platformDevice()) { 41 LOG(WebGPU, "GPUDevice::create() was unable to create the low-level device"); 40 if (!function->platformFunction()) 42 41 return nullptr; 43 }44 42 #endif 45 46 LOG(WebGPU, "GPUDevice::create() device is %p", device.get()); 47 return device; 43 return function; 48 44 } 49 45 50 GPU Device::~GPUDevice()46 GPUFunction::~GPUFunction() 51 47 { 52 LOG(WebGPU, "GPU Device::~GPUDevice()");48 LOG(WebGPU, "GPUFunction::~GPUFunction()"); 53 49 } 54 50 55 51 #if !PLATFORM(COCOA) 52 GPUFunction::GPUFunction(GPULibrary* library, const String& name) 53 { 54 LOG(WebGPU, "GPUFunction::GPUFunction()"); 56 55 57 GPUDevice::GPUDevice() 58 { 59 56 if (!library || !library->library()) 57 return; 60 58 } 61 59 62 void GPUDevice::reshape(int, int) 60 String GPUFunction::name() const 63 61 { 62 return emptyString(); 64 63 } 64 #endif 65 66 67 } // namespace WebCore 65 68 66 69 #endif 67 70 68 } // namespace WebCore69 70 #endif -
trunk/Source/WebCore/platform/graphics/gpu/GPUFunction.h
r213649 r213650 24 24 */ 25 25 26 #import "config.h" 27 #import "GPUDevice.h" 26 #pragma once 28 27 29 28 #if ENABLE(WEBGPU) 30 29 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) 36 OBJC_CLASS MTLFunction; 37 #endif 32 38 33 39 namespace WebCore { 34 40 35 RefPtr<GPUDevice> GPUDevice::create() 36 { 37 RefPtr<GPUDevice> device = adoptRef(new GPUDevice()); 41 class GPULibrary; 42 43 class GPUFunction : public RefCounted<GPUFunction> { 44 public: 45 static RefPtr<GPUFunction> create(GPULibrary*, const String& name); 46 WEBCORE_EXPORT ~GPUFunction(); 47 48 WEBCORE_EXPORT String name() const; 38 49 39 50 #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(); 44 52 #endif 45 53 46 LOG(WebGPU, "GPUDevice::create() device is %p", device.get()); 47 return device; 48 } 54 private: 55 GPUFunction(GPULibrary*, const String& name); 49 56 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; 66 59 #endif 67 60 }; 61 68 62 } // namespace WebCore 69 63 -
trunk/Source/WebCore/platform/graphics/gpu/GPULibrary.cpp
r213649 r213650 24 24 */ 25 25 26 #i mport"config.h"27 #i mport "GPUDevice.h"26 #include "config.h" 27 #include "GPULibrary.h" 28 28 29 29 #if ENABLE(WEBGPU) 30 30 31 #import "GPUDevice.h" 32 #import "GPUFunction.h" 31 33 #import "Logging.h" 32 34 33 35 namespace WebCore { 34 36 35 RefPtr<GPU Device> GPUDevice::create()37 RefPtr<GPULibrary> GPULibrary::create(GPUDevice* device, const String& sourceCode) 36 38 { 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; 48 41 } 49 42 50 GPU Device::~GPUDevice()43 GPULibrary::~GPULibrary() 51 44 { 52 LOG(WebGPU, "GPU Device::~GPUDevice()");45 LOG(WebGPU, "GPULibrary::~GPULibrary()"); 53 46 } 54 47 55 48 #if !PLATFORM(COCOA) 56 49 57 GPUDevice::GPUDevice() 50 String GPULibrary::label() const 58 51 { 59 52 return emptyString(); 60 53 } 61 54 62 void GPU Device::reshape(int, int)55 void GPULibrary::setLabel(const String&) 63 56 { 57 } 58 59 Vector<String> GPULibrary::functionNames() 60 { 61 return { }; 64 62 } 65 63 66 64 #endif 67 65 66 RefPtr<GPUFunction> GPULibrary::functionWithName(const String& name) 67 { 68 return GPUFunction::create(this, name); 69 } 70 68 71 } // namespace WebCore 69 72 -
trunk/Source/WebCore/platform/graphics/gpu/GPULibrary.h
r213649 r213650 28 28 #if ENABLE(WEBGPU) 29 29 30 #include "PlatformLayer.h"31 #include <runtime/ArrayBufferView.h>32 30 #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> 37 34 38 35 #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; 36 OBJC_CLASS MTLLibrary; 45 37 #endif 46 38 47 39 namespace WebCore { 48 40 49 class GPUDevice : public RefCounted<GPUDevice> { 41 class GPUDevice; 42 class GPUFunction; 43 44 class GPULibrary : public RefCounted<GPULibrary> { 50 45 public: 46 static RefPtr<GPULibrary> create(GPUDevice*, const String& sourceCode); 47 WEBCORE_EXPORT ~GPULibrary(); 51 48 52 WEBCORE_EXPORT static RefPtr<GPUDevice> create();53 WEBCORE_EXPORT ~GPUDevice();49 WEBCORE_EXPORT String label() const; 50 WEBCORE_EXPORT void setLabel(const String&); 54 51 55 void reshape(int width, int height); 52 WEBCORE_EXPORT Vector<String> functionNames(); 53 54 WEBCORE_EXPORT RefPtr<GPUFunction> functionWithName(const String&); 56 55 57 56 #if PLATFORM(COCOA) 58 CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_layer.get()); } 59 WEBCORE_EXPORT id platformDevice(); 57 WEBCORE_EXPORT MTLLibrary* platformLibrary(); 60 58 #endif 61 59 62 WebGPULayer* layer() { return m_layer.get(); }63 64 60 private: 65 GPUDevice(); 66 67 RetainPtr<WebGPULayer> m_layer; 61 GPULibrary(GPUDevice*, const String& sourceCode); 62 68 63 #if PLATFORM(COCOA) 69 RetainPtr< id> m_device;64 RetainPtr<MTLLibrary> m_library; 70 65 #endif 71 66 }; 72 67 73 68 } // namespace WebCore 74 75 69 #endif -
trunk/Tools/ChangeLog
r213645 r213650 1 2017-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 1 22 2017-03-08 Filip Pizlo <fpizlo@apple.com> 2 23 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r213645 r213650 95 95 315118101DB1AE4000176304 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */; }; 96 96 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 */; }; 97 99 33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */; }; 98 100 33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; }; … … 949 951 3151180F1DB1ADD500176304 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; }; 950 952 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>"; }; 951 956 333B9CE11277F23100FEFCE3 /* PreventEmptyUserAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PreventEmptyUserAgent.cpp; sourceTree = "<group>"; }; 952 957 33BE5AF4137B5A6C00705813 /* MouseMoveAfterCrash.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash.cpp; sourceTree = "<group>"; }; … … 1667 1672 children = ( 1668 1673 3162AE9B1E6F2FCE000E4DBC /* GPUDevice.mm */, 1674 316BDBA31E70EF5D00DE0D5A /* GPUFunction.mm */, 1675 316BDBA01E70D6D800DE0D5A /* GPULibrary.mm */, 1676 316BDBA21E70DEE500DE0D5A /* GPUTest.h */, 1669 1677 ); 1670 1678 path = mac; … … 2751 2759 7CCE7EFE1A411AE600447C4C /* LoadAlternateHTMLStringWithNonDirectoryURL.cpp in Sources */, 2752 2760 5C0BF8941DD599C900B00328 /* MenuTypesForMouseEvents.mm in Sources */, 2761 316BDBA11E70D71B00DE0D5A /* GPULibrary.mm in Sources */, 2753 2762 5C0BF8931DD599BD00B00328 /* IsNavigationActionTrusted.mm in Sources */, 2754 2763 7CCE7EFF1A411AE600447C4C /* LoadCanceledNoServerRedirectCallback.cpp in Sources */, … … 2881 2890 7CCE7F1C1A411AE600447C4C /* WillSendSubmitEvent.cpp in Sources */, 2882 2891 7CCE7ED81A411A7E00447C4C /* WillSendSubmitEvent.mm in Sources */, 2892 316BDBA41E70EF6800DE0D5A /* GPUFunction.mm in Sources */, 2883 2893 7CCE7ED91A411A7E00447C4C /* WindowlessWebViewWithMedia.mm in Sources */, 2884 2894 1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPUDevice.mm
r213549 r213650 24 24 */ 25 25 26 #i fdef ENABLE_WEBGPU26 #import "config.h" 27 27 28 #include "config.h" 29 #import "Test.h" 28 #if ENABLE(WEBGPU) 29 30 #import "GPUTest.h" 30 31 #import <Metal/Metal.h> 31 32 #import <WebCore/GPUDevice.h> … … 35 36 namespace TestWebKitAPI { 36 37 37 TEST (GPU, Basic)38 TEST_F(GPU, DeviceCreate) 38 39 { 39 40 auto device = GPUDevice::create(); -
trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPUFunction.mm
r213649 r213650 24 24 */ 25 25 26 #ifdef ENABLE_WEBGPU27 26 28 #include "config.h" 29 #import "Test.h" 27 #import "config.h" 28 29 #if ENABLE(WEBGPU) 30 31 #import "GPUTest.h" 30 32 #import <Metal/Metal.h> 31 33 #import <WebCore/GPUDevice.h> 34 #import <WebCore/GPUFunction.h> 35 #import <WebCore/GPULibrary.h> 36 #import <wtf/MainThread.h> 32 37 33 38 using namespace WebCore; … … 35 40 namespace TestWebKitAPI { 36 41 37 TEST (GPU, Basic)42 TEST_F(GPU, FunctionAccessByName) 38 43 { 39 44 auto device = GPUDevice::create(); … … 44 49 return; 45 50 46 EXPECT_NOT_NULL(device->layer());47 EXPECT_NOT_NULL(device->platformLayer());48 49 51 id<MTLDevice> mtlDevice = (id<MTLDevice>)device->platformDevice(); 50 52 EXPECT_NOT_NULL(mtlDevice); 51 53 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); 54 67 } 55 68 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPULibrary.mm
r213649 r213650 24 24 */ 25 25 26 #i fdef ENABLE_WEBGPU26 #import "config.h" 27 27 28 #include "config.h" 29 #import "Test.h" 28 #if ENABLE(WEBGPU) 29 30 #import "GPUTest.h" 30 31 #import <Metal/Metal.h> 31 32 #import <WebCore/GPUDevice.h> 33 #import <WebCore/GPULibrary.h> 34 #import <wtf/MainThread.h> 32 35 33 36 using namespace WebCore; … … 35 38 namespace TestWebKitAPI { 36 39 37 TEST (GPU, Basic)40 TEST_F(GPU, LibraryCreate) 38 41 { 39 42 auto device = GPUDevice::create(); … … 44 47 return; 45 48 46 EXPECT_NOT_NULL(device->layer());47 EXPECT_NOT_NULL(device->platformLayer());48 49 49 id<MTLDevice> mtlDevice = (id<MTLDevice>)device->platformDevice(); 50 50 EXPECT_NOT_NULL(mtlDevice); 51 51 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 56 TEST_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 69 TEST_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"); 54 82 } 55 83 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/mac/GPUTest.h
r213649 r213650 24 24 */ 25 25 26 # ifdef ENABLE_WEBGPU26 #pragma once 27 27 28 #include "config.h"29 28 #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> 34 31 35 32 namespace TestWebKitAPI { 36 33 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; 34 class GPU : public testing::Test { 35 public: 36 void SetUp() final 37 { 38 WTF::initializeMainThread(); 45 39 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 } 48 56 49 id<MTLDevice> mtlDevice = (id<MTLDevice>)device->platformDevice(); 50 EXPECT_NOT_NULL(mtlDevice); 57 const String& librarySourceCode() { return m_librarySourceCode; } 51 58 52 NSString *deviceName = mtlDevice.name; 53 EXPECT_GT(deviceName.length, static_cast<unsigned long>(0)); 59 private: 60 String m_librarySourceCode; 61 }; 62 54 63 } 55 56 } // namespace TestWebKitAPI57 58 #endif
Note: See TracChangeset
for help on using the changeset viewer.