MCPcopy
hub / github.com/processing/p5.js / flushDraw

Method flushDraw

src/webgpu/p5.RendererWebGPU.js:1705–1764  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1703 }
1704
1705 flushDraw() {
1706 this._finishActiveRenderPass();
1707 // Only submit if we actually had any draws
1708 if (this._hasPendingDraws) {
1709 // Create a copy of pending command encoders
1710 const commandsToSubmit = this._pendingCommandEncoders;
1711 this._pendingCommandEncoders = [];
1712 this._hasPendingDraws = false;
1713
1714 if (this.activeUniformBuffers.length > 0) {
1715 const encoder = this.device.createCommandEncoder();
1716 for (const bufferInfo of this.activeUniformBuffers) {
1717 bufferInfo.buffer.unmap();
1718 encoder.copyBufferToBuffer(
1719 bufferInfo.buffer,
1720 bufferInfo.uniformBuffer,
1721 );
1722 }
1723 commandsToSubmit.unshift(encoder.finish());
1724 }
1725
1726 // Submit the commands
1727 this.queue.submit(commandsToSubmit);
1728
1729 for (const buf of this.activeUniformBuffers) {
1730 // buf.buffer = this.device.createBuffer({
1731 // size: buf.size,
1732 // usage: GPUBufferUsage.MAP_WRITE | GPUBufferUsage.COPY_SRC,
1733 // mappedAtCreation: true,
1734 // });
1735 buf.offset = 0;
1736 buf.lastOffset = 0;
1737 // this.resettingUniformBuffers.push(
1738 buf.buffer.mapAsync(GPUMapMode.WRITE).then(() => {
1739 buf.data = new Float32Array(buf.buffer.getMappedRange());
1740 buf.dataView = new DataView(buf.data.buffer);
1741 this.uniformBufferPool.push(buf);
1742 return buf;
1743 })
1744 // )
1745 }
1746 this.activeUniformBuffers = [];
1747 this.currentUniformBuffer = undefined;
1748
1749 // Execute post-submit callbacks after GPU work completes
1750 if (this._postSubmitCallbacks.length > 0) {
1751 const callbacks = this._postSubmitCallbacks;
1752 this._postSubmitCallbacks = [];
1753 this.device.queue.onSubmittedWorkDone().then(() => {
1754 for (const callback of callbacks) {
1755 callback();
1756 }
1757 });
1758 }
1759
1760 // Reset canvas texture cache for next frame
1761 this.currentCanvasColorTexture = null;
1762 this.currentCanvasColorTextureView = null;

Callers 15

_initContextMethod · 0.95
_updateSizeMethod · 0.95
_promoteToFramebufferMethod · 0.95
resizeMethod · 0.95
finishDrawMethod · 0.95
uploadTextureFromDataMethod · 0.95

Calls 3

finishMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected