hostFeaturesFor()
함수, 백엔드 분류
Translate neutral capability ids into the feature strings one target's host has to activate before it creates a pipeline.
import { hostFeaturesFor } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function hostFeaturesFor(be: Backend, caps: readonly Capability[]): readonly string[]매개변수
beBackendthe backend whose capability profile does the translating.
capsreadonly Capability[]the neutral ids, usually
reflect(m).requiredFeatures.
반환값
readonly string[]
the host-side feature strings, in the order the ids arrived, with the id-less ones dropped.
설명
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.
예제
예제
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),})관련 가이드
함께 보기
소스
src/core/backend.ts, 143행, 커밋 c66579bf 기준