LCOV - demo-cpu.info - shader-coverage-demo/simulate.slang

LCOV - code coverage report
Current view: | top level - shader-coverage-demo - simulate.slang |  |  | Coverage | Total | Hit
Test: | demo-cpu.info |  | Lines: | 83.3 % | 12 | 10
Test Date: | 2026-04-24 16:05:06 |  | Functions: | - | 0 | 0

                Line data    Source code
           1              : // simulate.slang — particle physics compute kernel entry point.
           2              : //
           3              : // The per-type physics helpers (`applyGravity`, `stepFluid`,
           4              : // `stepGas`, `stepSolid`) and the `Particle` struct live in
           5              : // `physics.slang` as a separate module. When `-trace-coverage` is
           6              : // on, counters are attributed to whichever file each statement
           7              : // came from, so the resulting LCOV report spans BOTH files — one
           8              : // `SF:` record per file, each with its own per-line hit counts.
           9              :
          10              : import physics;
          11              :
          12              : // Particle type discriminants. Matches the `PARTICLE_TYPE_*` enum
          13              : // on the host side.
          14              : static const uint PARTICLE_TYPE_FLUID = 0;
          15              : static const uint PARTICLE_TYPE_GAS   = 1;
          16              : static const uint PARTICLE_TYPE_SOLID = 2;
          17              :
          18              : //TEST_INPUT: set particles = out ubuffer(data=[], stride=32)
          19              : RWStructuredBuffer<Particle> particles;
          20              :
          21              : //TEST_INPUT: set params = ubuffer(data=[0], stride=4)
          22              : cbuffer Params
          23              : {
          24              :     uint  particleCount;
          25              :     float dt;
          26              : }
          27              :
          28              : [numthreads(64, 1, 1)]
          29              : void computeMain(uint3 tid : SV_DispatchThreadID)
          30              : {
          31         1536 :     uint i = tid.x;
          32          512 :     if (i >= particleCount)
          33            0 :         return;
          34              :
          35          512 :     Particle p = particles[i];
          36              :
          37          512 :     if (p.type == PARTICLE_TYPE_FLUID)
          38              :     {
          39          352 :         stepFluid(p, dt);
          40              :     }
          41          336 :     else if (p.type == PARTICLE_TYPE_GAS)
          42              :     {
          43          336 :         stepGas(p, dt);
          44              :     }
          45          168 :     else if (p.type == PARTICLE_TYPE_SOLID)
          46              :     {
          47          336 :         stepSolid(p, dt);
          48              :     }
          49              :     else
          50              :     {
          51              :         // Unknown type — flag for host-side triage. This branch is
          52              :         // intentionally unreachable in the "normal" test scenarios;
          53              :         // the coverage report will show it uncovered, demonstrating
          54              :         // that the instrumentation spots dead code.
          55            0 :         p.flags |= 0x1u;
          56              :     }
          57              :
          58          512 :     particles[i] = p;
          59              : }

Generated by: LCOV version 2.4-0