@group(0) @binding(0)
var<storage, read> gridHashes: array<u32>;

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

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

@group(0) @binding(3)
var<storage, read_write> endIndices: array<u32>;

@group(0) @binding(4)
var<uniform> totalCount: u32;

@compute @workgroup_size(256)
fn findStartEndIndices(@builtin(global_invocation_id) globalId: vec3<u32>) {

	let i = globalId.x;

	if (i >= totalCount) {
		return;
	}
	
	let currentHash		= gridHashes[i];

	if (i == 0u || gridHashes[i - 1u] != currentHash) {

		startIndices[currentHash] = i;

	}


	if (i == totalCount - 1u || gridHashes[i + 1u] != currentHash) {

		endIndices[currentHash] = i;
		
	}

}