Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Using "viewport" texture in shaders does not work for multisample levels > 1 #2232

Closed
cosator opened this issue Jan 11, 2018 · 5 comments
Closed
Labels

Comments

@cosator
Copy link

cosator commented Jan 11, 2018

Steps to reproduce:

  • Change multisample level to 1 in Sample.inl
  • Build Water Sample and run it
  • Notice that Water refraction shows black, instead of bottom texture

Notes:

  • Verified on DX11 build on NVIDIA and Intel chipsets.
  • Introduced by commit 46793bb "Match multisample mode of the substitute rendertarget & screen buffers with the final destination".
  • Changing View.cpp line "int multiSample = renderTarget_ ? renderTarget_->GetMultiSample() : graphics_->GetMultiSample();" to "int multiSample = renderTarget_ ? renderTarget_->GetMultiSample() : 1;" appears to fix the issue.
@cadaver
Copy link
Contributor

cadaver commented Jan 12, 2018

This seems to be an oversight in Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport) .. basically, resolving backbuffer to a texture.

If the texture is multisampled and has autoresolve on, it should be marked "resolve dirty" so that it will be resolved to non-MS the next time before being sampled by a shader.

The following code needs to be inserted into the function (all API versions) to fix. Oddly, OpenGL appeared to work for me without.

    if (destination->GetMultiSample() > 1 && destination->GetAutoResolve())
        destination->SetResolveDirty(true);

@cosator
Copy link
Author

cosator commented Jan 12, 2018

@cadaver I tried the fix that you suggested and it did not work. I tried adding the line both at function entry point and exit point, and it didn't make a difference. I only tried for DX11 on an Intel chipset.

@cadaver
Copy link
Contributor

cadaver commented Jan 12, 2018

You're right. It does work on D3D9, but on D3D11 there's something further missing, probably the backbuffer is not being copied right to a multisampled texture. In which case your fix is OK too, and likely better for performance.

@cosator
Copy link
Author

cosator commented Jan 13, 2018

My fix was not based on knowledge of what needs to be done, but rather on reverting the change for that particular case. Right now I don't know enough about that portion of code to come up with a robust fix, but this temporary solution seems to work OK for my application until a proper fix is developed.
Thank you so much for looking into it!

@cadaver
Copy link
Contributor

cadaver commented Jan 13, 2018

I suspect this may have worked with older drivers (because a black screen in the post-process sample should have been noticeable); however on OpenGL it seems to have always worked, ie. the multisample contents seem to be transported almost "magically" to the texture being sampled. Will submit a PR which essentially reverts the change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants