Skip to content

Commit a2c702f

Browse files
committed
Fixes
1 parent a250001 commit a2c702f

File tree

10 files changed

+81
-16
lines changed

10 files changed

+81
-16
lines changed

build_scripts/build_usd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def InstallBoost(context, force, buildArgs):
868868
TBB_URL = "https://github.com/oneapi-src/oneTBB/archive/2018_U6.tar.gz"
869869

870870
# Note: this refers to a fork of tbb for wasm. Is this maintained?
871-
TBB_EMSCRIPTEN_URL = "https://github.com/hpcwasm/wasmtbb/archive/master.zip"
871+
TBB_EMSCRIPTEN_URL = "https://github.com/sdunkel/wasmtbb/archive/master.zip"
872872

873873
def InstallTBB(context, force, buildArgs):
874874
if context.emscripten:

extras/usd/js_bindings/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,37 @@ set(BUILD_FILES
4040
${CMAKE_CURRENT_BINARY_DIR}/${BINDINGS_NAME}.js
4141
${CMAKE_CURRENT_BINARY_DIR}/${BINDINGS_NAME}.wasm
4242
${CMAKE_CURRENT_BINARY_DIR}/${BINDINGS_NAME}.worker.js
43+
${CMAKE_SOURCE_DIR}/js/test.html
4344
)
4445

46+
install(
47+
FILES
48+
${BUILD_FILES}
49+
DESTINATION ${CMAKE_BINARY_DIR}/../../bin
50+
)
51+
52+
# Install files for npm package
4553
install(
4654
FILES
4755
${BUILD_FILES}
4856
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../../../js/bindings/${CMAKE_BUILD_TYPE}
4957
)
58+
59+
#[[
60+
# Create ES6 module - TBD
61+
install(
62+
CODE
63+
"execute_process(
64+
COMMAND
65+
${CMAKE_COMMAND}
66+
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
67+
-P
68+
${CMAKE_CURRENT_LIST_DIR}/create_es6_module.cmake
69+
)"
70+
)
71+
72+
install(
73+
FILES ${CMAKE_CURRENT_BINARY_DIR}/usd.js
74+
DESTINATION ${CMAKE_BINARY_DIR}/../../bin
75+
)
76+
]]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
set(BINDINGS_NAME "jsBindings")
3+
4+
function(cat IN_FILE OUT_FILE)
5+
file(READ ${IN_FILE} CONTENTS)
6+
file(APPEND ${OUT_FILE} "${CONTENTS}")
7+
endfunction()
8+
9+
message(STATUS "SOURCE_DIR: ${SOURCE_DIR}")
10+
11+
set(ES6_MODULE_FILES
12+
${CMAKE_BINARY_DIR}/extras/usd/js_bindings/${BINDINGS_NAME}.js
13+
${SOURCE_DIR}/js/usd-module-appendix.js
14+
)
15+
file(WRITE ${CMAKE_BINARY_DIR}/extras/usd/js_bindings/usd.js "")
16+
17+
foreach(ES6_MODULE_FILE ${ES6_MODULE_FILES})
18+
cat(${ES6_MODULE_FILE} ${CMAKE_BINARY_DIR}/extras/usd/js_bindings/usd.js)
19+
endforeach()

js/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ or in watch mode
4242
npm run test -- --watch
4343
```
4444

45+
After installation you have a *bin* subfolder under your *build* folder. This contains
46+
a *test.html* file you can open in a browser. USD-for-Web uses the SharedArrayBuffer
47+
feature - this requires certain security headers (CORS).
48+
If you don't want to worry about this for testing purposes you can run the Chrome browser
49+
with --enable-features=SharedArrayBuffer as a command line argument.
50+
4551
NPM package consumption
4652
------------------------
4753

@@ -67,16 +73,17 @@ and after adding `<script src="jsBindings.js"></script>` to your HTML page use i
6773
```
6874
<script src="jsBindings.js"></script>
6975
<script type="module">
70-
import {UsdStage} from './usd.js';
76+
const Usd = await usdModule();
77+
const UsdStage = Usd.UsdStage;
7178
let stage = UsdStage.CreateNew('HelloWorld.usda');
7279
</script>
7380
```
7481

7582
In Node.Js you can load it via
7683
```
7784
const usdModule = require("usd");
78-
let Usd = await usdModule();
79-
let UsdStage = Usd.UsdStage;
85+
const Usd = await usdModule();
86+
const UsdStage = Usd.UsdStage;
8087
8188
let stage = UsdStage.CreateNew('HelloWorld.usda');
8289
...

