lowerComputeToFragment()
Function in Emit
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'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function lowerComputeToFragment(m: ModuleDecl): ModuleDeclParameters
mModuleDecla module with one
@computeentry.
Return value
the rewritten module, with a @fragment entry and no read_write binding.
Exceptions
@link UnsupportedFeatureError(
SD0030) when the module has no@computeentry, noglobal_invocation_idparameter, noread_writestorage binding or nouniformbinding, and when the kernel is not gather-only: a write at an index other thangid.x, more than one write to the output, or a use ofglobal_invocation_idother than.x.@link TypeShadeErrorSD0111instead of the above when the entry is declaredportable: the portable-kernel check then reports every violation with its remedy at once, the same report both backends give.
Description
The rewrite:
- turns the
@computeentry into a@fragmententry and drops its workgroup size; - removes the
@builtin(global_invocation_id)parameter and adds a@builtin(position)one, sogid.xbecomesu32(floor(position.x)) + u32(floor(position.y)) * width, wherewidthis the.ycomponent of the module’s firstuniformbinding; - turns the single
out[gid.x] = ewrite to theread_writestorage binding intoreturn e, typedu32at@location(0), and removes that binding; - turns an expression-less
return;(the bounds guard) intodiscard;.
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.
Source
src/core/backends/glsl.ts, line 1647, at commit 26de7be8