The slang Lua Table#
Every function and constant a .slang.lua launch script can use. For what a launch script
is and when it runs, refer to The Lua Launch Script.
Accepted source assets: .slang, compiled on load, .slang-module, pre-compiled Slang
IR, and .spv, SPIR-V and compute only. Extensions are matched case-insensitively. That is
the complete list.
Slang nodes require the renderer to be running on Vulkan, the ovrtx default on Linux and Windows.
Describing Outputs#
Output descriptors state what an output has to be; SPG owns the memory. The split matches
CUDA: image is texture-backed, empty is buffer-backed.
Function |
Description |
|---|---|
|
A texture-backed output. Note the argument order against height-first shapes. |
|
The same, with the shape as a table: |
|
A buffer-backed output of arbitrary shape. |
|
A buffer filled with zeros, ones, or a stated value. |
slang.image and slang.empty take an optional trailing slang.stateful, which marks
the output persistent so SPG hands the same resource back next frame instead of a fresh one:
TrailKernel.slang.lua, from the runnable stateful node example#function trail(inputs, outputs)
local image = inputs["Image"]
assert(image.rank == 2, "Input must be a 2D image")
-- The input is HdrColor, linear radiance. Texture2D<float4> converts the
-- component type on load, so no exact dtype is pinned here.
-- The feedback framebuffer, and the only reason the effect exists.
outputs["History"] = slang.image(image.shape, slang.float4, slang.stateful)
-- Ordinary outputs: published as AOVs and handed out fresh each frame.
outputs["Live"] = slang.image(image.shape, slang.uchar4)
outputs["Trail"] = slang.image(image.shape, slang.uchar4)
return slang.dispatch({
bind = {
slang.ParameterBlock(
slang.float(inputs["decay"]) -- -> float decay
),
slang.Texture2D(image), -- -> Texture2D<float4> g_InImage
slang.RWTexture2D(outputs["History"]), -- -> RWTexture2D<float4> g_History
slang.RWTexture2D(outputs["Live"]), -- -> RWTexture2D<float4> g_OutLive
slang.RWTexture2D(outputs["Trail"]), -- -> RWTexture2D<float4> g_OutTrail
},
})
end
The Binders#
Each binder is named after the Slang type it binds to, and behaves like it.
Function |
Binds |
|---|---|
|
The shader’s constant buffer. |
|
A resource-input as a read-only texture of that rank. |
|
An output as a read/write texture of that rank. |
|
A read-only storage buffer, addressed by element or by byte offset. The two are the same descriptor and differ only in how the shader addresses it. Takes a resource-input or the result of |
|
A buffer-backed output as a read/write storage buffer, addressed by element or by byte offset. |
|
A read-only typed buffer, |
|
A buffer-backed output as a typed buffer, |
The binders check what they are given, in Lua, before anything reaches the GPU, and the message names the port: the rank must match the type, the direction must match, the backing must match, and for a buffer this node reads, the kind must match.
Shader-match failures cannot be caught this way, because the launch script does not see the shader. Those surface from the node at load time.
Grouping and Data#
Function |
Description |
|---|---|
|
Group bound resources into one descriptor set. Slots are positions in the group, counting
from zero; |
|
Upload a Lua table of numbers to a GPU buffer. Wrap it in a buffer binder to bind it. |
|
Reference a buffer-backed resource that already exists, such as a composite channel. |
|
Upload the raw bytes of an |
|
A |
What a Launch Script Returns#
A launch script returns one of three calls, and which one it returns decides the shader stage.
Function |
Description |
|---|---|
|
A compute launch. The fields are below. |
|
A ray-generation launch that traces inline, with no shader binding table and so no miss or
hit entry points. Takes |
|
A ray-generation launch that drives a full ray-tracing pipeline with a shader binding table, so shading happens in separate entry points. Takes the extra fields below. |
slang.dispatch fields#
Field |
Description |
|---|---|
|
Ordered list of resource bindings. Required unless the resources are grouped with |
|
The group size the shader was compiled with, as |
|
Number of thread groups as |
|
Shader stage. Optional; |
Set grid explicitly whenever the iteration domain is the data rather than the image. The
derived grid follows the output shape, which is wrong for a shader whose threads each walk a
buffer.
slang.traceRays fields#
In addition to bind. The named entry points live in the same source asset as the
ray-generation entry point.
Field |
Description |
|---|---|
|
Array of miss entry-point names, as strings. |
|
Array of hit groups, each a table defining |
|
Size of the |
|
Size of the hit attributes in bytes. A whole number from 0 to 65535. |
Binding by Name#
Function |
Description |
|---|---|
|
Bind a resource the renderer provides under a known name rather than one the scene
connected. |
Cached Computation#
Function |
Description |
|---|---|
|
Call |
Matrix Storage Order#
Constant |
Description |
|---|---|
|
How a matrix is stored in a parameter block, given as the |
dtype Constants#
Every constant is also callable as a constructor, so slang.float(inputs["strength"]) wraps a
value for a parameter block and slang.float3(x, y, z) builds one from components.
Scalar |
Element |
Vector forms |
Notes |
|---|---|---|---|
|
8-bit boolean |
|
|
|
8-bit signed, unsigned |
|
|
|
16-bit signed, unsigned |
|
|
|
32-bit signed, unsigned |
|
|
|
16-bit float |
|
|
|
32-bit float |
|
|
|
64-bit float |
|
|
|
64-bit signed, unsigned |
none |
Present, but a shader cannot use them: the Vulkan |
Square matrices are slang.float2x2, slang.float3x3, slang.float4x4 and the double
forms slang.double2x2, slang.double3x3, slang.double4x4. A matrix in a parameter block
needs its storage order as well as its offset; refer to Stating the Layout.
Quaternions are slang.quatf, slang.quatd and slang.quath, four components of the
matching float width.
The three-component types narrower than 32 bits cannot back a texture. Refer to not every dtype can back a texture.
What this table adds. Everything cuda carries is here. This table adds char,
short and ushort, the bool, char, short and ushort vectors, uchar2 and
uchar3, every matrix type and every quaternion type.