Skip to content

Commit

Permalink
Merge #2224
Browse files Browse the repository at this point in the history
2224: [mtl] dynamic depth bias, callback coalescence, and more stats r=grovesNL a=kvark

Fixes #2170

Expands our Metal stats to report the number of active and temporary command buffers. Coalesces the completion handlers, and finally fixes the depth bias issue we've been seeing (HAL breaking change).

PR checklist:
- [x] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [x] tested examples with the following backends:


Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
  • Loading branch information
bors[bot] and kvark committed Jul 16, 2018
2 parents d07a03b + b6fc043 commit 45a72f6
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 118 deletions.
12 changes: 8 additions & 4 deletions src/backend/dx11/src/conv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hal::format::{Format};
use hal::pso::{
BlendDesc, BlendOp, BlendState, ColorBlendDesc, Comparison, DepthStencilDesc,
BlendDesc, BlendOp, BlendState, ColorBlendDesc, Comparison, DepthBias, DepthStencilDesc,
DepthTest, Face, Factor, PolygonMode, Rasterizer, Rect, StencilFace, StencilOp, StencilTest,
Viewport, Stage, State, StencilValue, FrontFace,
};
Expand Down Expand Up @@ -271,16 +271,20 @@ fn map_cull_mode(mode: Face) -> D3D11_CULL_MODE {
}

pub(crate) fn map_rasterizer_desc(desc: &Rasterizer) -> D3D11_RASTERIZER_DESC {
let bias = match desc.depth_bias { //TODO: support dynamic depth bias
Some(State::Static(db)) => db,
Some(_) | None => DepthBias::default(),
};
D3D11_RASTERIZER_DESC {
FillMode: map_fill_mode(desc.polygon_mode),
CullMode: map_cull_mode(desc.cull_face),
FrontCounterClockwise: match desc.front_face {
FrontFace::Clockwise => FALSE,
FrontFace::CounterClockwise => TRUE,
},
DepthBias: desc.depth_bias.map_or(0, |bias| bias.const_factor as INT),
DepthBiasClamp: desc.depth_bias.map_or(0.0, |bias| bias.clamp),
SlopeScaledDepthBias: desc.depth_bias.map_or(0.0, |bias| bias.slope_factor),
DepthBias: bias.const_factor as INT,
DepthBiasClamp: bias.clamp,
SlopeScaledDepthBias: bias.slope_factor,
DepthClipEnable: !desc.depth_clamping as _,
// TODO:
ScissorEnable: TRUE,
Expand Down
11 changes: 8 additions & 3 deletions src/backend/dx12/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ pub fn map_rasterizer(rasterizer: &pso::Rasterizer) -> D3D12_RASTERIZER_DESC {
use hal::pso::PolygonMode::*;
use hal::pso::FrontFace::*;

let bias = match rasterizer.depth_bias { //TODO: support dynamic depth bias
Some(pso::State::Static(db)) => db,
Some(_) | None => pso::DepthBias::default(),
};

D3D12_RASTERIZER_DESC {
FillMode: match rasterizer.polygon_mode {
Point => {
Expand All @@ -172,9 +177,9 @@ pub fn map_rasterizer(rasterizer: &pso::Rasterizer) -> D3D12_RASTERIZER_DESC {
Clockwise => FALSE,
CounterClockwise => TRUE,
},
DepthBias: rasterizer.depth_bias.map_or(0, |bias| bias.const_factor as INT),
DepthBiasClamp: rasterizer.depth_bias.map_or(0.0, |bias| bias.clamp),
SlopeScaledDepthBias: rasterizer.depth_bias.map_or(0.0, |bias| bias.slope_factor),
DepthBias: bias.const_factor as INT,
DepthBiasClamp: bias.clamp,
SlopeScaledDepthBias: bias.slope_factor,
DepthClipEnable: !rasterizer.depth_clamping as _,
MultisampleEnable: FALSE, // TODO: currently not supported
ForcedSampleCount: 0, // TODO: currently not supported
Expand Down
6 changes: 3 additions & 3 deletions src/backend/gl/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hal::pso;
use gl;
use smallvec::SmallVec;

pub fn bind_polygon_mode(gl: &gl::Gl, mode: pso::PolygonMode, bias: Option<pso::DepthBias>) {
pub fn bind_polygon_mode(gl: &gl::Gl, mode: pso::PolygonMode, bias: Option<pso::State<pso::DepthBias>>) {
use hal::pso::PolygonMode::*;

let (gl_draw, gl_offset) = match mode {
Expand All @@ -20,11 +20,11 @@ pub fn bind_polygon_mode(gl: &gl::Gl, mode: pso::PolygonMode, bias: Option<pso::
unsafe { gl.PolygonMode(gl::FRONT_AND_BACK, gl_draw) };

match bias {
Some(bias) => unsafe {
Some(pso::State::Static(bias)) => unsafe {
gl.Enable(gl_offset);
gl.PolygonOffset(bias.slope_factor as _, bias.const_factor as _);
},
None => unsafe {
_ => unsafe {
gl.Disable(gl_offset)
},
}
Expand Down
Loading

0 comments on commit 45a72f6

Please sign in to comment.