RenderState
이 페이지에서

RenderState

인터페이스, 런타임 분류

렌더 파이프라인의 고정 기능 상태이며, 호스트가 씁니다. 컴파일러는 진입점의 입력과 출력을 알고, 런타임은 그 입력과 출력에 맞는 값을 채우고 검사합니다.

import type { RenderState } from 'typeshade/runtime'

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

구문

interface RenderState {
readonly vertex?: string;
readonly fragment?: string | null;
readonly targets?: readonly TargetState[];
readonly blendConstant?: ArrayLike<number>;
readonly depth?: { readonly format: string; /** depthCompare. How the depth test compares a fragment with the stored depth. Default `'less'`. A reversed projection compares `'greater'`, and a sky compares `'always'`. */ readonly compare?: CompareFunction; /** depthWriteEnabled. Whether a passing fragment writes its depth. Default `true`. */ readonly write?: boolean; /** depthBias, depthBiasSlopeScale and depthBiasClamp. Each defaults to 0. A negative `constant` or `slopeScale` lowers the depth of a fragment, so a coplanar draw wins a `less` test. A positive one raises it. The unit of `constant` is the smallest depth step of the format, so it depends on the format. A non-zero bias on a line or point topology is refused. */ readonly bias?: { /** depthBias. A whole number in the int32 range. The WebGL2 tier takes it on depth24plus, depth32float and depth24plus-stencil8, and refuses other formats. Measured on SwiftShader at 0.25, 0.5 and 0.75, from window depth 0.25 up its offset is at least the WebGPU offset and at most twice it. Measured on SwiftShader below 0.25: 8 times at 0.0625 and 4 times at 0.125. Below window depth 0.0625 the ratio is not measured. It is expected to grow as the depth falls (inference: it doubles each time the depth halves). To learn a refusal on WebGPU, run the host a second time with `createRuntime({ prefer: ['webgl2'] })`. */ readonly constant?: number; /** depthBiasSlopeScale. A finite number. The WebGL2 tier gives the same offset as WebGPU, on the formats that take a constant bias. */ readonly slopeScale?: number; /** depthBiasClamp. A finite number. The WebGL2 tier takes a non-zero value through `EXT_polygon_offset_clamp`. A non-zero value without that extension is not supported yet on the WebGL2 tier (Rule 11.11). */ readonly clamp?: number; }; /** stencilFront, stencilBack, stencilReadMask and stencilWriteMask of depthStencil. Needs a format with a stencil aspect. The reference comes from pass.setStencilReference, which is 0 at each pass start, or from this pipeline's reference. Lines and points use the front face. */ readonly stencil?: StencilState; };
readonly primitive?: { readonly topology?: string; readonly cullMode?: 'none' | 'front' | 'back'; readonly frontFace?: 'ccw' | 'cw'; };
readonly multisample?: { readonly count?: number; /** mask. A whole number from 0 to 0xFFFFFFFF, default 0xFFFFFFFF. A mask other than the default with a count other than 1 is refused. At count 1, bit 0 keeps or drops the draw. */ readonly mask?: number; };
readonly constants?: Constants;
}

인스턴스 속성

vertex선택 사항읽기 전용 string

버텍스 진입점입니다. 생략하면 프로그램에 있는 유일한 버텍스 진입점을 씁니다.

fragment선택 사항읽기 전용 string | null

프래그먼트 진입점입니다. 생략하면 프로그램에 있는 유일한 프래그먼트 진입점을 씁니다. 깊이 전용 패스에는 프래그먼트 진입점이 없습니다.

targets선택 사항읽기 전용 readonly TargetState[]

색상 출력마다 하나씩, location으로 지정합니다. 생략하면 각 출력에 rgba8unorm을 씁니다.

blendConstant선택 사항읽기 전용 ArrayLike<number>

setBlendConstant입니다. 파이프라인의 이 필드는 TypeShade가 더한 것입니다. WebGPU는 이 상수를 패스에만 설정합니다. 각각 0부터 1까지인 숫자 네 개를 받습니다. 설정하지 않으면 그리기는 패스의 값을 씁니다.

