mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
webgpu: Update to wgpu 0.20 (#32173)
* Update wgpu to 0.20 * good expectations * Throw TypeError in configure on unsupported format instead of panic * Expect * `into_command_buffer_id`,`into_command_encoder_id`
This commit is contained in:
parent
5298ccb0eb
commit
c4f8599404
21 changed files with 1552 additions and 852 deletions
|
@ -268,7 +268,8 @@ impl GPUBufferMethods for GPUBuffer {
|
|||
buffer_id: self.buffer.0,
|
||||
device_id: self.device.id().0,
|
||||
host_map,
|
||||
map_range: map_range.clone(),
|
||||
offset,
|
||||
size: Some(range_size),
|
||||
},
|
||||
)) {
|
||||
warn!(
|
||||
|
|
|
@ -208,14 +208,19 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
|
|||
}
|
||||
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-configure>
|
||||
fn Configure(&self, descriptor: &GPUCanvasConfiguration) {
|
||||
fn Configure(&self, descriptor: &GPUCanvasConfiguration) -> Fallible<()> {
|
||||
// Step 1 is let
|
||||
// Step 2
|
||||
// TODO: device features
|
||||
let format = match descriptor.format {
|
||||
GPUTextureFormat::Rgba8unorm | GPUTextureFormat::Rgba8unorm_srgb => ImageFormat::RGBA8,
|
||||
GPUTextureFormat::Bgra8unorm | GPUTextureFormat::Bgra8unorm_srgb => ImageFormat::BGRA8,
|
||||
_ => panic!("SwapChain format({:?}) not supported", descriptor.format), // TODO: Better handling
|
||||
_ => {
|
||||
return Err(Error::Type(format!(
|
||||
"SwapChain format({:?}) not supported",
|
||||
descriptor.format
|
||||
)))
|
||||
},
|
||||
};
|
||||
|
||||
// Step 3
|
||||
|
@ -287,6 +292,7 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
|
|||
.set(Some(&descriptor.device.CreateTexture(&text_desc).unwrap()));
|
||||
|
||||
self.webrender_image.set(Some(receiver.recv().unwrap()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-unconfigure>
|
||||
|
|
|
@ -393,7 +393,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.expect("Failed to send Finish");
|
||||
|
||||
*self.state.borrow_mut() = GPUCommandEncoderState::Closed;
|
||||
let buffer = webgpu::WebGPUCommandBuffer(self.encoder.0.transmute());
|
||||
let buffer = webgpu::WebGPUCommandBuffer(self.encoder.0.into_command_buffer_id());
|
||||
GPUCommandBuffer::new(
|
||||
&self.global(),
|
||||
self.channel.clone(),
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use webgpu::wgpu::command::{compute_ffi as wgpu_comp, ComputePass};
|
||||
use webgpu::wgpu::command::{compute_commands as wgpu_comp, ComputePass};
|
||||
use webgpu::{WebGPU, WebGPURequest};
|
||||
|
||||
use super::bindings::error::Fallible;
|
||||
|
@ -120,15 +120,12 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
|
|||
#[allow(unsafe_code)]
|
||||
fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec<u32>) {
|
||||
if let Some(compute_pass) = self.compute_pass.borrow_mut().as_mut() {
|
||||
unsafe {
|
||||
wgpu_comp::wgpu_compute_pass_set_bind_group(
|
||||
compute_pass,
|
||||
index,
|
||||
bind_group.id().0,
|
||||
dynamic_offsets.as_ptr(),
|
||||
dynamic_offsets.len(),
|
||||
)
|
||||
};
|
||||
wgpu_comp::wgpu_compute_pass_set_bind_group(
|
||||
compute_pass,
|
||||
index,
|
||||
bind_group.id().0,
|
||||
&dynamic_offsets,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -718,7 +718,9 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
layout,
|
||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
||||
module: descriptor.compute.module.id().0,
|
||||
entry_point: Cow::Owned(descriptor.compute.entryPoint.to_string()),
|
||||
entry_point: Some(Cow::Owned(descriptor.compute.entryPoint.to_string())),
|
||||
constants: Cow::Owned(HashMap::new()),
|
||||
zero_initialize_workgroup_memory: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -921,7 +923,11 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
vertex: wgpu_pipe::VertexState {
|
||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
||||
module: descriptor.vertex.parent.module.id().0,
|
||||
entry_point: Cow::Owned(descriptor.vertex.parent.entryPoint.to_string()),
|
||||
entry_point: Some(Cow::Owned(
|
||||
descriptor.vertex.parent.entryPoint.to_string(),
|
||||
)),
|
||||
constants: Cow::Owned(HashMap::new()),
|
||||
zero_initialize_workgroup_memory: true,
|
||||
},
|
||||
buffers: Cow::Owned(
|
||||
descriptor
|
||||
|
@ -955,7 +961,9 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.map(|stage| wgpu_pipe::FragmentState {
|
||||
stage: wgpu_pipe::ProgrammableStageDescriptor {
|
||||
module: stage.parent.module.id().0,
|
||||
entry_point: Cow::Owned(stage.parent.entryPoint.to_string()),
|
||||
entry_point: Some(Cow::Owned(stage.parent.entryPoint.to_string())),
|
||||
constants: Cow::Owned(HashMap::new()),
|
||||
zero_initialize_workgroup_memory: true,
|
||||
},
|
||||
targets: Cow::Owned(
|
||||
stage
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use webgpu::wgpu::command::{render_ffi as wgpu_render, RenderPass};
|
||||
use webgpu::wgpu::command::{render_commands as wgpu_render, RenderPass};
|
||||
use webgpu::{wgt, WebGPU, WebGPURequest};
|
||||
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::GPUIndexFormat;
|
||||
|
@ -86,15 +86,12 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
|
|||
#[allow(unsafe_code)]
|
||||
fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec<u32>) {
|
||||
if let Some(render_pass) = self.render_pass.borrow_mut().as_mut() {
|
||||
unsafe {
|
||||
wgpu_render::wgpu_render_pass_set_bind_group(
|
||||
render_pass,
|
||||
index,
|
||||
bind_group.id().0,
|
||||
dynamic_offsets.as_ptr(),
|
||||
dynamic_offsets.len(),
|
||||
)
|
||||
};
|
||||
wgpu_render::wgpu_render_pass_set_bind_group(
|
||||
render_pass,
|
||||
index,
|
||||
bind_group.id().0,
|
||||
&dynamic_offsets,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,13 +283,7 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
|
|||
fn ExecuteBundles(&self, bundles: Vec<DomRoot<GPURenderBundle>>) {
|
||||
let bundle_ids = bundles.iter().map(|b| b.id().0).collect::<Vec<_>>();
|
||||
if let Some(render_pass) = self.render_pass.borrow_mut().as_mut() {
|
||||
unsafe {
|
||||
wgpu_render::wgpu_render_pass_execute_bundles(
|
||||
render_pass,
|
||||
bundle_ids.as_ptr(),
|
||||
bundle_ids.len(),
|
||||
)
|
||||
};
|
||||
wgpu_render::wgpu_render_pass_execute_bundles(render_pass, &bundle_ids)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1048,6 +1048,7 @@ interface GPUCanvasContext {
|
|||
|
||||
// Calling configure() a second time invalidates the previous one,
|
||||
// and all of the textures it's produced.
|
||||
[Throws]
|
||||
undefined configure(GPUCanvasConfiguration descriptor);
|
||||
undefined unconfigure();
|
||||
|
||||
|
|
|
@ -2125,7 +2125,7 @@ impl ScriptThread {
|
|||
WebGPUMsg::FreeCommandBuffer(id) => self
|
||||
.gpu_id_hub
|
||||
.lock()
|
||||
.kill_command_buffer_id(id.transmute()),
|
||||
.kill_command_buffer_id(id.into_command_encoder_id()),
|
||||
WebGPUMsg::FreeSampler(id) => self.gpu_id_hub.lock().kill_sampler_id(id),
|
||||
WebGPUMsg::FreeShaderModule(id) => self.gpu_id_hub.lock().kill_shader_module_id(id),
|
||||
WebGPUMsg::FreeRenderBundle(id) => self.gpu_id_hub.lock().kill_render_bundle_id(id),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue