import '../../../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * Calculates a histogram in shared (workgroup) memory by using atomics
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import { alpenglow, COALESCED_LOOP_DEFAULTS, coalescedLoopWGSL, commentWGSL, wgsl } from '../../../imports.js';
import { optionize3 } from '../../../../../phet-core/js/optionize.js';
export const HISTOGRAM_DEFAULTS = {
    ...COALESCED_LOOP_DEFAULTS // eslint-disable-line phet/no-object-spread-on-non-literals
};
const histogramWGSL = (providedOptions) => {
    const options = optionize3()({}, HISTOGRAM_DEFAULTS, providedOptions);
    return wgsl `
    ${commentWGSL('begin histogram')}
    {
      ${coalescedLoopWGSL({
        workgroupSize: options.workgroupSize,
        grainSize: options.grainSize,
        lengthExpression: options.lengthExpression,
        workgroupIndex: options.workgroupIndex,
        localIndex: options.localIndex,
        callback: (localIndex, dataIndex) => wgsl `
          atomicAdd( &${options.histogramScratch}[ ${options.getBin(dataIndex)} ], 1u );
        `
    })}
    }
    ${commentWGSL('end histogram')}
  `;
};
export default histogramWGSL;
alpenglow.register('histogramWGSL', histogramWGSL);
//# sourceMappingURL=histogramWGSL.js.map