Skip to content

Commit

Permalink
Bug 1682194 - Accelerate cs_clip_rectangle in SWGL. r=jrmuizel
Browse files Browse the repository at this point in the history
cs_clip_rectangle is slow because we evaluate distance AA for every fragment
the shader touches. With SWGL, we can do much better since we have control
over span. We calculate an inner opaque octagon which can just use a cheap
solid fill and an outer AA octagon within which we need to actually we do
AA and outside which we can just do another solid clear. This reduces most
of the cost of rounded-rectangles to just some setup work, a few fragments
of distance AA on the ends of a span, and large runs of solid color where
we don't have to do much work.

Differential Revision: https://phabricator.services.mozilla.com/D106658

[ghsync] From https://hg.mozilla.org/mozilla-central/rev/8c6e26b7c2806578e92fcdb41b3b46f359f8b089
  • Loading branch information
lsalzman committed Feb 27, 2021
1 parent 25109a3 commit fee422c
Show file tree
Hide file tree
Showing 16 changed files with 710 additions and 132 deletions.
159 changes: 137 additions & 22 deletions glsl-to-cxx/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3206,6 +3206,9 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
declare_function(state, "abs", None, Type::new(Vec2), vec![Type::new(Vec2)]);
declare_function(state, "abs", None, Type::new(Vec3), vec![Type::new(Vec3)]);
declare_function(state, "abs", None, Type::new(Float), vec![Type::new(Float)]);
declare_function(state, "sign", None, Type::new(Vec2), vec![Type::new(Vec2)]);
declare_function(state, "sign", None, Type::new(Vec3), vec![Type::new(Vec3)]);
declare_function(state, "sign", None, Type::new(Float), vec![Type::new(Float)]);
declare_function(
state,
"dot",
Expand Down Expand Up @@ -3355,13 +3358,27 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
Type::new(Vec2),
vec![Type::new(Vec2), Type::new(Vec2)],
);
declare_function(
state,
"step",
None,
Type::new(Vec2),
vec![Type::new(Float), Type::new(Vec2)],
);
declare_function(
state,
"step",
None,
Type::new(Vec3),
vec![Type::new(Vec3), Type::new(Vec3)],
);
declare_function(
state,
"step",
None,
Type::new(Vec4),
vec![Type::new(Float), Type::new(Vec4)],
);
declare_function(
state,
"notEqual",
Expand All @@ -3370,13 +3387,31 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
vec![Type::new(IVec4), Type::new(IVec4)],
);

