Skip to main content

F64

Constant F64 

Source
pub const F64: &str = r#"const WORKGROUP_SIZE: u32 = {{WORKGROUP_SIZE}}u;

struct VertexRaw {
    data: array<f32, 12u>,
};

struct ScatterParams {
    color: vec4<f32>,
    point_size: f32,
    count: u32,
    lod_stride: u32,
    has_sizes: u32,
    has_colors: u32,
    color_stride: u32,
};

struct IndirectArgs {
    vertex_count: atomic<u32>,
    instance_count: u32,
    first_vertex: u32,
    first_instance: u32,
};

@group(0) @binding(0)
var<storage, read> buf_x: array<f64>;

@group(0) @binding(1)
var<storage, read> buf_y: array<f64>;

@group(0) @binding(2)
var<storage, read_write> out_vertices: array<VertexRaw>;

@group(0) @binding(3)
var<uniform> params: ScatterParams;

@group(0) @binding(4)
var<storage, read> buf_sizes: array<f32>;

@group(0) @binding(5)
var<storage, read> buf_colors: array<f32>;

@group(0) @binding(6)
var<storage, read_write> indirect: IndirectArgs;

@compute @workgroup_size(WORKGROUP_SIZE)
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
    let idx = gid.x;
    if (idx >= params.count) {
        return;
    }
    let stride = max(params.lod_stride, 1u);
    if ((idx % stride) != 0u) {
        return;
    }

    let px = f32(buf_x[idx]);
    let py = f32(buf_y[idx]);

    var v_color = params.color;
    if (params.has_colors != 0u) {
        let base = idx * params.color_stride;
        let r = buf_colors[base];
        let g = buf_colors[base + 1u];
        let b = buf_colors[base + 2u];
        let a = if params.color_stride > 3u {
            buf_colors[base + 3u]
        } else {
            1.0
        };
        v_color = vec4<f32>(r, g, b, a);
    }

    let mut marker_size = params.point_size;
    if (params.has_sizes != 0u) {
        marker_size = buf_sizes[idx];
    }

    let corners = array<vec2<f32>, 6u>(
        vec2<f32>(-1.0, -1.0),
        vec2<f32>( 1.0, -1.0),
        vec2<f32>( 1.0,  1.0),
        vec2<f32>(-1.0, -1.0),
        vec2<f32>( 1.0,  1.0),
        vec2<f32>(-1.0,  1.0)
    );
    let out_base = atomicAdd(&(indirect.vertex_count), 6u);
    for (var i: u32 = 0u; i < 6u; i = i + 1u) {
        var vertex: VertexRaw;
        vertex.data[0u] = px;
        vertex.data[1u] = py;
        vertex.data[2u] = 0.0;
        vertex.data[3u] = v_color.x;
        vertex.data[4u] = v_color.y;
        vertex.data[5u] = v_color.z;
        vertex.data[6u] = v_color.w;
        vertex.data[7u] = 0.0;
        vertex.data[8u] = 0.0;
        vertex.data[9u] = marker_size;
        vertex.data[10u] = corners[i].x;
        vertex.data[11u] = corners[i].y;
        out_vertices[out_base + i] = vertex;
    }
}
"#;