Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::WebGPUDevice Class Referencefinal
module nullptr

#include <WebGPUDevice.hpp>

Inheritance diagram for esengine::WebGPUDevice:

Classes

struct  NativeSurface

Public Types

enum  DsVariant : u32 { kDsNone = 0 , kDsDepthOnly = 1 , kDsDepthStencil = 2 , kDsVariantCount = 3 }
 Depth-stencil attachment shape of a pass — one WGPURenderPipeline per shape, since WebGPU validates a pipeline's depthStencil state against the pass it draws into (GL has no such coupling). More...
enum  ColorVariant : u32 {
  kColorRgba8 = 0 , kColorBgra8 = 1 , kColorSrgb8 = 2 , kColorRgba16f = 3 ,
  kColorRgba32f = 4 , kColorVariantCount = 5
}
 Color attachment format of a pass — like DsVariant, WebGPU validates the pipeline's color target format against the pass, and BGRA is a DIFFERENT format from RGBA to that check even though both are 8-bit unorm: a surface is usually the former, a render target the latter, so they cannot share a slot. More...
enum  SampleVariant : u32 { kSingleSample = 0 , kMultiSample = 1 , kSampleVariantCount = 2 }
 Sample count of a pass — a third thing WebGPU validates a pipeline against, and the reason a multisampled scene needs its own variant of every pipeline that draws into it. One or kMsaaSamples. More...
enum class  NativeWindowKind {
  MetalLayer , AndroidWindow , Win32Hwnd , WaylandSurface ,
  XlibWindow
}
 Binds a canvas as the default render target (bring-up entry, not part of the GfxDevice interface). selector is a CSS selector the emscripten surface source resolves, e.g. "#canvas". The web build's surface source; a native Dawn build reaches the surface through the NativeSurface overload instead. More...

Public Member Functions

u64 estimatedGpuBytes () const override
 WebGPUDevice (WGPUDevice device=nullptr, WGPUInstance instance=nullptr, WGPUAdapter adapter=nullptr)
 device may be null for bookkeeping-only use (tests, bring-up).
 ~WebGPUDevice () override
ClipDepthRange clipDepthRange () const override
 The clip volume this device keeps along z.
void init () override
 Initializes the graphics device.
void shutdown () override
 Shuts down the graphics device.
void reportUncapturedError (u32 wgpuErrorType, const char *message)
 Routes the device's uncaptured-error callback; only fatal kinds become losses.
bool pollDeviceLost () override
 Pumps backend-native loss detection.
void ownDeviceReference ()
 The web host transfers the reference it imported from JavaScript.
bool provideReplacementDevice (void *nativeDevice) override
 Hands a replacement in for the next recovery attempt to take up.
void setViewport (i32 x, i32 y, u32 w, u32 h) override
 Sets the rendering viewport.
