-
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 9 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 |
---|---|---|
|
@@ -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'; | ||
|
@@ -161,6 +165,32 @@ define([ | |
return worker; | ||
} | ||
|
||
function getWebAssemblyLoaderConfig(processor, wasmOptions) { | ||
var config = { | ||
modulePath : undefined, | ||
wasmBinaryFile : undefined, | ||
wasmBinary : undefined | ||
}; | ||
|
||
// Web assembly not supported, use fallback js module if provided | ||
if (!processor._supportsWasm) { | ||
if (defined(wasmOptions.fallbackModulePath)) { | ||
config.modulePath = buildModuleUrl(wasmOptions.fallbackModulePath); | ||
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. What happens if wasm is not supported and |
||
} | ||
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; | ||
}); | ||
} | ||
|
||
/** | ||
* A wrapper around a web worker that allows scheduling tasks for a given worker, | ||
* returning results asynchronously via a promise. | ||
|
@@ -182,6 +212,7 @@ define([ | |
this._activeTasks = 0; | ||
this._deferreds = {}; | ||
this._nextID = 0; | ||
this._supportsWasm = FeatureDetection.supportsWebAssembly(); // exposed for testing purposes | ||
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. Instead of adding this member variable for testing purposes, the test could mock |
||
} | ||
|
||
var emptyTransferableObjectArray = []; | ||
|
@@ -245,6 +276,48 @@ define([ | |
}); | ||
}; | ||
|
||
/** | ||
* Posts a message to a web worker with configuration to initialize loading | ||
* and compiling a web assembly module asychronously, as well as an optional | ||
* fallback JavaScript module to use if Web Assembly is not supported. | ||
* | ||
* @param {Object} [webAssemblyOptions] 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. | ||
* @returns {Promise.<Object>} A promise that resolves to the result when the web worker has loaded and compiled the web assembly module and is ready to process tasks. | ||
*/ | ||
TaskProcessor.prototype.initWebAssemblyModule = function (webAssemblyOptions) { | ||
if (!defined(this._worker)) { | ||
this._worker = createWorker(this); | ||
} | ||
|
||
var deferred = when.defer(); | ||
var processor = this; | ||
var worker = this._worker; | ||
getWebAssemblyLoaderConfig(this, webAssemblyOptions).then(function(wasmConfig) { | ||
return when(canTransferArrayBuffer(), function(canTransferArrayBuffer) { | ||
var transferableObjects; | ||
var binary = wasmConfig.wasmBinary; | ||
if (defined(binary) && canTransferArrayBuffer) { | ||
transferableObjects = [binary]; | ||
} | ||
|
||
worker.onmessage = function(event) { | ||
worker.onmessage = function(event) { | ||
completeTask(processor, event.data); | ||
}; | ||
|
||
deferred.resolve(event.data); | ||
}; | ||
|
||
worker.postMessage({ webAssemblyConfig : wasmConfig }, transferableObjects); | ||
}); | ||
}); | ||
|
||
return deferred; | ||
}; | ||
|
||
/** | ||
* Returns true if this object was destroyed; otherwise, false. | ||
* <br /><br /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,19 @@ define([ | |
|
||
// Exposed for testing purposes | ||
DracoLoader._decoderTaskProcessor = undefined; | ||
DracoLoader._taskProcessorReady = false; | ||
DracoLoader._getDecoderTaskProcessor = function () { | ||
if (!defined(DracoLoader._decoderTaskProcessor)) { | ||
DracoLoader._decoderTaskProcessor = new TaskProcessor('decodeDraco', DracoLoader._maxDecodingConcurrency); | ||
var processor = new TaskProcessor('decodeDraco', DracoLoader._maxDecodingConcurrency); | ||
processor._supportsWasm = false; | ||
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. This line should be removed. |
||
processor.initWebAssemblyModule({ | ||
modulePath : 'ThirdParty/Workers/draco_wasm_wrapper.js', | ||
wasmBinaryFile : 'ThirdParty/draco_decoder.wasm', | ||
fallbackModulePath : 'ThirdParty/Workers/draco_decoder.js' | ||
}).then(function () { | ||
DracoLoader._taskProcessorReady = true; | ||
}); | ||
DracoLoader._decoderTaskProcessor = processor; | ||
} | ||
|
||
return DracoLoader._decoderTaskProcessor; | ||
|
@@ -89,6 +99,11 @@ define([ | |
} | ||
|
||
function scheduleDecodingTask(decoderTaskProcessor, model, loadResources, context) { | ||
if (!DracoLoader._taskProcessorReady) { | ||
// The task processor is not ready to schedule tasks | ||
return; | ||
} | ||
|
||
var taskData = loadResources.primitivesToDecode.peek(); | ||
if (!defined(taskData)) { | ||
// All primitives are processing | ||
|
Large diffs are not rendered by default.
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.
Small typo:
to loading