Skip to content

Commit

Permalink
[Vk] pass Vulkan windows through validateSampleDescription, fixed "Va…
Browse files Browse the repository at this point in the history
…lidation Error: [ VUID-VkImageCreateInfo-samples-02258 ] | MessageID = 0x5fccc613 | vkCreateImage(): pCreateInfo->samples (VK_SAMPLE_COUNT_2_BIT) is not supported by format VK_FORMAT_R8G8B8A8_SRGB"
  • Loading branch information
eugenegff committed Oct 1, 2024
1 parent 1287dbb commit ad09907
Show file tree
Hide file tree
Showing 17 changed files with 77 additions and 118 deletions.
9 changes: 4 additions & 5 deletions OgreMain/include/OgreRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions OgreMain/src/OgreRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions OgreMain/src/OgreTextureGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions RenderSystems/Direct3D11/src/OgreD3D11Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ) );
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Metal/include/OgreMetalRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions RenderSystems/Metal/src/OgreMetalRenderSystem.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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, * ) )
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Metal/src/OgreMetalWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
101 changes: 31 additions & 70 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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;
}
}

Expand Down
8 changes: 5 additions & 3 deletions RenderSystems/Vulkan/src/OgreVulkanWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -567,8 +569,6 @@ namespace Ogre
mTexture->_setDepthBufferDefaults( DepthBuffer::POOL_NO_DEPTH, false, PFG_NULL );
}

mSampleDescription = mRequestedSampleDescription;

createSwapchain();

setHidden( mHidden );
Expand Down

0 comments on commit ad09907

Please sign in to comment.