From d4bd167d7f9cc6f3ba178abfc3714fff95968a2f Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Fri, 30 Nov 2018 09:27:49 -0800 Subject: [PATCH] don't use fences for now, too slow --- src/mol-gl/webgl/context.ts | 9 ++++++++- src/mol-math/geometry/gaussian-density/gpu.ts | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mol-gl/webgl/context.ts b/src/mol-gl/webgl/context.ts index 588c63936..afffafe8f 100644 --- a/src/mol-gl/webgl/context.ts +++ b/src/mol-gl/webgl/context.ts @@ -79,18 +79,23 @@ let SentWebglSyncObjectNotSupportedInWebglMessage = false function waitForGpuCommandsComplete(gl: GLRenderingContext): Promise<void> { return new Promise(resolve => { if (isWebGL2(gl)) { + // TODO seems quite slow fence(gl, resolve) } else { if (!SentWebglSyncObjectNotSupportedInWebglMessage) { console.info('Sync object not supported in WebGL') SentWebglSyncObjectNotSupportedInWebglMessage = true } - gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, tmpPixel) + waitForGpuCommandsCompleteSync(gl) resolve() } }) } +function waitForGpuCommandsCompleteSync(gl: GLRenderingContext): void { + gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, tmpPixel) +} + export function createImageData(buffer: ArrayLike<number>, width: number, height: number) { const w = width * 4 const h = height @@ -147,6 +152,7 @@ export interface WebGLContext { readPixels: (x: number, y: number, width: number, height: number, buffer: Uint8Array) => void readPixelsAsync: (x: number, y: number, width: number, height: number, buffer: Uint8Array) => Promise<void> waitForGpuCommandsComplete: () => Promise<void> + waitForGpuCommandsCompleteSync: () => void destroy: () => void } @@ -279,6 +285,7 @@ export function createContext(gl: GLRenderingContext): WebGLContext { }, readPixelsAsync, waitForGpuCommandsComplete: () => waitForGpuCommandsComplete(gl), + waitForGpuCommandsCompleteSync: () => waitForGpuCommandsCompleteSync(gl), destroy: () => { unbindResources(gl) diff --git a/src/mol-math/geometry/gaussian-density/gpu.ts b/src/mol-math/geometry/gaussian-density/gpu.ts index 993832874..7f7915115 100644 --- a/src/mol-math/geometry/gaussian-density/gpu.ts +++ b/src/mol-math/geometry/gaussian-density/gpu.ts @@ -110,7 +110,7 @@ async function GaussianDensityTexture2d(ctx: RuntimeContext, webgl: WebGLContext render(texture) if (ctx.shouldUpdate) await ctx.update({ message: 'gpu gaussian density calculation' }) - await webgl.waitForGpuCommandsComplete() + await webgl.waitForGpuCommandsCompleteSync() return { texture, scale: Vec3.inverse(Vec3.zero(), delta), bbox: expandedBox, dim } } @@ -157,7 +157,7 @@ async function GaussianDensityTexture3d(ctx: RuntimeContext, webgl: WebGLContext render(texture) await ctx.update({ message: 'gpu gaussian density calculation' }); - await webgl.waitForGpuCommandsComplete() + await webgl.waitForGpuCommandsCompleteSync() return { texture, scale: Vec3.inverse(Vec3.zero(), delta), bbox: expandedBox, dim } } -- GitLab