lowerComputeToFragment
이 페이지에서

lowerComputeToFragment()

함수, 출력 분류

Rewrite a gather-only @compute module into a @fragment one that WebGL2 runs as a fullscreen draw into an R32UI target, one texel per invocation.

import { lowerComputeToFragment } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

function lowerComputeToFragment(m: ModuleDecl): ModuleDecl

매개변수

m ModuleDecl

a module with one @compute entry.

반환값

ModuleDecl

the rewritten module, with a @fragment entry and no read_write binding.

예외

@link UnsupportedFeatureError

(SD0030) when the module has no @compute entry, no global_invocation_id parameter, no read_write storage binding or no uniform binding, and when the kernel is not gather-only: a write at an index other than gid.x, more than one write to the output, or a use of global_invocation_id other than .x.

@link TypeShadeError

SD0111 instead of the above when the entry is declared portable: the portable-kernel check then reports every violation with its remedy at once, the same report both backends give.

설명

The rewrite:

  • turns the @compute entry into a @fragment entry and drops its workgroup size;
  • removes the @builtin(global_invocation_id) parameter and adds a @builtin(position) one, so gid.x becomes u32(floor(position.x)) + u32(floor(position.y)) * width, where width is the .y component of the module’s first uniform binding;
  • turns the single out[gid.x] = e write to the read_write storage binding into return e, typed u32 at @location(0), and removes that binding;
  • turns an expression-less return; (the bounds guard) into discard;.

Read-only storage bindings are left in place; a full emit goes on to rewrite them as data textures, so a module this function returns is not yet ready to emit on its own.

소스

src/core/backends/glsl.ts, 1647행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고