Skip to content

compute

FreeBodyEngine.graphics.compute #

Backend-agnostic GPU compute dispatch.

On a backend with real hardware compute (a future GL4.4/Vulkan/Metal generator), a concrete ComputeShader would compile straight to a real compute shader and issue a real dispatch. GL33 (graphics/gl33/compute.py) has neither, so it emulates a dispatch as a fullscreen draw through the fixed vertex+ fragment pipeline - one output pixel per invocation, storage buffers read via buffer textures, results written to float framebuffer attachments. Either way, code written against this interface doesn't change.

ComputeShader(source, injector=None) #

Backend-agnostic GPU compute-kernel handle, compiled from FBUSL source. See the module docstring above for how GL33 emulates dispatch() vs. a backend with real hardware compute support.

Stores the kernel's FBUSL source and injector; compiling it into a runnable kernel is left to a concrete subclass's constructor.

injector = injector or Injector() instance-attribute #

source = source instance-attribute #

bind_buffer(name, buffer) #

Binds a storage buffer to the buffer block declared as name.

blit_to_screen(name, size=None) #

Draws one @output field's result directly to the currently bound framebuffer - the simplest way to show a result on screen.

dispatch(width, height) #

Runs the kernel once per (x, y) in [0, width) x [0, height).

get_output_texture(name) #

Exposes one @output field's results as a Texture, for chaining into the ordinary rendering/material pipeline without a readback.

read_output(name) #

Synchronous CPU readback of one @output field's results.

set_uniform(name, value) #

Sets uniform name to value for this kernel.