Manually check if web gpu support is available (#1372)
* Manually check if web gpu support is available * Add web-sys features * Disable use of unstable apis for non wasm targets
This commit is contained in:
parent
48e3f7c54a
commit
5b6a74eb38
|
|
@ -77,6 +77,8 @@ features = [
|
|||
"CanvasRenderingContext2d",
|
||||
"ImageData",
|
||||
"Document",
|
||||
"Navigator",
|
||||
"Gpu",
|
||||
"HtmlCanvasElement",
|
||||
"ImageBitmapRenderingContext",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -40,11 +40,25 @@ pub struct WasmApplicationIo {
|
|||
|
||||
impl WasmApplicationIo {
|
||||
pub async fn new() -> Self {
|
||||
#[cfg(all(feature = "wgpu", target_arch = "wasm32"))]
|
||||
let executor = if let Some(gpu) = web_sys::window().map(|w| w.navigator().gpu()) {
|
||||
let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).unwrap();
|
||||
let function = js_sys::Function::try_from(&request_adapter).unwrap();
|
||||
let result = function.call0(&gpu);
|
||||
match result {
|
||||
Err(_) => None,
|
||||
Ok(_) => WgpuExecutor::new().await,
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
#[cfg(all(feature = "wgpu", not(target_arch = "wasm32")))]
|
||||
let executor = None;
|
||||
let mut io = Self {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
ids: RefCell::new(0),
|
||||
#[cfg(feature = "wgpu")]
|
||||
gpu_executor: WgpuExecutor::new().await,
|
||||
gpu_executor: executor,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
windows: RefCell::new(Vec::new()),
|
||||
resources: HashMap::new(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue