-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Speed up Draco loading #6420
Speed up Draco loading #6420
Changes from 2 commits
0c9de68
00bc404
10df9c7
4298c08
c0a4f86
c34ba36
1a07fe3
c27c907
76b26a4
696e191
bb60b41
4d2c551
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
Change Log | ||
========== | ||
|
||
### 1.45 - 2018-05-01 | ||
|
||
##### Additions :tada: | ||
* Added `webAssemblyOptions` parameter to `TaskProcessor` to specify options for loading a Web Assembly module in a web worker. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mention the addition to |
||
|
||
##### Fixes :wrench: | ||
* Faster loading of Draco compressed glTF assets. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make some mention of WebAssembly, maybe "Faster loading of Draco compressed glTF assets in browsers that support WebAssembly". |
||
|
||
### 1.44 - 2018-04-02 | ||
|
||
##### Breaking Changes :mega: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,10 @@ define([ | |
'./destroyObject', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even though Draco doesn't work in IE yet I went to open Sandcastle in IE and it doesn't get past the loading screen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merged in master, that should incorporate the error message fix. |
||
'./DeveloperError', | ||
'./Event', | ||
'./FeatureDetection', | ||
'./getAbsoluteUri', | ||
'./isCrossOriginUrl', | ||
'./Resource', | ||
'./RuntimeError', | ||
'require' | ||
], function( | ||
|
@@ -18,8 +20,10 @@ define([ | |
destroyObject, | ||
DeveloperError, | ||
Event, | ||
FeatureDetection, | ||
getAbsoluteUri, | ||
isCrossOriginUrl, | ||
Resource, | ||
RuntimeError, | ||
require) { | ||
'use strict'; | ||
|
@@ -132,13 +136,49 @@ define([ | |
return bootstrapperUrlResult; | ||
} | ||
|
||
function getWebAssemblyLoaderConfig(processor) { | ||
if (defined(processor._webAssemblyConfig)) { | ||
return when.resolve(processor._webAssemblyConfig); | ||
} | ||
|
||
var config = { | ||
modulePath : undefined, | ||
wasmBinaryFile : undefined, | ||
wasmBinary : undefined | ||
}; | ||
|
||
var wasmOptions = processor._webAssemblyOptions; | ||
if (!defined(wasmOptions)) { | ||
return when.resolve(config); | ||
} | ||
|
||
// Web assembly not supported, use fallback js module if provided | ||
if (!FeatureDetection.supportsWebAssembly()) { | ||
if (defined(wasmOptions.fallbackModulePath)) { | ||
config.modulePath = buildModuleUrl(wasmOptions.fallbackModulePath); | ||
} | ||
return when.resolve(config); | ||
} | ||
|
||
config.modulePath = buildModuleUrl(wasmOptions.modulePath); | ||
config.wasmBinaryFile = buildModuleUrl(wasmOptions.wasmBinaryFile); | ||
|
||
return Resource.fetchArrayBuffer({ | ||
url: config.wasmBinaryFile | ||
}).then(function (arrayBuffer) { | ||
config.wasmBinary = arrayBuffer; | ||
return config; | ||
}); | ||
} | ||
|
||
function createWorker(processor) { | ||
var worker = new Worker(getBootstrapperUrl()); | ||
worker.postMessage = defaultValue(worker.webkitPostMessage, worker.postMessage); | ||
|
||
var bootstrapMessage = { | ||
loaderConfig : {}, | ||
workerModule : TaskProcessor._workerModulePrefix + processor._workerName | ||
workerModule : TaskProcessor._workerModulePrefix + processor._workerName, | ||
webAssemblyConfig : undefined | ||
}; | ||
|
||
if (defined(TaskProcessor._loaderConfig)) { | ||
|
@@ -152,11 +192,39 @@ define([ | |
}; | ||
} | ||
|
||
worker.postMessage(bootstrapMessage); | ||
getWebAssemblyLoaderConfig(processor).then(function(wasmConfig) { | ||
processor._webAssemblyConfig = wasmConfig; | ||
|
||
worker.onmessage = function(event) { | ||
completeTask(processor, event.data); | ||
}; | ||
return when(canTransferArrayBuffer(), function(canTransferArrayBuffer) { | ||
if (!defined(wasmConfig.modulePath)) { | ||
worker.postMessage(bootstrapMessage); | ||
|
||
worker.onmessage = function(event) { | ||
completeTask(processor, event.data); | ||
}; | ||
|
||
return processor._workerReadyPromise.resolve(canTransferArrayBuffer); | ||
} | ||
|
||
bootstrapMessage.webAssemblyConfig = wasmConfig; | ||
|
||
var transferableObjects; | ||
var binary = wasmConfig.wasmBinary; | ||
if (defined(binary) && canTransferArrayBuffer) { | ||
transferableObjects = [binary]; | ||
} | ||
|
||
worker.postMessage(bootstrapMessage, transferableObjects); | ||
|
||
worker.onmessage = function() { | ||
worker.onmessage = function(event) { | ||
completeTask(processor, event.data); | ||
}; | ||
|
||
processor._workerReadyPromise.resolve(canTransferArrayBuffer); | ||
}; | ||
}); | ||
}); | ||
|
||
return worker; | ||
} | ||
|
@@ -175,13 +243,21 @@ define([ | |
* @param {Number} [maximumActiveTasks=5] The maximum number of active tasks. Once exceeded, | ||
* scheduleTask will not queue any more tasks, allowing | ||
* work to be rescheduled in future frames. | ||
* @param {Object} [webAssemblyOptions] If specified, the worker will load and compile a Web Assembly module before scheduling tasks. An object with the following properties: | ||
* @param {String} [webAssemblyOptions.modulePath] The path of the web assembly JavaScript wrapper module. | ||
* @param {String} [webAssemblyOptions.wasmBinaryFile] The path of the web assembly binary file. | ||
* @param {String} [webAssemblyOptions.fallbackModulePath] The path of the fallback JavaScript module to use if web assembly is not supported. | ||
*/ | ||
function TaskProcessor(workerName, maximumActiveTasks) { | ||
function TaskProcessor(workerName, maximumActiveTasks, webAssemblyOptions) { | ||
this._workerName = workerName; | ||
this._maximumActiveTasks = defaultValue(maximumActiveTasks, 5); | ||
this._webAssemblyOptions = webAssemblyOptions; | ||
this._activeTasks = 0; | ||
this._deferreds = {}; | ||
this._nextID = 0; | ||
this._workerReadyPromise = when.defer(); | ||
|
||
this._webAssemblyConfig = undefined; | ||
} | ||
|
||
var emptyTransferableObjectArray = []; | ||
|
@@ -224,7 +300,8 @@ define([ | |
++this._activeTasks; | ||
|
||
var processor = this; | ||
return when(canTransferArrayBuffer(), function(canTransferArrayBuffer) { | ||
var readyPromise = processor._workerReadyPromise; | ||
return readyPromise.then(function (canTransferArrayBuffer) { | ||
if (!defined(transferableObjects)) { | ||
transferableObjects = emptyTransferableObjectArray; | ||
} else if (!canTransferArrayBuffer) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add links to the PR in the new entries.