From 0cdf8e0e0a5485af5d882cfd573c4edad88f7ebe Mon Sep 17 00:00:00 2001 From: greggman Date: Fri, 3 Jan 2025 22:20:58 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=200980f?= =?UTF-8?q?2f7a5da0bcda5e97ae50f257b66729094d4=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/workloadSimulator/index.html | 65 ++--------------------------- 1 file changed, 4 insertions(+), 61 deletions(-) diff --git a/sample/workloadSimulator/index.html b/sample/workloadSimulator/index.html index 41dba534..7b185b8f 100644 --- a/sample/workloadSimulator/index.html +++ b/sample/workloadSimulator/index.html @@ -418,9 +418,6 @@

Web graphics workload simulator

let renderBundleAfterScissor; let renderBundleNumDrawCalls; let renderBundleInstances; -let querySet; -let queryBuffers = []; -let queryResolveBuffer; let mapAsyncArray = new Float32Array(0); let mapAsyncTargetBuffer; let mapAsyncBufferSize = 0; @@ -448,8 +445,6 @@

Web graphics workload simulator

let timeout = null; let rafPending = 0; let postMessagePending = 0; -let timeQueryResultsMs = []; -let lastTimeQueryTime = 0; const animationDirection = [1, 1]; async function render(fromRaf, fromPostMessage) { @@ -596,10 +591,7 @@

Web graphics workload simulator

features: Array.from(adapter.features || []).sort(), limits: adapter.limits }, 0, 2); - const useTimestampQueries = adapter.features.has('timestamp-query'); - device = await adapter.requestDevice({ - nonGuaranteedFeatures: useTimestampQueries ? ['timestamp-query'] : [], - }); + device = await adapter.requestDevice({}); device.addEventListener('uncapturederror', (e)=>{ if (!errorMessage.textContent) errorMessage.textContent = 'Uncaptured error: ' + e.error.message; }); @@ -709,13 +701,6 @@

Web graphics workload simulator

{ binding: 2, resource: texture.createView() }, ], }); - if (useTimestampQueries && device.createQuerySet) { - querySet = device.createQuerySet({type: 'timestamp', count: 2}); - queryResolveBuffer = device.createBuffer({ - size: 16, - usage: GPUBufferUsage.QUERY_RESOLVE | GPUBufferUsage.COPY_SRC, - }); - } } catch(e) { if (!errorMessage.textContent) errorMessage.textContent = "Error initializing WebGPU: " + e; return; @@ -731,15 +716,10 @@

Web graphics workload simulator

} try { const canvasView = canvasContext.getCurrentTexture().createView(); - const commandBuffers = []; + device.queue.writeBuffer(uniformBuffer, 0, new Float32Array([position[0] / size * 2 - 1, 1 - position[1] * 2 / size])); let buffer = null; - // Start off by writing a timestamp for the beginning of the frame. - const timestampEncoder = device.createCommandEncoder(); - if (querySet) timestampEncoder.writeTimestamp(querySet, 0); - device.queue.submit([timestampEncoder.finish()]); - // Upload data using createBuffer with mappedAtCreation. if (bufferData.value > 0) { buffer = device.createBuffer({ size: bufferDataArray.byteLength, usage: GPUBufferUsage.VERTEX, mappedAtCreation: true }); @@ -890,39 +870,7 @@

Web graphics workload simulator

} passEncoder.end(); if (buffer) buffer.destroy(); - let queryBuffer; - if (querySet) { - // Timestamp for the end of the frame. - commandEncoder.writeTimestamp(querySet, 1); - // We create a queue of staging buffers to hold the timestamps while we - // map them into CPU memory. If the queue is empty, create a new buffer. - if (queryBuffers.length == 0) { - const buffer = device.createBuffer({ - size: 16, - usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ, - }); - queryBuffers.push(buffer); - } - // Write the timestamps into a GPU side buffer and copy into the staging buffer. - queryBuffer = queryBuffers.shift(); - commandEncoder.resolveQuerySet(querySet, 0, 2, queryResolveBuffer, 0); - commandEncoder.copyBufferToBuffer(queryResolveBuffer, 0, queryBuffer, 0, 16); - } - commandBuffers.push(commandEncoder.finish()); - device.queue.submit(commandBuffers); - if (querySet) { - // Once the staging buffer is mapped we can finally calculate the frame duration - // and put the staging buffer back into the queue. - queryBuffer.mapAsync(GPUMapMode.READ).then(()=>{ - let array = new BigInt64Array(queryBuffer.getMappedRange()); - let nanoseconds = Number(array[1] - array[0]); - if (timeQueryResultsMs.length > 10) timeQueryResultsMs.shift(); - timeQueryResultsMs.push(nanoseconds / 1000000); - lastTimeQueryTime = performance.now(); - queryBuffer.unmap(); - queryBuffers.push(queryBuffer); - }); - } + device.queue.submit([commandEncoder.finish()]); } catch(e) { if (!errorMessage.textContent) errorMessage.textContent = "Error: " + e; throw e; @@ -1174,12 +1122,7 @@

Web graphics workload simulator

} if (showFps.checked) { - if (performance.now() - lastTimeQueryTime < 1000 && timeQueryResultsMs.length) { - const averageTime = timeQueryResultsMs.reduce((x, y) => x + y) / timeQueryResultsMs.length; - fpsSpan.textContent = `${counters['render'].fps.toFixed()}, ${averageTime.toFixed(1)} ms GPU time`; - } else { - fpsSpan.textContent = counters['render'].fps.toFixed(); - } + fpsSpan.textContent = counters['render'].fps.toFixed(); if (showStats.checked) { let text = ""; for (let key in counters) {