Source browser

examples/shaders/rle_offsets.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// Serial prefix stage for a small tile table, independent encoders use these offsets.
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.
5layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; // Group 1 independent invocations along x.
6layout(std430, binding = 0) readonly buffer Sizes { // Read the size of each independently processed tile through buffer binding 0.
7    uint sizes[]; // Store the size of each independently processed tile.
8}; // Finish this declaration.
9layout(std430, binding = 1) writeonly buffer Offsets { // Write exclusive tile offsets followed by the complete payload size through buffer binding 1.
10    uint offsets[]; // Store exclusive tile offsets followed by the complete payload size.
11}; // Finish this declaration.
12uniform uint blocks; // Set the number of tile sizes to include in the prefix calculation.
13void main() { // Compute exclusive cumulative offsets for the input tile sizes.
14    uint sum = 0u; // Start the cumulative size at zero.
15    offsets[0] = 0u; // Place the first tile at the beginning of the destination.
16    for (uint b = 0u; b < blocks; ++b) { // Visit every tile size in original order.
17        sum += sizes[b]; // Add this tile's size in the caller's selected units.
18        offsets[b + 1u] = sum; // Write the next tile's exclusive start and the final total after the last tile.
19    } // End this block.
20} // End this block.