diff --git a/OgreMain/include/OgreRenderSystem.h b/OgreMain/include/OgreRenderSystem.h index 6fcede06fb6..4b28c06cf3f 100644 --- a/OgreMain/include/OgreRenderSystem.h +++ b/OgreMain/include/OgreRenderSystem.h @@ -316,16 +316,15 @@ namespace Ogre See TextureFlags::TextureFlags. Relevant flags are: NotTexture + RenderToTexture Uav - @param depthTextureFlags - Only used if format is a colour pixel format. - Same as textureFlags, but for associated depth buffer if format. + RenderWindowSpecific @return Supported sample description for requested FSAA mode, with graceful downgrading. */ virtual SampleDescription validateSampleDescription( const SampleDescription &sampleDesc, - PixelFormatGpu format, uint32 textureFlags, - uint32 depthTextureFlags ); + PixelFormatGpu format, + uint32 textureFlags ); /** Creates a new rendering window. @remarks diff --git a/OgreMain/src/OgreRenderSystem.cpp b/OgreMain/src/OgreRenderSystem.cpp index 2070405789a..65462105615 100644 --- a/OgreMain/src/OgreRenderSystem.cpp +++ b/OgreMain/src/OgreRenderSystem.cpp @@ -811,8 +811,7 @@ namespace Ogre //----------------------------------------------------------------------- SampleDescription RenderSystem::validateSampleDescription( const SampleDescription &sampleDesc, PixelFormatGpu format, - uint32 textureFlags, - uint32 depthTextureFlags ) + uint32 textureFlags ) { SampleDescription retVal( sampleDesc.getMaxSamples(), sampleDesc.getMsaaPattern() ); return retVal; diff --git a/OgreMain/src/OgreTextureGpu.cpp b/OgreMain/src/OgreTextureGpu.cpp index 53f5a3efc86..5f7fefc72c6 100644 --- a/OgreMain/src/OgreTextureGpu.cpp +++ b/OgreMain/src/OgreTextureGpu.cpp @@ -450,13 +450,9 @@ namespace Ogre uint32 msaaTextureFlags = TextureFlags::NotTexture; if( hasMsaaExplicitResolves() ) msaaTextureFlags = mTextureFlags; - uint32 depthFormatTextureFlags = 0u; - if( !getPreferDepthTexture() ) - depthFormatTextureFlags = TextureFlags::NotTexture; mSampleDescription = mTextureManager->getRenderSystem()->validateSampleDescription( - mRequestedSampleDescription, mPixelFormat, msaaTextureFlags, - depthFormatTextureFlags ); + mRequestedSampleDescription, mPixelFormat, msaaTextureFlags ); } if( !( mSampleDescription == mRequestedSampleDescription ) ) notifyAllListenersTextureChanged( TextureGpuListener::FsaaSettingAlteredByApi, 0 ); diff --git a/RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h b/RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h index 9d396ed525e..38efc81ccc8 100644 --- a/RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h +++ b/RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h @@ -334,8 +334,8 @@ namespace Ogre void postExtraThreadsStarted() override; SampleDescription validateSampleDescription( const SampleDescription &sampleDesc, - PixelFormatGpu format, uint32 textureFlags, - uint32 depthTextureFlags ) override; + PixelFormatGpu format, + uint32 textureFlags ) override; /// @copydoc RenderSystem::getDisplayMonitorCount unsigned int getDisplayMonitorCount() const override; diff --git a/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp b/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp index cd9d02695ab..3213838070f 100644 --- a/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp +++ b/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp @@ -3707,8 +3707,7 @@ namespace Ogre //--------------------------------------------------------------------- SampleDescription D3D11RenderSystem::validateSampleDescription( const SampleDescription &sampleDesc, PixelFormatGpu format, - uint32 textureFlags, - uint32 depthTextureFlags ) + uint32 textureFlags ) { OGRE_UNUSED_VAR( textureFlags ); OGRE_UNUSED_VAR( depthTextureFlags ); diff --git a/RenderSystems/Direct3D11/src/OgreD3D11Window.cpp b/RenderSystems/Direct3D11/src/OgreD3D11Window.cpp index dd42e0ed86a..e3576aa0739 100644 --- a/RenderSystems/Direct3D11/src/OgreD3D11Window.cpp +++ b/RenderSystems/Direct3D11/src/OgreD3D11Window.cpp @@ -336,9 +336,9 @@ namespace Ogre if( mUseFlipMode ) { // swapchain is not multisampled in flip sequential mode, so we reuse it - // D3D11 doesn't care about texture flags, so we leave them as 0. - mSampleDescription = mRenderSystem->validateSampleDescription( mRequestedSampleDescription, - _getRenderFormat(), 0u, 0u ); + mSampleDescription = mRenderSystem->validateSampleDescription( + mRequestedSampleDescription, _getRenderFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); } else { diff --git a/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowHwnd.cpp b/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowHwnd.cpp index 8bf6cdcf5fd..bdc7289d993 100644 --- a/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowHwnd.cpp +++ b/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowHwnd.cpp @@ -158,9 +158,9 @@ namespace Ogre //----------------------------------------------------------------------------------- HRESULT D3D11WindowHwnd::_createSwapChainImpl() { - // D3D11 doesn't care about texture flags, so we leave them as 0. - mSampleDescription = mRenderSystem->validateSampleDescription( mRequestedSampleDescription, - _getRenderFormat(), 0u, 0u ); + mSampleDescription = mRenderSystem->validateSampleDescription( + mRequestedSampleDescription, _getRenderFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); HRESULT hr; // Create swap chain diff --git a/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowWinRT.cpp b/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowWinRT.cpp index 461d9a1ddad..fff013f7c89 100644 --- a/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowWinRT.cpp +++ b/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowWinRT.cpp @@ -118,8 +118,8 @@ namespace Ogre { # if !__OGRE_WINRT_PHONE mSampleDescription = mRenderSystem->validateSampleDescription( - mRequestedSampleDescription, _getRenderFormat(), TextureFlags::NotTexture, - TextureFlags::NotTexture ); + mRequestedSampleDescription, _getRenderFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); # endif DXGI_SWAP_CHAIN_DESC1 desc = {}; desc.Width = 0; // Use automatic sizing. @@ -276,8 +276,8 @@ namespace Ogre { # if !__OGRE_WINRT_PHONE mSampleDescription = mRenderSystem->validateSampleDescription( - mRequestedSampleDescription, _getRenderFormat(), TextureFlags::NotTexture, - TextureFlags::NotTexture ); + mRequestedSampleDescription, _getRenderFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); # endif int widthPx = std::max( 1, (int)floorf( mRequestedWidth * mCompositionScale.Width + 0.5f ) ); diff --git a/RenderSystems/Metal/include/OgreMetalRenderSystem.h b/RenderSystems/Metal/include/OgreMetalRenderSystem.h index c56747ef026..f027e395deb 100644 --- a/RenderSystems/Metal/include/OgreMetalRenderSystem.h +++ b/RenderSystems/Metal/include/OgreMetalRenderSystem.h @@ -297,8 +297,8 @@ namespace Ogre unsigned int getDisplayMonitorCount() const override { return 1; } SampleDescription validateSampleDescription( const SampleDescription &sampleDesc, - PixelFormatGpu format, uint32 textureFlags, - uint32 depthTextureFlags ) override; + PixelFormatGpu format, + uint32 textureFlags ) override; const PixelFormatToShaderType *getPixelFormatToShaderType() const override; diff --git a/RenderSystems/Metal/src/OgreMetalRenderSystem.mm b/RenderSystems/Metal/src/OgreMetalRenderSystem.mm index afe8274a309..65df397c37b 100644 --- a/RenderSystems/Metal/src/OgreMetalRenderSystem.mm +++ b/RenderSystems/Metal/src/OgreMetalRenderSystem.mm @@ -240,8 +240,7 @@ of this software and associated documentation files (the "Software"), to deal //------------------------------------------------------------------------- SampleDescription MetalRenderSystem::validateSampleDescription( const SampleDescription &sampleDesc, PixelFormatGpu format, - uint32 textureFlags, - uint32 depthTextureFlags ) + uint32 textureFlags ) { uint8 samples = sampleDesc.getMaxSamples(); if( @available( iOS 9.0, * ) ) diff --git a/RenderSystems/Metal/src/OgreMetalWindow.mm b/RenderSystems/Metal/src/OgreMetalWindow.mm index 6da96af60cb..cfe29f57aa0 100644 --- a/RenderSystems/Metal/src/OgreMetalWindow.mm +++ b/RenderSystems/Metal/src/OgreMetalWindow.mm @@ -510,8 +510,8 @@ static void SetupMetalWindowListeners( Ogre::MetalWindow *metalWindow, NSWindow // We create our MSAA buffer and it is not accessible, thus NotTexture. // Same for our depth buffer. mSampleDescription = textureManager->getRenderSystem()->validateSampleDescription( - mRequestedSampleDescription, mTexture->getPixelFormat(), TextureFlags::NotTexture, - TextureFlags::NotTexture ); + mRequestedSampleDescription, mTexture->getPixelFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); diff --git a/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h b/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h index efad4ebefd0..a9379f17c91 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h +++ b/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h @@ -406,8 +406,8 @@ namespace Ogre void _descriptorSetUavDestroyed( DescriptorSetUav *set ) override; SampleDescription validateSampleDescription( const SampleDescription &sampleDesc, - PixelFormatGpu format, uint32 textureFlags, - uint32 depthTextureFlags ) override; + PixelFormatGpu format, + uint32 textureFlags ) override; VulkanDevice *getVulkanDevice() const { return mDevice; } void _notifyDeviceStalled(); diff --git a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp index 514ac6159aa..38b8aff68c7 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp @@ -3877,8 +3877,7 @@ namespace Ogre inline bool isPowerOf2( uint32 x ) { return ( x & ( x - 1u ) ) == 0u; } SampleDescription VulkanRenderSystem::validateSampleDescription( const SampleDescription &sampleDesc, PixelFormatGpu format, - uint32 textureFlags, - uint32 depthTextureFlags ) + uint32 textureFlags ) { if( !mDevice ) { @@ -3898,90 +3897,52 @@ namespace Ogre // TODO: Support VK_AMD_mixed_attachment_samples & VK_NV_framebuffer_mixed_samples. return validateSampleDescription( SampleDescription( sampleDesc.getMaxSamples(), sampleDesc.getMsaaPattern() ), format, - textureFlags, depthTextureFlags ); + textureFlags ); } else { // MSAA. - VkSampleCountFlags supportedSampleCounts = 0u; + VkSampleCountFlags supportedSampleCounts = (VK_SAMPLE_COUNT_64_BIT << 1) - 1; - if( PixelFormatGpuUtils::isDepth( format ) ) - { - // Not an if-else typo: storageImageSampleCounts is AND'ed against *DepthSampleCounts. - if( textureFlags & TextureFlags::Uav ) - supportedSampleCounts = deviceLimits.storageImageSampleCounts; - - if( textureFlags & TextureFlags::NotTexture ) - supportedSampleCounts = deviceLimits.framebufferDepthSampleCounts; - else - supportedSampleCounts = deviceLimits.sampledImageDepthSampleCounts; - - if( PixelFormatGpuUtils::isStencil( format ) ) - { - // Not a typo: storageImageSampleCounts is AND'ed against *StencilSampleCounts. - if( textureFlags & TextureFlags::Uav ) - supportedSampleCounts &= deviceLimits.storageImageSampleCounts; - - if( textureFlags & TextureFlags::NotTexture ) - supportedSampleCounts &= deviceLimits.framebufferStencilSampleCounts; - else - supportedSampleCounts &= deviceLimits.sampledImageStencilSampleCounts; - } - } - else if( PixelFormatGpuUtils::isStencil( format ) ) - { - // Not an if-else typo: storageImageSampleCounts is AND'ed against *StencilSampleCounts. - if( textureFlags & TextureFlags::Uav ) - supportedSampleCounts = deviceLimits.storageImageSampleCounts; - - if( textureFlags & TextureFlags::NotTexture ) - supportedSampleCounts = deviceLimits.framebufferStencilSampleCounts; - else - supportedSampleCounts = deviceLimits.sampledImageStencilSampleCounts; - } - else if( format == PFG_NULL ) + if( format == PFG_NULL ) { // PFG_NULL is always NotTexture and can't be Uav, // let's just return to the user what they intended to ask. supportedSampleCounts = deviceLimits.framebufferNoAttachmentsSampleCounts; } - else if( PixelFormatGpuUtils::isInteger( format ) ) - { - // TODO: Query Vulkan 1.2 / extensions to get framebufferIntegerColorSampleCounts. - // supportedSampleCounts = deviceLimits.framebufferIntegerColorSampleCounts; - supportedSampleCounts = VK_SAMPLE_COUNT_1_BIT; - } + else if( textureFlags & TextureFlags::Uav ) + supportedSampleCounts &= deviceLimits.storageImageSampleCounts; else { - if( textureFlags & TextureFlags::Uav ) - supportedSampleCounts = deviceLimits.storageImageSampleCounts; - else if( textureFlags & TextureFlags::NotTexture ) - supportedSampleCounts = deviceLimits.framebufferColorSampleCounts; - else - supportedSampleCounts = deviceLimits.sampledImageColorSampleCounts; + bool isDepth = PixelFormatGpuUtils::isDepth( format ); + bool isStencil = PixelFormatGpuUtils::isStencil( format ); + bool isInteger = PixelFormatGpuUtils::isInteger( format ); - if( PixelFormatGpuUtils::isDepth( format ) ) + if( textureFlags & ( TextureFlags::NotTexture | TextureFlags::RenderToTexture | + TextureFlags::RenderWindowSpecific ) ) { - // Not an if-else typo: storageImage... is AND'ed against *DepthSampleCounts. - if( depthTextureFlags & TextureFlags::Uav ) - supportedSampleCounts &= deviceLimits.storageImageSampleCounts; - - if( depthTextureFlags & TextureFlags::NotTexture ) + // frame buffer + if( !isDepth && !isStencil && !isInteger ) + supportedSampleCounts &= deviceLimits.framebufferColorSampleCounts; + if( isDepth || ( textureFlags & TextureFlags::RenderWindowSpecific ) ) supportedSampleCounts &= deviceLimits.framebufferDepthSampleCounts; - else - supportedSampleCounts &= deviceLimits.sampledImageDepthSampleCounts; + if( isStencil || ( textureFlags & TextureFlags::RenderWindowSpecific ) ) + supportedSampleCounts &= deviceLimits.framebufferStencilSampleCounts; + if( isInteger ) // TODO: Query Vulkan 1.2 / extensions to get framebufferIntegerColorSampleCounts. + supportedSampleCounts &= VK_SAMPLE_COUNT_1_BIT; + } - if( PixelFormatGpuUtils::isStencil( format ) ) - { - // Not a typo: storageImageSampleCounts is AND'ed against *StencilSampleCounts. - if( depthTextureFlags & TextureFlags::Uav ) - supportedSampleCounts &= deviceLimits.storageImageSampleCounts; - - if( depthTextureFlags & TextureFlags::NotTexture ) - supportedSampleCounts &= deviceLimits.framebufferStencilSampleCounts; - else - supportedSampleCounts &= deviceLimits.sampledImageStencilSampleCounts; - } + if( 0 == ( textureFlags & TextureFlags::NotTexture ) ) + { + // sampled image + if( !isDepth && !isStencil && !isInteger ) + supportedSampleCounts &= deviceLimits.sampledImageColorSampleCounts; + if( isDepth || ( textureFlags & TextureFlags::RenderWindowSpecific ) ) + supportedSampleCounts &= deviceLimits.sampledImageDepthSampleCounts; + if( isStencil || ( textureFlags & TextureFlags::RenderWindowSpecific ) ) + supportedSampleCounts &= deviceLimits.sampledImageStencilSampleCounts; + if( isInteger ) + supportedSampleCounts &= deviceLimits.sampledImageIntegerSampleCounts; } } diff --git a/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp b/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp index 3875b0e53aa..3b1bceab498 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp @@ -157,10 +157,12 @@ namespace Ogre mStencilBuffer = mDepthBuffer; } - mTexture->setSampleDescription( mRequestedSampleDescription ); + mSampleDescription = mDevice->mRenderSystem->validateSampleDescription( + mRequestedSampleDescription, mTexture->getPixelFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); + mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) - mDepthBuffer->setSampleDescription( mRequestedSampleDescription ); - mSampleDescription = mRequestedSampleDescription; + mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) { diff --git a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp index bc1b6032ec2..07d4101d34f 100644 --- a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp +++ b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp @@ -418,10 +418,12 @@ namespace Ogre mStencilBuffer = mDepthBuffer; } - mTexture->setSampleDescription( mRequestedSampleDescription ); + mSampleDescription = mDevice->mRenderSystem->validateSampleDescription( + mRequestedSampleDescription, mTexture->getPixelFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); + mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) - mDepthBuffer->setSampleDescription( mRequestedSampleDescription ); - mSampleDescription = mRequestedSampleDescription; + mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) { diff --git a/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp b/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp index db4f507a3e2..7f6e08a56fb 100644 --- a/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp +++ b/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp @@ -237,10 +237,12 @@ namespace Ogre mStencilBuffer = mDepthBuffer; } - mTexture->setSampleDescription( mRequestedSampleDescription ); + mSampleDescription = mDevice->mRenderSystem->validateSampleDescription( + mRequestedSampleDescription, mTexture->getPixelFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); + mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) - mDepthBuffer->setSampleDescription( mRequestedSampleDescription ); - mSampleDescription = mRequestedSampleDescription; + mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) { diff --git a/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp b/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp index 71b70db41a0..6c7206c6e56 100644 --- a/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp +++ b/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp @@ -552,10 +552,12 @@ namespace Ogre mStencilBuffer = mDepthBuffer; } - mTexture->setSampleDescription( mRequestedSampleDescription ); + mSampleDescription = mDevice->mRenderSystem->validateSampleDescription( + mRequestedSampleDescription, mTexture->getPixelFormat(), + TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific ); + mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) - mDepthBuffer->setSampleDescription( mRequestedSampleDescription ); - mSampleDescription = mRequestedSampleDescription; + mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription ); if( mDepthBuffer ) { @@ -567,8 +569,6 @@ namespace Ogre mTexture->_setDepthBufferDefaults( DepthBuffer::POOL_NO_DEPTH, false, PFG_NULL ); } - mSampleDescription = mRequestedSampleDescription; - createSwapchain(); setHidden( mHidden );