Source browser
examples/shaders/evt3_seed.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// Resolve inter-block dependencies using small summaries, retaining stream state.
2#ifdef __cplusplus // Include the runtime only when compiling the CPU adapter.
3#include "shdr.h" // Share the portable resource and math declarations.
4#endif // Finish the C++ declaration include guard.
5layout(local_size_x = 1) in; // Use one invocation for this ordered stream-state operation.
6layout(std430, binding = 0) readonly buffer Summaries { // Exchange compact block summaries between decoder stages.
7 uvec4 summaries[]; // Store three state and event-count records per input block.
8}; // Finish this shader storage resource declaration.
9layout(std430, binding = 1) writeonly buffer Seeds { // Exchange the decoder state preceding each block.
10 uvec4 seeds[]; // Store the two decoder-state records preceding each block.
11}; // Finish this shader storage resource declaration.
12layout(std430, binding = 2) writeonly buffer Sizes { // Write event counts used to allocate exclusive output intervals.
13 uint sizes[]; // Store the synchronized event count of each input block.
14}; // Finish this shader storage resource declaration.
15layout(std430, binding = 3) buffer State { // Access decoder state retained across input chunks.
16 uvec4 stream_state[]; // Retain pixel, vector and timestamp state between input chunks.
17}; // Finish this shader storage resource declaration.
18uniform uint blocks; // Receive the number of summarized input blocks.
19
20void main() { // Resolve block seeds in order and advance persistent decoder state.
21 // a=(Y+camera, vector X, vector polarity, high time), z=(low time, wraps, synchronized, reserved).
22 uvec4 a = stream_state[0], z = stream_state[1]; // Load pixel and high-time state together with low time, wraps and synchronization.
23 for (uint b = 0u; b < blocks; ++b) { // Carry each small summary into the following block's initial state.
24 seeds[2u * b] = a; // Save the pixel and high-time state preceding this block.
25 seeds[2u * b + 1u] = z; // Save low time, rollover count and synchronization preceding this block.
26 uvec4 last = summaries[3u * b], meta = summaries[3u * b + 1u], // Read the final state fields and replacement metadata for this block.
27 count = summaries[3u * b + 2u]; // Read the total and newly synchronized event counts.
28 sizes[b] = z.z != 0u ? count.x : count.y; // Include all events only when the stream was already synchronized.
29 if ((meta.w & 1u) != 0u) // Replace Y and camera state only if the block supplied them.
30 a.x = last.x; // Carry the final Y-coordinate and camera bit to later blocks.
31 if ((meta.w & 2u) != 0u) { // Replace vector state when this block supplied a new vector base.
32 a.y = last.y; // Carry the final vector X-coordinate to later blocks.
33 a.z = last.z; // Carry the final vector polarity to later blocks.
34 } else // Preserve the old vector base when this block only advanced mask positions.
35 a.y = (a.y + last.y) & 2047u; // Apply the block's net vector-base advance with eleven-bit wrapping.
36 if ((meta.w & 4u) != 0u) { // Update high time and synchronization when this block supplied high-time words.
37 uint cross = (z.z != 0u && a.w > meta.z && a.w - meta.z >= 4085u) ? 1u : 0u; // Detect a timestamp rollover between the preceding state and this block's first high time.
38 z.y += meta.y + cross; // Accumulate internal and cross-block 24-bit timestamp rollovers.
39 a.w = last.w; // Carry the last high timestamp payload forward.
40 z.z = 1u; // Mark the stream as synchronized after receiving high time.
41 } // Finish this decoder or fitting branch.
42 if ((meta.w & 8u) != 0u) // Replace low time only when this block changed timestamp state.
43 z.x = meta.x; // Carry the final low timestamp payload forward.
44 } // Finish this decoder or fitting branch.
45 stream_state[0] = a; // Save pixel, vector and high-time state for the next input chunk.
46 stream_state[1] = z; // Save low time, rollover count and synchronization for the next chunk.
47} // Finish this decoder or fitting branch.