diff --git a/.gitignore b/.gitignore index 40543d2b965..fd5c2ccb955 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ syntax: glob *.rule *.sdf .DS_Store -Dependencies/* +Dependencies iOSDependencies build/* SDK/OSX/sdk_contents @@ -28,4 +28,4 @@ AndroidBuild/ AndroidDependencies/ Build/ EmscriptenDependencies -EmscriptenBuild \ No newline at end of file +EmscriptenBuild diff --git a/CMakeLists.txt b/CMakeLists.txt index dac665e58c7..9828a8056d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ endif () # OgreAddTargets and OgreConfigTargets make use of OGRE_NEXT and OGRE_NEXT_PREFIX option(OGRE_USE_NEW_PROJECT_NAME "Libraries containing Ogre name will be called OgreNext, e.g. 'OgreNext.dll' instead of 'Ogre.dll'" - FALSE) + TRUE) if( OGRE_USE_NEW_PROJECT_NAME ) set( OGRE_NEXT "OgreNext" ) @@ -559,7 +559,7 @@ set( OGRE_DEBUG_LEVEL_DEBUG 3 CACHE STRING 3 - High. We perform intensive validation without concerns for performance." ) set( OGRE_DEBUG_LEVEL_RELEASE 0 CACHE STRING - "Specify debug level for Release, RelWithDebInfo and MinSizeRel builds. See OGRE_MAX_DEBUG_LEVEL_DEBUG" ) + "Specify debug level for Release, RelWithDebInfo and MinSizeRel builds. See OGRE_DEBUG_LEVEL_DEBUG" ) cmake_dependent_option(OGRE_CONFIG_CONTAINERS_USE_CUSTOM_ALLOCATOR "STL containers in Ogre use the custom allocator" TRUE "" FALSE) if( OGRE_CONFIG_ALLOCATOR EQUAL 0 ) diff --git a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp index 5c262cbf021..930591bc02f 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp @@ -1146,9 +1146,16 @@ namespace Ogre if( getProperty( tid, HlmsBaseProp::Pose ) > 0 ) setProperty( tid, HlmsBaseProp::VertexId, 1 ); - const int32 envProbeMapVal = getProperty( tid, PbsProperty::EnvProbeMap ); - const bool canUseManualProbe = - envProbeMapVal && envProbeMapVal != getProperty( tid, PbsProperty::TargetEnvprobeMap ); + const int32 envProbeMap = getProperty( tid, PbsProperty::EnvProbeMap ); + const int32 targetEnvProbeMap = getProperty( tid, PbsProperty::TargetEnvprobeMap ); + const bool canUseManualProbe = envProbeMap && envProbeMap != targetEnvProbeMap; + + // Reduce shaders variability, reset EnvProbeMap and TargetEnvprobeMap to 1 or 0 + // preserving outcome of predicate 'envprobe_map && envprobe_map != target_envprobe_map' + if( envProbeMap ) + setProperty( tid, PbsProperty::EnvProbeMap, 1 ); + setProperty( tid, PbsProperty::TargetEnvprobeMap, envProbeMap == targetEnvProbeMap ); + if( canUseManualProbe || getProperty( tid, PbsProperty::ParallaxCorrectCubemaps ) ) { setProperty( tid, PbsProperty::UseEnvProbeMap, 1 ); @@ -1368,8 +1375,6 @@ namespace Ogre } } - const int32 envProbeMap = getProperty( tid, PbsProperty::EnvProbeMap ); - const int32 targetEnvProbeMap = getProperty( tid, PbsProperty::TargetEnvprobeMap ); if( ( envProbeMap && envProbeMap != targetEnvProbeMap ) || parallaxCorrectCubemaps ) { if( !envProbeMap || envProbeMap == targetEnvProbeMap ) diff --git a/Components/SceneFormat/CMakeLists.txt b/Components/SceneFormat/CMakeLists.txt index 9a220ff667f..49ba326216d 100644 --- a/Components/SceneFormat/CMakeLists.txt +++ b/Components/SceneFormat/CMakeLists.txt @@ -21,7 +21,7 @@ file( include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -include_directories(${CMAKE_SOURCE_DIR}/Components/Hlms/Common/include) +include_directories(${OGRE_SOURCE_DIR}/Components/Hlms/Common/include) ogre_add_component_include_dir(Hlms/Pbs) add_definitions( -DOgreSceneFormat_EXPORTS ) diff --git a/OgreMain/include/Animation/OgreBone.h b/OgreMain/include/Animation/OgreBone.h index 2c8d21c08db..b9ba8766659 100644 --- a/OgreMain/include/Animation/OgreBone.h +++ b/OgreMain/include/Animation/OgreBone.h @@ -68,7 +68,7 @@ namespace Ogre ArrayMatrixAf4x3 const *RESTRICT_ALIAS mReverseBind; BoneTransform mTransform; -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM mutable bool mCachedTransformOutOfDate; Node *mDebugParentNode; bool mInitialized; @@ -281,9 +281,7 @@ namespace Ogre */ FORCEINLINE const SimpleMatrixAf4x3 &_getLocalSpaceTransform() const { -#if OGRE_DEBUG_MODE - assert( !mCachedTransformOutOfDate ); -#endif + OGRE_ASSERT_MEDIUM( !mCachedTransformOutOfDate ); return mTransform.mDerivedTransform[mTransform.mIndex]; } diff --git a/OgreMain/include/Animation/OgreBone.inl b/OgreMain/include/Animation/OgreBone.inl index d42773e00de..2410db65a7f 100644 --- a/OgreMain/include/Animation/OgreBone.inl +++ b/OgreMain/include/Animation/OgreBone.inl @@ -26,7 +26,7 @@ THE SOFTWARE. ----------------------------------------------------------------------------- */ -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM #define CACHED_TRANSFORM_OUT_OF_DATE() this->setCachedTransformOutOfDate() #else #define CACHED_TRANSFORM_OUT_OF_DATE() ((void)0) diff --git a/OgreMain/include/Compositor/OgreCompositorWorkspace.h b/OgreMain/include/Compositor/OgreCompositorWorkspace.h index cb990a0c434..ac60f53f87d 100644 --- a/OgreMain/include/Compositor/OgreCompositorWorkspace.h +++ b/OgreMain/include/Compositor/OgreCompositorWorkspace.h @@ -159,7 +159,7 @@ namespace Ogre /// Only valid workspaces can update without crashing bool isValid() const { return mValid; } - void setEnabled( bool bEnabled ) { mEnabled = bEnabled; } + void setEnabled( bool bEnabled ); bool getEnabled() const { return mEnabled; } /** When building with OGRE_PROFILING enabled, setting this option to true diff --git a/OgreMain/include/OgreAssert.h b/OgreMain/include/OgreAssert.h index 2aede1c8cb4..8c9934209d8 100644 --- a/OgreMain/include/OgreAssert.h +++ b/OgreMain/include/OgreAssert.h @@ -34,7 +34,6 @@ #define _OgreAssert_H_ #include "OgrePrerequisites.h" -#include "debugbreak/debugbreak.h" namespace Ogre { @@ -57,7 +56,46 @@ namespace Ogre } // namespace Assert } // namespace Ogre -#define OGRE_HALT() debug_break() +// We want to halt using macro + builtin rather than inline function, to generate debug information +// with assertion line number rather than halting machinery line number. Inspired by +// https://github.com/nemequ/portable-snippets/blob/master/debug-trap/debug-trap.h +// https://github.com/scottt/debugbreak/blob/master/debugbreak.h +#if defined( __has_builtin ) +# if __has_builtin( __builtin_debugtrap ) +# define OGRE_HALT() __builtin_debugtrap() +# elif __has_builtin( __debugbreak ) +# define OGRE_HALT() __debugbreak() +# endif +#endif +#if !defined( OGRE_HALT ) +# if defined( _MSC_VER ) || defined( __INTEL_COMPILER ) +# define OGRE_HALT() __debugbreak() +# elif defined( __DMC__ ) && defined( _M_IX86 ) +# define OGRE_HALT() __asm int 3h +# elif defined( __i386__ ) || defined( __x86_64__ ) +# define OGRE_HALT() __asm__ __volatile__( "int3" ) +# elif defined( __thumb__ ) +# define OGRE_HALT() __asm__ __volatile__( ".inst 0xde01" ) +# elif defined( __aarch64__ ) +# define OGRE_HALT() __asm__ __volatile__( ".inst 0xd4200000" ) +# elif defined( __arm__ ) +# define OGRE_HALT() __asm__ __volatile__( ".inst 0xe7f001f0" ) +# elif defined( __alpha__ ) && !defined( __osf__ ) +# define OGRE_HALT() __asm__ __volatile__( "bpt" ) +# elif defined( __powerpc__ ) +# define OGRE_HALT() __asm__ __volatile__( ".4byte 0x7d821008" ) +# elif defined( __riscv ) +# define OGRE_HALT() __asm__ __volatile__( ".4byte 0x00100073" ) +# else +# include +# if defined( SIGTRAP ) +# define OGRE_HALT() raise( SIGTRAP ) +# else +# define OGRE_HALT() raise( SIGABRT ) +# endif +# endif +#endif + #define OGRE_UNUSED( x ) \ do \ { \ @@ -126,12 +164,10 @@ namespace Ogre # define OGRE_VERIFY_MSG( cond, msg, ... ) ( (void)0 ) #endif -#if __cplusplus >= 201103L +#if __cplusplus >= 201703L || defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L +# define OGRE_STATIC_ASSERT( x ) static_assert( x ) +#else // C++11 # define OGRE_STATIC_ASSERT( x ) static_assert( x, # x ) -#else -# define OGRE_STATIC_ASSERT( x ) \ - typedef char OgreStaticAssert[( x ) ? 1 : -1]; \ - OGRE_UNUSED( OgreStaticAssert ); #endif #endif diff --git a/OgreMain/include/OgreDescriptorSetSampler.h b/OgreMain/include/OgreDescriptorSetSampler.h index 7e6a270be14..5d6edff03f2 100644 --- a/OgreMain/include/OgreDescriptorSetSampler.h +++ b/OgreMain/include/OgreDescriptorSetSampler.h @@ -108,17 +108,18 @@ namespace Ogre void checkValidity() const { -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM size_t totalSamplersUsed = 0u; for( size_t i = 0; i < NumShaderTypes; ++i ) totalSamplersUsed += mShaderTypeSamplerCount[i]; - assert( totalSamplersUsed > 0 && - "This DescriptorSetSampler doesn't use any sampler! Perhaps incorrectly setup?" ); - assert( totalSamplersUsed == mSamplers.size() && - "This DescriptorSetSampler doesn't use as many samplers as it " - "claims to have, or uses more than it has provided" ); + OGRE_ASSERT_MEDIUM( + totalSamplersUsed > 0 && + "This DescriptorSetSampler doesn't use any sampler! Perhaps incorrectly setup?" ); + OGRE_ASSERT_MEDIUM( totalSamplersUsed == mSamplers.size() && + "This DescriptorSetSampler doesn't use as many samplers as it " + "claims to have, or uses more than it has provided" ); #endif } }; diff --git a/OgreMain/include/OgreFileSystemLayer.h b/OgreMain/include/OgreFileSystemLayer.h index 02e9cb711ec..ee9cd868ff1 100644 --- a/OgreMain/include/OgreFileSystemLayer.h +++ b/OgreMain/include/OgreFileSystemLayer.h @@ -73,7 +73,7 @@ namespace Ogre */ const Ogre::String getConfigFilePath( Ogre::String filename ) const { -#if OGRE_DEBUG_MODE == 1 && \ +#if OGRE_DEBUG_MODE && \ ( OGRE_PLATFORM != OGRE_PLATFORM_APPLE && OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS ) // add OGRE_BUILD_SUFFIX (default: "_d") to config file names Ogre::String::size_type pos = filename.rfind( '.' ); diff --git a/OgreMain/include/OgreNode.h b/OgreMain/include/OgreNode.h index d7fbb61191a..72a911c529c 100644 --- a/OgreMain/include/OgreNode.h +++ b/OgreMain/include/OgreNode.h @@ -677,9 +677,7 @@ namespace Ogre */ virtual_l2 FORCEINLINE const Matrix4 &_getFullTransform() const { -#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM - assert( !mCachedTransformOutOfDate ); -#endif + OGRE_ASSERT_MEDIUM( !mCachedTransformOutOfDate ); return mTransform.mDerivedTransform[mTransform.mIndex]; } diff --git a/OgreMain/include/OgrePlatform.h b/OgreMain/include/OgrePlatform.h index 2f523435451..f9f7a12e46f 100644 --- a/OgreMain/include/OgrePlatform.h +++ b/OgreMain/include/OgrePlatform.h @@ -331,9 +331,12 @@ THE SOFTWARE. // No checks done at all #define OGRE_DEBUG_NONE 0 // We perform basic assert checks and other non-performance intensive checks +// This setting must NOT break the ABI. i.e. a binary compiled with OGRE_DEBUG_LOW +// must be ABI compatible with a binary compiled without it. #define OGRE_DEBUG_LOW 1 // We alter classes to add some debug variables for a bit more thorough checking // and also perform checks that may cause some performance hit +// This setting or higher is allowed to break the ABI. #define OGRE_DEBUG_MEDIUM 2 // We perform intensive validation without concerns for performance #define OGRE_DEBUG_HIGH 3 diff --git a/OgreMain/include/OgrePrerequisites.h b/OgreMain/include/OgrePrerequisites.h index d858a0fd5dc..29fea2e0750 100644 --- a/OgreMain/include/OgrePrerequisites.h +++ b/OgreMain/include/OgrePrerequisites.h @@ -82,7 +82,7 @@ namespace Ogre #define OGRE_UNUSED_VAR( x ) ( (void)x ) -#if __cplusplus >= 201703L +#if __cplusplus >= 201703L || defined( _MSVC_LANG ) && _MSVC_LANG >= 201703L # define OGRE_FALLTHROUGH [[fallthrough]] #else # if OGRE_COMPILER == OGRE_COMPILER_CLANG 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/include/OgreRenderSystemCapabilities.h b/OgreMain/include/OgreRenderSystemCapabilities.h index 740a41a6989..95b13e7b93e 100644 --- a/OgreMain/include/OgreRenderSystemCapabilities.h +++ b/OgreMain/include/OgreRenderSystemCapabilities.h @@ -331,7 +331,7 @@ namespace Ogre bool hasMinVersion( int minMajor, int minMinor, int minRel ) const { - return major > minMajor || ( major == minMajor && minor >= minMinor ) || + return major > minMajor || ( major == minMajor && minor > minMinor ) || ( major == minMajor && minor == minMinor && release >= minRel ); } }; diff --git a/OgreMain/include/OgreSceneNode.h b/OgreMain/include/OgreSceneNode.h index 9af91c12bfa..90b460364ed 100644 --- a/OgreMain/include/OgreSceneNode.h +++ b/OgreMain/include/OgreSceneNode.h @@ -319,7 +319,7 @@ namespace Ogre NodeMemoryManager *getDefaultNodeMemoryManager( SceneMemoryMgrTypes sceneType ) override; -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM void _setCachedTransformOutOfDate() override; #endif }; diff --git a/OgreMain/src/Animation/OgreBone.cpp b/OgreMain/src/Animation/OgreBone.cpp index 4545a6fddc8..36e97b68861 100644 --- a/OgreMain/src/Animation/OgreBone.cpp +++ b/OgreMain/src/Animation/OgreBone.cpp @@ -36,7 +36,7 @@ THE SOFTWARE. #include "OgreLogManager.h" #include "OgreNode.h" -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM # define CACHED_TRANSFORM_OUT_OF_DATE() this->setCachedTransformOutOfDate() #else # define CACHED_TRANSFORM_OUT_OF_DATE() ( (void)0 ) @@ -49,7 +49,7 @@ namespace Ogre IdObject( 0 ), mReverseBind( 0 ), mTransform( BoneTransform() ), -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM mCachedTransformOutOfDate( true ), mDebugParentNode( 0 ), mInitialized( false ), @@ -65,7 +65,7 @@ namespace Ogre //----------------------------------------------------------------------- Bone::~Bone() { -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM assert( !mInitialized && "Must call _deinitialize() before destructor!" ); #endif } @@ -73,7 +73,7 @@ namespace Ogre void Bone::_initialize( IdType id, BoneMemoryManager *boneMemoryManager, Bone *parent, ArrayMatrixAf4x3 const *RESTRICT_ALIAS reverseBind ) { -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM assert( !mInitialized ); mInitialized = true; #endif @@ -130,14 +130,14 @@ namespace Ogre mReverseBind = 0; mBoneMemoryManager = 0; -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM mInitialized = false; #endif } //----------------------------------------------------------------------- void Bone::setCachedTransformOutOfDate() const { -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM mCachedTransformOutOfDate = true; BoneVec::const_iterator itor = mChildren.begin(); @@ -213,7 +213,7 @@ namespace Ogre //----------------------------------------------------------------------- void Bone::_setNodeParent( Node *nodeParent ) { -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM mDebugParentNode = nodeParent; #endif if( nodeParent ) @@ -251,9 +251,7 @@ namespace Ogre //----------------------------------------------------------------------- Matrix4 Bone::_getDerivedTransform() const { -#if OGRE_DEBUG_MODE - assert( !mCachedTransformOutOfDate ); -#endif + OGRE_ASSERT_MEDIUM( !mCachedTransformOutOfDate ); OGRE_ALIGNED_DECL( Matrix4, localSpaceBone, OGRE_SIMD_ALIGNMENT ); OGRE_ALIGNED_DECL( Matrix4, parentNodeTransform, OGRE_SIMD_ALIGNMENT ); @@ -312,7 +310,7 @@ namespace Ogre /* mat.storeToAoS( mTransform.mDerivedTransform ); -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM for( size_t j=0; j= OGRE_DEBUG_MEDIUM for( size_t j = 0; j < ARRAY_PACKED_REALS; ++j ) { if( t.mOwner[j] ) @@ -403,7 +401,7 @@ namespace Ogre } } //----------------------------------------------------------------------- -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM void Bone::_setCachedTransformOutOfDate() { mCachedTransformOutOfDate = true; } #endif } // namespace Ogre diff --git a/OgreMain/src/Animation/OgreSkeletonAnimManager.cpp b/OgreMain/src/Animation/OgreSkeletonAnimManager.cpp index ba8f882da04..41045ca11d9 100644 --- a/OgreMain/src/Animation/OgreSkeletonAnimManager.cpp +++ b/OgreMain/src/Animation/OgreSkeletonAnimManager.cpp @@ -112,7 +112,7 @@ namespace Ogre skeletonsArray.insert( it, newInstance ); -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_HIGH { // Check all depth levels respect the same ordering FastArray::const_iterator itSkel = skeletonsArray.begin(); @@ -128,7 +128,7 @@ namespace Ogre { Bone **owner1 = transf1[i].mOwner + transf1[i].mIndex; Bone **owner2 = transf2[i].mOwner + transf2[i].mIndex; - assert( owner1 < owner2 ); + OGRE_ASSERT_HIGH( owner1 < owner2 ); } ++itSkel2; diff --git a/OgreMain/src/Animation/OgreTagPoint.cpp b/OgreMain/src/Animation/OgreTagPoint.cpp index f32abd0b4d4..8c31673fc68 100644 --- a/OgreMain/src/Animation/OgreTagPoint.cpp +++ b/OgreMain/src/Animation/OgreTagPoint.cpp @@ -99,9 +99,7 @@ namespace Ogre //----------------------------------------------------------------------- Matrix3 TagPoint::_getDerivedOrientationMatrix() const { -#if OGRE_DEBUG_MODE - assert( !mCachedTransformOutOfDate ); -#endif + OGRE_ASSERT_MEDIUM( !mCachedTransformOutOfDate ); Matrix3 retVal; mTransform.mDerivedTransform[mTransform.mIndex].extract3x3Matrix( retVal ); return retVal; @@ -165,7 +163,7 @@ namespace Ogre finalMat.decomposition( *t.mDerivedPosition, *t.mDerivedScale, *t.mDerivedOrientation ); -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM for( size_t j = 0; j < ARRAY_PACKED_REALS; ++j ) { if( t.mOwner[j] ) @@ -212,7 +210,7 @@ namespace Ogre finalMat.decomposition( *t.mDerivedPosition, *t.mDerivedScale, *t.mDerivedOrientation ); -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM for( size_t j = 0; j < ARRAY_PACKED_REALS; ++j ) { if( t.mOwner[j] ) diff --git a/OgreMain/src/Compositor/OgreCompositorWorkspace.cpp b/OgreMain/src/Compositor/OgreCompositorWorkspace.cpp index 208818a291e..5e0131b2403 100644 --- a/OgreMain/src/Compositor/OgreCompositorWorkspace.cpp +++ b/OgreMain/src/Compositor/OgreCompositorWorkspace.cpp @@ -737,6 +737,15 @@ namespace Ogre return finalTarget; } //----------------------------------------------------------------------------------- + void CompositorWorkspace::setEnabled( bool bEnabled ) + { + if( mEnabled != bEnabled ) + { + mEnabled = bEnabled; + _notifyBarriersDirty(); + } + } + //----------------------------------------------------------------------------------- void CompositorWorkspace::_notifyBarriersDirty() { getCompositorManager()->_notifyBarriersDirty(); } //----------------------------------------------------------------------------------- CompositorManager2 *CompositorWorkspace::getCompositorManager() diff --git a/OgreMain/src/OgreDescriptorSetTexture.cpp b/OgreMain/src/OgreDescriptorSetTexture.cpp index 6e64fccbf50..8c8f5037854 100644 --- a/OgreMain/src/OgreDescriptorSetTexture.cpp +++ b/OgreMain/src/OgreDescriptorSetTexture.cpp @@ -39,17 +39,18 @@ namespace Ogre { void DescriptorSetTexture::checkValidity() const { -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM size_t totalTexturesUsed = 0u; for( size_t i = 0; i < NumShaderTypes; ++i ) totalTexturesUsed += mShaderTypeTexCount[i]; - assert( totalTexturesUsed > 0 && - "This DescriptorSetTexture doesn't use any texture! Perhaps incorrectly setup?" ); - assert( totalTexturesUsed == mTextures.size() && - "This DescriptorSetTexture doesn't use as many textures as it " - "claims to have, or uses more than it has provided" ); + OGRE_ASSERT_MEDIUM( + totalTexturesUsed > 0 && + "This DescriptorSetTexture doesn't use any texture! Perhaps incorrectly setup?" ); + OGRE_ASSERT_MEDIUM( totalTexturesUsed == mTextures.size() && + "This DescriptorSetTexture doesn't use as many textures as it " + "claims to have, or uses more than it has provided" ); #endif } //----------------------------------------------------------------------------------- @@ -72,17 +73,18 @@ namespace Ogre "This DescriptorSetTexture2 doesn't use any texture/buffer! " "Perhaps incorrectly setup?" ); -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM size_t totalTexturesUsed = 0u; for( size_t i = 0; i < NumShaderTypes; ++i ) totalTexturesUsed += mShaderTypeTexCount[i]; - assert( totalTexturesUsed > 0 && - "This DescriptorSetTexture doesn't use any texture! Perhaps incorrectly setup?" ); - assert( totalTexturesUsed == mTextures.size() && - "This DescriptorSetTexture doesn't use as many textures as it " - "claims to have, or uses more than it has provided" ); + OGRE_ASSERT_MEDIUM( + totalTexturesUsed > 0 && + "This DescriptorSetTexture doesn't use any texture! Perhaps incorrectly setup?" ); + OGRE_ASSERT_MEDIUM( totalTexturesUsed == mTextures.size() && + "This DescriptorSetTexture doesn't use as many textures as it " + "claims to have, or uses more than it has provided" ); #endif FastArray::const_iterator itor = mTextures.begin(); diff --git a/OgreMain/src/OgreHlmsDatablock.cpp b/OgreMain/src/OgreHlmsDatablock.cpp index 3ca70250056..0db77973d06 100644 --- a/OgreMain/src/OgreHlmsDatablock.cpp +++ b/OgreMain/src/OgreHlmsDatablock.cpp @@ -382,13 +382,19 @@ namespace Ogre if( !casterBlock && overrideCasterBlock ) { mIgnoreFlushRenderables = true; - if( mBlendblock[0]->mAlphaToCoverage == HlmsBlendblock::A2cDisabled ) + if( mBlendblock[0]->mAlphaToCoverage == HlmsBlendblock::A2cDisabled && + mBlendblock[0]->mSourceBlendFactor == SBF_ONE && + mBlendblock[0]->mDestBlendFactor == SBF_ZERO && + ( !mBlendblock[0]->mSeparateBlend || + ( mBlendblock[0]->mSourceBlendFactorAlpha == SBF_ONE && + mBlendblock[0]->mDestBlendFactorAlpha == SBF_ZERO ) ) ) setBlendblock( mBlendblock[0], true ); else { - HlmsBlendblock blendblockNoAC = *mBlendblock[0]; - blendblockNoAC.mAlphaToCoverage = HlmsBlendblock::A2cDisabled; - setBlendblock( blendblockNoAC, true ); + HlmsBlendblock casterBlendblock = *mBlendblock[0]; + casterBlendblock.mAlphaToCoverage = HlmsBlendblock::A2cDisabled; + casterBlendblock.setBlendType( SBT_REPLACE ); + setBlendblock( casterBlendblock, true ); } mIgnoreFlushRenderables = false; } @@ -419,13 +425,19 @@ namespace Ogre if( !casterBlock && overrideCasterBlock ) { mIgnoreFlushRenderables = true; - if( mBlendblock[0]->mAlphaToCoverage == HlmsBlendblock::A2cDisabled ) + if( mBlendblock[0]->mAlphaToCoverage == HlmsBlendblock::A2cDisabled && + mBlendblock[0]->mSourceBlendFactor == SBF_ONE && + mBlendblock[0]->mDestBlendFactor == SBF_ZERO && + ( !mBlendblock[0]->mSeparateBlend || + ( mBlendblock[0]->mSourceBlendFactorAlpha == SBF_ONE && + mBlendblock[0]->mDestBlendFactorAlpha == SBF_ZERO ) ) ) setBlendblock( mBlendblock[0], true ); else { - HlmsBlendblock blendblockNoAC = *mBlendblock[0]; - blendblockNoAC.mAlphaToCoverage = HlmsBlendblock::A2cDisabled; - setBlendblock( blendblockNoAC, true ); + HlmsBlendblock casterBlendblock = *mBlendblock[0]; + casterBlendblock.mAlphaToCoverage = HlmsBlendblock::A2cDisabled; + casterBlendblock.setBlendType( SBT_REPLACE ); + setBlendblock( casterBlendblock, true ); } mIgnoreFlushRenderables = false; } diff --git a/OgreMain/src/OgreHlmsLowLevel.cpp b/OgreMain/src/OgreHlmsLowLevel.cpp index d3403b08d75..fe6d976e316 100644 --- a/OgreMain/src/OgreHlmsLowLevel.cpp +++ b/OgreMain/src/OgreHlmsLowLevel.cpp @@ -98,7 +98,7 @@ namespace Ogre if( pass->hasFragmentProgram() ) pso.pixelShader = pass->getFragmentProgram(); - bool casterPass = getProperty( tid, HlmsBaseProp::ShadowCaster ) != 0; + bool casterPass = getProperty( passCache.setProperties, HlmsBaseProp::ShadowCaster ) != 0; const HlmsDatablock *datablock = queuedRenderable.renderable->getDatablock(); pso.macroblock = datablock->getMacroblock( casterPass ); diff --git a/OgreMain/src/OgreNode.cpp b/OgreMain/src/OgreNode.cpp index c86b89caae0..de1b5224627 100644 --- a/OgreMain/src/OgreNode.cpp +++ b/OgreMain/src/OgreNode.cpp @@ -255,7 +255,7 @@ namespace Ogre //----------------------------------------------------------------------- /*const Matrix4& Node::_getFullTransform() const { - assert( !mCachedTransformOutOfDate ); + OGRE_ASSERT_MEDIUM( !mCachedTransformOutOfDate ); return mTransform.mDerivedTransform[mTransform.mIndex]; }*/ //----------------------------------------------------------------------- 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/OgreSceneNode.cpp b/OgreMain/src/OgreSceneNode.cpp index 516a11966a9..14b5e028c3a 100644 --- a/OgreMain/src/OgreSceneNode.cpp +++ b/OgreMain/src/OgreSceneNode.cpp @@ -505,7 +505,7 @@ namespace Ogre return &mCreator->_getNodeMemoryManager( sceneType ); } //----------------------------------------------------------------------- -#if OGRE_DEBUG_MODE +#if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM void SceneNode::_setCachedTransformOutOfDate() { Node::_setCachedTransformOutOfDate(); 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/OgreMain/src/WIN32/OgreConfigDialog.cpp b/OgreMain/src/WIN32/OgreConfigDialog.cpp index ccf1f5cf600..b12e301c083 100644 --- a/OgreMain/src/WIN32/OgreConfigDialog.cpp +++ b/OgreMain/src/WIN32/OgreConfigDialog.cpp @@ -47,7 +47,7 @@ namespace Ogre # ifdef OGRE_STATIC_LIB mHInstance = GetModuleHandle( NULL ); # else -# if OGRE_DEBUG_MODE == 1 +# if OGRE_DEBUG_MODE mHInstance = GetModuleHandle( "OgreMain_d.dll" ); # else mHInstance = GetModuleHandle( "OgreMain.dll" ); diff --git a/OgreMain/src/WIN32/OgreErrorDialog.cpp b/OgreMain/src/WIN32/OgreErrorDialog.cpp index f58a52c9b51..ca26ee7b147 100644 --- a/OgreMain/src/WIN32/OgreErrorDialog.cpp +++ b/OgreMain/src/WIN32/OgreErrorDialog.cpp @@ -44,7 +44,7 @@ namespace Ogre # ifdef OGRE_STATIC_LIB mHInstance = GetModuleHandle( NULL ); # else -# if OGRE_DEBUG_MODE == 1 +# if OGRE_DEBUG_MODE mHInstance = GetModuleHandle( "OgreMain_d.dll" ); # else mHInstance = GetModuleHandle( "OgreMain.dll" ); 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/OgreD3D11Device.cpp b/RenderSystems/Direct3D11/src/OgreD3D11Device.cpp index d824c88c6ab..b246b942714 100644 --- a/RenderSystems/Direct3D11/src/OgreD3D11Device.cpp +++ b/RenderSystems/Direct3D11/src/OgreD3D11Device.cpp @@ -224,13 +224,8 @@ namespace Ogre char tmp[64]; sprintf( tmp, "deviceRemovedReason = 0x%08X\n", (unsigned)deviceRemovedReason ); res.append( tmp ); + OGRE_FALLTHROUGH; } - // No 'break', fallthrough to the next switch statement -#if OGRE_COMPILER == OGRE_COMPILER_GNUC || OGRE_COMPILER == OGRE_COMPILER_CLANG - __attribute__( ( fallthrough ) ); -#elif __cplusplus >= 201703L - [[fallthrough]]; -#endif default: { char tmp[64]; diff --git a/RenderSystems/Direct3D11/src/OgreD3D11HLSLProgram.cpp b/RenderSystems/Direct3D11/src/OgreD3D11HLSLProgram.cpp index 9151805dfbc..828cad4df75 100644 --- a/RenderSystems/Direct3D11/src/OgreD3D11HLSLProgram.cpp +++ b/RenderSystems/Direct3D11/src/OgreD3D11HLSLProgram.cpp @@ -848,7 +848,7 @@ namespace Ogre GET_SIZE_OF_NAMES( memberTypeNameSize, mMemberTypeName, Name ); // clang-format off - int sizeOfData = sizeof(uint32) + mMicroCode.size() + size_t sizeOfData = sizeof(uint32) + mMicroCode.size() + sizeof(uint32) // mConstantBufferSize + sizeof(uint32) // mConstantBufferNr + sizeof(uint32) // mNumSlots @@ -973,7 +973,7 @@ namespace Ogre // create microcode GpuProgramManager::Microcode newMicrocode = - GpuProgramManager::getSingleton().createMicrocode( sizeOfData ); + GpuProgramManager::getSingleton().createMicrocode( (uint32)sizeOfData ); # define WRITE_START( curlist, memberType ) \ { \ diff --git a/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp b/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp index cd9d02695ab..26805ad7d36 100644 --- a/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp +++ b/RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp @@ -3707,11 +3707,9 @@ namespace Ogre //--------------------------------------------------------------------- SampleDescription D3D11RenderSystem::validateSampleDescription( const SampleDescription &sampleDesc, PixelFormatGpu format, - uint32 textureFlags, - uint32 depthTextureFlags ) + uint32 textureFlags ) { OGRE_UNUSED_VAR( textureFlags ); - OGRE_UNUSED_VAR( depthTextureFlags ); SampleDescription res; DXGI_FORMAT dxgiFormat = D3D11Mappings::get( format ); 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 3fb39a468b8..fff013f7c89 100644 --- a/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowWinRT.cpp +++ b/RenderSystems/Direct3D11/src/Windowing/WIN32/OgreD3D11WindowWinRT.cpp @@ -86,8 +86,8 @@ namespace Ogre Windows::Foundation::Rect rc = mCoreWindow->Bounds; mLeft = (int)floorf( rc.X * scale + 0.5f ); mTop = (int)floorf( rc.Y * scale + 0.5f ); - mRequestedWidth = rc.Width; - mRequestedHeight = rc.Height; + mRequestedWidth = (int)floorf( rc.Width + 0.5f ); + mRequestedHeight = (int)floorf( rc.Height + 0.5f ); } //----------------------------------------------------------------------------------- D3D11WindowCoreWindow::~D3D11WindowCoreWindow() { destroy(); } @@ -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. @@ -176,8 +176,8 @@ namespace Ogre Windows::Foundation::Rect rc = mCoreWindow->Bounds; mLeft = (int)floorf( rc.X * scale + 0.5f ); mTop = (int)floorf( rc.Y * scale + 0.5f ); - mRequestedWidth = rc.Width; - mRequestedHeight = rc.Height; + mRequestedWidth = (int)floorf( rc.Width + 0.5f ); + mRequestedHeight = (int)floorf( rc.Height + 0.5f ); resizeSwapChainBuffers( 0, 0 ); // pass zero to autodetect size } @@ -245,8 +245,8 @@ namespace Ogre static_cast( mSwapChainPanel->ActualHeight ) ); mCompositionScale = Windows::Foundation::Size( mSwapChainPanel->CompositionScaleX, mSwapChainPanel->CompositionScaleY ); - mRequestedWidth = sz.Width; - mRequestedHeight = sz.Height; + mRequestedWidth = (int)floorf( sz.Width + 0.5f ); + mRequestedHeight = (int)floorf( sz.Height + 0.5f ); } //----------------------------------------------------------------------------------- D3D11WindowSwapChainPanel::~D3D11WindowSwapChainPanel() { destroy(); } @@ -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 ) ); @@ -363,8 +363,8 @@ namespace Ogre static_cast( mSwapChainPanel->ActualHeight ) ); mCompositionScale = Windows::Foundation::Size( mSwapChainPanel->CompositionScaleX, mSwapChainPanel->CompositionScaleY ); - mRequestedWidth = sz.Width; - mRequestedHeight = sz.Height; + mRequestedWidth = (int)floorf( sz.Width + 0.5f ); + mRequestedHeight = (int)floorf( sz.Height + 0.5f ); int widthPx = std::max( 1, (int)floorf( mRequestedWidth * mCompositionScale.Width + 0.5f ) ); int heightPx = std::max( 1, (int)floorf( mRequestedHeight * mCompositionScale.Height + 0.5f ) ); diff --git a/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32GLSupport.cpp b/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32GLSupport.cpp index 48b22d9d5cd..4b5900616e6 100644 --- a/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32GLSupport.cpp +++ b/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32GLSupport.cpp @@ -503,7 +503,7 @@ namespace Ogre # ifdef OGRE_STATIC_LIB hinst = GetModuleHandle( NULL ); # else -# if OGRE_DEBUG_MODE == 1 +# if OGRE_DEBUG_MODE hinst = GetModuleHandle( "RenderSystem_GL3Plus_d.dll" ); # else hinst = GetModuleHandle( "RenderSystem_GL3Plus.dll" ); diff --git a/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp b/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp index 4db87daf02f..7f17e91e428 100644 --- a/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp +++ b/RenderSystems/GL3Plus/src/windowing/win32/OgreWin32Window.cpp @@ -404,7 +404,7 @@ namespace Ogre # ifdef OGRE_STATIC_LIB hInstance = GetModuleHandle( NULL ); # else -# if OGRE_DEBUG_MODE == 1 +# if OGRE_DEBUG_MODE hInstance = GetModuleHandle( "RenderSystem_GL3Plus_d.dll" ); # else hInstance = GetModuleHandle( "RenderSystem_GL3Plus.dll" ); 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/OgreVulkanDevice.h b/RenderSystems/Vulkan/include/OgreVulkanDevice.h index f1eeab966ea..2e2eab4dddd 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanDevice.h +++ b/RenderSystems/Vulkan/include/OgreVulkanDevice.h @@ -135,7 +135,7 @@ namespace Ogre FastArray &outQueueCiArray ); public: - VulkanDevice( VkInstance instance, uint32 deviceIdx, VulkanRenderSystem *renderSystem ); + VulkanDevice( VkInstance instance, const String &deviceName, VulkanRenderSystem *renderSystem ); VulkanDevice( VkInstance instance, const VulkanExternalDevice &externalDevice, VulkanRenderSystem *renderSystem ); ~VulkanDevice(); @@ -153,7 +153,7 @@ namespace Ogre static void addExternalInstanceExtensions( FastArray &extensions ); protected: - void createPhysicalDevice( uint32 deviceIdx ); + void createPhysicalDevice( const String &deviceName ); public: void createDevice( FastArray &extensions, uint32 maxComputeQueues, diff --git a/RenderSystems/Vulkan/include/OgreVulkanQueue.h b/RenderSystems/Vulkan/include/OgreVulkanQueue.h index 37b6dad1c14..a7dfa0a45fd 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanQueue.h +++ b/RenderSystems/Vulkan/include/OgreVulkanQueue.h @@ -77,7 +77,6 @@ namespace Ogre uint32 mQueueIdx; VkQueue mQueue; - VkCommandBuffer mCurrentCmdBuffer; VulkanDevice *mOwnerDevice; @@ -116,6 +115,7 @@ namespace Ogre FastArray mWindowsPendingSwap; protected: + VkCommandBuffer mCurrentCmdBuffer; FastArray mPendingCmds; VulkanVaoManager *mVaoManager; @@ -220,6 +220,11 @@ namespace Ogre void endCommandBuffer(); public: + VkCommandBuffer getCurrentCmdBuffer() + { + OGRE_ASSERT_LOW( mCurrentCmdBuffer ); + return mCurrentCmdBuffer; + } EncoderState getEncoderState() const { return mEncoderState; } void getGraphicsEncoder(); diff --git a/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h b/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h index efad4ebefd0..fa6a09b6b77 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h +++ b/RenderSystems/Vulkan/include/OgreVulkanRenderSystem.h @@ -51,6 +51,13 @@ namespace Ogre struct VulkanHlmsPso; class VulkanSupport; + struct VulkanPhysicalDevice + { + VkPhysicalDevice physicalDevice; + String title; + }; + typedef std::vector VulkanPhysicalDeviceList; + /** Implementation of Vulkan as a rendering system. */ @@ -74,6 +81,7 @@ namespace Ogre VulkanProgramFactory *mVulkanProgramFactory3; VkInstance mVkInstance; + VulkanPhysicalDeviceList mVulkanPhysicalDeviceList; VulkanSupport *mVulkanSupport; std::map mAvailableVulkanSupports; @@ -91,8 +99,6 @@ namespace Ogre v1::VertexData *mCurrentVertexBuffer; VkPrimitiveTopology mCurrentPrimType; - VulkanDevice *mActiveDevice; - VulkanDevice *mDevice; VulkanCache *mCache; @@ -148,8 +154,6 @@ namespace Ogre /// Creates a dummy VkRenderPass for use in PSO creation VkRenderPass getVkRenderPass( HlmsPassPso passPso, uint8 &outMrtCount ); - void bindDescriptorSet() const; - void flushRootLayout(); void flushRootLayoutCS(); @@ -161,7 +165,6 @@ namespace Ogre const String &getName() const override; const String &getFriendlyName() const override; - void refreshConfig(); void initConfigOptions(); ConfigOptionMap &getConfigOptions() override; void setConfigOption( const String &name, const String &value ) override; @@ -204,6 +207,7 @@ namespace Ogre void sharedVkInitialization(); VkInstance getVkInstance() const { return mVkInstance; } + const VulkanPhysicalDeviceList &getVulkanPhysicalDevices( bool refreshList = false ); Window *_initialise( bool autoCreateWindow, const String &windowTitle = "OGRE Render Window" ) override; @@ -274,14 +278,9 @@ namespace Ogre void _dispatch( const HlmsComputePso &pso ) override; void _setVertexArrayObject( const VertexArrayObject *vao ) override; - void flushDescriptorState( - VkPipelineBindPoint pipeline_bind_point, const VulkanConstBufferPacked &constBuffer, - const size_t bindOffset, const size_t bytesToWrite, - const unordered_map::type &shaderBindings ); void _render( const CbDrawCallIndexed *cmd ) override; void _render( const CbDrawCallStrip *cmd ) override; - void bindDescriptorSet( VulkanVaoManager *&vaoManager ); void _renderEmulated( const CbDrawCallIndexed *cmd ) override; void _renderEmulated( const CbDrawCallStrip *cmd ) override; @@ -406,8 +405,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/include/OgreVulkanSupport.h b/RenderSystems/Vulkan/include/OgreVulkanSupport.h index e43d88ff6dd..8e9b4bbfefa 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanSupport.h +++ b/RenderSystems/Vulkan/include/OgreVulkanSupport.h @@ -41,12 +41,8 @@ namespace Ogre class _OgreVulkanExport VulkanSupport { - FastArray mDevices; - bool mSupported; - void enumerateDevices( VulkanRenderSystem *renderSystem ); - void initialize( VulkanRenderSystem *renderSystem ); public: @@ -66,7 +62,7 @@ namespace Ogre virtual String validateConfigOptions(); - uint32 getSelectedDeviceIdx() const; + String getSelectedDeviceName() const; ConfigOptionMap &getConfigOptions( VulkanRenderSystem *renderSystem ); diff --git a/RenderSystems/Vulkan/include/Vao/OgreVulkanVaoManager.h b/RenderSystems/Vulkan/include/Vao/OgreVulkanVaoManager.h index ebb9e12f14a..2cd744be8ed 100644 --- a/RenderSystems/Vulkan/include/Vao/OgreVulkanVaoManager.h +++ b/RenderSystems/Vulkan/include/Vao/OgreVulkanVaoManager.h @@ -538,15 +538,15 @@ namespace Ogre /// Insert into the end of semaphoreArray 'numSemaphores' /// number of semaphores that are safe for use. - void getAvailableSempaphores( VkSemaphoreArray &semaphoreArray, size_t numSemaphores ); - VkSemaphore getAvailableSempaphore(); + void getAvailableSemaphores( VkSemaphoreArray &semaphoreArray, size_t numSemaphores ); + VkSemaphore getAvailableSemaphore(); /// Call this function after you've submitted to the GPU a VkSemaphore that will be waited on. /// i.e. 'semaphore' is part of VkSubmitInfo::pWaitSemaphores or part of /// VkPresentInfoKHR::pWaitSemaphores /// /// After enough frames have passed, this semaphore goes - /// back to a pool for getAvailableSempaphores to use + /// back to a pool for getAvailableSemaphores to use void notifyWaitSemaphoreSubmitted( VkSemaphore semaphore ); void notifyWaitSemaphoresSubmitted( const VkSemaphoreArray &semaphores ); void notifySemaphoreUnused( VkSemaphore semaphore ); diff --git a/RenderSystems/Vulkan/src/OgreVulkanAsyncTextureTicket.cpp b/RenderSystems/Vulkan/src/OgreVulkanAsyncTextureTicket.cpp index f19d91eb87e..7f23f57e19c 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanAsyncTextureTicket.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanAsyncTextureTicket.cpp @@ -132,7 +132,7 @@ namespace Ogre memBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; // GPU must stop using this buffer before we can write into it - vkCmdPipelineBarrier( mQueue->mCurrentCmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, + vkCmdPipelineBarrier( mQueue->getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1u, &memBarrier, 0u, 0, 0u, 0 ); } @@ -168,7 +168,7 @@ namespace Ogre region.imageExtent.height = srcTextureBox.height; region.imageExtent.depth = srcTextureBox.depth; - vkCmdCopyImageToBuffer( mQueue->mCurrentCmdBuffer, srcTextureVk->getFinalTextureName(), + vkCmdCopyImageToBuffer( mQueue->getCurrentCmdBuffer(), srcTextureVk->getFinalTextureName(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, mVboName.mVboName, 1u, ®ion ); if( accurateTracking ) diff --git a/RenderSystems/Vulkan/src/OgreVulkanDescriptorSets.cpp b/RenderSystems/Vulkan/src/OgreVulkanDescriptorSets.cpp index 867bdb3e004..130efa69e26 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanDescriptorSets.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanDescriptorSets.cpp @@ -122,6 +122,7 @@ namespace Ogre if( mLastHazardousTex != hazardousTexIdx ) { const size_t realNumTextures = descSet.mTextures.size(); + mTextures.reserve( 2 * realNumTextures ); mTextures.resize( realNumTextures ); mTextures.appendPOD( mTextures.begin(), mTextures.end() ); mWriteDescSetHazardous.pImageInfo = mTextures.begin() + realNumTextures; diff --git a/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp b/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp index 0df0992e21d..03d002452cc 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp @@ -49,7 +49,7 @@ namespace Ogre { static FastArray msInstanceExtensions; - VulkanDevice::VulkanDevice( VkInstance instance, uint32 deviceIdx, + VulkanDevice::VulkanDevice( VkInstance instance, const String &deviceName, VulkanRenderSystem *renderSystem ) : mInstance( instance ), mPhysicalDevice( 0 ), @@ -62,7 +62,7 @@ namespace Ogre mIsExternal( false ) { memset( &mDeviceMemoryProperties, 0, sizeof( mDeviceMemoryProperties ) ); - createPhysicalDevice( deviceIdx ); + createPhysicalDevice( deviceName ); } //------------------------------------------------------------------------- VulkanDevice::VulkanDevice( VkInstance instance, const VulkanExternalDevice &externalDevice, @@ -77,7 +77,8 @@ namespace Ogre mSupportedStages( 0xFFFFFFFF ), mIsExternal( true ) { - LogManager::getSingleton().logMessage( "Creating Vulkan Device from External VkVulkan handle" ); + LogManager::getSingleton().logMessage( + "Vulkan: Creating Vulkan Device from External VkVulkan handle" ); memset( &mDeviceMemoryProperties, 0, sizeof( mDeviceMemoryProperties ) ); @@ -123,7 +124,8 @@ namespace Ogre for( size_t i = 0u; i < numExtensions; ++i ) { const String extensionName = availableExtensions[i].extensionName; - LogManager::getSingleton().logMessage( "Found device extension: " + extensionName ); + LogManager::getSingleton().logMessage( "Vulkan: Found device extension: " + + extensionName ); extensions.insert( extensionName ); } @@ -136,7 +138,7 @@ namespace Ogre if( extensions.find( itor->extensionName ) == extensions.end() ) { LogManager::getSingleton().logMessage( - "[Vulkan][INFO] External Device claims extension " + + "Vulkan: [INFO] External Device claims extension " + String( itor->extensionName ) + " is present but it's not. This is normal. Ignoring." ); itor = efficientVectorRemove( deviceExtensionsCopy, itor ); @@ -152,8 +154,8 @@ namespace Ogre itor = deviceExtensionsCopy.begin(); while( itor != endt ) { - LogManager::getSingleton().logMessage( "Externally requested Device Extension: " + - String( itor->extensionName ) ); + LogManager::getSingleton().logMessage( + "Vulkan: Externally requested Device Extension: " + String( itor->extensionName ) ); mDeviceExtensions.push_back( itor->extensionName ); ++itor; } @@ -362,7 +364,7 @@ namespace Ogre while( itor != endt ) { - LogManager::getSingleton().logMessage( "Requesting Instance Extension: " + + LogManager::getSingleton().logMessage( "Vulkan: Requesting Instance Extension: " + String( *itor ) ); msInstanceExtensions.push_back( *itor ); ++itor; @@ -388,7 +390,7 @@ namespace Ogre while( itor != endt ) { - LogManager::getSingleton().logMessage( "Externally requested Instance Extension: " + + LogManager::getSingleton().logMessage( "Vulkan: Externally requested Instance Extension: " + String( itor->extensionName ) ); msInstanceExtensions.push_back( itor->extensionName ); ++itor; @@ -397,41 +399,21 @@ namespace Ogre std::sort( msInstanceExtensions.begin(), msInstanceExtensions.end() ); } //------------------------------------------------------------------------- - void VulkanDevice::createPhysicalDevice( uint32 deviceIdx ) + void VulkanDevice::createPhysicalDevice( const String &deviceName ) { - VkResult result = VK_SUCCESS; - - uint32 numDevices = 0u; - result = vkEnumeratePhysicalDevices( mInstance, &numDevices, NULL ); - checkVkResult( result, "vkEnumeratePhysicalDevices" ); - - if( numDevices == 0u ) - { - OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, "No Vulkan devices found.", - "VulkanDevice::createPhysicalDevice" ); - } - - const String numDevicesStr = StringConverter::toString( numDevices ); - String deviceIdsStr = StringConverter::toString( deviceIdx ); - - LogManager::getSingleton().logMessage( "[Vulkan] Found " + numDevicesStr + " devices" ); - - if( deviceIdx >= numDevices ) - { - LogManager::getSingleton().logMessage( "[Vulkan] Requested device index " + deviceIdsStr + - " but there's only " + - StringConverter::toString( numDevices ) + "devices" ); - deviceIdx = 0u; - deviceIdsStr = "0"; - } + const auto& devices = mRenderSystem->getVulkanPhysicalDevices(); + size_t deviceIdx = 0; + for( size_t i = 0; i < devices.size(); ++i ) + if( devices[i].title == deviceName ) + { + deviceIdx = i; + break; + } - LogManager::getSingleton().logMessage( "[Vulkan] Selecting device " + deviceIdsStr ); + LogManager::getSingleton().logMessage( "Vulkan: Requested \"" + deviceName + "\", selected \"" + + devices[deviceIdx].title + "\"" ); - FastArray pd; - pd.resize( numDevices ); - result = vkEnumeratePhysicalDevices( mInstance, &numDevices, pd.begin() ); - checkVkResult( result, "vkEnumeratePhysicalDevices" ); - mPhysicalDevice = pd[deviceIdx]; + mPhysicalDevice = devices[deviceIdx].physicalDevice; vkGetPhysicalDeviceMemoryProperties( mPhysicalDevice, &mDeviceMemoryProperties ); @@ -577,7 +559,8 @@ namespace Ogre while( itor != endt ) { - LogManager::getSingleton().logMessage( "Requesting Extension: " + String( *itor ) ); + LogManager::getSingleton().logMessage( "Vulkan: Requesting Extension: " + + String( *itor ) ); mDeviceExtensions.push_back( *itor ); ++itor; } diff --git a/RenderSystems/Vulkan/src/OgreVulkanDiscardBufferManager.cpp b/RenderSystems/Vulkan/src/OgreVulkanDiscardBufferManager.cpp index 78a35c689fc..cf0b1069688 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanDiscardBufferManager.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanDiscardBufferManager.cpp @@ -96,7 +96,7 @@ namespace Ogre region.srcOffset = ( *itor )->getBlockStart() + oldBuffer.mInternalBufferStart; region.dstOffset = ( *itor )->getBlockStart() + mBuffer.mInternalBufferStart; region.size = ( *itor )->getBlockSize(); - vkCmdCopyBuffer( mDevice->mGraphicsQueue.mCurrentCmdBuffer, oldBuffer.mVboName, + vkCmdCopyBuffer( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), oldBuffer.mVboName, mBuffer.mVboName, 1u, ®ion ); ( *itor )->mLastFrameUsed = currentFrame; } @@ -110,7 +110,7 @@ namespace Ogre } LogManager::getSingleton().logMessage( - "PERFORMANCE WARNING: MetalDiscardBufferManager::growToFit must stall." + "PERFORMANCE WARNING: VulkanDiscardBufferManager::growToFit must stall." "Consider increasing the default discard capacity to at least " + StringConverter::toString( newCapacity ) + " bytes" ); diff --git a/RenderSystems/Vulkan/src/OgreVulkanHardwareBufferCommon.cpp b/RenderSystems/Vulkan/src/OgreVulkanHardwareBufferCommon.cpp index 67bca529ccc..1224070574e 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanHardwareBufferCommon.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanHardwareBufferCommon.cpp @@ -297,7 +297,7 @@ namespace Ogre region.srcOffset = srcOffset + srcOffsetStart; region.dstOffset = dstOffset + dstOffsetStart; region.size = alignToNextMultiple( length, 4u ); - vkCmdCopyBuffer( mDevice->mGraphicsQueue.mCurrentCmdBuffer, srcBuf, dstBuf, 1u, + vkCmdCopyBuffer( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), srcBuf, dstBuf, 1u, ®ion ); if( this->mDiscardBuffer ) diff --git a/RenderSystems/Vulkan/src/OgreVulkanProgram.cpp b/RenderSystems/Vulkan/src/OgreVulkanProgram.cpp index 7bc58302076..d3b87bc146c 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanProgram.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanProgram.cpp @@ -361,7 +361,7 @@ namespace Ogre checkVkResult( result, "vkCreateShaderModule" ); setObjectName( mDevice->mDevice, (uint64_t)mShaderModule, - VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, mName.c_str() ); + VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, mName.c_str() ); } if( !mSpirv.empty() && mType == GPT_VERTEX_PROGRAM ) @@ -778,7 +778,7 @@ namespace Ogre checkVkResult( result, "vkCreateShaderModule" ); setObjectName( mDevice->mDevice, (uint64_t)mShaderModule, - VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, mName.c_str() ); + VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, mName.c_str() ); } if( !mSpirv.empty() && mType == GPT_VERTEX_PROGRAM ) diff --git a/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp b/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp index 327bc13047c..1401efce31b 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanQueue.cpp @@ -54,8 +54,8 @@ namespace Ogre mFamilyIdx( 0u ), mQueueIdx( 0u ), mQueue( 0 ), - mCurrentCmdBuffer( 0 ), mOwnerDevice( 0 ), + mCurrentCmdBuffer( 0 ), mVaoManager( 0 ), mRenderSystem( 0 ), mCurrentFence( 0 ), @@ -635,7 +635,7 @@ namespace Ogre // Wait until earlier render, compute and transfers are done so we can copy what // they wrote (unless we're only here for a texture transition) - vkCmdPipelineBarrier( mCurrentCmdBuffer, srcStage & mOwnerDevice->mSupportedStages, + vkCmdPipelineBarrier( getCurrentCmdBuffer(), srcStage & mOwnerDevice->mSupportedStages, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, numMemBarriers, &memBarrier, 0u, 0, numImageMemBarriers, &imageMemBarrier ); } @@ -839,7 +839,7 @@ namespace Ogre // Wait until earlier render, compute and transfers are done so we can copy what // they wrote (unless we're only here for a texture transition) - vkCmdPipelineBarrier( mCurrentCmdBuffer, srcStage & mOwnerDevice->mSupportedStages, + vkCmdPipelineBarrier( getCurrentCmdBuffer(), srcStage & mOwnerDevice->mSupportedStages, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, numMemBarriers, &memBarrier, 0u, 0, numImageMemBarriers, &imageMemBarrier ); } @@ -937,7 +937,7 @@ namespace Ogre numMemBarriers = 1u; // GPU must stop using this buffer before we can write into it - vkCmdPipelineBarrier( mCurrentCmdBuffer, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, + vkCmdPipelineBarrier( getCurrentCmdBuffer(), VK_PIPELINE_STAGE_VERTEX_INPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, numMemBarriers, &memBarrier, 0u, 0, 0u, 0 ); } @@ -997,7 +997,7 @@ namespace Ogre // Wait until earlier render, compute and transfers are done // Block render, compute and transfers until we're done - vkCmdPipelineBarrier( mCurrentCmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, + vkCmdPipelineBarrier( getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TRANSFER_BIT, dstStage & mOwnerDevice->mSupportedStages, 0, numMemBarriers, &memBarrier, 0u, 0, static_cast( mImageMemBarriers.size() ), mImageMemBarriers.begin() ); @@ -1220,8 +1220,8 @@ namespace Ogre // Get some semaphores so that presentation can wait for this job to finish rendering // (one for each window that will be swapped) numWindowsPendingSwap = mWindowsPendingSwap.size(); - mVaoManager->getAvailableSempaphores( mGpuSignalSemaphForCurrCmdBuff, - numWindowsPendingSwap ); + mVaoManager->getAvailableSemaphores( mGpuSignalSemaphForCurrCmdBuff, + numWindowsPendingSwap ); } if( !mGpuSignalSemaphForCurrCmdBuff.empty() ) diff --git a/RenderSystems/Vulkan/src/OgreVulkanRenderPassDescriptor.cpp b/RenderSystems/Vulkan/src/OgreVulkanRenderPassDescriptor.cpp index 90df712f152..d8139010fc1 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanRenderPassDescriptor.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanRenderPassDescriptor.cpp @@ -904,8 +904,9 @@ namespace Ogre if( mInformationOnly ) return; - VkCommandBuffer cmdBuffer = mQueue->mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mQueue->getCurrentCmdBuffer(); + OGRE_ASSERT_LOW( mSharedFboItor != mRenderSystem->_getFrameBufferDescMap().end() ); const VulkanFrameBufferDescValue &fboDesc = mSharedFboItor->second; size_t fboIdx = 0u; @@ -967,7 +968,7 @@ namespace Ogre if( mQueue->getEncoderState() != VulkanQueue::EncoderGraphicsOpen ) return; - vkCmdEndRenderPass( mQueue->mCurrentCmdBuffer ); + vkCmdEndRenderPass( mQueue->getCurrentCmdBuffer() ); if( isInterruptingRendering ) { diff --git a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp index 71e5906dad5..355f961608b 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp @@ -142,7 +142,8 @@ namespace Ogre sprintf(message, "INFORMATION: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg); } - LogManager::getSingleton().logMessage( message ); + LogManager::getSingleton().logMessage( message, + msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT ? LML_CRITICAL : LML_NORMAL ); free(message); @@ -178,7 +179,6 @@ namespace Ogre mAutoParamsBufferIdx( 0 ), mCurrentAutoParamsBufferPtr( 0 ), mCurrentAutoParamsBufferSpaceLeft( 0 ), - mActiveDevice( 0 ), mDevice( 0 ), mCache( 0 ), mPso( 0 ), @@ -346,13 +346,13 @@ namespace Ogre if( mDummySampler ) { - vkDestroySampler( mActiveDevice->mDevice, mDummySampler, 0 ); + vkDestroySampler( mDevice->mDevice, mDummySampler, 0 ); mDummySampler = 0; } if( mDummyTextureView ) { - vkDestroyImageView( mActiveDevice->mDevice, mDummyTextureView, 0 ); + vkDestroyImageView( mDevice->mDevice, mDummyTextureView, 0 ); mDummyTextureView = 0; } @@ -486,12 +486,11 @@ namespace Ogre auto &hdr = *(PipelineCachePrefixHeader *)buf.data(); if( hdr.magic == ( 'V' | ( 'K' << 8 ) | ( 'P' << 16 ) | ( 'C' << 24 ) ) && hdr.dataSize == buf.size() - sizeof( PipelineCachePrefixHeader ) && - hdr.vendorID == mActiveDevice->mDeviceProperties.vendorID && - hdr.deviceID == mActiveDevice->mDeviceProperties.deviceID && - hdr.driverVersion == mActiveDevice->mDeviceProperties.driverVersion && + hdr.vendorID == mDevice->mDeviceProperties.vendorID && + hdr.deviceID == mDevice->mDeviceProperties.deviceID && + hdr.driverVersion == mDevice->mDeviceProperties.driverVersion && hdr.driverABI == sizeof( void * ) && - 0 == memcmp( hdr.uuid, mActiveDevice->mDeviceProperties.pipelineCacheUUID, - VK_UUID_SIZE ) ) + 0 == memcmp( hdr.uuid, mDevice->mDeviceProperties.pipelineCacheUUID, VK_UUID_SIZE ) ) { auto dataHash = hdr.dataHash; hdr.dataHash = 0; @@ -502,7 +501,7 @@ namespace Ogre } if( result != VK_SUCCESS ) - LogManager::getSingleton().logMessage( "[Vulkan] Pipeline cache outdated, not loaded." ); + LogManager::getSingleton().logMessage( "Vulkan: Pipeline cache outdated, not loaded." ); else { VkPipelineCacheCreateInfo pipelineCacheCreateInfo; @@ -512,36 +511,42 @@ namespace Ogre pipelineCacheCreateInfo.pInitialData = buf.data() + sizeof( PipelineCachePrefixHeader ); VkPipelineCache pipelineCache{}; - result = vkCreatePipelineCache( mActiveDevice->mDevice, &pipelineCacheCreateInfo, + result = vkCreatePipelineCache( mDevice->mDevice, &pipelineCacheCreateInfo, nullptr, &pipelineCache ); if( VK_SUCCESS == result && pipelineCache != 0 ) - std::swap( mActiveDevice->mPipelineCache, pipelineCache ); + { + std::swap( mDevice->mPipelineCache, pipelineCache ); + LogManager::getSingleton().logMessage( "Vulkan: Pipeline cache loaded, " + + StringConverter::toString( buf.size() ) + + " bytes." ); + } else + { LogManager::getSingleton().logMessage( - "[Vulkan] Pipeline cache loading failed. VkResult = " + + "Vulkan: Pipeline cache loading failed. VkResult = " + vkResultToString( result ) ); + } if( pipelineCache != 0 ) - vkDestroyPipelineCache( mActiveDevice->mDevice, pipelineCache, nullptr ); + vkDestroyPipelineCache( mDevice->mDevice, pipelineCache, nullptr ); } } } //------------------------------------------------------------------------- void VulkanRenderSystem::savePipelineCache( DataStreamPtr stream ) const { - static_assert( sizeof( PipelineCachePrefixHeader ) == 48 ); - if( mActiveDevice->mPipelineCache ) + OGRE_STATIC_ASSERT( sizeof( PipelineCachePrefixHeader ) == 48 ); + if( mDevice->mPipelineCache ) { size_t size{}; - VkResult result = vkGetPipelineCacheData( mActiveDevice->mDevice, - mActiveDevice->mPipelineCache, &size, nullptr ); + VkResult result = vkGetPipelineCacheData( mDevice->mDevice, mDevice->mPipelineCache, &size, + nullptr ); if( result == VK_SUCCESS && size > 0 && size <= 0x7FFFFFFF ) { std::vector buf; // PipelineCachePrefixHeader + payload do { buf.resize( sizeof( PipelineCachePrefixHeader ) + size ); - result = vkGetPipelineCacheData( mActiveDevice->mDevice, - mActiveDevice->mPipelineCache, &size, + result = vkGetPipelineCacheData( mDevice->mDevice, mDevice->mPipelineCache, &size, buf.data() + sizeof( PipelineCachePrefixHeader ) ); } while( result == VK_INCOMPLETE ); @@ -554,23 +559,25 @@ namespace Ogre hdr.magic = 'V' | ( 'K' << 8 ) | ( 'P' << 16 ) | ( 'C' << 24 ); hdr.dataSize = (uint32_t)size; hdr.dataHash = 0; - hdr.vendorID = mActiveDevice->mDeviceProperties.vendorID; - hdr.deviceID = mActiveDevice->mDeviceProperties.deviceID; - hdr.driverVersion = mActiveDevice->mDeviceProperties.driverVersion; + hdr.vendorID = mDevice->mDeviceProperties.vendorID; + hdr.deviceID = mDevice->mDeviceProperties.deviceID; + hdr.driverVersion = mDevice->mDeviceProperties.driverVersion; hdr.driverABI = sizeof( void * ); - memcpy( hdr.uuid, mActiveDevice->mDeviceProperties.pipelineCacheUUID, VK_UUID_SIZE ); - static_assert( VK_UUID_SIZE == 16 ); + memcpy( hdr.uuid, mDevice->mDeviceProperties.pipelineCacheUUID, VK_UUID_SIZE ); + OGRE_STATIC_ASSERT( VK_UUID_SIZE == 16 ); uint64 hashResult[2] = {}; OGRE_HASH128_FUNC( buf.data(), (int)buf.size(), IdString::Seed, hashResult ); hdr.dataHash = hashResult[0]; stream->write( buf.data(), buf.size() ); - LogManager::getSingleton().logMessage( "[Vulkan] Pipeline cache saved." ); + LogManager::getSingleton().logMessage( "Vulkan: Pipeline cache saved, " + + StringConverter::toString( buf.size() ) + + " bytes." ); } } if( result != VK_SUCCESS ) - LogManager::getSingleton().logMessage( "[Vulkan] Pipeline cache not saved. VkResult = " + + LogManager::getSingleton().logMessage( "Vulkan: Pipeline cache not saved. VkResult = " + vkResultToString( result ) ); } } @@ -591,14 +598,14 @@ namespace Ogre if( !CreateDebugReportCallback ) { LogManager::getSingleton().logMessage( - "[Vulkan] GetProcAddr: Unable to find vkCreateDebugReportCallbackEXT. " + "Vulkan: GetProcAddr: Unable to find vkCreateDebugReportCallbackEXT. " "Debug reporting won't be available" ); return; } if( !DestroyDebugReportCallback ) { LogManager::getSingleton().logMessage( - "[Vulkan] GetProcAddr: Unable to find vkDestroyDebugReportCallbackEXT. " + "Vulkan: GetProcAddr: Unable to find vkDestroyDebugReportCallbackEXT. " "Debug reporting won't be available" ); return; } @@ -640,25 +647,25 @@ namespace Ogre // We would like to save the device properties for the device capabilities limits. // These limits are needed for buffers' binding alignments. VkPhysicalDeviceProperties *vkProperties = - const_cast( &mActiveDevice->mDeviceProperties ); - vkGetPhysicalDeviceProperties( mActiveDevice->mPhysicalDevice, vkProperties ); + const_cast( &mDevice->mDeviceProperties ); + vkGetPhysicalDeviceProperties( mDevice->mPhysicalDevice, vkProperties ); - VkPhysicalDeviceProperties &properties = mActiveDevice->mDeviceProperties; + VkPhysicalDeviceProperties &properties = mDevice->mDeviceProperties; LogManager::getSingleton().logMessage( - "[Vulkan] API Version: " + + "Vulkan: API Version: " + StringConverter::toString( VK_VERSION_MAJOR( properties.apiVersion ) ) + "." + StringConverter::toString( VK_VERSION_MINOR( properties.apiVersion ) ) + "." + StringConverter::toString( VK_VERSION_PATCH( properties.apiVersion ) ) + " (" + StringConverter::toString( properties.apiVersion, 0, ' ', std::ios::hex ) + ")" ); LogManager::getSingleton().logMessage( - "[Vulkan] Driver Version (raw): " + + "Vulkan: Driver Version (raw): " + StringConverter::toString( properties.driverVersion, 0, ' ', std::ios::hex ) ); LogManager::getSingleton().logMessage( - "[Vulkan] Vendor ID: " + + "Vulkan: Vendor ID: " + StringConverter::toString( properties.vendorID, 0, ' ', std::ios::hex ) ); LogManager::getSingleton().logMessage( - "[Vulkan] Device ID: " + + "Vulkan: Device ID: " + StringConverter::toString( properties.deviceID, 0, ' ', std::ios::hex ) ); rsc->setDeviceName( properties.deviceName ); @@ -710,10 +717,10 @@ namespace Ogre rsc->setDriverVersion( driverVersion ); } - if( mActiveDevice->mDeviceFeatures.imageCubeArray ) + if( mDevice->mDeviceFeatures.imageCubeArray ) rsc->setCapability( RSC_TEXTURE_CUBE_MAP_ARRAY ); - if( mActiveDevice->hasDeviceExtension( VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME ) ) + if( mDevice->hasDeviceExtension( VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME ) ) rsc->setCapability( RSC_VP_AND_RT_ARRAY_INDEX_FROM_ANY_SHADER ); rsc->setCapability( RSC_SHADER_RELAXED_FLOAT ); @@ -724,7 +731,7 @@ namespace Ogre rsc->setCapability( RSC_SHADER_FLOAT16 ); } - if( mActiveDevice->mDeviceFeatures.depthClamp ) + if( mDevice->mDeviceFeatures.depthClamp ) rsc->setCapability( RSC_DEPTH_CLAMP ); { @@ -767,7 +774,7 @@ namespace Ogre rsc->setMaxThreadsPerThreadgroupAxis( deviceLimits.maxComputeWorkGroupSize ); rsc->setMaxThreadsPerThreadgroup( deviceLimits.maxComputeWorkGroupInvocations ); - if( mActiveDevice->mDeviceFeatures.samplerAnisotropy && deviceLimits.maxSamplerAnisotropy > 1u ) + if( mDevice->mDeviceFeatures.samplerAnisotropy && deviceLimits.maxSamplerAnisotropy > 1u ) { rsc->setCapability( RSC_ANISOTROPY ); rsc->setMaxSupportedAnisotropy( deviceLimits.maxSamplerAnisotropy ); @@ -798,9 +805,12 @@ namespace Ogre rsc->setCapability( RSC_CUBEMAPPING ); rsc->setCapability( RSC_TEXTURE_COMPRESSION ); rsc->setCapability( RSC_VBO ); + // VK_INDEX_TYPE_UINT32 is always supported with range at least 2^24-1 + // and even 2^32-1 if mDevice->mDeviceFeatures.fullDrawIndexUint32 + rsc->setCapability( RSC_32BIT_INDEX ); rsc->setCapability( RSC_TWO_SIDED_STENCIL ); rsc->setCapability( RSC_STENCIL_WRAP ); - if( mActiveDevice->mDeviceFeatures.shaderClipDistance ) + if( mDevice->mDeviceFeatures.shaderClipDistance ) rsc->setCapability( RSC_USER_CLIP_PLANES ); rsc->setCapability( RSC_VERTEX_FORMAT_UBYTE4 ); rsc->setCapability( RSC_INFINITE_FAR_PLANE ); @@ -1020,7 +1030,7 @@ namespace Ogre //------------------------------------------------------------------------- void VulkanRenderSystem::initializeExternalVkInstance( VulkanExternalInstance *externalInstance ) { - LogManager::getSingleton().logMessage( "[Vulkan] VkInstance is provided externally" ); + LogManager::getSingleton().logMessage( "Vulkan: VkInstance is provided externally" ); OGRE_ASSERT_LOW( !mVkInstance ); @@ -1043,7 +1053,8 @@ namespace Ogre for( size_t i = 0u; i < numExtensions; ++i ) { const String extensionName = availableExtensions[i].extensionName; - LogManager::getSingleton().logMessage( "Found instance extension: " + extensionName ); + LogManager::getSingleton().logMessage( "Vulkan: Found instance extension: " + + extensionName ); extensions.insert( extensionName ); } @@ -1056,7 +1067,7 @@ namespace Ogre if( extensions.find( itor->extensionName ) == extensions.end() ) { LogManager::getSingleton().logMessage( - "[Vulkan][INFO] External Instance claims extension " + + "Vulkan: [INFO] External Instance claims extension " + String( itor->extensionName ) + " is present but it's not. This is normal. Ignoring." ); itor = efficientVectorRemove( externalInstance->instanceExtensions, itor ); @@ -1101,7 +1112,7 @@ namespace Ogre for( size_t i = 0u; i < numInstanceLayers; ++i ) { const String layerName = instanceLayerProps[i].layerName; - LogManager::getSingleton().logMessage( "Found instance layer: " + layerName ); + LogManager::getSingleton().logMessage( "Vulkan: Found instance layer: " + layerName ); layers.insert( layerName ); } @@ -1113,7 +1124,7 @@ namespace Ogre if( layers.find( itor->layerName ) == layers.end() ) { LogManager::getSingleton().logMessage( - "[Vulkan][INFO] External Instance claims layer " + String( itor->layerName ) + + "Vulkan: [INFO] External Instance claims layer " + String( itor->layerName ) + " is present but it's not. This is normal. Ignoring." ); itor = efficientVectorRemove( externalInstance->instanceLayers, itor ); endt = externalInstance->instanceLayers.end(); @@ -1138,7 +1149,7 @@ namespace Ogre if( mVkInstance ) return; - LogManager::getSingleton().logMessage( "[Vulkan] Initializing VkInstance" ); + LogManager::getSingleton().logMessage( "Vulkan: Initializing VkInstance" ); #ifdef OGRE_VULKAN_WINDOW_NULL mAvailableVulkanSupports["null"]->setSupported(); @@ -1159,7 +1170,8 @@ namespace Ogre for( size_t i = 0u; i < numExtensions; ++i ) { const String extensionName = availableExtensions[i].extensionName; - LogManager::getSingleton().logMessage( "Found instance extension: " + extensionName ); + LogManager::getSingleton().logMessage( "Vulkan: Found instance extension: " + + extensionName ); #ifdef OGRE_VULKAN_WINDOW_WIN32 if( extensionName == VulkanWin32Window::getRequiredExtensionName() ) @@ -1241,7 +1253,7 @@ namespace Ogre for( size_t i = 0u; i < numInstanceLayers; ++i ) { const String layerName = instanceLayerProps[i].layerName; - LogManager::getSingleton().logMessage( "Found instance layer: " + layerName ); + LogManager::getSingleton().logMessage( "Vulkan: Found instance layer: " + layerName ); #if OGRE_DEBUG_MODE >= OGRE_DEBUG_HIGH if( layerName == "VK_LAYER_KHRONOS_validation" ) { @@ -1285,8 +1297,7 @@ namespace Ogre { // vkEnumerateInstanceVersion is available since Vulkan 1.1 PFN_vkEnumerateInstanceVersion enumerateInstanceVersion = - (PFN_vkEnumerateInstanceVersion)vkGetInstanceProcAddr( mVkInstance, - "vkEnumerateInstanceVersion" ); + (PFN_vkEnumerateInstanceVersion)vkGetInstanceProcAddr( 0, "vkEnumerateInstanceVersion" ); if( enumerateInstanceVersion ) { uint32_t apiVersion; @@ -1295,7 +1306,8 @@ namespace Ogre { // Loader version < 1.1.114 is blacklisted as it will just crash. // See https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/258 - bAllow_VK_EXT_debug_utils = true; + bAllow_VK_EXT_debug_utils = + VulkanDevice::hasInstanceExtension( VK_EXT_DEBUG_UTILS_EXTENSION_NAME ); } } } @@ -1311,6 +1323,59 @@ namespace Ogre #endif } //------------------------------------------------------------------------- + const VulkanPhysicalDeviceList &VulkanRenderSystem::getVulkanPhysicalDevices( bool refreshList ) + { + + if( refreshList || mVulkanPhysicalDeviceList.empty() ) + { + LogManager::getSingleton().logMessage( "Vulkan: Device detection starts" ); + + // enumerate + std::vector devices; + VkResult result = VK_SUCCESS; + do + { + uint32 numDevices = 0u; + result = vkEnumeratePhysicalDevices( mVkInstance, &numDevices, NULL ); + checkVkResult( result, "vkEnumeratePhysicalDevices" ); + + if( numDevices == 0u ) + { + OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, "No Vulkan devices found.", + "VulkanRenderSystem::getVkPhysicalDevices" ); + } + + devices.resize( numDevices ); + result = vkEnumeratePhysicalDevices( mVkInstance, &numDevices, devices.data() ); + devices.resize( numDevices ); + if( result != VK_INCOMPLETE ) + checkVkResult( result, "vkEnumeratePhysicalDevices" ); + + } while( result == VK_INCOMPLETE ); + + // assign unique names, allowing reordering/inserting/removing + map::type sameNameCounter; + mVulkanPhysicalDeviceList.clear(); + mVulkanPhysicalDeviceList.reserve(devices.size()); + for (auto device : devices) + { + VkPhysicalDeviceProperties deviceProps; + vkGetPhysicalDeviceProperties( device, &deviceProps ); + + String name( deviceProps.deviceName ); + unsigned sameNameIndex = sameNameCounter[name]++; // inserted entry is zero-initialized + if( sameNameIndex != 0 ) + name += " (" + Ogre::StringConverter::toString( sameNameIndex + 1 ) + ")"; + + LogManager::getSingleton().logMessage( "Vulkan: \"" + name + "\"" ); + mVulkanPhysicalDeviceList.push_back( { device, name } ); + } + + LogManager::getSingleton().logMessage( "Vulkan: Device detection ends" ); + } + return mVulkanPhysicalDeviceList; + } + //------------------------------------------------------------------------- Window *VulkanRenderSystem::_initialise( bool autoCreateWindow, const String &windowTitle ) { Window *autoWindow = 0; @@ -1406,10 +1471,9 @@ namespace Ogre initializeVkInstance(); if( !externalDevice ) - mDevice = new VulkanDevice( mVkInstance, mVulkanSupport->getSelectedDeviceIdx(), this ); + mDevice = new VulkanDevice( mVkInstance, mVulkanSupport->getSelectedDeviceName(), this ); else mDevice = new VulkanDevice( mVkInstance, *externalDevice, this ); - mActiveDevice = mDevice; mNativeShadingLanguageVersion = 450; @@ -1437,7 +1501,8 @@ namespace Ogre for( size_t i = 0u; i < numExtensions; ++i ) { const String extensionName = availableExtensions[i].extensionName; - LogManager::getSingleton().logMessage( "Found device extension: " + extensionName ); + LogManager::getSingleton().logMessage( "Vulkan: Found device extension: " + + extensionName ); if( extensionName == VK_KHR_MAINTENANCE2_EXTENSION_NAME ) { @@ -1523,8 +1588,8 @@ namespace Ogre mVaoManager = vaoManager; mHardwareBufferManager = OGRE_NEW v1::VulkanHardwareBufferManager( mDevice, mVaoManager ); - mActiveDevice->mVaoManager = vaoManager; - mActiveDevice->initQueues(); + mDevice->mVaoManager = vaoManager; + mDevice->initQueues(); vaoManager->initDrawIdVertexBuffer(); FastArray depthFormatCandidates( 5u ); @@ -1589,21 +1654,20 @@ namespace Ogre imageViewCi.subresourceRange.layerCount = 1u; VkResult result = - vkCreateImageView( mActiveDevice->mDevice, &imageViewCi, 0, &mDummyTextureView ); + vkCreateImageView( mDevice->mDevice, &imageViewCi, 0, &mDummyTextureView ); checkVkResult( result, "vkCreateImageView" ); } { VkSamplerCreateInfo samplerDescriptor; makeVkStruct( samplerDescriptor, VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO ); - float maxAllowedAnisotropy = - mActiveDevice->mDeviceProperties.limits.maxSamplerAnisotropy; + float maxAllowedAnisotropy = mDevice->mDeviceProperties.limits.maxSamplerAnisotropy; samplerDescriptor.maxAnisotropy = maxAllowedAnisotropy; samplerDescriptor.anisotropyEnable = VK_FALSE; samplerDescriptor.minLod = -std::numeric_limits::max(); samplerDescriptor.maxLod = std::numeric_limits::max(); VkResult result = - vkCreateSampler( mActiveDevice->mDevice, &samplerDescriptor, 0, &mDummySampler ); + vkCreateSampler( mDevice->mDevice, &samplerDescriptor, 0, &mDummySampler ); checkVkResult( result, "vkCreateSampler" ); } @@ -1620,7 +1684,7 @@ namespace Ogre mInitialized = true; } - win->_setDevice( mActiveDevice ); + win->_setDevice( mDevice ); win->_initialize( mTextureGpuManager, miscParams ); return win; @@ -2034,7 +2098,7 @@ namespace Ogre RenderPassDescriptor *VulkanRenderSystem::createRenderPassDescriptor() { VulkanRenderPassDescriptor *retVal = - OGRE_NEW VulkanRenderPassDescriptor( &mActiveDevice->mGraphicsQueue, this ); + OGRE_NEW VulkanRenderPassDescriptor( &mDevice->mGraphicsQueue, this ); mRenderPassDescs.insert( retVal ); return retVal; } @@ -2060,7 +2124,7 @@ namespace Ogre #endif VkPipeline vulkanPso = 0u; - VkResult result = vkCreateComputePipelines( mActiveDevice->mDevice, VK_NULL_HANDLE, 1u, + VkResult result = vkCreateComputePipelines( mDevice->mDevice, mDevice->mPipelineCache, 1u, &computeInfo, 0, &vulkanPso ); checkVkResult( result, "vkCreateComputePipelines" ); @@ -2096,7 +2160,7 @@ namespace Ogre OGRE_ASSERT_LOW( pso->rsData ); VulkanHlmsPso *vulkanPso = static_cast( pso->rsData ); - delayed_vkDestroyPipeline( mVaoManager, mActiveDevice->mDevice, vulkanPso->pso, 0 ); + delayed_vkDestroyPipeline( mVaoManager, mDevice->mDevice, vulkanPso->pso, 0 ); delete vulkanPso; pso->rsData = 0; } @@ -2133,7 +2197,7 @@ namespace Ogre { RenderSystem::_endFrameOnce(); endRenderPassDescriptor( false ); - mActiveDevice->commitAndNextCommandBuffer( SubmissionType::EndFrameAndSwap ); + mDevice->commitAndNextCommandBuffer( SubmissionType::EndFrameAndSwap ); } //------------------------------------------------------------------------- void VulkanRenderSystem::_setHlmsSamplerblock( uint8 texUnit, const HlmsSamplerblock *samplerblock ) @@ -2168,7 +2232,7 @@ namespace Ogre //------------------------------------------------------------------------- void VulkanRenderSystem::_setPipelineStateObject( const HlmsPso *pso ) { - if( pso && mActiveDevice->mGraphicsQueue.getEncoderState() != VulkanQueue::EncoderGraphicsOpen ) + if( pso && mDevice->mGraphicsQueue.getEncoderState() != VulkanQueue::EncoderGraphicsOpen ) { OGRE_ASSERT_LOW( mInterruptedRenderCommandEncoder && @@ -2183,7 +2247,7 @@ namespace Ogre if( mPso ) oldRootLayout = reinterpret_cast( mPso->rsData )->rootLayout; - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); OGRE_ASSERT_LOW( pso->rsData ); VulkanHlmsPso *vulkanPso = reinterpret_cast( pso->rsData ); vkCmdBindPipeline( cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkanPso->pso ); @@ -2199,7 +2263,7 @@ namespace Ogre //------------------------------------------------------------------------- void VulkanRenderSystem::_setComputePso( const HlmsComputePso *pso ) { - mActiveDevice->mGraphicsQueue.getComputeEncoder(); + mDevice->mGraphicsQueue.getComputeEncoder(); if( mComputePso != pso ) { @@ -2213,7 +2277,7 @@ namespace Ogre { OGRE_ASSERT_LOW( pso->rsData ); vulkanPso = reinterpret_cast( pso->rsData ); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); vkCmdBindPipeline( cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, vulkanPso->pso ); if( vulkanPso->rootLayout != oldRootLayout ) @@ -2233,7 +2297,7 @@ namespace Ogre { flushRootLayoutCS(); - vkCmdDispatch( mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer, pso.mNumThreadGroups[0], + vkCmdDispatch( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), pso.mNumThreadGroups[0], pso.mNumThreadGroups[1], pso.mNumThreadGroups[2] ); } //------------------------------------------------------------------------- @@ -2259,7 +2323,7 @@ namespace Ogre OGRE_ASSERT_LOW( numVertexBuffers < 15u ); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); if( numVertexBuffers > 0u ) { vkCmdBindVertexBuffers( cmdBuffer, 0, static_cast( numVertexBuffers ), @@ -2305,7 +2369,7 @@ namespace Ogre { flushRootLayout(); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); vkCmdDrawIndexedIndirect( cmdBuffer, mIndirectBuffer, reinterpret_cast( cmd->indirectBufferOffset ), cmd->numDraws, sizeof( CbDrawIndexed ) ); @@ -2315,7 +2379,7 @@ namespace Ogre { flushRootLayout(); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); vkCmdDrawIndirect( cmdBuffer, mIndirectBuffer, reinterpret_cast( cmd->indirectBufferOffset ), cmd->numDraws, sizeof( CbDrawStrip ) ); @@ -2328,7 +2392,7 @@ namespace Ogre CbDrawIndexed *drawCmd = reinterpret_cast( mSwIndirectBufferPtr + (size_t)cmd->indirectBufferOffset ); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); for( uint32 i = cmd->numDraws; i--; ) { @@ -2346,7 +2410,7 @@ namespace Ogre CbDrawStrip *drawCmd = reinterpret_cast( mSwIndirectBufferPtr + (size_t)cmd->indirectBufferOffset ); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); for( uint32 i = cmd->numDraws; i--; ) { @@ -2360,7 +2424,7 @@ namespace Ogre { VulkanVaoManager *vaoManager = static_cast( mVaoManager ); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); VkBuffer vulkanVertexBuffers[16]; VkDeviceSize offsets[16]; @@ -2421,7 +2485,7 @@ namespace Ogre { flushRootLayout(); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); vkCmdDrawIndexed( cmdBuffer, cmd->primCount, cmd->instanceCount, cmd->firstVertexIndex, (int32_t)mCurrentVertexBuffer->vertexStart, cmd->baseInstance ); } @@ -2430,7 +2494,7 @@ namespace Ogre { flushRootLayout(); - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); vkCmdDraw( cmdBuffer, cmd->primCount, cmd->instanceCount, cmd->firstVertexIndex, cmd->baseInstance ); } @@ -2444,7 +2508,7 @@ namespace Ogre const size_t numberOfInstances = op.numberOfInstances; - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); // Render to screen! if( op.useIndexes ) @@ -2533,15 +2597,20 @@ namespace Ogre size_t bytesToWrite = shader->getBufferRequiredSize(); if( shader && bytesToWrite > 0 ) { - if( mCurrentAutoParamsBufferSpaceLeft < bytesToWrite ) + OGRE_ASSERT_LOW( + mCurrentAutoParamsBufferSpaceLeft % mVaoManager->getConstBufferAlignment() == 0 ); + + size_t bytesToWriteAligned = + alignToNextMultiple( bytesToWrite, mVaoManager->getConstBufferAlignment() ); + if( mCurrentAutoParamsBufferSpaceLeft < bytesToWriteAligned ) { if( mAutoParamsBufferIdx >= mAutoParamsBuffer.size() ) { // Ask for a coherent buffer to avoid excessive flushing. Note: VaoManager may ignore // this request if the GPU can't provide coherent memory and we must flush anyway. - ConstBufferPacked *constBuffer = - mVaoManager->createConstBuffer( std::max( 512u * 1024u, bytesToWrite ), - BT_DYNAMIC_PERSISTENT_COHERENT, 0, false ); + ConstBufferPacked *constBuffer = mVaoManager->createConstBuffer( + std::max( 512u * 1024u, bytesToWriteAligned ), + BT_DYNAMIC_PERSISTENT_COHERENT, 0, false ); mAutoParamsBuffer.push_back( constBuffer ); } @@ -2550,7 +2619,7 @@ namespace Ogre // This should be near-impossible to trigger because most Const Buffers are <= 64kb // and we reserver 512kb per const buffer. A Low Level Material using a Params buffer // with > 64kb is an edge case we don't care handling. - OGRE_ASSERT_LOW( bytesToWrite <= constBuffer->getTotalSizeBytes() ); + OGRE_ASSERT_LOW( bytesToWriteAligned <= constBuffer->getTotalSizeBytes() ); mCurrentAutoParamsBufferPtr = reinterpret_cast( constBuffer->map( 0, constBuffer->getNumElements() ) ); @@ -2571,18 +2640,8 @@ namespace Ogre constBuffer->bindAsParamBuffer( gptype, bindOffset, bytesToWrite ); - mCurrentAutoParamsBufferPtr += bytesToWrite; - - const uint8 *oldBufferPos = mCurrentAutoParamsBufferPtr; - mCurrentAutoParamsBufferPtr = reinterpret_cast( - alignToNextMultiple( reinterpret_cast( mCurrentAutoParamsBufferPtr ), - mVaoManager->getConstBufferAlignment() ) ); - bytesToWrite += (size_t)( mCurrentAutoParamsBufferPtr - oldBufferPos ); - - // We know that bytesToWrite <= mCurrentAutoParamsBufferSpaceLeft, but that was - // before padding. After padding this may no longer hold true. - mCurrentAutoParamsBufferSpaceLeft -= - std::min( mCurrentAutoParamsBufferSpaceLeft, bytesToWrite ); + mCurrentAutoParamsBufferPtr += bytesToWriteAligned; + mCurrentAutoParamsBufferSpaceLeft -= bytesToWriteAligned; } } //------------------------------------------------------------------------- @@ -2684,7 +2743,7 @@ namespace Ogre //------------------------------------------------------------------------- void VulkanRenderSystem::flushCommands() { - mActiveDevice->commitAndNextCommandBuffer( SubmissionType::FlushOnly ); + mDevice->commitAndNextCommandBuffer( SubmissionType::FlushOnly ); } //------------------------------------------------------------------------- void VulkanRenderSystem::beginProfileEvent( const String &eventName ) {} @@ -2698,7 +2757,7 @@ namespace Ogre #if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM if( !CmdBeginDebugUtilsLabelEXT ) return; // VK_EXT_debug_utils not available - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); VkDebugUtilsLabelEXT markerInfo; makeVkStruct( markerInfo, VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT ); markerInfo.pLabelName = event.c_str(); @@ -2711,7 +2770,7 @@ namespace Ogre #if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM if( !CmdEndDebugUtilsLabelEXT ) return; // VK_EXT_debug_utils not available - VkCommandBuffer cmdBuffer = mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer(); CmdEndDebugUtilsLabelEXT( cmdBuffer ); #endif } @@ -2727,7 +2786,7 @@ namespace Ogre void VulkanRenderSystem::endGpuDebuggerFrameCapture( Window *window, const bool bDiscard ) { if( mRenderDocApi && !bDiscard ) - mActiveDevice->commitAndNextCommandBuffer( SubmissionType::FlushOnly ); + mDevice->commitAndNextCommandBuffer( SubmissionType::FlushOnly ); RenderSystem::endGpuDebuggerFrameCapture( window, bDiscard ); } //------------------------------------------------------------------------- @@ -2773,18 +2832,18 @@ namespace Ogre void VulkanRenderSystem::initialiseFromRenderSystemCapabilities( RenderSystemCapabilities *caps, Window *primary ) { - mShaderManager = OGRE_NEW VulkanGpuProgramManager( mActiveDevice ); - mVulkanProgramFactory0 = OGRE_NEW VulkanProgramFactory( mActiveDevice, "glslvk", true ); - mVulkanProgramFactory1 = OGRE_NEW VulkanProgramFactory( mActiveDevice, "glsl", false ); - mVulkanProgramFactory2 = OGRE_NEW VulkanProgramFactory( mActiveDevice, "hlslvk", false ); - mVulkanProgramFactory3 = OGRE_NEW VulkanProgramFactory( mActiveDevice, "hlsl", false ); + mShaderManager = OGRE_NEW VulkanGpuProgramManager( mDevice ); + mVulkanProgramFactory0 = OGRE_NEW VulkanProgramFactory( mDevice, "glslvk", true ); + mVulkanProgramFactory1 = OGRE_NEW VulkanProgramFactory( mDevice, "glsl", false ); + mVulkanProgramFactory2 = OGRE_NEW VulkanProgramFactory( mDevice, "hlslvk", false ); + mVulkanProgramFactory3 = OGRE_NEW VulkanProgramFactory( mDevice, "hlsl", false ); HighLevelGpuProgramManager::getSingleton().addFactory( mVulkanProgramFactory0 ); // HighLevelGpuProgramManager::getSingleton().addFactory( mVulkanProgramFactory1 ); HighLevelGpuProgramManager::getSingleton().addFactory( mVulkanProgramFactory2 ); // HighLevelGpuProgramManager::getSingleton().addFactory( mVulkanProgramFactory3 ); - mCache = OGRE_NEW VulkanCache( mActiveDevice ); + mCache = OGRE_NEW VulkanCache( mDevice ); Log *defaultLog = LogManager::getSingleton().getDefaultLog(); if( defaultLog ) @@ -2810,7 +2869,7 @@ namespace Ogre // If we get a validation layer here; then the error was generated by the // Pass that last called beginRenderPassDescriptor (i.e. not this one) endRenderPassDescriptor( false ); - mActiveDevice->commitAndNextCommandBuffer( SubmissionType::FlushOnly ); + mDevice->commitAndNextCommandBuffer( SubmissionType::FlushOnly ); } const int oldWidth = mCurrentRenderViewport[0].getActualWidth(); @@ -2893,11 +2952,11 @@ namespace Ogre mInterruptedRenderCommandEncoder = false; const bool wasGraphicsOpen = - mActiveDevice->mGraphicsQueue.getEncoderState() != VulkanQueue::EncoderGraphicsOpen; + mDevice->mGraphicsQueue.getEncoderState() != VulkanQueue::EncoderGraphicsOpen; if( mEntriesToFlush ) { - mActiveDevice->mGraphicsQueue.endAllEncoders( false ); + mDevice->mGraphicsQueue.endAllEncoders( false ); VulkanRenderPassDescriptor *newPassDesc = static_cast( mCurrentRenderPassDescriptor ); @@ -2908,14 +2967,14 @@ namespace Ogre // This is a new command buffer / encoder. State needs to be set again if( mEntriesToFlush || !wasGraphicsOpen ) { - mActiveDevice->mGraphicsQueue.getGraphicsEncoder(); + mDevice->mGraphicsQueue.getGraphicsEncoder(); VulkanVaoManager *vaoManager = static_cast( mVaoManager ); - vaoManager->bindDrawIdVertexBuffer( mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer ); + vaoManager->bindDrawIdVertexBuffer( mDevice->mGraphicsQueue.getCurrentCmdBuffer() ); if( mStencilEnabled ) { - vkCmdSetStencilReference( mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdSetStencilReference( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), VK_STENCIL_FACE_FRONT_AND_BACK, mStencilRefValue ); } @@ -2949,7 +3008,8 @@ namespace Ogre #endif } - vkCmdSetViewport( mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer, 0u, numViewports, vkVp ); + vkCmdSetViewport( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), 0u, numViewports, + vkVp ); } if( mVpChanged || numViewports > 1u ) @@ -2972,7 +3032,7 @@ namespace Ogre #endif } - vkCmdSetScissor( mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer, 0u, numViewports, + vkCmdSetScissor( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), 0u, numViewports, scissorRect ); } @@ -3211,7 +3271,7 @@ namespace Ogre return retVal; } //------------------------------------------------------------------------- - void VulkanRenderSystem::endCopyEncoder() { mActiveDevice->mGraphicsQueue.endCopyEncoder(); } + void VulkanRenderSystem::endCopyEncoder() { mDevice->mGraphicsQueue.endCopyEncoder(); } //------------------------------------------------------------------------- void VulkanRenderSystem::executeResourceTransition( const ResourceTransitionArray &rstCollection ) { @@ -3219,7 +3279,7 @@ namespace Ogre return; // Needs to be done now, as it may change layouts of textures we're about to change - mActiveDevice->mGraphicsQueue.endAllEncoders(); + mDevice->mGraphicsQueue.endAllEncoders(); VkPipelineStageFlags srcStage = 0u; VkPipelineStageFlags dstStage = 0u; @@ -3292,20 +3352,28 @@ namespace Ogre if( texture->isMultisample() && !texture->hasMsaaExplicitResolves() ) { // Rare case where we render to an implicit resolve without resolving - // (otherwise newLayout = ResolveDest) - // - // Or more common case if we need to copy to/from an MSAA texture + // (otherwise newLayout = ResolveDest), or more common case if we need + // to copy to/from an MSAA texture. We can also try to sample from texture. + // In all these cases keep MSAA texture in predictable layout. // // This cannot catch all use cases, but if you fall into something this // doesn't catch, then you should probably be using explicit resolves - if( itor->newLayout == ResourceLayout::RenderTarget || - itor->newLayout == ResourceLayout::ResolveDest || - itor->newLayout == ResourceLayout::CopySrc || - itor->newLayout == ResourceLayout::CopyDst ) - { - imageBarrier.image = texture->getMsaaFramebufferName(); - mImageBarriers.push_back( imageBarrier ); - } + bool useNewLayoutForMsaa = + itor->newLayout == ResourceLayout::RenderTarget || + itor->newLayout == ResourceLayout::ResolveDest || + itor->newLayout == ResourceLayout::CopySrc || + itor->newLayout == ResourceLayout::CopyDst; + bool useOldLayoutForMsaa = + itor->oldLayout == ResourceLayout::RenderTarget || + itor->oldLayout == ResourceLayout::ResolveDest || + itor->oldLayout == ResourceLayout::CopySrc || + itor->oldLayout == ResourceLayout::CopyDst; + if( !useNewLayoutForMsaa ) + imageBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + if( !useOldLayoutForMsaa ) + imageBarrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + imageBarrier.image = texture->getMsaaFramebufferName(); + mImageBarriers.push_back( imageBarrier ); } } else @@ -3338,10 +3406,11 @@ namespace Ogre if( dstStage == 0 ) dstStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; - vkCmdPipelineBarrier( - mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer, srcStage & mActiveDevice->mSupportedStages, - dstStage & mActiveDevice->mSupportedStages, 0, numMemBarriers, &memBarrier, 0u, 0, - static_cast( mImageBarriers.size() ), mImageBarriers.begin() ); + vkCmdPipelineBarrier( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), + srcStage & mDevice->mSupportedStages, + dstStage & mDevice->mSupportedStages, 0, numMemBarriers, &memBarrier, + 0u, 0, static_cast( mImageBarriers.size() ), + mImageBarriers.begin() ); mImageBarriers.clear(); } //------------------------------------------------------------------------- @@ -3351,6 +3420,15 @@ namespace Ogre debugLogPso( newPso ); #endif + if( ( newPso->geometryShader && !mDevice->mDeviceFeatures.geometryShader ) || + ( newPso->tesselationHullShader && !mDevice->mDeviceFeatures.tessellationShader ) || + ( newPso->tesselationDomainShader && !mDevice->mDeviceFeatures.tessellationShader ) ) + { + OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, + "Geometry or tesselation shaders are not supported", + "VulkanRenderSystem::_hlmsPipelineStateObjectCreated" ); + } + size_t numShaderStages = 0u; VkPipelineShaderStageCreateInfo shaderStages[NumShaderTypes]; @@ -3476,6 +3554,9 @@ namespace Ogre VkPipelineTessellationStateCreateInfo tessStateCi; makeVkStruct( tessStateCi, VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO ); + tessStateCi.patchControlPoints = 1u; + bool useTesselationState = mDevice->mDeviceFeatures.tessellationShader && + ( newPso->tesselationHullShader || newPso->tesselationDomainShader ); VkPipelineViewportStateCreateInfo viewportStateCi; makeVkStruct( viewportStateCi, VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO ); @@ -3625,7 +3706,7 @@ namespace Ogre pipeline.pStages = shaderStages; pipeline.pVertexInputState = &vertexFormatCi; pipeline.pInputAssemblyState = &inputAssemblyCi; - pipeline.pTessellationState = &tessStateCi; + pipeline.pTessellationState = useTesselationState ? &tessStateCi : nullptr; pipeline.pViewportState = &viewportStateCi; pipeline.pRasterizationState = &rasterState; pipeline.pMultisampleState = &mssCi; @@ -3639,8 +3720,8 @@ namespace Ogre #endif VkPipeline vulkanPso = 0; - VkResult result = vkCreateGraphicsPipelines( - mActiveDevice->mDevice, mActiveDevice->mPipelineCache, 1u, &pipeline, 0, &vulkanPso ); + VkResult result = vkCreateGraphicsPipelines( mDevice->mDevice, mDevice->mPipelineCache, 1u, + &pipeline, 0, &vulkanPso ); checkVkResult( result, "vkCreateGraphicsPipelines" ); #if OGRE_DEBUG_MODE >= OGRE_DEBUG_MEDIUM @@ -3681,7 +3762,7 @@ namespace Ogre OGRE_ASSERT_LOW( pso->rsData ); VulkanHlmsPso *vulkanPso = static_cast( pso->rsData ); - delayed_vkDestroyPipeline( mVaoManager, mActiveDevice->mDevice, vulkanPso->pso, 0 ); + delayed_vkDestroyPipeline( mVaoManager, mDevice->mDevice, vulkanPso->pso, 0 ); delete vulkanPso; pso->rsData = 0; } @@ -3722,12 +3803,12 @@ namespace Ogre samplerDescriptor.magFilter = VulkanMappings::get( newBlock->mMagFilter ); samplerDescriptor.mipmapMode = VulkanMappings::getMipFilter( newBlock->mMipFilter ); samplerDescriptor.mipLodBias = newBlock->mMipLodBias; - float maxAllowedAnisotropy = mActiveDevice->mDeviceProperties.limits.maxSamplerAnisotropy; + float maxAllowedAnisotropy = mDevice->mDeviceProperties.limits.maxSamplerAnisotropy; samplerDescriptor.maxAnisotropy = newBlock->mMaxAnisotropy > maxAllowedAnisotropy ? maxAllowedAnisotropy : newBlock->mMaxAnisotropy; samplerDescriptor.anisotropyEnable = - ( mActiveDevice->mDeviceFeatures.samplerAnisotropy == VK_TRUE ) && + ( mDevice->mDeviceFeatures.samplerAnisotropy == VK_TRUE ) && ( samplerDescriptor.maxAnisotropy > 1.0f ? VK_TRUE : VK_FALSE ); samplerDescriptor.addressModeU = VulkanMappings::get( newBlock->mU ); samplerDescriptor.addressModeV = VulkanMappings::get( newBlock->mV ); @@ -3743,8 +3824,7 @@ namespace Ogre } VkSampler textureSampler; - VkResult result = - vkCreateSampler( mActiveDevice->mDevice, &samplerDescriptor, 0, &textureSampler ); + VkResult result = vkCreateSampler( mDevice->mDevice, &samplerDescriptor, 0, &textureSampler ); checkVkResult( result, "vkCreateSampler" ); #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 @@ -3763,7 +3843,7 @@ namespace Ogre VkSampler textureSampler = *static_cast( block->mRsData ); delete(uint64 *)block->mRsData; #endif - delayed_vkDestroySampler( mVaoManager, mActiveDevice->mDevice, textureSampler, 0 ); + delayed_vkDestroySampler( mVaoManager, mDevice->mDevice, textureSampler, 0 ); } //------------------------------------------------------------------------- void VulkanRenderSystem::_descriptorSetTextureCreated( DescriptorSetTexture *newSet ) @@ -3792,7 +3872,7 @@ namespace Ogre OGRE_ASSERT_LOW( set->mRsData ); VulkanDescriptorSetTexture2 *vulkanSet = static_cast( set->mRsData ); - vulkanSet->destroy( mVaoManager, mActiveDevice->mDevice, *set ); + vulkanSet->destroy( mVaoManager, mDevice->mDevice, *set ); delete vulkanSet; set->mRsData = 0; } @@ -3848,9 +3928,9 @@ namespace Ogre { mStencilRefValue = refValue; - if( mActiveDevice->mGraphicsQueue.getEncoderState() == VulkanQueue::EncoderGraphicsOpen ) + if( mDevice->mGraphicsQueue.getEncoderState() == VulkanQueue::EncoderGraphicsOpen ) { - vkCmdSetStencilReference( mActiveDevice->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdSetStencilReference( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), VK_STENCIL_FACE_FRONT_AND_BACK, mStencilRefValue ); } } @@ -3859,8 +3939,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 ) { @@ -3880,91 +3959,59 @@ 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; - - 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; + VkSampleCountFlags supportedSampleCounts = ( VK_SAMPLE_COUNT_64_BIT << 1 ) - 1; - 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 ) ) + else if( textureFlags & TextureFlags::Uav ) { - // TODO: Query Vulkan 1.2 / extensions to get framebufferIntegerColorSampleCounts. - // supportedSampleCounts = deviceLimits.framebufferIntegerColorSampleCounts; - supportedSampleCounts = VK_SAMPLE_COUNT_1_BIT; + supportedSampleCounts &= deviceLimits.storageImageSampleCounts; } else { - if( textureFlags & TextureFlags::Uav ) - supportedSampleCounts = deviceLimits.storageImageSampleCounts; - else if( textureFlags & TextureFlags::NotTexture ) - supportedSampleCounts = deviceLimits.framebufferColorSampleCounts; - else - supportedSampleCounts = deviceLimits.sampledImageColorSampleCounts; + const bool isDepth = PixelFormatGpuUtils::isDepth( format ); + const bool isStencil = PixelFormatGpuUtils::isStencil( format ); + const 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( PixelFormatGpuUtils::isStencil( format ) ) + if( isStencil || ( textureFlags & TextureFlags::RenderWindowSpecific ) ) + supportedSampleCounts &= deviceLimits.framebufferStencilSampleCounts; + if( isInteger ) { - // 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; + // TODO: Query Vulkan 1.2 / extensions to get + // framebufferIntegerColorSampleCounts. + supportedSampleCounts &= VK_SAMPLE_COUNT_1_BIT; } } + + 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; + } } uint8 samples = sampleDesc.getColourSamples(); diff --git a/RenderSystems/Vulkan/src/OgreVulkanRootLayout.cpp b/RenderSystems/Vulkan/src/OgreVulkanRootLayout.cpp index bb68f345d95..162eb433bc7 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanRootLayout.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanRootLayout.cpp @@ -611,7 +611,7 @@ namespace Ogre if( firstDirtySet < mSets.size() ) { vkCmdBindDescriptorSets( - device->mGraphicsQueue.mCurrentCmdBuffer, + device->mGraphicsQueue.getCurrentCmdBuffer(), mCompute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS, mRootLayout, firstDirtySet, static_cast( mSets.size() ) - firstDirtySet, &descSets[firstDirtySet], 0u, 0 ); diff --git a/RenderSystems/Vulkan/src/OgreVulkanStagingTexture.cpp b/RenderSystems/Vulkan/src/OgreVulkanStagingTexture.cpp index f3050b87630..134e7ed3219 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanStagingTexture.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanStagingTexture.cpp @@ -183,7 +183,7 @@ namespace Ogre region.imageExtent.height = srcBox.height; region.imageExtent.depth = srcBox.depth; - vkCmdCopyBufferToImage( device->mGraphicsQueue.mCurrentCmdBuffer, mVboName, + vkCmdCopyBufferToImage( device->mGraphicsQueue.getCurrentCmdBuffer(), mVboName, dstTextureVulkan->getFinalTextureName(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ®ion ); } diff --git a/RenderSystems/Vulkan/src/OgreVulkanSupport.cpp b/RenderSystems/Vulkan/src/OgreVulkanSupport.cpp index 166c43c1839..461ad0d6577 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanSupport.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanSupport.cpp @@ -34,60 +34,10 @@ Copyright (c) 2000-present Torus Knot Software Ltd namespace Ogre { - void VulkanSupport::enumerateDevices( VulkanRenderSystem *renderSystem ) - { - mDevices.clear(); - - VkInstance instance = renderSystem->getVkInstance(); - - VkResult result = VK_SUCCESS; - - uint32 numDevices = 0u; - result = vkEnumeratePhysicalDevices( instance, &numDevices, NULL ); - checkVkResult( result, "vkEnumeratePhysicalDevices" ); - - if( numDevices == 0u ) - { - OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR, "No Vulkan devices found.", - "VulkanSupport::enumerateDevices" ); - return; - } - - char tmpBuffer[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE + 32]; - LwString logStr( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); - - logStr.clear(); - logStr.a( "[Vulkan] Found ", numDevices, " devices" ); - LogManager::getSingleton().logMessage( logStr.c_str() ); - - FastArray pd; - pd.resize( numDevices ); - result = vkEnumeratePhysicalDevices( instance, &numDevices, pd.begin() ); - checkVkResult( result, "vkEnumeratePhysicalDevices" ); - - LogManager::getSingleton().logMessage( "[Vulkan] Found devices:" ); - - mDevices.reserve( numDevices ); - for( uint32 i = 0u; i < numDevices; ++i ) - { - VkPhysicalDeviceProperties deviceProps; - vkGetPhysicalDeviceProperties( pd[i], &deviceProps ); - - logStr.clear(); - logStr.a( deviceProps.deviceName, " #", i ); - mDevices.push_back( logStr.c_str() ); - - LogManager::getSingleton().logMessage( logStr.c_str() ); - } - } - //------------------------------------------------------------------------- void VulkanSupport::initialize( VulkanRenderSystem *renderSystem ) { if( !renderSystem->getVkInstance() ) renderSystem->initializeVkInstance(); - - if( mDevices.empty() ) - enumerateDevices( renderSystem ); } //------------------------------------------------------------------------- void VulkanSupport::setSupported() { mSupported = true; } @@ -102,16 +52,11 @@ namespace Ogre ConfigOption optSRGB; optDevices.name = "Device"; - - FastArray::const_iterator itor = mDevices.begin(); - FastArray::const_iterator endt = mDevices.end(); - optDevices.possibleValues.push_back( "(default)" ); - - while( itor != endt ) - optDevices.possibleValues.push_back( *itor++ ); - - optDevices.currentValue = mDevices.front(); + const auto &devices = renderSystem->getVulkanPhysicalDevices(); + for( auto &device : devices ) + optDevices.possibleValues.push_back( device.title ); + optDevices.currentValue = optDevices.possibleValues.front(); optDevices.immutable = false; optInterfaces.name = "Interface"; @@ -186,8 +131,8 @@ namespace Ogre if( it != mOptions.end() ) { const String deviceName = it->second.currentValue; - if( deviceName != "(default)" && - std::find( mDevices.begin(), mDevices.end(), deviceName ) == mDevices.end() ) + if( std::find( it->second.possibleValues.begin(), it->second.possibleValues.end(), + deviceName ) == it->second.possibleValues.end() ) { setConfigOption( "Device", "(default)" ); return "Requested rendering device could not be found, default will be used instead."; @@ -197,21 +142,13 @@ namespace Ogre return BLANKSTRING; } //------------------------------------------------------------------------- - uint32 VulkanSupport::getSelectedDeviceIdx() const + String VulkanSupport::getSelectedDeviceName() const { - uint32 deviceIdx = 0u; - ConfigOptionMap::const_iterator it = mOptions.find( "Device" ); if( it != mOptions.end() ) - { - const String deviceName = it->second.currentValue; - FastArray::const_iterator itDevice = - std::find( mDevices.begin(), mDevices.end(), deviceName ); - if( itDevice != mDevices.end() ) - deviceIdx = uint32( itDevice - mDevices.begin() ); - } + return it->second.currentValue; - return deviceIdx; + return "(default)"; } //------------------------------------------------------------------------- ConfigOptionMap &VulkanSupport::getConfigOptions( VulkanRenderSystem *renderSystem ) diff --git a/RenderSystems/Vulkan/src/OgreVulkanTextureGpu.cpp b/RenderSystems/Vulkan/src/OgreVulkanTextureGpu.cpp index de0d8a2e84f..cc4626c7bbb 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanTextureGpu.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanTextureGpu.cpp @@ -185,7 +185,7 @@ namespace Ogre imageBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; vkCmdPipelineBarrier( - device->mGraphicsQueue.mCurrentCmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + device->mGraphicsQueue.getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0u, 0, 0u, 0, 1u, &imageBarrier ); mCurrLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; @@ -223,7 +223,7 @@ namespace Ogre imageBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageBarrier.newLayout = mCurrLayout; vkCmdPipelineBarrier( - device->mGraphicsQueue.mCurrentCmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, + device->mGraphicsQueue.getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0u, 0, 0u, 0, 1u, &imageBarrier ); } } @@ -525,7 +525,7 @@ namespace Ogre if( dstTexture->isMultisample() && !dstTexture->hasMsaaExplicitResolves() ) dstTextureName = dstTexture->mMsaaFramebufferName; - vkCmdCopyImage( device->mGraphicsQueue.mCurrentCmdBuffer, srcTextureName, mCurrLayout, + vkCmdCopyImage( device->mGraphicsQueue.getCurrentCmdBuffer(), srcTextureName, mCurrLayout, dstTextureName, dstTexture->mCurrLayout, 1u, ®ion ); if( dstTexture->isMultisample() && !dstTexture->hasMsaaExplicitResolves() && @@ -542,7 +542,7 @@ namespace Ogre resolve.extent.height = getInternalHeight(); resolve.extent.depth = getDepth(); - vkCmdResolveImage( device->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdResolveImage( device->mGraphicsQueue.getCurrentCmdBuffer(), dstTexture->mMsaaFramebufferName, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dstTexture->mFinalTextureName, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &resolve ); @@ -602,7 +602,7 @@ namespace Ogre imageBarrier[1].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; imageBarrier[1].srcAccessMask = 0; imageBarrier[1].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - vkCmdPipelineBarrier( device->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdPipelineBarrier( device->mGraphicsQueue.getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0u, 0, 0u, 0, 1u, &imageBarrier[1] ); } @@ -641,7 +641,7 @@ namespace Ogre region.dstOffsets[1].y = static_cast( std::max( internalHeight >> i, 1u ) ); region.dstOffsets[1].z = static_cast( std::max( getDepth() >> i, 1u ) ); - vkCmdBlitImage( device->mGraphicsQueue.mCurrentCmdBuffer, mFinalTextureName, mCurrLayout, + vkCmdBlitImage( device->mGraphicsQueue.getCurrentCmdBuffer(), mFinalTextureName, mCurrLayout, mFinalTextureName, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ®ion, VK_FILTER_LINEAR ); @@ -656,7 +656,7 @@ namespace Ogre // Wait for vkCmdBlitImage on mip i to finish before advancing to mip i+1 // Also transition src mip 'i' to TRANSFER_SRC_OPTIMAL // Also transition src mip 'i+1' to TRANSFER_DST_OPTIMAL - vkCmdPipelineBarrier( device->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdPipelineBarrier( device->mGraphicsQueue.getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0u, 0, 0u, 0, numBarriers, imageBarrier ); } @@ -818,7 +818,7 @@ namespace Ogre #if OGRE_DEBUG_MODE >= OGRE_DEBUG_HIGH const String textureName = getNameStr() + "(View)"; - setObjectName( device->mDevice, (uint64_t)imageView, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, + setObjectName( device->mDevice, (uint64_t)imageView, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, textureName.c_str() ); #endif @@ -1008,7 +1008,7 @@ namespace Ogre imageBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageBarrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; imageBarrier.image = mMsaaFramebufferName; - vkCmdPipelineBarrier( device->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdPipelineBarrier( device->mGraphicsQueue.getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, PixelFormatGpuUtils::isDepth( finalPixelFormat ) ? ( VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | diff --git a/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp b/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp index 8ca4f4acafd..58180a5b99d 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanTextureGpuManager.cpp @@ -190,7 +190,7 @@ namespace Ogre ++barrierCount; } - vkCmdPipelineBarrier( device->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdPipelineBarrier( device->mGraphicsQueue.getCurrentCmdBuffer(), VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0u, 0, 0u, 0, static_cast( barrierCount ), imageMemBarrier ); @@ -229,7 +229,7 @@ namespace Ogre else region.imageExtent.height = 4u; - vkCmdCopyBufferToImage( device->mGraphicsQueue.mCurrentCmdBuffer, stagingBuffVboName, + vkCmdCopyBufferToImage( device->mGraphicsQueue.getCurrentCmdBuffer(), stagingBuffVboName, mBlankTexture[i].vkImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ®ion ); } @@ -250,9 +250,9 @@ namespace Ogre ++barrierCount; } - vkCmdPipelineBarrier( device->mGraphicsQueue.mCurrentCmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, - VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, 0, 0u, 0, 0u, 0, - static_cast( barrierCount ), imageMemBarrier ); + vkCmdPipelineBarrier( device->mGraphicsQueue.getCurrentCmdBuffer(), + VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, 0, 0u, + 0, 0u, 0, static_cast( barrierCount ), imageMemBarrier ); mBlankTexture[TextureTypes::Unknown] = mBlankTexture[TextureTypes::Type2D]; if( c_bSkipAliasable ) diff --git a/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp b/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp index 6a434faa2cb..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 ) { @@ -296,15 +298,6 @@ namespace Ogre Math::Clamp( getHeight(), surfaceCaps.minImageExtent.height, surfaceCaps.maxImageExtent.height ) ); - // We need to retransition the main texture now to create MSAA surfaces (if any). - // We need to do it now, because doing it later will overwrite the VkImage handles with NULL. - // - // mTexture is supposed to always be at Resident once it transitions there, - // so maintain that guarantee. - if( mTexture->getResidencyStatus() != GpuResidency::OnStorage ) - mTexture->_transitionTo( GpuResidency::OnStorage, (uint8 *)0 ); - mTexture->_transitionTo( GpuResidency::Resident, (uint8 *)0 ); - VkBool32 supported; result = vkGetPhysicalDeviceSurfaceSupportKHR( mDevice->mPhysicalDevice, mDevice->mGraphicsQueue.mFamilyIdx, mSurfaceKHR, &supported ); @@ -496,6 +489,12 @@ namespace Ogre mSwapchainImages.begin() ); checkVkResult( result, "vkGetSwapchainImagesKHR" ); + // We need to retransition the main texture now to re-create MSAA surfaces (if any). + // We need to do it now, because doing it later will overwrite the VkImage handles with NULL. + if( mTexture->getResidencyStatus() != GpuResidency::OnStorage ) + mTexture->_transitionTo( GpuResidency::OnStorage, (uint8 *)0 ); + mTexture->_transitionTo( GpuResidency::Resident, (uint8 *)0 ); + acquireNextSwapchain(); if( mDepthBuffer ) @@ -532,7 +531,7 @@ namespace Ogre VulkanVaoManager *vaoManager = mDevice->mVaoManager; - mSwapchainSemaphore = vaoManager->getAvailableSempaphore(); + mSwapchainSemaphore = vaoManager->getAvailableSemaphore(); uint32 swapchainIdx = 0u; VkResult result = vkAcquireNextImageKHR( mDevice->mDevice, mSwapchain, UINT64_MAX, diff --git a/RenderSystems/Vulkan/src/Vao/OgreVulkanBufferInterface.cpp b/RenderSystems/Vulkan/src/Vao/OgreVulkanBufferInterface.cpp index 21f0a82198c..a223a7725eb 100644 --- a/RenderSystems/Vulkan/src/Vao/OgreVulkanBufferInterface.cpp +++ b/RenderSystems/Vulkan/src/Vao/OgreVulkanBufferInterface.cpp @@ -203,7 +203,7 @@ namespace Ogre region.srcOffset = srcOffsetBytes; region.dstOffset = dstOffsetBytes; region.size = sizeBytes; - vkCmdCopyBuffer( device->mGraphicsQueue.mCurrentCmdBuffer, mVboName, dstBufferVk->getVboName(), - 1u, ®ion ); + vkCmdCopyBuffer( device->mGraphicsQueue.getCurrentCmdBuffer(), mVboName, + dstBufferVk->getVboName(), 1u, ®ion ); } } // namespace Ogre diff --git a/RenderSystems/Vulkan/src/Vao/OgreVulkanStagingBuffer.cpp b/RenderSystems/Vulkan/src/Vao/OgreVulkanStagingBuffer.cpp index a6b9d4ff2c3..84c058ec14e 100644 --- a/RenderSystems/Vulkan/src/Vao/OgreVulkanStagingBuffer.cpp +++ b/RenderSystems/Vulkan/src/Vao/OgreVulkanStagingBuffer.cpp @@ -221,7 +221,7 @@ namespace Ogre VulkanVaoManager *vaoManager = static_cast( mVaoManager ); VulkanDevice *device = vaoManager->getDevice(); - VkCommandBuffer cmdBuffer = device->mGraphicsQueue.mCurrentCmdBuffer; + VkCommandBuffer cmdBuffer = device->mGraphicsQueue.getCurrentCmdBuffer(); OGRE_ASSERT_MEDIUM( mUnmapTicket != std::numeric_limits::max() && "VulkanStagingBuffer already unmapped!" ); @@ -313,7 +313,7 @@ namespace Ogre OGRE_ASSERT_HIGH( !Workarounds::mPowerVRAlignment || ( region.dstOffset % Workarounds::mPowerVRAlignment ) == 0u ); #endif - vkCmdCopyBuffer( device->mGraphicsQueue.mCurrentCmdBuffer, bufferInterface->getVboName(), + vkCmdCopyBuffer( device->mGraphicsQueue.getCurrentCmdBuffer(), bufferInterface->getVboName(), mVboName, 1u, ®ion ); return freeRegionOffset; @@ -354,7 +354,7 @@ namespace Ogre OGRE_ASSERT_HIGH( !Workarounds::mPowerVRAlignment || ( region.dstOffset % Workarounds::mPowerVRAlignment ) == 0u ); #endif - vkCmdCopyBuffer( device->mGraphicsQueue.mCurrentCmdBuffer, mVboName, dstBuffer, 1u, ®ion ); + vkCmdCopyBuffer( device->mGraphicsQueue.getCurrentCmdBuffer(), mVboName, dstBuffer, 1u, ®ion ); if( mUploadOnly ) { @@ -417,7 +417,7 @@ namespace Ogre OGRE_ASSERT_HIGH( !Workarounds::mPowerVRAlignment || ( region.dstOffset % Workarounds::mPowerVRAlignment ) == 0u ); #endif - vkCmdCopyBuffer( device->mGraphicsQueue.mCurrentCmdBuffer, srcBuffer, mVboName, 1u, ®ion ); + vkCmdCopyBuffer( device->mGraphicsQueue.getCurrentCmdBuffer(), srcBuffer, mVboName, 1u, ®ion ); return freeRegionOffset + extraOffset; } diff --git a/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp b/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp index 5ed4ba5644e..8a1e81e03f2 100644 --- a/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp +++ b/RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp @@ -497,7 +497,7 @@ namespace Ogre char tmpBuffer[256]; LwString text( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) ); - text.a( "[Vulkan] Flushing all mDelayedBlocks(", bytesToMegabytes( mDelayedBlocksSize ), + text.a( "Vulkan: Flushing all mDelayedBlocks(", bytesToMegabytes( mDelayedBlocksSize ), " MB) because mDelayedBlocksFlushThreshold(", bytesToMegabytes( mDelayedBlocksFlushThreshold ), " MB) was exceeded. This prevents async operations (e.g. async compute)", @@ -525,7 +525,7 @@ namespace Ogre VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT /*| VK_ACCESS_HOST_READ_BIT | VK_ACCESS_HOST_WRITE_BIT*/; - vkCmdPipelineBarrier( mDevice->mGraphicsQueue.mCurrentCmdBuffer, + vkCmdPipelineBarrier( mDevice->mGraphicsQueue.getCurrentCmdBuffer(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 1u, &memBarrier, 0u, 0, 0u, 0 ); } @@ -705,6 +705,11 @@ namespace Ogre const VkPhysicalDeviceMemoryProperties &memProperties, const uint32 memoryTypeIdx ) { + // Skip zero size heaps, as in https://vulkan.gpuinfo.org/displayreport.php?id=34174#memory + // on Vulkan Compatibility Pack for Arm64 Windows over Parallels Display Adapter (WDDM) + if( memProperties.memoryHeaps[memProperties.memoryTypes[memoryTypeIdx].heapIndex].size == 0 ) + return; + FastArray::iterator itor = mBestVkMemoryTypeIndex[vboFlag].begin(); FastArray::iterator endt = mBestVkMemoryTypeIndex[vboFlag].end(); @@ -769,9 +774,9 @@ namespace Ogre VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT ); LogManager &logManager = LogManager::getSingleton(); - logManager.logMessage( "Supported memory types for general buffer usage: " + + logManager.logMessage( "Vulkan: Supported memory types for general buffer usage: " + StringConverter::toString( supportedMemoryTypesBuffer ) ); - logManager.logMessage( "Supported memory types for reading: " + + logManager.logMessage( "Vulkan: Supported memory types for reading: " + StringConverter::toString( supportedMemoryTypesRead ) ); const VkPhysicalDeviceMemoryProperties &memProperties = mDevice->mDeviceMemoryProperties; @@ -817,7 +822,7 @@ namespace Ogre { // This is BS. No heap is device-local. Sigh, just pick any and try to get the best score logManager.logMessage( - "VkDevice: No heap found with DEVICE_LOCAL bit set. This should be impossible", + "Vulkan: No heap found with DEVICE_LOCAL bit set. This should be impossible", LML_CRITICAL ); for( uint32 i = 0u; i < numMemoryTypes; ++i ) addMemoryType( CPU_INACCESSIBLE, memProperties, i ); @@ -863,17 +868,17 @@ namespace Ogre } } - logManager.logMessage( "VkDevice will use coherent memory buffers: " + + logManager.logMessage( "Vulkan: VkDevice will use coherent memory buffers: " + StringConverter::toString( mSupportsCoherentMemory ) ); - logManager.logMessage( "VkDevice will use non-coherent memory buffers: " + + logManager.logMessage( "Vulkan: VkDevice will use non-coherent memory buffers: " + StringConverter::toString( mSupportsNonCoherentMemory ) ); - logManager.logMessage( "VkDevice will prefer coherent memory buffers: " + + logManager.logMessage( "Vulkan: VkDevice will prefer coherent memory buffers: " + StringConverter::toString( mPreferCoherentMemory ) ); if( mBestVkMemoryTypeIndex[CPU_READ_WRITE].empty() ) { logManager.logMessage( - "VkDevice: could not find cached host-visible memory. GPU -> CPU transfers could be " + "Vulkan: could not find cached host-visible memory. GPU -> CPU transfers could be " "slow", LML_CRITICAL ); @@ -904,7 +909,7 @@ namespace Ogre if( mDevice->mDeviceProperties.limits.bufferImageGranularity != 1u ) mBestVkMemoryTypeIndex[TEXTURES_OPTIMAL] = mBestVkMemoryTypeIndex[CPU_INACCESSIBLE]; - logManager.logMessage( "VkDevice will use coherent memory for reading: " + + logManager.logMessage( "Vulkan: VkDevice will use coherent memory for reading: " + StringConverter::toString( mReadMemoryIsCoherent ) ); // Fill mMemoryTypesInUse @@ -922,7 +927,7 @@ namespace Ogre } } - logManager.logMessage( "VkDevice read memory is coherent: " + + logManager.logMessage( "Vulkan: VkDevice read memory is coherent: " + StringConverter::toString( mReadMemoryIsCoherent ) ); } //----------------------------------------------------------------------------------- @@ -2140,7 +2145,7 @@ namespace Ogre ++mFrameCount; } //----------------------------------------------------------------------------------- - void VulkanVaoManager::getAvailableSempaphores( VkSemaphoreArray &semaphoreArray, + void VulkanVaoManager::getAvailableSemaphores( VkSemaphoreArray &semaphoreArray, size_t numSemaphores ) { semaphoreArray.reserve( semaphoreArray.size() + numSemaphores ); @@ -2171,7 +2176,7 @@ namespace Ogre } } //----------------------------------------------------------------------------------- - VkSemaphore VulkanVaoManager::getAvailableSempaphore() + VkSemaphore VulkanVaoManager::getAvailableSemaphore() { VkSemaphore retVal; if( mAvailableSemaphores.empty() ) diff --git a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp index bc1b6032ec2..ca16434deca 100644 --- a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp +++ b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp @@ -241,6 +241,11 @@ namespace Ogre if( mClosed || !mNativeWindow ) return; + const uint32 newWidth = static_cast( ANativeWindow_getWidth( mNativeWindow ) ); + const uint32 newHeight = static_cast( ANativeWindow_getHeight( mNativeWindow ) ); + if( newWidth == getWidth() && newHeight == getHeight() && !mRebuildingSwapchain ) + return; + mDevice->stall(); #ifdef OGRE_VULKAN_USE_SWAPPY @@ -285,9 +290,6 @@ namespace Ogre mStencilBuffer->_transitionTo( GpuResidency::OnStorage, (uint8 *)0 ); } - const uint32 newWidth = static_cast( ANativeWindow_getWidth( mNativeWindow ) ); - const uint32 newHeight = static_cast( ANativeWindow_getHeight( mNativeWindow ) ); - setFinalResolution( newWidth, newHeight ); createSwapchain(); @@ -418,10 +420,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..7400a37722f 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 ) { @@ -515,6 +517,14 @@ namespace Ogre mTop = geom->y; } + auto newWidth = geom->width; + auto newHeight = geom->height; + + free( geom ); + + if( newWidth == getWidth() && newHeight == getHeight() && !mRebuildingSwapchain ) + return; + mDevice->stall(); destroySwapchain(); @@ -525,11 +535,9 @@ namespace Ogre if( mStencilBuffer && mStencilBuffer != mDepthBuffer ) mStencilBuffer->_transitionTo( GpuResidency::OnStorage, (uint8 *)0 ); - setFinalResolution( geom->width, geom->height ); + setFinalResolution( newWidth, newHeight ); createSwapchain(); - - free( geom ); } //------------------------------------------------------------------------- void VulkanXcbWindow::_setVisible( bool visible ) { mVisible = visible; } diff --git a/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp b/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp index 5f24bfd996f..351d0009d64 100644 --- a/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp +++ b/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp @@ -369,7 +369,7 @@ namespace Ogre # ifdef OGRE_STATIC_LIB hInstance = GetModuleHandle( NULL ); # else -# if OGRE_DEBUG_MODE == 1 +# if OGRE_DEBUG_MODE hInstance = GetModuleHandle( "RenderSystem_Vulkan_d.dll" ); # else hInstance = GetModuleHandle( "RenderSystem_Vulkan.dll" ); @@ -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 ); @@ -727,6 +727,9 @@ namespace Ogre updateWindowRect(); + if( mRequestedWidth == getWidth() && mRequestedHeight == getHeight() && !mRebuildingSwapchain ) + return; + mDevice->stall(); destroySwapchain(); diff --git a/Samples/2.0/CMakeLists.txt b/Samples/2.0/CMakeLists.txt index 7402d56f724..d5c2a4f4037 100644 --- a/Samples/2.0/CMakeLists.txt +++ b/Samples/2.0/CMakeLists.txt @@ -206,7 +206,7 @@ if( OGRE_BUILD_SAMPLES2 AND NOT OGRE_BUILD_SAMPLES2_SKIP ) add_subdirectory(Tutorials/Tutorial_Hlms02_CustomizationPerObj) add_subdirectory(Tutorials/Tutorial_Hlms03_AlwaysOnTopA) add_subdirectory(Tutorials/Tutorial_Hlms04_AlwaysOnTopB) - add_subdirectory(Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData) + add_subdirectory(Tutorials/Tutorial_Hlms05_CustomizationPerObjData) if( OGRE_BUILD_COMPONENT_SCENE_FORMAT ) add_subdirectory(Tutorials/Tutorial_Memory) endif() diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.h b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.h deleted file mode 100644 index c57437d4414..00000000000 --- a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.h +++ /dev/null @@ -1,23 +0,0 @@ - -#ifndef Demo_Hlms05CustomizationPerObjArbitraryDataGameState_H -#define Demo_Hlms05CustomizationPerObjArbitraryDataGameState_H - -#include "OgrePrerequisites.h" -#include "TutorialGameState.h" - -namespace Demo -{ - class Hlms05CustomizationPerObjArbitraryDataGameState : public TutorialGameState - { - std::vector mChangingItems; - - public: - Hlms05CustomizationPerObjArbitraryDataGameState( const Ogre::String &helpDescription ); - - void createScene01() override; - - void update( float timeSinceLast ) override; - }; -} // namespace Demo - -#endif diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/CMakeLists.txt b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/CMakeLists.txt similarity index 64% rename from Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/CMakeLists.txt rename to Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/CMakeLists.txt index 2f2d18aa8e4..ccfaf35d221 100644 --- a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/CMakeLists.txt +++ b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/CMakeLists.txt @@ -18,8 +18,8 @@ ogre_add_component_include_dir(Hlms/Pbs) add_recursive( ./ SOURCE_FILES ) -ogre_add_executable(Tutorial_Hlms05_CustomizationPerObjArbitraryData WIN32 MACOSX_BUNDLE ${SOURCE_FILES} ${SAMPLE_COMMON_RESOURCES}) +ogre_add_executable(Tutorial_Hlms05_CustomizationPerObjData WIN32 MACOSX_BUNDLE ${SOURCE_FILES} ${SAMPLE_COMMON_RESOURCES}) -target_link_libraries(Tutorial_Hlms05_CustomizationPerObjArbitraryData ${OGRE_LIBRARIES} ${OGRE_SAMPLES_LIBRARIES}) -ogre_config_sample_lib(Tutorial_Hlms05_CustomizationPerObjArbitraryData) -ogre_config_sample_pkg(Tutorial_Hlms05_CustomizationPerObjArbitraryData) +target_link_libraries(Tutorial_Hlms05_CustomizationPerObjData ${OGRE_LIBRARIES} ${OGRE_SAMPLES_LIBRARIES}) +ogre_config_sample_lib(Tutorial_Hlms05_CustomizationPerObjData) +ogre_config_sample_pkg(Tutorial_Hlms05_CustomizationPerObjData) diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryData.cpp b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjData.cpp similarity index 85% rename from Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryData.cpp rename to Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjData.cpp index 8225efe6cb7..9ca830a8f85 100644 --- a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryData.cpp +++ b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjData.cpp @@ -1,7 +1,7 @@ -#include "Tutorial_Hlms05_CustomizationPerObjArbitraryData.h" +#include "Tutorial_Hlms05_CustomizationPerObjData.h" -#include "Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.h" +#include "Tutorial_Hlms05_CustomizationPerObjDataGameState.h" // Declares WinMain / main #include "MainEntryPointHelper.h" @@ -25,9 +25,9 @@ namespace Demo GraphicsSystem **outGraphicsSystem, GameState **outLogicGameState, LogicSystem **outLogicSystem ) { - Hlms05CustomizationPerObjArbitraryDataGameState *gfxGameState = - new Hlms05CustomizationPerObjArbitraryDataGameState( - "Tutorial_Hlms02_CustomizationPerObj showed how to show send a custom colour.\n" + Hlms05CustomizationPerObjDataGameState *gfxGameState = + new Hlms05CustomizationPerObjDataGameState( + "Tutorial_Hlms05_CustomizationPerObjData showed how to show send a custom colour.\n" "However such sample forces all customized objects to share the same colour\n" "(or at most, a limited number of multiple colours).\n" "\n" @@ -53,10 +53,9 @@ namespace Demo "\n" "\n" "This sample depends on the media files:\n" - " * Samples/Media/2.0/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData\n" ); + " * Samples/Media/2.0/materials/Tutorial_Hlms05_CustomizationPerObjData\n" ); - GraphicsSystem *graphicsSystem = - new Hlms05CustomizationPerObjArbitraryDataGraphicsSystem( gfxGameState ); + GraphicsSystem *graphicsSystem = new Hlms05CustomizationPerObjDataGraphicsSystem( gfxGameState ); gfxGameState->_notifyGraphicsSystem( graphicsSystem ); diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryData.h b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjData.h similarity index 91% rename from Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryData.h rename to Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjData.h index 21d5ef63cc2..b249332b20a 100644 --- a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryData.h +++ b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjData.h @@ -1,6 +1,6 @@ -#ifndef Demo_Tutorial_Hlms05_CustomizationPerObjArbitraryData_H -#define Demo_Tutorial_Hlms05_CustomizationPerObjArbitraryData_H +#ifndef Demo_Tutorial_Hlms05_CustomizationPerObjData_H +#define Demo_Tutorial_Hlms05_CustomizationPerObjData_H #include "GraphicsSystem.h" @@ -20,7 +20,7 @@ namespace Demo { - class Hlms05CustomizationPerObjArbitraryDataGraphicsSystem final : public GraphicsSystem + class Hlms05CustomizationPerObjDataGraphicsSystem final : public GraphicsSystem { Ogre::CompositorWorkspace *setupCompositor() override { @@ -110,8 +110,7 @@ namespace Demo // The order in which we push to archivePbsLibraryFolders DOES matter // since script order parsing matters. Ogre::Archive *archiveLibrary = archiveManager.load( - rootHlmsFolder + - "2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData", + rootHlmsFolder + "2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjData", archiveType, true ); archivePbsLibraryFolders.push_back( archiveLibrary ); } @@ -137,8 +136,7 @@ namespace Demo } public: - Hlms05CustomizationPerObjArbitraryDataGraphicsSystem( GameState *gameState ) : - GraphicsSystem( gameState ) + Hlms05CustomizationPerObjDataGraphicsSystem( GameState *gameState ) : GraphicsSystem( gameState ) { } }; diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.cpp b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjDataGameState.cpp similarity index 94% rename from Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.cpp rename to Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjDataGameState.cpp index 558661835b1..37776536997 100644 --- a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.cpp +++ b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjDataGameState.cpp @@ -1,7 +1,7 @@ -#include "Tutorial_Hlms05_CustomizationPerObjArbitraryDataGameState.h" +#include "Tutorial_Hlms05_CustomizationPerObjDataGameState.h" -#include "Tutorial_Hlms05_CustomizationPerObjArbitraryData.h" +#include "Tutorial_Hlms05_CustomizationPerObjData.h" #include "Tutorial_Hlms05_MyHlmsPbs.h" #include "CameraController.h" @@ -23,13 +23,13 @@ using namespace Demo; -Hlms05CustomizationPerObjArbitraryDataGameState::Hlms05CustomizationPerObjArbitraryDataGameState( +Hlms05CustomizationPerObjDataGameState::Hlms05CustomizationPerObjDataGameState( const Ogre::String &helpDescription ) : TutorialGameState( helpDescription ) { } //----------------------------------------------------------------------------- -void Hlms05CustomizationPerObjArbitraryDataGameState::createScene01() +void Hlms05CustomizationPerObjDataGameState::createScene01() { Ogre::SceneManager *sceneManager = mGraphicsSystem->getSceneManager(); @@ -153,7 +153,7 @@ void Hlms05CustomizationPerObjArbitraryDataGameState::createScene01() TutorialGameState::createScene01(); } //----------------------------------------------------------------------------- -void Hlms05CustomizationPerObjArbitraryDataGameState::update( float timeSinceLast ) +void Hlms05CustomizationPerObjDataGameState::update( float timeSinceLast ) { for( Ogre::Item *item : mChangingItems ) { diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjDataGameState.h b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjDataGameState.h new file mode 100644 index 00000000000..77a219eb8e1 --- /dev/null +++ b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_CustomizationPerObjDataGameState.h @@ -0,0 +1,23 @@ + +#ifndef Demo_Hlms05CustomizationPerObjDataGameState_H +#define Demo_Hlms05CustomizationPerObjDataGameState_H + +#include "OgrePrerequisites.h" +#include "TutorialGameState.h" + +namespace Demo +{ + class Hlms05CustomizationPerObjDataGameState : public TutorialGameState + { + std::vector mChangingItems; + + public: + Hlms05CustomizationPerObjDataGameState( const Ogre::String &helpDescription ); + + void createScene01() override; + + void update( float timeSinceLast ) override; + }; +} // namespace Demo + +#endif diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_MyHlmsPbs.cpp b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_MyHlmsPbs.cpp similarity index 100% rename from Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_MyHlmsPbs.cpp rename to Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_MyHlmsPbs.cpp diff --git a/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_MyHlmsPbs.h b/Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_MyHlmsPbs.h similarity index 100% rename from Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/Tutorial_Hlms05_MyHlmsPbs.h rename to Samples/2.0/Tutorials/Tutorial_Hlms05_CustomizationPerObjData/Tutorial_Hlms05_MyHlmsPbs.h diff --git a/Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/MyCustom_piece_all.any b/Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjData/MyCustom_piece_all.any similarity index 100% rename from Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/MyCustom_piece_all.any rename to Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjData/MyCustom_piece_all.any diff --git a/Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/MyCustom_piece_ps.any b/Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjData/MyCustom_piece_ps.any similarity index 100% rename from Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/MyCustom_piece_ps.any rename to Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjData/MyCustom_piece_ps.any diff --git a/Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/MyCustom_piece_vs.any b/Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjData/MyCustom_piece_vs.any similarity index 100% rename from Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjArbitraryData/MyCustom_piece_vs.any rename to Samples/Media/2.0/scripts/materials/Tutorial_Hlms05_CustomizationPerObjData/MyCustom_piece_vs.any diff --git a/Samples/Media/Hlms/Common/Any/Cubemap_piece_all.any b/Samples/Media/Hlms/Common/Any/Cubemap_piece_all.any index 3cd2def5cb2..c83d200d6f5 100644 --- a/Samples/Media/Hlms/Common/Any/Cubemap_piece_all.any +++ b/Samples/Media/Hlms/Common/Any/Cubemap_piece_all.any @@ -61,7 +61,7 @@ INLINE midf4 localCorrect( midf3 reflDir, midf3 posLS, CubemapProbe probe ) \return Position in local space. */ -@property( syntax == metal )inline @end float3 toProbeLocalSpace( float3 pos, CubemapProbe probe ) +@property( syntax == metal )inline @end midf3 toProbeLocalSpace( float3 pos, CubemapProbe probe ) { float3 probeShapeCenterVS = float3( probe.row0_centerX.w, probe.row1_centerY.w, @@ -78,7 +78,7 @@ INLINE midf4 localCorrect( midf3 reflDir, midf3 posLS, CubemapProbe probe ) posLS = posLS * viewSpaceToProbeLocal; @end - return posLS; + return midf3_c( posLS ); } /// Returns true if position (in local space) is inside the probe. False otherwise diff --git a/Samples/Media/Hlms/Pbs/Any/ForwardPlus_DecalsCubemaps_piece_ps.any b/Samples/Media/Hlms/Pbs/Any/ForwardPlus_DecalsCubemaps_piece_ps.any index 194503bda24..92e7977d4f3 100644 --- a/Samples/Media/Hlms/Pbs/Any/ForwardPlus_DecalsCubemaps_piece_ps.any +++ b/Samples/Media/Hlms/Pbs/Any/ForwardPlus_DecalsCubemaps_piece_ps.any @@ -169,7 +169,7 @@ float4 probeInnerRange = readOnlyFetch( f3dLightList, int(idx + 6u) ).xyzw; float4 probeOuterRange = readOnlyFetch( f3dLightList, int(idx + 7u) ).xyzw; - midf3 posInProbSpace = midf3_c( toProbeLocalSpace( inPs.pos, probe ) ); + midf3 posInProbSpace = toProbeLocalSpace( inPs.pos, probe ); midf probeFade = getProbeFade( posInProbSpace, probe ); if( probeFade > _h( 0 ) ) diff --git a/Samples/Media/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any b/Samples/Media/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any index 152b2bd6ebc..48247f1af02 100644 --- a/Samples/Media/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any +++ b/Samples/Media/Hlms/Pbs/Any/Main/800.PixelShader_piece_ps.any @@ -367,9 +367,9 @@ @property( two_sided_lighting ) @property( hlms_forwardplus_flipY ) - @piece( two_sided_flip_normal )* (gl_FrontFacing ? -1.0 : 1.0)@end + @piece( two_sided_flip_normal )* (gl_FrontFacing ? _h(-1.0) : _h(1.0))@end @else - @piece( two_sided_flip_normal )* (gl_FrontFacing ? 1.0 : -1.0)@end + @piece( two_sided_flip_normal )* (gl_FrontFacing ? _h(1.0) : _h(-1.0))@end @end @end @piece( LoadGeomNormalData ) @@ -665,7 +665,7 @@ @end @piece( CubemapManualPcc ) - midf3 posInProbSpace = midf3_c( toProbeLocalSpace( inPs.pos, @insertpiece( pccProbeSource ) ) ); + midf3 posInProbSpace = toProbeLocalSpace( inPs.pos, @insertpiece( pccProbeSource ) ); midf probeFade = getProbeFade( posInProbSpace, @insertpiece( pccProbeSource ) ); @property( vct_num_probes ) if( probeFade > _h( 0 ) && (pixelData.roughness < _h( 1.0f ) || vctSpecular.w == 0) ) @@ -751,14 +751,14 @@ @piece( ProcessAlpha ) @property( hlms_alphablend || hlms_alpha_to_coverage || hlms_alpha_hash ) @property( use_texture_alpha ) - float finalAlpha = midf_c( material.F0.w ) * pixelData.diffuse.w; + midf finalAlpha = midf_c( material.F0.w ) * midf_c( pixelData.diffuse.w ); @else - float finalAlpha = midf_c( material.F0.w ); + midf finalAlpha = midf_c( material.F0.w ); @end @property( hlms_alpha_hash ) @property( hlms_alpha_to_coverage ) - finalAlpha = AlphaHashReject( finalAlpha, inPs.uv0.xy ALPHA_HASHING_ARG ); + finalAlpha = midf_c( AlphaHashReject( finalAlpha, inPs.uv0.xy ALPHA_HASHING_ARG ) ); @else if( AlphaHashReject( finalAlpha, inPs.uv0.xy ALPHA_HASHING_ARG ) ) discard; diff --git a/Samples/Media/Hlms/Pbs/Metal/VertexShader_vs.metal b/Samples/Media/Hlms/Pbs/Metal/VertexShader_vs.metal index 32871626436..418efcda80d 100644 --- a/Samples/Media/Hlms/Pbs/Metal/VertexShader_vs.metal +++ b/Samples/Media/Hlms/Pbs/Metal/VertexShader_vs.metal @@ -37,6 +37,9 @@ struct PS_INPUT @insertpiece( VStoPS_block ) float4 gl_Position [[position]]; + @property( hlms_instanced_stereo ) + uint gl_ViewportIndex [[viewport_array_index]]; + @end @property( hlms_pso_clip_distances ) float gl_ClipDistance [[clip_distance]] [@value( hlms_pso_clip_distances )]; @end diff --git a/Samples/Media/Hlms/Unlit/Any/800.PixelShader_piece_ps.any b/Samples/Media/Hlms/Unlit/Any/800.PixelShader_piece_ps.any index 181918bd92b..cd10a8eee9c 100644 --- a/Samples/Media/Hlms/Unlit/Any/800.PixelShader_piece_ps.any +++ b/Samples/Media/Hlms/Unlit/Any/800.PixelShader_piece_ps.any @@ -126,7 +126,7 @@ outPs_colour0 = diffuseCol; @property( hlms_alpha_hash && hlms_alpha_to_coverage ) - outPs_colour0.w = AlphaHashReject( diffuseCol.w, inPs.uv0.xy ALPHA_HASHING_ARG ); + outPs_colour0.w = midf_c( AlphaHashReject( diffuseCol.w, inPs.uv0.xy ALPHA_HASHING_ARG ) ); @end @end @end