Harbor

branch main
showing the latest snapshot on main
compute_basic.luma 792 B · Plain text
shader/tests/shaders/compute_basic.luma 0644 Raw
-- Basic compute shader test
-- Exercises: shared memory, barrier(), compute builtins, workgroup_size, buffer binding

struct Params
	count: uint
	scale: float
end

struct DataBuffer
	values: [64]float
end

@group(0) @binding(0) buffer params: Params
@group(0) @binding(1) buffer data: DataBuffer

shared scratch: [64]float

@entry(compute)
@workgroup_size(64, 1, 1)
function main(
	@builtin(global_invocation_id) global_id: uvec3,
	@builtin(local_invocation_id) local_id: uvec3
)
	let idx = local_id.x

	-- Load data into shared memory
	scratch[idx] = data.values[idx] * params.scale

	barrier()

	-- Simple parallel reduction step: add neighbor
	if idx < 32 then
		scratch[idx] = scratch[idx] + scratch[idx + 32]
	end

	barrier()

	-- Write result back
	data.values[idx] = scratch[idx]
end