---
title: "WGSL 스칼라와 벡터, 행렬의 표기"
description: "WGSL 타입 표면을 TypeShade 표기와 나란히 놓습니다. 스칼라와 벡터, 행렬, 배열과 atomic, 텍스처와 샘플러를 다룹니다."
url: https://typeshade.dev/ko/guide/language/from-wgsl/types/
language: ko
---

# 타입

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

## 스칼라

WGSL TypeShade

```wgsl
f32
```

```ts
f32
```

```wgsl
i32
```

```ts
i32
```

```wgsl
u32
```

```ts
u32
```

```wgsl
bool
```

```ts
bool
```

```wgsl
f16
```

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

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

```ts
f64
```

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

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

## 벡터

WGSL TypeShade

```wgsl
vec3<f32>
```

```ts
vec3
```

```wgsl
vec3<f32>
```

```ts
vec3f
```

```wgsl
vec3<u32>
```

```ts
vec3u
```

```wgsl
vec3<i32>
```

```ts
vec3i
```

```wgsl
vec3<bool>
```

```ts
vec3b
```

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

```ts
vec3d
```

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

## 행렬

WGSL TypeShade

```wgsl
mat2x2<f32>
```

```ts
mat2x2
```

```wgsl
mat2x3<f32>
```

```ts
mat2x3
```

```wgsl
mat2x4<f32>
```

```ts
mat2x4
```

```wgsl
mat3x2<f32>
```

```ts
mat3x2
```

```wgsl
mat3x3<f32>
```

```ts
mat3x3
```

```wgsl
mat3x4<f32>
```

```ts
mat3x4
```

```wgsl
mat4x2<f32>
```

```ts
mat4x2
```

```wgsl
mat4x3<f32>
```

```ts
mat4x3
```

```wgsl
mat4x4<f32>
```

```ts
mat4x4
```

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

## 배열과 atomic

WGSL TypeShade

```wgsl
array<f32, 4>
```

```ts
array<f32, 4>
```

```wgsl
array<f32, 2>
```

```ts
[f32, f32]
```

```wgsl
array<f32>
```

```ts
array<f32>
```

```wgsl
atomic<u32>
```

```ts
atomic<u32>
```

```wgsl
atomic<i32>
```

```ts
atomic<i32>
```

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

## 텍스처와 샘플러

WGSL TypeShade

```wgsl
texture_2d<f32>
```

```ts
texture_2d<f32>
```

```wgsl
texture_2d_array<f32>
```

```ts
texture_2d_array<f32>
```

```wgsl
texture_cube<f32>
```

```ts
texture_cube<f32>
```

```wgsl
texture_3d<f32>
```

```ts
texture_3d<f32>
```

```wgsl
texture_1d<f32>
```

```ts
texture_1d<f32>
```

```wgsl
texture_cube_array<f32>
```

```ts
texture_cube_array<f32>
```

```wgsl
texture_multisampled_2d<f32>
```

```ts
texture_multisampled_2d<f32>
```

```wgsl
texture_storage_2d<rgba8unorm, write>
```

```ts
texture_storage_2d<"rgba8unorm", "write">
```

```wgsl
texture_storage_2d_array<rgba8unorm, write>
```

```ts
texture_storage_2d_array<"rgba8unorm", "write">
```

```wgsl
texture_depth_2d
```

```ts
texture_depth_2d
```

```wgsl
texture_depth_2d_array
```

```ts
texture_depth_2d_array
```

```wgsl
texture_depth_cube
```

```ts
texture_depth_cube
```

```wgsl
texture_depth_cube_array
```

```ts
texture_depth_cube_array
```

```wgsl
texture_depth_multisampled_2d
```

```ts
texture_depth_multisampled_2d
```

```wgsl
sampler
```

```ts
sampler
```

```wgsl
sampler_comparison
```

```ts
sampler_comparison
```

```wgsl
texture_2d<u32>
```

```ts
texture_2d<u32>
```

```wgsl
texture_2d<i32>
```

```ts
texture_2d<i32>
```

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