타입
이 페이지에서

타입

타입은 WGSL이 타입을 적는 자리, 곧 선언과 매개변수와 필드와 반환 위치에 그대로 적습니다. WGSL이 타입 인자를 받는 자리에서는 요소 타입이 이름 안으로 들어가므로 vec3<u32>는 vec3u가 되고, 꺾쇠 안에서 틀릴 것이 남지 않습니다.

스칼라

WGSLTypeShade
f32
f32
i32
i32
u32
u32
bool
bool
f16

이 인터페이스에는 타입 이름이 없습니다. "use typeshade" 옆에 "enable f16"을 적으면 WGSL의 enable f16;이 생성되고, 리플렉션에는 호스트가 shader-f16으로 요청할 기능이 실립니다. 그래도 값을 선언할 f16은 아직 없습니다.

WGSL에는 64비트 부동소수점이 없습니다. 아래 패스가 생성기보다 먼저 선언을 바꿔 놓습니다.

f64

배정밀도에는 대응하는 WGSL 타입이 없습니다. 선언에는 f64라고 적고, 생성기가 돌기 전에 한 패스가 이를 모두 f32 레인 두 개와 그 위의 함수 라이브러리로 하향 변환합니다. 배정밀도 곱셈 하나는 WGSL에서 호출 한 번이 됩니다.

let d = df64_mul(vec2<f32>(uv.x, 0.0), vec2<f32>(u.a, 0.0), _fp64_g);

벡터

WGSLTypeShade
vec3<f32>
vec3
vec3<f32>
vec3f
vec3<u32>
vec3u
vec3<i32>
vec3i
vec3<bool>
vec3b

WGSL에는 64비트 벡터도 없어서 같은 패스가 이것도 바꿔 놓습니다.

vec3d

vec2와 vec4도 위의 세 가지와 같은 방식으로 읽습니다. vec3와 vec3f는 같은 타입이고, vec3d와 vec3f64도 마찬가지입니다.

행렬

WGSLTypeShade
mat2x2<f32>
mat2x2
mat2x3<f32>
mat2x3
mat2x4<f32>
mat2x4
mat3x2<f32>
mat3x2
mat3x3<f32>
mat3x3
mat3x4<f32>
mat3x4
mat4x2<f32>
mat4x2
mat4x3<f32>
mat4x3
mat4x4<f32>
mat4x4

정사각 행렬에는 두 타깃이 모두 주는 짧은 이름도 있어서 mat4와 mat4x4는 같은 선언입니다. C와 R의 뜻도 WGSL과 같아서 앞이 열, 뒤가 행입니다.

배열과 atomic

WGSLTypeShade
array<f32, 4>
array<f32, 4>
array<f32, 2>
[f32, f32]
array<f32>
array<f32>
atomic<u32>
atomic<u32>
atomic<i32>
atomic<i32>

튜플은 타입이 길이를 고정한 목록이고, 크기를 아는 배열이 바로 그것입니다. 그래서 [f32, f32]와 array<f32, 2>는 같은 타입에 닿습니다. 길이가 실행 시점에 정해지는 배열과 atomic은 각각 스토리지 바인딩 안에 놓입니다.

텍스처와 샘플러

WGSLTypeShade
texture_2d<f32>
texture_2d<f32>
texture_2d_array<f32>
texture_2d_array<f32>
texture_cube<f32>
texture_cube<f32>
texture_3d<f32>
texture_3d<f32>
texture_1d<f32>
texture_1d<f32>
texture_cube_array<f32>
texture_cube_array<f32>
texture_multisampled_2d<f32>
texture_multisampled_2d<f32>
texture_storage_2d<rgba8unorm, write>
texture_storage_2d<"rgba8unorm", "write">
texture_storage_2d_array<rgba8unorm, write>
texture_storage_2d_array<"rgba8unorm", "write">
texture_depth_2d
texture_depth_2d
texture_depth_2d_array
texture_depth_2d_array
texture_depth_cube
texture_depth_cube
texture_depth_cube_array
texture_depth_cube_array
texture_depth_multisampled_2d
texture_depth_multisampled_2d
sampler
sampler
sampler_comparison
sampler_comparison
texture_2d<u32>
texture_2d<u32>
texture_2d<i32>
texture_2d<i32>

텍스처와 샘플러는 주소 공간 래퍼 없이 그냥 적습니다. 핸들은 어느 주소 공간에도 놓이지 않기 때문입니다. 샘플링 텍스처는 f32나 i32나 u32를 받고, 그 요소 타입이 WGSL 표기와 적용 가능한 읽기 방식을 함께 결정합니다. 스토리지 텍스처는 포맷과 접근 모드를 문자열 리터럴 타입으로 받으므로 이 컴파일러보다 tsc가 먼저 검사합니다.

이 페이지 편집 문제 보고