resource()
함수, 레이아웃 분류
Declare a bound resource that is not a struct: a texture or a sampler.
import { resource } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function resource<T extends ShaderType>( name: string, type: T, at: { group: number; binding: number; space?: AddressSpace },): Resource<T>매개변수
namestringthe emitted binding name, which is also the name a host binds by.
typeT extends ShaderTypethe resource’s type, such as
texture2dfT,texture2dArrayfTorsamplerT.at{ group: number; binding: number; space?: AddressSpace }the
groupandbindingslot, and optionally the addressspace.
반환값
Resource<T>
the Resource handle, .binding and .node.
설명
The binding declaration and the access node come from this one call.
.node keeps the specific key of the type you passed: Node<'texture_2d<f32>'>,
Node<'sampler'>, Node<'texture_2d_array<u32>'>. That is what makes the texture calls
type-checked at the authoring line: textureSample
takes a sampled 2D texture and a sampler in that order, so swapping them is a tsc error,
an integer texture is rejected where filtering has no meaning, and an array texture
requires its layer argument.
.binding goes in module({ bindings }), or pass the handle in uses. The address space
defaults to 'uniform', the texture and sampler convention.
예제
예제
import { resource, textureSample, texture2dfT, samplerT } from 'typeshade'
const tex = resource('tex', texture2dfT, { group: 0, binding: 1 })const smp = resource('tex_sampler', samplerT, { group: 0, binding: 2 })const c = textureSample(tex.node, smp.node, uv)관련 가이드
함께 보기
소스
src/core/sot.ts, 848행, 커밋 c66579bf 기준