Replies: 8 comments
-
There's nothing in your code that's actually async. You're required to exit the current event handler in order for the fence to work. Maybe try this
|
Beta Was this translation helpful? Give feedback.
-
First, many thanks for your reply! I tried to do something similar to your answer in SO: ...
const fence = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
gl.flush();
let aux_resolve;
const aux_promise = new Promise(resolve => aux_resolve = resolve);
function checkSync() {
const status = gl.clientWaitSync(fence, 0, 0);
switch (status) {
case gl.TIMEOUT_EXPIRED:
return setTimeout(checkSync);
case gl.WAIT_FAILED:
throw new Error('should never get here');
default:
gl.deleteSync(fence);
gl.getBufferSubData(gl.TRANSFORM_FEEDBACK_BUFFER, 0, output_data);
aux_resolve();
}
}
setTimeout(checkSync);
await aux_promise;
... I got these messages:
The one below I believe that's due to infinite
Then a consequence of losing context, I believe...
|
Beta Was this translation helpful? Give feedback.
-
There's some voodoo here. I'd suggest you turn off transform feedback before trying to read the buffer, and further, read it via ARRAY_BUFFER, not TRANSFORM_FEEDBACK_BUFFER. It would be much easier to help if you put up a jsgist or jsfiddle or some kind of repo |
Beta Was this translation helpful? Give feedback.
-
Here's a standalone code: const foo_canvas = document.createElement('canvas');
const gl = foo_canvas.getContext("webgl2", {
alpha: false,
antialias: false,
powerPreference: "high-performance"
});
gl.enable(gl.RASTERIZER_DISCARD);
const fragment_shader_source = `
precision mediump float;
void main() {
gl_FragColor = vec4(0, 0, 0, 0);
}
`;
const vertex_shader_source = `
varying float position;
void main() {
position = 1.0;
gl_Position = vec4(0, 0, 0, 0);
}
`;
function create_shader(gl, type, source) {
const shader = gl.createShader(type);
gl.shaderSource(shader, source);
gl.compileShader(shader);
return shader;
}
const fragment_shader = create_shader(gl, gl.FRAGMENT_SHADER, fragment_shader_source);
const vertex_shader = create_shader(gl, gl.VERTEX_SHADER, vertex_shader_source);
const program = gl.createProgram();
gl.attachShader(program, fragment_shader);
gl.attachShader(program, vertex_shader);
gl.linkProgram(program);
gl.useProgram(program);
const data_length = 2;
const transform_feedback = gl.createTransformFeedback();
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, transform_feedback);
gl.transformFeedbackVaryings(program, ["position"], gl.INTERLEAVED_ATTRIBS);
gl.linkProgram(program);
const feedback_buffer = gl.createBuffer();
const output_data = new Float32Array(data_length);
gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, feedback_buffer);
gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, output_data, gl.STATIC_READ);
gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, feedback_buffer);
gl.beginTransformFeedback(gl.POINTS);
gl.drawArrays(gl.POINTS, 0, data_length);
gl.endTransformFeedback();
const fence = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
gl.flush();
checkSync = () => {
const status = gl.clientWaitSync(fence, 0, 0);
switch (status) {
case gl.TIMEOUT_EXPIRED:
return setTimeout(checkSync);
case gl.WAIT_FAILED:
throw new Error('should never get here');
default:
gl.deleteSync(fence);
gl.getBufferSubData(gl.TRANSFORM_FEEDBACK_BUFFER, 0, output_data);
console.log(output_data);
}
}
setTimeout(checkSync); The
But if I remove everything after gl.getBufferSubData(gl.TRANSFORM_FEEDBACK_BUFFER, 0, output_data);
console.log(output_data); I get the expected (I'm having problems to run this code in these code playgrounds, but here is what I tried in JSFiddle). |
Beta Was this translation helpful? Give feedback.
-
Btw, I tried it on Firefox. The code with |
Beta Was this translation helpful? Give feedback.
-
Funny fact about the behavior of this in Firefox, the |
Beta Was this translation helpful? Give feedback.
-
The issue is exactly what the error message said.
I did like I said above, use
https://jsgist.org/?src=502f2a5e036a3414de8ebd38f0eb2140 You can see some random discussion of related topics here |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I don't know whether it's the right place to ask about WebGL2, but if it's not the case, feel free to close this issue.
I'm trying to get some data from
TRANSFORM_FEEDBACK_BUFFER
with the code below:But if I do in this way, I get the following warning msg on
getBufferSubData
:Then, I tried to add the below code just after
gl.endTransformFeedback();
:The problem I'm having here is that
status
is always returninggl.TIMEOUT_EXPIRED
. Then I tried to setgl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL
as thetimeout
value ingl.clientWaitSync
, then I got:This also happens if I set
gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL - 1
. Next, I tried settinggl.TIMEOUT_IGNORED
astimeout
value, with this set,status
is gettinggl.WAIT_FAILED
.What am I missing here in order to rid of that performance warning?
I'm using Chrome 90.0.4430.212.
Beta Was this translation helpful? Give feedback.
All reactions