Skip to content

Commit e8b3856

Browse files
committed
[Vk] pass Vulkan windows through validateSampleDescription, fixed "Validation Error: [ VUID-VkImageCreateInfo-samples-02258 ] | MessageID = 0x5fccc613 | vkCreateImage(): pCreateInfo->samples (VK_SAMPLE_COUNT_2_BIT) is not supported by format VK_FORMAT_R8G8B8A8_SRGB"
1 parent 1287dbb commit e8b3856

17 files changed

+77
-119
lines changed

OgreMain/include/OgreRenderSystem.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,15 @@ namespace Ogre
316316
See TextureFlags::TextureFlags.
317317
Relevant flags are:
318318
NotTexture
319+
RenderToTexture
319320
Uav
320-
@param depthTextureFlags
321-
Only used if format is a colour pixel format.
322-
Same as textureFlags, but for associated depth buffer if format.
321+
RenderWindowSpecific
323322
@return
324323
Supported sample description for requested FSAA mode, with graceful downgrading.
325324
*/
326325
virtual SampleDescription validateSampleDescription( const SampleDescription &sampleDesc,
327-
PixelFormatGpu format, uint32 textureFlags,
328-
uint32 depthTextureFlags );
326+
PixelFormatGpu format,
327+
uint32 textureFlags );
329328

