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 all commits
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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,13 @@ Or for visionOS:

##### Windows:

Launch the "x64 Native Tools Command Prompt" for your version of Visual Studio
and run the script in the opened shell. Make sure to use the 64-bit (x64)
command prompt and not the 32-bit (x86) command prompt.
On Windows, it is possible to compile for either x64, or ARM64.
**Note**: ARM64EC is not compatible at this time.

Launch the "x64 Native Tools Command Prompt" (or "ARM64 Native Tools Command
Prompt" where appropriate) for your version of Visual Studio, and run the script
in the opened shell. Make sure to use the appropriate version of the command
prompt (e.g. on x64, use the x64 version, not the x86 version).

See https://docs.microsoft.com/en-us/cpp/build/how-to-enable-a-64-bit-visual-cpp-toolset-on-the-command-line for more details.

Expand Down
15 changes: 14 additions & 1 deletion build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ def IsVisualStudio2017OrGreater():
VISUAL_STUDIO_2017_VERSION = (14, 1)
return IsVisualStudioVersionOrGreater(VISUAL_STUDIO_2017_VERSION)

# Helper to get the current host arch on Windows
def GetWindowsHostArch():
identifier = os.environ.get('PROCESSOR_IDENTIFIER')
# ARM64 identifiers currently start with "ARMv8 ...."
# Note: This could be modified in the future to distinguish between ARMv8 and ARMv9
if "ARM" in identifier:
return "ARM64"
elif any(x64Arch in identifier for x64Arch in ["AMD64", "Intel64", "EM64T"]):
return "x64"
else:
raise RuntimeError("Unknown Windows host arch")

def GetPythonInfo(context):
"""Returns a tuple containing the path to the Python executable, shared
library, and include directory corresponding to the version of Python
Expand Down Expand Up @@ -393,7 +405,8 @@ 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"
windowsHostArch = GetWindowsHostArch()
generator = generator + " -A " + windowsHostArch

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