Skip to content

Conversation

@ilqvya
Copy link

@ilqvya ilqvya commented May 3, 2023

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS for the read framebuffer is one.

This API works by spec with a system multisampled renderbuffer BUT returns error with user-defined multisampled renderbuffers

MESA project introduced a workaround for Penumbra game: https://gitlab.freedesktop.org/mesa/mesa/-/commit/8ced03437d62b38dc2d8c1bd43c005aedcaf7f72

But it might break other games, so it need to be resolved in Proton layer

Note: Pure WINE does not have this issue, it's only Proton wine fail

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

This API works by spec with a system multisampled renderbuffer BUT returns
error with user-defined multisampled renderbuffers

MESA project introduced a workaround for Penumbra game:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/8ced03437d62b38dc2d8c1bd43c005aedcaf7f72

But it might break other games, so it need to be resolved in Proton layer

Note: Pure WINE does not have this issue, it's only Proton wine fail
@ilqvya
Copy link
Author

ilqvya commented Jun 16, 2023

@doitsujin @ivyl

@ivyl
Copy link
Collaborator

ivyl commented Jun 22, 2023

Merged, thanks!

It should show up in bleeding-edge soon and in the very next experimental release.

@ivyl ivyl closed this Jun 22, 2023
@ivyl
Copy link
Collaborator

ivyl commented Jun 22, 2023

My understanding is that we end up with a user-defined multisampled renderbuffer because of fshack in place of what normally is a system one.

@gofman has some concerns, especially around performance, with enabling this globally for each game that may not even need the hack. I've reverted the change for now and let you two discuss it out. Thanks!

@ivyl ivyl reopened this Jun 22, 2023
@gofman
Copy link
Contributor

gofman commented Jun 22, 2023

Ultimately I need a bit of time for me to come to this and understand the issue.

Do you know how exactly we end up with multisampled read buffer with Proton / fshack while the game does not end up with it in upstream Wine? I'd think that shouldn't happen, and if it does somehow, then maybe that is the part we can attempt to fix instead.

UPDATE:
Why I think it needs a more thorough understanding is:

  • adding an extra GL function hook to fshack diff is unfortunate by itself and complicates the thing, so we need good reason to do it;
  • there is also glCopyTextureSubImage2D function which would also need that probably? Not immediately sure, but there might be something else;
  • if wrongly getting multisampled read buffer ends up being unavoidable with fshack for some reason we will want to at least make sure that the given read buffer is resolved just once and not on every glTexSubImage. Maybe at the moment of such read buffer binding which would also avoid the need to override texture copy functions.

GloriousEggroll pushed a commit to GloriousEggroll/proton-wine that referenced this pull request Jul 2, 2023
GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

This API works by spec with a system multisampled renderbuffer BUT returns
error with user-defined multisampled renderbuffers

MESA project introduced a workaround for Penumbra game:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/8ced03437d62b38dc2d8c1bd43c005aedcaf7f72

But it might break other games, so it need to be resolved in Proton layer

Note: Pure WINE does not have this issue, it's only Proton wine fail

Link: ValveSoftware#189
@gofman
Copy link
Contributor

gofman commented Jul 4, 2023

So I took a look at the game and it doesn't do anything with frame buffers having only the default multisampled one from which it blits to texture with glCopyTextureSubImage2D. Indeed the only difference which fshack is introducing is that it sets a non-default framebuffer, and default framebuffer is special in a way that autoresolves are allowed from it but not from user (that is, having the name other than 0) framebuffers.

Unfortunately I don't see so far any good way of solving that in general with fshack. Note that even performance aside the implementation in this patch won't provide a correct behaviour as it doesn't mind user framebuffers (which, if multisampled, should probably fail the same way, and may even have a different size). That part could be fixed, also framebuffer blit can maybe be performed for only a part of framebuffer.

But more important is that there is much more functions which would need such a fixup to make it correct, at least: glCopyTextureSubImage2D, glCopyTextureSubImage3D, glCopyTexSubImage3D, glReadPixels (and maybe I missed some). That is rather lot of Proton specific function overrides. Doing that just for glCopyTexSubImage2D which is known to only fix one game which already got a workaround in Mesa is not obviously useful.

