hostFeaturesFor()
Function in Backends
Translate neutral capability ids into the feature strings one target's host has to activate before it creates a pipeline.
import { hostFeaturesFor } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function hostFeaturesFor(be: Backend, caps: readonly Capability[]): readonly string[]Parameters
beBackendthe backend whose capability profile does the translating.
capsreadonly Capability[]the neutral ids, usually
reflect(m).requiredFeatures.
Return value
readonly string[]
the host-side feature strings, in the order the ids arrived, with the id-less ones dropped.
Description
On WebGL2 those are extension names for
gl.getExtension, and on WebGPU they are feature names for
requestDevice({ requiredFeatures }).
Feed it reflect(m).requiredFeatures, which reports the ids neutrally because reflection
takes a module and never a backend.
It skips every id with no host half. A capability that is core on this target, or one the
backend covers by emitting a source directive, contributes nothing. That is why this is a
function: a map over the profile at each call site yields undefined holes a host then
hands to getExtension verbatim. The returned list has no holes.
Examples
Example
import { hostFeaturesFor, reflect, glslEs300Backend, wgslBackend } from 'typeshade'
const caps = reflect(MODULE).requiredFeatures
for (const ext of hostFeaturesFor(glslEs300Backend, caps)) { if (!gl.getExtension(ext)) throw new Error(`WebGL2 lacks ${ext}`)}
const device = await adapter.requestDevice({ requiredFeatures: hostFeaturesFor(wgslBackend, caps),})In the guide
See also
Source
src/core/backend.ts, line 143, at commit 26de7be8