Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
save
  • Loading branch information
nkreeger committed Oct 17, 2019
commit 26fa734d38cfd60bcb375fa9209850ece81f02f5
9 changes: 4 additions & 5 deletions tfjs-core/src/backends/webgl/canvas_util_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ import {browserContextFactory} from './canvas_util';

describeWithFlags('canvas_util', BROWSER_ENVS, () => {
it('Returns a valid canvas', () => {
const canvas = browserContextFactory(
tf.env().getNumber('WEBGL_VERSION'))
.canvas as (HTMLCanvasElement | OffscreenCanvas);
const canvas =
browserContextFactory(tf.env().getNumber('WEBGL_VERSION')).canvas as (
HTMLCanvasElement | OffscreenCanvas);
expect(
(canvas instanceof HTMLCanvasElement) ||
(canvas instanceof OffscreenCanvas))
.toBe(true);
});

it('Returns a valid gl context', () => {
const gl = browserContextFactory(
tf.env().getNumber('WEBGL_VERSION'));
const gl = browserContextFactory(tf.env().getNumber('WEBGL_VERSION'));
expect(gl.isContextLost()).toBe(false);
});
});
Expand Down
74 changes: 38 additions & 36 deletions tfjs-core/src/backends/webgl/flags_webgl_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import {WEBGL_ENVS} from './backend_webgl_test_registry';
import * as webgl_context_manager from './webgl_context_manager';

