-
Notifications
You must be signed in to change notification settings - Fork 669
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
Test for having the same read and write buffer using a transform feedback #2349
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
transform_feedback.html | ||
transform_feedback_same_buffers_as_input_and_output.html | ||
two-unreferenced-varyings.html | ||
unwritten-output-defaults-to-zero.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
<!-- | ||
|
||
/* | ||
** Copyright (c) 2017 The Khronos Group Inc. | ||
** | ||
** Permission is hereby granted, free of charge, to any person obtaining a | ||
** copy of this software and/or associated documentation files (the | ||
** "Materials"), to deal in the Materials without restriction, including | ||
** without limitation the rights to use, copy, modify, merge, publish, | ||
** distribute, sublicense, and/or sell copies of the Materials, and to | ||
** permit persons to whom the Materials are furnished to do so, subject to | ||
** the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be included | ||
** in all copies or substantial portions of the Materials. | ||
** | ||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. | ||
*/ | ||
|
||
--> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebGL Transform Feedback Conformance Test - Same Buffers as Input and Output</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> | ||
<canvas id="canvas" style="width: 50px; height: 50px;"> </canvas> | ||
<div id="console"></div> | ||
<script id="vshader" type="x-shader/x-vertex">#version 300 es | ||
in float in_value; | ||
out float out_value; | ||
|
||
void main() { | ||
out_value = in_value * 2.; | ||
} | ||
</script> | ||
<script id="fshader" type="x-shader/x-fragment">#version 300 es | ||
precision mediump float; | ||
out vec4 dummy; | ||
void main() { | ||
dummy = vec4(1); | ||
} | ||
</script> | ||
<script> | ||
"use strict"; | ||
description("This test verifies trying to read and write from the same buffers fails"); | ||
|
||
debug(""); | ||
|
||
var wtu = WebGLTestUtils; | ||
var canvas = document.getElementById("canvas"); | ||
var gl = wtu.create3DContext(canvas, null, 2); | ||
|
||
if (!gl) { | ||
testFailed("WebGL context does not exist"); | ||
} else { | ||
testPassed("WebGL context exists"); | ||
|
||
runSameInputOutputTest(); | ||
finishTest(); | ||
} | ||
|
||
function runSameInputOutputTest() { | ||
const prog = wtu.setupTransformFeedbackProgram(gl, ["vshader", "fshader"], | ||
["out_value"], gl.SEPARATE_ATTRIBS, | ||
["in_value"]); | ||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "linking transform feedback shader should not set an error"); | ||
|
||
const inLoc = 0; | ||
const outLoc = 0; | ||
|
||
const srcBuffer1 = createBuffer(gl, new Float32Array([1, 2, 3])); | ||
const srcVAO1 = createVAO(gl, srcBuffer1, inLoc); | ||
|
||
const dstBuffer = createBuffer(gl, Float32Array.BYTES_PER_ELEMENT * 3); | ||
const srcVAO2 = createVAO(gl, dstBuffer, inLoc); | ||
|
||
const tf = gl.createTransformFeedback(); | ||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf); | ||
gl.useProgram(prog); | ||
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, outLoc, dstBuffer); | ||
// this binds the default (id = 0) TRANSFORM_FEEBACK buffer | ||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null); | ||
|
||
// FIXME: this should not be needed once the spec and implementations are fixed | ||
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, outLoc, null); // this is not needed | ||
|
||
runFeedback(gl, prog, srcVAO1, tf); | ||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); | ||
|
||
const expected = [2, 4, 6]; | ||
gl.bindBuffer(gl.ARRAY_BUFFER, dstBuffer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am assuming this is where Chrome fails? According to the current spec restrictions, Chrome generates an INVALID_OPERATION here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is one place where chrome fails if the "FIXME" lines are removed. Otherwise Chrome fails because it allows calling |
||
wtu.checkFloatBuffer(gl, gl.ARRAY_BUFFER, expected); | ||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); | ||
|
||
// this should fail because the transform feedback's buffer #0 and the | ||
// srcVAO2's buffer #0 are the same buffer | ||
runFeedback(gl, prog, srcVAO2, tf); | ||
wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "reading and writing to same buffer"); | ||
|
||
gl.bindBuffer(gl.ARRAY_BUFFER, dstBuffer); | ||
wtu.checkFloatBuffer(gl, gl.ARRAY_BUFFER, expected, "should be the same as before as nothing has executed"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if it's executed, the result is still the same expected because it's the same program? So this is a useless and misleading check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If incorrectly executed (as it currently is in chrome) the result is 4, 8, 12 because it's manipulating the result from the first That result is probably GPU dependent since the whole problem is results of having the same input and output buffer is undefined. In any case it shouldn't execute and the buffer should still have 2, 4, 6 in it. It doesn't in Chrome currently on my MBP. Seems like the test is valid |
||
|
||
} | ||
|
||
function runFeedback(gl, prog, srcVAO, tf) { | ||
gl.enable(gl.RASTERIZER_DISCARD); | ||
|
||
gl.useProgram(prog); | ||
gl.bindVertexArray(srcVAO); | ||
|
||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf); | ||
gl.beginTransformFeedback(gl.TRIANGLES); | ||
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); | ||
gl.drawArrays(gl.TRIANGLES, 0, 3); | ||
gl.endTransformFeedback(); | ||
|
||
// FIXME: this should not be needed once the spec and implementations are fixed | ||
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null); // this is not needed | ||
|
||
gl.disable(gl.RASTERIZER_DISCARD); | ||
} | ||
|
||
function createBuffer(gl, dataOrSize) { | ||
const buf = gl.createBuffer(); | ||
gl.bindBuffer(gl.ARRAY_BUFFER, buf); | ||
gl.bufferData(gl.ARRAY_BUFFER, dataOrSize, gl.STATIC_DRAW); | ||
// FIXME: this should not be needed once the spec and implementations are fixed | ||
gl.bindBuffer(gl.ARRAY_BUFFER, null); // this is not needed | ||
return buf; | ||
} | ||
|
||
function createVAO(gl, buf, inLoc) { | ||
const vao = gl.createVertexArray(); | ||
gl.bindVertexArray(vao); | ||
gl.bindBuffer(gl.ARRAY_BUFFER, buf); | ||
gl.enableVertexAttribArray(inLoc); | ||
gl.vertexAttribPointer(inLoc, 1, gl.FLOAT, false, 0, 0); | ||
// FIXME: this should not be needed once the spec and implementations are fixed | ||
gl.bindBuffer(gl.ARRAY_BUFFER, null); // this is not needed | ||
gl.bindVertexArray(null); | ||
return vao; | ||
} | ||
</script> | ||
|
||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outLoc is not used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed