-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[webgpu] Add Surface API #21939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[webgpu] Add Surface API #21939
Changes from all commits
433fd95
767b08d
58bd82f
a0d767e
84cf370
ad186ce
222ef5a
c03ef6a
5c6c62d
d9dbf13
084f0a0
6f82930
c68cffd
8390ae3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,10 @@ wgpu${type}Release: (id) => WebGPU.mgr${type}.release(id),`; | |
| DeviceLost: 2, | ||
| Unknown: 3, | ||
| }, | ||
| CompositeAlphaMode: { | ||
| Auto: 0, | ||
| Opaque: 1, | ||
| }, | ||
| CreatePipelineAsyncStatus: { | ||
| Success: 0, | ||
| ValidationError: 1, | ||
|
|
@@ -154,6 +158,10 @@ wgpu${type}Release: (id) => WebGPU.mgr${type}.release(id),`; | |
| RenderPassDescriptorMaxDrawCount: 0xF, | ||
| TextureBindingViewDimensionDescriptor: 0x11, | ||
| }, | ||
| SurfaceGetCurrentTextureStatus: { | ||
| Success: 0, | ||
| DeviceLost: 5, | ||
| }, | ||
| QueueWorkDoneStatus: { | ||
| Success: 0, | ||
| Error: 1, | ||
|
|
@@ -2664,7 +2672,7 @@ var LibraryWebGPU = { | |
| // WGPUAdapterProperties | ||
|
|
||
| wgpuAdapterPropertiesFreeMembers: (value) => { | ||
| // wgpuAdapterGetProperties does currently allocate anything | ||
| // wgpuAdapterGetProperties doesn't currently allocate anything. | ||
| }, | ||
|
|
||
| // WGPUSampler | ||
|
|
@@ -2676,11 +2684,83 @@ var LibraryWebGPU = { | |
|
|
||
| // WGPUSurface | ||
|
|
||
| wgpuSurfaceConfigure: (surfaceId, config) => { | ||
| {{{ gpu.makeCheckDescriptor('config') }}} | ||
| var deviceId = {{{ makeGetValue('config', C_STRUCTS.WGPUSurfaceConfiguration.device, '*') }}}; | ||
| var context = WebGPU.mgrSurface.get(surfaceId); | ||
|
|
||
| #if ASSERTIONS | ||
| var viewFormatCount = {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.viewFormatCount) }}}; | ||
| var viewFormats = {{{ makeGetValue('config', C_STRUCTS.WGPUSurfaceConfiguration.viewFormats, '*') }}}; | ||
| assert(viewFormatCount === 0 && viewFormats === 0, "TODO: Support viewFormats."); | ||
| var alphaMode = {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.alphaMode) }}}; | ||
| assert(alphaMode === {{{ gpu.CompositeAlphaMode.Auto }}} || | ||
| alphaMode === {{{ gpu.CompositeAlphaMode.Opaque }}}, | ||
| "TODO: Support WGPUCompositeAlphaMode_Premultiplied."); | ||
| assert({{{ gpu.PresentMode.Fifo }}} === | ||
| {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.presentMode) }}}); | ||
| #endif | ||
|
|
||
| var canvasSize = [ | ||
| {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.width) }}}, | ||
| {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.height) }}} | ||
| ]; | ||
|
|
||
| if (canvasSize[0] !== 0) { | ||
| context["canvas"]["width"] = canvasSize[0]; | ||
| } | ||
|
|
||
| if (canvasSize[1] !== 0) { | ||
| context["canvas"]["height"] = canvasSize[1]; | ||
| } | ||
|
|
||
| var configuration = { | ||
| "device": WebGPU.mgrDevice.get(deviceId), | ||
| "format": WebGPU.TextureFormat[ | ||
| {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.format) }}}], | ||
| "usage": {{{ gpu.makeGetU32('config', C_STRUCTS.WGPUSurfaceConfiguration.usage) }}}, | ||
| "alphaMode": "opaque", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be either Alternatively, assert the alphaMode is Opaque for now with a TODO, and implement this later if you'd like.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've assert alphaMode is Opaque with a TODO. |
||
| }; | ||
| context.configure(configuration); | ||
| }, | ||
|
|
||
| wgpuSurfaceGetCurrentTexture: (surfaceId, surfaceTexturePtr) => { | ||
| {{{ gpu.makeCheck('surfaceTexturePtr') }}} | ||
| var context = WebGPU.mgrSurface.get(surfaceId); | ||
|
|
||
| try { | ||
| var texture = WebGPU.mgrTexture.create(context.getCurrentTexture()); | ||
| {{{ makeSetValue('surfaceTexturePtr', C_STRUCTS.WGPUSurfaceTexture.texture, 'texture', '*') }}}; | ||
| {{{ makeSetValue('surfaceTexturePtr', C_STRUCTS.WGPUSurfaceTexture.suboptimal, '0', 'i32') }}}; | ||
| {{{ makeSetValue('surfaceTexturePtr', C_STRUCTS.WGPUSurfaceTexture.status, | ||
| gpu.SurfaceGetCurrentTextureStatus.Success, 'i32') }}}; | ||
| } catch (ex) { | ||
| #if ASSERTIONS | ||
| err(`wgpuSurfaceGetCurrentTexture() failed: ${ex}`); | ||
| #endif | ||
kainino0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {{{ makeSetValue('surfaceTexturePtr', C_STRUCTS.WGPUSurfaceTexture.texture, '0', '*') }}}; | ||
| {{{ makeSetValue('surfaceTexturePtr', C_STRUCTS.WGPUSurfaceTexture.suboptimal, '0', 'i32') }}}; | ||
| // TODO(https://github.com/webgpu-native/webgpu-headers/issues/291): What should the status be here? | ||
| {{{ makeSetValue('surfaceTexturePtr', C_STRUCTS.WGPUSurfaceTexture.status, | ||
| gpu.SurfaceGetCurrentTextureStatus.DeviceLost, 'i32') }}}; | ||
| } | ||
| }, | ||
|
|
||
| wgpuSurfaceGetPreferredFormat: (surfaceId, adapterId) => { | ||
| var format = navigator["gpu"]["getPreferredCanvasFormat"](); | ||
| return WebGPU.Int_PreferredFormat[format]; | ||
| }, | ||
|
|
||
| wgpuSurfacePresent: (surfaceId) => { | ||
| // TODO: This could probably be emulated with ASYNCIFY. | ||
| abort('wgpuSurfacePresent is unsupported (use requestAnimationFrame via html5.h instead)'); | ||
| }, | ||
|
|
||
| wgpuSurfaceUnconfigure: (surfaceId) => { | ||
| var context = WebGPU.mgrSurface.get(surfaceId); | ||
| context.unconfigure(); | ||
| }, | ||
|
|
||
| // WGPUSwapChain | ||
|
|
||
| wgpuDeviceCreateSwapChain: (deviceId, surfaceId, descriptor) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.