The browser's GPU service, as the runtime uses it. More...
#include "donner/gpu/browser/BrowserBridge.h"
Public Member Functions | |
| 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 |
| virtual BridgeStatus | beginDeviceRequest ()=0 |
| 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. | |
| virtual BrowserDeviceRequestState | deviceRequestState () const =0 |
| How far the request begun by beginDeviceRequest has progressed. | |
| virtual RcString | deviceRequestError () const =0 |
| Why the request failed, when deviceRequestState reports a failure. Empty otherwise. | |
| virtual BridgeStatus | deviceStatus () const =0 |
| 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. | |
| virtual bool | isDeviceLost () const =0 |
| Whether the browser has reported the device lost. Once true it never becomes false again. | |
| virtual RcString | deviceLostReason () const =0 |
| What the browser said when it reported the device lost. Empty while the device is alive. | |
| virtual uint64_t | completedSerial () const =0 |
| 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. | |
| virtual uint32_t | maxTextureDimension2D () const =0 |
| 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. | |
| virtual const void * | sharedDeviceIdentity () const =0 |
| 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. | |
| virtual BridgeStatus | shareTexture (BrowserObjectId textureId, std::shared_ptr< const BrowserSharedTexture > &shared)=0 |
Holds the texture textureId for the other logical devices over the same browser device. | |
| virtual BridgeStatus | registerSharedTexture (BrowserObjectId id, const BrowserSharedTexture &shared)=0 |
Registers the texture shared names under id, as a read-only alias in this logical device. | |
| virtual BridgeStatus | createBuffer (BrowserObjectId id, uint64_t byteSize, uint32_t usageBits)=0 |
| Creates a buffer. | |
| virtual BridgeStatus | createTexture (BrowserObjectId id, uint32_t width, uint32_t height, uint32_t formatCode, uint32_t usageBits)=0 |
| Creates a texture. | |
| virtual BridgeStatus | createTextureView (BrowserObjectId id, BrowserObjectId textureId)=0 |
| Creates a view covering the whole texture. | |
| virtual BridgeStatus | createSampler (BrowserObjectId id, uint32_t magFilterCode, uint32_t minFilterCode, uint32_t addressUCode, uint32_t addressVCode)=0 |
| Creates a sampler. | |
| virtual BridgeStatus | createBindGroupLayout (BrowserObjectId id, std::span< const BrowserBindGroupLayoutEntry > entries)=0 |
| Creates a bind group layout. | |
| virtual BridgeStatus | createBindGroup (BrowserObjectId id, BrowserObjectId layoutId, std::span< const BrowserBindGroupEntry > entries)=0 |
| Creates a bind group. | |
| virtual BridgeStatus | createPipelineLayout (BrowserObjectId id, std::span< const BrowserObjectId > groupLayoutIds)=0 |
| Creates a pipeline layout. | |
| virtual BridgeStatus | createShaderModule (BrowserObjectId id, std::string_view wgsl)=0 |
| Creates a shader module from trusted build output. | |
| virtual BridgeStatus | createRenderPipeline (BrowserObjectId id, const BrowserRenderPipelineRequest &request)=0 |
| Creates a render pipeline. | |
| virtual BridgeStatus | createComputePipeline (BrowserObjectId id, const BrowserComputePipelineRequest &request)=0 |
| Creates a compute pipeline. | |
| virtual BridgeStatus | destroyObject (BrowserObjectKind kind, BrowserObjectId id)=0 |
| 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. | |
| virtual BridgeStatus | writeBuffer (BrowserObjectId bufferId, uint64_t offsetBytes, std::span< const uint8_t > data)=0 |
| Writes bytes into a buffer. | |
| virtual BridgeStatus | writeTexture (BrowserObjectId textureId, std::span< const uint8_t > data, const BrowserTexelLayout &layout, const BrowserCopyRegion ®ion)=0 |
| Writes texel rows into a texture. | |
| virtual BridgeStatus | beginCommandBuffer (uint64_t submissionSerial, uint32_t commandBufferIndex)=0 |
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. | |
| virtual BridgeStatus | beginRenderPass (std::span< const BrowserColorAttachment > colorAttachments)=0 |
| Begins a render pass. | |
| virtual BridgeStatus | endRenderPass ()=0 |
| Ends the open render pass. | |
| virtual BridgeStatus | beginComputePass ()=0 |
| Begins a compute pass. | |
| virtual BridgeStatus | endComputePass ()=0 |
| Ends the open compute pass. | |
| virtual BridgeStatus | setRenderPipeline (BrowserObjectId pipelineId)=0 |
| Sets the render pipeline of the open render pass. | |
| virtual BridgeStatus | setComputePipeline (BrowserObjectId pipelineId)=0 |
| Sets the compute pipeline of the open compute pass. | |
| virtual BridgeStatus | setBindGroup (uint32_t index, BrowserObjectId bindGroupId)=0 |
| Binds a group in the open pass. | |
| virtual BridgeStatus | setVertexBuffer (uint32_t slot, BrowserObjectId bufferId, uint64_t offsetBytes)=0 |
| Binds a vertex buffer. | |
| virtual BridgeStatus | setIndexBuffer (BrowserObjectId bufferId, uint32_t indexFormatCode, uint64_t offsetBytes)=0 |
| Binds an index buffer. | |
| virtual BridgeStatus | setScissorRect (uint32_t x, uint32_t y, uint32_t width, uint32_t height)=0 |
| Sets the scissor rectangle. | |
| virtual BridgeStatus | setViewport (float x, float y, float width, float height, float minDepth, float maxDepth)=0 |
| Sets the viewport. | |
| virtual BridgeStatus | draw (uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)=0 |
| Draws non-indexed geometry. | |
| virtual BridgeStatus | drawIndexed (uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance)=0 |
| Draws indexed geometry. | |
| virtual BridgeStatus | dispatchWorkgroups (uint32_t countX, uint32_t countY, uint32_t countZ)=0 |
| Dispatches compute workgroups. | |
| virtual BridgeStatus | copyTextureToBuffer (BrowserObjectId textureId, BrowserObjectId bufferId, const BrowserTexelLayout &layout, const BrowserCopyRegion ®ion)=0 |
| Copies texels into a buffer. | |
| virtual BridgeStatus | copyTextureToTexture (BrowserObjectId sourceTextureId, BrowserObjectId destinationTextureId, const BrowserCopyRegion ®ion)=0 |
| Copies texels between textures. | |
| virtual BridgeStatus | endCommandBuffer (uint64_t submissionSerial)=0 |
| 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. | |
| virtual BridgeStatus | submitCommandBuffers (uint64_t submissionSerial)=0 |
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. | |
| virtual BridgeStatus | mapBufferAsync (BrowserObjectId mappingId, BrowserObjectId bufferId, uint64_t offsetBytes, uint64_t byteCount)=0 |
| Begins mapping a buffer range for host reads. | |
| virtual MapSliceState | mappingState (BrowserObjectId mappingId) const =0 |
| State of a mapping the browser has been asked for. | |
| virtual BridgeStatus | requestMappingProgress (BrowserObjectId mappingId)=0 |
| Submits an empty command list while this mapping remains pending, without submitting recorded commands or changing logical submission serials. | |
| virtual void | yieldToBrowser (double seconds)=0 |
Gives the browser up to seconds of this thread to make progress. | |
| virtual BridgeStatus | mappedBytes (BrowserObjectId mappingId, std::span< const uint8_t > &bytes) const =0 |
| 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. | |
| virtual BridgeStatus | unmapBuffer (BrowserObjectId mappingId)=0 |
| Releases a mapping and unregisters its identifier. | |
| virtual BridgeStatus | createSurface (BrowserObjectId id, std::string_view canvasSelector)=0 |
Creates a surface over the canvas named by canvasSelector. | |
| virtual BridgeStatus | surfaceCapabilities (BrowserObjectId surfaceId, BrowserSurfaceCapabilities &capabilities) const =0 |
| Reports what a surface supports. | |
| virtual BridgeStatus | configureSurface (BrowserObjectId surfaceId, uint32_t formatCode, uint32_t usageBits, uint32_t width, uint32_t height, uint32_t alphaModeCode)=0 |
| Configures how a surface presents. | |
| virtual BridgeStatus | acquireCurrentTexture (BrowserObjectId surfaceId, BrowserObjectId textureId, SurfaceStatus &status)=0 |
Takes the surface's texture for this frame and registers it under textureId. | |
| virtual BridgeStatus | presentSurface (BrowserObjectId surfaceId, SurfaceStatus &status)=0 |
| Finishes the acquired canvas frame for implicit browser presentation. | |
| virtual BridgeStatus | abandonCurrentTexture (BrowserObjectId surfaceId)=0 |
| Gives back the acquired texture without showing it. | |
Protected Member Functions | |
| BrowserBridge () | |
| Constructor for implementations. | |
The browser's GPU service, as the runtime uses it.
One instance stands for one logical device: the state one runtime device keeps on the browser side, which is its identifiers, its host mappings, its recording and the serial of its last finished submission. Several logical devices in one worker share that worker's one browser device and its queue, the way a renderer and the snapshot capture context beside it do, and none of them may refuse, overwrite or release another's state. Implementations perform no validation of their own beyond the identifier, kind and ownership checks each call documents: everything else arrives already validated by donner::gpu::Device.
|
pure virtual |
Gives back the acquired texture without showing it.
| surfaceId | Surface holding it. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Begins a compute pass.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Begins a render pass.
| colorAttachments | Attachments of the pass. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Copies texels into a buffer.
| textureId | Source texture. |
| bufferId | Destination buffer. |
| layout | Destination row layout. |
| region | Copied rectangle. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Copies texels between textures.
| sourceTextureId | Source. |
| destinationTextureId | Destination. |
| region | Copied rectangle with both origins. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a bind group.
| id | Identifier to register it under. |
| layoutId | Layout the entries match. |
| entries | Bound resources. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a bind group layout.
| id | Identifier to register it under. |
| entries | Layout entries. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a buffer.
| id | Identifier to register it under. |
| byteSize | Size in bytes. |
| usageBits | Encoded BufferUsage mask. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a compute pipeline.
| id | Identifier to register it under. |
| request | Pipeline description. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a pipeline layout.
| id | Identifier to register it under. |
| groupLayoutIds | Bind group layouts, by group index. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a render pipeline.
| id | Identifier to register it under. |
| request | Pipeline description. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a shader module from trusted build output.
| id | Identifier to register it under. |
| wgsl | Shader source text. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a surface over the canvas named by canvasSelector.
| id | Identifier to register it under. |
| canvasSelector | CSS selector naming the canvas. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a texture.
| id | Identifier to register it under. |
| width | Width in texels. |
| height | Height in texels. |
| formatCode | Encoded TextureFormat. |
| usageBits | Encoded TextureUsage mask. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Creates a view covering the whole texture.
| id | Identifier to register it under. |
| textureId | Texture to view. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
What the browser said when it reported the device lost. Empty while the device is alive.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Why the request failed, when deviceRequestState reports a failure. Empty otherwise.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
How far the request begun by beginDeviceRequest has progressed.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Dispatches compute workgroups.
| countX | Workgroups along X. |
| countY | Workgroups along Y. |
| countZ | Workgroups along Z. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Draws non-indexed geometry.
| vertexCount | Vertices. |
| instanceCount | Instances. |
| firstVertex | First vertex. |
| firstInstance | First instance. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Draws indexed geometry.
| indexCount | Indices. |
| instanceCount | Instances. |
| firstIndex | First index. |
| baseVertex | Value added to every index. |
| firstInstance | First instance. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Ends the open compute pass.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Ends the open render pass.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Whether the browser has reported the device lost. Once true it never becomes false again.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
State of a mapping the browser has been asked for.
| mappingId | Mapping to query. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Finishes the acquired canvas frame for implicit browser presentation.
| surfaceId | Surface holding the frame. |
| status | Receives the presentation outcome. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Submits an empty command list while this mapping remains pending, without submitting recorded commands or changing logical submission serials.
| mappingId | Mapping to advance. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Binds a group in the open pass.
| index | Group index. |
| bindGroupId | Bind group. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Sets the compute pipeline of the open compute pass.
| pipelineId | Compute pipeline. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Binds an index buffer.
| bufferId | Buffer. |
| indexFormatCode | Encoded IndexFormat. |
| offsetBytes | Byte offset of the first index. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Sets the render pipeline of the open render pass.
| pipelineId | Render pipeline. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Sets the scissor rectangle.
| x | Left edge. |
| y | Top edge. |
| width | Width. |
| height | Height. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Binds a vertex buffer.
| slot | Vertex buffer slot. |
| bufferId | Buffer. |
| offsetBytes | Byte offset of the first element. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Sets the viewport.
| x | Left edge. |
| y | Top edge. |
| width | Width. |
| height | Height. |
| minDepth | Minimum depth. |
| maxDepth | Maximum depth. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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.
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Reports what a surface supports.
| surfaceId | Surface to query. |
| capabilities | Receives the capabilities on success. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Releases a mapping and unregisters its identifier.
| mappingId | Mapping to release. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Writes bytes into a buffer.
| bufferId | Destination buffer. |
| offsetBytes | Destination byte offset. |
| data | Payload. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
Writes texel rows into a texture.
| textureId | Destination texture. |
| data | Payload. |
| layout | Row layout of data. |
| region | Destination rectangle; its source coordinates are unused. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.
|
pure virtual |
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. |
Implemented in donner::gpu::browser::EmscriptenBrowserBridge.