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

premultiplied backbuffer for UWP/SwapchainPanel #2837

Merged
merged 6 commits into from
Jul 18, 2022

Conversation

CedricGuillemet
Copy link
Contributor

@CedricGuillemet CedricGuillemet commented Jul 7, 2022

Short story:
Add a new reset flag that will premultiply the back buffer RGB values for D3D11 / UWP / SwapchainPanel just before presentation.

Long Story:
For one of our partner, we want a transparent swapchainpanel on top of react-native components. Basically, use the alpha channel of the backbuffer for opacity when the SWP is ontop of other controls. It's not possible to change the composition mode of the SWP as it is on other platforms (for Android and iOS, it's simply an opacity flag). There is one compositing mode that is useless for us. When creating the SWP, it's possible to set it has having premultiplied alpha. Straight alpha is only available for CoreWindows (not our case). So, I've added a fullscreen pass using clearquad infos that multiplies the backbuffer RGB values by the alpha and keeps the alpha unchanged. And the SWP alpha flag is changed to premultiplied.

@bkaradzic
Copy link
Owner

Just to understand this feature, it's something like transparent window?
#1424

@CedricGuillemet
Copy link
Contributor Author

More or less, yes. But more specifically for swapchainpanel/dx11.

@bkaradzic
Copy link
Owner

More or less, yes. But more specifically for swapchainpanel/dx11.

Yeah, I just don't like features for single renderer. I want to try to add for at least one more, that way better terminology/naming is decided. For example this premultiplied sounds 1:1 with some D3D11 swapchain flag/feature. Where BGFX_RESET_TRANSPARENT_BACKBUFFER would be more appropriate in general case for all renderers.

@bkaradzic
Copy link
Owner

Also you would have to add BGFX_CAPS_TRANSPARENT_BACKBUFFER and enable it depending on support.

For example if you follow HDR10 support, it has both defined as:

./include/bgfx/defines.h
452:#define BGFX_RESET_HDR10                          UINT32_C(0x00010000) //!< Enable HDR10 rendering.
472:#define BGFX_CAPS_HDR10                           UINT64_C(0x0000000000000100) //!< HDR10 rendering is supported.

@CedricGuillemet
Copy link
Contributor Author

I want to try to add for at least one more

I can do it for DX11 and 12.

@bkaradzic
Copy link
Owner

I can do it for DX11 and 12.

Sure.

Rename BGFX_RESET_PREMULTIPLIED_BACKBUFFER to BGFX_RESET_TRANSPARENT_BACKBUFFER.

And add BGFX_CAPS_TRANSPARENT_BACKBUFFER flag, and in backends where you implement this feature, add this flag to cpas so that user can figure it out it's supported.

And I'll add support to GL, VK.

@CedricGuillemet
Copy link
Contributor Author

I did the change for GL instead of D3D12. I don't know enough the D3D12 API to do it properly.

src/dxgi.cpp Outdated
@@ -309,6 +309,9 @@ namespace bgfx

_caps.supported |= hdr10 ? BGFX_CAPS_HDR10 : 0;

#if BX_PLATFORM_WINRT
_caps.supported |= BGFX_CAPS_TRANSPARENT_BACKBUFFER;
Copy link
Owner

Choose a reason for hiding this comment

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

Preferred form is (reduces ifdefery):

_caps.supported |= BX_ENABLED(BX_PLATFORM_WINRT) ? BGFX_CAPS_TRANSPARENT_BACKBUFFER : 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@bkaradzic
Copy link
Owner

I did the change for GL instead of D3D12. I don't know enough the D3D12 API to do it properly.

Yeah two platforms is good enough, I'll add elsewhere.

@bkaradzic bkaradzic merged commit a3d52fa into bkaradzic:master Jul 18, 2022
mipek pushed a commit to mipek/bgfx that referenced this pull request Mar 2, 2024
* premultiplied backbuffer for UWP/SwapchainPanel

* init flag

* caps and feedback/opengl premul

* reduced #ifdef form

* removed ifdef
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.

2 participants