summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/bugs/qualcomm-crash.html
blob: f1ef1e47abfe7922df9a4bf44998de5700aacba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!--
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>Qualcomm program link crash Tests</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>
<script id='vshader1' type='x-shader/x-vertex'>
precision highp float;
void main() {
gl_Position = vec4( 1.0, 1.0, 1.0, 1.0 );
}
</script>
<script id='fshader1' type='x-shader/x-fragment'>
precision highp float;
uniform int renderType;
uniform sampler2D texMap;
void main() {
    vec2 uv = vec2(0.0, 0.0);
    if( renderType == 0 ) {
        gl_FragColor = texture2D( texMap, uv );
    } else {
        vec4 texture = texture2D( texMap, uv );
        gl_FragColor = texture;
    }
}
</script>

<script id='vshader2' type='x-shader/x-vertex'>
attribute vec3 vertex_position;
uniform mat4 matrix_model;
uniform mat4 matrix_viewProjection;

attribute vec4 vertex_boneWeights;
attribute vec4 vertex_boneIndices;

uniform sampler2D texture_poseMap;
uniform vec2 texture_poseMapSize;

mat4 getBoneMatrix(const in float i)
{
    float j = i * 4.0;
    float x = mod(j, float(texture_poseMapSize.x));
    float y = floor(j / float(texture_poseMapSize.x));

    float dx = 1.0 / float(texture_poseMapSize.x);
    float dy = 1.0 / float(texture_poseMapSize.y);

    y = dy * (y + 0.5);

    vec4 v1 = texture2D(texture_poseMap, vec2(dx * (x + 0.5), y));
    vec4 v2 = texture2D(texture_poseMap, vec2(dx * (x + 1.5), y));
    vec4 v3 = texture2D(texture_poseMap, vec2(dx * (x + 2.5), y));
    vec4 v4 = texture2D(texture_poseMap, vec2(dx * (x + 3.5), y));

    mat4 bone = mat4(v1, v2, v3, v4);

    return bone;
}

void main(void)
{
    mat4 modelMatrix = vertex_boneWeights.x * getBoneMatrix(vertex_boneIndices.x) +
                       vertex_boneWeights.y * getBoneMatrix(vertex_boneIndices.y) +
                       vertex_boneWeights.z * getBoneMatrix(vertex_boneIndices.z) +
                       vertex_boneWeights.w * getBoneMatrix(vertex_boneIndices.w);

    vec4 positionW = modelMatrix * vec4(vertex_position, 1.0);
    gl_Position = matrix_viewProjection * positionW;

}
</script>
<script id='fshader2' type='x-shader/x-fragment'>
precision highp float;
void main() {
    gl_FragColor = vec4( 1.0, 1.0, 1.0, 1.0 );
}
</script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test checks a known bug in some Qualcomm drivers which causes crashes when linking certain shaders. <a href='https://code.google.com/p/chromium/issues/detail?id=498947'>crbug.com/498947</a>");

debug("");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext();

gl.canvas.addEventListener("webglcontextlost", function(e) {
   testFailed("WebGL context lost");
});

if (!gl) {
    testFailed("WebGL context does not exist");
} else {
    testPassed("WebGL context exists");
    debug("");

    if (gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision == 0) {
        testPassed("highp precision not supported");
    } else {
        var program1 = wtu.setupProgram(gl, ['vshader1', 'fshader1']);
        if (!gl.getProgramParameter(program1, gl.LINK_STATUS)) {
            testFailed("Program failed to link");
        }
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");

        debug("");

        var program2 = wtu.setupProgram(gl, ['vshader2', 'fshader2']);
        if (!gl.getProgramParameter(program2, gl.LINK_STATUS)) {
            testFailed("Program failed to link");
        }
        wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
    }
}

// Cycle through a rAF once to give any webglcontextlost events a chance to propagate
window.requestAnimationFrame(function() { finishTest(); });

debug("");
var successfullyParsed = true;
</script>

</body>
</html>