mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
update wgpu, use serializable descriptors
This commit is contained in:
parent
a242913629
commit
75abccb16b
5 changed files with 249 additions and 354 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -6861,7 +6861,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "wgpu-core"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#73b230871ea4428ed3fb1e6e8bff81a7364fcdb2"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#4ed2c0a313deb48a99f15e8fe0558ad3d095ca01"
|
||||
dependencies = [
|
||||
"arrayvec 0.5.1",
|
||||
"bitflags",
|
||||
|
@ -6890,7 +6890,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "wgpu-types"
|
||||
version = "0.5.0"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#73b230871ea4428ed3fb1e6e8bff81a7364fcdb2"
|
||||
source = "git+https://github.com/gfx-rs/wgpu#4ed2c0a313deb48a99f15e8fe0558ad3d095ca01"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"serde",
|
||||
|
|
|
@ -25,6 +25,7 @@ use crate::dom::gpucomputepassencoder::GPUComputePassEncoder;
|
|||
use crate::dom::gpudevice::{convert_texture_size_to_dict, convert_texture_size_to_wgt};
|
||||
use crate::dom::gpurenderpassencoder::GPURenderPassEncoder;
|
||||
use dom_struct::dom_struct;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashSet;
|
||||
use webgpu::wgpu::command as wgpu_com;
|
||||
|
@ -135,55 +136,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
GPUCommandEncoderState::Open,
|
||||
);
|
||||
|
||||
let colors = descriptor
|
||||
.colorAttachments
|
||||
.iter()
|
||||
.map(|color| {
|
||||
let (load_op, clear_value) = match color.loadValue {
|
||||
GPUColorLoad::GPULoadOp(_) => (wgpu_com::LoadOp::Load, wgt::Color::TRANSPARENT),
|
||||
GPUColorLoad::DoubleSequence(ref s) => {
|
||||
let mut w = s.clone();
|
||||
if w.len() < 3 {
|
||||
w.resize(3, Finite::wrap(0.0f64));
|
||||
}
|
||||
w.resize(4, Finite::wrap(1.0f64));
|
||||
(
|
||||
wgpu_com::LoadOp::Clear,
|
||||
wgt::Color {
|
||||
r: *w[0],
|
||||
g: *w[1],
|
||||
b: *w[2],
|
||||
a: *w[3],
|
||||
},
|
||||
)
|
||||
},
|
||||
GPUColorLoad::GPUColorDict(ref d) => (
|
||||
wgpu_com::LoadOp::Clear,
|
||||
wgt::Color {
|
||||
r: *d.r,
|
||||
g: *d.g,
|
||||
b: *d.b,
|
||||
a: *d.a,
|
||||
},
|
||||
),
|
||||
};
|
||||
let channel = wgpu_com::PassChannel {
|
||||
load_op,
|
||||
store_op: match color.storeOp {
|
||||
GPUStoreOp::Store => wgpu_com::StoreOp::Store,
|
||||
GPUStoreOp::Clear => wgpu_com::StoreOp::Clear,
|
||||
},
|
||||
clear_value,
|
||||
read_only: false,
|
||||
};
|
||||
wgpu_com::ColorAttachmentDescriptor {
|
||||
attachment: color.attachment.id().0,
|
||||
resolve_target: color.resolveTarget.as_ref().map(|t| t.id().0),
|
||||
channel,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let depth_stencil = descriptor.depthStencilAttachment.as_ref().map(|depth| {
|
||||
let (depth_load_op, clear_depth) = match depth.depthLoadValue {
|
||||
GPULoadOpOrFloat::GPULoadOp(_) => (wgpu_com::LoadOp::Load, 0.0f32),
|
||||
|
@ -219,7 +171,58 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
});
|
||||
|
||||
let desc = wgpu_com::RenderPassDescriptor {
|
||||
color_attachments: colors.as_slice(),
|
||||
color_attachments: Cow::Owned(
|
||||
descriptor
|
||||
.colorAttachments
|
||||
.iter()
|
||||
.map(|color| {
|
||||
let (load_op, clear_value) = match color.loadValue {
|
||||
GPUColorLoad::GPULoadOp(_) => {
|
||||
(wgpu_com::LoadOp::Load, wgt::Color::TRANSPARENT)
|
||||
},
|
||||
GPUColorLoad::DoubleSequence(ref s) => {
|
||||
let mut w = s.clone();
|
||||
if w.len() < 3 {
|
||||
w.resize(3, Finite::wrap(0.0f64));
|
||||
}
|
||||
w.resize(4, Finite::wrap(1.0f64));
|
||||
(
|
||||
wgpu_com::LoadOp::Clear,
|
||||
wgt::Color {
|
||||
r: *w[0],
|
||||
g: *w[1],
|
||||
b: *w[2],
|
||||
a: *w[3],
|
||||
},
|
||||
)
|
||||
},
|
||||
GPUColorLoad::GPUColorDict(ref d) => (
|
||||
wgpu_com::LoadOp::Clear,
|
||||
wgt::Color {
|
||||
r: *d.r,
|
||||
g: *d.g,
|
||||
b: *d.b,
|
||||
a: *d.a,
|
||||
},
|
||||
),
|
||||
};
|
||||
let channel = wgpu_com::PassChannel {
|
||||
load_op,
|
||||
store_op: match color.storeOp {
|
||||
GPUStoreOp::Store => wgpu_com::StoreOp::Store,
|
||||
GPUStoreOp::Clear => wgpu_com::StoreOp::Clear,
|
||||
},
|
||||
clear_value,
|
||||
read_only: false,
|
||||
};
|
||||
wgpu_com::ColorAttachmentDescriptor {
|
||||
attachment: color.attachment.id().0,
|
||||
resolve_target: color.resolveTarget.as_ref().map(|t| t.id().0),
|
||||
channel,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
depth_stencil_attachment: depth_stencil.as_ref(),
|
||||
};
|
||||
|
||||
|
|
|
@ -57,16 +57,16 @@ use crate::dom::gputexture::GPUTexture;
|
|||
use crate::dom::promise::Promise;
|
||||
use crate::realms::InRealm;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use arrayvec::ArrayVec;
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{Heap, JSObject};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
use std::string::String;
|
||||
use webgpu::wgpu::binding_model::BufferBinding;
|
||||
use webgpu::{self, wgt, WebGPU, WebGPUBindings, WebGPURequest};
|
||||
use webgpu::wgpu::{binding_model as wgpu_bind, pipeline as wgpu_pipe};
|
||||
use webgpu::{self, wgt, WebGPU, WebGPURequest};
|
||||
|
||||
type ErrorScopeId = u64;
|
||||
|
||||
|
@ -401,6 +401,15 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
}
|
||||
}
|
||||
|
||||
let desc = wgt::BindGroupLayoutDescriptor {
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|s| Cow::Owned(s.to_string())),
|
||||
entries: Cow::Owned(entries.clone()),
|
||||
};
|
||||
|
||||
let bind_group_layout_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
|
@ -411,13 +420,8 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.send(WebGPURequest::CreateBindGroupLayout {
|
||||
device_id: self.device.0,
|
||||
bind_group_layout_id,
|
||||
entries: entries.clone(),
|
||||
scope_id,
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|s| String::from(s.as_ref())),
|
||||
descriptor: desc,
|
||||
})
|
||||
.expect("Failed to create WebGPU BindGroupLayout");
|
||||
|
||||
|
@ -437,11 +441,16 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
&self,
|
||||
descriptor: &GPUPipelineLayoutDescriptor,
|
||||
) -> DomRoot<GPUPipelineLayout> {
|
||||
let mut bgl_ids = Vec::new();
|
||||
descriptor
|
||||
.bindGroupLayouts
|
||||
.iter()
|
||||
.for_each(|each| bgl_ids.push(each.id().0));
|
||||
let desc = wgt::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Cow::Owned(
|
||||
descriptor
|
||||
.bindGroupLayouts
|
||||
.iter()
|
||||
.map(|each| each.id().0)
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
push_constant_ranges: Cow::Owned(vec![]),
|
||||
};
|
||||
|
||||
let scope_id = self.use_current_scope();
|
||||
|
||||
|
@ -455,7 +464,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.send(WebGPURequest::CreatePipelineLayout {
|
||||
device_id: self.device.0,
|
||||
pipeline_layout_id,
|
||||
bind_group_layouts: bgl_ids,
|
||||
descriptor: desc,
|
||||
scope_id,
|
||||
})
|
||||
.expect("Failed to create WebGPU PipelineLayout");
|
||||
|
@ -469,26 +478,36 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let entries = descriptor
|
||||
.entries
|
||||
.iter()
|
||||
.map(|bind| {
|
||||
(
|
||||
bind.binding,
|
||||
match bind.resource {
|
||||
GPUBindingResource::GPUSampler(ref s) => WebGPUBindings::Sampler(s.id().0),
|
||||
GPUBindingResource::GPUTextureView(ref t) => {
|
||||
WebGPUBindings::TextureView(t.id().0)
|
||||
},
|
||||
GPUBindingResource::GPUBufferBindings(ref b) => {
|
||||
WebGPUBindings::Buffer(BufferBinding {
|
||||
buffer_id: b.buffer.id().0,
|
||||
offset: b.offset,
|
||||
size: b.size.and_then(wgt::BufferSize::new),
|
||||
})
|
||||
},
|
||||
.map(|bind| wgpu_bind::BindGroupEntry {
|
||||
binding: bind.binding,
|
||||
resource: match bind.resource {
|
||||
GPUBindingResource::GPUSampler(ref s) => {
|
||||
wgpu_bind::BindingResource::Sampler(s.id().0)
|
||||
},
|
||||
)
|
||||
GPUBindingResource::GPUTextureView(ref t) => {
|
||||
wgpu_bind::BindingResource::TextureView(t.id().0)
|
||||
},
|
||||
GPUBindingResource::GPUBufferBindings(ref b) => {
|
||||
wgpu_bind::BindingResource::Buffer(wgpu_bind::BufferBinding {
|
||||
buffer_id: b.buffer.id().0,
|
||||
offset: b.offset,
|
||||
size: b.size.and_then(wgt::BufferSize::new),
|
||||
})
|
||||
},
|
||||
},
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let desc = wgpu_bind::BindGroupDescriptor {
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|l| Cow::Owned(l.to_string())),
|
||||
layout: descriptor.layout.id().0,
|
||||
entries: Cow::Owned(entries),
|
||||
};
|
||||
|
||||
let scope_id = self.use_current_scope();
|
||||
|
||||
let bind_group_id = self
|
||||
|
@ -501,14 +520,8 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.send(WebGPURequest::CreateBindGroup {
|
||||
device_id: self.device.0,
|
||||
bind_group_id,
|
||||
bind_group_layout_id: descriptor.layout.id().0,
|
||||
entries,
|
||||
descriptor: desc,
|
||||
scope_id,
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|s| String::from(s.as_ref())),
|
||||
})
|
||||
.expect("Failed to create WebGPU BindGroup");
|
||||
|
||||
|
@ -551,9 +564,6 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
&self,
|
||||
descriptor: &GPUComputePipelineDescriptor,
|
||||
) -> DomRoot<GPUComputePipeline> {
|
||||
let pipeline = descriptor.parent.layout.id();
|
||||
let program = descriptor.computeStage.module.id();
|
||||
let entry_point = descriptor.computeStage.entryPoint.to_string();
|
||||
let compute_pipeline_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
|
@ -562,15 +572,21 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
|
||||
let scope_id = self.use_current_scope();
|
||||
|
||||
let desc = wgpu_pipe::ComputePipelineDescriptor {
|
||||
layout: descriptor.parent.layout.id().0,
|
||||
compute_stage: wgpu_pipe::ProgrammableStageDescriptor {
|
||||
module: descriptor.computeStage.module.id().0,
|
||||
entry_point: Cow::Owned(descriptor.computeStage.entryPoint.to_string()),
|
||||
},
|
||||
};
|
||||
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateComputePipeline {
|
||||
device_id: self.device.0,
|
||||
scope_id,
|
||||
compute_pipeline_id,
|
||||
pipeline_layout_id: pipeline.0,
|
||||
program_id: program.0,
|
||||
entry_point,
|
||||
descriptor: desc,
|
||||
})
|
||||
.expect("Failed to create WebGPU ComputePipeline");
|
||||
|
||||
|
@ -712,104 +728,112 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
&self,
|
||||
descriptor: &GPURenderPipelineDescriptor,
|
||||
) -> DomRoot<GPURenderPipeline> {
|
||||
let vertex_module = descriptor.vertexStage.module.id().0;
|
||||
let vertex_entry_point = descriptor.vertexStage.entryPoint.to_string();
|
||||
let (fragment_module, fragment_entry_point) = match descriptor.fragmentStage {
|
||||
Some(ref frag) => (Some(frag.module.id().0), Some(frag.entryPoint.to_string())),
|
||||
None => (None, None),
|
||||
};
|
||||
|
||||
let primitive_topology = match descriptor.primitiveTopology {
|
||||
GPUPrimitiveTopology::Point_list => wgt::PrimitiveTopology::PointList,
|
||||
GPUPrimitiveTopology::Line_list => wgt::PrimitiveTopology::LineList,
|
||||
GPUPrimitiveTopology::Line_strip => wgt::PrimitiveTopology::LineStrip,
|
||||
GPUPrimitiveTopology::Triangle_list => wgt::PrimitiveTopology::TriangleList,
|
||||
GPUPrimitiveTopology::Triangle_strip => wgt::PrimitiveTopology::TriangleStrip,
|
||||
};
|
||||
|
||||
let ref rs_desc = descriptor.rasterizationState;
|
||||
let rasterization_state = wgt::RasterizationStateDescriptor {
|
||||
front_face: match rs_desc.frontFace {
|
||||
GPUFrontFace::Ccw => wgt::FrontFace::Ccw,
|
||||
GPUFrontFace::Cw => wgt::FrontFace::Cw,
|
||||
},
|
||||
cull_mode: match rs_desc.cullMode {
|
||||
GPUCullMode::None => wgt::CullMode::None,
|
||||
GPUCullMode::Front => wgt::CullMode::Front,
|
||||
GPUCullMode::Back => wgt::CullMode::Back,
|
||||
},
|
||||
depth_bias: rs_desc.depthBias,
|
||||
depth_bias_slope_scale: *rs_desc.depthBiasSlopeScale,
|
||||
depth_bias_clamp: *rs_desc.depthBiasClamp,
|
||||
};
|
||||
|
||||
let color_states = descriptor
|
||||
.colorStates
|
||||
.iter()
|
||||
.map(|state| wgt::ColorStateDescriptor {
|
||||
format: convert_texture_format(state.format),
|
||||
alpha_blend: convert_blend_descriptor(&state.alphaBlend),
|
||||
color_blend: convert_blend_descriptor(&state.colorBlend),
|
||||
write_mask: match wgt::ColorWrite::from_bits(state.writeMask) {
|
||||
Some(mask) => mask,
|
||||
None => wgt::ColorWrite::empty(),
|
||||
},
|
||||
})
|
||||
.collect::<ArrayVec<_>>();
|
||||
|
||||
let depth_stencil_state = if let Some(ref dss_desc) = descriptor.depthStencilState {
|
||||
Some(wgt::DepthStencilStateDescriptor {
|
||||
format: convert_texture_format(dss_desc.format),
|
||||
depth_write_enabled: dss_desc.depthWriteEnabled,
|
||||
depth_compare: convert_compare_function(dss_desc.depthCompare),
|
||||
stencil_front: wgt::StencilStateFaceDescriptor {
|
||||
compare: convert_compare_function(dss_desc.stencilFront.compare),
|
||||
fail_op: convert_stencil_op(dss_desc.stencilFront.failOp),
|
||||
depth_fail_op: convert_stencil_op(dss_desc.stencilFront.depthFailOp),
|
||||
pass_op: convert_stencil_op(dss_desc.stencilFront.passOp),
|
||||
},
|
||||
stencil_back: wgt::StencilStateFaceDescriptor {
|
||||
compare: convert_compare_function(dss_desc.stencilBack.compare),
|
||||
fail_op: convert_stencil_op(dss_desc.stencilBack.failOp),
|
||||
depth_fail_op: convert_stencil_op(dss_desc.stencilBack.depthFailOp),
|
||||
pass_op: convert_stencil_op(dss_desc.stencilBack.passOp),
|
||||
},
|
||||
stencil_read_mask: dss_desc.stencilReadMask,
|
||||
stencil_write_mask: dss_desc.stencilWriteMask,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let ref vs_desc = descriptor.vertexState;
|
||||
let vertex_state = (
|
||||
match vs_desc.indexFormat {
|
||||
GPUIndexFormat::Uint16 => wgt::IndexFormat::Uint16,
|
||||
GPUIndexFormat::Uint32 => wgt::IndexFormat::Uint32,
|
||||
|
||||
let desc = wgpu_pipe::RenderPipelineDescriptor {
|
||||
layout: descriptor.parent.layout.id().0,
|
||||
vertex_stage: wgpu_pipe::ProgrammableStageDescriptor {
|
||||
module: descriptor.vertexStage.module.id().0,
|
||||
entry_point: Cow::Owned(descriptor.vertexStage.entryPoint.to_string()),
|
||||
},
|
||||
vs_desc
|
||||
.vertexBuffers
|
||||
.iter()
|
||||
.map(|buffer| {
|
||||
(
|
||||
buffer.arrayStride,
|
||||
match buffer.stepMode {
|
||||
GPUInputStepMode::Vertex => wgt::InputStepMode::Vertex,
|
||||
GPUInputStepMode::Instance => wgt::InputStepMode::Instance,
|
||||
fragment_stage: descriptor.fragmentStage.as_ref().map(|stage| {
|
||||
wgpu_pipe::ProgrammableStageDescriptor {
|
||||
module: stage.module.id().0,
|
||||
entry_point: Cow::Owned(stage.entryPoint.to_string()),
|
||||
}
|
||||
}),
|
||||
rasterization_state: Some(wgt::RasterizationStateDescriptor {
|
||||
front_face: match rs_desc.frontFace {
|
||||
GPUFrontFace::Ccw => wgt::FrontFace::Ccw,
|
||||
GPUFrontFace::Cw => wgt::FrontFace::Cw,
|
||||
},
|
||||
cull_mode: match rs_desc.cullMode {
|
||||
GPUCullMode::None => wgt::CullMode::None,
|
||||
GPUCullMode::Front => wgt::CullMode::Front,
|
||||
GPUCullMode::Back => wgt::CullMode::Back,
|
||||
},
|
||||
depth_bias: rs_desc.depthBias,
|
||||
depth_bias_slope_scale: *rs_desc.depthBiasSlopeScale,
|
||||
depth_bias_clamp: *rs_desc.depthBiasClamp,
|
||||
}),
|
||||
primitive_topology: match descriptor.primitiveTopology {
|
||||
GPUPrimitiveTopology::Point_list => wgt::PrimitiveTopology::PointList,
|
||||
GPUPrimitiveTopology::Line_list => wgt::PrimitiveTopology::LineList,
|
||||
GPUPrimitiveTopology::Line_strip => wgt::PrimitiveTopology::LineStrip,
|
||||
GPUPrimitiveTopology::Triangle_list => wgt::PrimitiveTopology::TriangleList,
|
||||
GPUPrimitiveTopology::Triangle_strip => wgt::PrimitiveTopology::TriangleStrip,
|
||||
},
|
||||
color_states: Cow::Owned(
|
||||
descriptor
|
||||
.colorStates
|
||||
.iter()
|
||||
.map(|state| wgt::ColorStateDescriptor {
|
||||
format: convert_texture_format(state.format),
|
||||
alpha_blend: convert_blend_descriptor(&state.alphaBlend),
|
||||
color_blend: convert_blend_descriptor(&state.colorBlend),
|
||||
write_mask: match wgt::ColorWrite::from_bits(state.writeMask) {
|
||||
Some(mask) => mask,
|
||||
None => wgt::ColorWrite::empty(),
|
||||
},
|
||||
buffer
|
||||
.attributes
|
||||
.iter()
|
||||
.map(|att| wgt::VertexAttributeDescriptor {
|
||||
format: convert_vertex_format(att.format),
|
||||
offset: att.offset,
|
||||
shader_location: att.shaderLocation,
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
depth_stencil_state: descriptor.depthStencilState.as_ref().map(|dss_desc| {
|
||||
wgt::DepthStencilStateDescriptor {
|
||||
format: convert_texture_format(dss_desc.format),
|
||||
depth_write_enabled: dss_desc.depthWriteEnabled,
|
||||
depth_compare: convert_compare_function(dss_desc.depthCompare),
|
||||
stencil_front: wgt::StencilStateFaceDescriptor {
|
||||
compare: convert_compare_function(dss_desc.stencilFront.compare),
|
||||
fail_op: convert_stencil_op(dss_desc.stencilFront.failOp),
|
||||
depth_fail_op: convert_stencil_op(dss_desc.stencilFront.depthFailOp),
|
||||
pass_op: convert_stencil_op(dss_desc.stencilFront.passOp),
|
||||
},
|
||||
stencil_back: wgt::StencilStateFaceDescriptor {
|
||||
compare: convert_compare_function(dss_desc.stencilBack.compare),
|
||||
fail_op: convert_stencil_op(dss_desc.stencilBack.failOp),
|
||||
depth_fail_op: convert_stencil_op(dss_desc.stencilBack.depthFailOp),
|
||||
pass_op: convert_stencil_op(dss_desc.stencilBack.passOp),
|
||||
},
|
||||
stencil_read_mask: dss_desc.stencilReadMask,
|
||||
stencil_write_mask: dss_desc.stencilWriteMask,
|
||||
}
|
||||
}),
|
||||
vertex_state: wgt::VertexStateDescriptor {
|
||||
index_format: match vs_desc.indexFormat {
|
||||
GPUIndexFormat::Uint16 => wgt::IndexFormat::Uint16,
|
||||
GPUIndexFormat::Uint32 => wgt::IndexFormat::Uint32,
|
||||
},
|
||||
vertex_buffers: Cow::Owned(
|
||||
vs_desc
|
||||
.vertexBuffers
|
||||
.iter()
|
||||
.map(|buffer| wgt::VertexBufferDescriptor {
|
||||
stride: buffer.arrayStride,
|
||||
step_mode: match buffer.stepMode {
|
||||
GPUInputStepMode::Vertex => wgt::InputStepMode::Vertex,
|
||||
GPUInputStepMode::Instance => wgt::InputStepMode::Instance,
|
||||
},
|
||||
attributes: Cow::Owned(
|
||||
buffer
|
||||
.attributes
|
||||
.iter()
|
||||
.map(|att| wgt::VertexAttributeDescriptor {
|
||||
format: convert_vertex_format(att.format),
|
||||
offset: att.offset,
|
||||
shader_location: att.shaderLocation,
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
},
|
||||
sample_count: descriptor.sampleCount,
|
||||
sample_mask: descriptor.sampleMask,
|
||||
alpha_to_coverage_enabled: descriptor.alphaToCoverageEnabled,
|
||||
};
|
||||
|
||||
let render_pipeline_id = self
|
||||
.global()
|
||||
|
@ -825,19 +849,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
device_id: self.device.0,
|
||||
render_pipeline_id,
|
||||
scope_id,
|
||||
pipeline_layout_id: descriptor.parent.layout.id().0,
|
||||
vertex_module,
|
||||
vertex_entry_point,
|
||||
fragment_module,
|
||||
fragment_entry_point,
|
||||
primitive_topology,
|
||||
rasterization_state,
|
||||
color_states,
|
||||
depth_stencil_state,
|
||||
vertex_state,
|
||||
sample_count: descriptor.sampleCount,
|
||||
sample_mask: descriptor.sampleMask,
|
||||
alpha_to_coverage_enabled: descriptor.alphaToCoverageEnabled,
|
||||
descriptor: desc,
|
||||
})
|
||||
.expect("Failed to create WebGPU render pipeline");
|
||||
|
||||
|
|
|
@ -57,12 +57,12 @@ pub enum WebGPUMsg {
|
|||
#[derive(Debug)]
|
||||
pub struct IdentityRecycler {
|
||||
sender: IpcSender<WebGPUMsg>,
|
||||
self_sender: IpcSender<WebGPURequest>,
|
||||
self_sender: IpcSender<WebGPURequest<'static>>,
|
||||
}
|
||||
|
||||
pub struct IdentityRecyclerFactory {
|
||||
pub sender: IpcSender<WebGPUMsg>,
|
||||
pub self_sender: IpcSender<WebGPURequest>,
|
||||
pub self_sender: IpcSender<WebGPURequest<'static>>,
|
||||
}
|
||||
|
||||
macro_rules! impl_identity_handler {
|
||||
|
|
|
@ -31,11 +31,12 @@ use webrender_traits::{
|
|||
WebrenderImageSource,
|
||||
};
|
||||
use wgpu::{
|
||||
binding_model::{BindGroupDescriptor, BindGroupEntry, BindingResource, BufferBinding},
|
||||
binding_model::BindGroupDescriptor,
|
||||
command::{BufferCopyView, ComputePass, RenderPass, TextureCopyView},
|
||||
device::HostMap,
|
||||
id,
|
||||
instance::RequestAdapterOptions,
|
||||
pipeline::{ComputePipelineDescriptor, RenderPipelineDescriptor},
|
||||
resource::{BufferMapAsyncStatus, BufferMapOperation},
|
||||
};
|
||||
|
||||
|
@ -60,7 +61,7 @@ pub enum WebGPUResponse {
|
|||
pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebGPURequest {
|
||||
pub enum WebGPURequest<'a> {
|
||||
BufferMapAsync {
|
||||
sender: IpcSender<WebGPUResponseResult>,
|
||||
buffer_id: id::BufferId,
|
||||
|
@ -104,16 +105,13 @@ pub enum WebGPURequest {
|
|||
// TODO: Consider using NonZeroU64 to reduce enum size
|
||||
scope_id: Option<u64>,
|
||||
bind_group_id: id::BindGroupId,
|
||||
bind_group_layout_id: id::BindGroupLayoutId,
|
||||
entries: Vec<(u32, WebGPUBindings)>,
|
||||
label: Option<String>,
|
||||
descriptor: BindGroupDescriptor<'a>,
|
||||
},
|
||||
CreateBindGroupLayout {
|
||||
device_id: id::DeviceId,
|
||||
scope_id: Option<u64>,
|
||||
bind_group_layout_id: id::BindGroupLayoutId,
|
||||
entries: Vec<wgt::BindGroupLayoutEntry>,
|
||||
label: Option<String>,
|
||||
descriptor: wgt::BindGroupLayoutDescriptor<'a>,
|
||||
},
|
||||
CreateBuffer {
|
||||
device_id: id::DeviceId,
|
||||
|
@ -131,37 +129,20 @@ pub enum WebGPURequest {
|
|||
device_id: id::DeviceId,
|
||||
scope_id: Option<u64>,
|
||||
compute_pipeline_id: id::ComputePipelineId,
|
||||
pipeline_layout_id: id::PipelineLayoutId,
|
||||
program_id: id::ShaderModuleId,
|
||||
entry_point: String,
|
||||
descriptor: ComputePipelineDescriptor<'a>,
|
||||
},
|
||||
CreateContext(IpcSender<webrender_api::ExternalImageId>),
|
||||
CreatePipelineLayout {
|
||||
device_id: id::DeviceId,
|
||||
scope_id: Option<u64>,
|
||||
pipeline_layout_id: id::PipelineLayoutId,
|
||||
bind_group_layouts: Vec<id::BindGroupLayoutId>,
|
||||
descriptor: wgt::PipelineLayoutDescriptor<'a, id::BindGroupLayoutId>,
|
||||
},
|
||||
CreateRenderPipeline {
|
||||
device_id: id::DeviceId,
|
||||
scope_id: Option<u64>,
|
||||
render_pipeline_id: id::RenderPipelineId,
|
||||
pipeline_layout_id: id::PipelineLayoutId,
|
||||
vertex_module: id::ShaderModuleId,
|
||||
vertex_entry_point: String,
|
||||
fragment_module: Option<id::ShaderModuleId>,
|
||||
fragment_entry_point: Option<String>,
|
||||
primitive_topology: wgt::PrimitiveTopology,
|
||||
rasterization_state: wgt::RasterizationStateDescriptor,
|
||||
color_states: ArrayVec<[wgt::ColorStateDescriptor; wgpu::device::MAX_COLOR_TARGETS]>,
|
||||
depth_stencil_state: Option<wgt::DepthStencilStateDescriptor>,
|
||||
vertex_state: (
|
||||
wgt::IndexFormat,
|
||||
Vec<(u64, wgt::InputStepMode, Vec<wgt::VertexAttributeDescriptor>)>,
|
||||
),
|
||||
sample_count: u32,
|
||||
sample_mask: u32,
|
||||
alpha_to_coverage_enabled: bool,
|
||||
descriptor: RenderPipelineDescriptor<'a>,
|
||||
},
|
||||
CreateSampler {
|
||||
device_id: id::DeviceId,
|
||||
|
@ -255,13 +236,6 @@ pub enum WebGPURequest {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebGPUBindings {
|
||||
Buffer(BufferBinding),
|
||||
Sampler(id::SamplerId),
|
||||
TextureView(id::TextureViewId),
|
||||
}
|
||||
|
||||
struct BufferMapInfo<'a, T> {
|
||||
buffer_id: id::BufferId,
|
||||
sender: IpcSender<T>,
|
||||
|
@ -271,7 +245,7 @@ struct BufferMapInfo<'a, T> {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct WebGPU(pub IpcSender<WebGPURequest>);
|
||||
pub struct WebGPU(pub IpcSender<WebGPURequest<'static>>);
|
||||
|
||||
impl WebGPU {
|
||||
pub fn new(
|
||||
|
@ -335,8 +309,8 @@ impl WebGPU {
|
|||
}
|
||||
|
||||
struct WGPU<'a> {
|
||||
receiver: IpcReceiver<WebGPURequest>,
|
||||
sender: IpcSender<WebGPURequest>,
|
||||
receiver: IpcReceiver<WebGPURequest<'static>>,
|
||||
sender: IpcSender<WebGPURequest<'static>>,
|
||||
script_sender: IpcSender<WebGPUMsg>,
|
||||
global: wgpu::hub::Global<IdentityRecyclerFactory>,
|
||||
adapters: Vec<WebGPUAdapter>,
|
||||
|
@ -346,7 +320,7 @@ struct WGPU<'a> {
|
|||
// Buffers with pending mapping
|
||||
buffer_maps: HashMap<id::BufferId, Rc<BufferMapInfo<'a, WebGPUResponseResult>>>,
|
||||
// Presentation Buffers with pending mapping
|
||||
present_buffer_maps: HashMap<id::BufferId, Rc<BufferMapInfo<'a, WebGPURequest>>>,
|
||||
present_buffer_maps: HashMap<id::BufferId, Rc<BufferMapInfo<'a, WebGPURequest<'static>>>>,
|
||||
webrender_api: webrender_api::RenderApi,
|
||||
webrender_document: webrender_api::DocumentId,
|
||||
external_images: Arc<Mutex<WebrenderExternalImageRegistry>>,
|
||||
|
@ -356,8 +330,8 @@ struct WGPU<'a> {
|
|||
|
||||
impl<'a> WGPU<'a> {
|
||||
fn new(
|
||||
receiver: IpcReceiver<WebGPURequest>,
|
||||
sender: IpcSender<WebGPURequest>,
|
||||
receiver: IpcReceiver<WebGPURequest<'static>>,
|
||||
sender: IpcSender<WebGPURequest<'static>>,
|
||||
script_sender: IpcSender<WebGPUMsg>,
|
||||
webrender_api_sender: webrender_api::RenderApiSender,
|
||||
webrender_document: webrender_api::DocumentId,
|
||||
|
@ -420,7 +394,8 @@ impl<'a> WGPU<'a> {
|
|||
BufferMapAsyncStatus::Success => {
|
||||
let global = &info.global;
|
||||
let data_pt = gfx_select!(info.buffer_id =>
|
||||
global.buffer_get_mapped_range(info.buffer_id, 0, None));
|
||||
global.buffer_get_mapped_range(info.buffer_id, 0, None))
|
||||
.unwrap();
|
||||
let data = slice::from_raw_parts(data_pt, info.size);
|
||||
if let Err(e) =
|
||||
info.sender.send(Ok(WebGPUResponse::BufferMapAsync(
|
||||
|
@ -442,7 +417,7 @@ impl<'a> WGPU<'a> {
|
|||
),
|
||||
};
|
||||
let global = &self.global;
|
||||
gfx_select!(buffer_id => global.buffer_map_async(buffer_id, map_range, operation));
|
||||
let _ = gfx_select!(buffer_id => global.buffer_map_async(buffer_id, map_range, operation));
|
||||
},
|
||||
WebGPURequest::BufferMapComplete(buffer_id) => {
|
||||
self.buffer_maps.remove(&buffer_id);
|
||||
|
@ -518,32 +493,9 @@ impl<'a> WGPU<'a> {
|
|||
device_id,
|
||||
scope_id,
|
||||
bind_group_id,
|
||||
bind_group_layout_id,
|
||||
mut entries,
|
||||
label,
|
||||
descriptor,
|
||||
} => {
|
||||
let global = &self.global;
|
||||
let bindings = entries
|
||||
.drain(..)
|
||||
.map(|(bind, res)| {
|
||||
let resource = match res {
|
||||
WebGPUBindings::Sampler(s) => BindingResource::Sampler(s),
|
||||
WebGPUBindings::TextureView(t) => {
|
||||
BindingResource::TextureView(t)
|
||||
},
|
||||
WebGPUBindings::Buffer(b) => BindingResource::Buffer(b),
|
||||
};
|
||||
BindGroupEntry {
|
||||
binding: bind,
|
||||
resource,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let descriptor = BindGroupDescriptor {
|
||||
label: label.as_deref(),
|
||||
layout: bind_group_layout_id,
|
||||
entries: bindings.as_slice(),
|
||||
};
|
||||
let result = gfx_select!(bind_group_id =>
|
||||
global.device_create_bind_group(device_id, &descriptor, bind_group_id));
|
||||
if let Some(s_id) = scope_id {
|
||||
|
@ -554,14 +506,9 @@ impl<'a> WGPU<'a> {
|
|||
device_id,
|
||||
scope_id,
|
||||
bind_group_layout_id,
|
||||
entries,
|
||||
label,
|
||||
descriptor,
|
||||
} => {
|
||||
let global = &self.global;
|
||||
let descriptor = wgt::BindGroupLayoutDescriptor {
|
||||
entries: entries.as_slice(),
|
||||
label: label.as_deref(),
|
||||
};
|
||||
let result = gfx_select!(bind_group_layout_id =>
|
||||
global.device_create_bind_group_layout(device_id, &descriptor, bind_group_layout_id));
|
||||
if let Some(s_id) = scope_id {
|
||||
|
@ -607,18 +554,9 @@ impl<'a> WGPU<'a> {
|
|||
device_id,
|
||||
scope_id,
|
||||
compute_pipeline_id,
|
||||
pipeline_layout_id,
|
||||
program_id,
|
||||
entry_point,
|
||||
descriptor,
|
||||
} => {
|
||||
let global = &self.global;
|
||||
let descriptor = wgpu_core::pipeline::ComputePipelineDescriptor {
|
||||
layout: pipeline_layout_id,
|
||||
compute_stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
|
||||
module: program_id,
|
||||
entry_point: entry_point.as_str(),
|
||||
},
|
||||
};
|
||||
let result = gfx_select!(compute_pipeline_id =>
|
||||
global.device_create_compute_pipeline(device_id, &descriptor, compute_pipeline_id));
|
||||
if let Some(s_id) = scope_id {
|
||||
|
@ -639,13 +577,9 @@ impl<'a> WGPU<'a> {
|
|||
device_id,
|
||||
scope_id,
|
||||
pipeline_layout_id,
|
||||
bind_group_layouts,
|
||||
descriptor,
|
||||
} => {
|
||||
let global = &self.global;
|
||||
let descriptor = wgt::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: bind_group_layouts.as_slice(),
|
||||
push_constant_ranges: &[],
|
||||
};
|
||||
let result = gfx_select!(pipeline_layout_id =>
|
||||
global.device_create_pipeline_layout(device_id, &descriptor, pipeline_layout_id));
|
||||
if let Some(s_id) = scope_id {
|
||||
|
@ -657,65 +591,9 @@ impl<'a> WGPU<'a> {
|
|||
device_id,
|
||||
scope_id,
|
||||
render_pipeline_id,
|
||||
pipeline_layout_id,
|
||||
vertex_module,
|
||||
vertex_entry_point,
|
||||
fragment_module,
|
||||
fragment_entry_point,
|
||||
primitive_topology,
|
||||
rasterization_state,
|
||||
color_states,
|
||||
depth_stencil_state,
|
||||
vertex_state,
|
||||
sample_count,
|
||||
sample_mask,
|
||||
alpha_to_coverage_enabled,
|
||||
descriptor,
|
||||
} => {
|
||||
let global = &self.global;
|
||||
let frag_ep;
|
||||
let fragment_stage = match fragment_module {
|
||||
Some(frag) => {
|
||||
frag_ep = fragment_entry_point.unwrap().clone();
|
||||
let frag_module =
|
||||
wgpu_core::pipeline::ProgrammableStageDescriptor {
|
||||
module: frag,
|
||||
entry_point: frag_ep.as_str(),
|
||||
};
|
||||
Some(frag_module)
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
let vert_buffers = vertex_state
|
||||
.1
|
||||
.iter()
|
||||
.map(|&(stride, step_mode, ref attributes)| {
|
||||
wgt::VertexBufferDescriptor {
|
||||
stride,
|
||||
step_mode,
|
||||
attributes: attributes.as_slice(),
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let descriptor = wgpu_core::pipeline::RenderPipelineDescriptor {
|
||||
layout: pipeline_layout_id,
|
||||
vertex_stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
|
||||
module: vertex_module,
|
||||
entry_point: vertex_entry_point.as_str(),
|
||||
},
|
||||
fragment_stage,
|
||||
primitive_topology,
|
||||
rasterization_state: Some(rasterization_state),
|
||||
color_states: color_states.as_slice(),
|
||||
depth_stencil_state,
|
||||
vertex_state: wgt::VertexStateDescriptor {
|
||||
index_format: vertex_state.0,
|
||||
vertex_buffers: vert_buffers.as_slice(),
|
||||
},
|
||||
sample_count,
|
||||
sample_mask,
|
||||
alpha_to_coverage_enabled,
|
||||
};
|
||||
|
||||
let result = gfx_select!(render_pipeline_id =>
|
||||
global.device_create_render_pipeline(device_id, &descriptor, render_pipeline_id));
|
||||
if let Some(s_id) = scope_id {
|
||||
|
@ -1117,7 +995,7 @@ impl<'a> WGPU<'a> {
|
|||
self.present_buffer_maps.get(&buffer_id).unwrap().clone(),
|
||||
),
|
||||
};
|
||||
gfx_select!(buffer_id => global.buffer_map_async(buffer_id, 0..buffer_size, map_op));
|
||||
let _ = gfx_select!(buffer_id => global.buffer_map_async(buffer_id, 0..buffer_size, map_op));
|
||||
},
|
||||
WebGPURequest::UnmapBuffer {
|
||||
buffer_id,
|
||||
|
@ -1132,11 +1010,12 @@ impl<'a> WGPU<'a> {
|
|||
buffer_id,
|
||||
offset,
|
||||
wgt::BufferSize::new(size)
|
||||
));
|
||||
))
|
||||
.unwrap();
|
||||
unsafe { slice::from_raw_parts_mut(map_ptr, size as usize) }
|
||||
.copy_from_slice(&array_buffer);
|
||||
}
|
||||
gfx_select!(buffer_id => global.buffer_unmap(buffer_id));
|
||||
let _ = gfx_select!(buffer_id => global.buffer_unmap(buffer_id));
|
||||
},
|
||||
WebGPURequest::UpdateWebRenderData {
|
||||
buffer_id,
|
||||
|
@ -1145,7 +1024,8 @@ impl<'a> WGPU<'a> {
|
|||
} => {
|
||||
let global = &self.global;
|
||||
let data_pt = gfx_select!(buffer_id =>
|
||||
global.buffer_get_mapped_range(buffer_id, 0, None));
|
||||
global.buffer_get_mapped_range(buffer_id, 0, None))
|
||||
.unwrap();
|
||||
let data = unsafe { slice::from_raw_parts(data_pt, buffer_size) }.to_vec();
|
||||
if let Some(present_data) =
|
||||
self.wgpu_image_map.lock().unwrap().get_mut(&external_id)
|
||||
|
@ -1167,7 +1047,7 @@ impl<'a> WGPU<'a> {
|
|||
} else {
|
||||
warn!("Data not found for ExternalImageId({:?})", external_id);
|
||||
}
|
||||
gfx_select!(buffer_id => global.buffer_unmap(buffer_id));
|
||||
let _ = gfx_select!(buffer_id => global.buffer_unmap(buffer_id));
|
||||
self.present_buffer_maps.remove(&buffer_id);
|
||||
},
|
||||
WebGPURequest::WriteBuffer {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue