Skip to main content

Module gpu

Module gpu 

Source
Expand description

A wgpu custom backend that forwards to the host through the sg GPU API.

ⓘ
let instance = sg_guest::gpu::instance();
let surface = sg_guest::gpu::surface(&instance);
let adapter = instance.request_adapter(&Default::default()).await?;   // resolves immediately

Object handles are host ids. Command encoders, passes and bundles are recorded here and shipped in one request when finished. Objects referenced by a recording are kept alive until the host has the finished command buffer. Futures returned by this backend are always already resolved, so a trivial executor (see block_on) is enough. Callbacks (buffer mapping, work-done, uncaptured errors, device loss) run from Device::poll / pump, which the game should call once per frame, the way a browser runs them from its event loop.

Structs§

SgAdapter
SgBindGroup
SgBindGroupLayout
SgBlas
SgBuffer
SgCommandBuffer
SgCommandEncoder
SgComputePass
SgComputePipeline
SgDevice
SgExternalTexture
SgInstance
SgMappedRange
SgPipelineCache
SgPipelineLayout
SgQuerySet
SgQueue
SgRenderBundle
SgRenderBundleEncoder
SgRenderPass
SgRenderPipeline
SgSampler
SgShaderModule
SgStaging
SgSurface
SgSurfaceDetail
SgTexture
SgTextureView
SgTlas

Functions§

block_on
Runs a future that this backend returns (they are always ready).
frame_controls
Per-frame inputs for the host’s frame pass (DLSS5-NR when the user enabled it): call once per frame before presenting. motion is an Rg32Float texture of the surface’s size (COPY_SRC) of per-pixel offsets, in pixels, to the previous frame’s position (see sg_abi::gpu::FrameControls). Returns a sg_abi::gpu::frame_controls status.
instance
Creates a wgpu::Instance backed by the host GPU.
pump
Polls the host and runs completed callbacks. Call once per frame.
raw_request
Sends one raw sg-gpu request and returns the host’s reply. For tests and tools that need to speak the wire protocol directly (the sandbox tests send hostile requests with it); games use wgpu.
surface
Creates the game window’s surface.