Skip to content

Commit

Permalink
fixed memory leak on x86 android devices. (#17172)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Jun 18, 2024
1 parent 1841843 commit 6d7cfb1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/native-compile-platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ jobs:
sed -i "s@^COCOS_ENGINE_PATH.*@COCOS_ENGINE_PATH=$NATIVE_ROOT@g" gradle.properties
sed -i "s@^NATIVE_DIR.*@NATIVE_DIR=$NATIVE_DIR@g" gradle.properties
# To speedup CI, compile arm64-v8a only
# To speedup CI, compile x86 only
# sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=armeabi-v7a:arm64-v8a:x86@g" gradle.properties
sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=arm64-v8a@g" gradle.properties
sed -i "s@^PROP_APP_ABI.*@PROP_APP_ABI=x86@g" gradle.properties
echo "Compile Android - cmake ..."
echo "ANDROID_NDK ${ANDROID_NDK} or ${ANDROID_NDK_HOME}"
Expand Down
4 changes: 4 additions & 0 deletions native/cocos/base/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,7 @@ It should work same as apples CFSwapInt32LittleToHost(..)
#define CC_FORCE_INLINE inline
#endif
#endif

// Macro definition to check if a type has padding
#define CC_CHECK_STRUCT_NO_PADDING(T) \
static_assert(std::has_unique_object_representations_v<T>, "ERROR: Type has padding bytes!")
10 changes: 7 additions & 3 deletions native/cocos/renderer/gfx-base/GFXDef-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,9 @@ struct ALIGNAS(8) ColorAttachment {
LoadOp loadOp{LoadOp::CLEAR};
StoreOp storeOp{StoreOp::STORE};
GeneralBarrier *barrier{nullptr};

#if CC_CPU_ARCH == CC_CPU_ARCH_32
uint32_t _padding{0};
#endif
EXPOSE_COPY_FN(ColorAttachment)
};

Expand All @@ -1305,7 +1307,9 @@ struct ALIGNAS(8) DepthStencilAttachment {
LoadOp stencilLoadOp{LoadOp::CLEAR};
StoreOp stencilStoreOp{StoreOp::STORE};
GeneralBarrier *barrier{nullptr};

#if CC_CPU_ARCH == CC_CPU_ARCH_32
uint32_t _padding{0};
#endif
EXPOSE_COPY_FN(DepthStencilAttachment)
};

Expand Down Expand Up @@ -1396,7 +1400,7 @@ struct ALIGNAS(8) BufferBarrierInfo {

uint32_t offset{0};
uint32_t size{0};

uint32_t _padding{0};
uint64_t discardContents{0}; // @ts-boolean

Queue *srcQueue{nullptr}; // @ts-nullable
Expand Down
1 change: 1 addition & 0 deletions native/cocos/renderer/gfx-base/GFXDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace gfx {
// T must have no implicit padding
template <typename T>
ccstd::hash_t quickHashTrivialStruct(const T *info, size_t count = 1) {
CC_CHECK_STRUCT_NO_PADDING(T);
static_assert(std::is_trivially_copyable<T>::value && sizeof(T) % 8 == 0, "T must be 8 bytes aligned and trivially copyable");
return ccstd::hash_range(reinterpret_cast<const uint64_t *>(info), reinterpret_cast<const uint64_t *>(info + count));
}
Expand Down

0 comments on commit 6d7cfb1

Please sign in to comment.