releasePipeline method

  1. @override
void releasePipeline(
  1. PipelineHandle pipeline
)

Forgets what was built for pipeline's pair and layout once no other handle stands for them: every GPURenderPipeline the draws built in whatever state, and — when the pair has no handle left under any layout — its bind group layouts and the bind groups made from them.

WebGPU has no destroy for a pipeline, a layout or a bind group; they go with their last reference, and the device's caches were that reference for the life of the device. createPipeline is nearly free here and a renderer may ask for one pair twice, so the count keeps a second handle drawing after the first is given back.

Implementation

@override
void releasePipeline(PipelineHandle pipeline) {
  final stages = _heldStages[pipeline];
  if (stages == null) return;
  _heldStages[pipeline] = null;
  if (!_holders.release(stages)) return;
  _pipelines.forgetStages(stages);
  if (_holders.holdsPair(stages)) return;
  final layouts = _bindingLayouts.remove(
    _StagePairKey(stages.vertexModule!, stages.fragmentModule!),
  );
  if (layouts == null) return;
  _bindGroups.removeWhere(
    (_BindGroupKey key, GPUBindGroup _) => layouts.groups.any(
      (GPUBindGroupLayout g) => identical(g, key.layout),
    ),
  );
}