declare_function(
declare_function_ext(
state,
"fwidth",
None,
Type::new(Vec2),
vec![Type::new(Vec2)],
RunClass::Scalar,
);
declare_function_ext(
state,
"dFdx",
None,
Type::new(Float),
vec![Type::new(Float)],
RunClass::Scalar,
);
declare_function_ext(
state,
"dFdx",
None,
Type::new(Vec2),
vec![Type::new(Vec2)],
RunClass::Scalar,
);

declare_function(state, "cos", None, Type::new(Float), vec![Type::new(Float)]);
declare_function(state, "sin", None, Type::new(Float), vec![Type::new(Float)]);
declare_function(state, "tan", None, Type::new(Float), vec![Type::new(Float)]);
Expand All @@ -3393,8 +3428,8 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
state,
"clamp",
None,
Type::new(Double),
vec![Type::new(Double), Type::new(Double), Type::new(Double)],
Type::new(Float),
vec![Type::new(Float), Type::new(Float), Type::new(Float)],
);
declare_function(
state,
Expand All @@ -3417,6 +3452,13 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
Type::new(Vec4),
vec![Type::new(Vec4), Type::new(Vec4), Type::new(Vec4)],
);
declare_function(
state,
"clamp",
None,
Type::new(Vec4),
vec![Type::new(Vec4), Type::new(Float), Type::new(Float)],
);
declare_function(
state,
"length",
Expand All @@ -3430,35 +3472,66 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
declare_function(state, "exp2", None, Type::new(Float), vec![Type::new(Float)]);
declare_function(state, "log", None, Type::new(Float), vec![Type::new(Float)]);
declare_function(state, "log2", None, Type::new(Float), vec![Type::new(Float)]);
for t in &[Float, Vec2] {
// recip is non-standard
declare_function(
state,
"recip",
None,
Type::new(*t),
vec![Type::new(*t)],
);
declare_function(
state,
"inversesqrt",
None,
Type::new(*t),
vec![Type::new(*t)],
);
declare_function(
state,
"sqrt",
None,
Type::new(*t),
vec![Type::new(*t)],
);
}
declare_function(
state,
"recip",
"distance",
None,
Type::new(Float),
vec![Type::new(Float)],
vec![Type::new(Vec2), Type::new(Vec2)],
);

declare_function(
state,
"inversesqrt",
"equal",
None,
Type::new(Float),
vec![Type::new(Float)],
Type::new(BVec2),
vec![Type::new(Vec2), Type::new(Vec2)],
);
declare_function(
state,
"sqrt",
"equal",
None,
Type::new(Float),
vec![Type::new(Float)],
Type::new(BVec4),
vec![Type::new(Vec4), Type::new(Vec4)],
);
declare_function(
state,
"distance",
"notEqual",
None,
Type::new(Float),
Type::new(BVec2),
vec![Type::new(Vec2), Type::new(Vec2)],
);

declare_function(
state,
"notEqual",
None,
Type::new(BVec4),
vec![Type::new(Vec4), Type::new(Vec4)],
);
declare_function(
state,
"lessThanEqual",
Expand Down Expand Up @@ -3487,13 +3560,27 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
Type::new(BVec2),
vec![Type::new(Vec2), Type::new(Vec2)],
);
declare_function(
state,
"lessThan",
None,
Type::new(BVec4),
vec![Type::new(Vec4), Type::new(Vec4)],
);
declare_function(
state,
"greaterThan",
None,
Type::new(BVec2),
vec![Type::new(Vec2), Type::new(Vec2)],
);
declare_function(
state,
"greaterThan",
None,
Type::new(BVec4),
vec![Type::new(Vec4), Type::new(Vec4)],
);
declare_function(
state,
"greaterThanEqual",
Expand Down Expand Up @@ -3525,22 +3612,22 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
state,
"floor",
None,
Type::new(Double),
vec![Type::new(Double)],
Type::new(Float),
vec![Type::new(Float)],
);
declare_function(
state,
"ceil",
None,
Type::new(Double),
vec![Type::new(Double)],
Type::new(Float),
vec![Type::new(Float)],
);
declare_function(
state,
"round",
None,
Type::new(Double),
vec![Type::new(Double)],
Type::new(Float),
vec![Type::new(Float)],
);
declare_function(
state,
Expand Down Expand Up @@ -3708,6 +3795,20 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
);
}

// GL_ARB_shader_group_vote
for (name, cxx_name) in &[("anyInvocations", "test_any"),
("allInvocations", "test_all"),
("allInvocationsEqual", "test_equal")] {
declare_function_ext(
state,
name,
Some(cxx_name),
Type::new(Bool),
vec![Type::new(Bool)],
RunClass::Scalar,
);
}

declare_function(
state,
"swgl_stepInterp",
Expand All @@ -3727,6 +3828,20 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
);
}

declare_function(
state,
"swgl_commitPartialSolidRGBA8",
None,
Type::new(Void),
vec![Type::new(Int), Type::new(Vec4)],
);
declare_function(
state,
"swgl_commitPartialSolidR8",
None,
Type::new(Void),
vec![Type::new(Int), Type::new(Float)],
);
declare_function(
state,
"swgl_commitSolidRGBA8",
Expand All @@ -3746,14 +3861,14 @@ pub fn ast_to_hir(state: &mut State, tu: &syntax::TranslationUnit) -> Translatio
"swgl_commitColorRGBA8",
None,
Type::new(Void),
vec![Type::new(Vec4), Type::new(Float)],
vec![Type::new(Vec4)],
);
declare_function(
state,
"swgl_commitColorR8",
None,
Type::new(Void),
vec![Type::new(Float), Type::new(Float)],
vec![Type::new(Float)],
);
declare_function(
state,
Expand Down
2 changes: 1 addition & 1 deletion glsl-to-cxx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3164,7 +3164,7 @@ pub fn show_iteration_statement(state: &mut OutputState, ist: &hir::IterationSta
show_statement(state, body);
state.write(" while (");
show_hir_expr(state, cond);
state.write(")\n");
state.write(");\n");
}
hir::IterationStatement::For(ref init, ref rest, ref body) => {
state.write("for (");
Expand Down
Loading

0 comments on commit fee422c

Please sign in to comment.