aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gpuadapter.rs
diff options
context:
space:
mode:
authorSamson <16504129+sagudev@users.noreply.github.com>2023-08-21 01:16:46 +0200
committerGitHub <noreply@github.com>2023-08-20 23:16:46 +0000
commit71e0372ac18709da66e581cf4a777a7cc5d4cb92 (patch)
tree44907b543dcc822fe20025b2ac417da6e2b7c908 /components/script/dom/gpuadapter.rs
parentfed3491f23f8b7f3064ce297776deda76e485289 (diff)
downloadservo-71e0372ac18709da66e581cf4a777a7cc5d4cb92.tar.gz
servo-71e0372ac18709da66e581cf4a777a7cc5d4cb92.zip
Upgrade whole webgpu stack (#29795)
* Allow noidl files in script/dom/webidls * Upgrade wgpu to 0.16 and refresh whole webgpu implementation * Update WebGPU test expectations * misc * MutNullableDom -> DomRefCell<Option<Dom for GPUTexture * Direct use of GPUTextureDescriptor * Remove config from GPUCanvasContext * misc * finally blue color * gpubuffer "handle" error * GPU object have non-null label * gpu limits and info * use buffer_size * fix warnings * Cleanup * device destroy * fallback adapter * mach update-webgpu write webgpu commit hash in file * Mising deps in CI for webgpu tests * Updated expectations * Fixups * early reject * DomRefCell<Option<Dom -> MutNullableDom for GPUTexture
Diffstat (limited to 'components/script/dom/gpuadapter.rs')
-rw-r--r--components/script/dom/gpuadapter.rs217
1 files changed, 144 insertions, 73 deletions
diff --git a/components/script/dom/gpuadapter.rs b/components/script/dom/gpuadapter.rs
index e87f0589c51..db5be259375 100644
--- a/components/script/dom/gpuadapter.rs
+++ b/components/script/dom/gpuadapter.rs
@@ -3,11 +3,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::{
- GPUAdapterMethods, GPUDeviceDescriptor, GPUExtensionName, GPULimits,
+ GPUAdapterMethods, GPUDeviceDescriptor, GPUFeatureName,
};
use crate::dom::bindings::error::Error;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
-use crate::dom::bindings::root::DomRoot;
+use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpu::response_async;
@@ -15,13 +15,14 @@ use crate::dom::gpu::AsyncWGPUListener;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::promise::Promise;
use crate::realms::InRealm;
-use crate::script_runtime::JSContext as SafeJSContext;
use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
-use std::ptr::NonNull;
+use std::convert::TryFrom;
use std::rc::Rc;
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse, WebGPUResponseResult};
+use super::types::{GPUAdapterInfo, GPUSupportedLimits};
+
#[dom_struct]
pub struct GPUAdapter {
reflector_: Reflector,
@@ -31,6 +32,8 @@ pub struct GPUAdapter {
name: DOMString,
#[ignore_malloc_size_of = "mozjs"]
extensions: Heap<*mut JSObject>,
+ limits: Dom<GPUSupportedLimits>,
+ info: Dom<GPUAdapterInfo>,
#[no_trace]
adapter: WebGPUAdapter,
}
@@ -40,6 +43,8 @@ impl GPUAdapter {
channel: WebGPU,
name: DOMString,
extensions: Heap<*mut JSObject>,
+ limits: &GPUSupportedLimits,
+ info: &GPUAdapterInfo,
adapter: WebGPUAdapter,
) -> Self {
Self {
@@ -47,6 +52,8 @@ impl GPUAdapter {
channel,
name,
extensions,
+ limits: Dom::from_ref(limits),
+ info: Dom::from_ref(info),
adapter,
}
}
@@ -56,11 +63,15 @@ impl GPUAdapter {
channel: WebGPU,
name: DOMString,
extensions: Heap<*mut JSObject>,
+ limits: wgt::Limits,
+ info: wgt::AdapterInfo,
adapter: WebGPUAdapter,
) -> DomRoot<Self> {
+ let limits = GPUSupportedLimits::new(global, limits);
+ let info = GPUAdapterInfo::new(global, info);
reflect_dom_object(
Box::new(GPUAdapter::new_inherited(
- channel, name, extensions, adapter,
+ channel, name, extensions, &limits, &info, adapter,
)),
global,
)
@@ -68,57 +79,116 @@ impl GPUAdapter {
}
impl GPUAdapterMethods for GPUAdapter {
- // https://gpuweb.github.io/gpuweb/#dom-gpuadapter-name
- fn Name(&self) -> DOMString {
- self.name.clone()
- }
-
- // https://gpuweb.github.io/gpuweb/#dom-gpuadapter-extensions
- fn Extensions(&self, _cx: SafeJSContext) -> NonNull<JSObject> {
- NonNull::new(self.extensions.get()).unwrap()
- }
-
/// https://gpuweb.github.io/gpuweb/#dom-gpuadapter-requestdevice
fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InRealm) -> Rc<Promise> {
+ // Step 2
let promise = Promise::new_in_current_realm(comp);
let sender = response_async(&promise, self);
let mut features = wgt::Features::empty();
- for &ext in descriptor.extensions.iter() {
- if ext == GPUExtensionName::Depth_clamping {
- features.insert(wgt::Features::DEPTH_CLAMPING);
- } else if ext == GPUExtensionName::Texture_compression_bc {
- features.insert(wgt::Features::TEXTURE_COMPRESSION_BC)
+ for &ext in descriptor.requiredFeatures.iter() {
+ match ext {
+ GPUFeatureName::Depth_clip_control => {
+ features.insert(wgt::Features::DEPTH_CLIP_CONTROL)
+ },
+ GPUFeatureName::Depth24unorm_stencil8 => {
+ promise.reject_error(Error::Type(String::from(
+ "depth24unorm_stencil8 is not supported by wgpu",
+ )));
+ return promise;
+ },
+ GPUFeatureName::Depth32float_stencil8 => {
+ features.insert(wgt::Features::DEPTH32FLOAT_STENCIL8)
+ },
+ GPUFeatureName::Pipeline_statistics_query => {
+ features.insert(wgt::Features::PIPELINE_STATISTICS_QUERY)
+ },
+ GPUFeatureName::Texture_compression_bc => {
+ features.insert(wgt::Features::TEXTURE_COMPRESSION_BC)
+ },
+ GPUFeatureName::Texture_compression_etc2 => {
+ features.insert(wgt::Features::TEXTURE_COMPRESSION_ETC2)
+ },
+ GPUFeatureName::Texture_compression_astc => {
+ features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC)
+ },
+ GPUFeatureName::Timestamp_query => features.insert(wgt::Features::TIMESTAMP_QUERY),
+ GPUFeatureName::Indirect_first_instance => {
+ features.insert(wgt::Features::INDIRECT_FIRST_INSTANCE)
+ },
}
}
- let desc = wgt::DeviceDescriptor {
+ let mut desc = wgt::DeviceDescriptor {
features,
- limits: wgt::Limits {
- max_bind_groups: descriptor.limits.maxBindGroups,
- max_dynamic_uniform_buffers_per_pipeline_layout: descriptor
- .limits
- .maxDynamicUniformBuffersPerPipelineLayout,
- max_dynamic_storage_buffers_per_pipeline_layout: descriptor
- .limits
- .maxDynamicStorageBuffersPerPipelineLayout,
- max_sampled_textures_per_shader_stage: descriptor
- .limits
- .maxSampledTexturesPerShaderStage,
- max_samplers_per_shader_stage: descriptor.limits.maxSamplersPerShaderStage,
- max_storage_buffers_per_shader_stage: descriptor
- .limits
- .maxStorageBuffersPerShaderStage,
- max_storage_textures_per_shader_stage: descriptor
- .limits
- .maxStorageTexturesPerShaderStage,
- max_uniform_buffers_per_shader_stage: descriptor
- .limits
- .maxUniformBuffersPerShaderStage,
- max_uniform_buffer_binding_size: descriptor.limits.maxUniformBufferBindingSize,
- ..Default::default()
- },
- shader_validation: true,
+ limits: wgt::Limits::default(),
+ label: None,
};
+ if let Some(lim) = &descriptor.requiredLimits {
+ for (k, v) in (*lim).iter() {
+ let v = u32::try_from(*v).unwrap_or(u32::MAX);
+ match k.as_ref() {
+ "maxTextureDimension1D" => desc.limits.max_texture_dimension_1d = v,
+ "maxTextureDimension2D" => desc.limits.max_texture_dimension_2d = v,
+ "maxTextureDimension3D" => desc.limits.max_texture_dimension_3d = v,
+ "maxTextureArrayLayers" => desc.limits.max_texture_array_layers = v,
+ "maxBindGroups" => desc.limits.max_bind_groups = v,
+ "maxDynamicUniformBuffersPerPipelineLayout" => {
+ desc.limits.max_dynamic_uniform_buffers_per_pipeline_layout = v
+ },
+ "maxDynamicStorageBuffersPerPipelineLayout" => {
+ desc.limits.max_dynamic_storage_buffers_per_pipeline_layout = v
+ },
+ "maxSampledTexturesPerShaderStage" => {
+ desc.limits.max_sampled_textures_per_shader_stage = v
+ },
+ "maxSamplersPerShaderStage" => desc.limits.max_samplers_per_shader_stage = v,
+ "maxStorageBuffersPerShaderStage" => {
+ desc.limits.max_storage_buffers_per_shader_stage = v
+ },
+ "maxStorageTexturesPerShaderStage" => {
+ desc.limits.max_storage_textures_per_shader_stage = v
+ },
+ "maxUniformBuffersPerShaderStage" => {
+ desc.limits.max_uniform_buffers_per_shader_stage = v
+ },
+ "maxUniformBufferBindingSize" => {
+ desc.limits.max_uniform_buffer_binding_size = v
+ },
+ "maxStorageBufferBindingSize" => {
+ desc.limits.max_storage_buffer_binding_size = v
+ },
+ "minUniformBufferOffsetAlignment" => {
+ desc.limits.min_uniform_buffer_offset_alignment = v
+ },
+ "minStorageBufferOffsetAlignment" => {
+ desc.limits.min_storage_buffer_offset_alignment = v
+ },
+ "maxVertexBuffers" => desc.limits.max_vertex_buffers = v,
+ "maxVertexAttributes" => desc.limits.max_vertex_attributes = v,
+ "maxVertexBufferArrayStride" => desc.limits.max_vertex_buffer_array_stride = v,
+ "maxInterStageShaderComponents" => {
+ desc.limits.max_inter_stage_shader_components = v
+ },
+ "maxComputeWorkgroupStorageSize" => {
+ desc.limits.max_compute_workgroup_storage_size = v
+ },
+ "maxComputeInvocationsPerWorkgroup" => {
+ desc.limits.max_compute_invocations_per_workgroup = v
+ },
+ "maxComputeWorkgroupSizeX" => desc.limits.max_compute_workgroup_size_x = v,
+ "maxComputeWorkgroupSizeY" => desc.limits.max_compute_workgroup_size_y = v,
+ "maxComputeWorkgroupSizeZ" => desc.limits.max_compute_workgroup_size_z = v,
+ "maxComputeWorkgroupsPerDimension" => {
+ desc.limits.max_compute_workgroups_per_dimension = v
+ },
+ _ => {
+ error!("Unknown required limit: {k} with value {v}");
+ promise.reject_error(Error::Operation);
+ return promise;
+ },
+ }
+ }
+ }
let id = self
.global()
.wgpu_id_hub()
@@ -136,15 +206,40 @@ impl GPUAdapterMethods for GPUAdapter {
descriptor: desc,
device_id: id,
pipeline_id,
- label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
},
))
.is_err()
{
promise.reject_error(Error::Operation);
}
+ // Step 5
+ promise
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuadapter-isfallbackadapter
+ fn IsFallbackAdapter(&self) -> bool {
+ //TODO
+ false
+ }
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpuadapter-requestadapterinfo
+ fn RequestAdapterInfo(&self, unmask_hints: Vec<DOMString>, comp: InRealm) -> Rc<Promise> {
+ // XXX: Adapter info should be generated here ...
+ // Step 1
+ let promise = Promise::new_in_current_realm(comp);
+ // Step 4
+ if !unmask_hints.is_empty() {
+ todo!("unmaskHints on RequestAdapterInfo");
+ }
+ promise.resolve_native(&*self.info);
+ // Step 5
promise
}
+
+ /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-limits
+ fn Limits(&self) -> DomRoot<GPUSupportedLimits> {
+ DomRoot::from_ref(&self.limits)
+ }
}
impl AsyncWGPUListener for GPUAdapter {
@@ -154,40 +249,16 @@ impl AsyncWGPUListener for GPUAdapter {
device_id,
queue_id,
descriptor,
- label,
}) => {
- let limits = GPULimits {
- maxBindGroups: descriptor.limits.max_bind_groups,
- maxDynamicStorageBuffersPerPipelineLayout: descriptor
- .limits
- .max_dynamic_storage_buffers_per_pipeline_layout,
- maxDynamicUniformBuffersPerPipelineLayout: descriptor
- .limits
- .max_dynamic_uniform_buffers_per_pipeline_layout,
- maxSampledTexturesPerShaderStage: descriptor
- .limits
- .max_sampled_textures_per_shader_stage,
- maxSamplersPerShaderStage: descriptor.limits.max_samplers_per_shader_stage,
- maxStorageBuffersPerShaderStage: descriptor
- .limits
- .max_storage_buffers_per_shader_stage,
- maxStorageTexturesPerShaderStage: descriptor
- .limits
- .max_storage_textures_per_shader_stage,
- maxUniformBufferBindingSize: descriptor.limits.max_uniform_buffer_binding_size,
- maxUniformBuffersPerShaderStage: descriptor
- .limits
- .max_uniform_buffers_per_shader_stage,
- };
let device = GPUDevice::new(
&self.global(),
self.channel.clone(),
&self,
Heap::default(),
- limits,
+ descriptor.limits,
device_id,
queue_id,
- label,
+ descriptor.label.unwrap_or_default(),
);
self.global().add_gpu_device(&device);
promise.resolve_native(&device);