Ideally we'd have some way to enable the newly added allow_multisampled_copyteximage Mesa option from Proton through environment variable or somehow easier than getting a custom copy of dri conf file. But I'd be hesitant to do even that by default as it doesn't do a fully correct thing with allowing texture copies for all the user framebuffers and not just fshack special default replacement one.

So my suggestion is to leave it until we have at least one game besides already worked around in Mesa which needs something like this.

If there are other ideas how to make fshack behaviour correct here without redefining a lot more OpenGL functions in fshack that could be interesting even without finding games which need it first.

Plagman pushed a commit that referenced this pull request Jul 10, 2023
GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

This API works by spec with a system multisampled renderbuffer BUT returns
error with user-defined multisampled renderbuffers

MESA project introduced a workaround for Penumbra game:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/8ced03437d62b38dc2d8c1bd43c005aedcaf7f72

But it might break other games, so it need to be resolved in Proton layer

Note: Pure WINE does not have this issue, it's only Proton wine fail

Link: #189
Plagman pushed a commit that referenced this pull request Jul 21, 2023
GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

This API works by spec with a system multisampled renderbuffer BUT returns
error with user-defined multisampled renderbuffers

MESA project introduced a workaround for Penumbra game:
https://gitlab.freedesktop.org/mesa/mesa/-/commit/8ced03437d62b38dc2d8c1bd43c005aedcaf7f72

But it might break other games, so it need to be resolved in Proton layer

Note: Pure WINE does not have this issue, it's only Proton wine fail

Link: #189
Plagman pushed a commit that referenced this pull request Aug 29, 2023
Based on a patch by Illia Polishchuk <effolkronium@gmail.com> from
#189

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

CW-Bug-Id: #22662
@gofman
Copy link
Contributor

gofman commented Aug 29, 2023

So I came across another game which hits similar issue (Star Wars Knights of the Old Republic II: The Sith Lords). Unfortunately, as I feared in the previous comment, this PR as is doesn't help the game, it hits the same issue with different functions: glCopyTexImage2D, glReadPixels. The workaround added to Mesa doesn't fully work as well, as it doesn't consider all the related functions (glReadPixels in this case). And workaround in Mesa is not fully helping here anyway as the issue is also on Nvidia, and I'd personally wouldn't pursue perfecting it.

Ironically, there is GL extension EXT_multisampled_render_to_texture which allows to do exactly what we need in fshack, available on Mesa and Nvidia but... only for GLES / not on desktop. As I understand there are some reasons for that (even though the extension just works on desktop if enabled).

So I didn't find anything better than to proceed along the lines of this commit. I pushed an updated version of the commit from this PR to Proton Experimental (currently [bleeding-edge] branch, here is the commit: 6b40f84) followed up by doing the same for glCopyTexImage2D, glReadPixels. My changes in the patch are:

  • factor out resolve_fs_hack_fbo() so it can be reused for other functions, reducing the overall boilerplate;
  • also track fs_hack_needs_resolve in wgl_context to avoid getting gl drawable each time even if no resolve is needed (also avoiding leaking a reference to GL drawable present in the original patch);
  • don't resolve if fs_hack is not enabled at all;
  • don't resolve and don't erroneously bind resolve fbo if fs_hack fbo is not selected as read buffer.

@gofman
Copy link
Contributor

gofman commented Aug 29, 2023

Thanks Illia for your findings and useful patch!

Plagman pushed a commit that referenced this pull request Aug 30, 2023
Based on a patch by Illia Polishchuk <effolkronium@gmail.com> from
#189

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

CW-Bug-Id: #22662
Plagman pushed a commit that referenced this pull request Sep 7, 2023
Based on a patch by Illia Polishchuk <effolkronium@gmail.com> from
#189

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

CW-Bug-Id: #22662
Plagman pushed a commit that referenced this pull request Sep 12, 2023
Based on a patch by Illia Polishchuk <effolkronium@gmail.com> from
#189

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

CW-Bug-Id: #22662
bylaws pushed a commit to bylaws/wine that referenced this pull request Sep 6, 2024
Based on a patch by Illia Polishchuk <effolkronium@gmail.com> from
ValveSoftware/wine#189

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

