Closed iwoplaza closed 4 days ago
The tgpu.resolve function generates a WGSL code string that is representative of all inputs (+ extra dependencies).
tgpu.resolve
Expected signature:
function resolve( input: string | TgpuResolvable | (string | TgpuResolvable)[], extraDependencies?: Record<string, TgpuResolvable> ): string;
const Gradient = struct({ from: vec3f, to: vec3f, }); const foo0 = tgpu.resolve('fn foo() { var v: Gradient; }', { Gradient }); console.log(foo0); // struct Gradient_1 { from: vec3f, to: vec3f, } fn foo() { var v: Gradient_1; }
const { intensity } = tgpu .bindGroupLayout({ intensity: { uniform: f32 }, }).bound; const vertex = tgpu .vertexFn({}, {}) .does(() => { const v = intensity.value; }); const fragment = tgpu .fragmentFn({}, vec4f) .does(() => vec4f(intensity.value, 0, 0, 1)); // Deduplicates dependencies const foo0 = tgpu.resolve([vertex, fragment]); console.log(foo0); // @group(0) @binding(0) var<uniform> intensity_1: f32; // // @vertex // fn vertex_main() { // let v = intensity_1; // } // // @fragment // fn fragment_main() { // return vec4f(intensity_1, 0.0, 0.0, 1.0); // }
The
tgpu.resolve
function generates a WGSL code string that is representative of all inputs (+ extra dependencies).Expected signature:
Example uses
Adding dependencies to a plain code string.
Resolving two entry functions to get one shader code string