규칙 6.6
6장, 선언과 리소스 테스트
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 stands | What it is | Its location when none is written |
|---|---|---|
| A vertex entry’s parameter, or a field of one | A vertex attribute | The 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 returns | A value between stages | The 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 stages | The 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 it | A render target | The 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 one | Refused | None: 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).
규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
근거
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).
출처
- 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);
builtinandlocation;- change
0111inchanges/(D2, D7); change0130; change0135(D1.2, D2.1); change0137; - surface §3.
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
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 bysrc/compiler/ts/attribute-types.test.ts(aclass, aninterfaceand atypegive 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_NAMEandTS8025 BUILTIN_STAGEfor the builtin name and its stage;src/compiler/ts/type-map.ts, which readsbuiltin<N>as the typeWGSL_BUILTIN_TYPESgivesN, and the ambientbuiltintype, whose default is generated from the same table (Rule 12.7);src/compiler/ts/builtin-type-form.tsfor theTS8028warning on a written type that WGSL fixes ("vertex_index" has the type WGSL gives it, u32: write builtin<"vertex_index">, or run "tshc migrate".), theTS8003ofbuiltin<"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, bysrc/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, isTS8010("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 isTS8010("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 isTS8003, in the sentence alocation<n, bool>has; pinned in both halves bysrc/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), andreflect()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 readerreflect()uses (Rule 12.7); pinned besidereflect()’s location on the same source bysrc/language-service/entry-location-hover.test.ts;TS8029 STRUCT_FIELD_MISSING_ATTRfor a user-defined input of a compute entry, a bare parameter or a field of its struct, with alocation<…>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 bysrc/cli/migrate.test.ts.
커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
-
src/cli/migrate.test.ts:8 -
src/cli/migrate.ts:3 -
src/compiler/ts/attribute-types.test.ts:1 -
src/compiler/ts/attribute-types.ts:1 -
src/compiler/ts/builtin-type-form.test.ts:1 -
src/compiler/ts/builtin-type-form.ts:1 -
src/compiler/ts/builtin-values.test.ts:1 -
src/compiler/ts/decorated-form.test.ts:1 -
src/compiler/ts/entry-locations.test.ts:1 -
src/compiler/ts/entry-locations.ts:1 -
src/compiler/ts/io-attribute-arguments.test.ts:1 -
src/compiler/ts/io-name-cascades.test.ts:1 -
src/compiler/ts/stage3.test.ts:1 -
src/compiler/ts/type-map.ts:1 -
src/language-service/entry-location-hover-imports-programs.test.ts:1 -
src/language-service/entry-location-hover-imports-refusals.test.ts:1 -
src/language-service/entry-location-hover-imports.test.ts:1 -
src/language-service/entry-location-hover-places.test.ts:1 -
src/language-service/entry-location-hover.test.ts:1 -
src/language-service/hover.ts:1 -
src/language-service/new-entry-forms.test.ts:1
설명하는 절
커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.
적용하는 오류 코드
규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.
-
TS8003TYPE_MISMATCH - 연산자나 조건, 선언, 반환, 인자처럼 두 값이 만나는 자리에서 타입이 서로 맞지 않거나, 검사로 좁히지 않은 선택적 값(
T | undefined,T | null,T | null | undefined)을 읽거나(규칙 7.10), 컴파일러가 접는 상수를 WGSL이 거부합니다. 31을 넘는 시프트 양, 0인 제수, 서로 엇갈린 clamp 경계, 범위를 넘는f32값,Math.pow(-2., 2.)처럼 정의역 밖에서 부르는 내장 함수가 그렇습니다. -
TS8010STRUCT_FIELD - 구조체 필드나 선언의 모양이 잘못되었습니다. 필드가 없는 클래스는 받아들입니다. 이 코드는 잘못된 필드 선언, 클래스가 아닌 빈 구조체, 적용되지 않는 필드의
@align, 사용처마다 location이 둘로 갈리는 사용자 정의 값을 다룹니다(규칙 6.6). -
TS8024BUILTIN_NAME @builtin("...")의 이름 인자가 잘못되었거나, WGSL 내장 어휘에 없는 id입니다.-
TS8025BUILTIN_STAGE @builtin(...)id를 다른 스테이지의 입력이나 출력으로 씁니다. 예를 들어 정점 반환에frag_depth를, 정점 매개변수에front_facing을 씁니다.-
TS8028ATTRIBUTE_NAME - 이 표면이 읽지 않는 데코레이터나 진입점 형태입니다. 속성 어휘(
@vertex,@fragment,@compute,@builtin,@location) 밖의 식별자(@vertx같은 오타), 표면이 다른 방식으로 쓰거나 빌려 오지 않는 WGSL 속성(직접 쓴@diagnostic(…)같은 것),vertex(f)처럼 호출로 쓴 스테이지,export default처럼 규칙 8.1이 거부하는 형태로 쓴 진입점, 데코레이터를 받지 않는 선언이나 자리에 붙은 데코레이터가 그렇습니다(규칙 6.7). 이 코드가 없으면 데코레이터를 붙인 함수나 필드가 아무 말 없이 진입점이나 IO 필드가 아니게 됩니다. -
TS8029STRUCT_FIELD_MISSING_ATTR - compute 진입점의 사용자 정의 입력입니다.
builtin<…>가 없는 매개변수나 그 구조체의 필드가 그렇습니다. WGSL의 compute 진입점에는 사용자 정의 입력이 없으므로 프런트엔드가 거부합니다. 정점이나 프래그먼트 진입점에서는 속성이 없는 값이 사용자 정의 값이고, 컴파일러가 location을 줍니다(규칙 6.6).
함께 보기
소스
커밋 af54ddad5의 규칙 원문:
docs/language-design.md:524(설계 문서)reqs/rules/RULE-0606.md(추적 항목)