Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test that context creation reclaims vram to prevent creation fail… #2984

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions sdk/tests/conformance/context/00_test_list.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--max-version 1.9.9 constants-and-properties.html
--min-version 1.0.2 context-attribute-preserve-drawing-buffer.html
context-attributes-alpha-depth-stencil-antialias.html
--min-version 1.0.4 context-creation-reclaims-vram.html
--min-version 1.0.4 context-size-change.html
--min-version 1.0.4 context-no-alpha-fbo-with-alpha.html
--min-version 1.0.2 --slow context-creation-and-destruction.html
Expand Down
85 changes: 85 additions & 0 deletions sdk/tests/conformance/context/context-creation-reclaims-vram.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test that contexts are freed and garbage collected reasonably</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description();

const CANVAS_COUNT = 100;
const SIZE_REQUEST = 23170; // Chrome doesn't even try for >2GB backbuffers.

debug(`SIZE_REQUEST: ${SIZE_REQUEST*SIZE_REQUEST*4/1024/1024|0} MB`);

const wtu = WebGLTestUtils;

const canvasList = []; // Keeps canvases alive

function newCanvas() {
const canvas = document.createElement('canvas');
canvas.width = canvas.height = SIZE_REQUEST;

canvasList.push(canvas);
canvas.id = canvasList.length;

canvas.addEventListener("webglcontextlost", function(e) {
//e.preventDefault(); // preventDefault enables context restore.
debug(`(webglcontextlost on canvas ${canvas.id})`);
});

return canvas;
}

function testNextContext(minSize) {
const canvas = newCanvas();
const gl = wtu.create3DContext(canvas, {
depth: false,
antialias: false,
});
assertMsg(gl, `Creating context ${canvas.id} should succeed.`);
if (gl) {
const width = gl.drawingBufferWidth;
const height = gl.drawingBufferHeight;
debug(` allocated size: ${width*height*4/1024/1024|0} MB`);
assertMsg(width >= minSize,
` drawingBufferWidth (${width}) should be >= ${minSize}`);
assertMsg(height >= minSize,
` drawingBufferHeight (${height}) should be >= ${minSize}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chromium's WebGL implementation handles the scenario of users allocating many WebGL contexts with large back buffers by scaling down the size of newly created back buffers, rather than losing older contexts. We've tried in the past to lift the global limits on the amount of back buffer VRAM that can be allocated, but have never succeeded; crashes have been seen inside OpenGL drivers on various platforms, instead of GL_OUT_OF_MEMORY being reported. I'm not sure that requiring that newly-allocated contexts have the same back buffer size as the originally-allocated context is an invariant we should enforce; let's discuss in real time on tomorrow's working group conference call.

}

if (canvasList.length >= CANVAS_COUNT) {
finishTest();
return;
}

wtu.dispatchPromise(() => { testNextContext(minSize); });
}

(function() {
const probeCanvas = newCanvas();
const probeGl = wtu.create3DContext(probeCanvas);
const minSize = Math.min(probeGl.drawingBufferWidth, probeGl.drawingBufferHeight);

testNextContext(minSize);
})();

var successfullyParsed = true;
</script>

</body>
</html>