Skip to content

Annotations and attributes

Gustav Sterbrant edited this page Oct 14, 2024 · 4 revisions

Annotations

Annotations are data ignored by the shader compiler but serialized to the client API for parsing in your application. It allows for a user to annotate objects in the shader code, which can then be read back. Example:

@ShaderVisibility("CS")

Annotations can be either string, float, int, unsigned int or bool.

Attributes

Nearly all symbols in GPULang have a set of allowed attributes based on the type of symbol attached to them.

Scalar attributes

  • const Variable may not change its value after initialization
  • var Variable may change its value after initialization, and is implicit

Binding attributes

  • group Associates an externally provided resources with a certain binding group (descriptor set, root signature table, bind group)
  • binding Either associates an externally provided resource with a binding index within it's binding group, or associates an entry_point input or output with it's corresponding slot

Function attributes

  • entry_point Flags the function as being a shader entry point. It doesn't need to be consumed by a program. Special rules apply to a function of this nature, such as being able to set other function attributes associated with shader linkage.
  • local_size_x(N) Compute shader work group dimension in X. N must be a literal integer value. Valid for entry_point functions.
  • local_size_y(N) Compute shader work group dimension in Y. N must be a literal integer value. Valid for entry_point functions.
  • local_size_z(N) Compute shader work group dimension in Z. N must be a literal integer value. Valid for entry_point functions.
  • early_depth Pixel shader should eliminate if depth test fails before running the shader. Valid for entry_point functions.
  • group_size(N) Compute shader subgroup size. Default is 64. N must be a literal integer value. Valid for entry_point functions.
  • groups_per_workgroup(N) Compute shader subgroups per workgroup. Default is 1. N must be a literal integer value. Valid for entry_point functions.
  • input_vertices(N) Hull/Mesh shader input vertex count. N must be a literal integer value. Valid for entry_point functions.
  • max_output_vertices(N) - Geometry/Mesh/Hull shader max vertex output count. N must be a literal integer value. Valid for entry_point functions.
  • winding(CW/CCW) - Domain shader winding order. Can be either CW (clockwise) or CCW (counter-clockwise) Valid for entry_point functions.
  • input_topology(points/lines/lines_adjacency/triangles/triangles_adjacency/quads/isoline) - Hull/Geometry shader mesh input topology. For Hull shaders, valid values include points/lines/lines_adjacency/triangles_adjacency. For Geometry shaders, valid values include triangles/quads/isolines. Valid for entry_point functions.
  • output_topology(points/lines/triangles) - Geometry shader mesh output topology. Valid for entry_point functions.
  • patch_type(triangles/quads/isolines) - Domain shader patch type. Valid for entry_point functions.
  • partition(integer, fract_even, fract_odd) - Hull shader partitioning method. Valid for entry_point functions.
  • pixel_origin(lower_left/lower/upper_left/upper/center) - Pixel shader origin point. lower_left and lower denote the same mode, as well as upper_left and upper. Valid for entry_point functions.
  • prototype - Flags the function as being bound on a per-program basis.

Parameter attributes

  • in For entry_point parameters, makes up the linking interface with the previous shader or client. Can be combined with binding to assign a specific binding point
  • out Same as for in but for linking with the next shader stage or framebuffer output.
  • patch This parameter comes from a patch produced by a Hull shader. Valid for Domain shader inputs.
  • no_interpolate - This parameter should not undergo any barycentric interpolation at shader start. Valid for Pixel shader inputs and Vertex/Domain/Geometry/Mesh shader outputs.
  • no_perspective - Do not perform perspective correction on input. Valid for Pixel shader inputs and Vertex/Domain/Geometry/Mesh shader outputs.

Pointer attributes

  • no_read For externally provided resources in the global scope, this means the resource cannot be read.

  • atomic Resource manages writes atomically.

  • volatile Accesses to this resource may not be optimized away.

Storage attributes

  • uniform Indicates the value is uniform across a work group.
  • inline Resource reads it's data inline from the command buffer (push constants/root constants).
  • workgroup Value is shared across the workgroup (LDS).
Clone this wiki locally