describe('WEBGL_FORCE_F16_TEXTURES', () => {
afterAll(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('can be activated via forceHalfFloat utility', () => {
tf.webgl.forceHalfFloat();
expect(tf.env().getBool('WEBGL_FORCE_F16_TEXTURES')).toBe(true);
});

it('turns off WEBGL_RENDER_FLOAT32_ENABLED', () => {
tf.env().reset();
// tf.env().reset();
tf.webgl.forceHalfFloat();
expect(tf.env().getBool('WEBGL_RENDER_FLOAT32_ENABLED')).toBe(false);
});
Expand All @@ -48,11 +48,12 @@ const RENDER_FLOAT16_ENVS = {
};

describeWithFlags('WEBGL_RENDER_FLOAT32_CAPABLE', RENDER_FLOAT32_ENVS, () => {
beforeEach(() => {
tf.env().reset();
});
beforeEach(
() => {
// tf.env().reset();
});

afterAll(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('should be independent of forcing f16 rendering', () => {
tf.webgl.forceHalfFloat();
Expand All @@ -66,11 +67,12 @@ describeWithFlags('WEBGL_RENDER_FLOAT32_CAPABLE', RENDER_FLOAT32_ENVS, () => {
});

describeWithFlags('WEBGL_RENDER_FLOAT32_CAPABLE', RENDER_FLOAT16_ENVS, () => {
beforeEach(() => {
tf.env().reset();
});
beforeEach(
() => {
// tf.env().reset();
});

afterAll(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('should be independent of forcing f16 rendering', () => {
tf.webgl.forceHalfFloat();
Expand All @@ -83,8 +85,8 @@ describeWithFlags('WEBGL_RENDER_FLOAT32_CAPABLE', RENDER_FLOAT16_ENVS, () => {
});

describe('HAS_WEBGL', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('false when version is 0', () => {
tf.env().set('WEBGL_VERSION', 0);
Expand All @@ -103,8 +105,8 @@ describe('HAS_WEBGL', () => {
});

describe('WEBGL_PACK', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when HAS_WEBGL is true', () => {
tf.env().set('HAS_WEBGL', true);
Expand All @@ -118,8 +120,8 @@ describe('WEBGL_PACK', () => {
});

describe('WEBGL_PACK_NORMALIZATION', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when WEBGL_PACK is true', () => {
tf.env().set('WEBGL_PACK', true);
Expand All @@ -133,8 +135,8 @@ describe('WEBGL_PACK_NORMALIZATION', () => {
});

describe('WEBGL_PACK_CLIP', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when WEBGL_PACK is true', () => {
tf.env().set('WEBGL_PACK', true);
Expand Down Expand Up @@ -179,8 +181,8 @@ describe('WEBGL_PACK_BINARY_OPERATIONS', () => {
});

describe('WEBGL_PACK_ARRAY_OPERATIONS', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when WEBGL_PACK is true', () => {
tf.env().set('WEBGL_PACK', true);
Expand All @@ -194,8 +196,8 @@ describe('WEBGL_PACK_ARRAY_OPERATIONS', () => {
});

describe('WEBGL_PACK_IMAGE_OPERATIONS', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when WEBGL_PACK is true', () => {
tf.env().set('WEBGL_PACK', true);
Expand All @@ -209,8 +211,8 @@ describe('WEBGL_PACK_IMAGE_OPERATIONS', () => {
});

describe('WEBGL_PACK_REDUCE', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when WEBGL_PACK is true', () => {
tf.env().set('WEBGL_PACK', true);
Expand All @@ -224,8 +226,8 @@ describe('WEBGL_PACK_REDUCE', () => {
});

describe('WEBGL_LAZILY_UNPACK', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when WEBGL_PACK is true', () => {
tf.env().set('WEBGL_PACK', true);
Expand All @@ -239,8 +241,8 @@ describe('WEBGL_LAZILY_UNPACK', () => {
});

describe('WEBGL_CONV_IM2COL', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('true when WEBGL_PACK is true', () => {
tf.env().set('WEBGL_PACK', true);
Expand All @@ -255,7 +257,7 @@ describe('WEBGL_CONV_IM2COL', () => {

describe('WEBGL_MAX_TEXTURE_SIZE', () => {
beforeEach(() => {
tf.env().reset();
// tf.env().reset();
webgl_util.resetMaxTextureSize();

spyOn(webgl_context_manager, 'getContextByVersion').and.returnValue({
Expand All @@ -270,7 +272,7 @@ describe('WEBGL_MAX_TEXTURE_SIZE', () => {
});

afterAll(() => {
tf.env().reset();
// tf.env().reset();
webgl_util.resetMaxTextureSize();
});

Expand All @@ -282,7 +284,7 @@ describe('WEBGL_MAX_TEXTURE_SIZE', () => {
describe('WEBGL_MAX_TEXTURES_IN_SHADER', () => {
let maxTextures: number;
beforeEach(() => {
tf.env().reset();
// tf.env().reset();
webgl_util.resetMaxTexturesInShader();

spyOn(webgl_context_manager, 'getContextByVersion').and.callFake(() => {
Expand All @@ -299,7 +301,7 @@ describe('WEBGL_MAX_TEXTURES_IN_SHADER', () => {
});

afterAll(() => {
tf.env().reset();
// tf.env().reset();
webgl_util.resetMaxTexturesInShader();
});

Expand All @@ -315,8 +317,8 @@ describe('WEBGL_MAX_TEXTURES_IN_SHADER', () => {
});

describe('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('disjoint query timer disabled', () => {
tf.env().set('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', 0);
Expand Down Expand Up @@ -344,8 +346,8 @@ describe('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', () => {
});

describe('WEBGL_SIZE_UPLOAD_UNIFORM', () => {
beforeEach(() => tf.env().reset());
afterAll(() => tf.env().reset());
// beforeEach(() => tf.env().reset());
// afterAll(() => tf.env().reset());

it('is 0 when there is no float32 bit support', () => {
tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', false);
Expand Down
22 changes: 11 additions & 11 deletions tfjs-core/src/backends/webgl/gpgpu_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import * as util from '../../util';
import * as gpgpu_util from './gpgpu_util';
import * as tex_util from './tex_util';
import {TextureConfig} from './tex_util';
import {callAndCheck, checkWebGLError} from './webgl_check';
import {callAndCheck} from './webgl_check';
import {getActiveContext} from './webgl_context_manager';
import {WebGL1DisjointQueryTimerExtension, WebGL2DisjointQueryTimerExtension} from './webgl_types';
import * as webgl_util from './webgl_util';
Expand Down Expand Up @@ -104,15 +104,15 @@ export class GPGPUContext {
'matrix texture with GPGPUContext.deleteMatrixTexture before ' +
'disposing.');
}
const debug = true;
const gl = getActiveContext();
checkWebGLError(gl);
callAndCheck(gl, debug, () => gl.finish());
callAndCheck(gl, debug, () => gl.bindFramebuffer(gl.FRAMEBUFFER, null));
callAndCheck(gl, debug, () => gl.deleteFramebuffer(this.framebuffer));
callAndCheck(gl, debug, () => gl.bindBuffer(gl.ARRAY_BUFFER, null));
callAndCheck(gl, debug, () => gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null));
callAndCheck(gl, debug, () => gl.deleteBuffer(this.indexBuffer));
callAndCheck(gl, this.debug, () => gl.finish());
callAndCheck(
gl, this.debug, () => gl.bindFramebuffer(gl.FRAMEBUFFER, null));
callAndCheck(gl, this.debug, () => gl.deleteFramebuffer(this.framebuffer));
callAndCheck(gl, this.debug, () => gl.bindBuffer(gl.ARRAY_BUFFER, null));
callAndCheck(
gl, this.debug, () => gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null));
callAndCheck(gl, this.debug, () => gl.deleteBuffer(this.indexBuffer));
this.disposed = true;
}

Expand Down Expand Up @@ -164,7 +164,7 @@ export class GPGPUContext {
WebGLTexture {
this.throwIfDisposed();
return gpgpu_util.createPackedMatrixTexture(
getActiveContext(), true, rows, columns, this.textureConfig);
getActiveContext(), this.debug, rows, columns, this.textureConfig);
}

public deleteMatrixTexture(texture: WebGLTexture) {
Expand All @@ -175,7 +175,7 @@ export class GPGPUContext {
this.outputTexture = null;
}
callAndCheck(
getActiveContext(), true,
getActiveContext(), this.debug,
() => getActiveContext().deleteTexture(texture));
}

Expand Down
3 changes: 1 addition & 2 deletions tfjs-core/src/backends/webgl/webgl_context_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {ENV} from '../../environment';
import {browserContextCleanup, browserContextFactory} from './canvas_util';
import {checkWebGLError} from './webgl_check';

let count = 0;
const contexts: {[key: string]: WebGLRenderingContext} = {};
let contextFactory: (version: number) => WebGLRenderingContext = null;
let contextCleanup: (context: WebGLRenderingContext) => void = null;
Expand Down Expand Up @@ -67,7 +66,7 @@ export function getContextByVersion(version: number): WebGLRenderingContext {
}

if (!(version in contexts)) {
contexts[version] = contextFactory(version), ++count;
contexts[version] = contextFactory(version);
bootstrapWebGLContext(contexts[version]);
checkWebGLError(contexts[version]);
}
Expand Down
10 changes: 2 additions & 8 deletions tfjs-core/src/backends/webgl/webgl_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {env} from '../../environment';
import * as util from '../../util';

import {getTextureConfig} from './tex_util';
import {callAndCheck, checkWebGLError} from './webgl_check';
import {callAndCheck} from './webgl_check';
import {getContextByVersion} from './webgl_context_manager';

// https://en.wikipedia.org/wiki/Half-precision_floating-point_format
Expand Down Expand Up @@ -186,7 +186,7 @@ export function validateTextureSize(width: number, height: number) {
export function createFramebuffer(
gl: WebGLRenderingContext, debug: boolean): WebGLFramebuffer {
return throwIfNull<WebGLFramebuffer>(
gl, true, () => gl.createFramebuffer(),
gl, debug, () => gl.createFramebuffer(),
'Unable to create WebGLFramebuffer.');
}

Expand Down Expand Up @@ -511,12 +511,6 @@ export function getWebGLDisjointQueryTimerVersion(webGLVersion: number):

export function hasExtension(gl: WebGLRenderingContext, extensionName: string) {
const ext = gl.getExtension(extensionName);
try {
checkWebGLError(gl);
} catch (e) {
console.log('exception getting: ' + extensionName);
throw e;
}
return ext != null;
}

Expand Down