Rule 6.6
On this page

Rule 6.6

Chapter 6, Declarations and resources Test

An entry point’s inputs and outputs are explicit parameters and return values. A built-in value carries builtin<N>, whose type WGSL gives (builtin<"clip_distances", array<f32, N>> writes its type); every other input or output is user-defined, and the compiler gives it its location, which location<n, T> may state. The builtin name must be one WGSL defines for that stage and direction (change 0111, D2; change 0135). Each attribute type means its value type: pos: builtin<"position"> is a vec4 to the compiler and to the editor, the type WGSL gives position, and uv: location<0, vec2> is a vec2. A written type that WGSL fixes, builtin<"vertex_index", u32>, is the migration form: it must compile with a TS8028 warning that names builtin<"vertex_index"> and tshc migrate in the release that ships change 0135, and the release after it refuses the written type (decision D1.2); a written type that is not WGSL’s is TS8003. builtin<"clip_distances">, the one name whose type the author chooses, is TS8003. The other attributes of an input or an output are an object type of options. On a built-in value the options are the second argument, builtin<"position", { invariant: true }> (D1.3). On a user-defined value they are the third argument of location<n, T, O>, so a value that states an option writes its location: location<1, u32, { interpolate: "flat" }>, location<0, vec4, { blend_src: 1 }> (change 0111, D7; change 0135, D2.3). A written n is always the location. Where a user-defined value stands decides what it is and the location the compiler gives it when none is written (change 0135, D2.1):

Where the value standsWhat it isIts location when none is written
A vertex entry’s parameter, or a field of oneA vertex attributeThe lowest number no written location of that entry holds, in declaration order (the order Rule 6.8 packs the buffer in)
A field of a struct that a vertex entry returnsA value between stagesThe lowest number no written location of that struct holds, in declaration order. The scope is the struct, so a struct has one set of locations wherever it is used
A fragment entry’s input (a field of a struct no vertex entry returns, or a bare parameter)A value between stagesThe location the field of the same name has in the vertex results of the program. Refused (TS8010) when no vertex result has the name, or two give it different locations
A fragment entry’s result, or a field of itA render targetThe lowest number no written location of that entry holds, in declaration order; a bare result is location 0
A compute entry’s parameter, or a field of oneRefusedNone: TS8029, since a compute entry has no user-defined input

A fragment input that is a field of the struct a vertex entry returns has that struct’s locations. A value between stages is linked by its name, as GLSL ES 3.00 links a varying. In the mixed case each struct keeps its written numbers: with interface A { pos: builtin<"position">; uv: location<0, vec2>; n: vec3 } and interface B { pos: builtin<"position">; n: location<0, vec3> }, A.n is 1, the lowest number no written field of A holds, and B.n stays 0, as written. If B is a fragment input and writes no number on n, B.n takes the location n has in the vertex results; with A the only one, that is 1. An entry I/O struct may be a class, an interface or a type (Rule 6.9), and a field of one writes its attribute in its type where it writes one (a user-defined input or output may leave its location to the compiler), and needs no initializer and no !; a written ! is accepted and changes nothing, and the language service sets strictPropertyInitialization: false in the TypeShade program, since an entry I/O field is filled by the stage that produces it, not by an initializer. No attribute decorator is written on an entry’s parameter or on a field of an entry I/O struct: @builtin("...") or @location(n) there stays accepted with a TS8028 warning until the release that refuses it (change 0111, D5), and the language service hides TypeScript’s TS1206 on it only while compile() warns. A parameter qualifier on a function of the file is no entry I/O attribute (Rule 8.25).

The rule text and the parts under it are the compiler's own English, as the design document writes them.

Rationale

an implicit stage input hides a dependency, and the input stays an explicit parameter or field. WGSL refuses an entry I/O member with no attribute, and the emitted WGSL keeps an explicit attribute on each one: that requirement binds the emitted module and not the TypeShade source (OD-1, Rule 1.1). The compiler knows the type of a built-in value and can count a location, so the author writes neither (OD-3). An input or an output is a value that flows in or out, so its attribute, when it is written, is part of its type (Rule 1.8, OD-5).

Derives from

  • Shader Interface;
  • Inter-stage Input and Output Interface, whose definition of a stage input reads “each datum is either a built-in input value, or a user-defined input”;
  • its subsection Input-output Locations, which carries the two requirements (“each user-defined input and output must have an explicitly specified IO location”; “each structure member in the entry point IO must be one of either a built-in value, or assigned a location”, each a shader-creation error);
  • builtin and location;
  • change 0111 in changes/ (D2, D7); change 0130; change 0135 (D1.2, D2.1); change 0137;
  • surface §3.

