Source browser
examples/shaders/rle_decode.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// Reconstruct each tile from its compact range, preserving every input sample bit.
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 = 64, local_size_y = 1, local_size_z = 1) in; // Group 64 independent invocations along x.
6layout(std430, binding = 0) readonly buffer Encoded { // Read alternating original values and unsigned run lengths through buffer binding 0.
7 uint encoded[]; // Store alternating original values and unsigned run lengths.
8}; // Finish this declaration.
9layout(std430, binding = 1) readonly buffer Offsets { // Read 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.
12layout(std430, binding = 2) writeonly buffer Restored { // Write the losslessly reconstructed unsigned values through buffer binding 2.
13 uint restored[]; // Store the losslessly reconstructed unsigned values.
14}; // Finish this declaration.
15uniform uint count; // Limit work to the valid element count, including a partial final workgroup.
16uniform uint block_size; // Limit each independent encoder or decoder to this many original values.
17void main() { // Reconstruct one original tile from its encoded value and run-length pairs.
18 uint block = gl_GlobalInvocationID.x; // Assign one independent output tile to this invocation.
19 uint begin = block * block_size; // Locate this tile's first reconstructed value.
20 if (begin >= count) // Ignore workgroup padding after the final tile.
21 return; // Stop this invocation before performing another resource access.
22 uint write_position = begin; // Write restored values into their original tile positions.
23 for (uint i = offsets[block]; i < offsets[block + 1u]; i += 2u) { // Visit each encoded value and run-length pair in this tile's prefix range.
24 uint value = encoded[i]; // Read the exact unsigned value recorded by the encoder.
25 uint run = encoded[i + 1u]; // Read the number of repetitions of that value.
26 for (uint j = 0u; j < run && write_position < count; ++j) // Expand the run while respecting the actual original input length.
27 restored[write_position++] = value; // Restore one original value and advance to the next destination.
28 } // End this block.
29} // End this block.