Repository: pixijs/pixijs
File: src/rendering/renderers/gpu/texture/GpuTextureSystem.ts (TypeScript)

Code before:
        video: gpuUploadVideoResource,
        compressed: gpuUploadCompressedTextureResource
    };

    private _gpu: GPU;
    private _mipmapGenerator?: GpuMipmapGenerator;

    private readonly _renderer: WebGPURenderer;

    constructor(renderer: WebGPURenderer)
    {
        this._renderer = renderer;
        renderer.renderableGC.addManagedHash(this, '_gpuSources');
        renderer.renderableGC.addManagedHash(this, '_gpuSamplers');
        renderer.renderableGC.addManagedHash(this, '_bindGroupHash');
        renderer.renderableGC.addManagedHash(this, '_textureViewHash');
    }

    protected contextChange(gpu: GPU): void
    {
        this._gpu = gpu;
    }

    public initSource(source: TextureSource): GPUTexture
    {
        let gpuTexture = this._gpuSources[source.uid];

        if (gpuTexture) return gpuTexture;

        if (source.autoGenerateMipmaps)
        {
            const biggestDimension = Math.max(source.pixelWidth, source.pixelHeight);

            source.mipLevelCount = Math.floor(Math.log2(biggestDimension)) + 1;
        }

        let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST;

        if (source.uploadMethodId !== 'compressed')
        {
            usage |= GPUTextureUsage.RENDER_ATTACHMENT;
            usage |= GPUTextureUsage.COPY_SRC;
        }

        const blockData = blockDataMap[source.format] || { blockBytes: 4, blockWidth: 1, blockHeight: 1 };

        const width = Math.ceil(source.pixelWidth / blockData.blockWidth) * blockData.blockWidth;
        const height = Math.ceil(source.pixelHeight / blockData.blockHeight) * blockData.blockHeight;

        const textureDescriptor: GPUTextureDescriptor = {
            label: source.label,

Review comment (suggestion):
heyhey! whilst this is a fixe, the deeper issue is that initSource should not be called if the texture already exists. would love for us to understand why this is being called each time

Code after:
        video: gpuUploadVideoResource,
        compressed: gpuUploadCompressedTextureResource
    };

    private _gpu: GPU;
    private _mipmapGenerator?: GpuMipmapGenerator;

    private readonly _renderer: WebGPURenderer;

    constructor(renderer: WebGPURenderer)
    {
        this._renderer = renderer;
        renderer.renderableGC.addManagedHash(this, '_gpuSources');
        renderer.renderableGC.addManagedHash(this, '_gpuSamplers');
        renderer.renderableGC.addManagedHash(this, '_bindGroupHash');
        renderer.renderableGC.addManagedHash(this, '_textureViewHash');
    }

    protected contextChange(gpu: GPU): void
    {
        this._gpu = gpu;
    }

    /**
     * Initializes a texture source, if it has already been initialized nothing will happen.
     * @param source - The texture source to initialize.
     * @returns The initialized texture source.
     */
    public initSource(source: TextureSource): GPUTexture
    {
        if (this._gpuSources[source.uid])
        {
            return this._gpuSources[source.uid];
        }

        return this._initSource(source);
    }

    private _initSource(source: TextureSource): GPUTexture
    {
        if (source.autoGenerateMipmaps)
        {
            const biggestDimension = Math.max(source.pixelWidth, source.pixelHeight);

            source.mipLevelCount = Math.floor(Math.log2(biggestDimension)) + 1;
        }

        let usage = GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST;

        if (source.uploadMethodId !== 'compressed')
        {