Skip to content

Commit

Permalink
basic clear_texture impl for vulkan
Browse files Browse the repository at this point in the history
lots of todos and unknowns
  • Loading branch information
Wumpf committed Aug 21, 2021
1 parent 70fd71b commit 8dda966
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
8 changes: 8 additions & 0 deletions wgpu-hal/src/dx12/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
}
}

unsafe fn clear_texture(
&mut self,
texture: &super::Texture,
ranges: &[wgt::ImageSubresourceRange],
) {
// TODO
}

unsafe fn copy_buffer_to_buffer<T>(
&mut self,
src: &super::Buffer,
Expand Down
2 changes: 2 additions & 0 deletions wgpu-hal/src/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ impl crate::CommandEncoder<Api> for Encoder {

unsafe fn fill_buffer(&mut self, buffer: &Resource, range: crate::MemoryRange, value: u8) {}

unsafe fn clear_texture(&mut self, texture: &Resource, ranges: &[wgt::ImageSubresourceRange]) {}

unsafe fn copy_buffer_to_buffer<T>(&mut self, src: &Resource, dst: &Resource, regions: T) {}

unsafe fn copy_texture_to_texture<T>(
Expand Down
8 changes: 8 additions & 0 deletions wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
});
}

unsafe fn clear_texture(
&mut self,
texture: &super::Texture,
ranges: &[wgt::ImageSubresourceRange],
) {
// TODO
}

unsafe fn copy_buffer_to_buffer<T>(
&mut self,
src: &super::Buffer,
Expand Down
8 changes: 8 additions & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@ pub trait CommandEncoder<A: Api>: Send + Sync {
/// Otherwise `wgt::Features::CLEAR_COMMANDS` is required.
unsafe fn fill_buffer(&mut self, buffer: &A::Buffer, range: MemoryRange, value: u8);

/// Clears all aspects of a texture.
/// Note: Current usage has to be `TextureUses::COPY_DST`.
unsafe fn clear_texture(
&mut self,
texture: &A::Texture,
subresource_ranges: &[wgt::ImageSubresourceRange],
);

unsafe fn copy_buffer_to_buffer<T>(&mut self, src: &A::Buffer, dst: &A::Buffer, regions: T)
where
T: Iterator<Item = BufferCopy>;
Expand Down
8 changes: 8 additions & 0 deletions wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
encoder.fill_buffer(&buffer.raw, conv::map_range(&range), value);
}

unsafe fn clear_texture(
&mut self,
texture: &super::Texture,
ranges: &[wgt::ImageSubresourceRange],
) {
// TODO
}

unsafe fn copy_buffer_to_buffer<T>(
&mut self,
src: &super::Buffer,
Expand Down
29 changes: 29 additions & 0 deletions wgpu-hal/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,35 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
);
}

unsafe fn clear_texture(
&mut self,
texture: &super::Texture,
ranges: &[wgt::ImageSubresourceRange],
) {
let ranges = ranges
.iter()
.map(|r| conv::map_subresource_range(r, texture.aspects))
.collect::<Vec<vk::ImageSubresourceRange>>();

if texture.aspects.contains(crate::FormatAspects::COLOR) {
self.device.raw.cmd_clear_color_image(
self.active,
texture.raw,
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
&vk::ClearColorValue::default(),
&ranges,
);
} else {
self.device.raw.cmd_clear_depth_stencil_image(
self.active,
texture.raw,
vk::ImageLayout::TRANSFER_DST_OPTIMAL,
&vk::ClearDepthStencilValue::default(),
&ranges,
);
}
}

unsafe fn copy_buffer_to_buffer<T>(
&mut self,
src: &super::Buffer,
Expand Down

0 comments on commit 8dda966

Please sign in to comment.