Changeset 241181 in webkit
- Timestamp:
- Feb 7, 2019 6:01:39 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r241179 r241181 1 2019-02-07 Justin Fan <justin_fan@apple.com> 2 3 [Web GPU] GPUDevice::createTexture implementation prototype 4 https://bugs.webkit.org/show_bug.cgi?id=194409 5 <rdar://problem/47894312> 6 7 Reviewed by Myles C. Maxfield. 8 9 Update textures-textureviews.html to WPT format and to test creation of textures via the GPUDevice. 10 11 * webgpu/textures-textureviews-expected.txt: 12 * webgpu/textures-textureviews.html: 13 1 14 2019-02-07 Shawn Roberts <sroberts@apple.com> 2 15 -
trunk/LayoutTests/webgpu/textures-textureviews-expected.txt
r238382 r241181 1 PASS [object WebGPU] is defined.2 PASS Acquired next WebGPUTexture from WebGPURenderingContext.3 PASS Created default WebGPUTextureView from a WebGPUTexture4 All tests complete.5 PASS successfullyParsed is true6 1 7 TEST COMPLETE 2 PASS Create texture view from swap chain. 3 PASS Create basic depth texture from device. 4 PASS Create basic 4x multisampled texture. 5 PASS Create basic 3D texture from device. 8 6 -
trunk/LayoutTests/webgpu/textures-textureviews.html
r238382 r241181 1 <!DOCTYPE html> 2 <html> 3 <script src="../resources/js-test-pre.js"></script> 4 <script src="js/basic-webgpu-functions.js"></script> 1 <!DOCTYPE html><!-- webkit-test-runner [ experimental:WebGPUEnabled=true ] --> 2 <meta charset=utf-8> 3 <title>Basic GPUTexture Tests.</title> 4 <body> 5 <canvas width="400" height="400"></canvas> 6 <script src="js/webgpu-functions.js"></script> 7 <script src="../resources/testharness.js"></script> 8 <script src="../resources/testharnessreport.js"></script> 5 9 <script> 6 if (window.testRunner) 7 window.testRunner.dumpAsText();10 const canvas = document.querySelector("canvas"); 11 let device, context; 8 12 9 function setUpNextTextureView() { 10 let texture = context.getNextTexture(); 11 if (texture) 12 testPassed("Acquired next WebGPUTexture from WebGPURenderingContext."); 13 else { 14 testFailed("Could not get next WebGPUTexture from WebGPURenderingContext!"); 15 return; 16 } 13 let texSize = { 14 width: canvas.width, 15 height: canvas.height, 16 depth: 1 17 }; 17 18 18 let textureView = texture.createDefaultTextureView(); 19 if (textureView) 20 testPassed("Created default WebGPUTextureView from a WebGPUTexture"); 21 else { 22 testFailed("Could not create default WebGPUTextureView!"); 23 return; 24 } 25 } 19 let texDescriptor = { 20 size: texSize, 21 arrayLayerCount: 1, 22 mipLevelCount: 1, 23 sampleCount: 1, 24 dimension: "2d", 25 format: "d32-float-s8-uint", 26 usage: GPUTextureUsage.OUTPUT_ATTACHMENT 27 }; 26 28 27 // FIXME: Add tests for device.createTexture, WebGPUTextureDescriptor, and WebGPUTextureViewDescriptor. 29 promise_test(async () => { 30 device = await getBasicDevice(); 31 context = createBasicContext(canvas, device); 28 32 29 runWebGPUTests([setUpNextTextureView]); 33 const texture = context.getNextTexture(); 34 assert_true(texture instanceof WebGPUTexture, "Successfully acquired next texture."); 30 35 31 successfullyParsed = true; 36 const textureView = texture.createDefaultTextureView(); 37 assert_true(textureView instanceof WebGPUTextureView, "Successfully created texture view from next texture."); 38 }, "Create texture view from swap chain."); 39 40 promise_test(async () => { 41 const depthTexture = device.createTexture(texDescriptor); 42 assert_true(depthTexture instanceof WebGPUTexture, "Successfully created depth texture."); 43 }, "Create basic depth texture from device."); 44 45 promise_test(async () => { 46 texDescriptor.sampleCount = 4; 47 texDescriptor.format = "r8g8b8a8-unorm"; 48 texDescriptor.usage = GPUTextureUsage.SAMPLED | GPUTextureUsage.TRANSFER_SRC 49 50 const multisampledTexture = device.createTexture(texDescriptor); 51 assert_true(multisampledTexture instanceof WebGPUTexture, "Successfully created multisampled texture."); 52 }, "Create basic 4x multisampled texture."); 53 54 promise_test(async () => { 55 texDescriptor.size.depth = 3; 56 texDescriptor.sampleCount = 1; 57 texDescriptor.dimension = "3d"; 58 59 const texture3d = device.createTexture(texDescriptor); 60 assert_true(texture3d instanceof WebGPUTexture, "Successfully created basic 3D texture."); 61 }, "Create basic 3D texture from device."); 62 63 // FIXME: Add tests for 1D textures, textureArrays, and WebGPUTextureViews. 32 64 </script> 33 < script src="../resources/js-test-post.js"></script>65 </body> 34 66 </html> -
trunk/Source/WebCore/ChangeLog
r241170 r241181 1 2019-02-07 Justin Fan <justin_fan@apple.com> 2 3 [Web GPU] GPUDevice::createTexture implementation prototype 4 https://bugs.webkit.org/show_bug.cgi?id=194409 5 <rdar://problem/47894312> 6 7 Reviewed by Myles C. Maxfield. 8 9 Test: textures-textureviews.html updated to test new functionality. 10 11 Implement GPUDevice::createTexture(): 12 * Modules/webgpu/WebGPUDevice.cpp: 13 (WebCore::WebGPUDevice::createTexture const): 14 * Modules/webgpu/WebGPUDevice.h: 15 * Modules/webgpu/WebGPUDevice.idl: 16 * Modules/webgpu/WebGPUTexture.cpp: 17 (WebCore::WebGPUTexture::create): Modified to return non-nullable to match direction of API. 18 (WebCore::WebGPUTexture::WebGPUTexture): 19 * Modules/webgpu/WebGPUTexture.h: 20 21 Metal backend MTLTextureDescriptor and MTLTexture creation: 22 * platform/graphics/gpu/GPUDevice.cpp: 23 (WebCore::GPUDevice::tryCreateTexture const): 24 * platform/graphics/gpu/GPUDevice.h: 25 * platform/graphics/gpu/GPUTexture.h: 26 * platform/graphics/gpu/cocoa/GPUTextureMetal.mm: 27 (WebCore::mtlTextureTypeForGPUTextureDescriptor): 28 (WebCore::mtlTextureUsageForGPUTextureUsageFlags): 29 (WebCore::storageModeForPixelFormatAndSampleCount): 30 (WebCore::tryCreateMtlTextureDescriptor): 31 (WebCore::GPUTexture::tryCreate): 32 (WebCore::GPUTexture::createDefaultTextureView): Add ObjC try/catch guards. 33 34 Add GPUUtils.h/cpp for shared utility functions: 35 * SourcesCocoa.txt: 36 * WebCore.xcodeproj/project.pbxproj: 37 * platform/graphics/gpu/GPUUtils.h: Added. Moved platformTextureFormatForGPUTextureFormat here. 38 * platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm: 39 (WebCore::GPUSwapChain::setFormat): 40 (WebCore::platformTextureFormatForGPUTextureFormat): Moved to GPUUtils. 41 * platform/graphics/gpu/cocoa/GPUUtilsMetal.mm: Added. 42 (WebCore::platformTextureFormatForGPUTextureFormat): Moved here to be referenced by multiple files. 43 1 44 2019-02-07 Sihui Liu <sihui_liu@apple.com> 2 45 -
trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp
r240807 r241181 37 37 #include "GPURenderPipelineDescriptor.h" 38 38 #include "GPUShaderModuleDescriptor.h" 39 #include "GPUTextureDescriptor.h" 39 40 #include "Logging.h" 40 41 #include "WebGPUBindGroup.h" … … 53 54 #include "WebGPUShaderModule.h" 54 55 #include "WebGPUShaderModuleDescriptor.h" 56 #include "WebGPUTexture.h" 55 57 #include <wtf/Variant.h> 56 58 … … 77 79 return WebGPUBuffer::create(buffer.releaseNonNull()); 78 80 return nullptr; 81 } 82 83 Ref<WebGPUTexture> WebGPUDevice::createTexture(GPUTextureDescriptor&& descriptor) const 84 { 85 auto texture = m_device->tryCreateTexture(WTFMove(descriptor)); 86 return WebGPUTexture::create(WTFMove(texture)); 79 87 } 80 88 -
trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h
r239853 r241181 48 48 class WebGPURenderPipeline; 49 49 class WebGPUShaderModule; 50 class WebGPUTexture; 50 51 52 struct GPUTextureDescriptor; 51 53 struct WebGPUBindGroupDescriptor; 52 54 struct WebGPUPipelineLayoutDescriptor; … … 62 64 63 65 RefPtr<WebGPUBuffer> createBuffer(WebGPUBufferDescriptor&&) const; 66 Ref<WebGPUTexture> createTexture(GPUTextureDescriptor&&) const; 64 67 65 68 Ref<WebGPUBindGroupLayout> createBindGroupLayout(WebGPUBindGroupLayoutDescriptor&&) const; -
trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl
r240748 r241181 33 33 34 34 WebGPUBuffer createBuffer(WebGPUBufferDescriptor descriptor); 35 WebGPUTexture createTexture(GPUTextureDescriptor descriptor); 35 36 36 37 WebGPUBindGroupLayout createBindGroupLayout(WebGPUBindGroupLayoutDescriptor descriptor); -
trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp
r239535 r241181 33 33 namespace WebCore { 34 34 35 Ref Ptr<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture)35 Ref<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture) 36 36 { 37 return texture ? adoptRef(new WebGPUTexture(texture.releaseNonNull())) : nullptr;37 return adoptRef(*new WebGPUTexture(WTFMove(texture))); 38 38 } 39 39 40 WebGPUTexture::WebGPUTexture(Ref <GPUTexture>&& texture)40 WebGPUTexture::WebGPUTexture(RefPtr<GPUTexture>&& texture) 41 41 : m_texture(WTFMove(texture)) 42 42 { -
trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.h
r238741 r241181 39 39 class WebGPUTexture : public RefCounted<WebGPUTexture> { 40 40 public: 41 static Ref Ptr<WebGPUTexture> create(RefPtr<GPUTexture>&&);41 static Ref<WebGPUTexture> create(RefPtr<GPUTexture>&&); 42 42 43 43 RefPtr<WebGPUTextureView> createDefaultTextureView(); 44 44 45 45 private: 46 explicit WebGPUTexture(Ref <GPUTexture>&&);46 explicit WebGPUTexture(RefPtr<GPUTexture>&&); 47 47 48 Ref <GPUTexture> m_texture;48 RefPtr<GPUTexture> m_texture; 49 49 }; 50 50 -
trunk/Source/WebCore/SourcesCocoa.txt
r241105 r241181 332 332 platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm 333 333 platform/graphics/gpu/cocoa/GPUTextureMetal.mm 334 platform/graphics/gpu/cocoa/GPUUtilsMetal.mm 334 335 platform/graphics/gpu/Texture.cpp 335 336 platform/graphics/gpu/TilingData.cpp -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r241105 r241181 14067 14067 D06C0D8D0CFD11460065F43F /* RemoveFormatCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoveFormatCommand.h; sourceTree = "<group>"; }; 14068 14068 D06C0D8E0CFD11460065F43F /* RemoveFormatCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoveFormatCommand.cpp; sourceTree = "<group>"; }; 14069 D06EF552220BA26A0018724E /* GPUUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUUtils.h; sourceTree = "<group>"; }; 14070 D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUUtilsMetal.mm; sourceTree = "<group>"; }; 14069 14071 D07DEAB70A36554A00CA30F8 /* InsertListCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InsertListCommand.cpp; sourceTree = "<group>"; }; 14070 14072 D07DEAB80A36554A00CA30F8 /* InsertListCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InsertListCommand.h; sourceTree = "<group>"; }; … … 18504 18506 312FF8C321A4C2F300EB199D /* GPUTextureFormat.h */, 18505 18507 D026F485220A477200AC5F49 /* GPUTextureUsage.h */, 18508 D06EF552220BA26A0018724E /* GPUUtils.h */, 18506 18509 D0D8649B21BA1C2D003C983C /* GPUVertexAttributeDescriptor.h */, 18507 18510 D0D8649C21BA1CE8003C983C /* GPUVertexInputDescriptor.h */, … … 26189 26192 D087CE3E21ACA94200BDE174 /* GPUSwapChainMetal.mm */, 26190 26193 D087CE3F21ACA94200BDE174 /* GPUTextureMetal.mm */, 26194 D06EF553220BA26A0018724E /* GPUUtilsMetal.mm */, 26191 26195 ); 26192 26196 path = cocoa; -
trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
r240180 r241181 40 40 #include "GPUShaderModule.h" 41 41 #include "GPUShaderModuleDescriptor.h" 42 #include "GPUTexture.h" 43 #include "GPUTextureDescriptor.h" 42 44 43 45 namespace WebCore { … … 46 48 { 47 49 return GPUBuffer::create(*this, WTFMove(descriptor)); 50 } 51 52 RefPtr<GPUTexture> GPUDevice::tryCreateTexture(GPUTextureDescriptor&& descriptor) const 53 { 54 return GPUTexture::tryCreate(*this, WTFMove(descriptor)); 48 55 } 49 56 -
trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h
r240807 r241181 47 47 class GPURenderPipeline; 48 48 class GPUShaderModule; 49 class GPUTexture; 49 50 50 51 struct GPUBindGroupLayoutDescriptor; … … 54 55 struct GPURequestAdapterOptions; 55 56 struct GPUShaderModuleDescriptor; 57 struct GPUTextureDescriptor; 56 58 57 59 class GPUDevice : public RefCounted<GPUDevice> { … … 60 62 61 63 RefPtr<GPUBuffer> createBuffer(GPUBufferDescriptor&&) const; 64 RefPtr<GPUTexture> tryCreateTexture(GPUTextureDescriptor&&) const; 62 65 63 66 RefPtr<GPUBindGroupLayout> tryCreateBindGroupLayout(GPUBindGroupLayoutDescriptor&&) const; -
trunk/Source/WebCore/platform/graphics/gpu/GPUTexture.h
r238629 r241181 36 36 namespace WebCore { 37 37 38 class GPUDevice; 39 40 struct GPUTextureDescriptor; 41 38 42 using PlatformTexture = MTLTexture; 39 43 using PlatformTextureSmartPtr = RetainPtr<MTLTexture>; … … 41 45 class GPUTexture : public RefCounted<GPUTexture> { 42 46 public: 47 static RefPtr<GPUTexture> tryCreate(const GPUDevice&, GPUTextureDescriptor&&); 43 48 static Ref<GPUTexture> create(PlatformTextureSmartPtr&&); 44 49 -
trunk/Source/WebCore/platform/graphics/gpu/GPUUtils.h
r241180 r241181 1 1 /* 2 * Copyright (C) 201 8Apple Inc. All rights reserved.2 * Copyright (C) 2019 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 28 28 #if ENABLE(WEBGPU) 29 29 30 #include "GPUTexture.h" 31 32 #include <wtf/RefCounted.h> 33 #include <wtf/RefPtr.h> 30 #include "GPUTextureFormat.h" 34 31 35 32 namespace WebCore { 36 33 37 class WebGPUTextureView; 38 39 class WebGPUTexture : public RefCounted<WebGPUTexture> { 40 public: 41 static RefPtr<WebGPUTexture> create(RefPtr<GPUTexture>&&); 42 43 RefPtr<WebGPUTextureView> createDefaultTextureView(); 44 45 private: 46 explicit WebGPUTexture(Ref<GPUTexture>&&); 47 48 Ref<GPUTexture> m_texture; 49 }; 34 PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat); 50 35 51 36 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm
r241048 r241181 32 32 #import "GPUTexture.h" 33 33 #import "GPUTextureFormat.h" 34 #import "GPUUtils.h" 34 35 #import "Logging.h" 35 36 #import "WebGPULayer.h" 36 37 37 #import <Metal/Metal.h> 38 38 #import <QuartzCore/QuartzCore.h> … … 81 81 } 82 82 83 static Optional<PlatformTextureFormat> platformTextureFormatForGPUTextureFormat(GPUTextureFormat format)84 {85 switch (format) {86 case GPUTextureFormat::R8g8b8a8Unorm:87 return MTLPixelFormatRGBA8Unorm;88 case GPUTextureFormat::R8g8b8a8Uint:89 return MTLPixelFormatRGBA8Uint;90 case GPUTextureFormat::B8g8r8a8Unorm:91 return MTLPixelFormatBGRA8Unorm;92 case GPUTextureFormat::D32FloatS8Uint:93 return MTLPixelFormatDepth32Float_Stencil8;94 default:95 LOG(WebGPU, "GPUSwapChain::setFormat(): Invalid texture format specified!");96 return WTF::nullopt;97 }98 }99 100 83 void GPUSwapChain::setFormat(GPUTextureFormat format) 101 84 { 102 auto result = platformTextureFormatForGPUTextureFormat(format); 103 if (!result) 104 return; 85 auto mtlFormat = static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(format)); 105 86 106 auto mtlResult = static_cast<MTLPixelFormat>(result.value()); 107 108 switch (mtlResult) { 87 switch (mtlFormat) { 109 88 case MTLPixelFormatBGRA8Unorm: 110 89 // FIXME: Add the other supported swap layer formats as they are added to GPU spec. 111 90 // MTLPixelFormatBGRA8Unorm_sRGB, MTLPixelFormatRGBA16Float, MTLPixelFormatBGRA10_XR, and MTLPixelFormatBGRA10_XR_sRGB. 112 [m_platformSwapLayer setPixelFormat:mtl Result];91 [m_platformSwapLayer setPixelFormat:mtlFormat]; 113 92 return; 114 93 default: -
trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm
r239094 r241181 29 29 #if ENABLE(WEBGPU) 30 30 31 #import "GPUDevice.h" 32 #import "GPUTextureDescriptor.h" 33 #import "GPUUtils.h" 31 34 #import "Logging.h" 32 33 35 #import <Metal/Metal.h> 34 36 #import <wtf/BlockObjCExceptions.h> 37 #import <wtf/Optional.h> 35 38 36 39 namespace WebCore { 40 41 static MTLTextureType mtlTextureTypeForGPUTextureDescriptor(const GPUTextureDescriptor& descriptor) 42 { 43 switch (descriptor.dimension) { 44 case GPUTextureDimension::_1d: 45 return (descriptor.arrayLayerCount == 1) ? MTLTextureType1D : MTLTextureType1DArray; 46 case GPUTextureDimension::_2d: { 47 if (descriptor.arrayLayerCount == 1) 48 return (descriptor.sampleCount == 1) ? MTLTextureType2D : MTLTextureType2DMultisample; 49 50 return MTLTextureType2DArray; 51 } 52 case GPUTextureDimension::_3d: 53 return MTLTextureType3D; 54 } 55 } 56 57 static Optional<MTLTextureUsage> mtlTextureUsageForGPUTextureUsageFlags(GPUTextureUsageFlags flags) 58 { 59 MTLTextureUsage usage = MTLTextureUsageUnknown; 60 61 if (flags & GPUTextureUsage::Storage) 62 usage |= MTLTextureUsageShaderWrite | MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView; 63 64 if (flags & GPUTextureUsage::Sampled) { 65 // SAMPLED is a read-only usage. 66 if (flags & GPUTextureUsage::Storage) 67 return WTF::nullopt; 68 69 usage |= MTLTextureUsageShaderRead | MTLTextureUsagePixelFormatView; 70 } 71 72 if (flags & GPUTextureUsage::OutputAttachment) 73 usage |= MTLTextureUsageRenderTarget; 74 75 return usage; 76 } 77 78 static MTLStorageMode storageModeForPixelFormatAndSampleCount(MTLPixelFormat format, unsigned long samples) 79 { 80 // Depth, Stencil, DepthStencil, and Multisample textures must be allocated with the MTLStorageModePrivate resource option. 81 if (format == MTLPixelFormatDepth32Float_Stencil8 || samples > 1) 82 return MTLStorageModePrivate; 83 84 return MTLStorageModeManaged; 85 } 86 87 static RetainPtr<MTLTextureDescriptor> tryCreateMtlTextureDescriptor(const char* const functionName, const GPUTextureDescriptor&& descriptor) 88 { 89 #if LOG_DISABLED 90 UNUSED_PARAM(functionName); 91 #endif 92 93 RetainPtr<MTLTextureDescriptor> mtlDescriptor; 94 95 BEGIN_BLOCK_OBJC_EXCEPTIONS; 96 97 mtlDescriptor = adoptNS([MTLTextureDescriptor new]); 98 99 END_BLOCK_OBJC_EXCEPTIONS; 100 101 if (!mtlDescriptor) { 102 LOG(WebGPU, "%s: Unable to create new MTLTextureDescriptor!", functionName); 103 return nullptr; 104 } 105 106 // FIXME: Add more validation as constraints are added to spec. 107 auto pixelFormat = static_cast<MTLPixelFormat>(platformTextureFormatForGPUTextureFormat(descriptor.format)); 108 109 auto usage = mtlTextureUsageForGPUTextureUsageFlags(descriptor.usage); 110 if (!usage) { 111 LOG(WebGPU, "%s: Invalid GPUTextureUsageFlags!", functionName); 112 return nullptr; 113 } 114 115 auto storageMode = storageModeForPixelFormatAndSampleCount(pixelFormat, descriptor.sampleCount); 116 117 BEGIN_BLOCK_OBJC_EXCEPTIONS; 118 119 [mtlDescriptor setWidth:descriptor.size.width]; 120 [mtlDescriptor setHeight:descriptor.size.height]; 121 [mtlDescriptor setDepth:descriptor.size.depth]; 122 [mtlDescriptor setArrayLength:descriptor.arrayLayerCount]; 123 [mtlDescriptor setMipmapLevelCount:descriptor.mipLevelCount]; 124 [mtlDescriptor setSampleCount:descriptor.sampleCount]; 125 [mtlDescriptor setTextureType:mtlTextureTypeForGPUTextureDescriptor(descriptor)]; 126 [mtlDescriptor setPixelFormat:pixelFormat]; 127 [mtlDescriptor setUsage:*usage]; 128 129 [mtlDescriptor setStorageMode:storageMode]; 130 131 END_BLOCK_OBJC_EXCEPTIONS; 132 133 return mtlDescriptor; 134 } 135 136 RefPtr<GPUTexture> GPUTexture::tryCreate(const GPUDevice& device, GPUTextureDescriptor&& descriptor) 137 { 138 const char* const functionName = "GPUTexture::tryCreate()"; 139 140 if (!device.platformDevice()) { 141 LOG(WebGPU, "%s: Invalid GPUDevice!", functionName); 142 return nullptr; 143 } 144 145 auto mtlDescriptor = tryCreateMtlTextureDescriptor(functionName, WTFMove(descriptor)); 146 if (!mtlDescriptor) 147 return nullptr; 148 149 RetainPtr<MTLTexture> mtlTexture; 150 151 BEGIN_BLOCK_OBJC_EXCEPTIONS; 152 153 mtlTexture = adoptNS([device.platformDevice() newTextureWithDescriptor:mtlDescriptor.get()]); 154 155 END_BLOCK_OBJC_EXCEPTIONS; 156 157 if (!mtlTexture) { 158 LOG(WebGPU, "%s: Unable to create MTLTexture!", functionName); 159 return nullptr; 160 } 161 162 return adoptRef(new GPUTexture(WTFMove(mtlTexture))); 163 } 37 164 38 165 Ref<GPUTexture> GPUTexture::create(PlatformTextureSmartPtr&& texture) … … 50 177 RetainPtr<MTLTexture> texture; 51 178 179 BEGIN_BLOCK_OBJC_EXCEPTIONS; 180 52 181 texture = adoptNS([m_platformTexture newTextureViewWithPixelFormat:m_platformTexture.get().pixelFormat]); 182 183 END_BLOCK_OBJC_EXCEPTIONS; 53 184 54 185 if (!texture) { -
trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUUtilsMetal.mm
r241180 r241181 1 1 /* 2 * Copyright (C) 201 8Apple Inc. All rights reserved.2 * Copyright (C) 2019 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 #pragma once 26 #import "config.h" 27 #import "GPUUtils.h" 27 28 28 29 #if ENABLE(WEBGPU) 29 30 30 #include "GPUTexture.h" 31 32 #include <wtf/RefCounted.h> 33 #include <wtf/RefPtr.h> 31 #import <Metal/Metal.h> 34 32 35 33 namespace WebCore { 36 34 37 class WebGPUTextureView; 38 39 class WebGPUTexture : public RefCounted<WebGPUTexture>{40 public:41 static RefPtr<WebGPUTexture> create(RefPtr<GPUTexture>&&);42 43 RefPtr<WebGPUTextureView> createDefaultTextureView();44 45 private: 46 explicit WebGPUTexture(Ref<GPUTexture>&&);47 48 Ref<GPUTexture> m_texture;49 } ;35 PlatformTextureFormat platformTextureFormatForGPUTextureFormat(GPUTextureFormat format) 36 { 37 switch (format) { 38 case GPUTextureFormat::R8g8b8a8Unorm: 39 return MTLPixelFormatRGBA8Unorm; 40 case GPUTextureFormat::R8g8b8a8Uint: 41 return MTLPixelFormatRGBA8Uint; 42 case GPUTextureFormat::B8g8r8a8Unorm: 43 return MTLPixelFormatBGRA8Unorm; 44 case GPUTextureFormat::D32FloatS8Uint: 45 return MTLPixelFormatDepth32Float_Stencil8; 46 } 47 } 50 48 51 49 } // namespace WebCore
Note: See TracChangeset
for help on using the changeset viewer.