How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

  • src/compiler/ts/attribute-types.ts, which reads each attribute type as the decorators it stands for, so every check below reads both forms; pinned by src/compiler/ts/attribute-types.test.ts (a class, an interface and a type give the decorated form’s WGSL and GLSL ES 3.00, and the editor reports nothing) and the language-service check that reports no TS1206 and no TS2564 on any example (src/language-service/new-entry-forms.test.ts);
  • TS8024 BUILTIN_NAME and TS8025 BUILTIN_STAGE for the builtin name and its stage;
  • src/compiler/ts/type-map.ts, which reads builtin<N> as the type WGSL_BUILTIN_TYPES gives N, and the ambient builtin type, whose default is generated from the same table (Rule 12.7); src/compiler/ts/builtin-type-form.ts for the TS8028 warning on a written type that WGSL fixes ("vertex_index" has the type WGSL gives it, u32: write builtin<"vertex_index">, or run "tshc migrate".), the TS8003 of builtin<"clip_distances"> (Builtin "clip_distances" has no single type: write builtin<"clip_distances", array<f32, N>> with N from 1 to 8.) and the one diagnostic of an unknown name that writes no type; pinned in both halves, with the hover, by src/compiler/ts/builtin-type-form.test.ts;
  • src/compiler/ts/entry-locations.ts, which gives each user-defined input and output that writes no location its location by the table above, once every entry is read, in the IR’s field and parameter that a written location fills; a fragment input whose name no vertex result has, or two give different locations, is TS8010 ("FsIn.n" has no location and the vertex results give "n" none: write location<n, T> on it.; … give "n" 1 in "A" and 0 in "C": …); a field that two places of its struct would give two numbers is TS8010 ("S.a" has no location and its uses give it 1 as an input of "v1" and 0 as an input of "v2": write location<n, T> on it.); a user-defined value of a type that cannot cross is TS8003, in the sentence a location<n, bool> has; pinned in both halves by src/compiler/ts/entry-locations.test.ts, which also holds the emit of the short forms to the emit of the written ones byte for byte, an inferred result included (Rule 8.19), and reflect() to the same locations;
  • src/language-service/hover.ts, which shows that location under the type in the editor’s hover, written or given, read off the same IR with the reader reflect() uses (Rule 12.7); pinned beside reflect()’s location on the same source by src/language-service/entry-location-hover.test.ts;
  • TS8029 STRUCT_FIELD_MISSING_ATTR for a user-defined input of a compute entry, a bare parameter or a field of its struct, with a location<…> or with no attribute ("x" is a user-defined input of a compute entry, which has no user IO: a compute shader reads its work from resources and the builtin<…> invocation ids.); measured against Tint with its valid neighbours by the compile gate (Rules 12.6 and 13.3);
  • src/cli/migrate.ts, which rewrites a written type that WGSL fixes to the short form, pinned by src/cli/migrate.test.ts.

The files that verify it at commit af54ddad5, each at the first line that names the rule:

Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

TS8003 TYPE_MISMATCH
Two types that do not fit where they meet (an operator, a condition, a declaration, a return or an argument), a read of an optional value (T | undefined, T | null or T | null | undefined) that no test narrowed (Rule 7.10), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross, an f32 past its range or a builtin call outside its domain, such as Math.pow(-2., 2.).
TS8010 STRUCT_FIELD
An invalid struct field or declaration shape. A class with no fields is accepted; this code covers an invalid field declaration, an empty struct that is not a class, an @align on a field, which is not applied, and a user-defined value whose uses give it two locations (Rule 6.6).
TS8024 BUILTIN_NAME
A @builtin("...") with a malformed name argument, or with an id outside WGSL's builtin vocabulary.
TS8025 BUILTIN_STAGE
A @builtin(...) id used as the input or output of the wrong stage, for example frag_depth on a vertex return or front_facing on a vertex parameter.
TS8028 ATTRIBUTE_NAME
A decorator or an entry form that this surface does not read: an identifier outside the attribute vocabulary (@vertex, @fragment, @compute, @builtin, @location), such as a misspelled @vertx; a WGSL attribute that the surface writes another way or does not borrow, such as a written @diagnostic(…); a stage written as a call, such as vertex(f); an entry that is written in a form that Rule 8.1 refuses, such as export default; or a decorator on a declaration or in a place that takes none (Rule 6.7). Without this code the decorated function or field would silently stop being an entry point or an I/O field.
TS8029 STRUCT_FIELD_MISSING_ATTR
A user-defined input of a compute entry: a parameter, or a field of its struct, that carries no builtin<…>. A compute entry has no user-defined input in WGSL, so the front end refuses it. On a vertex or fragment entry a value with no attribute is user-defined, and the compiler gives it its location (Rule 6.6).

See also

Source

The rule at commit af54ddad5:

Edit this page Report a problem