Skip to content

Commit

Permalink
Apply clang format to Metal (#235)
Browse files Browse the repository at this point in the history
Fix build errors when building iOS with Ninja
  • Loading branch information
darksylinc committed Dec 27, 2021
1 parent d98afac commit 1499e2c
Show file tree
Hide file tree
Showing 71 changed files with 3,533 additions and 3,698 deletions.
2 changes: 1 addition & 1 deletion CMake/Utils/OgreConfigTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if(APPLE)

if(NOT OGRE_BUILD_PLATFORM_ANDROID AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS)
set(PLATFORM_NAME "macosx")
elseif(OGRE_BUILD_PLATFORM_APPLE_IOS)
elseif(OGRE_BUILD_PLATFORM_APPLE_IOS AND NOT CMAKE_GENERATOR STREQUAL "Ninja")
set(PLATFORM_NAME "$(PLATFORM_NAME)")
endif()
endif()
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ if (OGRE_BUILD_PLATFORM_APPLE_IOS)
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.yourcompany.\${PRODUCT_NAME:rfc1034identifier}")
set( CMAKE_XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2" )

set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_INCLUDING_64_BIT)")
if( NOT CMAKE_GENERATOR STREQUAL "Ninja" )
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_INCLUDING_64_BIT)")
endif()
string (REPLACE "-msse2" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string (REPLACE "-msse" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
elseif (ANDROID)
Expand Down
43 changes: 43 additions & 0 deletions RenderSystems/Metal/include/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
BasedOnStyle: Google
AlignAfterOpenBracket: Align
#AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'true'
AlignEscapedNewlines: DontAlign
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
BinPackParameters: 'true'
BreakBeforeBraces: Custom
ColumnLimit: '105'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
BreakConstructorInitializers: 'AfterColon'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'false'
DerivePointerAlignment: 'false'
IndentCaseLabels: 'false'
IndentWidth: '4'
NamespaceIndentation: All
PointerAlignment: Right
SpaceBeforeParens: Never
SpaceInEmptyParentheses: 'false'
SpacesInParentheses: 'true'
TabWidth: '4'
UseTab: Never
AccessModifierOffset: '-4'
IndentPPDirectives: 'AfterHash'
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false

...
26 changes: 14 additions & 12 deletions RenderSystems/Metal/include/OgreMetalAsyncTextureTicket.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,44 @@ THE SOFTWARE.
#define _OgreMetalAsyncTextureTicket_H_

#include "OgreMetalPrerequisites.h"

#include "OgreAsyncTextureTicket.h"

#include "OgreTextureBox.h"

#include <dispatch/dispatch.h>

namespace Ogre
{
/** See AsyncTextureTicket
*/
*/
class _OgreMetalExport MetalAsyncTextureTicket : public AsyncTextureTicket
{
protected:
id<MTLBuffer> mVboName;
id<MTLBuffer> mVboName;

uint32 mDownloadFrame;
dispatch_semaphore_t mAccurateFence;
MetalVaoManager *mVaoManager;
MetalDevice *mDevice;
uint32 mDownloadFrame;
dispatch_semaphore_t mAccurateFence;
MetalVaoManager * mVaoManager;
MetalDevice * mDevice;

virtual TextureBox mapImpl( uint32 slice );
virtual void unmapImpl();
virtual void unmapImpl();

void waitForDownloadToFinish();

virtual void downloadFromGpu( TextureGpu *textureSrc, uint8 mipLevel,
bool accurateTracking, TextureBox *srcBox=0 );
virtual void downloadFromGpu( TextureGpu *textureSrc, uint8 mipLevel, bool accurateTracking,
TextureBox *srcBox = 0 );

public:
MetalAsyncTextureTicket( uint32 width, uint32 height, uint32 depthOrSlices,
TextureTypes::TextureTypes textureType,
PixelFormatGpu pixelFormatFamily,
MetalVaoManager *vaoManager,
PixelFormatGpu pixelFormatFamily, MetalVaoManager *vaoManager,
MetalDevice *device );
virtual ~MetalAsyncTextureTicket();

virtual bool queryIsTransferDone();
};
}
} // namespace Ogre

#endif
29 changes: 15 additions & 14 deletions RenderSystems/Metal/include/OgreMetalDescriptorSetTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,41 @@ THE SOFTWARE.
#define _OgreMetalDescriptorSetTexture_H_

#include "OgreMetalPrerequisites.h"

#include "OgreDescriptorSetTexture.h"

#include "OgreHeaderPrefix.h"

namespace Ogre
{
/** \addtogroup Core
* @{
*/
* @{
*/
/** \addtogroup Resources
* @{
*/
* @{
*/

struct MetalTexRegion
{
__unsafe_unretained id <MTLTexture> *textures;
NSRange range;
ShaderType shaderType;
__unsafe_unretained id<MTLTexture> *textures;
NSRange range;
ShaderType shaderType;
};
struct MetalBufferRegion
{
__unsafe_unretained id <MTLBuffer> *buffers;
NSUInteger *offsets;
NSRange range;
ShaderType shaderType;
__unsafe_unretained id<MTLBuffer> *buffers;
NSUInteger * offsets;
NSRange range;
ShaderType shaderType;
};

struct _OgreExport MetalDescriptorSetTexture
{
FastArray<MetalTexRegion> textures;
FastArray<MetalTexRegion> textures;
FastArray<MetalBufferRegion> buffers;

__strong id <MTLTexture> *textureViews;
size_t numTextureViews;
__strong id<MTLTexture> *textureViews;
size_t numTextureViews;
};

/** @} */
Expand Down
44 changes: 23 additions & 21 deletions RenderSystems/Metal/include/OgreMetalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ namespace Ogre
struct _OgreMetalExport MetalDevice
{
/// Once a frame is aborted, MTLRenderCommandEncoder are no longer created (ignored).
bool mFrameAborted;
id<MTLDevice> mDevice;
id<MTLCommandQueue> mMainCommandQueue;
id<MTLCommandBuffer> mCurrentCommandBuffer;
id<MTLBlitCommandEncoder> mBlitEncoder;
id<MTLComputeCommandEncoder>mComputeEncoder;
id<MTLRenderCommandEncoder> mRenderEncoder;
MetalRenderSystem *mRenderSystem;
dispatch_semaphore_t mStallSemaphore;
bool mFrameAborted;
id<MTLDevice> mDevice;
id<MTLCommandQueue> mMainCommandQueue;
id<MTLCommandBuffer> mCurrentCommandBuffer;
id<MTLBlitCommandEncoder> mBlitEncoder;
id<MTLComputeCommandEncoder> mComputeEncoder;
id<MTLRenderCommandEncoder> mRenderEncoder;
MetalRenderSystem * mRenderSystem;
dispatch_semaphore_t mStallSemaphore;

MetalDevice( MetalRenderSystem *renderSystem );
~MetalDevice();

void init( const MetalDeviceItem *device );

void endBlitEncoder();
void endRenderEncoder( bool endRenderPassDesc=true );
void endRenderEncoder( bool endRenderPassDesc = true );
void endComputeEncoder();

void endAllEncoders( bool endRenderPassDesc=true );
void endAllEncoders( bool endRenderPassDesc = true );

//Ends all encoders, calls commit and grabs a new mMainCommandBuffer
// Ends all encoders, calls commit and grabs a new mMainCommandBuffer
void commitAndNextCommandBuffer();

/** Gets current blit encoder. If none is current, ends all other
Expand All @@ -81,30 +81,32 @@ namespace Ogre
void stall();
};


class _OgreMetalExport MetalDeviceItem
{
id<MTLDevice> mDevice;
unsigned mSameNameAdapterIndex;
unsigned mSameNameAdapterIndex;

public:
MetalDeviceItem();
MetalDeviceItem(id<MTLDevice> device, unsigned sameNameIndex);
String getDescription() const;
MetalDeviceItem( id<MTLDevice> device, unsigned sameNameIndex );

String getDescription() const;
id<MTLDevice> getMTLDevice() const;
};

class _OgreMetalExport MetalDeviceList
{
vector<MetalDeviceItem>::type mItems;

public:
void refresh();
void clear();

size_t count() const;
const MetalDeviceItem* item( size_t index ) const;
const MetalDeviceItem* item( const String &name ) const;

const MetalDeviceItem *item( size_t index ) const;
const MetalDeviceItem *item( const String &name ) const;
};
}
} // namespace Ogre

#endif
61 changes: 33 additions & 28 deletions RenderSystems/Metal/include/OgreMetalDiscardBufferManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ Copyright (c) 2000-2016 Torus Knot Software Ltd
#define _OgreMetalDiscardBufferManager_H_

#include "OgreMetalPrerequisites.h"

#include "Vao/OgreMetalVaoManager.h"

namespace Ogre
{
class MetalDiscardBuffer;
typedef vector<MetalDiscardBuffer*>::type MetalDiscardBufferVec;
typedef vector<MetalDiscardBuffer *>::type MetalDiscardBufferVec;

/// Metal doesn't support "DISCARD" like D3D9/D3D11 (and OpenGL but often it's broken)
/// where we requested to map a write-only buffer and the API would discard the previous
Expand All @@ -51,24 +52,27 @@ namespace Ogre
uint32 lastFrameUsed;

UnsafeBlock( size_t _offset, size_t _size, uint32 _lastFrameUsed ) :
MetalVaoManager::Block( _offset, _size ), lastFrameUsed( _lastFrameUsed ) {}
MetalVaoManager::Block( _offset, _size ),
lastFrameUsed( _lastFrameUsed )
{
}

bool operator < ( const UnsafeBlock &other ) const
bool operator<( const UnsafeBlock &other ) const
{
return this->lastFrameUsed < other.lastFrameUsed;
}
};
typedef vector<UnsafeBlock>::type UnsafeBlockVec;

private:
id<MTLBuffer> mBuffer;
MetalDevice *mDevice;
VaoManager *mVaoManager;
MetalVaoManager::BlockVec mFreeBlocks;
id<MTLBuffer> mBuffer;
MetalDevice * mDevice;
VaoManager * mVaoManager;
MetalVaoManager::BlockVec mFreeBlocks;

UnsafeBlockVec mUnsafeBlocks;
UnsafeBlockVec mUnsafeBlocks;

MetalDiscardBufferVec mDiscardBuffers;
MetalDiscardBufferVec mDiscardBuffers;

/** Moves our current mBuffer into a new one (bigger one). Used when we've ran
out of usable space. This operation can be slow and will increase GPU memory
Expand Down Expand Up @@ -108,32 +112,33 @@ namespace Ogre
@return
A new MetalDiscardBuffer
*/
MetalDiscardBuffer* createDiscardBuffer( size_t bufferSize, uint16 alignment );
MetalDiscardBuffer *createDiscardBuffer( size_t bufferSize, uint16 alignment );

/** Destroys an existing MetalDiscardBuffer, releasing its memory.
@param discardBuffer
MetalDiscardBuffer to destroy
*/
void destroyDiscardBuffer( MetalDiscardBuffer *discardBuffer );

MetalDevice* getDevice() const { return mDevice; }
VaoManager* getVaoManager() const { return mVaoManager; }
MetalDevice *getDevice() const { return mDevice; }
VaoManager * getVaoManager() const { return mVaoManager; }
};

class _OgreMetalExport MetalDiscardBuffer : public BufferAlloc
{
friend class MetalDiscardBufferManager;

__unsafe_unretained id<MTLBuffer> mBuffer;
size_t mBlockPrePadding;
size_t mBufferOffset;
size_t mBufferSize;

uint16 mAlignment;
uint32 mLastFrameUsed;
size_t mBlockPrePadding;
size_t mBufferOffset;
size_t mBufferSize;

uint16 mAlignment;
uint32 mLastFrameUsed;

VaoManager *mVaoManager;
MetalDiscardBufferManager *mOwner;
VaoManager * mVaoManager;
MetalDiscardBufferManager *mOwner;

public:
MetalDiscardBuffer( size_t bufferSize, uint16 alignment, VaoManager *vaoManager,
Expand All @@ -144,14 +149,14 @@ namespace Ogre
When true, noOverwrite is slow
@return
*/
void* map( bool noOverwrite );
void unmap();
void *map( bool noOverwrite );
void unmap();

uint16 getAlignment() const { return mAlignment; }
uint16 getAlignment() const { return mAlignment; }
/// Size of the buffer, may be bigger than requested due to 4-byte alignment required by Metal.
size_t getSizeBytes() const { return mBufferSize; }
size_t getSizeBytes() const { return mBufferSize; }

size_t getOffset() const { return mBufferOffset; }
size_t getOffset() const { return mBufferOffset; }
/** Returns the actual API buffer, but first sets mLastFrameUsed as we
assume you're calling this function to use the buffer in the GPU.
@param outOffset
Expand All @@ -163,11 +168,11 @@ namespace Ogre
id<MTLBuffer> getBufferName( size_t &outOffset );

/// For internal use by MetalDiscardBufferManager
size_t getBlockStart() const { return mBufferOffset - mBlockPrePadding; }
size_t getBlockSize() const { return mBufferSize + mBlockPrePadding; }
size_t getBlockStart() const { return mBufferOffset - mBlockPrePadding; }
size_t getBlockSize() const { return mBufferSize + mBlockPrePadding; }

MetalDiscardBufferManager* getOwner() { return mOwner; }
MetalDiscardBufferManager *getOwner() { return mOwner; }
};
}
} // namespace Ogre

#endif
Loading

0 comments on commit 1499e2c

Please sign in to comment.