array-of-struct-with-int-first-position.html (3635B)
1 <!-- 2 Copyright (c) 2019 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 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>Driver Bug - Array of structs with int or bool in first position</title> 12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 13 <script src="../../../js/js-test-pre.js"></script> 14 <script src="../../../js/webgl-test-utils.js"></script> 15 </head> 16 17 <body> 18 <canvas id="example" style="border: none;" width="788" height="256"></canvas> 19 <div id="description"></div> 20 <div id="console"></div> 21 22 <script id="shader-vs" type="x-shader/x-vertex"> 23 attribute vec2 pos; 24 void main(void) { 25 gl_Position = vec4(pos, 0.0, 1.0); 26 } 27 </script> 28 29 <script id="shader-fs-int" type="x-shader/x-fragment"> 30 precision mediump float; 31 struct Light { 32 int unused; 33 vec3 color; 34 }; 35 const int numLights = 1; 36 void main() { 37 Light lights[numLights]; 38 lights[0].color = vec3(0.0, 0.5, 0.0); 39 40 vec3 result = vec3(0.0, 0.0, 0.0); 41 for (int i=0; i<numLights; i++) { 42 result += lights[i].color; 43 } 44 gl_FragColor = vec4(result.rgb, 1.0); 45 } 46 </script> 47 48 <script id="shader-fs-bool" type="x-shader/x-fragment"> 49 precision mediump float; 50 struct Light { 51 bool unused; 52 vec3 color; 53 }; 54 const int numLights = 1; 55 void main() { 56 Light lights[numLights]; 57 lights[0].color = vec3(0.0, 0.5, 0.0); 58 59 vec3 result = vec3(0.0, 0.0, 0.0); 60 for (int i=0; i<numLights; i++) { 61 result += lights[i].color; 62 } 63 gl_FragColor = vec4(result.rgb, 1.0); 64 } 65 </script> 66 67 <script id="shader-fs-bool-read" type="x-shader/x-fragment"> 68 precision mediump float; 69 struct Light { 70 bool useLight; 71 vec3 color; 72 }; 73 const int numLights = 1; 74 void main() { 75 Light lights[numLights]; 76 lights[0].color = vec3(0.0, 0.5, 0.0); 77 lights[0].useLight = true; 78 79 vec3 result = vec3(0.0, 0.0, 0.0); 80 for (int i=0; i<numLights; i++) { 81 Light light = lights[i]; 82 if (light.useLight) { 83 result += light.color; 84 } 85 } 86 gl_FragColor = vec4(result.rgb, 1.0); 87 } 88 </script> 89 90 <script> 91 "use strict"; 92 93 function test() { 94 description(); 95 debug( 96 "This test checks accessing an array of structs, where the struct " + 97 "definition has an int or bool in the first position. " + 98 "This test has has failed in OS X on some NVIDIA cards, " + 99 "such as the NVIDIA GeForce GT 650M. If things are working " + 100 "correctly, then there will be a series of 50% green squares.") 101 debug(""); 102 103 var wtu = WebGLTestUtils; 104 var canvas = document.getElementById("example"); 105 var gl = wtu.create3DContext(canvas); 106 107 var testNum = 0; 108 var border = 10; // border between test squares for visibility 109 var squareSize = 256; 110 var expectedColor = [0, 127, 0, 255]; // 50% green 111 112 function subTest(message, fragmentShader) { 113 debug(message); 114 var startX = (squareSize + border) * testNum; 115 var program = wtu.setupProgram( 116 gl, ["shader-vs", fragmentShader], ["pos"], null, true); 117 gl.viewport(startX, 0, squareSize, squareSize); 118 wtu.drawUnitQuad(gl); 119 wtu.checkCanvasRect( 120 gl, startX, 0, squareSize, squareSize, 121 expectedColor, "square should be 50% green", 1); 122 debug(""); 123 testNum++; 124 } 125 126 if (!gl) { 127 testFailed("context does not exist"); 128 } else { 129 wtu.setupUnitQuad(gl); 130 subTest("Test unused int in first struct position.", "shader-fs-int"); 131 subTest("Test unused bool in first struct position.", "shader-fs-bool"); 132 subTest("Test used bool in first struct position.", "shader-fs-bool-read"); 133 } 134 } 135 136 test(); 137 var successfullyParsed = true; 138 </script> 139 <script src="../../../js/js-test-post.js"></script> 140 </body> 141 </html>