Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change GLOBAL_ALIGNMENT to 8 bytes #316

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ZeunO8
Copy link

@ZeunO8 ZeunO8 commented Feb 7, 2023

While debugging Android I found that some assertions for byte alignment were failing.

Changing to 8 bytes alignment fixed the issue and I now have my build working on Android

@@ -324,7 +324,7 @@ void HeapAllocator::reserve(size_t sizeToAllocate) {
void* memory = mBaseAllocator.allocate(sizeToAllocate + sizeof(MemoryUnitHeader));
assert(memory != nullptr);

// Check that allocated memory is 16-bytes aligned
// Check that allocated memory is 8-bytes aligned
assert(reinterpret_cast<uintptr_t>(memory) % GLOBAL_ALIGNMENT == 0);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the assertion that was failing. The memory address was aligned to 8 not 16 (when GLOBAL_ALIGNMENT was 16)

Copy link
Owner

@DanielChappuis DanielChappuis Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please provide a document/link or something saying that 8 bytes memory alignment is required on Android? I want to make sure this is not a bug or something else that is wrong. I don't want to change this value just because it solves an issue on your side.

Can you please tell me what asserts where failing exactly with 16 bytes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any documents or links that says 8 bytes memory alignment is required on Android. However I just know from experience getting my Android NDK app up and running that 8 bytes is optimal.
The assertion that was failing was HeapAllocator.cpp:328

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this assert was failing when GLOBAL_ALIGMNENT =16, this could be a bug. It means that the previous call:

void* memory = mBaseAllocator.allocate(sizeToAllocate + sizeof(MemoryUnitHeader));

failed to allocated 16 bytes aligned memory. That's strange because this statement should call the following line:

return std::aligned_alloc(GLOBAL_ALIGNMENT, size);

Can you check if this line with the call to std::aligned_alloc() really returns memory that is not 16 bytes aligned when GLOBAL_ALIGNMENT=16? This mean that there is something wrong with this standard library method on Android or maybe there is another method that should be used on Android to get aligned memory but the solution is probably not to change GLOBAL_ALIGNMENT to 8 bytes.

Copy link
Author

@ZeunO8 ZeunO8 Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have another debugging session later on today and get back to you (:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello. I know when spoke about this last year but do you have any news regarding this issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't sadly. I have gone through various Physics Engines in the last year, currently settling on Bullet.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants