Closed Bug 1698156 Opened 4 years ago Closed 4 years ago

GLSL macros with arguments causes parse errors. (impossible to build Firefox)

Categories

(Core :: Graphics: WebRender, defect)

x86_64
Linux
defect

Tracking

()

RESOLVED FIXED
89 Branch
Tracking Status
firefox88 --- fixed
firefox89 --- fixed

People

(Reporter: nbp, Assigned: lsalzman)

References

(Blocks 1 open bug)

Details

(Keywords: perf-alert)

Attachments

(3 files)

When building Firefox, I see the following error messages on mozilla/central.

 2:12.41   /home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/x86_64-unknown-linux-gnu/release/build/swgl-2a88ebe753c74f59/out/brush_blend.frag: Err(
 2:12.42       ParseError {
 2:12.42           info: "0: at line 511, in TakeWhile1:\n#define antialias_brush() 1.0\n                        ^\n\n",
 2:12.42       },
 2:12.42   )

After adding extra code to dump the file name.

I seems that the macro with parentheses are not supported. Doing the following fixes this issue:
git grep -l antialias_brush | xargs sed -ie 's/antialias_brush()/antialias_brush/'

but yield another issue of the same nature:

 0:51.01   /home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/x86_64-unknown-linux-gnu/release/build/swgl-2a88ebe753c74f59/out/cs_clip_rectangle.frag: Err(
 0:51.01       ParseError {
 0:51.01           info: "0: at line 565:\n#define CLIP_CORNER(offset,normal,info) do { float dist = dot(local_pos0 - (offset), (normal)); float scale = -dot(local_step, (normal)); if (scale >= 0.0) { if (dist > opaque_start * scale) { start_corner = info; start_plane = vec4(offset, normal); float inv_scale = recip(max(scale, 1.0e-6)); opaque_start = dist * inv_scale; float apex = (0.7071 - 0.5) * 2.0 * abs(normal.x * normal.y); aa_start = opaque_start - apex * inv_scale; } } else if (dist > opaque_end * scale) { end_corner = info; end_plane = vec4(offset, normal); float inv_scale = recip(min(scale, -1.0e-6)); opaque_end = dist * inv_scale; float apex = (0.7071 - 0.5) * 2.0 * abs(normal.x * normal.y); aa_end = opaque_end - apex * inv_scale; } } while (false)\n^\nexpected \'}\', found #\n\n",
 0:51.02       },
 0:51.02   )

It seems like swgl is getting unpreprocessed glsl. It is supposed to be preprocessed by this code: https://searchfox.org/mozilla-central/source/gfx/wr/swgl/build.rs#81

Attached file generated-command-line.txt (obsolete) —
Running `./mach build -v` leads to the following command line: ``` "/nix/store/ca37d3qrydh0wpw40kswsx30j8dyzxh2-gcc-wrapper-10.2.0/bin/cc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-std=gnu99" "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/system_wrappers" "-include" "/home/nicolas/mozilla/wksp-5/config/gcc_hidden.h" "-U_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=2" "-fstack-protector-strong" "-DNDEBUG=1" "-DTRIMMED=1" "-I/home/nicolas/mozilla/wksp-5/toolkit/library/rust" "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/toolkit/library/rust" "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include" "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include/nspr" "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include/nss" "-fPIC" "-include" "/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/mozilla-config.h" "-DMOZILLA_CLIENT" "-fno-strict-aliasing" "-fno-math-errno" "-pthread" "-pipe" "-ggdb3" "-freorder-blocks" "-O2" "-fno-omit-frame-pointer" "-funwind-tables" "-DMOZILLA_CONFIG_H" "-xc" "-P" "-DWR_FRAGMENT_SHADER=1" "-E" "/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/x86_64-unknown-linux-gnu/release/build/swgl-2a88ebe753c74f59/out/cs_clip_rectangle.c" ``` Which is a wrapper provided by Nix around the compiler, which expand to the following set of command line arguments: ``` ```
Attached file generated command line

Running ./mach build -v leads to the following command line:

