RenderState
On this page

RenderState

Interface in Runtime

The fixed-function state of a render pipeline, which the host writes: the compiler knows its entries' inputs and outputs, and the runtime fills and checks those.

import type { RenderState } from 'typeshade/runtime'

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

Syntax

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;
}

Instance properties

vertexoptionalread only string

The vertex entry; the program’s only one when omitted.

fragmentoptionalread only string | null

The fragment entry; the program’s only one when omitted, none for a depth-only pass.

targetsoptionalread only readonly TargetState[]

One per colour output, by location. Omitted: rgba8unorm for each.

blendConstantoptionalread only ArrayLike<number>

setBlendConstant. The pipeline field is a TypeShade addition: WebGPU sets the constant on the pass only. Four numbers, each from 0 to 1. Unset, a draw uses the pass value.

depthoptionalread only { 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; }

The depth attachment’s format, and how the pipeline tests and writes it: compare defaults to 'less' and write to true. A reversed projection compares 'greater', and a pass drawn behind everything else (a sky) compares 'always' and does not write. bias offsets the depth of each triangle. stencil adds the stencil test. Omitted: no depth test, for a pass with no depth attachment.

primitiveoptionalread only { readonly topology?: string; readonly cullMode?: 'none' | 'front' | 'back'; readonly frontFace?: 'ccw' | 'cw'; }

What the vertices make: topology defaults to 'triangle-list', cullMode to 'none' and frontFace to 'ccw'.

multisampleoptionalread only { 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; }

The sample count of the targets it draws into: 1 when omitted, 4 for a multisampled target. The WebGL2 tier refuses a count of 4. To learn that on WebGPU, run the host a second time with createRuntime({ prefer: ['webgl2'] }).

constantsoptionalread only Constants

The values of the program’s overrides (surface §15), by the names the source declares: { quality: 3 }. The vertex and the fragment stage are each created with them, as WebGPU’s constants. An override the record leaves out takes the default its declaration states, so omitted, every override does. An f32 takes a finite number no larger than 3.4028234663852886e38 in magnitude, an i32 or a u32 a whole number in its range, and a bool a boolean or a number, where 0 is false. A name the program does not declare is a TypeError that names the program’s overrides, and a value its type cannot hold one that says what the type takes. Two states that differ in an override are two pipelines, and the same values give the same pipeline back.

Source

src/runtime/program.ts, line 273, at commit af54ddad5

Edit this page Report a problem