1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(op_crates/webgpu): create instance only when required (#9771)

Co-authored-by: Luca Casonato <lucacasonato@yahoo.com>
This commit is contained in:
crowlKats 2021-03-20 00:43:54 +01:00 committed by GitHub
parent 941a7c8ec9
commit 0f9c929b3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 16 deletions

View file

@ -198,7 +198,16 @@ pub async fn op_webgpu_request_adapter(
) -> Result<Value, AnyError> {
let mut state = state.borrow_mut();
check_unstable(&state, "navigator.gpu.requestAdapter");
let instance = state.borrow::<Instance>();
let instance = if let Some(instance) = state.try_borrow::<Instance>() {
instance
} else {
state.put(wgpu_core::hub::Global::new(
"webgpu",
wgpu_core::hub::IdentityManagerFactory,
wgpu_types::BackendBit::PRIMARY,
));
state.borrow::<Instance>()
};
let descriptor = wgpu_core::instance::RequestAdapterOptions {
power_preference: match args.power_preference {

View file

@ -4,11 +4,6 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
{
let op_state = rt.op_state();
let mut state = op_state.borrow_mut();
state.put(wgpu_core::hub::Global::new(
"webgpu",
wgpu_core::hub::IdentityManagerFactory,
wgpu_types::BackendBit::PRIMARY,
));
let unstable_checker = state.borrow::<super::UnstableChecker>();
let unstable = unstable_checker.unstable;
state.put(Unstable(unstable));