"/nix/store/ca37d3qrydh0wpw40kswsx30j8dyzxh2-gcc-wrapper-10.2.0/bin/cc"
  "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-std=gnu99"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/system_wrappers"
  "-include" "/home/nicolas/mozilla/wksp-5/config/gcc_hidden.h"
  "-U_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=2"
  "-fstack-protector-strong" "-DNDEBUG=1" "-DTRIMMED=1"
  "-I/home/nicolas/mozilla/wksp-5/toolkit/library/rust"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/toolkit/library/rust"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include/nspr"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include/nss"
  "-fPIC"
  "-include" "/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/mozilla-config.h"
  "-DMOZILLA_CLIENT" "-fno-strict-aliasing" "-fno-math-errno" "-pthread"
  "-pipe" "-ggdb3" "-freorder-blocks" "-O2" "-fno-omit-frame-pointer" "-funwind-tables"
  "-DMOZILLA_CONFIG_H" "-xc" "-P" "-DWR_FRAGMENT_SHADER=1"
  "-E" "/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/x86_64-unknown-linux-gnu/release/build/swgl-2a88ebe753c74f59/out/cs_clip_rectangle.c"

Which is a wrapper provided by Nix around the compiler, which expand to the following set of command line arguments

Ok, bisecting the command line, it seems that -ggdb3 adds all the macro definitions, and -include /home/nicolas/mozilla/wksp-5/config/gcc_hidden.h add a visibility pragma, which does not seems to cause errors while parsing.

I will note, that -ggdb3 comes from --enable-debug-symbols=-ggdb3 in the mozconfig.

Lee, any ideas why this compiler command line would cause this swgl build error?

Blocks: sw-wr
Severity: -- → S3
Flags: needinfo?(lsalzman)

Apparently -ggdb3 adds back the macro definitions after preprocessing which breaks the glsl parsing which assumes preprocessed source.

My guess would be that we could filter out these macros from the output, as these are being collected in Rust code.
We could have some code similar to:

  let mut in_macro = false;
  let fs : Vec<u8> = fs.into_iter().filter(|c| {
    if c == b'#' {
      in_macro = true;
    } else if c == b'\n' {
      in_macro = false;
    }
    !in_macro
  }).collect();

Should I make this patch?

Or strip out '-ggdb3' or even all of the CFLAGS from the compiler flags.

