Debian Codegraph @

Sources/nCine/Graphics/RHI/Software/SwScanlineOps.h

raw
1 #pragma once
2
3 #if defined(WITH_RHI_SOFTWARE)
4
5 #include <cstdint>
6
7 namespace nCine::RHI::Software
8 {
9 // CPU-dispatched scanline operations shared by the immediate rasterizer (SwRaster.cpp, which owns the
10 // implementations and their SSE2/AVX2/NEON/SIMD128 variants) and the tile rasterizer (SwTileRasterizer.cpp).
11 // Both hot loops must run the same best-for-this-CPU code path; keeping a per-TU copy caused the tile path -
12 // the one that renders nearly every frame - to fall back to scalar on x86.
13
14 /** @brief Blends a scanline of RGBA8 pixels over the destination with SrcAlpha/OneMinusSrcAlpha factors */
15 void BlendScanlineSrcAlpha(std::uint8_t* dst, const std::uint8_t* src, std::int32_t count);
16
17 /**
18 * @brief Looks up a scanline of consecutive R8 palette-index bytes in a 256-entry packed-RGBA LUT and
19 * blends the results over the destination with SrcAlpha/OneMinusSrcAlpha factors
20 *
21 * The fused form of "gather + palette LUT into a staging row, then @ref BlendScanlineSrcAlpha" for the
22 * dominant tile/sprite draw (1:1-mapped R8 index texture, constant source alpha - `packed[idx]` is the
23 * final pixel). Bit-identical to that two-pass form, including the `0` / `255` alpha shortcuts; a
24 * transparent texel never touches the destination. The AVX2 variant gathers 8 LUT entries per step.
25 */
26 void FusedLutBlendScanline(std::uint8_t* dst, const std::uint8_t* srcIdx, std::int32_t count, const std::uint8_t (*packed)[4]);
27
28 /** @brief Multiplies a scanline of RGBA8 pixels in place by a constant color (values 0-256 per channel) */
29 void TintScanline(std::uint8_t* buf, std::int32_t count, std::int32_t tR, std::int32_t tG, std::int32_t tB, std::int32_t tA);
30
31 /**
32 * @brief Blends one constant RGBA8 source color over a scanline with SrcAlpha/OneMinusSrcAlpha factors
33 *
34 * The solid (no-texture) fill path: every destination pixel receives `(src * a + dst * (255 - a)) >> 8`
35 * per channel with the alpha channel using `(a * 255 + dst.a * (255 - a)) >> 8` - bit-identical to the
36 * per-pixel fast-blend the tile rasterizer runs, including the destination alpha. `src[3]` is expected
37 * in `(0, 255)`; the fully transparent / fully opaque shortcuts are the caller's (skip / plain fill).
38 */
39 void BlendScanlineConstSrcAlpha(std::uint8_t* dst, std::int32_t count, const std::uint8_t src[4]);
40
41 /**
42 * @brief Applies the dynamic-lighting combine to one row of screen pixels
43 *
44 * The per-row core of @ref SwDevice::ApplyPendingSoftwareLighting(): for each pixel `x` it samples the
45 * half-resolution lightmap row (`lmRow`, 2 floats per texel, indexed by `min(x / scale, lmW - 1)`),
46 * clamps both channels to `[0, 1]` and composites in place:
47 * `lit = main * (1 + g) + max(g - 0.7, 0)`, then `out = mix(lit, ambient, clamp(1 - r, 0, 1))`.
48 * A fully lit texel (`r >= 1`, `g <= 0`) leaves the pixel bytes untouched. The SIMD variants keep the
49 * scalar float operations in the same order, so the output is bit-identical to the scalar loop
50 * (fully lit lanes round-trip exactly; the alpha byte is rewritten with its own value).
51 */
52 void CombineLightingScanline(std::uint8_t* px, std::int32_t width, const float* lmRow, std::int32_t lmW,
53 std::int32_t scale, float ambR, float ambG, float ambB);
54 }
55
56 #endif