js/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
},
99
"scripts": {
1010
"test": "jest --forceExit",
11-
"test-html": "emrun --no_browser test.html",
12-
"postinstall": "cp usd.mjs bindings/RelWithDebInfo"
11+
"test-html": "emrun --no_browser test.html"
1312
},
1413
"jest": {
1514
"testTimeout": 30000,

js/test.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<html>
2-
<head>
3-
<base href="bindings/RelWithDebInfo/">
4-
</head>
52
<body>
6-
<script src="jsBindings.js"></script>
3+
<script src='./jsBindings.js'></script>
4+
75
<script type="module">
8-
import {UsdStage} from './usd.mjs';
6+
const Usd = await getUsdModule();
7+
const UsdStage = Usd.UsdStage;
98

109
let stage = UsdStage.CreateNew('HelloWorld.usda');
1110
stage.DefinePrim('/hello', 'Xform');

js/usd-module-appendix.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
if (typeof window === 'object') {
3+
window.GET_USD_MODULE = getUsdModule;
4+
}
5+

js/usd.mjs

Lines changed: 0 additions & 2 deletions
This file was deleted.

pxr/base/arch/timing.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ Arch_InitTickTimer()
7272
{
7373
}
7474

75+
static
76+
void
77+
Arch_ComputeNanosecondsPerTick()
78+
{
79+
}
7580
#elif defined(ARCH_OS_LINUX)
7681

7782
static
@@ -200,6 +205,7 @@ Arch_ComputeNanosecondsPerTick()
200205
#error Unknown architecture.
201206
#endif
202207

208+
#if !defined(__EMSCRIPTEN__)
203209
// A externally visible variable used only to ensure the compiler doesn't do
204210
// certain optimizations we don't want in order to measure accurate times.
205211
uint64_t testTimeAccum;
@@ -240,6 +246,7 @@ Arch_InitTickTimer()
240246
});
241247
}
242248
}
249+
#endif
243250

244251
uint64_t
245252
ArchGetTickQuantum()
@@ -295,9 +302,13 @@ Arch_MeasureExecutionTime(uint64_t maxMicroseconds, bool *reachedConsensus,
295302
// Since measured times are +/- 1 quantum, we multiply by 2000 to get the
296303
// desired runtime, and from there figure number of iterations for a sample.
297304
const uint64_t minTicksPerSample = 2000 * ArchGetTickQuantum();
305+
#if defined(__EMSCRIPTEN__)
306+
const int sampleIters = 1; // FIXME
307+
#else
298308
const int sampleIters = (estTicksPer < minTicksPerSample)
299309
? (minTicksPerSample + estTicksPer/2) / estTicksPer
300-
: 1;
310+
: 1;
311+
#endif
301312

302313
auto measureSample = [&measureN, sampleIters]() {
303314
return (measureN(sampleIters) + sampleIters/2) / sampleIters;

pxr/base/arch/timing.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ inline uint64_t
9696
ArchGetStartTickTime()
9797
{
9898
uint64_t t;
99-
#if defined (ARCH_OS_DARWIN)
99+
#if defined (ARCH_OS_DARWIN) || defined(__EMSCRIPTEN__)
100100
return ArchGetTickTime();
101101
#elif defined (ARCH_CPU_ARM)
102102
std::atomic_signal_fence(std::memory_order_seq_cst);
@@ -137,7 +137,7 @@ inline uint64_t
137137
ArchGetStopTickTime()
138138
{
139139
uint64_t t;
140-
#if defined (ARCH_OS_DARWIN)
140+
#if defined (ARCH_OS_DARWIN) || defined(__EMSCRIPTEN__)
141141
return ArchGetTickTime();
142142
#elif defined (ARCH_CPU_ARM)
143143
std::atomic_signal_fence(std::memory_order_seq_cst);

0 commit comments

Comments
 (0)