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

Add support for building for Windows ARM64 devices #3430

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,10 @@ def RunCMake(context, force, extraArgs = None):

# Note - don't want to add -A (architecture flag) if generator is, ie, Ninja
if IsVisualStudio2019OrGreater() and "Visual Studio" in generator:
generator = generator + " -A x64"
if "ARM" in os.environ.get('PROCESSOR_IDENTIFIER'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could the platform module be used here?
https://docs.python.org/3/library/platform.html#module-platform

Copy link
Author

@anthony-linaro anthony-linaro Dec 10, 2024

Choose a reason for hiding this comment

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

(repost from correct account)

It could be, but problems arise when running an emulated x64 version of python (which is easy to do by mistake, as that's what the website gives you by default).

This way checks the name of the processor directly, which is not affected by emulation.

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be good to follow the convention in apple_utils.py and extract this into GetHostArch https://github.com/PixarAnimationStudios/OpenUSD/blob/release/build_scripts/apple_utils.py#L66

Copy link
Author

Choose a reason for hiding this comment

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

Is the suggestion here to write a whole new windows_utils.py (and extract/refactor some things like IsVisualStudioXXXXOrGreater() which are windows only), or just add a function to build_usd.py called something along the lines of GetWindowsHostArch()?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I'd advocate for another file necessarily (though it is the route I would take myself)

But just extracting the heuristics for detecting arm into a function somewhere in this file itself should be fine?

I just imagine that in the future, we'll need to modify the build parameters for certain dependencies etc based on the current arch, and so it'd be nice to have it as a function from the get go.

Copy link
Author

Choose a reason for hiding this comment

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

I have now moved it out to a seperate function - it should now reliably detect ARM or x64

Critique very much welcome - I've never been much of a python dev

generator = generator + " -A arm64"
anthony-linaro marked this conversation as resolved.
Show resolved Hide resolved
else:
generator = generator + " -A x64"

toolset = context.cmakeToolset
if toolset is not None:
Expand Down
6 changes: 4 additions & 2 deletions pxr/base/arch/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
#if defined(i386) || defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_X64)
#define ARCH_CPU_INTEL
#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM)
#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || \
defined(_M_ARM64)
anthony-linaro marked this conversation as resolved.
Show resolved Hide resolved
#define ARCH_CPU_ARM
#endif

//
// Bits
//

#if defined(__x86_64__) || defined(__aarch64__) || defined(_M_X64)
#if defined(__x86_64__) || defined(__aarch64__) || defined(_M_X64) || \
defined(_M_ARM64)
#define ARCH_BITS_64
#else
#error "Unsupported architecture. x86_64 or ARM64 required."
Expand Down
12 changes: 10 additions & 2 deletions pxr/base/arch/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ ArchGetTickTime()
return __rdtsc();
#elif defined (ARCH_CPU_ARM)
uint64_t result;
#if defined(ARCH_COMPILER_MSVC)
// MSVC does not support inline assembly on ARM64 platforms
// 0x5F02 == ARM64_CNTVCT - manually calculated value avoids <windows.h>
result = _ReadStatusReg(0x5F02);
#else
__asm __volatile("mrs %0, CNTVCT_EL0" : "=&r" (result));
#endif
return result;
#else
#error Unknown architecture.
Expand All @@ -68,7 +74,8 @@ inline uint64_t
ArchGetStartTickTime()
{
uint64_t t;
#if defined (ARCH_OS_DARWIN)
#if defined (ARCH_OS_DARWIN) || \
(defined (ARCH_CPU_ARM) && defined (ARCH_COMPILER_MSVC))
return ArchGetTickTime();
#elif defined (ARCH_CPU_ARM)
std::atomic_signal_fence(std::memory_order_seq_cst);
Expand Down Expand Up @@ -109,7 +116,8 @@ inline uint64_t
ArchGetStopTickTime()
{
uint64_t t;
#if defined (ARCH_OS_DARWIN)
#if defined (ARCH_OS_DARWIN) || \
(defined (ARCH_CPU_ARM) && defined (ARCH_COMPILER_MSVC))
return ArchGetTickTime();
#elif defined (ARCH_CPU_ARM)
std::atomic_signal_fence(std::memory_order_seq_cst);
Expand Down