Address Spaces

Making it easier to work with shaders


Address Spaces

An address space defines a view into memory. It determines how memory objects are addressed and accessed by threads. In Slang, the address space for a variable is determined by its type, modifiers, and attributes. For example, data in ConstantBuffer<T> belongs to the uniform address space, and the address space for a static groupshared variable is group-shared.

The following address spaces are defined:

Address space Slang construct Instance scope Description
Uniform uniform
ConstantBuffer<T>
All threads Uniform values are parameters of a Slang program. They are expected to remain constant over the lifetime of a launch/dispatch.
Image Texture1D<...>
Texture2D<...>
etc.
All threads Images are multi-dimensional arrays of texels, typically containing color, depth, stencil, and similar data.
Push constant [push_constant]
[vk_push_constant]
All threads Push constants are small, frequently updated constants passed directly through the command stream. On Vulkan, these correspond to push constants.
Storage buffer StructuredBuffer<T>
RWStructuredBuffer<T>
All threads Storage buffers are read-only or read-write buffers, typically shared between the host and Slang programs.
Group-shared static groupshared (global scope) Thread group Group-shared variable instances are shared by a thread group.
Function Function parameters and non-static local variable declarations Thread Function parameters and local variables are visible only to the function invocation.
Thread-local static (global scope) Thread Thread-local variables have separate instances per thread.
Input Entry point input parameters (non-uniform) Thread Entry point inputs to a graphics shader stage come from the system and the previous stage.
Output Entry point output parameters
Entry point return value
Thread Entry point outputs from a graphics shader stage are inputs to the next stage.
Specialization constant [SpecializationConstant]
[vk::specialization_constant]
All threads Vulkan specialization constants have values that are fixed at pipeline creation time.
Host None Host process The host address space is used by the host program. This is typically the virtual address space of the application process. The host address space is not usually directly accessible by a Slang program, except when the program is compiled for the C++ target.

📝 Remark 1: Address spaces specific to graphics pipeline stages are not enumerated here. See Graphics Shaders and Compute Kernels for a description.

📝 Remark 2: A pointer to memory in one address space is generally not interchangeable with a pointer to memory in another address space. In particular, pointers to group-shared memory are not interchangeable between thread groups.

📝 Remark 3: Address spaces in Slang are roughly equivalent to SPIR-V storage classes.