CW-Bug-Id: #22662
@ilqvya ilqvya closed this by deleting the head repository Sep 10, 2024
bylaws pushed a commit to bylaws/wine that referenced this pull request Apr 30, 2025
Based on work by Zhiyi Zhang, includes work by Giovanni Mascellani, Rémi
Bernon, Arkadiusz Hiler, Kai Krakow, Joshua Ashton, Zebediah Figura, and
Matteo Bruni.

fshack: winex11: Protect fshack framebuffer from glFramebufferTexture2D().

glFramebufferTexture2D() just fails with default framebuffer. But when we have
substitued fshack framebuffer setting the texture destroys it instead.

CW-Bug-Id: #20669

fshack: winex11: Clear fs hack depth / stencil attachment.

fshack: winex11: Support adjusting gamma in the fshack

CW-Bug-Id: 16421

fshack: winex11: Setup gamma shader only once per context.

Fixes GL objects leak and avoids unneccessary shader recreation
when the fs_hack_setup_context() is called due to switching GL
drawable.

For Star Wars - Knights of the Old Republic blank screen.

CW-Bug-Id: #19002

fshack: winex11: Track if multisample resolve is needed in gl_drawable.

As that changes per drawable and not per context.

fshack: winex11: Destroy fshack GL objects only at GL context destroy.

fshack: winex11: Set viewport in fs_hack_setup_context().

For Star Wars - Knights of the Old Republic blank screen.

CW-Bug-Id: #19002

fshack: winex11: Also enable fshack for drawable due to gamma in create_gl_drawable().

For Star Wars - Knights of the Old Republic blank screen.

CW-Bug-Id: #19002

fshack: winex11: Use window dimensions in GL if fshack is enabled for gamma only.

For Star Wars - Knights of the Old Republic blank screen.

CW-Bug-Id: #19002

fshack: winex11: Use window size for texture and framebuffers in fs_hack_setup_context().

For Star Wars - Knights of the Old Republic blank screen.

CW-Bug-Id: #19002

fshack: winex11: Blit the contents of current framebuffer to the fshack's framebuffer in fs_hack_setup_context().

CW-Bug-Id: #20102

Some games might not clear the framebuffer on each frame and rely on the data
in framebuffer to persist through glFlush(), glFinish() etc.
That is currently not the case if the fshack is getting turned on after
some drawing was performed already.

fshack: winex11: Use specific names for textures for SWJKJA.

CW-Bug-Id: #20102

fshack: winex11: Interpolate looked up colour in gamma shader.

CW-Bug-Id: #20400

fshack: winex11: Enable specific names for textures for Quake III Arena.

CW-Bug-Id: #21474

fshack: winex11: Enable specific names for textures for Quake III Team Arena.

CW-Bug-Id: #21474

fshack: winex11: Use linear colour internal format for GL fshack buffer.

CW-Bug-Id: #22260

fshack: winex11: Always blit fs_hack in wglFlush and wglFinish when drawing to front buffer.

CW-Bug-Id: #22608

fshack: winex11: Resolve fbo for glCopyTexSubImage2D.

Based on a patch by Illia Polishchuk <effolkronium@gmail.com> from
ValveSoftware/wine#189

GL_INVALID_OPERATION is generated if: the effective value of GL_SAMPLE_BUFFERS
for the read framebuffer is one.

CW-Bug-Id: #22662

fshack: winex11: Resolve fbo for glCopyTexImage2D.

CW-Bug-Id: #22662

fshack: winex11: Resolve fbo for glReadPixels.

CW-Bug-Id: #22662

fshack: winex11: Save and restore GL_PIXEL_UNPACK_BUFFER_BINDING too.

CW-Bug-Id: #23257

fshack: Use texture name hack for Descent 3

Descent 3's OpenGL renderer will use a texture conflicting with the FS
hack texture, and only a small rectangle in the bottom left corner will
be rendered.

Signed-off-by: John Brooks <john@fastquake.com>

ValveSoftware/wine#211

CW-Bug-Id: #23791

fshack: winex11.drv: Enable GL fshack blitting to GL_FRONT for Arcanum (500810).

CW-Bug-Id: #23916
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.

3 participants