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.
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. |
The same functions describe the node’s memory: storage only the node reads and writes,
kept across frames for as long as the node lives. A memory is stated on self.memory under
its name instead of on outputs, and passed to the kernel with the same wrappers as an
output, as in the snippet below. Refer to
Keep State Across Frames.
slang.image and slang.empty also take an optional trailing slang.stateful, which marks
an output persistent so SPG hands the same resource back next frame instead of a fresh one:
state the scene reads as well.
TrailKernel.slang.lua, from the runnable stateful node example#function trail(inputs, outputs)
local image = inputs["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, kept between executions.
self.memory["History"] = slang.image(image.shape, slang.float4)
-- 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.compute({
bind = {
slang.ParameterBlock(
slang.float(inputs["decay"]) -- -> float decay
),
slang.Texture2D(image), -- -> Texture2D<float4> g_InImage
slang.RWTexture2D(self.memory["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, created 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. An empty table binds a placeholder the shader must not read. |
|
A GPU buffer of that shape filled with zeros, ones, or a stated value. Wrap it in a buffer binder to bind it, as the result of |
|
An array inside a parameter block, |
|
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 the calls below, and the call it returns decides the shader stage.
Function |
Description |
|---|---|
|
A compute launch. The fields are below. |
|
Deprecated: the same call as |
|
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.compute 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 |
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 |
|---|---|
|
Deprecated: 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. A
constructor holds one value of its type: given an input that holds more elements, it fails the
launch, and the array goes in with slang.array instead.
Scalar |
Element |
Vector forms |
Notes |
|---|---|---|---|
|
8-bit boolean |
|
In a parameter block each component is packed as a four-byte shader |
|
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 the parameter block
of a shader without reflection needs its offset and strides; 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.