(In reply to Jeff Muizelaar [:jrmuizel] from comment #10)

Or strip out '-ggdb3' or even all of the CFLAGS from the compiler flags.

This is my current work-around, to remove the --enable-debug-symbols from the mozconfig.

The cc crate says the setting the environment variable CRATE_CC_NO_DEFAULTS=true will make it not use the default C flags. Does this fix it for you?

Flags: needinfo?(lsalzman) → needinfo?(nicolas.b.pierron)
Assignee: nobody → lsalzman
Status: NEW → ASSIGNED

Adding the same line as the patch locally does not seems to fix the issue:

"/nix/store/ca37d3qrydh0wpw40kswsx30j8dyzxh2-gcc-wrapper-10.2.0/bin/cc"
  "-std=gnu99"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/system_wrappers"
  "-include" "/home/nicolas/mozilla/wksp-5/config/gcc_hidden.h"
  "-U_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=2"
  "-fstack-protector-strong" "-DNDEBUG=1" "-DTRIMMED=1"
  "-I/home/nicolas/mozilla/wksp-5/toolkit/library/rust"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/toolkit/library/rust"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include/nspr"
  "-I/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/dist/include/nss"
  "-fPIC"
  "-include" "/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/mozilla-config.h"
  "-DMOZILLA_CLIENT" "-fno-strict-aliasing" "-fno-math-errno" "-pthread"
  "-pipe" "-ggdb2" "-freorder-blocks" "-O2" "-fno-omit-frame-pointer" "-funwind-tables"
  "-DMOZILLA_CONFIG_H" "-xc" "-P" "-DWR_FRAGMENT_SHADER=1"
  "-E" "/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/x86_64-unknown-linux-gnu/release/build/swgl-2a88ebe753c74f59/out/cs_clip_rectangle.c"

This is tested without the CRATE_CC_NO_DEFAULTS environment variable.
Here we see the -ggdb2 (same as -ggdb) added in the mozconfig file using ac_add_options --enable-debug-symbols=-ggdb2.

Flags: needinfo?(nicolas.b.pierron)

Testing with the patch and export CRATE_CC_NO_DEFAULTS=true in the mozconfig behaves the same way as in comment 15.

Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3de8645714dc Disable default flags for SWGL preprocessor. r=jrmuizel
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 88 Branch

Based on comment 15 and comment 16, I do not think this bug is resolved.
However, I do understand that this is not a priority given that it can be worked around.

Flags: needinfo?(lsalzman)

Yeah, it looks like no_default_flags doesn't prevent CFLAGS/CXXFLAGS from being used.

Status: RESOLVED → REOPENED
Resolution: FIXED → ---

Nicolas, can you see if that SWGLPP workaround works for you?

Flags: needinfo?(lsalzman) → needinfo?(nicolas.b.pierron)

FWIW, this causes an error when compiling the unoptimized shaders on Adreno 3xx. (Presumably a driver bug). How would we feel about replacing it with a function? Presumably the compiler would optimize it out.

To clarify, the antialias_brush macro causes the issue, not the workarounds

ERROR: 0:1287: '(' : Syntax error:  syntax error

Replacing it with a function should be fine. Usually we're getting optimized shaders anyways.

(In reply to Lee Salzman [:lsalzman] from comment #22)

Nicolas, can you see if that SWGLPP workaround works for you?

This seems to work!

"/nix/store/ca37d3qrydh0wpw40kswsx30j8dyzxh2-gcc-wrapper-10.2.0/bin/cc"
  "-std=gnu99" "-O2" "-ffunction-sections" "-fdata-sections"
  "-fPIC"
  "-xc"
  "-P"
  "-DWR_FRAGMENT_SHADER=1"
  "-E" "/home/nicolas/mozilla/_build/firefox/bugzil.la/1698045/wip/x64/gcc/opt/x86_64-unknown-linux-gnu/release/build/swgl-2a88ebe753c74f59/out/cs_clip_rectangle.c"
Flags: needinfo?(nicolas.b.pierron)
Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/38a9b0040e8f Set up SWGLPP env target with null CFLAGS and CXXFLAGS. r=jrmuizel
Flags: needinfo?(lsalzman)
Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/97c081de7aa5 Set up SWGLPP env target with null CFLAGS and CXXFLAGS. r=jrmuizel
Flags: needinfo?(lsalzman)

Argh, there was an unfortunate interaction with our build system wherein overriding the target caused us to pick up the wrong CC var. I found a workaround to force the existing CC target though.

Flags: needinfo?(lsalzman)
Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/be9bb9b16fc0 Set up SWGLPP env target with null CFLAGS and CXXFLAGS. r=jrmuizel
Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7781dd4fce4a Set up SWGLPP env target with null CFLAGS and CXXFLAGS. r=jrmuizel
Flags: needinfo?(lsalzman)
Pushed by lsalzman@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d9094761d8a9 Set up SWGLPP env target with null CFLAGS and CXXFLAGS. r=jrmuizel
Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED
Target Milestone: 88 Branch → 89 Branch

(In reply to Sandor Molnar from comment #35)

Backed out for causing linux build bustages

Backout link: https://hg.mozilla.org/integration/autoland/rev/14dbcc65d5826b46fbb8da0a9be23fcede418f16

Push with failures

Failure log

== Change summary for alert #29513 (as of Tue, 30 Mar 2021 07:04:03 GMT) ==

Regressions:

Ratio Suite Test Platform Options Absolute values (old vs new)
0.30% Base Content JS macosx1015-64-shippable-qr 2,407,737.67 -> 2,414,969.33
0.05% Base Content JS macosx1015-64-shippable-qr 2,407,750.00 -> 2,408,839.33

For up to date results, see: https://treeherder.mozilla.org/perfherder/alerts?id=29513

Keywords: perf-alert
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: