mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-26 01:11:22 +01:00
[core] Make Global methods thin in transfer
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
1 parent
6b410aa5c3
commit
c5b16e1843
1 file changed
+126
-53
@@ -825,63 +825,56 @@ fn handle_buffer_init(
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_copy_buffer_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: BufferId,
|
||||
impl super::CommandEncoder {
|
||||
pub fn copy_buffer_to_buffer(
|
||||
self: &Arc<Self>,
|
||||
source: Arc<Buffer>,
|
||||
source_offset: BufferAddress,
|
||||
destination: BufferId,
|
||||
destination: Arc<Buffer>,
|
||||
destination_offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
profiling::scope!("CommandEncoder::copy_buffer_to_buffer");
|
||||
api_log!(
|
||||
"CommandEncoder::copy_buffer_to_buffer {source:?} -> {destination:?} {size:?}bytes"
|
||||
"CommandEncoder::copy_buffer_to_buffer {:?} -> {:?} {size:?}bytes",
|
||||
Arc::as_ptr(&source),
|
||||
Arc::as_ptr(&destination)
|
||||
);
|
||||
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let mut cmd_buf_data = cmd_enc.data.lock();
|
||||
let mut cmd_buf_data = self.data.lock();
|
||||
|
||||
cmd_buf_data.push_with(|| -> Result<_, CommandEncoderError> {
|
||||
let source_buffer = self.resolve_buffer_id(source);
|
||||
source_buffer.check_is_valid()?;
|
||||
let destination_buffer = self.resolve_buffer_id(destination);
|
||||
destination_buffer.check_is_valid()?;
|
||||
source.check_is_valid()?;
|
||||
destination.check_is_valid()?;
|
||||
Ok(ArcCommand::CopyBufferToBuffer {
|
||||
src: source_buffer,
|
||||
src: source,
|
||||
src_offset: source_offset,
|
||||
dst: destination_buffer,
|
||||
dst: destination,
|
||||
dst_offset: destination_offset,
|
||||
size,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_buffer_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &TexelCopyBufferInfo,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
pub fn copy_buffer_to_texture(
|
||||
self: &Arc<Self>,
|
||||
source: &wgt::TexelCopyBufferInfo<Arc<Buffer>>,
|
||||
destination: &wgt::TexelCopyTextureInfo<Arc<Texture>>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
profiling::scope!("CommandEncoder::copy_buffer_to_texture");
|
||||
api_log!(
|
||||
"CommandEncoder::copy_buffer_to_texture {:?} -> {:?} {copy_size:?}",
|
||||
source.buffer,
|
||||
destination.texture
|
||||
Arc::as_ptr(&source.buffer),
|
||||
Arc::as_ptr(&destination.texture)
|
||||
);
|
||||
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let mut cmd_buf_data = cmd_enc.data.lock();
|
||||
let mut cmd_buf_data = self.data.lock();
|
||||
|
||||
cmd_buf_data.push_with(|| -> Result<_, CommandEncoderError> {
|
||||
let texture = self.resolve_texture_id(destination.texture);
|
||||
let texture = destination.texture.clone();
|
||||
texture.check_valid()?;
|
||||
let source_buffer = self.resolve_buffer_id(source.buffer);
|
||||
let source_buffer = source.buffer.clone();
|
||||
source_buffer.check_is_valid()?;
|
||||
Ok(ArcCommand::CopyBufferToTexture {
|
||||
src: wgt::TexelCopyBufferInfo::<Arc<Buffer>> {
|
||||
@@ -899,28 +892,25 @@ impl Global {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &TexelCopyBufferInfo,
|
||||
pub fn copy_texture_to_buffer(
|
||||
self: &Arc<Self>,
|
||||
source: &wgt::TexelCopyTextureInfo<Arc<Texture>>,
|
||||
destination: &wgt::TexelCopyBufferInfo<Arc<Buffer>>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
profiling::scope!("CommandEncoder::copy_texture_to_buffer");
|
||||
api_log!(
|
||||
"CommandEncoder::copy_texture_to_buffer {:?} -> {:?} {copy_size:?}",
|
||||
source.texture,
|
||||
destination.buffer
|
||||
Arc::as_ptr(&source.texture),
|
||||
Arc::as_ptr(&destination.buffer)
|
||||
);
|
||||
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let mut cmd_buf_data = cmd_enc.data.lock();
|
||||
let mut cmd_buf_data = self.data.lock();
|
||||
|
||||
cmd_buf_data.push_with(|| -> Result<_, CommandEncoderError> {
|
||||
let texture = self.resolve_texture_id(source.texture);
|
||||
let texture = source.texture.clone();
|
||||
texture.check_valid()?;
|
||||
let destination_buffer = self.resolve_buffer_id(destination.buffer);
|
||||
let destination_buffer = destination.buffer.clone();
|
||||
destination_buffer.check_is_valid()?;
|
||||
Ok(ArcCommand::CopyTextureToBuffer {
|
||||
src: wgt::TexelCopyTextureInfo::<Arc<Texture>> {
|
||||
@@ -938,27 +928,24 @@ impl Global {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
pub fn copy_texture_to_texture(
|
||||
self: &Arc<Self>,
|
||||
source: &wgt::TexelCopyTextureInfo<Arc<Texture>>,
|
||||
destination: &wgt::TexelCopyTextureInfo<Arc<Texture>>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
profiling::scope!("CommandEncoder::copy_texture_to_texture");
|
||||
api_log!(
|
||||
"CommandEncoder::copy_texture_to_texture {:?} -> {:?} {copy_size:?}",
|
||||
source.texture,
|
||||
destination.texture
|
||||
Arc::as_ptr(&source.texture),
|
||||
Arc::as_ptr(&destination.texture)
|
||||
);
|
||||
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let mut cmd_buf_data = cmd_enc.data.lock();
|
||||
let mut cmd_buf_data = self.data.lock();
|
||||
|
||||
cmd_buf_data.push_with(|| -> Result<_, CommandEncoderError> {
|
||||
let src_texture = self.resolve_texture_id(source.texture);
|
||||
let dst_texture = self.resolve_texture_id(destination.texture);
|
||||
let src_texture = source.texture.clone();
|
||||
let dst_texture = destination.texture.clone();
|
||||
src_texture.check_valid()?;
|
||||
dst_texture.check_valid()?;
|
||||
Ok(ArcCommand::CopyTextureToTexture {
|
||||
@@ -980,6 +967,92 @@ impl Global {
|
||||
}
|
||||
}
|
||||
|
||||
impl Global {
|
||||
pub fn command_encoder_copy_buffer_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: BufferId,
|
||||
source_offset: BufferAddress,
|
||||
destination: BufferId,
|
||||
destination_offset: BufferAddress,
|
||||
size: Option<BufferAddress>,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let hub = &self.hub;
|
||||
|
||||
let cmd_enc = hub.command_encoders.get(command_encoder_id);
|
||||
let source = self.resolve_buffer_id(source);
|
||||
let destination = self.resolve_buffer_id(destination);
|
||||
cmd_enc.copy_buffer_to_buffer(source, source_offset, destination, destination_offset, size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_buffer_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &TexelCopyBufferInfo,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
let source = wgt::TexelCopyBufferInfo {
|
||||
buffer: self.resolve_buffer_id(source.buffer),
|
||||
layout: source.layout,
|
||||
};
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(destination.texture),
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
cmd_enc.copy_buffer_to_texture(&source, &destination, copy_size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_buffer(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &TexelCopyBufferInfo,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let source = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(source.texture),
|
||||
mip_level: source.mip_level,
|
||||
origin: source.origin,
|
||||
aspect: source.aspect,
|
||||
};
|
||||
let destination = wgt::TexelCopyBufferInfo {
|
||||
buffer: self.resolve_buffer_id(destination.buffer),
|
||||
layout: destination.layout,
|
||||
};
|
||||
cmd_enc.copy_texture_to_buffer(&source, &destination, copy_size)
|
||||
}
|
||||
|
||||
pub fn command_encoder_copy_texture_to_texture(
|
||||
&self,
|
||||
command_encoder_id: CommandEncoderId,
|
||||
source: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
destination: &wgt::TexelCopyTextureInfo<TextureId>,
|
||||
copy_size: &Extent3d,
|
||||
) -> Result<(), EncoderStateError> {
|
||||
let cmd_enc = self.hub.command_encoders.get(command_encoder_id);
|
||||
|
||||
let source = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(source.texture),
|
||||
mip_level: source.mip_level,
|
||||
origin: source.origin,
|
||||
aspect: source.aspect,
|
||||
};
|
||||
let destination = wgt::TexelCopyTextureInfo {
|
||||
texture: self.resolve_texture_id(destination.texture),
|
||||
mip_level: destination.mip_level,
|
||||
origin: destination.origin,
|
||||
aspect: destination.aspect,
|
||||
};
|
||||
cmd_enc.copy_texture_to_texture(&source, &destination, copy_size)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn copy_buffer_to_buffer(
|
||||
state: &mut EncodingState,
|
||||
src_buffer: &Arc<Buffer>,
|
||||
|
||||
Reference in new issue
Block a user