-
Notifications
You must be signed in to change notification settings - Fork 0
Binding interface
Putting a variable in the binding interface is as simple as declaring a pointer in the global scope. Only interface bindable types, such as structs, textures, samplers and acceleration structures are allowed to be declared as such.
All bindable variables can be categorized put in different groups (descriptor sets/root tables) by using the group(N)
attribute, where N
denotes the binding group to use. To select a specific slot, or to alias multiple bindings within a group, use the binding(M)
attribute to bind a variable within group N
to slot M
. By default, the group is implicitly 0, and the binding is an automatically increasing value within that group if nothing else is specified.
To express a binding of a buffer to a shader, first create a struct, for example:
struct Camera
{
viewProjection : f32x4x4;
position : f32x4;
};
And then declare a pointer to that struct:
uniform camera: *Camera;
This will cause GPULang to generate the code necessary to make Camera part of the binding interface, in this case a uniform/constant buffer. Do not be misled by the usage of the 'uniform' keyword here though. uniform
here merely means the storage of camera
, which is set to be uniformely identical across all shaders in a work group. In this case, we are saying that the binding of camera
is the same across all work groups.
Changing the type of a buffer to be writeable is done in the above example by making the type mutable
:
uniform camera: *mutable Camera;
Think of it as being a "pointer to a mutable Camera identical within a workgroup".
With the syntax for buffers in mind, expressing textures is done in the same way. A typical texture which supports sampling but not reading is:
uniform albedo: *texture2D;
This type of texture will require a sampler before sampling can take place. They are defined as:
uniform albedoSampler: *sampler;
To sample from 'albedo' using 'albedoSampler', we pass them to textureSample
:
textureSample(albedo, albedoSampler, uv);
GPULang also supports combined textures and samplers:
uniform albedo: *sampled texture2D;
For textures of this type, there is a separate set of textureSample
intrinsics which accept sampled texture types:
textureSample(albedo, uv);
To make it a writeable texture, simply add mutable
to the type:
uniform albedo: *mutable texture2D;