import { native_ } from './Constants';
import { GPUCommandBuffer } from './GPUCommandBuffer';
import { GPUComputePassEncoder } from './GPUComputePassEncoder';
import { GPURenderPassEncoder } from './GPURenderPassEncoder';
import { parseComputePassDescriptor, parseRenderPassDescriptor } from './Utils';
export class GPUCommandEncoder {
    get label() {
        return this[native_]?.label ?? '';
    }
    static fromNative(encoder) {
        if (encoder) {
            const ret = new GPUCommandEncoder();
            ret[native_] = encoder;
            return ret;
        }
        return null;
    }
    beginComputePass(descriptor) {
        const desc = parseComputePassDescriptor(descriptor);
        return GPUComputePassEncoder.fromNative(this[native_].beginComputePass(desc));
    }
    beginRenderPass(descriptor) {
        const desc = parseRenderPassDescriptor(descriptor);
        const passEncoder = this[native_].beginRenderPass(desc);
        return GPURenderPassEncoder.fromNative(passEncoder);
    }
    clearBuffer(buffer, offset, size) {
        this[native_].clearBuffer(buffer[native_], offset ?? -1, size ?? -1);
    }
    copyBufferToBuffer(source, sourceOffset, destination, destinationOffset, size) {
        this[native_].copyBufferToBuffer(source[native_], sourceOffset, destination[native_], destinationOffset, size);
    }
    copyBufferToTexture(source, destination, copySize) {
        const src = {
            buffer: source.buffer[native_],
            bytesPerRow: source.bytesPerRow,
        };
        if (typeof source.offset === 'number') {
            src.offset = source.offset;
        }
        if (typeof source.rowsPerImage === 'number') {
            src.rowsPerImage = source.rowsPerImage;
        }
        const dst = {
            texture: destination.texture[native_],
        };
        if (destination.aspect) {
            dst.aspect = destination.aspect;
        }
        if (typeof destination.mipLevel === 'number') {
            dst.mipLevel = destination.mipLevel;
        }
        if (destination.origin) {
            dst.origin = destination.origin;
        }
        let size;
        if (Array.isArray(copySize)) {
            size = {
                width: copySize[0],
                height: copySize[1] ?? 1,
                depthOrArrayLayers: copySize[2] ?? 1,
            };
        }
        else {
            size = { ...copySize };
        }
        this[native_].copyBufferToTexture(src, dst, size);
    }
    copyTextureToBuffer(source, destination, copySize) {
        const src = {
            texture: source.texture[native_],
        };
        if (source.aspect) {
            src.aspect = source.aspect;
        }
        if (typeof source.mipLevel === 'number') {
            src.mipLevel = source.mipLevel;
        }
        if (source.origin) {
            src.origin = source.origin;
        }
        const dst = {
            buffer: destination.buffer[native_],
            bytesPerRow: destination.bytesPerRow,
        };
        if (typeof destination.offset === 'number') {
            dst.offset = destination.offset;
        }
        if (typeof destination.rowsPerImage === 'number') {
            dst.rowsPerImage = destination.rowsPerImage;
        }
        let size;
        if (Array.isArray(copySize)) {
            size = {
                width: copySize[0],
                height: copySize[1] ?? 1,
                depthOrArrayLayers: copySize[2] ?? 1,
            };
        }
        else {
            size = { ...copySize };
        }
        this[native_].copyTextureToBuffer(src, dst, size);
    }
    copyTextureToTexture(source, destination, copySize) {
        const src = {
            texture: source.texture[native_],
        };
        if (source.aspect) {
            src.aspect = source.aspect;
        }
        if (typeof source.mipLevel === 'number') {
            src.mipLevel = source.mipLevel;
        }
        if (source.origin) {
            src.origin = source.origin;
        }
        const dst = {
            texture: destination.texture[native_],
        };
        if (destination.aspect) {
            dst.aspect = destination.aspect;
        }
        if (typeof destination.mipLevel === 'number') {
            dst.mipLevel = destination.mipLevel;
        }
        if (destination.origin) {
            dst.origin = destination.origin;
        }
        let size;
        if (Array.isArray(copySize)) {
            size = {
                width: copySize[0],
                height: copySize[1] ?? 1,
                depthOrArrayLayers: copySize[2] ?? 1,
            };
        }
        else {
            size = { ...copySize };
        }
        this[native_].copyTextureToTexture(src, dst, size);
    }
    finish(descriptor) {
        const ret = this[native_].finish(descriptor);
        return GPUCommandBuffer.fromNative(ret);
    }
    insertDebugMarker(markerLabel) {
        this[native_].insertDebugMarker(markerLabel);
    }
    popDebugGroup() {
        this[native_].popDebugGroup();
    }
    pushDebugGroup(groupLabel) {
        this[native_].pushDebugGroup(groupLabel);
    }
    resolveQuerySet(querySet, firstQuery, queryCount, destination, destinationOffset) {
        this[native_].resolveQuerySet(querySet[native_], firstQuery, queryCount, destination[native_], destinationOffset);
    }
    writeTimestamp(querySet, queryIndex) {
        this[native_].writeTimestamp(querySet[native_], queryIndex);
    }
}
//# sourceMappingURL=GPUCommandEncoder.js.map