diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /gfx/wgpu_bindings/src | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/wgpu_bindings/src')
-rw-r--r-- | gfx/wgpu_bindings/src/client.rs | 108 | ||||
-rw-r--r-- | gfx/wgpu_bindings/src/command.rs | 207 | ||||
-rw-r--r-- | gfx/wgpu_bindings/src/lib.rs | 4 | ||||
-rw-r--r-- | gfx/wgpu_bindings/src/server.rs | 22 |
4 files changed, 152 insertions, 189 deletions
diff --git a/gfx/wgpu_bindings/src/client.rs b/gfx/wgpu_bindings/src/client.rs index ae1a5ef5ea..15c41a2264 100644 --- a/gfx/wgpu_bindings/src/client.rs +++ b/gfx/wgpu_bindings/src/client.rs @@ -13,7 +13,6 @@ use crate::SwapChainId; use wgc::{id, identity::IdentityManager}; use wgt::{Backend, TextureFormat}; -pub use wgc::command::{compute_ffi::*, render_ffi::*}; use wgc::id::markers; use parking_lot::Mutex; @@ -38,16 +37,38 @@ fn make_byte_buf<T: serde::Serialize>(data: &T) -> ByteBuf { } #[repr(C)] +pub struct ConstantEntry { + key: RawString, + value: f64, +} + +#[repr(C)] pub struct ProgrammableStageDescriptor { module: id::ShaderModuleId, entry_point: RawString, + constants: *const ConstantEntry, + constants_length: usize, } impl ProgrammableStageDescriptor { fn to_wgpu(&self) -> wgc::pipeline::ProgrammableStageDescriptor { + let constants = make_slice(self.constants, self.constants_length) + .iter() + .map(|ce| { + ( + unsafe { std::ffi::CStr::from_ptr(ce.key) } + .to_str() + .unwrap() + .to_string(), + ce.value, + ) + }) + .collect(); wgc::pipeline::ProgrammableStageDescriptor { module: self.module, entry_point: cow_label(&self.entry_point), + constants: Cow::Owned(constants), + zero_initialize_workgroup_memory: true, } } } @@ -525,17 +546,9 @@ pub extern "C" fn wgpu_client_make_buffer_id( } #[no_mangle] -pub extern "C" fn wgpu_client_free_buffer_id( - client: &Client, - id: id::BufferId, -) { +pub extern "C" fn wgpu_client_free_buffer_id(client: &Client, id: id::BufferId) { let backend = id.backend(); - client - .identities - .lock() - .select(backend) - .buffers - .free(id) + client.identities.lock().select(backend).buffers.free(id) } #[no_mangle] @@ -569,20 +582,11 @@ pub extern "C" fn wgpu_client_create_texture( } #[no_mangle] -pub extern "C" fn wgpu_client_free_texture_id( - client: &Client, - id: id::TextureId, -) { +pub extern "C" fn wgpu_client_free_texture_id(client: &Client, id: id::TextureId) { let backend = id.backend(); - client - .identities - .lock() - .select(backend) - .textures - .free(id) + client.identities.lock().select(backend).textures.free(id) } - #[no_mangle] pub extern "C" fn wgpu_client_create_texture_view( client: &Client, @@ -619,10 +623,7 @@ pub extern "C" fn wgpu_client_create_texture_view( } #[no_mangle] -pub extern "C" fn wgpu_client_free_texture_view_id( - client: &Client, - id: id::TextureViewId, -) { +pub extern "C" fn wgpu_client_free_texture_view_id(client: &Client, id: id::TextureViewId) { let backend = id.backend(); client .identities @@ -667,17 +668,9 @@ pub extern "C" fn wgpu_client_create_sampler( } #[no_mangle] -pub extern "C" fn wgpu_client_free_sampler_id( - client: &Client, - id: id::SamplerId, -) { +pub extern "C" fn wgpu_client_free_sampler_id(client: &Client, id: id::SamplerId) { let backend = id.backend(); - client - .identities - .lock() - .select(backend) - .samplers - .free(id) + client.identities.lock().select(backend).samplers.free(id) } #[no_mangle] @@ -692,24 +685,20 @@ pub extern "C" fn wgpu_client_make_encoder_id( .select(backend) .command_buffers .process(backend) - .transmute() + .into_command_encoder_id() } #[no_mangle] -pub extern "C" fn wgpu_client_free_command_encoder_id( - client: &Client, - id: id::CommandEncoderId, -) { +pub extern "C" fn wgpu_client_free_command_encoder_id(client: &Client, id: id::CommandEncoderId) { let backend = id.backend(); client .identities .lock() .select(backend) .command_buffers - .free(id.transmute()) + .free(id.into_command_buffer_id()) } - #[no_mangle] pub extern "C" fn wgpu_client_create_command_encoder( client: &Client, @@ -726,7 +715,7 @@ pub extern "C" fn wgpu_client_create_command_encoder( .select(backend) .command_buffers .process(backend) - .transmute(); + .into_command_encoder_id(); let action = DeviceAction::CreateCommandEncoder(id, desc.map_label(|_| label)); *bb = make_byte_buf(&action); @@ -772,7 +761,6 @@ pub extern "C" fn wgpu_device_create_render_bundle_encoder( } } - #[no_mangle] pub unsafe extern "C" fn wgpu_render_bundle_encoder_destroy( pass: *mut wgc::command::RenderBundleEncoder, @@ -829,10 +817,7 @@ pub unsafe extern "C" fn wgpu_client_create_render_bundle_error( } #[no_mangle] -pub extern "C" fn wgpu_client_free_render_bundle_id( - client: &Client, - id: id::RenderBundleId, -) { +pub extern "C" fn wgpu_client_free_render_bundle_id(client: &Client, id: id::RenderBundleId) { let backend = id.backend(); client .identities @@ -1160,10 +1145,7 @@ pub unsafe extern "C" fn wgpu_client_create_pipeline_layout( } #[no_mangle] -pub extern "C" fn wgpu_client_free_pipeline_layout_id( - client: &Client, - id: id::PipelineLayoutId, -) { +pub extern "C" fn wgpu_client_free_pipeline_layout_id(client: &Client, id: id::PipelineLayoutId) { let backend = id.backend(); client .identities @@ -1221,10 +1203,7 @@ pub unsafe extern "C" fn wgpu_client_create_bind_group( } #[no_mangle] -pub extern "C" fn wgpu_client_free_bind_group_id( - client: &Client, - id: id::BindGroupId, -) { +pub extern "C" fn wgpu_client_free_bind_group_id(client: &Client, id: id::BindGroupId) { let backend = id.backend(); client .identities @@ -1249,10 +1228,7 @@ pub extern "C" fn wgpu_client_make_shader_module_id( } #[no_mangle] -pub extern "C" fn wgpu_client_free_shader_module_id( - client: &Client, - id: id::ShaderModuleId, -) { +pub extern "C" fn wgpu_client_free_shader_module_id(client: &Client, id: id::ShaderModuleId) { let backend = id.backend(); client .identities @@ -1304,10 +1280,7 @@ pub unsafe extern "C" fn wgpu_client_create_compute_pipeline( } #[no_mangle] -pub extern "C" fn wgpu_client_free_compute_pipeline_id( - client: &Client, - id: id::ComputePipelineId, -) { +pub extern "C" fn wgpu_client_free_compute_pipeline_id(client: &Client, id: id::ComputePipelineId) { let backend = id.backend(); client .identities @@ -1361,10 +1334,7 @@ pub unsafe extern "C" fn wgpu_client_create_render_pipeline( } #[no_mangle] -pub extern "C" fn wgpu_client_free_render_pipeline_id( - client: &Client, - id: id::RenderPipelineId, -) { +pub extern "C" fn wgpu_client_free_render_pipeline_id(client: &Client, id: id::RenderPipelineId) { let backend = id.backend(); client .identities diff --git a/gfx/wgpu_bindings/src/command.rs b/gfx/wgpu_bindings/src/command.rs index acba975c13..51da50f3a2 100644 --- a/gfx/wgpu_bindings/src/command.rs +++ b/gfx/wgpu_bindings/src/command.rs @@ -4,11 +4,18 @@ use crate::{id, RawString}; use std::{borrow::Cow, ffi, slice}; -use wgc::{command::{compute_ffi, render_ffi, ComputePassDescriptor, ComputePassTimestampWrites, RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor, RenderPassTimestampWrites}, id::CommandEncoderId}; +use wgc::{ + command::{ + compute_commands as compute_ffi, render_commands as render_ffi, ComputePassDescriptor, + ComputePassTimestampWrites, RenderPassColorAttachment, RenderPassDepthStencilAttachment, + RenderPassDescriptor, RenderPassTimestampWrites, + }, + id::CommandEncoderId, +}; use wgt::{BufferAddress, BufferSize, Color, DynamicOffset, IndexFormat}; -use serde::{Serialize, Deserialize}; use arrayvec::ArrayVec; +use serde::{Deserialize, Serialize}; /// A stream of commands for a render pass or compute pass. /// @@ -22,8 +29,7 @@ use arrayvec::ArrayVec; /// [`SetBindGroup`]: RenderCommand::SetBindGroup /// [`InsertDebugMarker`]: RenderCommand::InsertDebugMarker #[doc(hidden)] -#[derive(Debug)] -#[derive(serde::Serialize, serde::Deserialize)] +#[derive(Debug, serde::Serialize, serde::Deserialize)] pub struct BasePass<C> { pub label: Option<String>, @@ -90,8 +96,7 @@ impl RecordedComputePass { } #[doc(hidden)] -#[derive(Clone, Copy, Debug)] -#[derive(serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] pub enum RenderCommand { SetBindGroup { index: u32, @@ -114,11 +119,19 @@ pub enum RenderCommand { SetBlendConstant(Color), SetStencilReference(u32), SetViewport { - x: f32, y: f32, w: f32, h: f32, + x: f32, + y: f32, + w: f32, + h: f32, depth_min: f32, depth_max: f32, }, - SetScissor { x: u32, y: u32, w: u32, h: u32 }, + SetScissor { + x: u32, + y: u32, + w: u32, + h: u32, + }, Draw { vertex_count: u32, instance_count: u32, @@ -173,8 +186,7 @@ pub enum RenderCommand { } #[doc(hidden)] -#[derive(Clone, Copy, Debug)] -#[derive(serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] pub enum ComputeCommand { SetBindGroup { index: u32, @@ -219,7 +231,8 @@ pub unsafe extern "C" fn wgpu_recorded_render_pass_set_bind_group( offsets: *const DynamicOffset, offset_length: usize, ) { - pass.base.dynamic_offsets + pass.base + .dynamic_offsets .extend_from_slice(unsafe { slice::from_raw_parts(offsets, offset_length) }); pass.base.commands.push(RenderCommand::SetBindGroup { @@ -272,14 +285,20 @@ pub extern "C" fn wgpu_recorded_render_pass_set_index_buffer( } #[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_blend_constant(pass: &mut RecordedRenderPass, color: &Color) { +pub extern "C" fn wgpu_recorded_render_pass_set_blend_constant( + pass: &mut RecordedRenderPass, + color: &Color, +) { pass.base .commands .push(RenderCommand::SetBlendConstant(*color)); } #[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_set_stencil_reference(pass: &mut RecordedRenderPass, value: u32) { +pub extern "C" fn wgpu_recorded_render_pass_set_stencil_reference( + pass: &mut RecordedRenderPass, + value: u32, +) { pass.base .commands .push(RenderCommand::SetStencilReference(value)); @@ -296,7 +315,10 @@ pub extern "C" fn wgpu_recorded_render_pass_set_viewport( depth_max: f32, ) { pass.base.commands.push(RenderCommand::SetViewport { - x, y, w, h, + x, + y, + w, + h, depth_min, depth_max, }); @@ -534,7 +556,9 @@ pub extern "C" fn wgpu_recorded_render_pass_begin_pipeline_statistics_query( } #[no_mangle] -pub extern "C" fn wgpu_recorded_render_pass_end_pipeline_statistics_query(pass: &mut RecordedRenderPass) { +pub extern "C" fn wgpu_recorded_render_pass_end_pipeline_statistics_query( + pass: &mut RecordedRenderPass, +) { pass.base .commands .push(RenderCommand::EndPipelineStatisticsQuery); @@ -550,8 +574,7 @@ pub unsafe extern "C" fn wgpu_recorded_render_pass_execute_bundles( render_bundle_ids: *const id::RenderBundleId, render_bundle_ids_length: usize, ) { - for &bundle_id in - unsafe { slice::from_raw_parts(render_bundle_ids, render_bundle_ids_length) } + for &bundle_id in unsafe { slice::from_raw_parts(render_bundle_ids, render_bundle_ids_length) } { pass.base .commands @@ -571,7 +594,8 @@ pub unsafe extern "C" fn wgpu_recorded_compute_pass_set_bind_group( offsets: *const DynamicOffset, offset_length: usize, ) { - pass.base.dynamic_offsets + pass.base + .dynamic_offsets .extend_from_slice(unsafe { slice::from_raw_parts(offsets, offset_length) }); pass.base.commands.push(ComputeCommand::SetBindGroup { @@ -684,7 +708,9 @@ pub extern "C" fn wgpu_recorded_compute_pass_begin_pipeline_statistics_query( } #[no_mangle] -pub extern "C" fn wgpu_recorded_compute_pass_end_pipeline_statistics_query(pass: &mut RecordedComputePass) { +pub extern "C" fn wgpu_recorded_compute_pass_end_pipeline_statistics_query( + pass: &mut RecordedComputePass, +) { pass.base .commands .push(ComputeCommand::EndPipelineStatisticsQuery); @@ -692,9 +718,8 @@ pub extern "C" fn wgpu_recorded_compute_pass_end_pipeline_statistics_query(pass: pub fn replay_render_pass( id: CommandEncoderId, - src_pass: &RecordedRenderPass + src_pass: &RecordedRenderPass, ) -> wgc::command::RenderPass { - let mut dst_pass = wgc::command::RenderPass::new( id, &wgc::command::RenderPassDescriptor { @@ -726,15 +751,12 @@ pub fn replay_render_pass( bind_group_id, } => { let offsets = dynamic_offsets(num_dynamic_offsets); - unsafe { - render_ffi::wgpu_render_pass_set_bind_group( - &mut dst_pass, - index, - bind_group_id, - offsets.as_ptr(), - offsets.len(), - ); - } + render_ffi::wgpu_render_pass_set_bind_group( + &mut dst_pass, + index, + bind_group_id, + offsets, + ); } RenderCommand::SetPipeline(pipeline_id) => { render_ffi::wgpu_render_pass_set_pipeline(&mut dst_pass, pipeline_id); @@ -750,7 +772,7 @@ pub fn replay_render_pass( buffer_id, index_format, offset, - size + size, ); } RenderCommand::SetVertexBuffer { @@ -758,15 +780,13 @@ pub fn replay_render_pass( buffer_id, offset, size, - } => { - render_ffi::wgpu_render_pass_set_vertex_buffer( - &mut dst_pass, - slot, - buffer_id, - offset, - size - ) - } + } => render_ffi::wgpu_render_pass_set_vertex_buffer( + &mut dst_pass, + slot, + buffer_id, + offset, + size, + ), RenderCommand::SetBlendConstant(ref color) => { render_ffi::wgpu_render_pass_set_blend_constant(&mut dst_pass, color); } @@ -774,22 +794,25 @@ pub fn replay_render_pass( render_ffi::wgpu_render_pass_set_stencil_reference(&mut dst_pass, value); } RenderCommand::SetViewport { - x, y, w, h, + x, + y, + w, + h, depth_min, depth_max, } => { render_ffi::wgpu_render_pass_set_viewport( &mut dst_pass, - x, y, w, h, + x, + y, + w, + h, depth_min, depth_max, ); } RenderCommand::SetScissor { x, y, w, h } => { - render_ffi::wgpu_render_pass_set_scissor_rect( - &mut dst_pass, - x, y, w, h - ); + render_ffi::wgpu_render_pass_set_scissor_rect(&mut dst_pass, x, y, w, h); } RenderCommand::Draw { vertex_count, @@ -834,17 +857,17 @@ pub fn replay_render_pass( offset, count, ), - (false, None) => render_ffi::wgpu_render_pass_draw_indirect( - &mut dst_pass, - buffer_id, - offset, - ), - (true, Some(count)) => render_ffi::wgpu_render_pass_multi_draw_indexed_indirect( - &mut dst_pass, - buffer_id, - offset, - count, - ), + (false, None) => { + render_ffi::wgpu_render_pass_draw_indirect(&mut dst_pass, buffer_id, offset) + } + (true, Some(count)) => { + render_ffi::wgpu_render_pass_multi_draw_indexed_indirect( + &mut dst_pass, + buffer_id, + offset, + count, + ) + } (true, None) => render_ffi::wgpu_render_pass_draw_indexed_indirect( &mut dst_pass, buffer_id, @@ -882,28 +905,16 @@ pub fn replay_render_pass( } RenderCommand::PushDebugGroup { color, len } => { let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - render_ffi::wgpu_render_pass_push_debug_group( - &mut dst_pass, - label.as_ptr(), - color - ); - } + let label = std::str::from_utf8(label).unwrap(); + render_ffi::wgpu_render_pass_push_debug_group(&mut dst_pass, label, color); } RenderCommand::PopDebugGroup => { render_ffi::wgpu_render_pass_pop_debug_group(&mut dst_pass); } RenderCommand::InsertDebugMarker { color, len } => { let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - render_ffi::wgpu_render_pass_insert_debug_marker( - &mut dst_pass, - label.as_ptr(), - color, - ); - } + let label = std::str::from_utf8(label).unwrap(); + render_ffi::wgpu_render_pass_insert_debug_marker(&mut dst_pass, label, color); } RenderCommand::WriteTimestamp { query_set_id, @@ -916,10 +927,7 @@ pub fn replay_render_pass( ); } RenderCommand::BeginOcclusionQuery { query_index } => { - render_ffi::wgpu_render_pass_begin_occlusion_query( - &mut dst_pass, - query_index - ); + render_ffi::wgpu_render_pass_begin_occlusion_query(&mut dst_pass, query_index); } RenderCommand::EndOcclusionQuery => { render_ffi::wgpu_render_pass_end_occlusion_query(&mut dst_pass); @@ -938,13 +946,7 @@ pub fn replay_render_pass( render_ffi::wgpu_render_pass_end_pipeline_statistics_query(&mut dst_pass); } RenderCommand::ExecuteBundle(bundle_id) => { - unsafe { - render_ffi::wgpu_render_pass_execute_bundles( - &mut dst_pass, - &bundle_id, - 1, - ); - } + render_ffi::wgpu_render_pass_execute_bundles(&mut dst_pass, &[bundle_id]); } } } @@ -954,7 +956,7 @@ pub fn replay_render_pass( pub fn replay_compute_pass( id: CommandEncoderId, - src_pass: &RecordedComputePass + src_pass: &RecordedComputePass, ) -> wgc::command::ComputePass { let mut dst_pass = wgc::command::ComputePass::new( id, @@ -984,15 +986,12 @@ pub fn replay_compute_pass( bind_group_id, } => { let offsets = dynamic_offsets(num_dynamic_offsets); - unsafe { - compute_ffi::wgpu_compute_pass_set_bind_group( - &mut dst_pass, - index, - bind_group_id, - offsets.as_ptr(), - offsets.len() - ); - } + compute_ffi::wgpu_compute_pass_set_bind_group( + &mut dst_pass, + index, + bind_group_id, + offsets, + ); } ComputeCommand::SetPipeline(pipeline_id) => { compute_ffi::wgpu_compute_pass_set_pipeline(&mut dst_pass, pipeline_id) @@ -1009,28 +1008,16 @@ pub fn replay_compute_pass( } ComputeCommand::PushDebugGroup { color, len } => { let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - compute_ffi::wgpu_compute_pass_push_debug_group( - &mut dst_pass, - label.as_ptr(), - color - ); - } + let label = std::str::from_utf8(label).unwrap(); + compute_ffi::wgpu_compute_pass_push_debug_group(&mut dst_pass, label, color); } ComputeCommand::PopDebugGroup => { compute_ffi::wgpu_compute_pass_pop_debug_group(&mut dst_pass); } ComputeCommand::InsertDebugMarker { color, len } => { let label = strings(len); - let label = std::ffi::CString::new(label).unwrap(); - unsafe { - compute_ffi::wgpu_compute_pass_insert_debug_marker( - &mut dst_pass, - label.as_ptr(), - color, - ); - } + let label = std::str::from_utf8(label).unwrap(); + compute_ffi::wgpu_compute_pass_insert_debug_marker(&mut dst_pass, label, color); } ComputeCommand::WriteTimestamp { query_set_id, diff --git a/gfx/wgpu_bindings/src/lib.rs b/gfx/wgpu_bindings/src/lib.rs index 6e6b79c991..660b15bdc1 100644 --- a/gfx/wgpu_bindings/src/lib.rs +++ b/gfx/wgpu_bindings/src/lib.rs @@ -5,12 +5,10 @@ use crate::error::ErrorBufferType; use wgc::id; -pub use wgc::command::{compute_ffi::*, render_ffi::*}; - pub mod client; +pub mod command; pub mod error; pub mod server; -pub mod command; pub use wgc::device::trace::Command as CommandEncoderAction; diff --git a/gfx/wgpu_bindings/src/server.rs b/gfx/wgpu_bindings/src/server.rs index 1cedf35ea5..51936617fe 100644 --- a/gfx/wgpu_bindings/src/server.rs +++ b/gfx/wgpu_bindings/src/server.rs @@ -303,7 +303,7 @@ pub unsafe extern "C" fn wgpu_server_adapter_request_device( // TODO: in https://github.com/gfx-rs/wgpu/pull/3626/files#diff-033343814319f5a6bd781494692ea626f06f6c3acc0753a12c867b53a646c34eR97 // which introduced the queue id parameter, the queue id is also the device id. I don't know how applicable this is to // other situations (this one in particular). - let (_, _, error) = gfx_select!(self_id => global.adapter_request_device(self_id, &desc, trace_path, Some(new_id), Some(new_id.transmute()))); + let (_, _, error) = gfx_select!(self_id => global.adapter_request_device(self_id, &desc, trace_path, Some(new_id), Some(new_id.into_queue_id()))); if let Some(err) = error { error_buf.init(err); } @@ -342,7 +342,13 @@ impl ShaderModuleCompilationMessage { let utf16_offset; let utf16_length; - if let Some(location) = error.location(source) { + let location = match error { + CreateShaderModuleError::Parsing(e) => e.inner.location(source), + CreateShaderModuleError::Validation(e) => e.inner.location(source), + _ => None, + }; + + if let Some(location) = location { let len_utf16 = |s: &str| s.chars().map(|c| c.len_utf16() as u64).sum(); let start = location.offset as usize; let end = start + location.length as usize; @@ -945,11 +951,13 @@ impl Global { base, timestamp_writes, } => { - if let Err(err) = self.command_encoder_run_compute_pass_impl::<A>( - self_id, - base.as_ref(), - timestamp_writes.as_ref(), - ) { + if let Err(err) = self + .command_encoder_run_compute_pass_with_unresolved_commands::<A>( + self_id, + base.as_ref(), + timestamp_writes.as_ref(), + ) + { error_buf.init(err); } } |