mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +00:00
Update WebGPU to mozilla-central from hg rev 0f1a8e4c6a76b3b0b16902c7fdfe2356c60ca351
This commit is contained in:
parent
4f937c04e1
commit
b5ba17012a
@ -726,9 +726,9 @@ WGPURawPass *wgpu_command_encoder_begin_compute_pass(WGPUCommandEncoderId encode
|
||||
/**
|
||||
* # Safety
|
||||
*
|
||||
* This function is unsafe as there is no guarantee that the given pointer
|
||||
* (`RenderPassDescriptor::color_attachments`) is valid for
|
||||
* `RenderPassDescriptor::color_attachments_length` elements.
|
||||
* This function is unsafe because improper use may lead to memory
|
||||
* problems. For example, a double-free may occur if the function is called
|
||||
* twice on the same raw pointer.
|
||||
*/
|
||||
WGPURawPass *wgpu_command_encoder_begin_render_pass(WGPUCommandEncoderId encoder_id,
|
||||
const WGPURenderPassDescriptor *desc);
|
||||
|
@ -40,7 +40,7 @@ enum ComputeCommand {
|
||||
}
|
||||
|
||||
impl super::RawPass {
|
||||
pub fn new_compute(parent: id::CommandEncoderId) -> Self {
|
||||
pub unsafe fn new_compute(parent: id::CommandEncoderId) -> Self {
|
||||
Self::from_vec(Vec::<ComputeCommand>::with_capacity(1), parent)
|
||||
}
|
||||
|
||||
|
@ -218,40 +218,6 @@ pub struct RawRenderTargets {
|
||||
pub depth_stencil: RenderPassDepthStencilAttachmentDescriptor,
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe as there is no guarantee that the given pointer
|
||||
/// (`RenderPassDescriptor::color_attachments`) is valid for
|
||||
/// `RenderPassDescriptor::color_attachments_length` elements.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass(
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &RenderPassDescriptor,
|
||||
) -> *mut RawPass {
|
||||
let mut targets = RawRenderTargets {
|
||||
depth_stencil: desc.depth_stencil_attachment
|
||||
.cloned()
|
||||
.unwrap_or_else(|| mem::zeroed()),
|
||||
colors: mem::zeroed(),
|
||||
};
|
||||
for (color, at) in targets.colors
|
||||
.iter_mut()
|
||||
.zip(slice::from_raw_parts(desc.color_attachments, desc.color_attachments_length))
|
||||
{
|
||||
*color = RawRenderPassColorAttachmentDescriptor {
|
||||
attachment: at.attachment,
|
||||
resolve_target: at.resolve_target.map_or(id::TextureViewId::ERROR, |rt| *rt),
|
||||
load_op: at.load_op,
|
||||
store_op: at.store_op,
|
||||
clear_color: at.clear_color,
|
||||
};
|
||||
}
|
||||
|
||||
let mut pass = RawPass::new_render(encoder_id);
|
||||
pass.encode(&targets);
|
||||
Box::into_raw(Box::new(pass))
|
||||
}
|
||||
|
||||
impl<F> Global<F> {
|
||||
pub fn command_encoder_finish<B: GfxBackend>(
|
||||
&self,
|
||||
|
@ -6,6 +6,7 @@ use crate::{
|
||||
command::{
|
||||
bind::{Binder, LayoutChange},
|
||||
PhantomSlice,
|
||||
RawRenderPassColorAttachmentDescriptor,
|
||||
RawRenderTargets,
|
||||
},
|
||||
conv,
|
||||
@ -39,6 +40,7 @@ use std::{
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ops::Range,
|
||||
slice,
|
||||
};
|
||||
|
||||
|
||||
@ -155,8 +157,30 @@ enum RenderCommand {
|
||||
}
|
||||
|
||||
impl super::RawPass {
|
||||
pub fn new_render(parent_id: id::CommandEncoderId) -> Self {
|
||||
Self::from_vec(Vec::<RenderCommand>::with_capacity(1), parent_id)
|
||||
pub unsafe fn new_render(parent_id: id::CommandEncoderId, desc: &RenderPassDescriptor) -> Self {
|
||||
let mut pass = Self::from_vec(Vec::<RenderCommand>::with_capacity(1), parent_id);
|
||||
|
||||
let mut targets = RawRenderTargets {
|
||||
depth_stencil: desc.depth_stencil_attachment
|
||||
.cloned()
|
||||
.unwrap_or_else(|| mem::zeroed()),
|
||||
colors: mem::zeroed(),
|
||||
};
|
||||
for (color, at) in targets.colors
|
||||
.iter_mut()
|
||||
.zip(slice::from_raw_parts(desc.color_attachments, desc.color_attachments_length))
|
||||
{
|
||||
*color = RawRenderPassColorAttachmentDescriptor {
|
||||
attachment: at.attachment,
|
||||
resolve_target: at.resolve_target.map_or(id::TextureViewId::ERROR, |rt| *rt),
|
||||
load_op: at.load_op,
|
||||
store_op: at.store_op,
|
||||
clear_color: at.clear_color,
|
||||
};
|
||||
}
|
||||
|
||||
pass.encode(&targets);
|
||||
pass
|
||||
}
|
||||
|
||||
pub unsafe fn finish_render(mut self) -> (Vec<u8>, id::CommandEncoderId) {
|
||||
@ -1365,9 +1389,4 @@ pub mod render_ffi {
|
||||
*length = pass.size();
|
||||
pass.base
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_render_pass_destroy(pass: *mut RawPass) {
|
||||
let _ = Box::from_raw(pass).into_vec();
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
use crate::GLOBAL;
|
||||
|
||||
pub use core::command::{
|
||||
wgpu_command_encoder_begin_render_pass,
|
||||
compute_ffi::*,
|
||||
render_ffi::*,
|
||||
};
|
||||
@ -82,6 +81,20 @@ pub extern "C" fn wgpu_command_encoder_copy_texture_to_texture(
|
||||
}
|
||||
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe because improper use may lead to memory
|
||||
/// problems. For example, a double-free may occur if the function is called
|
||||
/// twice on the same raw pointer.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass(
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &core::command::RenderPassDescriptor,
|
||||
) -> *mut core::command::RawPass {
|
||||
let pass = core::command::RawPass::new_render(encoder_id, desc);
|
||||
Box::into_raw(Box::new(pass))
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe because improper use may lead to memory
|
||||
@ -93,6 +106,11 @@ pub unsafe extern "C" fn wgpu_render_pass_end_pass(pass_id: id::RenderPassId) {
|
||||
gfx_select!(encoder_id => GLOBAL.command_encoder_run_render_pass(encoder_id, &pass_data))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_render_pass_destroy(pass: *mut core::command::RawPass) {
|
||||
let _ = Box::from_raw(pass).into_vec();
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe because improper use may lead to memory
|
||||
|
@ -9,7 +9,6 @@ use core::{
|
||||
};
|
||||
|
||||
pub use core::command::{
|
||||
wgpu_command_encoder_begin_render_pass,
|
||||
compute_ffi::*,
|
||||
render_ffi::*,
|
||||
};
|
||||
@ -32,6 +31,7 @@ struct IdentityHub {
|
||||
bind_groups: IdentityManager,
|
||||
shader_modules: IdentityManager,
|
||||
compute_pipelines: IdentityManager,
|
||||
render_pipelines: IdentityManager,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
@ -219,6 +219,19 @@ pub unsafe extern "C" fn wgpu_compute_pass_destroy(pass: core::command::RawPass)
|
||||
let _ = pass.into_vec();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_command_encoder_begin_render_pass(
|
||||
encoder_id: id::CommandEncoderId,
|
||||
desc: &core::command::RenderPassDescriptor,
|
||||
) -> core::command::RawPass {
|
||||
core::command::RawPass::new_render(encoder_id, desc)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_render_pass_destroy(pass: core::command::RawPass) {
|
||||
let _ = pass.into_vec();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_client_make_bind_group_layout_id(
|
||||
client: &Client,
|
||||
@ -353,3 +366,16 @@ pub extern "C" fn wgpu_client_kill_compute_pipeline_id(
|
||||
.compute_pipelines
|
||||
.free(id)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_client_kill_render_pipeline_id(
|
||||
client: &Client,
|
||||
id: id::RenderPipelineId,
|
||||
) {
|
||||
client
|
||||
.identities
|
||||
.lock()
|
||||
.select(id.backend())
|
||||
.render_pipelines
|
||||
.free(id)
|
||||
}
|
||||
|
@ -190,6 +190,11 @@ pub unsafe extern "C" fn wgpu_server_encoder_copy_buffer_to_buffer(
|
||||
gfx_select!(self_id => global.command_encoder_copy_buffer_to_buffer(self_id, source_id, source_offset, destination_id, destination_offset, size));
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// This function is unsafe as there is no guarantee that the given pointers are
|
||||
/// valid for `color_attachments_length` and `command_length` elements,
|
||||
/// respectively.
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wgpu_server_encode_compute_pass(
|
||||
global: &Global,
|
||||
@ -321,3 +326,11 @@ pub extern "C" fn wgpu_server_compute_pipeline_destroy(
|
||||
) {
|
||||
gfx_select!(self_id => global.compute_pipeline_destroy(self_id));
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wgpu_server_render_pipeline_destroy(
|
||||
global: &Global,
|
||||
self_id: id::RenderPipelineId,
|
||||
) {
|
||||
gfx_select!(self_id => global.render_pipeline_destroy(self_id));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user