Skip to content

Commit

Permalink
RSC_TILER + TextureFlags::Tiler[Depth]Memoryless => MTLStorageModeMem…
Browse files Browse the repository at this point in the history
…oryless and VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
  • Loading branch information
eugenegff committed Nov 16, 2024
1 parent 93c3add commit be65a3c
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 2 deletions.
17 changes: 16 additions & 1 deletion OgreMain/include/OgreTextureGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,17 @@ namespace Ogre
/// frames (e.g. HDR luminance change over time)
///
/// If this flag is present, either RenderToTexture or Uav must be present
DiscardableContent = 1u << 14u
DiscardableContent = 1u << 14u,
/// When this flag is present, we can save VRAM by using memoryless storage mode (Metal on
/// iOS and Apple Silicon macOS). Choose the memoryless mode if your texture is a memoryless
/// render target that’s temporarily populated and accessed by the GPU. Memoryless render
/// targets are render targets that exist only in tile memory and are not backed by system
/// memory. An example is a depth or stencil texture thatʼs used only within a render pass
/// and isnʼt needed before or after GPU execution. This flag requires RenderToTexture
TilerMemoryless = 1u << 15u,
/// When this flag is present together with RenderToTexture it will use DepthBuffer with
/// TilerMemoryless option
TilerDepthMemoryless = 1u << 16u
// clang-format on
};
}
Expand Down Expand Up @@ -649,6 +659,11 @@ namespace Ogre
bool isManualTexture() const;
bool isPoolOwner() const;
bool isDiscardableContent() const;
bool isTilerMemoryless() const { return ( mTextureFlags & TextureFlags::TilerMemoryless ) != 0; }
bool isTilerDepthMemoryless() const
{
return ( mTextureFlags & TextureFlags::TilerDepthMemoryless ) != 0;
}

/// OpenGL RenderWindows are a bit specific:
/// * Their origins are upside down. Which means we need to flip Y.
Expand Down
3 changes: 3 additions & 0 deletions OgreMain/src/OgreRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ namespace Ogre
if( !preferDepthTexture )
textureFlags |= TextureFlags::NotTexture | TextureFlags::DiscardableContent;

if( colourTexture->isTilerMemoryless() || colourTexture->isTilerDepthMemoryless() )
textureFlags |= TextureFlags::TilerMemoryless;

