The BrowserBridge implementation that actually calls the browser's GPU service. More...
#include "donner/gpu/browser/EmscriptenBrowserBridge.h"
Public Member Functions | |
| EmscriptenBrowserBridge () | |
| Constructs a bridge over the browser's GPU service. No browser call happens until beginDeviceRequest. | |
| ~EmscriptenBrowserBridge () override | |
| Destructor; releases this logical device's state on the browser side and leaves every other logical device's alone. The browser device, and the textures its shares still hold, go with the last logical device over it. | |
| BridgeStatus | beginDeviceRequest () override |
| Asks for this logical device's browser GPU device. The first logical device in a worker to ask begins the browser's request, which settles asynchronously; every later one joins the device that request obtains. | |
| BrowserDeviceRequestState | deviceRequestState () const override |
| How far the request begun by beginDeviceRequest has progressed. | |
| RcString | deviceRequestError () const override |
| Why the request failed, when deviceRequestState reports a failure. Empty otherwise. | |
| BridgeStatus | deviceStatus () const override |
| Checks current ownership and loss together. Returns Success for an owned, live device, NotOwner for a missing device or foreign context, or DeviceLost for an owned, lost device. Other statuses indicate a failed query. Implementations must not cache this state. | |
| bool | isDeviceLost () const override |
| Whether the browser has reported the device lost. Once true it never becomes false again. | |
| RcString | deviceLostReason () const override |
| What the browser said when it reported the device lost. Empty while the device is alive. | |
| uint64_t | completedSerial () const override |
| Serial of this logical device's most recent submission the browser has reported finished (0 if none). Each logical device numbers its submissions on its own. | |
| uint32_t | maxTextureDimension2D () const override |
| Largest width or height of a 2D texture the browser device supports, as its limits report it, or 0 when this logical device holds no device or the browser reports no such limit. | |
| const void * | sharedDeviceIdentity () const override |
| Identity of the browser device this logical device runs on: the same for every bridge over that device and different for every other, including a device obtained after this one was released. | |
| BridgeStatus | shareTexture (BrowserObjectId textureId, std::shared_ptr< const BrowserSharedTexture > &shared) override |
Holds the texture textureId for the other logical devices over the same browser device. | |
| BridgeStatus | registerSharedTexture (BrowserObjectId id, const BrowserSharedTexture &shared) override |
Registers the texture shared names under id, as a read-only alias in this logical device. | |
| BridgeStatus | createBuffer (BrowserObjectId id, uint64_t byteSize, uint32_t usageBits) override |
| Creates a buffer. | |
| BridgeStatus | createTexture (BrowserObjectId id, uint32_t width, uint32_t height, uint32_t formatCode, uint32_t usageBits) override |
| Creates a texture. | |
| BridgeStatus | createTextureView (BrowserObjectId id, BrowserObjectId textureId) override |
| Creates a view covering the whole texture. | |
| BridgeStatus | createSampler (BrowserObjectId id, uint32_t magFilterCode, uint32_t minFilterCode, uint32_t addressUCode, uint32_t addressVCode) override |
| Creates a sampler. | |
| BridgeStatus | createBindGroupLayout (BrowserObjectId id, std::span< const BrowserBindGroupLayoutEntry > entries) override |
| Creates a bind group layout. | |
| BridgeStatus | createBindGroup (BrowserObjectId id, BrowserObjectId layoutId, std::span< const BrowserBindGroupEntry > entries) override |
| Creates a bind group. | |
| BridgeStatus | createPipelineLayout (BrowserObjectId id, std::span< const BrowserObjectId > groupLayoutIds) override |
| Creates a pipeline layout. | |
| BridgeStatus | createShaderModule (BrowserObjectId id, std::string_view wgsl) override |
| Creates a shader module from trusted build output. | |
| BridgeStatus | createRenderPipeline (BrowserObjectId id, const BrowserRenderPipelineRequest &request) override |
| Creates a render pipeline. | |
| BridgeStatus | createComputePipeline (BrowserObjectId id, const BrowserComputePipelineRequest &request) override |
| Creates a compute pipeline. | |
| BridgeStatus | destroyObject (BrowserObjectKind kind, BrowserObjectId id) override |
| Releases a browser object and unregisters its identifier, which is never reissued. A texture a share still holds is not destroyed until the share is released. | |
| BridgeStatus | writeBuffer (BrowserObjectId bufferId, uint64_t offsetBytes, std::span< const uint8_t > data) override |
| Writes bytes into a buffer. | |
| BridgeStatus | writeTexture (BrowserObjectId textureId, std::span< const uint8_t > data, const BrowserTexelLayout &layout, const BrowserCopyRegion ®ion) override |
| Writes texel rows into a texture. | |
| BridgeStatus | beginCommandBuffer (uint64_t submissionSerial, uint32_t commandBufferIndex) override |
Opens recording for the command buffer at commandBufferIndex of the submission with submissionSerial. Index zero starts the submission and discards whatever an earlier attempt finished without submitting, so a refused command can never end up submitted as part of a later frame; a later index must find exactly that many finished buffers under the same serial, which is how the two halves agree on what is being recorded. | |
| BridgeStatus | beginRenderPass (std::span< const BrowserColorAttachment > colorAttachments) override |
| Begins a render pass. | |
| BridgeStatus | endRenderPass () override |
| Ends the open render pass. | |
| BridgeStatus | beginComputePass () override |
| Begins a compute pass. | |
| BridgeStatus | endComputePass () override |
| Ends the open compute pass. | |
| BridgeStatus | setRenderPipeline (BrowserObjectId pipelineId) override |
| Sets the render pipeline of the open render pass. | |
| BridgeStatus | setComputePipeline (BrowserObjectId pipelineId) override |
| Sets the compute pipeline of the open compute pass. | |
| BridgeStatus | setBindGroup (uint32_t index, BrowserObjectId bindGroupId) override |
| Binds a group in the open pass. | |
| BridgeStatus | setVertexBuffer (uint32_t slot, BrowserObjectId bufferId, uint64_t offsetBytes) override |
| Binds a vertex buffer. | |
| BridgeStatus | setIndexBuffer (BrowserObjectId bufferId, uint32_t indexFormatCode, uint64_t offsetBytes) override |
| Binds an index buffer. | |
| BridgeStatus | setScissorRect (uint32_t x, uint32_t y, uint32_t width, uint32_t height) override |
| Sets the scissor rectangle. | |
| BridgeStatus | setViewport (float x, float y, float width, float height, float minDepth, float maxDepth) override |
| Sets the viewport. | |
| BridgeStatus | draw (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) override |
| Draws non-indexed geometry. | |
| BridgeStatus | drawIndexed (uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance) override |
| Draws indexed geometry. | |
| BridgeStatus | dispatchWorkgroups (uint32_t countX, uint32_t countY, uint32_t countZ) override |
| Dispatches compute workgroups. | |
| BridgeStatus | copyTextureToBuffer (BrowserObjectId textureId, BrowserObjectId bufferId, const BrowserTexelLayout &layout, const BrowserCopyRegion ®ion) override |
| Copies texels into a buffer. | |
| BridgeStatus | copyTextureToTexture (BrowserObjectId sourceTextureId, BrowserObjectId destinationTextureId, const BrowserCopyRegion ®ion) override |
| Copies texels between textures. | |
| BridgeStatus | endCommandBuffer (uint64_t submissionSerial) override |
| Finishes the open command buffer and holds it for the submission, without reaching the queue: a submission of several buffers reaches the queue once, in submitCommandBuffers. | |
| BridgeStatus | submitCommandBuffers (uint64_t submissionSerial) override |
Submits every command buffer finished under submissionSerial as one queue submission, in the order they were recorded, and arranges for the reported completed serial to reach submissionSerial once that submission finishes. | |
| BridgeStatus | mapBufferAsync (BrowserObjectId mappingId, BrowserObjectId bufferId, uint64_t offsetBytes, uint64_t byteCount) override |
| Begins mapping a buffer range for host reads. | |
| MapSliceState | mappingState (BrowserObjectId mappingId) const override |
| State of a mapping the browser has been asked for. | |
| BridgeStatus | requestMappingProgress (BrowserObjectId mappingId) override |
| Submits an empty command list while this mapping remains pending, without submitting recorded commands or changing logical submission serials. | |
| void | yieldToBrowser (double seconds) override |
Gives the browser up to seconds of this thread to make progress. | |
| BridgeStatus | mappedBytes (BrowserObjectId mappingId, std::span< const uint8_t > &bytes) const override |
| Bytes of a completed mapping, valid until the mapping is released. Returns an empty span with a non-success status when the mapping is not readable. | |
| BridgeStatus | unmapBuffer (BrowserObjectId mappingId) override |
| Releases a mapping and unregisters its identifier. | |
| BridgeStatus | createSurface (BrowserObjectId id, std::string_view canvasSelector) override |
Creates a surface over the canvas named by canvasSelector. | |
| BridgeStatus | surfaceCapabilities (BrowserObjectId surfaceId, BrowserSurfaceCapabilities &capabilities) const override |
| Reports what a surface supports. | |
| BridgeStatus | configureSurface (BrowserObjectId surfaceId, uint32_t formatCode, uint32_t usageBits, uint32_t width, uint32_t height, uint32_t alphaModeCode) override |
| Configures how a surface presents. | |
| BridgeStatus | acquireCurrentTexture (BrowserObjectId surfaceId, BrowserObjectId textureId, SurfaceStatus &status) override |
Takes the surface's texture for this frame and registers it under textureId. | |
| BridgeStatus | presentSurface (BrowserObjectId surfaceId, SurfaceStatus &status) override |
| Finishes the acquired canvas frame for implicit browser presentation. | |
| BridgeStatus | abandonCurrentTexture (BrowserObjectId surfaceId) override |
| Gives back the acquired texture without showing it. | |
| Public Member Functions inherited from donner::gpu::browser::BrowserBridge | |
| virtual | ~BrowserBridge () |
| Destructor; releases this logical device's state on the browser side. The browser device itself goes once no logical device over it is left. | |
| BrowserBridge (const BrowserBridge &)=delete | |
| BrowserBridge & | operator= (const BrowserBridge &)=delete |
| BrowserBridge (BrowserBridge &&)=delete | |
| BrowserBridge & | operator= (BrowserBridge &&)=delete |
Additional Inherited Members | |
| Protected Member Functions inherited from donner::gpu::browser::BrowserBridge | |
| BrowserBridge () | |
| Constructor for implementations. | |
The BrowserBridge implementation that actually calls the browser's GPU service.
Every method forwards to one entry point of library_donner_gpu.js, which owns the browser objects and performs the identifier, kind and ownership checks on its side. This class holds no browser state of its own beyond the mapped bytes it copies out of the browser's heap, so what exists is recorded in one place rather than in two that could disagree.
Each bridge is one logical device and names itself to the library by a handle it is given at construction, which every entry point takes first. Handles come from one counter shared by every worker in the process and are never reused, so a handle names one logical device anywhere, and a stale one names nothing. The library keys each logical device's identifiers, mappings, recording and completed serial by that handle. The editor registers its application thread as GPU owner; all logical devices dispatch raw browser primitives to that thread and share its device/queue. Standalone modules without a registered owner execute on the caller. C++ handle tables and mapped byte storage stay on the creating caller; GPU objects never cross worker boundaries.
beginDeviceRequest compares ProtocolCodeTable against the table the library holds before asking for a device, so the two halves agree on what their numbers mean before anything is built on them. See BrowserWireCodes.h for what that check covers and what it does not.
Sizes and offsets cross as doubles rather than 64-bit integers. Every value that crosses is bounded far below the 2^53 a double represents exactly - the runtime caps buffers at 1 GiB and textures at 16384 texels a side - and a double is the one numeric type both sides agree on without a 64-bit calling-convention dependency.
WebAssembly only: it exists to call a browser.
|
overridevirtual |
Gives back the acquired texture without showing it.
| surfaceId | Surface holding it. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Takes the surface's texture for this frame and registers it under textureId.
| surfaceId | Surface to acquire from. |
| textureId | Identifier for the frame texture. |
| status | Receives what the surface reported. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Opens recording for the command buffer at commandBufferIndex of the submission with submissionSerial. Index zero starts the submission and discards whatever an earlier attempt finished without submitting, so a refused command can never end up submitted as part of a later frame; a later index must find exactly that many finished buffers under the same serial, which is how the two halves agree on what is being recorded.
| submissionSerial | Serial the runtime assigned. |
| commandBufferIndex | Position of this buffer within the submission. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Begins a compute pass.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Asks for this logical device's browser GPU device. The first logical device in a worker to ask begins the browser's request, which settles asynchronously; every later one joins the device that request obtains.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Begins a render pass.
| colorAttachments | Attachments of the pass. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Serial of this logical device's most recent submission the browser has reported finished (0 if none). Each logical device numbers its submissions on its own.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Configures how a surface presents.
| surfaceId | Surface to configure. |
| formatCode | Encoded TextureFormat. |
| usageBits | Encoded TextureUsage mask. |
| width | Width in texels. |
| height | Height in texels. |
| alphaModeCode | Encoded SurfaceAlphaMode. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Copies texels into a buffer.
| textureId | Source texture. |
| bufferId | Destination buffer. |
| layout | Destination row layout. |
| region | Copied rectangle. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Copies texels between textures.
| sourceTextureId | Source. |
| destinationTextureId | Destination. |
| region | Copied rectangle with both origins. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a bind group.
| id | Identifier to register it under. |
| layoutId | Layout the entries match. |
| entries | Bound resources. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a bind group layout.
| id | Identifier to register it under. |
| entries | Layout entries. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a buffer.
| id | Identifier to register it under. |
| byteSize | Size in bytes. |
| usageBits | Encoded BufferUsage mask. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a compute pipeline.
| id | Identifier to register it under. |
| request | Pipeline description. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a pipeline layout.
| id | Identifier to register it under. |
| groupLayoutIds | Bind group layouts, by group index. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a render pipeline.
| id | Identifier to register it under. |
| request | Pipeline description. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a sampler.
| id | Identifier to register it under. |
| magFilterCode | Encoded magnification FilterMode. |
| minFilterCode | Encoded minification FilterMode. |
| addressUCode | Encoded U AddressMode. |
| addressVCode | Encoded V AddressMode. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a shader module from trusted build output.
| id | Identifier to register it under. |
| wgsl | Shader source text. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a surface over the canvas named by canvasSelector.
| id | Identifier to register it under. |
| canvasSelector | CSS selector naming the canvas. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a texture.
| id | Identifier to register it under. |
| width | Width in texels. |
| height | Height in texels. |
| formatCode | Encoded TextureFormat. |
| usageBits | Encoded TextureUsage mask. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Creates a view covering the whole texture.
| id | Identifier to register it under. |
| textureId | Texture to view. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Releases a browser object and unregisters its identifier, which is never reissued. A texture a share still holds is not destroyed until the share is released.
| kind | Kind the identifier must name. |
| id | Identifier to release. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
What the browser said when it reported the device lost. Empty while the device is alive.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Why the request failed, when deviceRequestState reports a failure. Empty otherwise.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
How far the request begun by beginDeviceRequest has progressed.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Checks current ownership and loss together. Returns Success for an owned, live device, NotOwner for a missing device or foreign context, or DeviceLost for an owned, lost device. Other statuses indicate a failed query. Implementations must not cache this state.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Dispatches compute workgroups.
| countX | Workgroups along X. |
| countY | Workgroups along Y. |
| countZ | Workgroups along Z. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Draws non-indexed geometry.
| vertexCount | Vertices. |
| instanceCount | Instances. |
| firstVertex | First vertex. |
| firstInstance | First instance. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Draws indexed geometry.
| indexCount | Indices. |
| instanceCount | Instances. |
| firstIndex | First index. |
| baseVertex | Value added to every index. |
| firstInstance | First instance. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Finishes the open command buffer and holds it for the submission, without reaching the queue: a submission of several buffers reaches the queue once, in submitCommandBuffers.
| submissionSerial | Serial the runtime assigned. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Ends the open compute pass.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Ends the open render pass.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Whether the browser has reported the device lost. Once true it never becomes false again.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Begins mapping a buffer range for host reads.
| mappingId | Identifier to register the mapping under. |
| bufferId | Buffer to map. |
| offsetBytes | Byte offset of the range. |
| byteCount | Length of the range. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Bytes of a completed mapping, valid until the mapping is released. Returns an empty span with a non-success status when the mapping is not readable.
| mappingId | Mapping to read. |
| bytes | Receives the mapped bytes on success. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
State of a mapping the browser has been asked for.
| mappingId | Mapping to query. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Largest width or height of a 2D texture the browser device supports, as its limits report it, or 0 when this logical device holds no device or the browser reports no such limit.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Finishes the acquired canvas frame for implicit browser presentation.
| surfaceId | Surface holding the frame. |
| status | Receives the presentation outcome. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Registers the texture shared names under id, as a read-only alias in this logical device.
Destroying the alias releases nothing but the identifier.
| id | Identifier to register the alias under. |
| shared | Share another logical device over the same browser device made. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Submits an empty command list while this mapping remains pending, without submitting recorded commands or changing logical submission serials.
| mappingId | Mapping to advance. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Binds a group in the open pass.
| index | Group index. |
| bindGroupId | Bind group. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Sets the compute pipeline of the open compute pass.
| pipelineId | Compute pipeline. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Binds an index buffer.
| bufferId | Buffer. |
| indexFormatCode | Encoded IndexFormat. |
| offsetBytes | Byte offset of the first index. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Sets the render pipeline of the open render pass.
| pipelineId | Render pipeline. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Sets the scissor rectangle.
| x | Left edge. |
| y | Top edge. |
| width | Width. |
| height | Height. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Binds a vertex buffer.
| slot | Vertex buffer slot. |
| bufferId | Buffer. |
| offsetBytes | Byte offset of the first element. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Sets the viewport.
| x | Left edge. |
| y | Top edge. |
| width | Width. |
| height | Height. |
| minDepth | Minimum depth. |
| maxDepth | Maximum depth. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Identity of the browser device this logical device runs on: the same for every bridge over that device and different for every other, including a device obtained after this one was released.
Null until the request is Ready.
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Holds the texture textureId for the other logical devices over the same browser device.
| textureId | Texture of this logical device; refused if it is a registration or is already shared. |
| shared | Receives the share on success. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Submits every command buffer finished under submissionSerial as one queue submission, in the order they were recorded, and arranges for the reported completed serial to reach submissionSerial once that submission finishes.
| submissionSerial | Serial the runtime assigned. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Reports what a surface supports.
| surfaceId | Surface to query. |
| capabilities | Receives the capabilities on success. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Releases a mapping and unregisters its identifier.
| mappingId | Mapping to release. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Writes bytes into a buffer.
| bufferId | Destination buffer. |
| offsetBytes | Destination byte offset. |
| data | Payload. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Writes texel rows into a texture.
| textureId | Destination texture. |
| data | Payload. |
| layout | Row layout of data. |
| region | Destination rectangle; its source coordinates are unused. |
Implements donner::gpu::browser::BrowserBridge.
|
overridevirtual |
Gives the browser up to seconds of this thread to make progress.
A browser settles a mapping on its own event loop, so a caller that waits by blocking prevents the very progress it is waiting for: the promise that would mark the mapping ready cannot run until this thread yields. Resting between slices is not enough, because resting is still not yielding. This is the call that hands the loop back.
How a shipped build yields is not settled. The implementation unwinds the stack, which needs that support enabled at link time and costs module size and speed; the WebAssembly binaries enable it today, but they do so for the transitional WebGPU path this bridge is meant to replace, so its presence is not something this bridge can assume it keeps. The alternatives are stack switching, which is not available on every browser in the support matrix, and making readback asynchronous up the calling stack so nothing ever waits here. That choice belongs to the production cutover and touches renderer code outside this package; until it is made, treat a blocking wait through this call as workable rather than as the shipped design.
| seconds | Longest this call may yield for. |
Implements donner::gpu::browser::BrowserBridge.