emitFragment
On this page

emitFragment()

Function in Emit

Emit a ModuleDecl as a WGSL fragment for a host that assembles the final module itself: the declarations and helper functions without the enable directive header and, unless opts.entryPoints is true, without the stage entry points.

import { emitFragment } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

const emitFragment: (
m: ModuleDecl,
opts?: EmitOptions & { entryPoints?: boolean; },
) => EmitFragment

Parameters

m ModuleDecl
optsoptional EmitOptions & { entryPoints?: boolean }

Return value

EmitFragment

Description

Where GLSL would use #include, a WGSL host composes by concatenating fragments, so the directives it must place at the top of the module come back in the result’s preamble field, and what the fragment declares and requires comes back alongside (see EmitFragment).

Prefer this over concatenating emitFuncs and emitConst output. This function runs the same validation and capability check as emitModule, so it never writes a module that validate or the capability check would have rejected.

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

Writes WGSL for WebGPU.

GLSL ES 3.00 (WebGL2) Does not apply
CPU oracle Does not apply

In the guide

See also

Source

src/core/backends/wgsl.ts, line 586, at commit 26de7be8

Edit this page Report a problem