import '../../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * TODO: doc
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import { alpenglow, Binding, BindingLocation, BufferBinding, BufferSlot, webgpu } from '../../imports.js';
export default class BindGroupLayout {
    constructor(deviceContext, name, groupIndex, bindingDescriptors) {
        this.deviceContext = deviceContext;
        this.name = name;
        this.groupIndex = groupIndex;
        this.bindingDescriptors = bindingDescriptors;
        this.layout = webgpu.deviceCreateBindGroupLayout(deviceContext.device, {
            label: `${name} bind group layout`,
            entries: bindingDescriptors.map(binding => binding.getBindGroupLayoutEntry())
        });
        this.bindings = bindingDescriptors.map(bindingDescriptor => {
            const location = new BindingLocation(groupIndex, bindingDescriptor.bindingIndex);
            if (bindingDescriptor.slot instanceof BufferSlot) {
                return new BufferBinding(location, bindingDescriptor.bindingType, bindingDescriptor.slot);
            }
            else {
                return new Binding(location, bindingDescriptor.bindingType, bindingDescriptor.slot);
            }
        });
    }
    hasBindingWithSlot(slot) {
        return this.bindings.some(binding => binding.slot === slot);
    }
    getBindingFromSlot(slot) {
        return this.bindings.find(binding => binding.slot === slot) || null;
    }
}
alpenglow.register('BindGroupLayout', BindGroupLayout);
//# sourceMappingURL=BindGroupLayout.js.map