char tmpBuffer[64];
LwString depthBufferName( LwString::FromEmptyPointer( tmpBuffer, sizeof( tmpBuffer ) ) );
depthBufferName.a( "DepthBuffer_", Id::generateNewId<TextureGpu>() );
Expand Down
1 change: 1 addition & 0 deletions OgreMain/src/OgreTextureGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ namespace Ogre
if( this->getInternalWidth() == colourTarget->getInternalWidth() &&
this->getInternalHeight() == colourTarget->getInternalHeight() &&
this->getSampleDescription() == colourTarget->getSampleDescription() &&
this->isTilerMemoryless() == (colourTarget->isTilerMemoryless() || colourTarget->isTilerDepthMemoryless()) &&
this->isRenderWindowSpecific() == colourTarget->isRenderWindowSpecific() )
{
return true;
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Metal/src/OgreMetalRenderPassDescriptor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ of this software and associated documentation files (the "Software"), to deal
return MTLLoadActionDontCare;
case LoadAction::Clear:
return MTLLoadActionClear;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS || ( OGRE_PLATFORM == OGRE_PLATFORM_APPLE && OGRE_CPU == OGRE_CPU_ARM && OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 )
case LoadAction::ClearOnTilers:
return MTLLoadActionClear;
#else
Expand Down
27 changes: 27 additions & 0 deletions RenderSystems/Metal/src/OgreMetalTextureGpu.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ of this software and associated documentation files (the "Software"), to deal
#include "OgreVector2.h"
#include "Vao/OgreVaoManager.h"

#include "OgreRoot.h"
#import "Metal/MTLBlitCommandEncoder.h"

namespace Ogre
Expand Down Expand Up @@ -79,6 +80,24 @@ of this software and associated documentation files (the "Software"), to deal
if( mTextureType == TextureTypes::TypeCube || mTextureType == TextureTypes::TypeCubeArray )
desc.arrayLength /= 6u;

RenderSystem* rs = Root::getSingleton().getRenderSystem();
const RenderSystemCapabilities *capabilities = rs->getCapabilities();
bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
if(isTiler && isRenderWindowSpecific() && isRenderToTexture())
{
ConfigOptionMap& options = rs->getConfigOptions();
Ogre::ConfigOptionMap::iterator opt = options.find("WindowMemoryless");
if(opt!=options.end())
isTiler = opt->second.currentValue=="Yes";
}
if(isTiler)
{
if(@available(iOS 10, macOS 11, *))
{
if( (isTilerMemoryless() && isRenderToTexture()) || (isMultisample() && hasMsaaExplicitResolves() && !isTexture() && isRenderToTexture() && isDiscardableContent()) )
desc.storageMode = MTLStorageModeMemoryless;
}
}
if( isMultisample() && hasMsaaExplicitResolves() )
{
desc.textureType = MTLTextureType2DMultisample;
Expand Down Expand Up @@ -112,6 +131,14 @@ of this software and associated documentation files (the "Software"), to deal

if( isMultisample() && !hasMsaaExplicitResolves() )
{
if(isTiler)
{
if(@available(iOS 10, macOS 11, *))
{
if(((isTilerMemoryless() || isTilerDepthMemoryless()) && isRenderToTexture()) || (!isTexture() && isRenderToTexture() && isDiscardableContent()) )
desc.storageMode = MTLStorageModeMemoryless;
}
}
desc.textureType = MTLTextureType2DMultisample;
desc.depth = 1u;
desc.arrayLength = 1u;
Expand Down
7 changes: 7 additions & 0 deletions RenderSystems/Metal/src/OgreMetalTextureGpuManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ of this software and associated documentation files (the "Software"), to deal
#include "Vao/OgreMetalVaoManager.h"

#include "OgreException.h"
#include "OgreRoot.h"

namespace Ogre
{
Expand Down Expand Up @@ -150,18 +151,24 @@ of this software and associated documentation files (the "Software"), to deal
//-----------------------------------------------------------------------------------
TextureGpu *MetalTextureGpuManager::createTextureGpuWindow( MetalWindow *window )
{
const RenderSystemCapabilities *capabilities = Root::getSingleton().getRenderSystem()->getCapabilities();
const bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
return OGRE_NEW MetalTextureGpuWindow( GpuPageOutStrategy::Discard, mVaoManager, "RenderWindow",
TextureFlags::NotTexture | TextureFlags::RenderToTexture |
(isTiler ? TextureFlags::TilerDepthMemoryless : 0) |
TextureFlags::RenderWindowSpecific |
TextureFlags::DiscardableContent,
TextureTypes::Type2D, this, window );
}
//-----------------------------------------------------------------------------------
TextureGpu *MetalTextureGpuManager::createWindowDepthBuffer()
{
const RenderSystemCapabilities *capabilities = Root::getSingleton().getRenderSystem()->getCapabilities();
const bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
return OGRE_NEW MetalTextureGpuRenderTarget(
GpuPageOutStrategy::Discard, mVaoManager, "RenderWindow DepthBuffer",
TextureFlags::NotTexture | TextureFlags::RenderToTexture |
(isTiler ? TextureFlags::TilerMemoryless : 0) |
TextureFlags::RenderWindowSpecific | TextureFlags::DiscardableContent,
TextureTypes::Type2D, this );
}
Expand Down
17 changes: 17 additions & 0 deletions RenderSystems/Metal/src/OgreMetalWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ of this software and associated documentation files (the "Software"), to deal
#include "OgreStringConverter.h"
#include "OgreViewport.h"
#include "OgreWindowEventUtilities.h"
#include "OgreRoot.h"

#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS

Expand Down Expand Up @@ -197,6 +198,22 @@ static void SetupMetalWindowListeners( Ogre::MetalWindow *metalWindow, NSWindow
desc.sampleCount = mSampleDescription.getColourSamples();
desc.usage = MTLTextureUsageRenderTarget;
desc.storageMode = MTLStorageModePrivate;
RenderSystem* rs = Root::getSingleton().getRenderSystem();
assert(rs);
const RenderSystemCapabilities *capabilities = rs->getCapabilities();
bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
if(isTiler)
{
ConfigOptionMap& options = rs->getConfigOptions();
Ogre::ConfigOptionMap::iterator opt = options.find("WindowMemoryless");
if(opt!=options.end())
isTiler = opt->second.currentValue=="Yes";
}
if(isTiler)
{
if(@available(iOS 10, macOS 11, *))
desc.storageMode = MTLStorageModeMemoryless;
}

id<MTLTexture> msaaTex = [mDevice->mDevice newTextureWithDescriptor:desc];
if( !msaaTex )
Expand Down
40 changes: 40 additions & 0 deletions RenderSystems/Vulkan/src/OgreVulkanTextureGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ THE SOFTWARE.
#include "OgreVulkanMappings.h"
#include "OgreVulkanTextureGpuManager.h"
#include "OgreVulkanUtils.h"
#include "OgreRoot.h"
#include "OgreRenderSystem.h"

#define TODO_add_resource_transitions

Expand Down Expand Up @@ -144,6 +146,25 @@ namespace Ogre
if( isUav() )
imageInfo.usage |= VK_IMAGE_USAGE_STORAGE_BIT;

RenderSystem* rs = Root::getSingleton().getRenderSystem();
const RenderSystemCapabilities *capabilities = rs->getCapabilities();
bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
if(isTiler && isRenderWindowSpecific() && isRenderToTexture())
{
ConfigOptionMap& options = rs->getConfigOptions();
Ogre::ConfigOptionMap::iterator opt = options.find("WindowMemoryless");
if(opt!=options.end())
isTiler = opt->second.currentValue=="Yes";
}
if(isTiler && !isUav() && !isPoolOwner() && isRenderToTexture())
{
if( isTilerMemoryless() || (isMultisample() && hasMsaaExplicitResolves() && !isTexture() && isDiscardableContent()) )
{
imageInfo.usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
imageInfo.usage &= (VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
}
}

String textureName = getNameStr();

VulkanTextureGpuManager *textureManager =
Expand Down Expand Up @@ -979,6 +1000,25 @@ namespace Ogre
? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
: VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

RenderSystem* rs = Root::getSingleton().getRenderSystem();
const RenderSystemCapabilities *capabilities = rs->getCapabilities();
bool isTiler = capabilities->hasCapability( RSC_IS_TILER );
if(isTiler && isRenderWindowSpecific() && isRenderToTexture())
{
ConfigOptionMap& options = rs->getConfigOptions();
Ogre::ConfigOptionMap::iterator opt = options.find("WindowMemoryless");
if(opt!=options.end())
isTiler = opt->second.currentValue=="Yes";
}
if(isTiler && isRenderToTexture())
{
if((isTilerMemoryless() || isTilerDepthMemoryless()) || (!isTexture() && isDiscardableContent()) )
{
imageInfo.usage |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
imageInfo.usage &= (VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
}
}

String textureName = getNameStr() + "/MsaaImplicit";

VulkanTextureGpuManager *textureManager =
Expand Down

0 comments on commit be65a3c

Please sign in to comment.