Harbor

branch main
showing the latest snapshot on main
compute_basic.wgsl 641 B · Plain text
shader/tests/golden/compute_basic.wgsl 0644 Raw
var<workgroup> scratch: array<f32, 64>;

struct Params {
	count: u32,
	scale: f32,
}

@group(0) @binding(0) var<storage, read_write> params: Params;
struct DataBuffer {
	values: array<f32, 64>,
}

@group(0) @binding(1) var<storage, read_write> data: DataBuffer;

@compute @workgroup_size(64, 1, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>, @builtin(local_invocation_id) local_id: vec3<u32>) {
	let idx = local_id.x;
	scratch[idx] = (data.values[idx] * params.scale);
	workgroupBarrier();
	if ((idx < 32)) {
		scratch[idx] = (scratch[idx] + scratch[(idx + 32)]);
	}
	workgroupBarrier();
	data.values[idx] = scratch[idx];
}