Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / wasm / teximage2d-4gb-wasm-memory.html
blob5d6897347d2e4c40374be8b83b3c7bcf3f058be2
1 <!--
2 Copyright (c) 2023 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
6 <!DOCTYPE html>
7 <html>
8 <head>
9 <meta charset="utf-8">
10 <title>gl.texImage2D() test to Wasm Memory 4GB in size.</title>
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
12 <script src="../../js/js-test-pre.js"></script>
13 <script src="../../js/webgl-test-utils.js"> </script>
14 </head>
15 <body>
16 <canvas id="canvas" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
17 <div id="description"></div>
18 <div id="console"></div>
19 <script>
20 "use strict";
21 description(document.title);
22 debug("Tests that gl.texImage2D() can be called on WebAssembly Memory 4GB in size.");
23 debug("");
24 let wtu = WebGLTestUtils;
25 let gl = wtu.create3DContext("canvas", undefined, 2);
27 const PAGE = 65536;
28 const SIZE = 4*1024*1024*1024 - PAGE; // when uint32_t size is max, we can only reach one page short of full 4GB
29 let view = new Uint8Array(new WebAssembly.Memory({ initial: SIZE/PAGE }).buffer);
31 function compileShader(type, src) {
32 let shader = gl.createShader(type);
33 gl.shaderSource(shader, src);
34 gl.compileShader(shader);
35 let log = gl.getShaderInfoLog(shader);
36 if (log) debug(log);
37 return shader;
40 function createProgram(vs, fs) {
41 let program = gl.createProgram();
42 gl.attachShader(program, vs);
43 gl.attachShader(program, fs);
44 gl.bindAttribLocation(program, 0, 'pos');
45 gl.linkProgram(program);
46 gl.useProgram(program);
47 return program;
50 let program = createProgram(
51 compileShader(gl.VERTEX_SHADER, `
52 varying vec2 uv;
53 attribute vec2 pos;
54 void main() { uv = pos; gl_Position = vec4(pos*2.0-vec2(1.0,1.0),0,1); }`),
55 compileShader(gl.FRAGMENT_SHADER, `
56 precision lowp float;
57 uniform sampler2D tex;
58 varying vec2 uv;
59 void main() { gl_FragColor = texture2D(tex,uv); }`));
61 gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
62 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]), gl.STATIC_DRAW);
63 gl.vertexAttribPointer(0, 2, gl.FLOAT, gl.FALSE, 0, 0);
64 gl.enableVertexAttribArray(0);
66 let texture = gl.createTexture();
67 gl.bindTexture(gl.TEXTURE_2D, texture);
69 // Test uploading an image
70 const expectedColor = [42, 84, 128, 255];
71 const offset = SIZE - 4;
72 view.set(expectedColor, offset);
73 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, view, offset);
74 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
76 // Test rendering with that image
77 gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
79 // Verify that we rendered what we expected
80 wtu.checkCanvasRect(gl, 0, 0, 1, 1, expectedColor, "texImage2D produced expected color");
81 var successfullyParsed = true;
82 </script>
83 <script src="../../js/js-test-post.js"></script>
84 </body>
85 </html>