Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/buffer/bufferShorthand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class TgpuBufferShorthandImpl<
}

$name(label: string): this {
setName(this[$getNameForward], label);
setName(this, label);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/buffer/bufferUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class TgpuFixedBufferImpl<
}

$name(label: string) {
this.buffer.$name(label);
setName(this, label);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/tgpuComputeFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function createComputeFn<ComputeIn extends IORecord<AnyComputeBuiltin>>(
[$internal]: true,
[$getNameForward]: core,
$name(newLabel: string): This {
setName(core, newLabel);
setName(this, newLabel);
if (isNamable(inputType)) {
inputType.$name(`${newLabel}_Input`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/typegpu/src/core/function/tgpuFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function createFn<ImplSchema extends AnyFn>(

[$getNameForward]: core,
$name(label: string): This {
setName(core, label);
setName(this, label);
return this;
},

Expand Down Expand Up @@ -283,7 +283,7 @@ function createBoundFunction<ImplSchema extends AnyFn>(

[$getNameForward]: innerFn,
$name(label: string): This {
innerFn.$name(label);
setName(this, label);
return this;
},

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/tgpuFragmentFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function createFragmentFn(
[$internal]: true,
[$getNameForward]: core,
$name(newLabel: string): This {
setName(core, newLabel);
setName(this, newLabel);
if (isNamable(outputType)) {
outputType.$name(`${newLabel}_Output`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/tgpuVertexFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function createVertexFn(
[$internal]: true,
[$getNameForward]: core,
$name(newLabel: string): This {
setName(core, newLabel);
setName(this, newLabel);
if (isNamable(inputType)) {
inputType.$name(`${newLabel}_Input`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/pipeline/computePipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class TgpuComputePipelineImpl implements TgpuComputePipeline {
}

$name(label: string): this {
setName(this._core, label);
setName(this, label);
return this;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/pipeline/renderPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class TgpuRenderPipelineImpl implements TgpuRenderPipeline {
}

$name(label: string): this {
setName(this[$internal].core, label);
setName(this, label);
return this;
}

Expand Down
20 changes: 16 additions & 4 deletions packages/typegpu/src/core/root/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { WeakMemo } from '../../memo.ts';
import { clearTextureUtilsCache } from '../texture/textureUtils.ts';
import type { Infer } from '../../shared/repr.ts';
import { $internal } from '../../shared/symbols.ts';
import { $getNameForward, $internal } from '../../shared/symbols.ts';
import type { AnyVertexAttribs } from '../../shared/vertexFormat.ts';
import type {
ExtractBindGroupInputFromLayout,
Expand Down Expand Up @@ -120,6 +120,7 @@ import { vec3f, vec3u } from '../../data/vector.ts';
import { u32 } from '../../data/numeric.ts';
import { ceil } from '../../std/numeric.ts';
import { allEq } from '../../std/boolean.ts';
import { setName } from '../../shared/meta.ts';

/**
* Changes the given array to a vec of 3 numbers, filling missing values with 1.
Expand Down Expand Up @@ -194,6 +195,15 @@ export class TgpuGuardedComputePipelineImpl<TArgs extends number[]>
get sizeUniform() {
return this.#sizeUniform;
}

[$internal] = true;
get [$getNameForward]() {
return this.#pipeline;
}
$name(label: string): this {
setName(this, label);
return this;
}
}

class WithBindingImpl implements WithBinding {
Expand Down Expand Up @@ -253,9 +263,11 @@ class WithBindingImpl implements WithBinding {
wrappedCallback(in.id.x, in.id.y, in.id.z);
}`.$uses({ sizeUniform, wrappedCallback });

const pipeline = this
.withCompute(mainCompute)
.createPipeline();
// NOTE: in certain setups, unplugin can run on package typegpu, so we have to avoid auto-naming triggering here
const pipeline = (() =>
this
.withCompute(mainCompute)
.createPipeline())();

return new TgpuGuardedComputePipelineImpl(
root,
Expand Down
4 changes: 3 additions & 1 deletion packages/typegpu/src/core/root/rootTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ import type { LayoutToAllowedAttribs } from '../vertexLayout/vertexAttribute.ts'
import type { TgpuVertexLayout } from '../vertexLayout/vertexLayout.ts';
import type { TgpuComputeFn } from './../function/tgpuComputeFn.ts';
import type { WgslStorageTexture, WgslTexture } from '../../data/texture.ts';
import type { TgpuNamable } from '../../shared/meta.ts';

// ----------
// Public API
// ----------

export interface TgpuGuardedComputePipeline<TArgs extends number[] = number[]> {
export interface TgpuGuardedComputePipeline<TArgs extends number[] = number[]>
extends TgpuNamable {
/**
* Returns a pipeline wrapper with the specified bind group bound.
* Analogous to `TgpuComputePipeline.with(bindGroup)`.
Expand Down
4 changes: 2 additions & 2 deletions packages/typegpu/src/core/slot/accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { schemaCallWrapper } from '../../data/schemaCallWrapper.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import type { AnyWgslData } from '../../data/wgslTypes.ts';
import { getResolutionCtx, inCodegenMode } from '../../execMode.ts';
import { getName } from '../../shared/meta.ts';
import { getName, setName } from '../../shared/meta.ts';
import type { Infer, InferGPU } from '../../shared/repr.ts';
import {
$getNameForward,
Expand Down Expand Up @@ -109,7 +109,7 @@ export class TgpuAccessorImpl<T extends AnyWgslData>
}

$name(label: string) {
this.slot.$name(label);
setName(this, label);
return this;
}

Expand Down
11 changes: 9 additions & 2 deletions packages/typegpu/src/core/texture/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export interface TgpuTextureView<
TSchema extends WgslStorageTexture | WgslTexture =
| WgslStorageTexture
| WgslTexture,
> {
> extends TgpuNamable {
readonly [$internal]: TextureViewInternals;
readonly resourceType: 'texture-view';
readonly schema: TSchema;
Expand Down Expand Up @@ -738,13 +738,20 @@ export class TgpuLaidOutTextureViewImpl<
}

throw new Error(
'Direct access to texture views values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead',
`Accessed view '${
getName(this) ?? '<unnamed>'
}' outside of codegen mode. Direct access to texture views values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead`,
);
}

get value(): Infer<T> {
return this.$;
}

$name(label: string): this {
setName(this, label);
return this;
}
}

export class TgpuTextureRenderViewImpl implements TgpuTextureRenderView {
Expand Down
2 changes: 2 additions & 0 deletions packages/typegpu/src/nameRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ const bannedTokens = new Set([
'yield',
// Keywords that should be reserved
'sampler',
'uniform',
'storage',
]);

const builtins = new Set([
Expand Down
5 changes: 2 additions & 3 deletions packages/typegpu/src/shared/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ export function setName(definition: object, name: string): void {
}

/**
* Can be assigned a name. Not to be confused with
* being able to HAVE a name.
* Can be assigned a name. Not to be confused with just having a name.
* The `$name` function should use `setName` to rename the object itself,
* or rename the object `$getNameForward` symbol points to instead if applicable.
* even if `$getNameForward` symbol is present.
*/
export interface TgpuNamable {
$name(label: string): this;
Expand Down
4 changes: 4 additions & 0 deletions packages/typegpu/src/shared/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const $internal = Symbol(`typegpu:${version}:$internal`);
* The getter to the value of this resource, accessible on the GPU
*/
export const $gpuValueOf = Symbol(`typegpu:${version}:$gpuValueOf`);
/**
* If this symbol is present, this means that getName and setName
* will refer to object behind this property instead.
*/
export const $getNameForward = Symbol(`typegpu:${version}:$getNameForward`);
/**
* Marks an object with slot-value bindings
Expand Down
4 changes: 2 additions & 2 deletions packages/typegpu/tests/examples/individual/gravity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('gravity example', () => {
return skyBoxVertex_Output((camera.projection * vec4f(viewPos, 1f)), input.position.xyz);
}
@group(0) @binding(1) var item: texture_cube<f32>;
@group(0) @binding(1) var skyBox: texture_cube<f32>;
@group(0) @binding(2) var sampler_1: sampler;
Expand All @@ -209,7 +209,7 @@ describe('gravity example', () => {
}
@fragment fn skyBoxFragment(input: skyBoxFragment_Input) -> @location(0) vec4f {
return textureSample(item, sampler_1, normalize(input.texCoord));
return textureSample(skyBox, sampler_1, normalize(input.texCoord));
}
struct CelestialBody {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('jelly-slider example', () => {
projInv: mat4x4f,
}

@group(0) @binding(1) var<uniform> cameraUniform: Camera;
@group(0) @binding(1) var<uniform> uniform_1: Camera;

struct Ray {
origin: vec3f,
Expand All @@ -95,8 +95,8 @@ describe('jelly-slider example', () => {

fn getRay(ndc: vec2f) -> Ray {
var clipPos = vec4f(ndc.x, ndc.y, -1f, 1f);
let invView = (&cameraUniform.viewInv);
let invProj = (&cameraUniform.projInv);
let invView = (&uniform_1.viewInv);
let invProj = (&uniform_1.projInv);
var viewPos = ((*invProj) * clipPos);
var viewPosNormalized = vec4f((viewPos.xyz / viewPos.w), 1f);
var worldPos = ((*invView) * viewPosNormalized);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('jelly switch example', () => {
projInv: mat4x4f,
}

@group(0) @binding(1) var<uniform> cameraUniform: Camera;
@group(0) @binding(1) var<uniform> uniform_1: Camera;

struct Ray {
origin: vec3f,
Expand All @@ -69,8 +69,8 @@ describe('jelly switch example', () => {

fn getRay(ndc: vec2f) -> Ray {
var clipPos = vec4f(ndc.x, ndc.y, -1f, 1f);
let invView = (&cameraUniform.viewInv);
let invProj = (&cameraUniform.projInv);
let invView = (&uniform_1.viewInv);
let invProj = (&uniform_1.projInv);
var viewPos = ((*invProj) * clipPos);
var viewPosNormalized = vec4f((viewPos.xyz / viewPos.w), 1f);
var worldPos = ((*invView) * viewPosNormalized);
Expand Down
Loading
Loading