Harbor

branch main
showing the latest snapshot on main
compute_basic.msl 661 B · Plain text
gpu/shader/tests/golden/compute_basic.msl 0644 Raw
#include <metal_stdlib>
using namespace metal;

struct Params {
	uint count;
	float scale;
};

struct DataBuffer {
	array<float, 64> values;
};

kernel void main(uint3 global_id [[thread_position_in_grid]],
	uint3 local_id [[thread_position_in_threadgroup]],
	device Params* params [[buffer(0)]],
	device DataBuffer* data [[buffer(1)]]) {
	threadgroup float scratch[64];
	
	uint idx = local_id.x;
	scratch[idx] = (data.values[idx] * params.scale);
	threadgroup_barrier(mem_flags::mem_threadgroup);
	if ((idx < 32)) {
		scratch[idx] = (scratch[idx] + scratch[(idx + 32)]);
	}
	threadgroup_barrier(mem_flags::mem_threadgroup);
	data.values[idx] = scratch[idx];
}