diff --git a/wgpu-bindings/wgpu.h b/wgpu-bindings/wgpu.h index cbfcc4508..11fc5b373 100644 --- a/wgpu-bindings/wgpu.h +++ b/wgpu-bindings/wgpu.h @@ -284,7 +284,8 @@ typedef struct { #define WGPUWHITE (Color){ .r = 1, .g = 1, .b = 1, .a = 1 } -WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, WGPUDeviceDescriptor _desc); +WGPUDeviceId wgpu_adapter_create_device(WGPUAdapterId adapter_id, + const WGPUDeviceDescriptor *_desc); WGPUComputePassId wgpu_command_buffer_begin_compute_pass(WGPUCommandBufferId command_buffer_id); @@ -296,34 +297,35 @@ WGPUCommandBufferId wgpu_compute_pass_end_pass(WGPUComputePassId pass_id); WGPUInstanceId wgpu_create_instance(void); WGPUAttachmentStateId wgpu_device_create_attachment_state(WGPUDeviceId device_id, - WGPUAttachmentStateDescriptor desc); + const WGPUAttachmentStateDescriptor *desc); WGPUBindGroupLayoutId wgpu_device_create_bind_group_layout(WGPUDeviceId device_id, - WGPUBindGroupLayoutDescriptor desc); + const WGPUBindGroupLayoutDescriptor *desc); WGPUBlendStateId wgpu_device_create_blend_state(WGPUDeviceId _device_id, - WGPUBlendStateDescriptor desc); + const WGPUBlendStateDescriptor *desc); WGPUCommandBufferId wgpu_device_create_command_buffer(WGPUDeviceId device_id, - WGPUCommandBufferDescriptor _desc); + const WGPUCommandBufferDescriptor *_desc); WGPUDepthStencilStateId wgpu_device_create_depth_stencil_state(WGPUDeviceId _device_id, - WGPUDepthStencilStateDescriptor desc); + const WGPUDepthStencilStateDescriptor *desc); WGPUPipelineLayoutId wgpu_device_create_pipeline_layout(WGPUDeviceId device_id, - WGPUPipelineLayoutDescriptor desc); + const WGPUPipelineLayoutDescriptor *desc); WGPURenderPipelineId wgpu_device_create_render_pipeline(WGPUDeviceId device_id, - WGPURenderPipelineDescriptor desc); + const WGPURenderPipelineDescriptor *desc); WGPUShaderModuleId wgpu_device_create_shader_module(WGPUDeviceId device_id, - WGPUShaderModuleDescriptor desc); + const WGPUShaderModuleDescriptor *desc); -WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, WGPUTextureDescriptor desc); +WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc); WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id); -WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id, WGPUAdapterDescriptor desc); +WGPUAdapterId wgpu_instance_get_adapter(WGPUInstanceId instance_id, + const WGPUAdapterDescriptor *desc); void wgpu_queue_submit(WGPUQueueId queue_id, const WGPUCommandBufferId *command_buffer_ptr, diff --git a/wgpu-native/src/conv.rs b/wgpu-native/src/conv.rs index d2c977ed8..f467fbeb5 100644 --- a/wgpu-native/src/conv.rs +++ b/wgpu-native/src/conv.rs @@ -88,13 +88,13 @@ pub(crate) fn map_primitive_topology( } pub(crate) fn map_blend_state_descriptor( - desc: pipeline::BlendStateDescriptor, + desc: &pipeline::BlendStateDescriptor, ) -> hal::pso::ColorBlendDesc { let color_mask = desc.write_mask; let blend_state = match desc.blend_enabled { true => hal::pso::BlendState::On { - color: map_blend_descriptor(desc.color), - alpha: map_blend_descriptor(desc.alpha), + color: map_blend_descriptor(&desc.color), + alpha: map_blend_descriptor(&desc.alpha), }, false => hal::pso::BlendState::Off, }; @@ -122,7 +122,7 @@ fn map_color_write_flags(flags: u32) -> hal::pso::ColorMask { value } -fn map_blend_descriptor(blend_desc: pipeline::BlendDescriptor) -> hal::pso::BlendOp { +fn map_blend_descriptor(blend_desc: &pipeline::BlendDescriptor) -> hal::pso::BlendOp { use hal::pso::BlendOp as H; use pipeline::BlendOperation::*; match blend_desc.operation { @@ -164,7 +164,7 @@ fn map_blend_factor(blend_factor: pipeline::BlendFactor) -> hal::pso::Factor { } pub(crate) fn map_depth_stencil_state( - desc: pipeline::DepthStencilStateDescriptor, + desc: &pipeline::DepthStencilStateDescriptor, ) -> hal::pso::DepthStencilDesc { hal::pso::DepthStencilDesc { // TODO DepthTest::Off? @@ -175,14 +175,14 @@ pub(crate) fn map_depth_stencil_state( depth_bounds: false, // TODO // TODO StencilTest::Off? stencil: hal::pso::StencilTest::On { - front: map_stencil_face(desc.front, desc.stencil_read_mask, desc.stencil_write_mask), - back: map_stencil_face(desc.back, desc.stencil_read_mask, desc.stencil_write_mask), + front: map_stencil_face(&desc.front, desc.stencil_read_mask, desc.stencil_write_mask), + back: map_stencil_face(&desc.back, desc.stencil_read_mask, desc.stencil_write_mask), }, } } fn map_stencil_face( - stencil_state_face_desc: pipeline::StencilStateFaceDescriptor, + stencil_state_face_desc: &pipeline::StencilStateFaceDescriptor, stencil_read_mask: u32, stencil_write_mask: u32, ) -> hal::pso::StencilFace { diff --git a/wgpu-native/src/device.rs b/wgpu-native/src/device.rs index 79796efc7..b9941a819 100644 --- a/wgpu-native/src/device.rs +++ b/wgpu-native/src/device.rs @@ -65,7 +65,7 @@ pub(crate) struct ShaderModule { #[no_mangle] pub extern "C" fn wgpu_device_create_texture( device_id: DeviceId, - desc: resource::TextureDescriptor, + desc: &resource::TextureDescriptor, ) -> TextureId { let kind = conv::map_texture_dimension_size(desc.dimension, desc.size); let format = conv::map_texture_format(desc.format); @@ -111,7 +111,7 @@ pub extern "C" fn wgpu_device_create_texture( #[no_mangle] pub extern "C" fn wgpu_device_create_bind_group_layout( device_id: DeviceId, - desc: binding_model::BindGroupLayoutDescriptor, + desc: &binding_model::BindGroupLayoutDescriptor, ) -> BindGroupLayoutId { let bindings = unsafe { slice::from_raw_parts(desc.bindings, desc.bindings_length) }; @@ -142,7 +142,7 @@ pub extern "C" fn wgpu_device_create_bind_group_layout( #[no_mangle] pub extern "C" fn wgpu_device_create_pipeline_layout( device_id: DeviceId, - desc: binding_model::PipelineLayoutDescriptor, + desc: &binding_model::PipelineLayoutDescriptor, ) -> PipelineLayoutId { let bind_group_layouts = unsafe { slice::from_raw_parts(desc.bind_group_layouts, desc.bind_group_layouts_length) @@ -169,7 +169,7 @@ pub extern "C" fn wgpu_device_create_pipeline_layout( #[no_mangle] pub extern "C" fn wgpu_device_create_blend_state( _device_id: DeviceId, - desc: pipeline::BlendStateDescriptor, + desc: &pipeline::BlendStateDescriptor, ) -> BlendStateId { HUB.blend_states .lock() @@ -181,7 +181,7 @@ pub extern "C" fn wgpu_device_create_blend_state( #[no_mangle] pub extern "C" fn wgpu_device_create_depth_stencil_state( _device_id: DeviceId, - desc: pipeline::DepthStencilStateDescriptor, + desc: &pipeline::DepthStencilStateDescriptor, ) -> DepthStencilStateId { HUB.depth_stencil_states .lock() @@ -193,7 +193,7 @@ pub extern "C" fn wgpu_device_create_depth_stencil_state( #[no_mangle] pub extern "C" fn wgpu_device_create_shader_module( device_id: DeviceId, - desc: pipeline::ShaderModuleDescriptor, + desc: &pipeline::ShaderModuleDescriptor, ) -> ShaderModuleId { let spv = unsafe { slice::from_raw_parts(desc.code.bytes, desc.code.length) @@ -213,7 +213,7 @@ pub extern "C" fn wgpu_device_create_shader_module( #[no_mangle] pub extern "C" fn wgpu_device_create_command_buffer( device_id: DeviceId, - _desc: command::CommandBufferDescriptor, + _desc: &command::CommandBufferDescriptor, ) -> CommandBufferId { let mut device_guard = HUB.devices.lock(); let device = device_guard.get_mut(device_id); @@ -286,7 +286,7 @@ pub extern "C" fn wgpu_queue_submit( #[no_mangle] pub extern "C" fn wgpu_device_create_attachment_state( device_id: DeviceId, - desc: pipeline::AttachmentStateDescriptor, + desc: &pipeline::AttachmentStateDescriptor, ) -> AttachmentStateId { let device_guard = HUB.devices.lock(); let device = &device_guard.get(device_id).raw; @@ -339,7 +339,7 @@ pub extern "C" fn wgpu_device_create_attachment_state( #[no_mangle] pub extern "C" fn wgpu_device_create_render_pipeline( device_id: DeviceId, - desc: pipeline::RenderPipelineDescriptor, + desc: &pipeline::RenderPipelineDescriptor, ) -> RenderPipelineId { // TODO let extent = hal::window::Extent2D { diff --git a/wgpu-native/src/instance.rs b/wgpu-native/src/instance.rs index 5217bae11..2c2ad3e14 100644 --- a/wgpu-native/src/instance.rs +++ b/wgpu-native/src/instance.rs @@ -50,7 +50,7 @@ pub extern "C" fn wgpu_create_instance() -> InstanceId { #[no_mangle] pub extern "C" fn wgpu_instance_get_adapter( instance_id: InstanceId, - desc: AdapterDescriptor, + desc: &AdapterDescriptor, ) -> AdapterId { let instance_guard = HUB.instances.lock(); let instance = instance_guard.get(instance_id); @@ -75,7 +75,7 @@ pub extern "C" fn wgpu_instance_get_adapter( #[no_mangle] pub extern "C" fn wgpu_adapter_create_device( adapter_id: AdapterId, - _desc: DeviceDescriptor, + _desc: &DeviceDescriptor, ) -> DeviceId { let mut adapter_guard = HUB.adapters.lock(); let adapter = adapter_guard.get_mut(adapter_id); diff --git a/wgpu-rs/src/lib.rs b/wgpu-rs/src/lib.rs index 3daa29907..2efffe217 100644 --- a/wgpu-rs/src/lib.rs +++ b/wgpu-rs/src/lib.rs @@ -120,7 +120,7 @@ impl Instance { } } - pub fn get_adapter(&self, desc: AdapterDescriptor) -> Adapter { + pub fn get_adapter(&self, desc: &AdapterDescriptor) -> Adapter { Adapter { id: wgn::wgpu_instance_get_adapter(self.id, desc), } @@ -128,7 +128,7 @@ impl Instance { } impl Adapter { - pub fn create_device(&self, desc: DeviceDescriptor) -> Device { + pub fn create_device(&self, desc: &DeviceDescriptor) -> Device { Device { id: wgn::wgpu_adapter_create_device(self.id, desc), } @@ -154,13 +154,13 @@ impl Device { } } - pub fn create_command_buffer(&self, desc: CommandBufferDescriptor) -> CommandBuffer { + pub fn create_command_buffer(&self, desc: &CommandBufferDescriptor) -> CommandBuffer { CommandBuffer { id: wgn::wgpu_device_create_command_buffer(self.id, desc), } } - pub fn create_bind_group_layout(&self, desc: BindGroupLayoutDescriptor) -> BindGroupLayout { + pub fn create_bind_group_layout(&self, desc: &BindGroupLayoutDescriptor) -> BindGroupLayout { BindGroupLayout { id: wgn::wgpu_device_create_bind_group_layout(self.id, wgn::BindGroupLayoutDescriptor { bindings: desc.bindings.as_ptr(), @@ -169,7 +169,7 @@ impl Device { } } - pub fn create_pipeline_layout(&self, desc: PipelineLayoutDescriptor) -> PipelineLayout { + pub fn create_pipeline_layout(&self, desc: &PipelineLayoutDescriptor) -> PipelineLayout { PipelineLayout { id: wgn::wgpu_device_create_pipeline_layout(self.id, wgn::PipelineLayoutDescriptor { bind_group_layouts: desc.bind_group_layouts.as_ptr() as *const _, @@ -178,19 +178,19 @@ impl Device { } } - pub fn create_blend_state(&self, desc: BlendStateDescriptor) -> BlendState { + pub fn create_blend_state(&self, desc: &BlendStateDescriptor) -> BlendState { BlendState { id: wgn::wgpu_device_create_blend_state(self.id, desc), } } - pub fn create_depth_stencil_state(&self, desc: DepthStencilStateDescriptor) -> DepthStencilState { + pub fn create_depth_stencil_state(&self, desc: &DepthStencilStateDescriptor) -> DepthStencilState { DepthStencilState { id: wgn::wgpu_device_create_depth_stencil_state(self.id, desc), } } - pub fn create_attachment_state(&self, desc: AttachmentStateDescriptor) -> AttachmentState { + pub fn create_attachment_state(&self, desc: &AttachmentStateDescriptor) -> AttachmentState { AttachmentState { id: wgn::wgpu_device_create_attachment_state(self.id, wgn::AttachmentStateDescriptor { formats: desc.formats.as_ptr(), @@ -199,7 +199,7 @@ impl Device { } } - pub fn create_render_pipeline(&self, desc: RenderPipelineDescriptor) -> RenderPipeline { + pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor) -> RenderPipeline { let entry_points = desc.stages .iter() .map(|ps| CString::new(ps.entry_point).unwrap()) @@ -230,7 +230,7 @@ impl Device { } impl CommandBuffer { - pub fn begin_render_pass(&mut self, desc: RenderPassDescriptor<&TextureView>) -> RenderPass { + pub fn begin_render_pass(&mut self, desc: &RenderPassDescriptor<&TextureView>) -> RenderPass { let colors = desc.color_attachments .iter() .map(|ca| RenderPassColorAttachmentDescriptor {