I just wrote a demo from https://www.khronos.org/registry/webgl/sdk/tests/conformance2/glsl3/matrix-row-major.html?webglVersion=2&dumpShaders=undefined&quiet=0:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Row-major matrix test</title>
<link rel="stylesheet" href="https://www.khronos.org/registry/webgl/sdk/tests/resources/js-test-style.css" />
<script src="https://www.khronos.org/registry/webgl/sdk/tests/js/js-test-pre.js"></script>
<script src="https://www.khronos.org/registry/webgl/sdk/tests/js/webgl-test-utils.js"></script>
<script src="https://www.khronos.org/registry/webgl/sdk/tests/js/glsl-conformance-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="vshaderUniformMatrixRowMajor" type="x-shader/x-vertex">#version 300 es
out vec2 pos;
in vec4 vPosition;
in vec2 texCoord0;
void main()
{
pos = texCoord0;
pos.y = 1.0 - pos.y;
gl_Position = vPosition;
}
</script>
<script id="fshaderUniformMatrixRowMajor" type="x-shader/x-fragment">#version 300 es
precision mediump float;
in highp vec2 pos;
layout (location = 0) out vec4 my_FragColor;
uniform vec4 m[4];
layout(std140, row_major) uniform type_m2 {
mat4 mat;
} m2;
void main()
{
my_FragColor = vec4(m2.mat[int(floor(pos.x * 4.0))][int(floor(pos.y * 4.0))], 0.0, 0.0, 1.0);
}
</script>
<script type="application/javascript">
"use strict";
description("Row-major matrix layouts should work.");
GLSLConformanceTester.runRenderTests([
{
vShaderId: 'vshaderUniformMatrixRowMajor',
vShaderSuccess: true,
fShaderId: 'fshaderUniformMatrixRowMajor',
fShaderSuccess: true,
linkSuccess: true,
passMsg: '',
uniformBlocks: [{
name: "type_m2", value: new Float32Array([
0, 0.2, 0.4, 0.6,
1, 0.1, 0.3, 0.5,
0, 0, 0, 0,
1, 1, 1, 1,
])
}]
}
], 2);
</script>
</body>
</html>
On win10 Chrome 81.0.4044.129
I got the result: Shader with row_major qualifier
I cannot figure out why it looks like this.
When I remove the row_major qualifier, I got another result:
Shader without row_major qualifier ( Do not care about the html wording in the image below, this is column_major )
And this is expected result.
UPDATE
To make things clear: My question is that two result should be transposed from each other since they use the same matrix data. The shader tries to paint each float number in matrix which ranges from 0 to 1 to the red channel. However shader with row_major (the first result) shows that the element in matrix is either 0 or 1, but this is not the fact. And the second result exactly do what is expected.