mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Implement device_features and adapter_features for the web backend (#2986)
* Implement device_features and adapter_features for the web backend * Use dyn_into instead * Same for device_features * Fix nit
This commit is contained in:
@@ -530,6 +530,42 @@ fn map_map_mode(mode: crate::MapMode) -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
const FEATURES_MAPPING: [(wgt::Features, web_sys::GpuFeatureName); 8] = [
|
||||
//TODO: update the name
|
||||
(
|
||||
wgt::Features::DEPTH_CLIP_CONTROL,
|
||||
web_sys::GpuFeatureName::DepthClipControl,
|
||||
),
|
||||
(
|
||||
wgt::Features::DEPTH32FLOAT_STENCIL8,
|
||||
web_sys::GpuFeatureName::Depth32floatStencil8,
|
||||
),
|
||||
(
|
||||
wgt::Features::TEXTURE_COMPRESSION_BC,
|
||||
web_sys::GpuFeatureName::TextureCompressionBc,
|
||||
),
|
||||
(
|
||||
wgt::Features::TEXTURE_COMPRESSION_ETC2,
|
||||
web_sys::GpuFeatureName::TextureCompressionEtc2,
|
||||
),
|
||||
(
|
||||
wgt::Features::TEXTURE_COMPRESSION_ASTC_LDR,
|
||||
web_sys::GpuFeatureName::TextureCompressionAstc,
|
||||
),
|
||||
(
|
||||
wgt::Features::TIMESTAMP_QUERY,
|
||||
web_sys::GpuFeatureName::TimestampQuery,
|
||||
),
|
||||
(
|
||||
wgt::Features::INDIRECT_FIRST_INSTANCE,
|
||||
web_sys::GpuFeatureName::IndirectFirstInstance,
|
||||
),
|
||||
(
|
||||
wgt::Features::SHADER_FLOAT16,
|
||||
web_sys::GpuFeatureName::ShaderF16,
|
||||
),
|
||||
];
|
||||
|
||||
type JsFutureResult = Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>;
|
||||
|
||||
fn future_request_adapter(result: JsFutureResult) -> Option<(Identified<web_sys::GpuAdapter>, ())> {
|
||||
@@ -840,8 +876,6 @@ impl crate::context::Context for Context {
|
||||
desc: &crate::DeviceDescriptor,
|
||||
trace_dir: Option<&std::path::Path>,
|
||||
) -> Self::RequestDeviceFuture {
|
||||
use web_sys::GpuFeatureName as Gfn;
|
||||
|
||||
if trace_dir.is_some() {
|
||||
//Error: Tracing isn't supported on the Web target
|
||||
}
|
||||
@@ -849,33 +883,7 @@ impl crate::context::Context for Context {
|
||||
// TODO: non-guaranteed limits
|
||||
let mut mapped_desc = web_sys::GpuDeviceDescriptor::new();
|
||||
|
||||
let possible_features = [
|
||||
//TODO: update the name
|
||||
(wgt::Features::DEPTH_CLIP_CONTROL, Gfn::DepthClipControl),
|
||||
(
|
||||
wgt::Features::DEPTH32FLOAT_STENCIL8,
|
||||
Gfn::Depth32floatStencil8,
|
||||
),
|
||||
(
|
||||
wgt::Features::TEXTURE_COMPRESSION_BC,
|
||||
Gfn::TextureCompressionBc,
|
||||
),
|
||||
(
|
||||
wgt::Features::TEXTURE_COMPRESSION_ETC2,
|
||||
Gfn::TextureCompressionEtc2,
|
||||
),
|
||||
(
|
||||
wgt::Features::TEXTURE_COMPRESSION_ASTC_LDR,
|
||||
Gfn::TextureCompressionAstc,
|
||||
),
|
||||
(wgt::Features::TIMESTAMP_QUERY, Gfn::TimestampQuery),
|
||||
(
|
||||
wgt::Features::INDIRECT_FIRST_INSTANCE,
|
||||
Gfn::IndirectFirstInstance,
|
||||
),
|
||||
(wgt::Features::SHADER_FLOAT16, Gfn::ShaderF16),
|
||||
];
|
||||
let required_features = possible_features
|
||||
let required_features = FEATURES_MAPPING
|
||||
.iter()
|
||||
.copied()
|
||||
.flat_map(|(flag, value)| {
|
||||
@@ -920,9 +928,23 @@ impl crate::context::Context for Context {
|
||||
adapter: &Self::AdapterId,
|
||||
_adapter_data: &Self::AdapterData,
|
||||
) -> wgt::Features {
|
||||
// TODO
|
||||
let _features = adapter.0.features();
|
||||
wgt::Features::empty()
|
||||
let features = adapter.0.features();
|
||||
|
||||
let features_set: js_sys::Set = features
|
||||
.dyn_into()
|
||||
.expect("adapter.features() is not setlike");
|
||||
|
||||
let mut features = wgt::Features::empty();
|
||||
|
||||
for (wgpu_feat, web_feat) in FEATURES_MAPPING {
|
||||
let value = wasm_bindgen::JsValue::from(web_feat);
|
||||
|
||||
if features_set.has(&value) {
|
||||
features |= wgpu_feat;
|
||||
}
|
||||
}
|
||||
|
||||
features
|
||||
}
|
||||
|
||||
fn adapter_limits(
|
||||
@@ -1078,11 +1100,26 @@ impl crate::context::Context for Context {
|
||||
|
||||
fn device_features(
|
||||
&self,
|
||||
_device: &Self::DeviceId,
|
||||
device: &Self::DeviceId,
|
||||
_device_data: &Self::DeviceData,
|
||||
) -> wgt::Features {
|
||||
// TODO
|
||||
wgt::Features::empty()
|
||||
let features = device.0.features();
|
||||
|
||||
let features_set: js_sys::Set = features
|
||||
.dyn_into()
|
||||
.expect("device.features() is not setlike");
|
||||
|
||||
let mut features = wgt::Features::empty();
|
||||
|
||||
for (wgpu_feat, web_feat) in FEATURES_MAPPING {
|
||||
let value = wasm_bindgen::JsValue::from(web_feat);
|
||||
|
||||
if features_set.has(&value) {
|
||||
features |= wgpu_feat;
|
||||
}
|
||||
}
|
||||
|
||||
features
|
||||
}
|
||||
|
||||
fn device_limits(
|
||||
|
||||
Reference in New Issue
Block a user