330329
/** Creates a new rendering window.
331330
@remarks

OgreMain/src/OgreRenderSystem.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,8 +811,7 @@ namespace Ogre
811811
//-----------------------------------------------------------------------
812812
SampleDescription RenderSystem::validateSampleDescription( const SampleDescription &sampleDesc,
813813
PixelFormatGpu format,
814-
uint32 textureFlags,
815-
uint32 depthTextureFlags )
814+
uint32 textureFlags )
816815
{
817816
SampleDescription retVal( sampleDesc.getMaxSamples(), sampleDesc.getMsaaPattern() );
818817
return retVal;

OgreMain/src/OgreTextureGpu.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,9 @@ namespace Ogre
450450
uint32 msaaTextureFlags = TextureFlags::NotTexture;
451451
if( hasMsaaExplicitResolves() )
452452
msaaTextureFlags = mTextureFlags;
453-
uint32 depthFormatTextureFlags = 0u;
454-
if( !getPreferDepthTexture() )
455-
depthFormatTextureFlags = TextureFlags::NotTexture;
456453

457454
mSampleDescription = mTextureManager->getRenderSystem()->validateSampleDescription(
458-
mRequestedSampleDescription, mPixelFormat, msaaTextureFlags,
459-
depthFormatTextureFlags );
455+
mRequestedSampleDescription, mPixelFormat, msaaTextureFlags );
460456
}
461457
if( !( mSampleDescription == mRequestedSampleDescription ) )
462458
notifyAllListenersTextureChanged( TextureGpuListener::FsaaSettingAlteredByApi, 0 );

RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ namespace Ogre
334334
void postExtraThreadsStarted() override;
335335

336336
SampleDescription validateSampleDescription( const SampleDescription &sampleDesc,
337-
PixelFormatGpu format, uint32 textureFlags,
338-
uint32 depthTextureFlags ) override;
337+
PixelFormatGpu format,
338+
uint32 textureFlags ) override;
339339

340340
/// @copydoc RenderSystem::getDisplayMonitorCount
341341
unsigned int getDisplayMonitorCount() const override;

RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,11 +3707,9 @@ namespace Ogre
37073707
//---------------------------------------------------------------------
37083708
SampleDescription D3D11RenderSystem::validateSampleDescription( const SampleDescription &sampleDesc,
37093709
PixelFormatGpu format,
3710-
uint32 textureFlags,
3711-
uint32 depthTextureFlags )
3710+
uint32 textureFlags )
37123711
{
37133712
OGRE_UNUSED_VAR( textureFlags );
3714-
OGRE_UNUSED_VAR( depthTextureFlags );
37153713

37163714
SampleDescription res;
37173715
DXGI_FORMAT dxgiFormat = D3D11Mappings::get( format );

RenderSystems/Direct3D11/src/OgreD3D11Window.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ namespace Ogre
336336
if( mUseFlipMode )
337337
{
338338
// swapchain is not multisampled in flip sequential mode, so we reuse it
339-
// D3D11 doesn't care about texture flags, so we leave them as 0.
340-
mSampleDescription = mRenderSystem->validateSampleDescription( mRequestedSampleDescription,
341-
_getRenderFormat(), 0u, 0u );
339+
mSampleDescription = mRenderSystem->validateSampleDescription(
340+
mRequestedSampleDescription, _getRenderFormat(),
341+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
342342
}
343343
else
344344
{

RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowHwnd.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ namespace Ogre
158158
//-----------------------------------------------------------------------------------
159159
HRESULT D3D11WindowHwnd::_createSwapChainImpl()
160160
{
161-
// D3D11 doesn't care about texture flags, so we leave them as 0.
162-
mSampleDescription = mRenderSystem->validateSampleDescription( mRequestedSampleDescription,
163-
_getRenderFormat(), 0u, 0u );
161+
mSampleDescription = mRenderSystem->validateSampleDescription(
162+
mRequestedSampleDescription, _getRenderFormat(),
163+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
164164
HRESULT hr;
165165

166166
// Create swap chain

RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowWinRT.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ namespace Ogre
118118
{
119119
# if !__OGRE_WINRT_PHONE
120120
mSampleDescription = mRenderSystem->validateSampleDescription(
121-
mRequestedSampleDescription, _getRenderFormat(), TextureFlags::NotTexture,
122-
TextureFlags::NotTexture );
121+
mRequestedSampleDescription, _getRenderFormat(),
122+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
123123
# endif
124124
DXGI_SWAP_CHAIN_DESC1 desc = {};
125125
desc.Width = 0; // Use automatic sizing.
@@ -276,8 +276,8 @@ namespace Ogre
276276
{
277277
# if !__OGRE_WINRT_PHONE
278278
mSampleDescription = mRenderSystem->validateSampleDescription(
279-
mRequestedSampleDescription, _getRenderFormat(), TextureFlags::NotTexture,
280-
TextureFlags::NotTexture );
279+
mRequestedSampleDescription, _getRenderFormat(),
280+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
281281
# endif
282282

283283
int widthPx = std::max( 1, (int)floorf( mRequestedWidth * mCompositionScale.Width + 0.5f ) );

RenderSystems/Metal/include/OgreMetalRenderSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ namespace Ogre
297297
unsigned int getDisplayMonitorCount() const override { return 1; }
298298

299299
SampleDescription validateSampleDescription( const SampleDescription &sampleDesc,
300-
PixelFormatGpu format, uint32 textureFlags,
301-
uint32 depthTextureFlags ) override;
300+
PixelFormatGpu format,
301+
uint32 textureFlags ) override;
302302

303303
const PixelFormatToShaderType *getPixelFormatToShaderType() const override;
304304

RenderSystems/Metal/src/OgreMetalRenderSystem.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ of this software and associated documentation files (the "Software"), to deal
240240
//-------------------------------------------------------------------------
241241
SampleDescription MetalRenderSystem::validateSampleDescription( const SampleDescription &sampleDesc,
242242
PixelFormatGpu format,
243-
uint32 textureFlags,
244-
uint32 depthTextureFlags )
243+
uint32 textureFlags )
245244
{
246245
uint8 samples = sampleDesc.getMaxSamples();
247246
if( @available( iOS 9.0, * ) )

RenderSystems/Metal/src/OgreMetalWindow.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ static void SetupMetalWindowListeners( Ogre::MetalWindow *metalWindow, NSWindow
510510
// We create our MSAA buffer and it is not accessible, thus NotTexture.
511511
// Same for our depth buffer.
512512
mSampleDescription = textureManager->getRenderSystem()->validateSampleDescription(
513-
mRequestedSampleDescription, mTexture->getPixelFormat(), TextureFlags::NotTexture,
514-
TextureFlags::NotTexture );
513+
mRequestedSampleDescription, mTexture->getPixelFormat(),
514+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
515515
mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );
516516
if( mDepthBuffer )
517517
mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );

RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ namespace Ogre
406406
void _descriptorSetUavDestroyed( DescriptorSetUav *set ) override;
407407

408408
SampleDescription validateSampleDescription( const SampleDescription &sampleDesc,
409-
PixelFormatGpu format, uint32 textureFlags,
410-
uint32 depthTextureFlags ) override;
409+
PixelFormatGpu format,
410+
uint32 textureFlags ) override;
411411
VulkanDevice *getVulkanDevice() const { return mDevice; }
412412
void _notifyDeviceStalled();
413413

RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp

Lines changed: 31 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,8 +3877,7 @@ namespace Ogre
38773877
inline bool isPowerOf2( uint32 x ) { return ( x & ( x - 1u ) ) == 0u; }
38783878
SampleDescription VulkanRenderSystem::validateSampleDescription( const SampleDescription &sampleDesc,
38793879
PixelFormatGpu format,
3880-
uint32 textureFlags,
3881-
uint32 depthTextureFlags )
3880+
uint32 textureFlags )
38823881
{
38833882
if( !mDevice )
38843883
{
@@ -3898,90 +3897,52 @@ namespace Ogre
38983897
// TODO: Support VK_AMD_mixed_attachment_samples & VK_NV_framebuffer_mixed_samples.
38993898
return validateSampleDescription(
39003899
SampleDescription( sampleDesc.getMaxSamples(), sampleDesc.getMsaaPattern() ), format,
3901-
textureFlags, depthTextureFlags );
3900+
textureFlags );
39023901
}
39033902
else
39043903
{
39053904
// MSAA.
3906-
VkSampleCountFlags supportedSampleCounts = 0u;
3905+
VkSampleCountFlags supportedSampleCounts = (VK_SAMPLE_COUNT_64_BIT << 1) - 1;
39073906

3908-
if( PixelFormatGpuUtils::isDepth( format ) )
3909-
{
3910-
// Not an if-else typo: storageImageSampleCounts is AND'ed against *DepthSampleCounts.
3911-
if( textureFlags & TextureFlags::Uav )
3912-
supportedSampleCounts = deviceLimits.storageImageSampleCounts;
3913-
3914-
if( textureFlags & TextureFlags::NotTexture )
3915-
supportedSampleCounts = deviceLimits.framebufferDepthSampleCounts;
3916-
else
3917-
supportedSampleCounts = deviceLimits.sampledImageDepthSampleCounts;
3918-
3919-
if( PixelFormatGpuUtils::isStencil( format ) )
3920-
{
3921-
// Not a typo: storageImageSampleCounts is AND'ed against *StencilSampleCounts.
3922-
if( textureFlags & TextureFlags::Uav )
3923-
supportedSampleCounts &= deviceLimits.storageImageSampleCounts;
3924-
3925-
if( textureFlags & TextureFlags::NotTexture )
3926-
supportedSampleCounts &= deviceLimits.framebufferStencilSampleCounts;
3927-
else
3928-
supportedSampleCounts &= deviceLimits.sampledImageStencilSampleCounts;
3929-
}
3930-
}
3931-
else if( PixelFormatGpuUtils::isStencil( format ) )
3932-
{
3933-
// Not an if-else typo: storageImageSampleCounts is AND'ed against *StencilSampleCounts.
3934-
if( textureFlags & TextureFlags::Uav )
3935-
supportedSampleCounts = deviceLimits.storageImageSampleCounts;
3936-
3937-
if( textureFlags & TextureFlags::NotTexture )
3938-
supportedSampleCounts = deviceLimits.framebufferStencilSampleCounts;
3939-
else
3940-
supportedSampleCounts = deviceLimits.sampledImageStencilSampleCounts;
3941-
}
3942-
else if( format == PFG_NULL )
3907+
if( format == PFG_NULL )
39433908
{
39443909
// PFG_NULL is always NotTexture and can't be Uav,
39453910
// let's just return to the user what they intended to ask.
39463911
supportedSampleCounts = deviceLimits.framebufferNoAttachmentsSampleCounts;
39473912
}
3948-
else if( PixelFormatGpuUtils::isInteger( format ) )
3949-
{
3950-
// TODO: Query Vulkan 1.2 / extensions to get framebufferIntegerColorSampleCounts.
3951-
// supportedSampleCounts = deviceLimits.framebufferIntegerColorSampleCounts;
3952-
supportedSampleCounts = VK_SAMPLE_COUNT_1_BIT;
3953-
}
3913+
else if( textureFlags & TextureFlags::Uav )
3914+
supportedSampleCounts &= deviceLimits.storageImageSampleCounts;
39543915
else
39553916
{
3956-
if( textureFlags & TextureFlags::Uav )
3957-
supportedSampleCounts = deviceLimits.storageImageSampleCounts;
3958-
else if( textureFlags & TextureFlags::NotTexture )
3959-
supportedSampleCounts = deviceLimits.framebufferColorSampleCounts;
3960-
else
3961-
supportedSampleCounts = deviceLimits.sampledImageColorSampleCounts;
3917+
bool isDepth = PixelFormatGpuUtils::isDepth( format );
3918+
bool isStencil = PixelFormatGpuUtils::isStencil( format );
3919+
bool isInteger = PixelFormatGpuUtils::isInteger( format );
39623920

3963-
if( PixelFormatGpuUtils::isDepth( format ) )
3921+
if( textureFlags & ( TextureFlags::NotTexture | TextureFlags::RenderToTexture |
3922+
TextureFlags::RenderWindowSpecific ) )
39643923
{
3965-
// Not an if-else typo: storageImage... is AND'ed against *DepthSampleCounts.
3966-
if( depthTextureFlags & TextureFlags::Uav )
3967-
supportedSampleCounts &= deviceLimits.storageImageSampleCounts;
3968-
3969-
if( depthTextureFlags & TextureFlags::NotTexture )
3924+
// frame buffer
3925+
if( !isDepth && !isStencil && !isInteger )
3926+
supportedSampleCounts &= deviceLimits.framebufferColorSampleCounts;
3927+
if( isDepth || ( textureFlags & TextureFlags::RenderWindowSpecific ) )
39703928
supportedSampleCounts &= deviceLimits.framebufferDepthSampleCounts;
3971-
else
3972-
supportedSampleCounts &= deviceLimits.sampledImageDepthSampleCounts;
3929+
if( isStencil || ( textureFlags & TextureFlags::RenderWindowSpecific ) )
3930+
supportedSampleCounts &= deviceLimits.framebufferStencilSampleCounts;
3931+
if( isInteger ) // TODO: Query Vulkan 1.2 / extensions to get framebufferIntegerColorSampleCounts.
3932+
supportedSampleCounts &= VK_SAMPLE_COUNT_1_BIT;
3933+
}
39733934

3974-
if( PixelFormatGpuUtils::isStencil( format ) )
3975-
{
3976-
// Not a typo: storageImageSampleCounts is AND'ed against *StencilSampleCounts.
3977-
if( depthTextureFlags & TextureFlags::Uav )
3978-
supportedSampleCounts &= deviceLimits.storageImageSampleCounts;
3979-
3980-
if( depthTextureFlags & TextureFlags::NotTexture )
3981-
supportedSampleCounts &= deviceLimits.framebufferStencilSampleCounts;
3982-
else
3983-
supportedSampleCounts &= deviceLimits.sampledImageStencilSampleCounts;
3984-
}
3935+
if( 0 == ( textureFlags & TextureFlags::NotTexture ) )
3936+
{
3937+
// sampled image
3938+
if( !isDepth && !isStencil && !isInteger )
3939+
supportedSampleCounts &= deviceLimits.sampledImageColorSampleCounts;
3940+
if( isDepth || ( textureFlags & TextureFlags::RenderWindowSpecific ) )
3941+
supportedSampleCounts &= deviceLimits.sampledImageDepthSampleCounts;
3942+
if( isStencil || ( textureFlags & TextureFlags::RenderWindowSpecific ) )
3943+
supportedSampleCounts &= deviceLimits.sampledImageStencilSampleCounts;
3944+
if( isInteger )
3945+
supportedSampleCounts &= deviceLimits.sampledImageIntegerSampleCounts;
39853946
}
39863947
}
39873948

RenderSystems/Vulkan/src/OgreVulkanWindow.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ namespace Ogre
157157
mStencilBuffer = mDepthBuffer;
158158
}
159159

160-
mTexture->setSampleDescription( mRequestedSampleDescription );
160+
mSampleDescription = mDevice->mRenderSystem->validateSampleDescription(
161+
mRequestedSampleDescription, mTexture->getPixelFormat(),
162+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
163+
mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );
161164
if( mDepthBuffer )
162-
mDepthBuffer->setSampleDescription( mRequestedSampleDescription );
163-
mSampleDescription = mRequestedSampleDescription;
165+
mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );
164166

165167
if( mDepthBuffer )
166168
{

RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,12 @@ namespace Ogre
418418
mStencilBuffer = mDepthBuffer;
419419
}
420420

421-
mTexture->setSampleDescription( mRequestedSampleDescription );
421+
mSampleDescription = mDevice->mRenderSystem->validateSampleDescription(
422+
mRequestedSampleDescription, mTexture->getPixelFormat(),
423+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
424+
mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );
422425
if( mDepthBuffer )
423-
mDepthBuffer->setSampleDescription( mRequestedSampleDescription );
424-
mSampleDescription = mRequestedSampleDescription;
426+
mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );
425427

426428
if( mDepthBuffer )
427429
{

RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,12 @@ namespace Ogre
237237
mStencilBuffer = mDepthBuffer;
238238
}
239239

240-
mTexture->setSampleDescription( mRequestedSampleDescription );
240+
mSampleDescription = mDevice->mRenderSystem->validateSampleDescription(
241+
mRequestedSampleDescription, mTexture->getPixelFormat(),
242+
TextureFlags::NotTexture | TextureFlags::RenderWindowSpecific );
243+
mTexture->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );
241244
if( mDepthBuffer )
242-
mDepthBuffer->setSampleDescription( mRequestedSampleDescription );
243-
mSampleDescription = mRequestedSampleDescription;
245+
mDepthBuffer->_setSampleDescription( mRequestedSampleDescription, mSampleDescription );
244246

245247
if( mDepthBuffer )
246248
{

0 commit comments

Comments
 (0)