규칙 4.8
이 페이지에서

규칙 4.8

4장, 타입 테스트

Every matCxR with C and R in 2, 3, 4 must be a type, and a square one must also answer to matN. A matrix element must be f32, or f64 on a square shape only. A two-row matrix (mat2x2, mat3x2, mat4x2) in a uniform block must be refused with the remedy, since WGSL gives its column a stride of 8 and std140 rounds every column to 16, so the two targets would place it and every later field at different offsets.

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

근거

a shape both targets lay out alike needs no ceremony, and a shape they lay out differently is refused rather than padded, because padding would make the emitted WGSL disagree with the offsets reflect() reports (Rule 6.8).

출처

Matrix Types (matCxR<T>, T a floating-point type) and Memory Layout (the column stride is AlignOf(vecR<T>)); PR #166, which measured the std140 stride on a WebGL2 driver and on Tint (surface §40); #149.

검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

  • MAT_TYPE_NAMES in src/compiler/ts/type-map/scalar-names.ts for the nine shapes and the three short spellings (TS8002 UNKNOWN_TYPE names all twelve);
  • TS8027 MAT_UNSUPPORTED for a non-square matCxR<f64> (mat2x3<f64> has no emulated-double form: the fp64 pass carries a square matrix of doubles only (mat2, mat3, mat4). Declare it mat2x3 and narrow, or use a square shape.);
  • TS8051 LAYOUT in src/compiler/ts/bindings.ts for the two-row uniform field, at the binding’s declaration and with neither target emitted ("U.m" is in a uniform: mat2x2 in std140 is not supported, a sentence that goes on to name mat2x4 and two vec2 fields as the remedies), pinned by src/compiler/ts/uniform-layout.test.ts; wgslLayout in src/core/reflect.ts throws the same sentence from src/core/std140.ts for a std140 layout built another way;
  • TS8003 TYPE_MISMATCH for a * b on two matrices whose dimensions do not meet, two of one non-square shape among them (Type mismatch: cannot * mat2x3 and mat2x3. WGSL's matrix product is matKxR * matCxK -> matCxR: …), pinned by src/compiler/ts/matrices.test.ts (refuses two matrices of ONE non-square shape, which have one type key) (#169);
  • src/compiler/ts/matrices.test.ts, src/core/reflect.test.ts, and examples/gallery/normal-matrix/normal-matrix.shade.ts on both halves of the gate, which pin them.

커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

설명하는 절

커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.

적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

TS8002 UNKNOWN_TYPE
아무것도 선언하지 않은 타입 이름입니다. 매개변수, 타입 인자, 별칭, implements 절, 기반 클래스 어디에 써도 걸리고, 이 표면이 매퍼가 읽는 자리에서 받지 않는 타입도 여기에 속합니다(규칙 2.1). 파일이 선언했지만 구조체로 모으지 않은 기반은 STRUCT_FIELD입니다.
TS8003 TYPE_MISMATCH
연산자나 조건, 선언, 반환, 인자처럼 두 값이 만나는 자리에서 타입이 서로 맞지 않거나, 검사로 좁히지 않은 선택적 값(T | undefined, T | null, T | null | undefined)을 읽거나(규칙 7.10), 컴파일러가 접는 상수를 WGSL이 거부합니다. 31을 넘는 시프트 양, 0인 제수, 서로 엇갈린 clamp 경계, 범위를 넘는 f32 값, Math.pow(-2., 2.)처럼 정의역 밖에서 부르는 내장 함수가 그렇습니다.
TS8027 MAT_UNSUPPORTED
정방이 아닌 matCxR<f64>입니다. fp64 패스는 차원마다 double-float 본문 하나를 두므로 정방 double 행렬만 낮출 수 있습니다. 모든 matCxR<f32>는 타입입니다.
TS8051 LAYOUT
버퍼 바인딩의 저장 타입이 WGSL의 호스트 공유 규칙 하나를 어깁니다. uniform이나 storage 바인딩 안의 bool(단독이든 벡터든), 구조체의 마지막 멤버가 아닌 런타임 크기 array<T>, uniform 안의 런타임 크기 배열, uniform 안의 두 행 행렬(mat2x2, mat3x2, mat4x2)이 그렇습니다. 마지막은 WGSL과 std140이 서로 다른 오프셋에 배치합니다(규칙 4.8).

함께 보기

소스

커밋 af54ddad5의 규칙 원문:

이 페이지 편집 문제 보고