void clearStencil (i32 value) override
 Mid-pass stencil reset (the one clear that isn't a pass load-op).
void setScissorTest (bool enabled) override
 Enables or disables scissor test.
void setScissor (i32 x, i32 y, i32 w, i32 h) override
 Sets the scissor rectangle.
void setVertexBuffer (u32 slot, BufferHandle buffer, u32 offsetBytes) override
 Binds a vertex buffer to a layout slot for subsequent draws.
void setIndexBuffer (BufferHandle buffer) override
 Binds the index buffer for subsequent indexed draws.
void bindTexture (u32 slot, TextureHandle texture) override
 Activates a texture slot and binds a 2D texture.
bool supportsCompressedFormat (GfxCompressedFormat format) override
 Reports whether the backend can sample the given compressed format.
bool supportsFloatTargets () override
 Whether RGBA16F color attachments are renderable.
bool supportsUnblendedSurfaceTarget () const override
u32 maxSamples () override
 Most samples an offscreen colour attachment may carry; 1 = none.
bool resolvesDepth () const override
void setSurfaceSamples (u32 samples) override
 How many samples a SURFACE pass draws with — a frame with no post chain draws straight to the backbuffer.
bool supportsCompute () const override
 WebGPU is the backend with a compute stage; a device-less instance (bookkeeping only) has none to offer.
ReadbackHandle requestBufferReadback (BufferHandle buffer, u32 offsetBytes, u32 sizeBytes) override
 Copies bytes of a storage buffer out, to be taken with pollReadback / takeReadback.
ReadbackHandle requestTextureReadback (TextureHandle texture) override
 Copies a storage texture's pixels out, tightly packed in the texture's own format (rows top-down).
bool supportsShaderLanguage (GfxShaderLanguage language) const override
 Whether this backend compiles language (GL: GLSL ES 300; WebGPU: WGSL).
void setStencilReference (i32 reference) override
 WebGPU stores a texture from the top down.
void drawElements (u32 indexCount, GfxDataType indexType, u32 indexByteOffset) override
 Draws indexed triangles.
void drawArrays (u32 firstVertex, u32 vertexCount) override
 Draws non-indexed triangles.
void drawElementsInstanced (u32 indexCount, GfxDataType indexType, u32 indexByteOffset, u32 instanceCount) override
 Draws indexed triangles with instancing.
void beginRenderPass (const RenderPassDesc &desc) override
 Targets a framebuffer for subsequent draws and applies the pass's clears.
void endRenderPass () override
 Ends the current pass, restoring the default framebuffer.
void resizeBackbuffer (u32 width, u32 height) override
 Resizes the default backbuffer to the viewport size.
ReadbackHandle requestReadback (FramebufferHandle target, u32 w, u32 h) override
 Requests an RGBA8 readback of a framebuffer's color attachment.
GfxReadbackStatus pollReadback (ReadbackHandle handle) override
 The state of an in-flight readback; pumps backend completion events. A Failed readback is released by the poll that reported it.
bool takeReadback (ReadbackHandle handle, void *dest, usize destSize) override
 Copies a Ready readback's pixels (w*h*4 bytes) into dest and releases it.
void discardReadback (ReadbackHandle handle) override
 Abandons a readback (any state); its resources are released.
void beginTimerQuery (u32 query) override
 Starts timing GPU work into a query; one query may be active at a time.
void endTimerQuery () override
 Stops the active timer query.
bool timerDisjoint () override
 True when GPU timing was disturbed since the last check.
bool getTimerQueryNs (u32 query, u64 *outNs) override
 Fetches a completed query's elapsed nanoseconds; false while still pending.
void setWireframe (bool enabled) override
 Enables or disables wireframe rendering (desktop only).
u32 getError () override
 Queries the last error.
std::string getString (GfxStringName name) override
 Queries a backend identification string (diagnostics).
i32 getInt (GfxIntParam param) override
 Queries a backend integer capability/limit.
bool hasDevice () const
bool configureSurface (const NativeSurface &window, u32 width, u32 height)
 Binds a native window as the render target; shares configureSwapchain with the web path. Native Dawn build only.
void present ()
 Flips the swapchain to the display. The web path relies on the browser presenting the canvas after the frame callback; a native host must present the surface explicitly, once per frame after endRenderPass. No-op until a surface is configured.
bool surfaceBytesAreBGRA () const
 Whether bytes read back from the DEFAULT framebuffer are BGRA rather than RGBA.
bool frameCaptureIsBGRA () const override
 Whether a captured frame's bytes are BGRA rather than RGBA — the surface's choice on a backend that has one, and never GL's.
void setPreferredSurfaceBGRA (bool bgra)
 The surface format the host says its canvas prefers.
void setSurfaceReadback (bool enabled)
 Configure the swapchain with CopySrc, so captureNextFrame can read it. Must be set BEFORE the surface is configured.
void setLateSurfaceAcquire (bool enabled)
 Worker passes can span browser tasks. Acquire their expiring canvas texture at present.
void setPresentUncapped (bool enabled)
 Present as fast as the surface allows instead of waiting for the display. Set BEFORE the surface is configured; off by default.
ReadbackHandle captureNextFrame (u32 w, u32 h) override
 Copy the next completed frame's swapchain image into a readback.
void endFrame () override
 The frame is over — everything drawn for it has been submitted.
bool framePending () override
Public Member Functions inherited from esengine::GfxDevice
virtual ~GfxDevice ()=default
GfxDeviceStatus deviceStatus () const
 Whether the device can be drawn to (see GfxDeviceStatus).
bool isDeviceLive () const
 Strictly Live: recovered but still-refilling counts as false.
bool isDeviceUsable () const
 Whether work may be submitted — the one check the guards make.
u64 deviceGeneration () const
 Which generation of the device the live GPU objects belong to.
u64 geometryWrites () const
 How many times a static vertex or index buffer has been written or resized since the device was made.
const GfxDeviceLostInfo * deviceLostInfo () const
 The loss report, or null while the device is Live.
const GfxDeviceIdentity & deviceIdentity () const
 Who this device is — available WHILE it is alive, unlike the loss report.
void notifyDeviceLost (GfxDeviceLostReason reason, std::string message={}, std::string context={})
 Declares the device lost from outside the backend.
bool recoverDevice ()
 Rebuilds the device and every object it issued, behind the same handles.
std::vector< GfxOwedContent > owedContent () const
 Sourced objects that have storage again and are waiting for their contents.
void forgoContent (const GfxOwedContent &owed)
 Gives up on one owed object's contents: it keeps its placeholder.
void restoreContent (const GfxOwedContent &owed)
 Settles one owed object whose provider wrote its contents itself.
usize retainedBytes () const
 CPU bytes the device holds to put content back after a loss.
u32 takeDraws ()
 Every draw the GPU was asked for since the last call, and the tally started again.
void setRetainedBudget (usize bytes)
 Warns once when retainedBytes() grows past bytes; 0 never warns.
void markDeviceDead ()
 Gives up on the device: no further recovery will be attempted.
bool beginDeviceFrame ()
 Opens a frame: polls for loss, and numbers the frame a report is stamped with.
void setDeviceLostHandler (std::function< void(const GfxDeviceLostInfo &)> handler)
 Called once per loss, with the completed report.
const Viewport & viewport () const
BufferHandle createBuffer (const BufferDesc &desc, GfxContent content, const void *initialData)
 Creates a buffer with fixed capacity and optional initial contents.
void deleteBuffer (BufferHandle buffer)
 Deletes a buffer.
void updateBuffer (BufferHandle buffer, u32 offsetBytes, const void *data, u32 sizeBytes)
 Updates a sub-range of a buffer; must fit within its capacity.
void resizeBuffer (BufferHandle buffer, u32 sizeBytes, const void *data)
 Re-specifies a buffer's store with a new capacity, discarding prior contents.
const BufferDesc * bufferDesc (BufferHandle buffer) const
 A buffer's description as it stands, or null for a handle that names none.
void setUniformBuffer (u32 slot, BufferHandle buffer, u32 offsetBytes=0, u32 sizeBytes=0)
 Binds a buffer to a uniform binding slot (the block index shaders are linked to).
VertexLayoutHandle createVertexLayout (const VertexLayoutDesc &desc)
 Registers an immutable vertex layout; pipelines reference it by handle.
void deleteVertexLayout (VertexLayoutHandle layout)
 Deletes a vertex layout (no pipeline may reference it afterwards).
const VertexLayoutDesc * vertexLayoutDesc (VertexLayoutHandle layout) const
 A layout's description, or null for a handle that names none.
TextureHandle createTexture (const TextureDesc &desc, GfxContent content, const void *pixels)
 Creates a 2D texture; uploads pixels (tightly packed, desc-sized) when non-null.
TextureHandle createCompressedTexture (const TextureDesc &desc, GfxContent content, GfxCompressedFormat format, const void *data, u32 byteLength, u32 mipLevels)
 Creates a texture from pre-compressed GPU block data.
bool restoreCompressedTexture (TextureHandle texture, GfxCompressedFormat format, const void *data, u32 byteLength, u32 mipLevels)
 Puts compressed contents back behind an owed texture's handle.
TextureHandle importExternalTexture (u32 nativeId, const TextureDesc &desc, GfxContent content)
 Adopts a texture a host created with the device's own API (a JS-side WebGL upload).
bool restoreTextureFromNative (TextureHandle texture, u32 nativeId)
 Replaces the native texture behind texture with one the host created again.
bool adoptTextureContent (TextureHandle into, TextureHandle from)
 Moves from's storage and description behind into, and ends from.
void deleteTexture (TextureHandle texture)
 Deletes a texture.
void updateTexture (TextureHandle texture, i32 x, i32 y, u32 width, u32 height, const void *pixels, bool flipY)
 Uploads pixels to a sub-rectangle of a texture (transfer format from its desc).
void setTextureParams (TextureHandle texture, TextureFilter min, TextureFilter mag, TextureWrap wrapS, TextureWrap wrapT)
 Sets texture filtering and wrap parameters.
void generateMipmaps (TextureHandle texture)
 Generates mipmaps for a texture.
u64 textureRevision (TextureHandle texture) const
 A texture's description as it stands, or null for a handle that names none.
u64 trackedTextureRevision (TextureHandle texture) const
 Zero for content that can change without an upload, including render targets and host textures.
u64 textureShapes () const
 Counts every texture made, deleted, or given new storage under its handle (a restore, an adopt): what changes the size a handle answers, never what its pixels hold.
const TextureDesc * textureDesc (TextureHandle texture) const
ShaderHandle createProgram (const GfxShaderSource &source, const GfxAttribBinding *bindings, u32 bindingCount, std::string *outLog, GfxShaderStage *outFailedStage)
 Compiles and links a GPU program from GLSL sources.
virtual bool supportsDeferredLink () const
 Whether createProgram honours GfxShaderSource::deferLink (GL: yes; a backend that links at once does not).
void onProgramLinked (ShaderHandle program, std::function< void()> callback)
 Runs callback when program has linked, once: now if it already has, at the first thing that needs it otherwise.
bool finishProgram (ShaderHandle program)
 Waits for program to link if it has not yet. False when it failed to.
bool programReady (ShaderHandle program)
 Whether program can be drawn with now, without waiting: linked, or finished linking in the background (and then finished here, which is quick). False while it is still compiling, and for one that failed. Always true for a program that was not deferred.
u32 pendingProgramCount ()
 How many programs made with deferLink are still compiling.
std::string pendingProgramLabels ()
 What each program still compiling in the background is, one line each: what a "compiling shaders" readout names.
void setSkipPendingPrograms (bool on)
 Whether a draw whose program is not ready is left out, instead of waited for.
bool skipPendingPrograms () const
void deleteProgram (ShaderHandle program)
 Deletes a shader program.
virtual bool supportsAsyncCompute () const
 Hardware with an independent queue. Individual bindings can still require the graphics queue.
void setAsyncComputeEnabled (bool enabled)
bool asyncComputeEnabled () const
bool beginAsyncComputeJob (AsyncComputePriority priority=AsyncComputePriority::Default)
 Opens a compute-only scope, including on single-queue devices. Scopes cannot nest.
AsyncComputeFence endAsyncComputeJob ()
 A fence for submitted work, or -1 when it is already ordered on the graphics queue.
void graphicsWaitOnAsyncComputeJob (AsyncComputeFence fence)
void manualComputeBarrier ()
 Order dispatches across queues. Each inline dispatch is already a complete compute pass.
ComputeHandle createCompute (const GfxComputeSource &source, std::string *outLog=nullptr)
 Compiles a compute program.
void deleteCompute (ComputeHandle program)
 Deletes a compute program.
bool dispatchCompute (ComputeHandle program, const GfxComputeBinding *bindings, u32 bindingCount, u32 groupsX, u32 groupsY=1, u32 groupsZ=1)
 Runs program over groupsX x groupsY x groupsZ workgroups, with these resources bound.
void useProgram (ShaderHandle program)
 Binds a program directly, for setup-time uniform seeding.
i32 getUniformLocation (ShaderHandle program, const char *name)
 Gets a uniform location by name, -1 when the linked program has none.
i32 getAttribLocation (ShaderHandle program, const char *name)
 Gets a vertex attribute location by name (-1 if not found).
u32 boundSamplerUnits ()
 The texture units the bound program samples, one bit a unit; every unit where the backend cannot say.
void setUniform1i (i32 location, i32 value)
 Sets an integer uniform of the bound program.
void setUniform1f (i32 location, f32 value)
 Sets a float uniform.
void setUniform2f (i32 location, f32 x, f32 y)
 Sets a vec2 uniform.
void setUniform3f (i32 location, f32 x, f32 y, f32 z)
 Sets a vec3 uniform.
void setUniform4f (i32 location, f32 x, f32 y, f32 z, f32 w)
 Sets a vec4 uniform.
void setUniformMat3 (i32 location, const f32 *data)
 Sets a mat3 uniform.
void setUniformMat4 (i32 location, const f32 *data)
 Sets a mat4 uniform.
std::vector< GfxUniformInfo > getActiveUniforms (ShaderHandle program)
 Enumerates all active uniforms of a linked shader program.
u32 getUniformBlockIndex (ShaderHandle program, const char *name)
 Returns a program's uniform-block index by name, or GFX_INVALID_UNIFORM_BLOCK if absent.
void uniformBlockBinding (ShaderHandle program, u32 blockIndex, u32 bindingPoint)
 Links a program's uniform block to an indexed binding slot.
PipelineHandle createPipeline (const PipelineDesc &desc)
 Resolves a pipeline description to a cached handle (creating it on first use).
const PipelineDesc * pipelineDesc (PipelineHandle handle) const
 A pipeline's description, or null for a handle that names none.
void setPipeline (PipelineHandle handle)
 Binds a pipeline: applies its program, blend, depth, stencil compare/op and culling.
void invalidatePipelineCache ()
 Forces the next setPipeline to re-apply, dropping the cached current pipeline.
virtual bool supportsMultiDraw () const
 Whether drawElementsInstancedMulti is one call here, its draws told apart by gl_DrawID (WEBGL_multi_draw).
virtual void drawElementsInstancedMulti (GfxDataType indexType, const u32 *counts, const u32 *byteOffsets, const u32 *instanceCounts, u32 drawCount)
 drawCount indexed instanced draws through the bound pipeline and buffers, as one call where supportsMultiDraw().
FramebufferHandle createFramebuffer (const FramebufferDesc &desc)
 Creates a framebuffer from its attachments and validates completeness.
void deleteFramebuffer (FramebufferHandle framebuffer)
 Deletes a framebuffer (its attachment textures are owned by the caller).
const FramebufferDesc * framebufferDesc (FramebufferHandle framebuffer) const
 A framebuffer's description, or null for Default and unknown handles.
u32 createTimerQuery ()
 Creates a GPU elapsed-time query, or 0 when the backend cannot time GPU work.
GfxLiveObjects liveObjects () const
 GPU objects alive right now (see GfxLiveObjects), read off the registry.
virtual u32 nativeTextureName (TextureHandle texture) const
 The backend's own name for the object behind texture, or 0.

Static Public Member Functions

static u32 colorVariantOf (WGPUTextureFormat format)
 Which variant slot a pass's colour format uses. Beside the enum because the two are one decision: a format that shares a slot with another is a pipeline handed to a pass that rejects it.
static GfxDeviceLostReason reasonFromWgpu (u32 wgpuReason)
 Maps a WGPUDeviceLostReason to the backend-neutral reason.

Public Attributes

u32 validation_errors_logged_ = 0
 Validation errors said so far (reportUncapturedError says the first few).

Static Public Attributes

static constexpr u32 kMsaaSamples = 4
 The multisampled count this backend offers. WebGPU guarantees 1 and 4 for every renderable format; nothing else is portable.

Protected Member Functions

void captureDeviceIdentity () override
 Records who this backend is, so a later loss report can name it.
bool recreateDevice () override
 Backend half of recoverDevice: a working device again, with every id-to-native map and derived cache emptied.
bool backendCreateBuffer (u32 id, const BufferDesc &desc, const void *data) override
void backendDeleteBuffer (u32 id) override
void backendUpdateBuffer (u32 id, u32 offsetBytes, const void *data, u32 sizeBytes) override
void backendResizeBuffer (u32 id, const BufferDesc &desc, const void *data) override
void backendSetUniformBuffer (u32 slot, BufferHandle buffer, u32 offsetBytes, u32 sizeBytes) override
bool backendCreateTexture (u32 id, const TextureDesc &desc, const void *pixels) override
bool backendCreateCompressedTexture (u32 id, const TextureDesc &desc, GfxCompressedFormat format, const void *data, u32 byteLength, u32 mipLevels) override
bool backendAdoptTexture (u32, u32, const TextureDesc &) override
void backendDeleteTexture (u32 id) override
void backendMoveTexture (u32 into, u32 from) override
 Re-keys from's native texture under into; into holds none on entry.
void backendUpdateTexture (u32 id, i32 x, i32 y, u32 width, u32 height, const void *pixels, bool flipY) override
void backendSetTextureParams (u32 id, const TextureDesc &desc) override
void backendGenerateMipmaps (u32 id) override
bool backendCreateCompute (u32 id, const GfxComputeSource &source, std::string *outLog) override
void backendDeleteCompute (u32 id) override
bool backendDispatchCompute (u32 id, const GfxComputeBinding *bindings, u32 bindingCount, u32 groupsX, u32 groupsY, u32 groupsZ) override
bool backendCreateProgram (u32 id, const GfxShaderSource &source, const GfxAttribBinding *bindings, u32 bindingCount, std::string *outLog, GfxShaderStage *outFailedStage) override
void backendDeleteProgram (u32 id) override
void backendUseProgram (u32) override
i32 backendUniformLocation (u32, const char *) override
 The backend's own location this generation, -1 when absent.
i32 backendAttribLocation (u32, const char *) override
void backendSetUniform (i32, const GfxUniformValue &) override
std::vector< GfxUniformInfo > backendActiveUniforms (u32) override
u32 backendUniformBlockIndex (u32, const char *) override
void backendUniformBlockBinding (u32, u32, u32) override
bool backendAcceptsVertexLayout (const VertexLayoutDesc &desc) override
 False for a layout this backend has no way to express.
void backendDeleteVertexLayout (u32) override
 Drops what the backend derived from a layout (a GL VAO); the desc stays here.
void backendSetPipeline (u32 id, const PipelineDesc &desc) override
void backendInvalidatePipelineCache () override
bool backendCreateFramebuffer (u32 id, const FramebufferDesc &desc) override
void backendDeleteFramebuffer (u32) override
bool backendCreateTimerQuery (u32 id) override
u32 backendReadbackCount () const override
 Readbacks in flight, the one live object the registry does not hold.
Protected Member Functions inherited from esengine::GfxDevice
void countDraw ()
 A backend has issued one draw (see takeDraws).
bool computeJobOpen () const
const GfxResourceRegistry & resourceRecords () const
virtual void backendSetAsyncComputeEnabled (bool)
virtual bool backendDispatchAsyncCompute (AsyncComputePriority, u32, const GfxComputeBinding *, u32, u32, u32, u32)
virtual void backendWaitAsyncCompute ()
virtual bool backendProgramPending (u32 id) const
 True while a program created with deferLink has not been waited for.
virtual bool backendProgramReady (u32 id)
virtual u32 backendPendingProgramCount ()
virtual std::string backendPendingProgramLabels ()
virtual bool backendFinishProgram (u32 id)
 Waits for a deferred program, runs its onLinked callback; false when it failed to link. True for a program that was not deferred.
void notifyProgramLinked (u32 id)
 For a backend finishing a deferred program: runs its onLinked callback, leaving the bound program as it was.
virtual u32 backendBoundSamplerUnits ()
virtual void backendIntUniformSet (u32 program)
PipelineHandle currentPipeline () const
 The pipeline most recently bound, whose program uniforms are set on.
void setDeviceIdentity (std::string backend, std::string vendor, std::string renderer, std::string version)
 Records the backend identity; see captureDeviceIdentity.
bool markDeviceLost (GfxDeviceLostReason reason, std::string message={}, std::string context={})
 The single transition into Lost. Backends call this on detection.
virtual void onDeviceLost ()
 Release what only this backend can name, while the dead device is still the current one.

Additional Inherited Members

Protected Attributes inherited from esengine::GfxDevice
Viewport viewport_
 Backends record what they were last handed; see viewport.

Detailed Description

Definition at line 51 of file WebGPUDevice.hpp.

Member Enumeration Documentation

◆ ColorVariant

Color attachment format of a pass — like DsVariant, WebGPU validates the pipeline's color target format against the pass, and BGRA is a DIFFERENT format from RGBA to that check even though both are 8-bit unorm: a surface is usually the former, a render target the latter, so they cannot share a slot.

Enumerator
kColorRgba8 
kColorBgra8 
kColorSrgb8 
kColorRgba16f 
kColorRgba32f 
kColorVariantCount 

Definition at line 64 of file WebGPUDevice.hpp.

◆ DsVariant

Depth-stencil attachment shape of a pass — one WGPURenderPipeline per shape, since WebGPU validates a pipeline's depthStencil state against the pass it draws into (GL has no such coupling).

Enumerator
kDsNone 
kDsDepthOnly 
kDsDepthStencil 
kDsVariantCount 

Definition at line 57 of file WebGPUDevice.hpp.

◆ NativeWindowKind

Binds a canvas as the default render target (bring-up entry, not part of the GfxDevice interface). selector is a CSS selector the emscripten surface source resolves, e.g. "#canvas". The web build's surface source; a native Dawn build reaches the surface through the NativeSurface overload instead.

The kind of native window a non-emscripten host draws into. Linux is TWO kinds because a Linux desktop is two display servers, and which one a machine is running is not a build-time fact.

Enumerator
MetalLayer 
AndroidWindow 
Win32Hwnd 
WaylandSurface 
XlibWindow 

Definition at line 267 of file WebGPUDevice.hpp.

◆ SampleVariant

Sample count of a pass — a third thing WebGPU validates a pipeline against, and the reason a multisampled scene needs its own variant of every pipeline that draws into it. One or kMsaaSamples.

Enumerator
kSingleSample 
kMultiSample 
kSampleVariantCount 

Definition at line 71 of file WebGPUDevice.hpp.

Constructor & Destructor Documentation

◆ WebGPUDevice()

esengine::WebGPUDevice::WebGPUDevice ( WGPUDevice device = nullptr,
WGPUInstance instance = nullptr,
WGPUAdapter adapter = nullptr )
explicit

device may be null for bookkeeping-only use (tests, bring-up).

Parameters
instanceThe host's WGPUInstance to share. Web/emscripten passes null and the device creates its own (the emscripten singleton). A native shell that already built the instance to acquire the adapter/device passes it here so the surface is created on the SAME instance — native Dawn ties a surface to its creating instance.
adapterNative hosts pass theirs so the swapchain can ask the surface which formats it supports; omitting it assumes RGBA8.

Definition at line 63 of file WebGPUDevice.cpp.

◆ ~WebGPUDevice()

esengine::WebGPUDevice::~WebGPUDevice ( )
override

Definition at line 77 of file WebGPUDevice.cpp.

References shutdown().

Member Function Documentation

◆ backendAcceptsVertexLayout()

bool esengine::WebGPUDevice::backendAcceptsVertexLayout ( const VertexLayoutDesc & desc)
overrideprotectedvirtual

◆ backendActiveUniforms()

std::vector< GfxUniformInfo > esengine::WebGPUDevice::backendActiveUniforms ( u32 )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 231 of file WebGPUDevice.hpp.

◆ backendAdoptTexture()

bool esengine::WebGPUDevice::backendAdoptTexture ( u32 ,
u32 ,
const TextureDesc &  )
inlineoverrideprotectedvirtual

A foreign surface (canvas, video frame) arrives as a WGPUTexture, never an integer.

Implements esengine::GfxDevice.

Definition at line 208 of file WebGPUDevice.hpp.

◆ backendAttribLocation()

i32 esengine::WebGPUDevice::backendAttribLocation ( u32 ,
const char *  )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 229 of file WebGPUDevice.hpp.

◆ backendCreateBuffer()

bool esengine::WebGPUDevice::backendCreateBuffer ( u32 id,
const BufferDesc & desc,
const void * data )
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 888 of file WebGPUDevice.cpp.

References esengine::BufferDesc::size, and esengine::BufferDesc::usage.

◆ backendCreateCompressedTexture()

◆ backendCreateCompute()

bool esengine::WebGPUDevice::backendCreateCompute ( u32 id,
const GfxComputeSource & source,
std::string * outLog )
overrideprotectedvirtual

Reimplemented from esengine::GfxDevice.

Definition at line 3320 of file WebGPUDevice.cpp.

◆ backendCreateFramebuffer()

bool esengine::WebGPUDevice::backendCreateFramebuffer ( u32 id,
const FramebufferDesc & desc )
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 2538 of file WebGPUDevice.cpp.

◆ backendCreateProgram()

◆ backendCreateTexture()

bool esengine::WebGPUDevice::backendCreateTexture ( u32 id,
const TextureDesc & desc,
const void * pixels )
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 1161 of file WebGPUDevice.cpp.

References backendCreateTexture().

Referenced by backendCreateTexture().

◆ backendCreateTimerQuery()

bool esengine::WebGPUDevice::backendCreateTimerQuery ( u32 id)
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 3088 of file WebGPUDevice.cpp.

◆ backendDeleteBuffer()

void esengine::WebGPUDevice::backendDeleteBuffer ( u32 id)
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 905 of file WebGPUDevice.cpp.

◆ backendDeleteCompute()

void esengine::WebGPUDevice::backendDeleteCompute ( u32 id)
overrideprotectedvirtual

Reimplemented from esengine::GfxDevice.

Definition at line 3346 of file WebGPUDevice.cpp.

◆ backendDeleteFramebuffer()

void esengine::WebGPUDevice::backendDeleteFramebuffer ( u32 )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 241 of file WebGPUDevice.hpp.

◆ backendDeleteProgram()

void esengine::WebGPUDevice::backendDeleteProgram ( u32 id)
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 1445 of file WebGPUDevice.cpp.

References backendDeleteProgram().

Referenced by backendDeleteProgram().

◆ backendDeleteTexture()

void esengine::WebGPUDevice::backendDeleteTexture ( u32 id)
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 1249 of file WebGPUDevice.cpp.

References backendDeleteTexture().

Referenced by backendDeleteTexture().

◆ backendDeleteVertexLayout()

void esengine::WebGPUDevice::backendDeleteVertexLayout ( u32 id)
inlineoverrideprotectedvirtual

Drops what the backend derived from a layout (a GL VAO); the desc stays here.

Implements esengine::GfxDevice.

Definition at line 236 of file WebGPUDevice.hpp.

◆ backendDispatchCompute()

bool esengine::WebGPUDevice::backendDispatchCompute ( u32 id,
const GfxComputeBinding * bindings,
u32 bindingCount,
u32 groupsX,
u32 groupsY,
u32 groupsZ )
overrideprotectedvirtual

Reimplemented from esengine::GfxDevice.

Definition at line 3359 of file WebGPUDevice.cpp.

◆ backendGenerateMipmaps()

void esengine::WebGPUDevice::backendGenerateMipmaps ( u32 id)
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 1328 of file WebGPUDevice.cpp.

References backendGenerateMipmaps().

Referenced by backendGenerateMipmaps().

◆ backendInvalidatePipelineCache()

void esengine::WebGPUDevice::backendInvalidatePipelineCache ( )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 238 of file WebGPUDevice.hpp.

◆ backendMoveTexture()

void esengine::WebGPUDevice::backendMoveTexture ( u32 into,
u32 from )
overrideprotectedvirtual

Re-keys from's native texture under into; into holds none on entry.

Implements esengine::GfxDevice.

Definition at line 1256 of file WebGPUDevice.cpp.

References backendMoveTexture().

Referenced by backendMoveTexture().

◆ backendReadbackCount()

u32 esengine::WebGPUDevice::backendReadbackCount ( ) const
inlineoverrideprotectedvirtual

Readbacks in flight, the one live object the registry does not hold.

Implements esengine::GfxDevice.

Definition at line 244 of file WebGPUDevice.hpp.

◆ backendResizeBuffer()

void esengine::WebGPUDevice::backendResizeBuffer ( u32 id,
const BufferDesc & desc,
const void * data )
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 962 of file WebGPUDevice.cpp.

References esengine::BufferDesc::size, and esengine::BufferDesc::usage.

◆ backendSetPipeline()

void esengine::WebGPUDevice::backendSetPipeline ( u32 id,
const PipelineDesc & desc )
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 1576 of file WebGPUDevice.cpp.

References backendSetPipeline().

Referenced by backendSetPipeline().

◆ backendSetTextureParams()

void esengine::WebGPUDevice::backendSetTextureParams ( u32 id,
const TextureDesc & desc )
overrideprotectedvirtual

◆ backendSetUniform()

void esengine::WebGPUDevice::backendSetUniform ( i32 ,
const GfxUniformValue &  )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 230 of file WebGPUDevice.hpp.

◆ backendSetUniformBuffer()

void esengine::WebGPUDevice::backendSetUniformBuffer ( u32 slot,
BufferHandle buffer,
u32 offsetBytes,
u32 sizeBytes )
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 981 of file WebGPUDevice.cpp.

◆ backendUniformBlockBinding()

void esengine::WebGPUDevice::backendUniformBlockBinding ( u32 ,
u32 ,
u32  )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 233 of file WebGPUDevice.hpp.

◆ backendUniformBlockIndex()

u32 esengine::WebGPUDevice::backendUniformBlockIndex ( u32 ,
const char *  )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 232 of file WebGPUDevice.hpp.

References esengine::GFX_INVALID_UNIFORM_BLOCK.

◆ backendUniformLocation()

i32 esengine::WebGPUDevice::backendUniformLocation ( u32 program,
const char * name )
inlineoverrideprotectedvirtual

The backend's own location this generation, -1 when absent.

Implements esengine::GfxDevice.

Definition at line 228 of file WebGPUDevice.hpp.

◆ backendUpdateBuffer()

void esengine::WebGPUDevice::backendUpdateBuffer ( u32 id,
u32 offsetBytes,
const void * data,
u32 sizeBytes )
overrideprotectedvirtual

◆ backendUpdateTexture()

void esengine::WebGPUDevice::backendUpdateTexture ( u32 id,
i32 x,
i32 y,
u32 width,
u32 height,
const void * pixels,
bool flipY )
overrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 1266 of file WebGPUDevice.cpp.

References backendUpdateTexture().

Referenced by backendUpdateTexture().

◆ backendUseProgram()

void esengine::WebGPUDevice::backendUseProgram ( u32 )
inlineoverrideprotectedvirtual

Implements esengine::GfxDevice.

Definition at line 227 of file WebGPUDevice.hpp.

◆ beginRenderPass()

void esengine::WebGPUDevice::beginRenderPass ( const RenderPassDesc & desc)
overridevirtual

Targets a framebuffer for subsequent draws and applies the pass's clears.

Beginning a pass while another is open retargets directly (the GL model has no explicit pass object); endRenderPass returns to the backbuffer. A WebGPU backend maps this to real pass boundaries.

Implements esengine::GfxDevice.

Definition at line 2547 of file WebGPUDevice.cpp.

◆ beginTimerQuery()

void esengine::WebGPUDevice::beginTimerQuery ( u32 query)
overridevirtual

Starts timing GPU work into a query; one query may be active at a time.

The same span on every backend: the GPU's time for everything issued until endTimerQuery, every pass included. A render pass still open at the end belongs to the span up to where the pass ends.

Implements esengine::GfxDevice.

Definition at line 3095 of file WebGPUDevice.cpp.

◆ bindTexture()

void esengine::WebGPUDevice::bindTexture ( u32 slot,
TextureHandle texture )
overridevirtual

Activates a texture slot and binds a 2D texture.

Implements esengine::GfxDevice.

Definition at line 1333 of file WebGPUDevice.cpp.

References bindTexture().

Referenced by bindTexture().

◆ captureDeviceIdentity()

void esengine::WebGPUDevice::captureDeviceIdentity ( )
overrideprotectedvirtual

Records who this backend is, so a later loss report can name it.

Called from init() while the backend still answers, and again after a recovery: a rebuilt device can be a DIFFERENT GPU, and a report naming the one that is gone sends the reader hunting the wrong hardware. Implementations call setDeviceIdentity.

Reimplemented from esengine::GfxDevice.

Definition at line 93 of file WebGPUDevice.cpp.

References getString(), esengine::Renderer, esengine::GfxDevice::setDeviceIdentity(), and esengine::Version.

Referenced by init().

◆ captureNextFrame()

ReadbackHandle esengine::WebGPUDevice::captureNextFrame ( u32 w,
u32 h )
overridevirtual

Copy the next completed frame's swapchain image into a readback.

Books the copy; endFrame performs it, because the renderer gives the swapchain image back there and every caller outside runs too late. This is the whole reason the seam is virtual: a GL default framebuffer can be read on demand, and this one cannot.

Invalid without setSurfaceReadback, or with a capture in flight.

Reimplemented from esengine::GfxDevice.

Definition at line 2851 of file WebGPUDevice.cpp.

◆ clearStencil()

void esengine::WebGPUDevice::clearStencil ( i32 value)
overridevirtual

Mid-pass stencil reset (the one clear that isn't a pass load-op).

The mask pass wipes the stencil attachment of the CURRENT target before rebuilding mask refs — it must not restart the pass (the scene may be rendering into a post-process capture). GL clears the attachment; a WebGPU backend emulates with a stencil-write quad.

Implements esengine::GfxDevice.

Definition at line 795 of file WebGPUDevice.cpp.

References ES_LOG_WARN, and esengine::webgpu::hasStencilPlanes().

◆ clipDepthRange()

ClipDepthRange esengine::WebGPUDevice::clipDepthRange ( ) const
inlineoverridevirtual

The clip volume this device keeps along z.

Pure: a backend that does not state this is a backend whose projections silently mean something else, which is the bug this exists to make impossible. It is not read off deviceIdentity, whose backend name is a label rather than a capability.

Implements esengine::GfxDevice.

Definition at line 94 of file WebGPUDevice.hpp.

References esengine::ZeroToOne.

◆ colorVariantOf()

u32 esengine::WebGPUDevice::colorVariantOf ( WGPUTextureFormat format)
static

Which variant slot a pass's colour format uses. Beside the enum because the two are one decision: a format that shares a slot with another is a pipeline handed to a pass that rejects it.

Definition at line 1028 of file WebGPUDevice.cpp.

References kColorBgra8, kColorRgba16f, kColorRgba32f, kColorRgba8, and kColorSrgb8.

◆ configureSurface()

bool esengine::WebGPUDevice::configureSurface ( const NativeSurface & window,
u32 width,
u32 height )

Binds a native window as the render target; shares configureSwapchain with the web path. Native Dawn build only.

Definition at line 378 of file WebGPUDevice.cpp.

References AndroidWindow, endFrame(), ES_LOG_ERROR, esengine::WebGPUDevice::NativeSurface::handle, esengine::WebGPUDevice::NativeSurface::instance, esengine::WebGPUDevice::NativeSurface::kind, MetalLayer, WaylandSurface, Win32Hwnd, and XlibWindow.

◆ discardReadback()

void esengine::WebGPUDevice::discardReadback ( ReadbackHandle handle)
overridevirtual

Abandons a readback (any state); its resources are released.

Implements esengine::GfxDevice.

Definition at line 3054 of file WebGPUDevice.cpp.

References esengine::Failed.

◆ drawArrays()

void esengine::WebGPUDevice::drawArrays ( u32 first,
u32 vertexCount )
overridevirtual

Draws non-indexed triangles.

Implements esengine::GfxDevice.

Definition at line 2517 of file WebGPUDevice.cpp.

◆ drawElements()

void esengine::WebGPUDevice::drawElements ( u32 indexCount,
GfxDataType indexType,
u32 byteOffset )
overridevirtual

Draws indexed triangles.

Implements esengine::GfxDevice.

Definition at line 2505 of file WebGPUDevice.cpp.

◆ drawElementsInstanced()

void esengine::WebGPUDevice::drawElementsInstanced ( u32 indexCount,
GfxDataType indexType,
u32 byteOffset,
u32 instanceCount )
overridevirtual

Draws indexed triangles with instancing.

Implements esengine::GfxDevice.

Definition at line 2524 of file WebGPUDevice.cpp.

◆ endFrame()

void esengine::WebGPUDevice::endFrame ( )
overridevirtual

The frame is over — everything drawn for it has been submitted.

A backend that borrows the swapchain image for the duration of a frame gives it back here (WebGPU hands one out per frame and takes it back at present), which is why the boundary has to be stated rather than inferred from the last pass: a frame may open several passes on the swapchain — a post-process blit over the captured scene, a second camera — and each of those is NOT the end. Default: nothing to do (GL presents through the platform).

Reimplemented from esengine::GfxDevice.

Definition at line 2814 of file WebGPUDevice.cpp.

Referenced by configureSurface(), and present().

◆ endRenderPass()

void esengine::WebGPUDevice::endRenderPass ( )
overridevirtual

Ends the current pass, restoring the default framebuffer.

Implements esengine::GfxDevice.

Definition at line 2759 of file WebGPUDevice.cpp.

Referenced by framePending().

◆ endTimerQuery()

void esengine::WebGPUDevice::endTimerQuery ( )
overridevirtual

Stops the active timer query.

Implements esengine::GfxDevice.

Definition at line 3152 of file WebGPUDevice.cpp.

◆ estimatedGpuBytes()

u64 esengine::WebGPUDevice::estimatedGpuBytes ( ) const
overridevirtual

◆ frameCaptureIsBGRA()

bool esengine::WebGPUDevice::frameCaptureIsBGRA ( ) const
inlineoverridevirtual

Whether a captured frame's bytes are BGRA rather than RGBA — the surface's choice on a backend that has one, and never GL's.

Reimplemented from esengine::GfxDevice.

Definition at line 305 of file WebGPUDevice.hpp.

References surfaceBytesAreBGRA().

◆ framePending()

bool esengine::WebGPUDevice::framePending ( )
overridevirtual

Give the swapchain texture back: the frame is over (see GfxDevice::endFrame). A frame may have opened several passes on it, so no single pass may do this.

Reimplemented from esengine::GfxDevice.

Definition at line 2807 of file WebGPUDevice.cpp.

References endRenderPass().

◆ getError()

u32 esengine::WebGPUDevice::getError ( )
overridevirtual

Queries the last error.

Implements esengine::GfxDevice.

Definition at line 3279 of file WebGPUDevice.cpp.

◆ getInt()

i32 esengine::WebGPUDevice::getInt ( GfxIntParam name)
overridevirtual

Queries a backend integer capability/limit.

Implements esengine::GfxDevice.

Definition at line 3291 of file WebGPUDevice.cpp.

◆ getString()

std::string esengine::WebGPUDevice::getString ( GfxStringName name)
overridevirtual

Queries a backend identification string (diagnostics).

Implements esengine::GfxDevice.

Definition at line 3281 of file WebGPUDevice.cpp.

Referenced by captureDeviceIdentity().

◆ getTimerQueryNs()

bool esengine::WebGPUDevice::getTimerQueryNs ( u32 query,
u64 * outNanoseconds )
overridevirtual

Fetches a completed query's elapsed nanoseconds; false while still pending.

Implements esengine::GfxDevice.

Definition at line 3195 of file WebGPUDevice.cpp.

◆ hasDevice()

bool esengine::WebGPUDevice::hasDevice ( ) const
inline

Definition at line 251 of file WebGPUDevice.hpp.

◆ init()

void esengine::WebGPUDevice::init ( )
overridevirtual

◆ maxSamples()

u32 esengine::WebGPUDevice::maxSamples ( )
overridevirtual

Most samples an offscreen colour attachment may carry; 1 = none.

The engine owns its own multisampling: a target the scene draws into is created with this many samples and resolves itself. Ask before requesting samples — a backend answering 1 has no MSAA to give, and a target that asks anyway would resolve from nothing.

Implements esengine::GfxDevice.

Definition at line 84 of file WebGPUDevice.cpp.

References kMsaaSamples.

◆ ownDeviceReference()

void esengine::WebGPUDevice::ownDeviceReference ( )
inline

The web host transfers the reference it imported from JavaScript.

Definition at line 114 of file WebGPUDevice.hpp.

◆ pollDeviceLost()

bool esengine::WebGPUDevice::pollDeviceLost ( )
overridevirtual

Pumps backend-native loss detection.

Backends whose loss arrives as a callback (WebGPU) or a status query (GL robustness) surface it here. Default: the backend cannot detect loss itself and depends entirely on notifyDeviceLost.

Returns
True when THIS call is the one that observed the loss.

Reimplemented from esengine::GfxDevice.

Definition at line 121 of file WebGPUDevice.cpp.

◆ pollReadback()

GfxReadbackStatus esengine::WebGPUDevice::pollReadback ( ReadbackHandle handle)
overridevirtual

The state of an in-flight readback; pumps backend completion events. A Failed readback is released by the poll that reported it.

Implements esengine::GfxDevice.

Definition at line 2997 of file WebGPUDevice.cpp.

◆ present()

void esengine::WebGPUDevice::present ( )

Flips the swapchain to the display. The web path relies on the browser presenting the canvas after the frame callback; a native host must present the surface explicitly, once per frame after endRenderPass. No-op until a surface is configured.

Definition at line 484 of file WebGPUDevice.cpp.

References endFrame().

◆ provideReplacementDevice()

bool esengine::WebGPUDevice::provideReplacementDevice ( void * nativeDevice)
inlineoverridevirtual

Hands a replacement in for the next recovery attempt to take up.

Reimplemented from esengine::GfxDevice.

Definition at line 116 of file WebGPUDevice.hpp.

◆ reasonFromWgpu()

GfxDeviceLostReason esengine::WebGPUDevice::reasonFromWgpu ( u32 wgpuReason)
static

Maps a WGPUDeviceLostReason to the backend-neutral reason.

Definition at line 112 of file WebGPUDevice.cpp.

References esengine::Destroyed, esengine::Internal, and esengine::Unknown.

◆ recreateDevice()

bool esengine::WebGPUDevice::recreateDevice ( )
overrideprotectedvirtual

Backend half of recoverDevice: a working device again, with every id-to-native map and derived cache emptied.

The registry then rebuilds each object through the primitives above. Default: this backend cannot rebuild itself, so a loss is final.

Reimplemented from esengine::GfxDevice.

Definition at line 173 of file WebGPUDevice.cpp.

◆ reportUncapturedError()

void esengine::WebGPUDevice::reportUncapturedError ( u32 wgpuErrorType,
const char * message )

Routes the device's uncaptured-error callback; only fatal kinds become losses.

Definition at line 130 of file WebGPUDevice.cpp.

References ES_LOG_WARN, esengine::Internal, esengine::GfxDevice::markDeviceLost(), esengine::OutOfMemory, and validation_errors_logged_.

◆ requestBufferReadback()

ReadbackHandle esengine::WebGPUDevice::requestBufferReadback ( BufferHandle buffer,
u32 offsetBytes,
u32 sizeBytes )
overridevirtual

Copies bytes of a storage buffer out, to be taken with pollReadback / takeReadback.

takeReadback hands the bytes back as they are in the buffer; size and offsetBytes are multiples of 4. Invalid on a device that does not compute.

Reimplemented from esengine::GfxDevice.

Definition at line 3555 of file WebGPUDevice.cpp.

◆ requestReadback()

ReadbackHandle esengine::WebGPUDevice::requestReadback ( FramebufferHandle target,
u32 w,
u32 h )
overridevirtual

Requests an RGBA8 readback of a framebuffer's color attachment.

Backend-neutral contract: GL reads synchronously (the first poll reports Ready); WebGPU records a texture→staging copy and resolves when the buffer map lands, so callers must poll across event-loop turns. Must be called OUTSIDE a render pass. Rows land bottom-up (the GL convention every capture consumer assumes). The WebGPU backend reads offscreen targets only — the surface texture is not copyable — so a Default-target request returns Invalid there.

Returns
A handle to poll, or Invalid when the request cannot be issued.

Implements esengine::GfxDevice.

Definition at line 2919 of file WebGPUDevice.cpp.

◆ requestTextureReadback()

ReadbackHandle esengine::WebGPUDevice::requestTextureReadback ( TextureHandle texture)
overridevirtual

Copies a storage texture's pixels out, tightly packed in the texture's own format (rows top-down).

Unlike requestReadback it names the texture, not a framebuffer, since a compute target has none. RGBA8, RGBA16F and RGBA32F: four, eight and sixteen bytes a texel.

Reimplemented from esengine::GfxDevice.

Definition at line 3581 of file WebGPUDevice.cpp.

◆ resizeBackbuffer()

void esengine::WebGPUDevice::resizeBackbuffer ( u32 width,
u32 height )
overridevirtual

Resizes the default backbuffer to the viewport size.

GL tracks the canvas drawing buffer implicitly (default no-op); WebGPU swapchains are fixed-size, so its backend reconfigures the surface + companion depth-stencil when the size changes. Called once per frame with the current viewport (cheap when unchanged); must not be called inside a render pass.

Reimplemented from esengine::GfxDevice.

Definition at line 762 of file WebGPUDevice.cpp.

References ES_LOG_WARN.

◆ resolvesDepth()

bool esengine::WebGPUDevice::resolvesDepth ( ) const
inlineoverridevirtual

Colour resolves in the pass; depth is resolved by a pass of our own (resolveDepthAttachment), since WebGPU's depth attachment has no resolve target. Either way nothing above the RHI knows.

Reimplemented from esengine::GfxDevice.

Definition at line 142 of file WebGPUDevice.hpp.

◆ setIndexBuffer()

void esengine::WebGPUDevice::setIndexBuffer ( BufferHandle buffer)
overridevirtual

Binds the index buffer for subsequent indexed draws.

Implements esengine::GfxDevice.

Definition at line 1018 of file WebGPUDevice.cpp.

◆ setLateSurfaceAcquire()

void esengine::WebGPUDevice::setLateSurfaceAcquire ( bool enabled)
inline

Worker passes can span browser tasks. Acquire their expiring canvas texture at present.

Definition at line 325 of file WebGPUDevice.hpp.

◆ setPreferredSurfaceBGRA()

void esengine::WebGPUDevice::setPreferredSurfaceBGRA ( bool bgra)
inline

The surface format the host says its canvas prefers.

Only the page can answer it (navigator.gpu.getPreferredCanvasFormat()), and configuring anything else costs a full-frame copy per present. Must be set BEFORE the surface is configured.

Definition at line 314 of file WebGPUDevice.hpp.

◆ setPresentUncapped()

void esengine::WebGPUDevice::setPresentUncapped ( bool enabled)
inline

Present as fast as the surface allows instead of waiting for the display. Set BEFORE the surface is configured; off by default.

For MEASUREMENT only: under Fifo every frame reads as the refresh interval or a multiple of one, and a cost quantised to the panel is not a cost. Best effort — Mailbox, then Immediate, then Fifo.

Definition at line 335 of file WebGPUDevice.hpp.

◆ setScissor()

void esengine::WebGPUDevice::setScissor ( i32 x,
i32 y,
i32 w,
i32 h )
overridevirtual

Sets the scissor rectangle.

Implements esengine::GfxDevice.

Definition at line 817 of file WebGPUDevice.cpp.

◆ setScissorTest()

void esengine::WebGPUDevice::setScissorTest ( bool enabled)
overridevirtual

Enables or disables scissor test.

Implements esengine::GfxDevice.

Definition at line 810 of file WebGPUDevice.cpp.

◆ setStencilReference()

void esengine::WebGPUDevice::setStencilReference ( i32 reference)
overridevirtual

WebGPU stores a texture from the top down.

Implements esengine::GfxDevice.

Definition at line 1587 of file WebGPUDevice.cpp.

References setStencilReference().

Referenced by setStencilReference().

◆ setSurfaceReadback()

void esengine::WebGPUDevice::setSurfaceReadback ( bool enabled)
inline

Configure the swapchain with CopySrc, so captureNextFrame can read it. Must be set BEFORE the surface is configured.

Off by default: a surface is entitled not to support the usage, and every shipped frame would pay for a check nobody asked for.

Definition at line 323 of file WebGPUDevice.hpp.

◆ setSurfaceSamples()

void esengine::WebGPUDevice::setSurfaceSamples ( u32 samples)
inlineoverridevirtual

How many samples a SURFACE pass draws with — a frame with no post chain draws straight to the backbuffer.

A WebGL canvas is created antialiased; a WebGPU surface texture never is, so the backbuffer gets a multisampled companion that resolves into it. The change lands on the next frame.

Reimplemented from esengine::GfxDevice.

Definition at line 150 of file WebGPUDevice.hpp.

References kMsaaSamples.

◆ setVertexBuffer()

void esengine::WebGPUDevice::setVertexBuffer ( u32 slot,
BufferHandle buffer,
u32 offsetBytes )
overridevirtual

Binds a vertex buffer to a layout slot for subsequent draws.

Parameters
offsetBytesByte offset of element 0 — how an instanced draw rebases its per-instance stream (GLES3 has no baseInstance).

Implements esengine::GfxDevice.

Definition at line 1011 of file WebGPUDevice.cpp.

◆ setViewport()

void esengine::WebGPUDevice::setViewport ( i32 x,
i32 y,
u32 w,
u32 h )
overridevirtual

Sets the rendering viewport.

Implements esengine::GfxDevice.

Definition at line 787 of file WebGPUDevice.cpp.

References esengine::GfxDevice::viewport_.

◆ setWireframe()

void esengine::WebGPUDevice::setWireframe ( bool enabled)
overridevirtual

Enables or disables wireframe rendering (desktop only).

Implements esengine::GfxDevice.

Definition at line 3278 of file WebGPUDevice.cpp.

◆ shutdown()

void esengine::WebGPUDevice::shutdown ( )
overridevirtual

Shuts down the graphics device.

Implements esengine::GfxDevice.

Definition at line 183 of file WebGPUDevice.cpp.

Referenced by ~WebGPUDevice().

◆ supportsCompressedFormat()

bool esengine::WebGPUDevice::supportsCompressedFormat ( GfxCompressedFormat format)
overridevirtual

Reports whether the backend can sample the given compressed format.

ETC2/EAC is always true on a WebGL2/GLES3 backend (core spec); ASTC and S3TC depend on driver extensions. Probe this before calling createCompressedTexture with a non-core format.

Implements esengine::GfxDevice.

Definition at line 1342 of file WebGPUDevice.cpp.

References esengine::webgpu::compressionFeatureFor(), supportsCompressedFormat(), and esengine::webgpu::toWGPUCompressedFormat().

Referenced by supportsCompressedFormat().

◆ supportsCompute()

bool esengine::WebGPUDevice::supportsCompute ( ) const
inlineoverridevirtual

WebGPU is the backend with a compute stage; a device-less instance (bookkeeping only) has none to offer.

Reimplemented from esengine::GfxDevice.

Definition at line 158 of file WebGPUDevice.hpp.

◆ supportsFloatTargets()

bool esengine::WebGPUDevice::supportsFloatTargets ( )
inlineoverridevirtual

Whether RGBA16F color attachments are renderable.

WebGL2 gates float-target rendering behind EXT_color_buffer_float (sampling half-float textures is core); WebGPU always supports it. Probe this before creating an HDR framebuffer and fall back to SRGB8_ALPHA8/RGBA8.

Implements esengine::GfxDevice.

Definition at line 135 of file WebGPUDevice.hpp.

◆ supportsShaderLanguage()

bool esengine::WebGPUDevice::supportsShaderLanguage ( GfxShaderLanguage language) const
inlineoverridevirtual

Whether this backend compiles language (GL: GLSL ES 300; WebGPU: WGSL).

Implements esengine::GfxDevice.

Definition at line 162 of file WebGPUDevice.hpp.

References esengine::WGSL.

◆ supportsUnblendedSurfaceTarget()

bool esengine::WebGPUDevice::supportsUnblendedSurfaceTarget ( ) const
inlineoverridevirtual

The surface record's target carries no blend state of its own (see createPipeline).

Reimplemented from esengine::GfxDevice.

Definition at line 137 of file WebGPUDevice.hpp.

◆ surfaceBytesAreBGRA()

bool esengine::WebGPUDevice::surfaceBytesAreBGRA ( ) const

Whether bytes read back from the DEFAULT framebuffer are BGRA rather than RGBA.

The format is the surface's choice (BGRA8 on Metal, RGBA8 on Vulkan), so anyone writing an image has to ask rather than assume.

Definition at line 497 of file WebGPUDevice.cpp.

Referenced by frameCaptureIsBGRA().

◆ takeReadback()

bool esengine::WebGPUDevice::takeReadback ( ReadbackHandle handle,
void * dest,
usize destSize )
overridevirtual

Copies a Ready readback's pixels (w*h*4 bytes) into dest and releases it.

Returns
False when the handle is unknown, still Pending, or destSize is short — a Pending readback stays alive.

Implements esengine::GfxDevice.

Definition at line 3011 of file WebGPUDevice.cpp.

◆ timerDisjoint()

bool esengine::WebGPUDevice::timerDisjoint ( )
overridevirtual

True when GPU timing was disturbed since the last check.

In-flight query results are then meaningless and must be discarded.

Implements esengine::GfxDevice.

Definition at line 3193 of file WebGPUDevice.cpp.

Member Data Documentation

◆ kMsaaSamples

u32 esengine::WebGPUDevice::kMsaaSamples = 4
staticconstexpr

The multisampled count this backend offers. WebGPU guarantees 1 and 4 for every renderable format; nothing else is portable.

Definition at line 75 of file WebGPUDevice.hpp.

Referenced by maxSamples(), and setSurfaceSamples().

◆ validation_errors_logged_

u32 esengine::WebGPUDevice::validation_errors_logged_ = 0

Validation errors said so far (reportUncapturedError says the first few).

Definition at line 109 of file WebGPUDevice.hpp.

Referenced by reportUncapturedError().


The documentation for this class was generated from the following files:
  • /home/runner/work/estella/estella/src/esengine/renderer/webgpu/WebGPUDevice.hpp
  • /home/runner/work/estella/estella/src/esengine/renderer/webgpu/WebGPUDevice.cpp