cinder.gfx
cinder.gfx #
Source: cinder/gfx/__init__.mojo
Safe, typed layer over wgpu-native. Gfx owns the instance, adapter, device and queue and drains the shim's event queue into diagnostics (validation errors, device loss, wgpu log). Resource modules build on it with one distinct handle type per resource kind and ownership through __deinit__.
cinder.gfx.commands #
Source: cinder/gfx/commands.mojo
Command recording: encoders, render and compute passes, copies, submission and readback.
comptime NoChain = Optional[Pointer[WGPUChainedStruct, MutUntrackedOrigin]]— NullnextInChainfor wgpu descriptors that carry no chained extension struct.
struct ColorAttachment #
struct ColorAttachment(Copyable, Movable)A colour target of a render pass. view may be a swapchain view obtained outside Resources; resolve is the single-sample target when view is multisampled (null otherwise).
Fields:
-
view: WGPUTextureView -
clear: Bool -
clear_color: WGPUColor -
store: Bool -
resolve: WGPUTextureView -
__init____init__( out self, view: WGPUTextureView, clear: Bool, var clear_color: WGPUColor, store: Bool, resolve: WGPUTextureView = WGPUTextureView(), ) -
clearedcleared( view: WGPUTextureView, r: Float64, g: Float64, b: Float64, a: Float64 ) -> ColorAttachment
Clearsviewto (r, g, b, a) at load and stores the result; no resolve target. -
cleared_resolvingcleared_resolving( view: WGPUTextureView, resolve: WGPUTextureView, r: Float64, g: Float64, b: Float64, a: Float64, ) -> ColorAttachment
Clears the multisampledviewto (r, g, b, a), resolves intoresolveand discards the multisampled contents (store op Discard). -
loadedloaded(view: WGPUTextureView) -> ColorAttachment
Keeps the existing contents ofview(load op Load) and stores the result. -
comptime MAX_COLOR_ATTACHMENTS = 4— Colour attachments per render pass (wgpu allows 8; the engine uses at most 1 + resolve).
struct DepthAttachment #
struct DepthAttachment(ImplicitlyCopyable, Movable)Depth target. Reverse-Z clears to 0.0 (far).
Fields:
-
view: WGPUTextureView -
clear: Bool -
clear_depth: Float32 -
store: Bool -
nonenone() -> DepthAttachment
No depth target:begin_render_passthen passes no depth-stencil attachment. -
cleared_reverse_zcleared_reverse_z(view: WGPUTextureView) -> DepthAttachment
Clearsviewto 0.0 (the far plane under reverse-Z) and stores the result.
struct RenderPass #
struct RenderPass(Movable)An open render pass. end must be called exactly once.
Fields:
-
gfx: Pointer[Gfx, MutUntrackedOrigin] -
res: Pointer[Resources, MutUntrackedOrigin] -
raw: WGPURenderPassEncoder -
ended: Bool -
__init____init__( out self, gfx: Pointer[Gfx, MutUntrackedOrigin], res: Pointer[Resources, MutUntrackedOrigin], raw: WGPURenderPassEncoder, ) -
set_pipelineset_pipeline(self, h: RenderPipelineHandle) raises
Binds the render pipeline; raises if the handle is not live inResources. -
set_bind_groupset_bind_group(self, index: UInt32, h: BindGroupHandle) raises
Binds a bind group at groupindexwith no dynamic offsets; raises on an invalid handle. -
set_bind_group_dynamicset_bind_group_dynamic( self, index: UInt32, h: BindGroupHandle, mut offsets: List[UInt32] ) raises
Binds a bind group at groupindexwith one dynamic offset per dynamic binding.offsetsis read during the call only. Raises on an invalid handle; a wrong offset count or alignment surfaces as a validation diagnostic throughGfx.pump. -
set_vertex_bufferset_vertex_buffer( self, slot: UInt32, h: BufferHandle, offset: UInt64 = 0 ) raises
Bindshto vertex slotslotfromoffsetto the end of the buffer. Raises on an invalid handle or whenoffsetis not below the buffer size (nothing is bound then). -
set_index_bufferset_index_buffer( self, h: BufferHandle, format: WGPUIndexFormat, offset: UInt64 = 0 ) raises
Bindshas the index buffer withformatfromoffsetto the end of the buffer. Raises on an invalid handle or whenoffsetis not below the buffer size (nothing is bound then). -
set_viewportset_viewport( self, x: Float32, y: Float32, width: Float32, height: Float32 )
Sets the viewport rectangle in pixels with depth range 0..1. -
set_scissorset_scissor(self, x: UInt32, y: UInt32, width: UInt32, height: UInt32)
Sets the scissor rectangle in pixels. -
drawdraw( self, vertex_count: UInt32, instance_count: UInt32 = 1, first_vertex: UInt32 = 0, first_instance: UInt32 = 0, )
Draws non-indexed primitives with the bound pipeline and vertex buffers. -
draw_indexeddraw_indexed( self, index_count: UInt32, instance_count: UInt32 = 1, first_index: UInt32 = 0, base_vertex: Int32 = 0, first_instance: UInt32 = 0, )
Draws indexed primitives from the bound index buffer;base_vertexis added to each index. -
endend(mut self)
Ends and releases the pass encoder. Later calls do nothing. A pass dropped withoutendis ended and released by its destructor, which runs right after the pass's last use, so the encoder is never left with an open pass.
struct ComputePass #
struct ComputePass(Movable)An open compute pass from CommandEncoder.begin_compute_pass. end must be called exactly once.
Fields:
-
gfx: Pointer[Gfx, MutUntrackedOrigin] -
res: Pointer[Resources, MutUntrackedOrigin] -
raw: WGPUComputePassEncoder -
ended: Bool -
__init____init__( out self, gfx: Pointer[Gfx, MutUntrackedOrigin], res: Pointer[Resources, MutUntrackedOrigin], raw: WGPUComputePassEncoder, ) -
set_pipelineset_pipeline(self, h: ComputePipelineHandle) raises
Binds the compute pipeline; raises if the handle is not live inResources. -
set_bind_groupset_bind_group(self, index: UInt32, h: BindGroupHandle) raises
Binds a bind group at groupindexwith no dynamic offsets; raises on an invalid handle. -
set_bind_group_dynamicset_bind_group_dynamic( self, index: UInt32, h: BindGroupHandle, mut offsets: List[UInt32] ) raises
Binds a bind group at groupindexwith one dynamic offset per dynamic binding.offsetsis read during the call only. Raises on an invalid handle; a wrong offset count or alignment surfaces as a validation diagnostic throughGfx.pump. -
dispatchdispatch(self, x: UInt32, y: UInt32 = 1, z: UInt32 = 1)
Dispatches an x by y by z grid of workgroups with the bound pipeline. -
endend(mut self)
Ends and releases the pass encoder. Later calls do nothing. A pass dropped withoutendis ended and released by its destructor, which runs right after the pass's last use, so the encoder is never left with an open pass.
def command_encoder_descriptor #
def command_encoder_descriptor(ref label: String) -> WGPUCommandEncoderDescriptorThe descriptor CommandEncoder creates its encoder with: no chain, label as the label. The view borrows label, which must outlive the wgpu call (keep it).
struct CommandEncoder #
struct CommandEncoder(Movable)Records one command buffer. finish_and_submit consumes it; an encoder dropped without it is released by its destructor and its commands are discarded.
Fields:
-
gfx: Pointer[Gfx, MutUntrackedOrigin] -
res: Pointer[Resources, MutUntrackedOrigin] -
raw: WGPUCommandEncoder -
__init____init__( out self, gfx: Pointer[Gfx, MutUntrackedOrigin], res: Pointer[Resources, MutUntrackedOrigin], label: String, ) raises -
begin_render_passbegin_render_pass( self, colors: List[ColorAttachment], depth: DepthAttachment ) raises -> RenderPass
Begins a render pass on the given colour targets and optional depth target. Raises when there are more thanMAX_COLOR_ATTACHMENTScolours or wgpu returns NULL. The depth attachment is used only whendepth.viewis non-null; stencil is not used. CallRenderPass.endbefore recording anything else on this encoder. -
begin_compute_passbegin_compute_pass(self) raises -> ComputePass
Begins a compute pass without timestamp writes; raises if wgpu returns NULL. CallComputePass.endbefore recording anything else on this encoder. -
copy_buffer_to_buffercopy_buffer_to_buffer( self, src: BufferHandle, src_offset: UInt64, dst: BufferHandle, dst_offset: UInt64, size: UInt64, ) raises
Records a copy ofsizebytes between two buffers. Raises on an invalid handle; range and usage errors surface as validation diagnostics throughGfx.pump. -
copy_texture_to_buffercopy_texture_to_buffer( self, texture: TextureHandle, dst: BufferHandle, bytes_per_row: UInt32, width: UInt32, height: UInt32, ) raises
Copies mip 0, layer 0 of aResourcestexture intodstat offset 0, withbytes_per_rowstride andheightrows per image. Raises on an invalid handle. -
copy_raw_texture_to_buffercopy_raw_texture_to_buffer( self, texture: WGPUTexture, dst: BufferHandle, bytes_per_row: UInt32, width: UInt32, height: UInt32, ) raises
Copies mip 0 of a texture outsideResources(a swapchain texture) intodst. -
finish_and_submitfinish_and_submit(deinit self) raises
Finishes the encoder, submits the command buffer to the queue and releases both. Raises ifwgpuCommandEncoderFinishreturns NULL (the encoder is still released). Does not wait for the GPU; usewait_for_queuefor that.
def wait_for_queue #
def wait_for_queue(mut gfx: Gfx) raises GfxErrorBlocks until all submitted work has completed (tests and shutdown; never in the frame loop).
def read_buffer #
def read_buffer( mut gfx: Gfx, res: Resources, buffer: BufferHandle, size: Int ) raises -> List[UInt8]Maps a MapRead buffer, copies size bytes out and unmaps it (tests and tools only).
cinder.gfx.debug_draw #
Source: cinder/gfx/debug_draw.mojo
Immediate-mode debug lines: segments, boxes, spheres, axes and grids drawn in one line-list pass. Vertices accumulate on the CPU each frame (line, aabb, ...) and are uploaded once in flush, which records the draw into an open RenderPass. The vertex buffer grows by doubling and is never shrunk, so the steady state allocates nothing. Depth testing is reverse-Z when a depth format is given; depth_format == Undefined draws on top of everything.
comptime VERTEX_BYTES = 16— Float32x3 position + Unorm8x4 colour.comptime SHADER = """— WGSL for debug lines: transforms positions by the camera uniform and passes the vertex colour through unlit.
struct Color8 #
struct Color8(Equatable, ImplicitlyCopyable, RegisterPassable)8-bit RGBA colour.
Fields:
-
r: UInt8 -
g: UInt8 -
b: UInt8 -
a: UInt8 -
redred() -> Color8
Opaque red (255, 0, 0, 255). -
greengreen() -> Color8
Opaque green (0, 255, 0, 255). -
blueblue() -> Color8
Opaque blue (0, 0, 255, 255). -
whitewhite() -> Color8
Opaque white (255, 255, 255, 255). -
yellowyellow() -> Color8
Opaque yellow (255, 255, 0, 255).
struct DebugDraw #
struct DebugDraw(Movable)Per-frame line accumulator plus the GPU objects that draw it.
Fields:
-
gfx: Pointer[Gfx, MutUntrackedOrigin] -
res: Pointer[Resources, MutUntrackedOrigin] -
shader: ShaderHandle -
pipeline: RenderPipelineHandle -
camera_buffer: BufferHandle -
camera_group: BindGroupHandle -
vertex_buffer: BufferHandle -
vertex_capacity: Int — Vertices the GPU buffer can hold. -
vertices: List[UInt8] -
vertex_count: Int -
grows: Int — Times the vertex buffer was reallocated (tests check this stays flat in steady state). -
__init____init__( out self, gfx: Pointer[Gfx, MutUntrackedOrigin], res: Pointer[Resources, MutUntrackedOrigin], mut shaders: ShaderManager, color_format: WGPUTextureFormat, depth_format: WGPUTextureFormat = WGPUTextureFormat_Undefined, initial_capacity: Int = 4096, ) raises -
clearclear(mut self)
Drops this frame's lines (called byflush). -
lineline(mut self, a: Vec3, b: Vec3, color: Color8)
Queues one world-space segment fromatobfor this frame (two vertices). Only CPU memory grows here;uploadenlarges the GPU buffer if needed,flushdraws and clears. -
aabbaabb(mut self, min: Vec3, max: Vec3, color: Color8)
The 12 edges of an axis-aligned box. -
spheresphere( mut self, centre: Vec3, radius: Float32, color: Color8, segments: Int = 24, )
Three great circles (XY, XZ, YZ). -
axesaxes(mut self, origin: Vec3, length: Float32)
X red, Y green, Z blue. -
gridgrid(mut self, half_extent: Int, spacing: Float32, color: Color8)
An XZ ground grid centred on the origin with2 * half_extent + 1lines per axis. -
uploadupload(mut self, view_proj: Mat4) raises
Writes the camera and this frame's vertices to the GPU (before the render pass opens). -
flushflush(mut self, pass_: RenderPass) raises
Records the draw for the vertices uploaded byupload, then clears them.
cinder.gfx.device #
Source: cinder/gfx/device.mojo
Gfx: instance, adapter, device and queue, with every wgpu callback pulled from the shim queue.
comptime EventQueuePtr = Optional[Pointer[CnEventQueue, MutUntrackedOrigin]]— Nullable pointer to the shim's CnEventQueue that carries every wgpu callback as an event.comptime NoChain = Optional[Pointer[WGPUChainedStruct, MutUntrackedOrigin]]— NullnextInChainfor wgpu descriptors that carry no chained extension struct.comptime DEFAULT_TIMEOUT_NS = 10_000_000_000— How longGfx.await_eventpumps before raising GfxError: 10 seconds.
struct GfxError #
struct GfxError(Copyable, Movable, Writable)A recoverable graphics failure (adapter/device request, timeout, lost device).
Fields:
-
message: String -
write_towrite_to(self, mut writer: Some[Writer])
struct Gfx #
struct Gfx(Movable)Owns one wgpu instance, adapter, device and queue. Callbacks never run in Mojo: pump drives wgpu and drains the shim's event queue, turning log lines, uncaptured validation errors and device loss into diagnostics (LogRecords for the engine logger) while returning every other event to the caller that awaits it.
Fields:
-
lib: NativePtr -
events: EventQueuePtr -
instance: WGPUInstance -
adapter: WGPUAdapter -
device: WGPUDevice -
queue: WGPUQueue -
adapter_name: String -
backend: UInt32 -
wireframe_supported: Bool — True when the device was created with wgpu-native's PolygonModeLine feature. -
bc_supported: Bool — True when the device was created with BC (DXT/BC7) texture compression. -
diagnostics: List[LogRecord] -
error_count: Int — Uncaptured validation errors seen since creation. Tests assert this stays zero. -
lost: Bool -
surface: WGPUSurface — The window surface when constructed from aWindow; null for headless devices. -
surface_window: Optional[Pointer[Window, MutUntrackedOrigin]] -
__init____init__( out self, lib: NativePtr, surface: WGPUSurface ) raises GfxError
Creates instance, adapter (compatible withsurfacewhen given) and device. -
__init____init__(out self, lib: NativePtr, ref window: Window) raises GfxError
Creates instance, a surface forwindow, a compatible adapter and device.Gfxkeeps the surface (surfacefield) and destroys it at teardown. -
__init____init__( out self, lib: NativePtr, surface: WGPUSurface, window: Optional[Pointer[Window, MutUntrackedOrigin]], ) raises GfxError -
next_request_idnext_request_id(mut self) -> UInt64
Returns a fresh id (1, 2, ...) that tags an async shim request so its reply event can be matched byawait_event/take_pending. -
pumppump(mut self, wait: Bool)
Drives wgpu callbacks and drains the shim queue. Log, error and device-lost events become diagnostics; everything else is held forawait_event/take_pending. -
await_eventawait_event( mut self, kind: UInt32, request_id: UInt64, timeout_ns: Int = DEFAULT_TIMEOUT_NS, ) raises GfxError -> CnEvent
Pumps until the event (kind, request id) arrives; raises GfxError on timeout. -
take_pendingtake_pending( mut self, kind: UInt32, request_id: UInt64, mut out: List[CnEvent] )
Moves every pending event matching (kind, request id) intoout, in arrival order. -
take_diagnosticstake_diagnostics(mut self) -> List[LogRecord]
Returns and clears the LogRecords collected bypump: wgpu log lines (wgpu), uncaptured validation errors (wgpu.validation) and device loss (wgpu.device).error_countandlostare not reset.
cinder.gfx.pipeline #
Source: cinder/gfx/pipeline.mojo
Typed descriptors for bind group layouts, bind groups, pipeline layouts and pipelines. Each create_* builds the wgpu descriptor from engine-side structs, calls wgpu with every pointee kept alive for the call, and adopts the result into Resources under a typed handle.
comptime NoChain = Optional[Pointer[WGPUChainedStruct, MutUntrackedOrigin]]— NullnextInChainfor wgpu descriptors that carry no chained extension struct.
struct BindingKind #
struct BindingKind(Equatable, ImplicitlyCopyable, RegisterPassable)What a bind group layout slot holds.
Fields:
-
value: UInt8 -
uniform_bufferuniform_buffer() -> BindingKind
Uniform buffer;LayoutEntry.dynamic_offsetandmin_binding_sizeapply. -
storage_bufferstorage_buffer() -> BindingKind
Read-write storage buffer;dynamic_offsetandmin_binding_sizeapply. -
readonly_storage_bufferreadonly_storage_buffer() -> BindingKind
Read-only storage buffer;dynamic_offsetandmin_binding_sizeapply. -
texture_2dtexture_2d() -> BindingKind
Filterable float texture with a 2D view dimension. -
samplersampler() -> BindingKind
Filtering sampler. -
comparison_samplercomparison_sampler() -> BindingKind
Comparison sampler, as made byResources.create_comparison_sampler. -
depth_texture_2ddepth_texture_2d() -> BindingKind
Depth texture with a 2D view dimension. -
depth_texture_2d_arraydepth_texture_2d_array() -> BindingKind
Depth texture with a 2D-array view dimension. -
texture_cubetexture_cube() -> BindingKind
Filterable float texture with a cube view dimension. -
texture_2d_arraytexture_2d_array() -> BindingKind
Filterable float texture with a 2D-array view dimension. -
storage_texture_2d_writestorage_texture_2d_write() -> BindingKind
Write-only storage texture;LayoutEntry.formatnames the texel format. -
storage_texture_2d_array_writestorage_texture_2d_array_write() -> BindingKind
Write-only storage texture with a 2D-array view;LayoutEntry.formatnames the texel format. -
depth_texture_multisampled_2ddepth_texture_multisampled_2d() -> BindingKind
Multisampled depth texture with a 2D view dimension. -
non_filtering_samplernon_filtering_sampler() -> BindingKind
Non-filtering sampler, for use withtexture_2d_unfilterabletextures. -
texture_2d_unfilterabletexture_2d_unfilterable() -> BindingKind
Float texture read with textureLoad or a non-filtering sampler (RGBA32Float).
struct LayoutEntry #
struct LayoutEntry(ImplicitlyCopyable, Movable)One slot of a bind group layout. format matters for storage textures only.
Fields:
-
binding: UInt32 -
visibility: UInt64 -
kind: BindingKind -
dynamic_offset: Bool -
min_binding_size: UInt64 -
format: WGPUTextureFormat -
__init____init__( out self, binding: UInt32, visibility: UInt64, kind: BindingKind, dynamic_offset: Bool = False, min_binding_size: UInt64 = 0, format: WGPUTextureFormat = WGPUTextureFormat_Undefined, )
struct BindingResource #
struct BindingResource(ImplicitlyCopyable, Movable)What to bind in a slot: exactly one of buffer, texture view or sampler is non-null.
Fields:
-
binding: UInt32 -
buffer: BufferHandle -
buffer_offset: UInt64 -
buffer_size: UInt64 -
texture_view: TextureViewHandle -
sampler: SamplerHandle -
for_bufferfor_buffer( binding: UInt32, buffer: BufferHandle, offset: UInt64, size: UInt64 ) -> BindingResource
Bindssizebytes ofbufferfromoffset; asizeof 0 binds fromoffsetto the end of the buffer (resolved increate_bind_group). -
for_texturefor_texture( binding: UInt32, view: TextureViewHandle ) -> BindingResource
Binds a texture view fromResources(owned or imported). -
for_samplerfor_sampler(binding: UInt32, sampler: SamplerHandle) -> BindingResource
Binds a sampler fromResources.
struct VertexAttribute #
struct VertexAttribute(ImplicitlyCopyable, Movable)One vertex attribute: its format, byte offset within the vertex and shader location.
Fields:
format: WGPUVertexFormatoffset: UInt64location: UInt32
struct VertexLayout #
struct VertexLayout(Copyable, Movable)One vertex buffer slot: stride, step mode and attributes.
Fields:
-
stride: UInt64 -
step_mode: WGPUVertexStepMode -
attributes: List[VertexAttribute] -
__init____init__( out self, stride: UInt64, var attributes: List[VertexAttribute], step_mode: WGPUVertexStepMode = WGPUVertexStepMode_Vertex, )
struct DepthState #
struct DepthState(ImplicitlyCopyable, Movable)Depth testing. Reverse-Z means GreaterEqual is the engine's default compare.
Fields:
-
format: WGPUTextureFormat -
write: Bool -
compare: WGPUCompareFunction -
bias: Int32 -
bias_slope: Float32 -
bias_clamp: Float32 -
__init____init__( out self, format: WGPUTextureFormat, write: Bool, compare: WGPUCompareFunction, bias: Int32 = 0, bias_slope: Float32 = 0.0, bias_clamp: Float32 = 0.0, ) -
nonenone() -> DepthState
No depth-stencil state:build_render_pipelineomits it because the format is Undefined. -
reverse_zreverse_z(format: WGPUTextureFormat, write: Bool = True) -> DepthState
Reverse-Z depth test (GreaterEqual) onformat, writing depth unlesswriteis False, with no bias. -
reverse_z_biasedreverse_z_biased( format: WGPUTextureFormat, bias: Int32, bias_slope: Float32 ) -> DepthState
Shadow-map depth: reverse-Z, written, with constant and slope bias (negative values push depth away from the light in reverse-Z).
struct BlendMode #
struct BlendMode(Equatable, ImplicitlyCopyable, RegisterPassable)Colour blending preset of a ColorTarget, expanded to a WGPUBlendState when a pipeline is built. Any value other than alpha or additive builds as opaque.
Fields:
-
value: UInt8 -
opaqueopaque() -> BlendMode
No blending: the source replaces the destination (One, Zero). -
alphaalpha() -> BlendMode
Premultiplied-free source-over: src * a + dst * (1 - a). -
additiveadditive() -> BlendMode
Adds source to destination for colour and alpha (One, One).
struct ColorTarget #
struct ColorTarget(ImplicitlyCopyable, Movable)One colour output of a render pipeline: its texture format and blend mode, written with all channels enabled.
Fields:
format: WGPUTextureFormatblend: BlendMode
struct RenderPipelineDesc #
struct RenderPipelineDesc(Copyable, Movable)Everything needed for a render pipeline. Entry points name functions in shader.
Fields:
-
label: String -
layout: PipelineLayoutHandle -
shader: ShaderHandle -
vertex_entry: String -
fragment_entry: String -
vertex_layouts: List[VertexLayout] -
color_targets: List[ColorTarget] -
depth: DepthState -
topology: WGPUPrimitiveTopology -
cull_mode: WGPUCullMode -
sample_count: UInt32 -
wireframe: Bool — Line polygon mode (needs the device feature; seeGfx.wireframe_supported). -
front_face_cw: Bool -
__init____init__( out self, label: String, layout: PipelineLayoutHandle, shader: ShaderHandle, vertex_entry: String, fragment_entry: String, var vertex_layouts: List[VertexLayout], var color_targets: List[ColorTarget], depth: DepthState = DepthState.none(), topology: WGPUPrimitiveTopology = WGPUPrimitiveTopology_TriangleList, cull_mode: WGPUCullMode = WGPUCullMode_None, sample_count: UInt32 = 1, wireframe: Bool = False, front_face_cw: Bool = False, )
def create_bind_group_layout #
def create_bind_group_layout( mut res: Resources, label: String, entries: List[LayoutEntry] ) raises -> BindGroupLayoutHandleCreates a WGPUBindGroupLayout from entries and adopts it into res. Each entry becomes a buffer, sampler, texture or storage-texture layout according to its BindingKind; a kind not handled here leaves every binding type unused. Raises if wgpu returns NULL; other validation errors surface through Gfx.pump diagnostics. The caller destroys the handle with Resources.destroy_bind_group_layout.
def create_pipeline_layout #
def create_pipeline_layout( mut res: Resources, label: String, layouts: List[BindGroupLayoutHandle] ) raises -> PipelineLayoutHandleCreates a WGPUPipelineLayout whose bind group layouts are in group order and adopts it. Raises on an invalid layout handle or a NULL result. The caller destroys the handle with Resources.destroy_pipeline_layout.
def create_bind_group #
def create_bind_group( mut res: Resources, label: String, layout: BindGroupLayoutHandle, bindings: List[BindingResource], ) raises -> BindGroupHandleCreates a WGPUBindGroup for layout from bindings and adopts it into res. The raw wgpu objects behind the handles are captured at creation time; replacing them behind the same handle later does not update this bind group. Raises on any invalid handle or a NULL result; mismatches with the layout surface through Gfx.pump diagnostics. The caller destroys the handle with Resources.destroy_bind_group.
def build_render_pipeline #
def build_render_pipeline( res: Resources, desc: RenderPipelineDesc ) raises -> WGPURenderPipelineCreates the raw pipeline object (used by create_render_pipeline and by hot reload). Raises on an invalid handle, a NULL result, or a validation error drained right after creation; the invalid object is then released and the error carries wgpu's validation message. The caller owns the returned object.
def create_render_pipeline #
def create_render_pipeline( mut res: Resources, desc: RenderPipelineDesc ) raises -> RenderPipelineHandleBuilds a render pipeline with build_render_pipeline and adopts it into res. Raises if creation fails, including validation errors drained right after creation. The caller destroys the handle with Resources.destroy_render_pipeline.
def build_compute_pipeline #
def build_compute_pipeline( res: Resources, label: String, layout: PipelineLayoutHandle, shader: ShaderHandle, entry: String, ) raises -> WGPUComputePipelineCreates the raw compute pipeline object, adopted by create_compute_pipeline or passed to Resources.replace_compute_pipeline to swap it behind an existing handle. A null layout handle passes a null pipeline layout to wgpu. Raises on an invalid handle, a NULL result, or a validation error drained right after creation; the invalid object is then released and the error carries wgpu's validation message. The caller owns the returned object.
def create_compute_pipeline #
def create_compute_pipeline( mut res: Resources, label: String, layout: PipelineLayoutHandle, shader: ShaderHandle, entry: String, ) raises -> ComputePipelineHandleBuilds a compute pipeline with build_compute_pipeline and adopts it into res. The caller destroys the handle with Resources.destroy_compute_pipeline.
cinder.gfx.resources #
Source: cinder/gfx/resources.mojo
Typed GPU resources: one handle type per kind, pooled records, ownership and leak tracking. Every resource created through Resources is tracked in a generational pool for its kind, so a BufferHandle cannot be passed where a TextureHandle is expected (compile error), stale handles fail validation (raise), and live_counts() reports exactly what is still alive. Check live_counts().total() == 0 before teardown to assert a clean shutdown. __deinit__ releases everything left and, when anything was left, appends one gfx.resources warning LogRecord with those counts to Gfx.diagnostics (read it with Gfx.take_diagnostics). Ownership rules: a pool owns every object it holds except views wrapped by import_texture_view, which are only dropped (forget_texture_view), never released. A texture cannot be destroyed while views created from it are alive (destroy_texture raises). adopt_* and create_* take ownership even when they raise: the new object is released if it cannot be stored.
comptime NoChain = Optional[Pointer[WGPUChainedStruct, MutUntrackedOrigin]]— NullnextInChainfor wgpu descriptors that carry no chained extension struct.
struct BufferTag #
struct BufferTagPhantom tag that makes BufferHandle a distinct type.
Fields:
struct TextureTag #
struct TextureTagPhantom tag that makes TextureHandle a distinct type.
Fields:
struct TextureViewTag #
struct TextureViewTagPhantom tag that makes TextureViewHandle a distinct type.
Fields:
struct SamplerTag #
struct SamplerTagPhantom tag that makes SamplerHandle a distinct type.
Fields:
struct ShaderTag #
struct ShaderTagPhantom tag that makes ShaderHandle a distinct type.
Fields:
struct BindGroupLayoutTag #
struct BindGroupLayoutTagPhantom tag that makes BindGroupLayoutHandle a distinct type.
Fields:
struct PipelineLayoutTag #
struct PipelineLayoutTagPhantom tag that makes PipelineLayoutHandle a distinct type.
Fields:
struct BindGroupTag #
struct BindGroupTagPhantom tag that makes BindGroupHandle a distinct type.
Fields:
struct RenderPipelineTag #
struct RenderPipelineTagPhantom tag that makes RenderPipelineHandle a distinct type.
Fields:
struct ComputePipelineTag #
struct ComputePipelineTagPhantom tag that makes ComputePipelineHandle a distinct type.
Fields:
comptime BufferHandle = Handle[BufferTag]— Generational handle to a WGPUBuffer owned byResources.buffers.comptime TextureHandle = Handle[TextureTag]— Generational handle to a WGPUTexture owned byResources.textures.comptime TextureViewHandle = Handle[TextureViewTag]— Generational handle to a WGPUTextureView inResources.texture_views(owned or imported).comptime SamplerHandle = Handle[SamplerTag]— Generational handle to a WGPUSampler owned byResources.samplers.comptime ShaderHandle = Handle[ShaderTag]— Generational handle to a WGPUShaderModule owned byResources.shaders.comptime BindGroupLayoutHandle = Handle[BindGroupLayoutTag]— Generational handle to a WGPUBindGroupLayout owned byResources.bind_group_layouts.comptime PipelineLayoutHandle = Handle[PipelineLayoutTag]— Generational handle to a WGPUPipelineLayout owned byResources.pipeline_layouts.comptime BindGroupHandle = Handle[BindGroupTag]— Generational handle to a WGPUBindGroup owned byResources.bind_groups.comptime RenderPipelineHandle = Handle[RenderPipelineTag]— Generational handle to a WGPURenderPipeline owned byResources.render_pipelines.comptime ComputePipelineHandle = Handle[ComputePipelineTag]— Generational handle to a WGPUComputePipeline owned byResources.compute_pipelines.
struct BufferDesc #
struct BufferDesc(Copyable, Movable)What to create a buffer with. usage is a WGPUBufferUsage bit set.
Fields:
label: Stringsize: UInt64usage: UInt64mapped_at_creation: Bool
struct TextureDesc #
struct TextureDesc(Copyable, Movable)A 2D texture (array layers and 3D arrive with the renderer). usage is WGPUTextureUsage bits.
Fields:
label: Stringwidth: UInt32height: UInt32depth_or_layers: UInt32mip_levels: UInt32sample_count: UInt32format: WGPUTextureFormatusage: UInt64
struct SamplerDesc #
struct SamplerDesc(Copyable, Movable)Filtering and addressing. linear selects trilinear filtering; otherwise nearest.
Fields:
label: Stringlinear: Booladdress_mode: UInt32max_anisotropy: UInt16
struct BufferRecord #
struct BufferRecord(Copyable, Movable)Pool entry for a buffer: the WGPUBuffer plus the size and usage it was created with. Copies handed out by Resources.buffer share the raw object; only the pool releases it.
Fields:
raw: WGPUBuffersize: UInt64usage: UInt64
struct TextureRecord #
struct TextureRecord(Copyable, Movable)Pool entry for a texture: the WGPUTexture plus the extent, mip count, format and usage it was created with. Copies share the raw object; only the pool releases it.
Fields:
raw: WGPUTexturewidth: UInt32height: UInt32depth_or_layers: UInt32mip_levels: UInt32format: WGPUTextureFormatusage: UInt64
struct TextureViewRecord #
struct TextureViewRecord(Copyable, Movable)Pool entry for a view: the WGPUTextureView and the texture it views. texture is null for views wrapped by import_texture_view, whose raw object the caller owns (is_imported).
Fields:
-
raw: WGPUTextureView -
texture: TextureHandle -
is_importedis_imported(self) -> Bool
True for a view wrapped byimport_texture_view:Resourcesnever releases it.
struct SamplerRecord #
struct SamplerRecord(Copyable, Movable)Pool entry for a sampler: the WGPUSampler, released by Resources.destroy_sampler.
Fields:
raw: WGPUSampler
struct ShaderRecord #
struct ShaderRecord(Copyable, Movable)Pool entry for a shader: the WGPUShaderModule and the WGSL path it was compiled from. ShaderManager swaps raw in place on hot reload, keeping the handle stable.
Fields:
raw: WGPUShaderModulesource_path: String
struct BindGroupLayoutRecord #
struct BindGroupLayoutRecord(Copyable, Movable)Pool entry for a bind group layout: the WGPUBindGroupLayout the pool owns.
Fields:
raw: WGPUBindGroupLayout
struct PipelineLayoutRecord #
struct PipelineLayoutRecord(Copyable, Movable)Pool entry for a pipeline layout: the WGPUPipelineLayout the pool owns.
Fields:
raw: WGPUPipelineLayout
struct BindGroupRecord #
struct BindGroupRecord(Copyable, Movable)Pool entry for a bind group: the WGPUBindGroup the pool owns.
Fields:
raw: WGPUBindGroup
struct RenderPipelineRecord #
struct RenderPipelineRecord(Copyable, Movable)Pool entry for a render pipeline: the WGPURenderPipeline the pool owns.
Fields:
raw: WGPURenderPipeline
struct ComputePipelineRecord #
struct ComputePipelineRecord(Copyable, Movable)Pool entry for a compute pipeline: the WGPUComputePipeline the pool owns.
Fields:
raw: WGPUComputePipeline
struct LiveCounts #
struct LiveCounts(ImplicitlyCopyable, Movable, Writable)Resources alive per kind.
Fields:
-
buffers: Int -
textures: Int -
texture_views: Int -
samplers: Int -
shaders: Int -
bind_group_layouts: Int -
pipeline_layouts: Int -
bind_groups: Int -
render_pipelines: Int -
compute_pipelines: Int -
totaltotal(self) -> Int
Sum over every kind; zero means nothing is left to release. -
write_towrite_to(self, mut writer: Some[Writer])
struct Resources #
struct Resources(Movable)Pools of every GPU resource kind, owning the wgpu objects behind typed handles.
Fields:
-
gfx: Pointer[Gfx, MutUntrackedOrigin] -
buffers: Pool[BufferRecord, BufferTag] -
textures: Pool[TextureRecord, TextureTag] -
texture_views: Pool[TextureViewRecord, TextureViewTag] -
samplers: Pool[SamplerRecord, SamplerTag] -
shaders: Pool[ShaderRecord, ShaderTag] -
bind_group_layouts: Pool[BindGroupLayoutRecord, BindGroupLayoutTag] -
pipeline_layouts: Pool[PipelineLayoutRecord, PipelineLayoutTag] -
bind_groups: Pool[BindGroupRecord, BindGroupTag] -
render_pipelines: Pool[RenderPipelineRecord, RenderPipelineTag] -
compute_pipelines: Pool[ComputePipelineRecord, ComputePipelineTag] -
__init____init__( out self, gfx: Pointer[Gfx, MutUntrackedOrigin], capacity: Int = 4096 ) raises -
live_countslive_counts(self) -> LiveCounts
Live handles per pool right now. Imported texture views count until they are forgotten. A non-zerototal()just before teardown is what__deinit__reports as left alive. -
create_buffercreate_buffer(mut self, desc: BufferDesc) raises -> BufferHandle
Creates a GPU buffer. Validation failures surface throughGfx.pumpdiagnostics; a NULL object (out of memory) raises, as does a full buffer pool (the new buffer is then released). -
bufferbuffer(self, h: BufferHandle) raises -> BufferRecord
A copy of the buffer's record; raises on a null, stale or foreign handle. -
destroy_bufferdestroy_buffer(mut self, h: BufferHandle) raises
Removes the handle, then destroys and releases the WGPUBuffer. Raises on an invalid handle, in which case nothing is released. -
write_bufferwrite_buffer( self, h: BufferHandle, offset: UInt64, data: Span[UInt8, _] ) raises
Uploadsdatathrough the queue (copied immediately; no mapping). -
write_texturewrite_texture( self, h: TextureHandle, mip_level: UInt32, width: UInt32, height: UInt32, layer: UInt32, data: Span[UInt8, _], bytes_per_row: UInt32, rows_per_image: UInt32 = 0, ) raises
Uploads one mip level of one array layer through the queue (copied immediately).rows_per_imageis the number of rows indata; it defaults toheightand must be the block-row count for block-compressed formats. -
create_texturecreate_texture(mut self, desc: TextureDesc) raises -> TextureHandle
Creates a 2D WGPUTexture (depth_or_layersarray layers) and returns its handle. Validation failures surface throughGfx.pumpdiagnostics; a NULL object raises, as does a full texture pool (the new texture is then released). -
texturetexture(self, h: TextureHandle) raises -> TextureRecord
A copy of the texture's record; raises on a null, stale or foreign handle. -
texture_view_counttexture_view_count(self, h: TextureHandle) raises -> Int
How many live views created throughResourcesview this texture; raises on an invalid handle. -
destroy_texturedestroy_texture(mut self, h: TextureHandle) raises
Removes the handle, then destroys and releases the WGPUTexture. Raises, releasing nothing, on an invalid handle or while views created from the texture are still alive: destroy those views first (destroy_texture_view), so no live view handle is left pointing at a destroyed texture. -
create_texture_view_excreate_texture_view_ex( mut self, texture: TextureHandle, dimension: WGPUTextureViewDimension, base_mip: UInt32, mip_count: UInt32, base_layer: UInt32, layer_count: UInt32, ) raises -> TextureViewHandle
A view of a mip range and layer range with an explicit dimension (2D array, cube, one layer of an array as 2D, one mip as a storage target). -
create_texture_viewcreate_texture_view( mut self, texture: TextureHandle ) raises -> TextureViewHandle
A view of the whole texture with its own format and dimension. -
import_texture_viewimport_texture_view( mut self, raw: WGPUTextureView ) raises -> TextureViewHandle
Wraps a view the caller owns (a swapchain frame) so renderers can target it. Drop it withforget_texture_view; the raw view is never released here, not even at teardown, anddestroy_texture_viewrefuses it. -
forget_texture_viewforget_texture_view(mut self, h: TextureViewHandle) raises
Drops an imported view without releasing the wgpu object. Raises, dropping nothing, on an invalid handle or on a view created byResources(that one must be released withdestroy_texture_view, or it would leak). -
texture_viewtexture_view(self, h: TextureViewHandle) raises -> TextureViewRecord
A copy of the view's record; raises on a null, stale or foreign handle. -
destroy_texture_viewdestroy_texture_view(mut self, h: TextureViewHandle) raises
Removes the handle and releases the WGPUTextureView. Raises, releasing nothing, on an invalid handle or on an imported view (the caller owns that one; drop it withforget_texture_view). -
create_samplercreate_sampler(mut self, desc: SamplerDesc) raises -> SamplerHandle
Creates a sampler with the same address mode on u, v and w and LOD clamp 0..32.linearpicks linear min/mag/mip filtering, otherwise nearest. A NULL object raises; invalid settings surface as validation diagnostics throughGfx.pump. -
create_comparison_samplercreate_comparison_sampler( mut self, label: String ) raises -> SamplerHandle
Linear PCF sampler: clamp to edge, compare GreaterEqual (reverse-Z shadow maps). -
samplersampler(self, h: SamplerHandle) raises -> SamplerRecord
A copy of the sampler's record; raises on a null, stale or foreign handle. -
destroy_samplerdestroy_sampler(mut self, h: SamplerHandle) raises
Removes the handle and releases the WGPUSampler; raises on an invalid handle. -
adopt_shaderadopt_shader( mut self, raw: WGPUShaderModule, source_path: String ) raises -> ShaderHandle
Takes ownership of a compiled module (fromShaderManager) and returns its handle. Raises on a null module. Ownership passes even when this raises: if the pool is full the module is released before the error propagates. -
shadershader(self, h: ShaderHandle) raises -> ShaderRecord
A copy of the shader's record; raises on a null, stale or foreign handle. -
destroy_shaderdestroy_shader(mut self, h: ShaderHandle) raises
Removes the handle and releases the WGPUShaderModule. AShaderManagerthat loaded it keeps watching the file; a later change then fails to reload and logs an error. -
adopt_bind_group_layoutadopt_bind_group_layout( mut self, raw: WGPUBindGroupLayout ) raises -> BindGroupLayoutHandle
Takes ownership of a WGPUBindGroupLayout built inpipeline.mojo. Raises on a nullraw; a full pool releasesrawand raises. -
bind_group_layoutbind_group_layout( self, h: BindGroupLayoutHandle ) raises -> BindGroupLayoutRecord
A copy of the layout's record; raises on a null, stale or foreign handle. -
destroy_bind_group_layoutdestroy_bind_group_layout(mut self, h: BindGroupLayoutHandle) raises
Removes the handle and releases the WGPUBindGroupLayout; raises on an invalid handle. -
adopt_pipeline_layoutadopt_pipeline_layout( mut self, raw: WGPUPipelineLayout ) raises -> PipelineLayoutHandle
Takes ownership of a WGPUPipelineLayout built inpipeline.mojo. Raises on a nullraw; a full pool releasesrawand raises. -
pipeline_layoutpipeline_layout( self, h: PipelineLayoutHandle ) raises -> PipelineLayoutRecord
A copy of the layout's record; raises on a null, stale or foreign handle. -
destroy_pipeline_layoutdestroy_pipeline_layout(mut self, h: PipelineLayoutHandle) raises
Removes the handle and releases the WGPUPipelineLayout; raises on an invalid handle. -
adopt_bind_groupadopt_bind_group( mut self, raw: WGPUBindGroup ) raises -> BindGroupHandle
Takes ownership of a WGPUBindGroup built inpipeline.mojo. Raises on a nullraw; a full pool releasesrawand raises. -
bind_groupbind_group(self, h: BindGroupHandle) raises -> BindGroupRecord
A copy of the bind group's record; raises on a null, stale or foreign handle. -
destroy_bind_groupdestroy_bind_group(mut self, h: BindGroupHandle) raises
Removes the handle and releases the WGPUBindGroup; raises on an invalid handle. -
adopt_render_pipelineadopt_render_pipeline( mut self, raw: WGPURenderPipeline ) raises -> RenderPipelineHandle
Takes ownership of a WGPURenderPipeline built inpipeline.mojo. Raises on a nullraw; a full pool releasesrawand raises. -
render_pipelinerender_pipeline( self, h: RenderPipelineHandle ) raises -> RenderPipelineRecord
A copy of the pipeline's record; raises on a null, stale or foreign handle. -
replace_render_pipelinereplace_render_pipeline( mut self, h: RenderPipelineHandle, raw: WGPURenderPipeline ) raises
Swaps the object behind an existing handle (hot reload), releasing the old one. Takes ownership ofrawin every case: on a nullrawor an invalid handle it raises, and a non-nullrawis released first, so a failed hot reload never leaks. -
destroy_render_pipelinedestroy_render_pipeline(mut self, h: RenderPipelineHandle) raises
Removes the handle and releases the WGPURenderPipeline; raises on an invalid handle. -
adopt_compute_pipelineadopt_compute_pipeline( mut self, raw: WGPUComputePipeline ) raises -> ComputePipelineHandle
Takes ownership of a WGPUComputePipeline built inpipeline.mojo. Raises on a nullraw; a full pool releasesrawand raises. -
compute_pipelinecompute_pipeline( self, h: ComputePipelineHandle ) raises -> ComputePipelineRecord
A copy of the pipeline's record; raises on a null, stale or foreign handle. -
replace_compute_pipelinereplace_compute_pipeline( mut self, h: ComputePipelineHandle, raw: WGPUComputePipeline ) raises
Swaps the object behind an existing handle (hot reload), releasing the old one. Takes ownership ofrawin every case: on a nullrawor an invalid handle it raises, and a non-nullrawis released first, so a failed hot reload never leaks. -
destroy_compute_pipelinedestroy_compute_pipeline(mut self, h: ComputePipelineHandle) raises
Removes the handle and releases the WGPUComputePipeline; raises on an invalid handle.
cinder.gfx.shaders #
Source: cinder/gfx/shaders.mojo
ShaderManager: WGSL modules from files, compile diagnostics with file:line:column, hot reload. Every loaded shader remembers its path and modification time. check_for_changes recompiles files that changed on disk; a successful recompile swaps the module behind the same ShaderHandle and reports the handle so pipeline owners rebuild, a failed one keeps the last good module and reports the error. Compile messages come from wgpu's async compilation-info callback through the shim queue.
comptime NoChain = Optional[Pointer[WGPUChainedStruct, MutUntrackedOrigin]]— NullnextInChainfor wgpu descriptors that carry no chained extension struct.
struct ShaderMessage #
struct ShaderMessage(Copyable, Movable, Writable)One compiler diagnostic, already formatted with its source location.
Fields:
-
path: String -
line: Int -
column: Int -
is_error: Bool -
text: String -
write_towrite_to(self, mut writer: Some[Writer])
struct ShaderError #
struct ShaderError(Copyable, Movable, Writable)Raised when a WGSL file fails to compile. messages holds every diagnostic.
Fields:
-
path: String -
messages: List[ShaderMessage] -
write_towrite_to(self, mut writer: Some[Writer])
struct ShaderSource #
struct ShaderSource(Copyable, Movable)A loaded shader file and its on-disk state.
Fields:
handle: ShaderHandlepath: Stringmtime_ns: Intreload_failures: Int
struct ReloadResult #
struct ReloadResult(Copyable, Movable)Outcome of check_for_changes for one changed file.
Fields:
handle: ShaderHandlepath: Stringsuccess: Bool
def parse_wgsl_report #
def parse_wgsl_report(path: String, report: String) -> List[ShaderMessage]Turns a naga validation report into messages with locations. naga marks each location as wgsl:LINE:COLUMN; every such mark becomes one error message carrying the whole report text. A report with no mark yields one message at line 0.
struct ShaderManager #
struct ShaderManager(Movable)Owns the list of shader files; the modules themselves live in Resources.
Fields:
-
gfx: Pointer[Gfx, MutUntrackedOrigin] -
resources: Pointer[Resources, MutUntrackedOrigin] -
sources: List[ShaderSource] -
diagnostics: List[LogRecord] -
__init____init__( out self, gfx: Pointer[Gfx, MutUntrackedOrigin], resources: Pointer[Resources, MutUntrackedOrigin], ) -
compile_sourcecompile_source( mut self, path: String, source: String ) raises -> WGPUShaderModule
Compiles WGSL text and returns the module, or raises ShaderError with every diagnostic. wgpu-native 29 does not implement the compilation-info callback, so the module is created inside a validation error scope; naga's report (which nameswgsl:line:columnlocations) is popped through the shim queue and parsed intoShaderMessages. -
loadload(mut self, path: String) raises -> ShaderHandle
Loads and compiles a WGSL file, registering it for hot reload. -
check_for_changescheck_for_changes(mut self) -> List[ReloadResult]
Recompiles every registered file whose modification time changed. On success the module behind the handle is replaced (old one released); on failure the last good module stays and an error diagnostic with file:line:column is recorded. -
take_diagnosticstake_diagnostics(mut self) -> List[LogRecord]
Returns and clears the reload LogRecords fromcheck_for_changes(info on a successful reload, error with the reason when the last good module was kept).
cinder.gfx.swapchain #
Source: cinder/gfx/swapchain.mojo
Swapchain: surface configuration, per-frame texture acquisition and presentation. Handles the three real-world cases a frame loop meets: resize (reconfigure on the next acquire), minimise (zero-sized window; frames are skipped until it is restored) and surface loss/outdated (reconfigure and retry once, then report). Device loss is Gfx.lost and is the caller's decision.
comptime NoChain = Optional[Pointer[WGPUChainedStruct, MutUntrackedOrigin]]— NullnextInChainfor wgpu descriptors that carry no chained extension struct.
struct SurfaceFrame #
struct SurfaceFrame(Movable)The acquired swapchain texture for one frame. present consumes it.
Fields:
texture: WGPUTextureview: WGPUTextureViewsuboptimal: Boolwidth: UInt32height: UInt32
struct Swapchain #
struct Swapchain(Movable)Owns the configuration of a wgpu surface created by Window.create_surface.
Fields:
-
gfx: Pointer[Gfx, MutUntrackedOrigin] -
surface: WGPUSurface -
format: WGPUTextureFormat -
usage: WGPUTextureUsage -
width: UInt32 -
height: UInt32 -
present_mode: WGPUPresentMode -
configured: Bool -
needs_reconfigure: Bool -
frames_skipped: Int — Frames skipped because the window had no area (minimised). -
reconfigures: Int — Reconfigurations performed (resize, outdated or lost surfaces). -
__init____init__( out self, gfx: Pointer[Gfx, MutUntrackedOrigin], surface: WGPUSurface, width: Int, height: Int, prefer_srgb: Bool = True, readback: Bool = False, ) raises GfxError
Picks a surface format (8-bit BGRA/RGBA, sRGB whenprefer_srgb) and configures. -
resizeresize(mut self, width: Int, height: Int)
Records a new size; the surface is reconfigured on the nextacquire. -
acquireacquire(mut self) raises GfxError -> Optional[SurfaceFrame]
Returns the frame's texture, or None when the window is minimised. Outdated and lost surfaces are reconfigured and retried once; a second failure raises. -
presentpresent(self, var frame: SurfaceFrame)
Presents the acquired frame and releases its view and texture. -
discarddiscard(self, var frame: SurfaceFrame)
Releases an acquired frame without presenting (used when a frame is abandoned).
cinder.gfx.util #
Source: cinder/gfx/util.mojo
Small conversions shared by the gfx modules.
def string_view #
def string_view(ref text: String) -> WGPUStringViewA non-owning WGPUStringView over text. text must outlive every use of the view.
def empty_string_view #
def empty_string_view() -> WGPUStringViewA WGPUStringView with a null pointer and zero length, for absent labels and strings.
def c_message #
def c_message(ev: CnEvent) -> StringThe NUL-terminated message of a shim event as a String, decoded as UTF-8 (invalid sequences become U+FFFD). Reads at most the 1000-byte message buffer.
def zero_event #
def zero_event() -> CnEventAn all-zero CnEvent, used as the out-parameter that cn_event_queue_pop fills.
def ptr_to #
def ptr_to[ T: AnyType ](ref value: T) -> Optional[Pointer[T, MutUntrackedOrigin]]Raw pointer for a C call. The pointee must stay alive past the call (keep it).
def opaque_to #
def opaque_to[ T: AnyType ](ref value: T) -> Optional[OpaquePointer[MutUntrackedOrigin]]ptr_to for void* parameters.
def handle_from #
def handle_from[ T: AnyType ](address: UInt64) -> Optional[Pointer[T, MutUntrackedOrigin]]Rebuilds a wgpu object handle delivered through a CnEvent.