Source browser

examples/shaders/affine.cpp

Read the complete file below or download its original bytes. Line numbers provide stable links to a declaration or processing step.

File fingerprint
1// Apply a scale and offset to a buffer. The build embeds this native GLSL and generates its C++11 CPU adapter.
2#ifdef __cplusplus // Expose host declarations only when a C++ compiler reads this shader.
3#include "shdr.h" // Include shdr.h declarations.
4#endif // Finish this conditional compilation branch.
5
6layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; // Group 64 independent invocations along x.
7layout(std430, binding = 0) readonly buffer Storage_input_values { // Read the preceding stage's input elements through buffer binding 0.
8    float input_values[]; // Store the preceding stage's input elements.
9}; // Finish this declaration.
10layout(std430, binding = 1) writeonly buffer Storage_output_values { // Write this stage's output elements through buffer binding 1.
11    float output_values[]; // Store this stage's output elements.
12}; // Finish this declaration.
13uniform uint count; // Limit work to the valid element count, including a partial final workgroup.
14uniform float scale; // Multiply each input value by this scalar gain.
15uniform float offset; // Add this bias after scaling the input.
16
17void main() { // Apply the configured scale and offset to one input element.
18    uint i = gl_GlobalInvocationID.x; // Select this invocation's global x coordinate.
19    if (i < count) { // Ignore padding invocations in the final workgroup.
20        output_values[i] = input_values[i] * scale + offset; // Apply the gain and then add the bias, with one independent output per invocation.
21    } // End this block.
22} // End this block.