depth선택 사항읽기 전용 { readonly format: string; /** depthCompare. How the depth test compares a fragment with the stored depth. Default `'less'`. A reversed projection compares `'greater'`, and a sky compares `'always'`. */ readonly compare?: CompareFunction; /** depthWriteEnabled. Whether a passing fragment writes its depth. Default `true`. */ readonly write?: boolean; /** depthBias, depthBiasSlopeScale and depthBiasClamp. Each defaults to 0. A negative `constant` or `slopeScale` lowers the depth of a fragment, so a coplanar draw wins a `less` test. A positive one raises it. The unit of `constant` is the smallest depth step of the format, so it depends on the format. A non-zero bias on a line or point topology is refused. */ readonly bias?: { /** depthBias. A whole number in the int32 range. The WebGL2 tier takes it on depth24plus, depth32float and depth24plus-stencil8, and refuses other formats. Measured on SwiftShader at 0.25, 0.5 and 0.75, from window depth 0.25 up its offset is at least the WebGPU offset and at most twice it. Measured on SwiftShader below 0.25: 8 times at 0.0625 and 4 times at 0.125. Below window depth 0.0625 the ratio is not measured. It is expected to grow as the depth falls (inference: it doubles each time the depth halves). To learn a refusal on WebGPU, run the host a second time with `createRuntime({ prefer: ['webgl2'] })`. */ readonly constant?: number; /** depthBiasSlopeScale. A finite number. The WebGL2 tier gives the same offset as WebGPU, on the formats that take a constant bias. */ readonly slopeScale?: number; /** depthBiasClamp. A finite number. The WebGL2 tier takes a non-zero value through `EXT_polygon_offset_clamp`. A non-zero value without that extension is not supported yet on the WebGL2 tier (Rule 11.11). */ readonly clamp?: number; }; /** stencilFront, stencilBack, stencilReadMask and stencilWriteMask of depthStencil. Needs a format with a stencil aspect. The reference comes from pass.setStencilReference, which is 0 at each pass start, or from this pipeline's reference. Lines and points use the front face. */ readonly stencil?: StencilState; }

깊이 어태치먼트의 포맷과, 파이프라인이 깊이를 검사하고 쓰는 방식입니다. compare의 기본값은 'less'이고 write의 기본값은 true입니다. 뒤집힌 투영은 'greater'로 비교합니다. 다른 모든 것 뒤에 그리는 패스(예: 하늘)는 'always'로 비교하고 깊이를 쓰지 않습니다. bias는 삼각형마다 깊이를 옮기고, stencil은 스텐실 검사를 더합니다. 생략하면 깊이 검사를 하지 않습니다. 깊이 어태치먼트가 없는 패스는 이렇게 씁니다.

primitive선택 사항읽기 전용 { readonly topology?: string; readonly cullMode?: 'none' | 'front' | 'back'; readonly frontFace?: 'ccw' | 'cw'; }

버텍스가 만드는 프리미티브입니다. topology의 기본값은 'triangle-list', cullMode의 기본값은 'none', frontFace의 기본값은 'ccw'입니다.

multisample선택 사항읽기 전용 { readonly count?: number; /** mask. A whole number from 0 to 0xFFFFFFFF, default 0xFFFFFFFF. A mask other than the default with a count other than 1 is refused. At count 1, bit 0 keeps or drops the draw. */ readonly mask?: number; }

이 파이프라인이 그리는 대상의 샘플 수입니다. 생략하면 1이고, 멀티샘플 대상에는 4입니다. WebGL2 tier는 4를 거부합니다. WebGPU에서 이를 확인하려면 createRuntime({ prefer: ['webgl2'] })로 호스트를 한 번 더 실행합니다.

constants선택 사항읽기 전용 Constants

프로그램 오버라이드(surface §15)의 값입니다. 소스가 선언한 이름으로 적습니다. 예: { quality: 3 }. 버텍스 스테이지와 프래그먼트 스테이지는 각각 이 값으로 만들어지며, 이는 WebGPU의 constants와 같습니다. 상태에서 빠뜨린 오버라이드는 선언이 밝힌 기본값을 씁니다. 따라서 이 값을 생략하면 모든 오버라이드가 기본값을 씁니다. f32는 크기가 3.4028234663852886e38 이하인 유한한 수를 받고, i32와 u32는 각 범위 안의 정수를 받습니다. bool은 불리언이나 숫자를 받으며, 이때 0은 false입니다. 프로그램이 선언하지 않은 이름에는 프로그램의 오버라이드 목록을 알려 주는 TypeError가 발생합니다. 타입이 담을 수 없는 값에는 그 타입이 받는 값을 알려 주는 오류가 발생합니다. 오버라이드 값이 다른 두 상태는 파이프라인이 둘이며, 같은 값은 같은 파이프라인을 반환합니다.

소스

src/runtime/program.ts, 273행, 커밋 af54ddad5 기준

이 페이지 편집 문제 보고