mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Use Device limits and features provided by user
Spec update
This commit is contained in:
parent
cd73193efe
commit
3661aa3d8c
16 changed files with 210 additions and 57 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -7044,7 +7044,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "wgpu-core"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#d423d3d5d7cb7e21e5277628681a1a9dc1715c8e"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#e72724a6e393503c73f37e86aa9317a5c62e32b8"
|
||||
dependencies = [
|
||||
"arrayvec 0.5.1",
|
||||
"bitflags",
|
||||
|
@ -7072,7 +7072,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "wgpu-types"
|
||||
version = "0.6.0"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#d423d3d5d7cb7e21e5277628681a1a9dc1715c8e"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#e72724a6e393503c73f37e86aa9317a5c62e32b8"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"serde",
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::{
|
||||
GPUAdapterMethods, GPUDeviceDescriptor,
|
||||
GPUAdapterMethods, GPUDeviceDescriptor, GPUExtensionName, GPULimits,
|
||||
};
|
||||
use crate::dom::bindings::error::Error;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
|
@ -80,10 +80,39 @@ impl GPUAdapterMethods for GPUAdapter {
|
|||
fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InRealm) -> Rc<Promise> {
|
||||
let promise = Promise::new_in_current_realm(&self.global(), 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)
|
||||
}
|
||||
}
|
||||
|
||||
let desc = wgt::DeviceDescriptor {
|
||||
features: wgt::Features::empty(),
|
||||
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,
|
||||
|
@ -122,15 +151,38 @@ impl AsyncWGPUListener for GPUAdapter {
|
|||
Ok(WebGPUResponse::RequestDevice {
|
||||
device_id,
|
||||
queue_id,
|
||||
_descriptor,
|
||||
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(),
|
||||
Heap::default(),
|
||||
limits,
|
||||
device_id,
|
||||
queue_id,
|
||||
label,
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::GPULimits;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUComputePipelineBinding::GPUComputePipelineMethods;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
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::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
|
||||
use crate::dom::gpudevice::GPUDevice;
|
||||
use dom_struct::dom_struct;
|
||||
use std::string::String;
|
||||
use webgpu::{WebGPUBindGroupLayout, WebGPUComputePipeline};
|
||||
|
@ -21,6 +21,7 @@ pub struct GPUComputePipeline {
|
|||
label: DomRefCell<Option<USVString>>,
|
||||
compute_pipeline: WebGPUComputePipeline,
|
||||
bind_group_layouts: Vec<WebGPUBindGroupLayout>,
|
||||
device: Dom<GPUDevice>,
|
||||
}
|
||||
|
||||
impl GPUComputePipeline {
|
||||
|
@ -28,12 +29,14 @@ impl GPUComputePipeline {
|
|||
compute_pipeline: WebGPUComputePipeline,
|
||||
label: Option<USVString>,
|
||||
bgls: Vec<WebGPUBindGroupLayout>,
|
||||
device: &GPUDevice,
|
||||
) -> Self {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
label: DomRefCell::new(label),
|
||||
compute_pipeline,
|
||||
bind_group_layouts: bgls,
|
||||
device: Dom::from_ref(device),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,12 +45,14 @@ impl GPUComputePipeline {
|
|||
compute_pipeline: WebGPUComputePipeline,
|
||||
label: Option<USVString>,
|
||||
bgls: Vec<WebGPUBindGroupLayout>,
|
||||
device: &GPUDevice,
|
||||
) -> DomRoot<Self> {
|
||||
reflect_dom_object(
|
||||
Box::new(GPUComputePipeline::new_inherited(
|
||||
compute_pipeline,
|
||||
label,
|
||||
bgls,
|
||||
device,
|
||||
)),
|
||||
global,
|
||||
)
|
||||
|
@ -73,7 +78,8 @@ impl GPUComputePipelineMethods for GPUComputePipeline {
|
|||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpupipelinebase-getbindgrouplayout
|
||||
fn GetBindGroupLayout(&self, index: u32) -> Fallible<DomRoot<GPUBindGroupLayout>> {
|
||||
if index > self.bind_group_layouts.len() as u32 || index > GPULimits::empty().maxBindGroups
|
||||
if index > self.bind_group_layouts.len() as u32 ||
|
||||
index > self.device.limits().maxBindGroups
|
||||
{
|
||||
return Err(Error::Range(String::from("Index out of bounds")));
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ use js::jsapi::{Heap, JSObject};
|
|||
use std::borrow::Cow;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::ptr::NonNull;
|
||||
use std::ptr::{self, NonNull};
|
||||
use std::rc::Rc;
|
||||
use webgpu::wgpu::{
|
||||
binding_model as wgpu_bind, command as wgpu_com,
|
||||
|
@ -112,8 +112,8 @@ pub struct GPUDevice {
|
|||
adapter: Dom<GPUAdapter>,
|
||||
#[ignore_malloc_size_of = "mozjs"]
|
||||
extensions: Heap<*mut JSObject>,
|
||||
#[ignore_malloc_size_of = "mozjs"]
|
||||
limits: Heap<*mut JSObject>,
|
||||
#[ignore_malloc_size_of = "Because it is non-owning"]
|
||||
limits: GPULimits,
|
||||
label: DomRefCell<Option<USVString>>,
|
||||
device: webgpu::WebGPUDevice,
|
||||
default_queue: Dom<GPUQueue>,
|
||||
|
@ -127,7 +127,7 @@ impl GPUDevice {
|
|||
channel: WebGPU,
|
||||
adapter: &GPUAdapter,
|
||||
extensions: Heap<*mut JSObject>,
|
||||
limits: Heap<*mut JSObject>,
|
||||
limits: GPULimits,
|
||||
device: webgpu::WebGPUDevice,
|
||||
queue: &GPUQueue,
|
||||
label: Option<String>,
|
||||
|
@ -155,7 +155,7 @@ impl GPUDevice {
|
|||
channel: WebGPU,
|
||||
adapter: &GPUAdapter,
|
||||
extensions: Heap<*mut JSObject>,
|
||||
limits: Heap<*mut JSObject>,
|
||||
limits: GPULimits,
|
||||
device: webgpu::WebGPUDevice,
|
||||
queue: webgpu::WebGPUQueue,
|
||||
label: Option<String>,
|
||||
|
@ -177,6 +177,10 @@ impl GPUDevice {
|
|||
self.device
|
||||
}
|
||||
|
||||
pub fn limits(&self) -> &GPULimits {
|
||||
&self.limits
|
||||
}
|
||||
|
||||
pub fn handle_server_msg(&self, scope: Option<ErrorScopeId>, result: WebGPUOpResult) {
|
||||
let result = match result {
|
||||
WebGPUOpResult::Success => Ok(()),
|
||||
|
@ -299,7 +303,7 @@ impl GPUDevice {
|
|||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_pipeline_layout_id(self.device.0.backend());
|
||||
let max_bind_grps = GPULimits::empty().maxBindGroups;
|
||||
let max_bind_grps = self.limits.maxBindGroups;
|
||||
let mut bgls = Vec::with_capacity(max_bind_grps as usize);
|
||||
let mut bgl_ids = Vec::with_capacity(max_bind_grps as usize);
|
||||
for _ in 0..max_bind_grps {
|
||||
|
@ -328,8 +332,12 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-limits
|
||||
fn Limits(&self, _cx: SafeJSContext) -> NonNull<JSObject> {
|
||||
NonNull::new(self.extensions.get()).unwrap()
|
||||
fn Limits(&self, cx: SafeJSContext) -> NonNull<JSObject> {
|
||||
rooted!(in (*cx) let mut limits = ptr::null_mut::<JSObject>());
|
||||
unsafe {
|
||||
self.limits.to_jsobject(*cx, limits.handle_mut());
|
||||
}
|
||||
NonNull::new(limits.get()).unwrap()
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-defaultqueue
|
||||
|
@ -439,17 +447,17 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
};
|
||||
let ty = match bind.type_ {
|
||||
GPUBindingType::Uniform_buffer => wgt::BindingType::UniformBuffer {
|
||||
dynamic: bind.hasDynamicOffset,
|
||||
min_binding_size: wgt::BufferSize::new(bind.minBufferBindingSize),
|
||||
dynamic: bind.hasDynamicOffset.unwrap_or(false),
|
||||
min_binding_size: bind.minBufferBindingSize.and_then(wgt::BufferSize::new),
|
||||
},
|
||||
GPUBindingType::Storage_buffer => wgt::BindingType::StorageBuffer {
|
||||
dynamic: bind.hasDynamicOffset,
|
||||
min_binding_size: wgt::BufferSize::new(bind.minBufferBindingSize),
|
||||
dynamic: bind.hasDynamicOffset.unwrap_or(false),
|
||||
min_binding_size: bind.minBufferBindingSize.and_then(wgt::BufferSize::new),
|
||||
readonly: false,
|
||||
},
|
||||
GPUBindingType::Readonly_storage_buffer => wgt::BindingType::StorageBuffer {
|
||||
dynamic: bind.hasDynamicOffset,
|
||||
min_binding_size: wgt::BufferSize::new(bind.minBufferBindingSize),
|
||||
dynamic: bind.hasDynamicOffset.unwrap_or(false),
|
||||
min_binding_size: bind.minBufferBindingSize.and_then(wgt::BufferSize::new),
|
||||
readonly: true,
|
||||
},
|
||||
GPUBindingType::Sampled_texture => wgt::BindingType::SampledTexture {
|
||||
|
@ -458,16 +466,17 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.map_or(wgt::TextureViewDimension::D2, |v| {
|
||||
convert_texture_view_dimension(v)
|
||||
}),
|
||||
component_type: if let Some(c) = bind.textureComponentType {
|
||||
match c {
|
||||
GPUTextureComponentType::Float => wgt::TextureComponentType::Float,
|
||||
GPUTextureComponentType::Sint => wgt::TextureComponentType::Sint,
|
||||
GPUTextureComponentType::Uint => wgt::TextureComponentType::Uint,
|
||||
}
|
||||
} else {
|
||||
wgt::TextureComponentType::Float
|
||||
component_type: convert_texture_component_type(bind.textureComponentType),
|
||||
multisampled: false,
|
||||
},
|
||||
multisampled: bind.multisampled,
|
||||
GPUBindingType::Multisampled_texture => wgt::BindingType::SampledTexture {
|
||||
dimension: bind
|
||||
.viewDimension
|
||||
.map_or(wgt::TextureViewDimension::D2, |v| {
|
||||
convert_texture_view_dimension(v)
|
||||
}),
|
||||
component_type: convert_texture_component_type(bind.textureComponentType),
|
||||
multisampled: true,
|
||||
},
|
||||
GPUBindingType::Readonly_storage_texture => wgt::BindingType::StorageTexture {
|
||||
dimension: bind
|
||||
|
@ -742,6 +751,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
compute_pipeline,
|
||||
descriptor.parent.parent.label.as_ref().cloned(),
|
||||
bgls,
|
||||
&self,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1048,6 +1058,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
render_pipeline,
|
||||
descriptor.parent.parent.label.as_ref().cloned(),
|
||||
bgls,
|
||||
&self,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1273,7 +1284,6 @@ pub fn convert_texture_format(format: GPUTextureFormat) -> wgt::TextureFormat {
|
|||
GPUTextureFormat::Bgra8unorm => wgt::TextureFormat::Bgra8Unorm,
|
||||
GPUTextureFormat::Bgra8unorm_srgb => wgt::TextureFormat::Bgra8UnormSrgb,
|
||||
GPUTextureFormat::Rgb10a2unorm => wgt::TextureFormat::Rgb10a2Unorm,
|
||||
GPUTextureFormat::Rg11b10float => wgt::TextureFormat::Rg11b10Float,
|
||||
GPUTextureFormat::Rg32uint => wgt::TextureFormat::Rg32Uint,
|
||||
GPUTextureFormat::Rg32sint => wgt::TextureFormat::Rg32Sint,
|
||||
GPUTextureFormat::Rg32float => wgt::TextureFormat::Rg32Float,
|
||||
|
@ -1286,6 +1296,34 @@ pub fn convert_texture_format(format: GPUTextureFormat) -> wgt::TextureFormat {
|
|||
GPUTextureFormat::Depth32float => wgt::TextureFormat::Depth32Float,
|
||||
GPUTextureFormat::Depth24plus => wgt::TextureFormat::Depth24Plus,
|
||||
GPUTextureFormat::Depth24plus_stencil8 => wgt::TextureFormat::Depth24PlusStencil8,
|
||||
GPUTextureFormat::Bc1_rgba_unorm => wgt::TextureFormat::Bc1RgbaUnorm,
|
||||
GPUTextureFormat::Bc1_rgba_unorm_srgb => wgt::TextureFormat::Bc1RgbaUnormSrgb,
|
||||
GPUTextureFormat::Bc2_rgba_unorm => wgt::TextureFormat::Bc2RgbaUnorm,
|
||||
GPUTextureFormat::Bc2_rgba_unorm_srgb => wgt::TextureFormat::Bc2RgbaUnormSrgb,
|
||||
GPUTextureFormat::Bc3_rgba_unorm => wgt::TextureFormat::Bc3RgbaUnorm,
|
||||
GPUTextureFormat::Bc3_rgba_unorm_srgb => wgt::TextureFormat::Bc3RgbaUnormSrgb,
|
||||
GPUTextureFormat::Bc4_r_unorm => wgt::TextureFormat::Bc4RUnorm,
|
||||
GPUTextureFormat::Bc4_r_snorm => wgt::TextureFormat::Bc4RSnorm,
|
||||
GPUTextureFormat::Bc5_rg_unorm => wgt::TextureFormat::Bc5RgUnorm,
|
||||
GPUTextureFormat::Bc5_rg_snorm => wgt::TextureFormat::Bc5RgSnorm,
|
||||
GPUTextureFormat::Bc6h_rgb_ufloat => wgt::TextureFormat::Bc6hRgbUfloat,
|
||||
GPUTextureFormat::Bc7_rgba_unorm => wgt::TextureFormat::Bc7RgbaUnorm,
|
||||
GPUTextureFormat::Bc7_rgba_unorm_srgb => wgt::TextureFormat::Bc7RgbaUnormSrgb,
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_texture_component_type(
|
||||
ty: Option<GPUTextureComponentType>,
|
||||
) -> wgt::TextureComponentType {
|
||||
if let Some(c) = ty {
|
||||
match c {
|
||||
GPUTextureComponentType::Float => wgt::TextureComponentType::Float,
|
||||
GPUTextureComponentType::Sint => wgt::TextureComponentType::Sint,
|
||||
GPUTextureComponentType::Uint => wgt::TextureComponentType::Uint,
|
||||
GPUTextureComponentType::Depth_comparison => wgt::TextureComponentType::DepthComparison,
|
||||
}
|
||||
} else {
|
||||
wgt::TextureComponentType::Float
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use crate::dom::bindings::codegen::Bindings::GPUCommandEncoderBinding::{
|
|||
};
|
||||
use crate::dom::bindings::codegen::Bindings::GPUQueueBinding::GPUQueueMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUTextureBinding::GPUExtent3D;
|
||||
use crate::dom::bindings::codegen::UnionTypes::ArrayBufferViewOrArrayBuffer as BufferSource;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
|
@ -20,8 +21,6 @@ use crate::dom::gpucommandencoder::{convert_texture_cv, convert_texture_data_lay
|
|||
use crate::dom::gpudevice::{convert_texture_size_to_dict, convert_texture_size_to_wgt, GPUDevice};
|
||||
use dom_struct::dom_struct;
|
||||
use ipc_channel::ipc::IpcSharedMemory;
|
||||
use js::rust::CustomAutoRooterGuard;
|
||||
use js::typedarray::ArrayBuffer;
|
||||
use webgpu::{identity::WebGPUOpResult, wgt, WebGPU, WebGPUQueue, WebGPURequest};
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -104,11 +103,14 @@ impl GPUQueueMethods for GPUQueue {
|
|||
&self,
|
||||
buffer: &GPUBuffer,
|
||||
buffer_offset: GPUSize64,
|
||||
data: CustomAutoRooterGuard<ArrayBuffer>,
|
||||
data: BufferSource,
|
||||
data_offset: GPUSize64,
|
||||
size: Option<GPUSize64>,
|
||||
) -> Fallible<()> {
|
||||
let bytes = data.to_vec();
|
||||
let bytes = match data {
|
||||
BufferSource::ArrayBufferView(d) => d.to_vec(),
|
||||
BufferSource::ArrayBuffer(d) => d.to_vec(),
|
||||
};
|
||||
let content_size = if let Some(s) = size {
|
||||
s
|
||||
} else {
|
||||
|
@ -146,12 +148,15 @@ impl GPUQueueMethods for GPUQueue {
|
|||
fn WriteTexture(
|
||||
&self,
|
||||
destination: &GPUTextureCopyView,
|
||||
data: CustomAutoRooterGuard<ArrayBuffer>,
|
||||
data: BufferSource,
|
||||
data_layout: &GPUTextureDataLayout,
|
||||
size: GPUExtent3D,
|
||||
) -> Fallible<()> {
|
||||
let bytes = data.to_vec();
|
||||
let valid = data_layout.offset <= data.len() as u64;
|
||||
let (bytes, len) = match data {
|
||||
BufferSource::ArrayBufferView(d) => (d.to_vec(), d.len() as u64),
|
||||
BufferSource::ArrayBuffer(d) => (d.to_vec(), d.len() as u64),
|
||||
};
|
||||
let valid = data_layout.offset <= len;
|
||||
|
||||
if !valid {
|
||||
return Err(Error::Operation);
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::GPULimits;
|
||||
use crate::dom::bindings::codegen::Bindings::GPURenderPipelineBinding::GPURenderPipelineMethods;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
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::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
|
||||
use crate::dom::gpudevice::GPUDevice;
|
||||
use dom_struct::dom_struct;
|
||||
use std::string::String;
|
||||
use webgpu::{WebGPUBindGroupLayout, WebGPURenderPipeline};
|
||||
|
@ -21,6 +21,7 @@ pub struct GPURenderPipeline {
|
|||
label: DomRefCell<Option<USVString>>,
|
||||
render_pipeline: WebGPURenderPipeline,
|
||||
bind_group_layouts: Vec<WebGPUBindGroupLayout>,
|
||||
device: Dom<GPUDevice>,
|
||||
}
|
||||
|
||||
impl GPURenderPipeline {
|
||||
|
@ -28,12 +29,14 @@ impl GPURenderPipeline {
|
|||
render_pipeline: WebGPURenderPipeline,
|
||||
label: Option<USVString>,
|
||||
bgls: Vec<WebGPUBindGroupLayout>,
|
||||
device: &GPUDevice,
|
||||
) -> Self {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
label: DomRefCell::new(label),
|
||||
render_pipeline,
|
||||
bind_group_layouts: bgls,
|
||||
device: Dom::from_ref(device),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,12 +45,14 @@ impl GPURenderPipeline {
|
|||
render_pipeline: WebGPURenderPipeline,
|
||||
label: Option<USVString>,
|
||||
bgls: Vec<WebGPUBindGroupLayout>,
|
||||
device: &GPUDevice,
|
||||
) -> DomRoot<Self> {
|
||||
reflect_dom_object(
|
||||
Box::new(GPURenderPipeline::new_inherited(
|
||||
render_pipeline,
|
||||
label,
|
||||
bgls,
|
||||
device,
|
||||
)),
|
||||
global,
|
||||
)
|
||||
|
@ -73,7 +78,8 @@ impl GPURenderPipelineMethods for GPURenderPipeline {
|
|||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpupipelinebase-getbindgrouplayout
|
||||
fn GetBindGroupLayout(&self, index: u32) -> Fallible<DomRoot<GPUBindGroupLayout>> {
|
||||
if index > self.bind_group_layouts.len() as u32 || index > GPULimits::empty().maxBindGroups
|
||||
if index > self.bind_group_layouts.len() as u32 ||
|
||||
index > self.device.limits().maxBindGroups
|
||||
{
|
||||
return Err(Error::Range(String::from("Index out of bounds")));
|
||||
}
|
||||
|
|
|
@ -18,8 +18,12 @@ dictionary GPUDeviceDescriptor : GPUObjectDescriptorBase {
|
|||
};
|
||||
|
||||
enum GPUExtensionName {
|
||||
"depth-clamping",
|
||||
"depth24unorm-stencil8",
|
||||
"depth32float-stencil8",
|
||||
"pipeline-statistics-query",
|
||||
"texture-compression-bc",
|
||||
"pipeline-statistics-query"
|
||||
"timestamp-query",
|
||||
};
|
||||
|
||||
dictionary GPULimits {
|
||||
|
|
|
@ -16,11 +16,10 @@ dictionary GPUBindGroupLayoutEntry {
|
|||
required GPUIndex32 binding;
|
||||
required GPUShaderStageFlags visibility;
|
||||
required GPUBindingType type;
|
||||
boolean hasDynamicOffset = false;
|
||||
GPUSize64 minBufferBindingSize = 0;
|
||||
boolean hasDynamicOffset;
|
||||
GPUSize64 minBufferBindingSize;
|
||||
GPUTextureViewDimension viewDimension;
|
||||
GPUTextureComponentType textureComponentType;
|
||||
boolean multisampled = false;
|
||||
GPUTextureFormat storageTextureFormat;
|
||||
};
|
||||
|
||||
|
@ -31,6 +30,7 @@ enum GPUBindingType {
|
|||
"sampler",
|
||||
"comparison-sampler",
|
||||
"sampled-texture",
|
||||
"multisampled-texture",
|
||||
"readonly-storage-texture",
|
||||
"writeonly-storage-texture"
|
||||
};
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
// https://gpuweb.github.io/gpuweb/#gpucommandbuffer
|
||||
[Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"]
|
||||
interface GPUCommandBuffer {
|
||||
//readonly attribute Promise<double> executionTime;
|
||||
};
|
||||
GPUCommandBuffer includes GPUObjectBase;
|
||||
|
|
|
@ -9,6 +9,11 @@ interface GPUComputePassEncoder {
|
|||
void dispatch(GPUSize32 x, optional GPUSize32 y = 1, optional GPUSize32 z = 1);
|
||||
void dispatchIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
|
||||
|
||||
//void beginPipelineStatisticsQuery(GPUQuerySet querySet, GPUSize32 queryIndex);
|
||||
//void endPipelineStatisticsQuery();
|
||||
|
||||
//void writeTimestamp(GPUQuerySet querySet, GPUSize32 queryIndex);
|
||||
|
||||
void endPass();
|
||||
};
|
||||
GPUComputePassEncoder includes GPUObjectBase;
|
||||
|
|
|
@ -22,11 +22,16 @@ interface GPUDevice : EventTarget {
|
|||
GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor);
|
||||
GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor);
|
||||
GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);
|
||||
//Promise<GPUComputePipeline> createReadyComputePipeline(GPUComputePipelineDescriptor descriptor);
|
||||
//Promise<GPURenderPipeline> createReadyRenderPipeline(GPURenderPipelineDescriptor descriptor);
|
||||
|
||||
GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {});
|
||||
GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
|
||||
|
||||
//GPUQuerySet createQuerySet(GPUQuerySetDescriptor descriptor);
|
||||
};
|
||||
GPUDevice includes GPUObjectBase;
|
||||
|
||||
dictionary GPUCommandEncoderDescriptor : GPUObjectDescriptorBase {
|
||||
boolean measureExecutionTime = false;
|
||||
};
|
||||
|
|
|
@ -13,13 +13,13 @@ interface GPUQueue {
|
|||
[Throws] void writeBuffer(
|
||||
GPUBuffer buffer,
|
||||
GPUSize64 bufferOffset,
|
||||
/*[AllowShared]*/ ArrayBuffer data,
|
||||
/*[AllowShared]*/ BufferSource data,
|
||||
optional GPUSize64 dataOffset = 0,
|
||||
optional GPUSize64 size);
|
||||
|
||||
[Throws] void writeTexture(
|
||||
GPUTextureCopyView destination,
|
||||
/*[AllowShared]*/ ArrayBuffer data,
|
||||
/*[AllowShared]*/ BufferSource data,
|
||||
GPUTextureDataLayout dataLayout,
|
||||
GPUExtent3D size);
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@ dictionary GPUSamplerDescriptor : GPUObjectDescriptorBase {
|
|||
GPUFilterMode minFilter = "nearest";
|
||||
GPUFilterMode mipmapFilter = "nearest";
|
||||
float lodMinClamp = 0;
|
||||
float lodMaxClamp = 0xfffff; // TODO: Update this. Value in spec was too big
|
||||
float lodMaxClamp = 0xfffff; // TODO: What should this be? Was Number.MAX_VALUE.
|
||||
GPUCompareFunction compare;
|
||||
unsigned short maxAnisotropy = 1;
|
||||
};
|
||||
|
||||
enum GPUAddressMode {
|
||||
|
|
|
@ -57,8 +57,9 @@ enum GPUTextureFormat {
|
|||
"bgra8unorm",
|
||||
"bgra8unorm-srgb",
|
||||
// Packed 32-bit formats
|
||||
//"rgb9e5ufloat",
|
||||
"rgb10a2unorm",
|
||||
"rg11b10float",
|
||||
//"rg11b10ufloat",
|
||||
|
||||
// 64-bit formats
|
||||
"rg32uint",
|
||||
|
@ -74,15 +75,42 @@ enum GPUTextureFormat {
|
|||
"rgba32float",
|
||||
|
||||
// Depth and stencil formats
|
||||
"depth32float",
|
||||
//"stencil8",
|
||||
//"depth16unorm",
|
||||
"depth24plus",
|
||||
"depth24plus-stencil8"
|
||||
"depth24plus-stencil8",
|
||||
"depth32float",
|
||||
|
||||
// BC compressed formats usable if "texture-compression-bc" is both
|
||||
// supported by the device/user agent and enabled in requestDevice.
|
||||
"bc1-rgba-unorm",
|
||||
"bc1-rgba-unorm-srgb",
|
||||
"bc2-rgba-unorm",
|
||||
"bc2-rgba-unorm-srgb",
|
||||
"bc3-rgba-unorm",
|
||||
"bc3-rgba-unorm-srgb",
|
||||
"bc4-r-unorm",
|
||||
"bc4-r-snorm",
|
||||
"bc5-rg-unorm",
|
||||
"bc5-rg-snorm",
|
||||
"bc6h-rgb-ufloat",
|
||||
//"bc6h-rgb-float",
|
||||
"bc7-rgba-unorm",
|
||||
"bc7-rgba-unorm-srgb",
|
||||
|
||||
// "depth24unorm-stencil8" extension
|
||||
//"depth24unorm-stencil8",
|
||||
|
||||
// "depth32float-stencil8" extension
|
||||
//"depth32float-stencil8",
|
||||
};
|
||||
|
||||
enum GPUTextureComponentType {
|
||||
"float",
|
||||
"sint",
|
||||
"uint"
|
||||
"uint",
|
||||
// Texture is used with comparison sampling only.
|
||||
"depth-comparison"
|
||||
};
|
||||
|
||||
dictionary GPUExtent3DDict {
|
||||
|
|
|
@ -61,7 +61,7 @@ pub enum WebGPUResponse {
|
|||
RequestDevice {
|
||||
device_id: WebGPUDevice,
|
||||
queue_id: WebGPUQueue,
|
||||
_descriptor: wgt::DeviceDescriptor,
|
||||
descriptor: wgt::DeviceDescriptor,
|
||||
label: Option<String>,
|
||||
},
|
||||
BufferMapAsync(IpcSharedMemory),
|
||||
|
@ -960,7 +960,7 @@ impl<'a> WGPU<'a> {
|
|||
if let Err(e) = sender.send(Ok(WebGPUResponse::RequestDevice {
|
||||
device_id: device,
|
||||
queue_id: queue,
|
||||
_descriptor: descriptor,
|
||||
descriptor,
|
||||
label,
|
||||
})) {
|
||||
warn!(
|
||||
|
|
|
@ -33,6 +33,7 @@ packages = [
|
|||
"base64",
|
||||
"cloudabi",
|
||||
"cocoa",
|
||||
"fixedbitset",
|
||||
"gleam",
|
||||
"libloading",
|
||||
"lock_api",
|
||||
|
@ -41,6 +42,7 @@ packages = [
|
|||
"num-rational",
|
||||
"parking_lot",
|
||||
"parking_lot_core",
|
||||
"petgraph",
|
||||
"ron",
|
||||
"wayland-sys",
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue