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

Angle depth clear workaround #2126

Merged
merged 2 commits into from Nov 29, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Refactored Device::clear_rect

  • Loading branch information
kvark committed Nov 28, 2017
commit bbb57914e9321f02758b5326195953a22fa95bba
@@ -1603,29 +1603,11 @@ impl Device {
self.frame_id.0 += 1;
}

pub fn clear_target(&self, color: Option<[f32; 4]>, depth: Option<f32>) {
let mut clear_bits = 0;

if let Some(color) = color {
self.gl.clear_color(color[0], color[1], color[2], color[3]);
clear_bits |= gl::COLOR_BUFFER_BIT;
}

if let Some(depth) = depth {
self.gl.clear_depth(depth as f64);
clear_bits |= gl::DEPTH_BUFFER_BIT;
}

if clear_bits != 0 {
self.gl.clear(clear_bits);
}
}

pub fn clear_target_rect(
pub fn clear_target(
&self,
color: Option<[f32; 4]>,
depth: Option<f32>,
rect: DeviceIntRect,
rect: Option<DeviceIntRect>,
) {
let mut clear_bits = 0;

@@ -1635,20 +1617,28 @@ impl Device {
}

if let Some(depth) = depth {
debug_assert_ne!(self.gl.get_boolean_v(gl::DEPTH_WRITEMASK), 0);
self.gl.clear_depth(depth as f64);
clear_bits |= gl::DEPTH_BUFFER_BIT;
}

if clear_bits != 0 {
self.gl.enable(gl::SCISSOR_TEST);
self.gl.scissor(
rect.origin.x,
rect.origin.y,
rect.size.width,
rect.size.height,
);
self.gl.clear(clear_bits);
self.gl.disable(gl::SCISSOR_TEST);
match rect {
Some(rect) => {
self.gl.enable(gl::SCISSOR_TEST);
self.gl.scissor(
rect.origin.x,
rect.origin.y,
rect.size.width,
rect.size.height,
);
self.gl.clear(clear_bits);
self.gl.disable(gl::SCISSOR_TEST);
}
None => {
self.gl.clear(clear_bits);
}
}
}
}

@@ -2442,7 +2442,9 @@ impl Renderer {
None
};
self.device.bind_draw_target(None, None);
self.device.clear_target(clear_color, clear_depth_value);
self.device.enable_depth_write();
self.device.clear_target(clear_color, clear_depth_value, None);
self.device.disable_depth_write();
}

// Re-use whatever targets possible from the pool, before
@@ -2980,31 +2982,30 @@ impl Renderer {
None
};

if render_target.is_some() {
let clear_rect = if render_target.is_some() {
if self.enable_clear_scissor {
// TODO(gw): Applying a scissor rect and minimal clear here
// is a very large performance win on the Intel and nVidia
// GPUs that I have tested with. It's possible it may be a
// performance penalty on other GPU types - we should test this
// and consider different code paths.
self.device.clear_target_rect(clear_color, depth_clear, target.used_rect());
Some(target.used_rect())
} else {
self.device.clear_target(clear_color, depth_clear);
None
}
} else if framebuffer_target_rect == DeviceUintRect::new(DeviceUintPoint::zero(), target_size) {
// whole screen is covered, no need for scissor
self.device.clear_target(clear_color, depth_clear);
None
} else {
// Note: for non-intersecting document rectangles,
// we can omit clearing the depth here, and instead
// just clear it for the whole framebuffer at start of the frame.
let mut clear_rect = framebuffer_target_rect.to_i32();
let mut rect = framebuffer_target_rect.to_i32();
// Note: `framebuffer_target_rect` needs a Y-flip before going to GL
// Note: at this point, the target rectangle is not guaranteed to be within the main framebuffer bounds
// but `clear_target_rect` is totally fine with negative origin, as long as width & height are positive
clear_rect.origin.y = target_size.height as i32 - clear_rect.origin.y - clear_rect.size.height;
self.device.clear_target_rect(clear_color, depth_clear, clear_rect);
}
rect.origin.y = target_size.height as i32 - rect.origin.y - rect.size.height;
Some(rect)
};

self.device.clear_target(clear_color, depth_clear, clear_rect);

if depth_clear.is_some() {
self.device.disable_depth_write();
@@ -3397,14 +3398,20 @@ impl Renderer {
// performance penalty on other GPU types - we should test this
// and consider different code paths.
let clear_color = [1.0, 1.0, 1.0, 0.0];
self.device
.clear_target_rect(Some(clear_color), None, target.used_rect());
self.device.clear_target(
Some(clear_color),
None,
Some(target.used_rect()),
);

let zero_color = [0.0, 0.0, 0.0, 0.0];
for &task_id in &target.zero_clears {
let (rect, _) = render_tasks[task_id].get_target_rect();
self.device
.clear_target_rect(Some(zero_color), None, rect);
self.device.clear_target(
Some(zero_color),
None,
Some(rect),
);
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.