Skip to content
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

fix(webgl) texture to texture copy; framebuffer state leak #2042

Merged
merged 2 commits into from Mar 17, 2024

Conversation

Pessimistress
Copy link
Collaborator

Change List

  • WEBGLFramebuffer constructor resets framebuffer binding to previous handle instead of null
  • WEBGLCommandBuffer copy-texture-to-buffer resets framebuffer binding to previous handle instead of null
  • Fix WEBGLCommandBuffer copy-texture-to-texture

Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, apologize for removing that rebind. It is quite a hack, changing the underlying webgl function, but seems we do need it.

I hope the debugging required to nail this wasn't too painful.

@@ -181,7 +183,9 @@ function _copyTextureToBuffer(device: WebGLDevice, options: CopyTextureToBufferO
);
} finally {
device.gl.bindBuffer(GL.PIXEL_PACK_BUFFER, null);
device.gl.bindFramebuffer(GL.FRAMEBUFFER, null);
if (prevHandle !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - When do we get undefined? When not instrumented?

Can we add a comment explaining why we do not reset in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assignment of prevHandle is in a try/catch so the code may not get executed.

// destinationZ = destinationZ || 0;
device.gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer.handle);
// @ts-expect-error native bindFramebuffer is overridden by our state tracker
const prevHandle: WebGLFramebuffer | null = device.gl.bindFramebuffer(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No undefined here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in a try/catch.

switch (textureTarget) {
case GL.TEXTURE_2D:
case GL.TEXTURE_CUBE_MAP:
device.gl.copyTexSubImage2D(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are new helper functions for 9.1 in webgl-texture-helpers that take care of calling the right webgl function and handle more cases, but if this is meant for cherry-pick to 9.0 the maybe aligning with those can be a separate step.

@Pessimistress Pessimistress merged commit e393572 into master Mar 17, 2024
1 check passed
@Pessimistress Pessimistress deleted the x/framebuffer-fix branch March 17, 2024 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants