diff --git a/prismarine-viewer/examples/Cube.comp.wgsl b/prismarine-viewer/examples/Cube.comp.wgsl index c62d49c7..0ace92cd 100644 --- a/prismarine-viewer/examples/Cube.comp.wgsl +++ b/prismarine-viewer/examples/Cube.comp.wgsl @@ -21,7 +21,7 @@ struct IndirectDrawParams { @group(0) @binding(2) var visibleCubes: array; // Changed to @binding(4) @group(0) @binding(3) var drawParams: IndirectDrawParams; -@compute @workgroup_size(64) +@compute @workgroup_size(256) fn main(@builtin(global_invocation_id) global_id: vec3) { let index = global_id.x; if (index >= arrayLength(&cubes)) { diff --git a/prismarine-viewer/examples/playground.ts b/prismarine-viewer/examples/playground.ts index 75ccd650..f88b0bf6 100644 --- a/prismarine-viewer/examples/playground.ts +++ b/prismarine-viewer/examples/playground.ts @@ -22,8 +22,10 @@ import { renderPlayground } from './TouchControls2' import { WorldRendererWebgpu } from '../viewer/lib/worldrendererWebgpu' import { TextureAnimation } from './TextureAnimation' import { BlockType } from './shared' +import { addNewStat } from './newStats' const gui = new GUI() +const { updateText: updateTextEvent } = addNewStat('events', 90, 0, 40) // initial values const params = { @@ -214,9 +216,11 @@ async function main () { // mouse const mouse = { x: 0, y: 0 } + let mouseMoveCounter = 0 const mouseMove = (e: PointerEvent) => { if ((e.target as HTMLElement).closest('.lil-gui')) return if (e.buttons === 1 || e.pointerType === 'touch') { + mouseMoveCounter++ viewer.camera.rotation.x -= e.movementY / 100 //viewer.camera. viewer.camera.rotation.y -= e.movementX / 100 @@ -230,6 +234,10 @@ async function main () { viewer.camera.position.set(0, 0, 0) } } + setInterval(() => { + updateTextEvent(`Mouse Events: ${mouseMoveCounter}`) + mouseMoveCounter = 0 + }, 1000) window.addEventListener('pointermove', mouseMove) } viewer.camera.position.set(0, 0, 8) diff --git a/prismarine-viewer/examples/webgpuRenderer.ts b/prismarine-viewer/examples/webgpuRenderer.ts index 99786579..dec2d6c8 100644 --- a/prismarine-viewer/examples/webgpuRenderer.ts +++ b/prismarine-viewer/examples/webgpuRenderer.ts @@ -56,6 +56,7 @@ export class WebgpuRenderer { this.device = await adapter.requestDevice(); const { device } = this; this.maxBufferSize = device.limits.maxStorageBufferBindingSize; + this.renderedFrames = device.limits.maxComputeWorkgroupSizeX; console.log('max buffer size', this.maxBufferSize / 1024 / 1024, 'MB') const ctx = this.ctx = canvas.getContext('webgpu')!; @@ -461,9 +462,7 @@ export class WebgpuRenderer { device.queue.writeBuffer( uniformBuffer, 0, - ViewProjection.buffer, - ViewProjection.byteOffset, - ViewProjection.byteLength + ViewProjection ); // const EmptyVisibleCubes = new Float32Array([36, 0, 0, 0]) ; @@ -483,7 +482,7 @@ export class WebgpuRenderer { computePass.setPipeline(this.computePipeline); //computePass.setBindGroup(0, this.uniformBindGroup); computePass.setBindGroup(0, this.computeBindGroup); - computePass.dispatchWorkgroups(Math.ceil(this.NUMBER_OF_CUBES / 64)); + computePass.dispatchWorkgroups(Math.ceil(this.NUMBER_OF_CUBES / 256)); computePass.end(); device.queue.submit([commandEncoder.finish()]); commandEncoder = device.createCommandEncoder(); diff --git a/prismarine-viewer/examples/webgpuRendererWorker.ts b/prismarine-viewer/examples/webgpuRendererWorker.ts index e566313b..453a47f0 100644 --- a/prismarine-viewer/examples/webgpuRendererWorker.ts +++ b/prismarine-viewer/examples/webgpuRendererWorker.ts @@ -73,6 +73,7 @@ export const workerProxyType = createWorkerProxy({ }, generateRandom(count: number) { const square = Math.sqrt(count) + if (square % 1 !== 0) throw new Error('square must be a whole number') const blocks = {} const getFace = (face: number) => { return { @@ -159,12 +160,12 @@ export const workerProxyType = createWorkerProxy({ // } }, camera (newCam) { - if (webgpuRenderer?.isPlayground) { - camera.rotation.order = 'ZYX' - new tweenJs.Tween(camera.rotation).to({ x: newCam.rotation.x, y: newCam.rotation.y, z: newCam.rotation.z }, 50).start() - } else { + // if (webgpuRenderer?.isPlayground) { + // camera.rotation.order = 'ZYX' + // new tweenJs.Tween(camera.rotation).to({ x: newCam.rotation.x, y: newCam.rotation.y, z: newCam.rotation.z }, 50).start() + // } else { camera.rotation.set(newCam.rotation.x, newCam.rotation.y, newCam.rotation.z, 'ZYX') - } + // } if (newCam.position.x === 0 && newCam.position.y === 0 && newCam.position.z === 0) { // initial camera position camera.position.set(newCam.position.x, newCam.position.y, newCam.position.z) diff --git a/prismarine-viewer/playground.html b/prismarine-viewer/playground.html index 2c3b5ddc..20317781 100644 --- a/prismarine-viewer/playground.html +++ b/prismarine-viewer/playground.html @@ -8,6 +8,7 @@ overflow: hidden; background: black; user-select: none; + touch-action: none; } html, body {