backends.wgsl.ShaderProgram

backends.wgsl.ShaderProgram(
    wgsl,
    parameters,
    buffer_bytes,
    group,
    binding,
    nan_offset=0,
    cull_margin_offset=None,
)

WGSL source plus the parameter buffer its entry points read.

Attributes

Name Type Description
wgsl str The shader source, identical for every value of every parameter.
parameters tuple[ShaderParameter, …] Buffer layout, in binding order.
buffer_bytes int Total size of the uniform buffer to allocate.
group int Bind group index the uniform declares.
binding int Binding index within that group.
nan_offset int Byte offset of the reserved slot holding a NaN. WGSL has no NaN literal that survives const-evaluation — Tint rejects the bit-pattern bitcast outright, so a module containing one will not compile in Chromium — and the uniform form does produce NaNs: a material property the scene never set folds away when the values are literals but survives when they are buffer reads. A load from this slot is exact, and no compiler can fold it.
cull_margin_offset int | None Byte offset of the reserved slot holding the bounding-box cull margin, or None when the program reserved no such slot. None rather than 0 because 0 names a real parameter’s slot, and a program that had merely forgotten to set this would overwrite that parameter’s value with the margin. Writing :data:CULL_MARGIN there is culling on; writing :data:CULL_DISABLED_MARGIN makes every skip test false, which is the flat field that evaluates every leaf. It rides here rather than in the viewer’s own uniform block because the tests are inside the generated module, which reads nothing else.

Methods

Name Description
as_dict The buffer contract as plain JSON — what the compile payload carries.
buffer The current parameter values, packed for upload.

as_dict

backends.wgsl.ShaderProgram.as_dict()

The buffer contract as plain JSON — what the compile payload carries.

The source itself travels separately (embedded in the two shaders), so this is only the layout and the values.

buffer

backends.wgsl.ShaderProgram.buffer()

The current parameter values, packed for upload.

Returns

Name Type Description
np.ndarray A float32 array of buffer_bytes // 4 elements, with each parameter written at its own slot and the padding left zero.