Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
SnapshotUnpremultiplySource.h File Reference

Authoritative WGSL for the snapshot readback unpremultiply pass. More...

#include "donner/gpu/shader/wgsl/Compiler.h"
Include dependency graph for SnapshotUnpremultiplySource.h:

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Variables

constexpr wgsl::SourceText donner::gpu::shader::programs::kSnapshotUnpremultiplySource
 Authoritative WGSL for the snapshot readback unpremultiply pass.

Detailed Description

Authoritative WGSL for the snapshot readback unpremultiply pass.

Variable Documentation

◆ kSnapshotUnpremultiplySource

wgsl::SourceText donner::gpu::shader::programs::kSnapshotUnpremultiplySource
inlineconstexpr
Initial value:
{
R"wgsl(@group(0) @binding(0) var inputTexture: texture_2d<f32>;
@group(0) @binding(1) var outputTexture: texture_storage_2d<rgba8unorm, write>;
@compute @workgroup_size(8, 8, 1)
fn cs_main(@builtin(global_invocation_id) gid: vec3<u32>) {
let extent = min(textureDimensions(inputTexture), textureDimensions(outputTexture));
if (any((gid.xy >= extent))) {
return;
}
let coords = vec2<i32>(gid.xy);
let premul = textureLoad(inputTexture, coords, 0i);
let r8 = u32(round((premul.x * 255f)));
let g8 = u32(round((premul.y * 255f)));
let b8 = u32(round((premul.z * 255f)));
let a8 = u32(round((premul.w * 255f)));
var sr: u32 = 0u;
var sg: u32 = 0u;
var sb: u32 = 0u;
if ((a8 != 0u)) {
let halfAlpha = (a8 >> 1u);
sr = min(255u, (((r8 * 255u) + halfAlpha) / a8));
sg = min(255u, (((g8 * 255u) + halfAlpha) / a8));
sb = min(255u, (((b8 * 255u) + halfAlpha) / a8));
}
let straight = vec4<f32>((f32(sr) / 255f), (f32(sg) / 255f), (f32(sb) / 255f), (f32(a8) / 255f));
textureStore(outputTexture, coords, straight);
}
)wgsl"}

Authoritative WGSL for the snapshot readback unpremultiply pass.