-
Notifications
You must be signed in to change notification settings - Fork 0
Programs
GPULang allows for program assembly to take place during compile time, and provides a suite of validation to make sure your shader combinations can actually translate to a pipeline object at runtime.
To declare a program, write:
program MyProgram
{
...
};
A program can compose different shaders and a render state into a semi-complete pipeline object.
render_state MyRenderState
{
DepthTest = true;
};
program MyProgram
{
RenderState = MyRenderState;
VertexShader = MyVertexShader;
PixelShader = MyPixelShader;
};
The above example will setup a program using MyVertexShader and MyPixelShader, using the render state called MyRenderState to compose a partially complete pipeline object. GPULang will then validate the bindings between these two shaders to ensure compatibility, and generate the necessary target language code for these shaders.
GPULang also defines the gplIsXShader
constant depending on the slot the function is assigned to.
GPULang will not try to change the interface between the shaders in a program for the sake of keeping a consistent interface.
To bind a shader to a program, a function must be declared as entry_point
. Example:
entry_point
MyPixelShader(
in UV : f32x2
) void
{
var color = textureSample(Albedo, Sampler, UV);
gplExportColor(color, Framebuffer.Color);
}
GPULang also allows a program to override const
qualified global values, example:
enum ShaderMode
{
OutputLocalInvocationIndex,
OutputSpecializedVector
};
const Mode : ShaderMode = ShaderMode.OutputLocalInvocationIndex;
...
program TestProgram
{
ComputeShader = ComputeWithStore;
Mode = ShaderMode.OutputLocalInvocationIndex;
};
program TestProgram2
{
ComputeShader = ComputeWithStore;
Mode = ShaderMode.OutputSpecializedVector;
};
Both program TestProgram
and TestProgram2
will execute the same shader, but will have different values generated for Mode
. This allows for very simple shader generation at compile time.