When using TypeGPU for resolution, there is no need to ever define either var<uniform> or var<storage[, address_space]>, as such definitions are added automatically.
For example, in the code snippet below, the external counter is automatically included as a @group(0) @binding(0) var<storage, read_write> counter: vec3f.
In this case, the group and index match the automatically generated “catchall” bind group, used for fixed, “bindless” resources.
A schema that represents a 32-bit float value. (equivalent to f32 in WGSL)
Can also be called to cast a value to an f32.
@exampleconst value = f32(); // 0
@exampleconst value = f32(1.23); // 1.23
@exampleconst value = f32(true); // 1
f32(
input: {
num: d.v3u;
}
input.
num: d.v3u
num.
v3u.x: number
x);
});
const
const pipeline:TgpuComputePipeline
pipeline =
const root:TgpuRoot
root['~unstable'].
withCompute<{
num:d.BuiltinNumWorkgroups;
}>(entryFn:TgpuComputeFn<{
num:d.BuiltinNumWorkgroups;
}>):WithCompute
withCompute(
const increment:TgpuComputeFn<{
num:d.BuiltinNumWorkgroups;
}>
increment).
WithCompute.createPipeline(): TgpuComputePipeline
createPipeline();
var console:Console
The console module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
A global console instance configured to write to process.stdout and
process.stderr. The global console can be used without importing the node:console module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O for
more information.
Example using the global console:
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(newError('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console class:
const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = newconsole.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(newError('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
Prints to stdout with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()).
Resolves a template with external values. Each external will get resolved to a code string and replaced in the template.
Any dependencies of the externals will also be resolved and included in the output.
@param ― options - The options for the resolution.
The meaning of const differs between JS and WGSL.
In JS, a const is a reference that cannot be reassigned, while in WGSL, it means a value known at shader-creation time.
Therefore, to use the WGSL const, TypeGPU provides tgpu.const(), an interface analogous to tgpu.privateVar() and tgpu.workgroupVar(), with the only difference being that the previously optional init value is now required.
const
const Boid: d.WgslStruct<{
pos:d.Vec3f;
vel:d.Vec3u;
}>
Boid =
import d
d.
struct<{
pos:d.Vec3f;
vel:d.Vec3u;
}>(props: {
pos: d.Vec3f;
vel: d.Vec3u;
}): d.WgslStruct<{
pos:d.Vec3f;
vel:d.Vec3u;
}>
export struct
Creates a struct schema that can be used to construct GPU buffers.
Ensures proper alignment and padding of properties (as opposed to a d.unstruct schema).
The order of members matches the passed in properties object.