shadow$provide.module$node_modules$pixi_DOT_js$lib$rendering$renderers$gpu$buffer$GpuBufferSystem = function(global, require, module, exports) {
  global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
  var GCManagedHash = require("module$node_modules$pixi_DOT_js$lib$utils$data$GCManagedHash"), uid = require("module$node_modules$pixi_DOT_js$lib$utils$data$uid"), fastCopy = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$buffer$utils$fastCopy");
  "use strict";
  class GpuBufferData {
    constructor(gpuBuffer) {
      this.gpuBuffer = gpuBuffer;
    }
    destroy() {
      this.gpuBuffer.destroy();
      this.gpuBuffer = null;
    }
  }
  class GpuBufferSystem {
    constructor(renderer) {
      this._renderer = renderer;
      this._managedBuffers = new GCManagedHash.GCManagedHash({renderer, type:"resource", onUnload:this.onBufferUnload.bind(this), name:"gpuBuffer"});
    }
    contextChange(gpu) {
      this._gpu = gpu;
    }
    getGPUBuffer(buffer) {
      buffer._gcLastUsed = this._renderer.gc.now;
      return buffer._gpuData[this._renderer.uid]?.gpuBuffer || this.createGPUBuffer(buffer);
    }
    updateBuffer(buffer) {
      const gpuBuffer = this.getGPUBuffer(buffer), data = buffer.data;
      buffer._updateID && data && (buffer._updateID = 0, this._gpu.device.queue.writeBuffer(gpuBuffer, 0, data.buffer, 0, (buffer._updateSize || data.byteLength) + 3 & -4));
      return gpuBuffer;
    }
    destroyAll() {
      this._managedBuffers.removeAll();
    }
    onBufferUnload(buffer) {
      buffer.off("update", this.updateBuffer, this);
      buffer.off("change", this.onBufferChange, this);
    }
    createGPUBuffer(buffer) {
      const gpuBuffer = this._gpu.device.createBuffer(buffer.descriptor);
      buffer._updateID = 0;
      buffer._resourceId = uid.uid("resource");
      buffer.data && (fastCopy.fastCopy(buffer.data.buffer, gpuBuffer.getMappedRange(), buffer.data.byteOffset, buffer.data.byteLength), gpuBuffer.unmap());
      buffer._gpuData[this._renderer.uid] = new GpuBufferData(gpuBuffer);
      this._managedBuffers.add(buffer) && (buffer.on("update", this.updateBuffer, this), buffer.on("change", this.onBufferChange, this));
      return gpuBuffer;
    }
    onBufferChange(buffer) {
      this._managedBuffers.remove(buffer);
      buffer._updateID = 0;
      this.createGPUBuffer(buffer);
    }
    destroy() {
      this._managedBuffers.destroy();
      this._gpu = this._renderer = null;
    }
  }
  GpuBufferSystem.extension = {type:[global.ExtensionType.WebGPUSystem], name:"buffer"};
  exports.GpuBufferData = GpuBufferData;
  exports.GpuBufferSystem = GpuBufferSystem;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$rendering$renderers$gpu$buffer$GpuBufferSystem.js.map
