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

Use z-buffer for rejecting opaque fragments. #648

Merged
merged 5 commits into from Dec 23, 2016
Merged

Use z-buffer for rejecting opaque fragments. #648

merged 5 commits into from Dec 23, 2016

Conversation

@glennw
Copy link
Member

glennw commented Dec 15, 2016

This change is Reviewable

@glennw
Copy link
Member Author

glennw commented Dec 15, 2016

This still needs a little bit of cleanup - but it implements the functionality and passes all tests. So it should be fairly close to the final version.

@@ -286,6 +287,7 @@ struct PrimitiveInstance {
int clip_task_index;
int layer_index;
int sub_index;
int z;

This comment has been minimized.

@kvark

kvark Dec 15, 2016

Member

we could probably reduce the user_data to a single int in order to keep the 32 byte size

This comment has been minimized.

@glennw

glennw Dec 21, 2016

Author Member

Yep, I think it's fine to do this as a follow up though.

@@ -352,6 +356,7 @@ Primitive load_primitive_custom(PrimitiveInstance pi) {
prim.prim_index = pi.specific_prim_index;
prim.sub_index = pi.sub_index;
prim.user_data = pi.user_data;
prim.z = pi.z;

This comment has been minimized.

@kvark

kvark Dec 15, 2016

Member

I think some compilers may require an explicit cast here.
Moreover, what are you going to do with this Z value? We need to scale it down into [-1, 1] region before passing into gl_Position, and I don't see this happening anywhere.

This comment has been minimized.

@glennw

glennw Dec 21, 2016

Author Member

Fixed the cast. The vertices are transformed by uTransform, which is an orthographic projection matrix at the end of the function. This converts the z values to NDC.

}
}

pub fn enable_depth(&self) {

This comment has been minimized.

@kvark

kvark Dec 15, 2016

Member

we could merge those enable_*/disable_* for tinier interface with the device

This comment has been minimized.

@glennw

glennw Dec 21, 2016

Author Member

Yep, perhaps as a follow up we should tidy up the whole device interface?

@@ -39,6 +39,7 @@ void main(void) {
#ifdef WR_FEATURE_TRANSFORM
TransformVertexInfo vi = write_transform_vertex(segment_rect,
prim.local_clip_rect,
prim.z,

This comment has been minimized.

@kvark

kvark Dec 15, 2016

Member

at this point, we might as well want to just pass prim there directly

This comment has been minimized.

@glennw

glennw Dec 21, 2016

Author Member

Some of the shaders generate the local rect separately (as in the case above), which is why I wasn't passing in the prim directly - to avoid bugs where that code accesses the prim.local_rect accidentally. But we could probably tidy up those structure definitions in the shader code.

@@ -123,7 +122,6 @@ const CLIP_FEATURE: &'static str = "CLIP";

enum ShaderKind {
Primitive,
Clear,

This comment has been minimized.

@kvark

kvark Dec 15, 2016

Member

sweeet!

@@ -990,12 +961,87 @@ impl Renderer {
self.profile_counters.draw_calls.inc();
}

fn submit_batch(&mut self,

This comment has been minimized.

@kvark

kvark Dec 15, 2016

Member

👍

let needs_clipping = batch.key.flags.needs_clipping();
debug_assert!(!needs_clipping || batch.key.blend_mode == BlendMode::Alpha);
self.device.enable_depth();
self.device.enable_depth_write();

This comment has been minimized.

@kvark

kvark Dec 15, 2016

Member

do we set the depth function anywhere?

This comment has been minimized.

@glennw

glennw Dec 21, 2016

Author Member

Fixed

@glennw
Copy link
Member Author

glennw commented Dec 21, 2016

@kvark @pcwalton I think this is ready for review now.

@glennw glennw changed the title [WIP] Use z-buffer for rejecting opaque fragments. Use z-buffer for rejecting opaque fragments. Dec 21, 2016
Copy link
Collaborator

pcwalton left a comment

Looks good, just had one question

@@ -120,7 +120,6 @@ fn main() {
debug: false,
enable_subpixel_aa: false,
clear_framebuffer: true,
clear_empty_tiles: false,

This comment has been minimized.

@pcwalton

pcwalton Dec 21, 2016

Collaborator

Why do we not clear empty tiles anymore?

This comment has been minimized.

@kvark

kvark Dec 22, 2016

Member

I think it's already guaranteed to be cleared in draw_target. Not sure though, at what point it became redundant/useless.

This comment has been minimized.

@glennw

glennw Dec 22, 2016

Author Member

Since we have to clear the z-buffer now, I figure we might as well just do a clear of the color buffer as well. This also makes it perform much better on mobile / tiled GPUs which rely on a clear due to the way tiling works. We could definitely re-instate this later as an optimization if it makes sense to.

@kvark
kvark approved these changes Dec 22, 2016
Copy link
Member

kvark left a comment

@glennw I agree with all the "let's do X as follow up" requests, the PR looks good!

@@ -120,7 +120,6 @@ fn main() {
debug: false,
enable_subpixel_aa: false,
clear_framebuffer: true,
clear_empty_tiles: false,

This comment has been minimized.

@kvark

kvark Dec 22, 2016

Member

I think it's already guaranteed to be cleared in draw_target. Not sure though, at what point it became redundant/useless.

@kvark
Copy link
Member

kvark commented Dec 23, 2016

@kvark
Copy link
Member

kvark commented Dec 23, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

📌 Commit 7eb458c has been approved by kvark

@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

Testing commit 7eb458c with merge 56131c9...

bors-servo added a commit that referenced this pull request Dec 23, 2016
Use z-buffer for rejecting opaque fragments.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/648)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 23, 2016

☀️ Test successful - status-travis

@bors-servo bors-servo merged commit 7eb458c into servo:master Dec 23, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@glennw glennw deleted the glennw:zb branch Dec 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.