---
title: "wgslLayout(): TypeShade 셰이더 API의 리플렉션 분류 함수 참조 문서"
description: "wgslLayout, TypeShade API의 리플렉션 분류에 속하는 함수입니다. LayoutKind 규칙에 따라 구조체 하나의 바이트 레이아웃을 계산합니다. 각 필드의 오프셋, 정렬, 크기와 구조체 전체의 크기 및 정렬을 구합니다."
url: https://typeshade.dev/ko/api/wgsllayout/
language: ko
---

# `wgslLayout()`

함수, 리플렉션 분류

LayoutKind 규칙에 따라 구조체 하나의 바이트 레이아웃을 계산합니다. 각 필드의 오프셋, 정렬, 크기와 구조체 전체의 크기 및 정렬을 구합니다.

`import { wgslLayout } from 'typeshade'`

설명은 커밋 af54ddad5의 검토된 컴파일러 문서를 번역한 것입니다. 시그니처와 예제 코드는 원문을 따르며, 필요한 경우 설명에 편집상 수정이 반영됩니다.

## 구문

```ts
function wgslLayout(
  struct: StructDecl,
  layout: LayoutKind,
  structs: ReadonlyMap<string, StructDecl> = new Map(),
): StructLayout
```

## 매개변수

**`struct` `StructDecl`**

레이아웃을 계산할 구조체입니다.

**`layout` `LayoutKind`**

유니폼 버퍼에는 `'std140'`, 스토리지 버퍼에는 `'std430'`을 씁니다.

**`structs` 선택 사항 `ReadonlyMap<string, StructDecl>`**

중첩된 구조체 타입 필드가 이름으로 참조할 수 있는 구조체들입니다. 기본값은 `struct` 자체만 담는 맵입니다.

## 반환값

`StructLayout`

[`StructLayout`](https://typeshade.dev/ko/api/structlayout/)을 반환합니다.

## 예외

**`Error`**

필드 타입에 바이트 레이아웃이 없는 경우(텍스처 또는 샘플러), 중첩된 구조체가 `structs`에 없는 경우, 또는 `mat2` 필드를 `'std140'`으로 계산하는 경우에 던집니다([`LayoutKind`](https://typeshade.dev/ko/api/layoutkind/) 참조).

## 설명

`'std140'`에서는 구조체와 중첩된 모든 배열의 기본 정렬이 16으로 올림됩니다. `'std430'`에서는 자연 정렬이 적용됩니다.

## 예제

### 예제

```ts
import { wgslLayout } from 'typeshade'
import { vec3fT, f32T } from 'typeshade/core/ir'

const light = { name: 'Light', fields: [{ name: 'pos', type: vec3fT }, { name: 'radius', type: f32T }] }
wgslLayout(light, 'std140')
// { name: 'Light', size: 16, align: 16, fields: [
//   { name: 'pos', type: 'vec3<f32>', offset: 0, align: 16, size: 12 },
//   { name: 'radius', type: 'f32', offset: 12, align: 4, size: 4 } ] }
```

## 관련 가이드

- [생성과 리플렉션](https://typeshade.dev/ko/guide/internals/emitting-and-reflection/)

## 함께 보기

- [`LayoutKind`](https://typeshade.dev/ko/api/layoutkind/)
- [`StructLayout`](https://typeshade.dev/ko/api/structlayout/)
- [`reflect`](https://typeshade.dev/ko/api/reflect/)

## 소스

[`src/core/reflect/layout.ts`, 211행](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/reflect/layout.ts#L211), 커밋 af54ddad5 기준
