UNPKG

typegpu

Version:

A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.

60 lines (59 loc) 2.24 kB
import { isMarkedInternal } from "../../shared/symbols.js"; export function isComputePipeline(value) { const maybe = value; return maybe?.resourceType === 'compute-pipeline' && isMarkedInternal(maybe); } export function isRenderPipeline(value) { const maybe = value; return maybe?.resourceType === 'render-pipeline' && isMarkedInternal(maybe); } export function isPipeline(value) { return isRenderPipeline(value) || isComputePipeline(value); } export function isTgpuCommandEncoder(value) { const maybe = value; return maybe?.resourceType === 'command-encoder' && isMarkedInternal(maybe); } export function isTgpuRenderPass(value) { const maybe = value; return maybe?.resourceType === 'render-pass' && isMarkedInternal(maybe); } export function isTgpuRenderCommands(value) { const maybe = value; return ((maybe?.resourceType === 'render-pass' || maybe?.resourceType === 'render-bundle-encoder') && isMarkedInternal(maybe)); } export function isTgpuComputePass(value) { const maybe = value; return maybe?.resourceType === 'compute-pass' && isMarkedInternal(maybe); } export function isGPUCanvasContext(value) { return typeof value?.getCurrentTexture === 'function'; } export function isGPUCommandEncoder(value) { const maybe = value; return (!isMarkedInternal(maybe) && typeof maybe?.beginRenderPass === 'function' && typeof maybe?.beginComputePass === 'function'); } export function isGPUComputePassEncoder(value) { const maybe = value; return (!isMarkedInternal(maybe) && typeof maybe?.dispatchWorkgroups === 'function' && maybe?.beginRenderPass === undefined); } export function isGPURenderPassEncoder(value) { const maybe = value; return (!isMarkedInternal(maybe) && typeof maybe?.executeBundles === 'function' && typeof maybe?.draw === 'function'); } export function isGPURenderBundleEncoder(value) { const maybe = value; return (!isMarkedInternal(maybe) && typeof maybe?.draw === 'function' && typeof maybe?.finish === 'function' && maybe?.executeBundles === undefined && maybe?.beginRenderPass === undefined && maybe?.dispatchWorkgroups === undefined); }