Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stencil/depth unification #247

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions blade-graphics/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,15 @@
if let crate::InitOp::Clear(color) = rt.init_op {
self.commands.push(super::Command::ClearDepthStencil {
depth: if rt.view.aspects.contains(crate::TexelAspects::DEPTH) {
Some(match color {
crate::TextureColor::White => 1.0,
_ => 0.0,
})
Some(color.depth_clear_value())
} else {
None
},
stencil: if rt.view.aspects.contains(crate::TexelAspects::STENCIL) {
Some(color.stencil_clear_value())
} else {
None
},
stencil: None, //TODO
});
}
}
Expand Down Expand Up @@ -309,7 +310,7 @@
.push(super::Command::SetViewport(viewport.clone()));
}

fn set_stencil_reference(&mut self, reference: u32) {

Check warning on line 313 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `reference`

Check warning on line 313 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `reference`
unimplemented!()
}
}
Expand Down Expand Up @@ -473,7 +474,7 @@
.push(super::Command::SetViewport(viewport.clone()));
}

fn set_stencil_reference(&mut self, reference: u32) {

Check warning on line 477 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `reference`

Check warning on line 477 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `reference`
unimplemented!()
}
}
Expand Down Expand Up @@ -829,10 +830,10 @@
gl.bind_buffer(glow::PIXEL_UNPACK_BUFFER, None);
}
Self::CopyTextureToBuffer {
ref src,

Check warning on line 833 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `src`

Check warning on line 833 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `src`
ref dst,

Check warning on line 834 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `dst`

Check warning on line 834 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `dst`
bytes_per_row,

Check warning on line 835 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `bytes_per_row`

Check warning on line 835 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `bytes_per_row`
ref size,

Check warning on line 836 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `size`

Check warning on line 836 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `size`
} => unimplemented!(),
Self::ResetFramebuffer => {
for &attachment in COLOR_ATTACHMENTS.iter() {
Expand Down Expand Up @@ -1056,9 +1057,9 @@
gl.scissor(rect.x, rect.y, rect.w as i32, rect.h as i32);
}
Self::SetStencilFunc {
face,

Check warning on line 1060 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `face`

Check warning on line 1060 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `face`
function,

Check warning on line 1061 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `function`

Check warning on line 1061 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `function`
reference,

Check warning on line 1062 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Web, ubuntu-latest, wasm32-unknown-unknown, false)

unused variable: `reference`

Check warning on line 1062 in blade-graphics/src/gles/command.rs

View workflow job for this annotation

GitHub Actions / build (Linux, ubuntu-latest, x86_64-unknown-linux-gnu, true)

unused variable: `reference`
read_mask,
} => unimplemented!(),
Self::SetStencilOps {
Expand Down
2 changes: 1 addition & 1 deletion blade-graphics/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl super::Context {
let window_ptr = handle.ns_view.as_ptr();
#[cfg(target_os = "macos")]
let window_ptr = unsafe {
use objc::{msg_send, runtime::Object, sel, sel_impl};
use objc2::{msg_send, runtime::Object};
// ns_view always have a layer and don't need to verify that it exists.
let layer: *mut Object =
msg_send![handle.ns_view.as_ptr() as *mut Object, layer];
Expand Down
14 changes: 3 additions & 11 deletions blade-graphics/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,8 @@ impl super::CommandEncoder {
let load_action = match rt.init_op {
crate::InitOp::Load => metal::MTLLoadAction::Load,
crate::InitOp::Clear(color) => {
let clear_depth = match color {
crate::TextureColor::TransparentBlack
| crate::TextureColor::OpaqueBlack => 0.0,
crate::TextureColor::White => 1.0,
};
at_descriptor.setClearDepth(clear_depth);
let clear_depth = color.depth_clear_value();
at_descriptor.setClearDepth(clear_depth as f64);
metal::MTLLoadAction::Clear
}
crate::InitOp::DontCare => metal::MTLLoadAction::DontCare,
Expand All @@ -290,11 +286,7 @@ impl super::CommandEncoder {
let load_action = match rt.init_op {
crate::InitOp::Load => metal::MTLLoadAction::Load,
crate::InitOp::Clear(color) => {
let clear_stencil = match color {
crate::TextureColor::TransparentBlack
| crate::TextureColor::OpaqueBlack => 0,
crate::TextureColor::White => !0,
};
let clear_stencil = color.stencil_clear_value();
at_descriptor.setClearStencil(clear_stencil);
metal::MTLLoadAction::Clear
}
Expand Down
18 changes: 18 additions & 0 deletions blade-graphics/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ impl super::TextureFormat {
}
}

impl super::TextureColor {
pub fn stencil_clear_value(&self) -> u32 {
match self {
crate::TextureColor::TransparentBlack => 0,
crate::TextureColor::OpaqueBlack => !0,
crate::TextureColor::White => !0,
}
}

pub fn depth_clear_value(&self) -> f32 {
match self {
crate::TextureColor::TransparentBlack => 0.0,
crate::TextureColor::OpaqueBlack => 0.0,
crate::TextureColor::White => 1.0,
}
}
}

impl super::ComputePipeline {
/// Return the dispatch group counts sufficient to cover the given extent.
pub fn get_dispatch_for(&self, extent: super::Extent) -> [u32; 3] {
Expand Down
19 changes: 6 additions & 13 deletions blade-graphics/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ fn map_render_target(rt: &crate::RenderTarget) -> vk::RenderingAttachmentInfo<'s
let cv = if rt.view.aspects.contains(crate::TexelAspects::COLOR) {
vk::ClearValue {
color: match color {
crate::TextureColor::TransparentBlack => vk::ClearColorValue::default(),
crate::TextureColor::TransparentBlack => {
vk::ClearColorValue { float32: [0.0; 4] }
}
crate::TextureColor::OpaqueBlack => vk::ClearColorValue {
float32: [0.0, 0.0, 0.0, 1.0],
},
Expand All @@ -180,18 +182,9 @@ fn map_render_target(rt: &crate::RenderTarget) -> vk::RenderingAttachmentInfo<'s
}
} else {
vk::ClearValue {
depth_stencil: match color {
crate::TextureColor::TransparentBlack => {
vk::ClearDepthStencilValue::default()
}
crate::TextureColor::OpaqueBlack => vk::ClearDepthStencilValue {
depth: 1.0,
stencil: 0,
},
crate::TextureColor::White => vk::ClearDepthStencilValue {
depth: 1.0,
stencil: !0,
},
depth_stencil: vk::ClearDepthStencilValue {
depth: color.depth_clear_value(),
stencil: color.stencil_clear_value(),
},
}
};
Expand Down
Loading