Skip to content

Commit b9f2ee0

Browse files
committed
Add --allow-fragment-no-output compiler flag to bypass fragment shader validation
Implements a new compiler flag that allows fragment shaders with no output operations to compile without errors. This addresses issue #284 where fragment shaders optimized by DCE (Dead Code Elimination) would fail validation even when the lack of output was intentional. Changes: - Add `allow_fragment_no_output` field to linker Options struct - Add command-line flag parsing for `--allow-fragment-no-output` - Skip fragment shader output validation when flag is enabled - Update error message to include usage hint for the new flag This flag is intended for testing scenarios and special use cases where fragment shaders legitimately produce no output. The validation remains active by default to catch unintentional issues.
1 parent becdc41 commit b9f2ee0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ pub struct Options {
5555
/// **Note**: currently only used for unit testing, and not exposed elsewhere.
5656
pub keep_link_exports: bool,
5757

58+
/// Allow fragment shaders with no output operations (disables Issue #284 validation)
59+
pub allow_fragment_no_output: bool,
60+
5861
// NOTE(eddyb) these are debugging options that used to be env vars
5962
// (for more information see `docs/src/codegen-args.md`).
6063
pub dump_post_merge: Option<PathBuf>,
@@ -711,7 +714,9 @@ pub fn link(
711714
}
712715

713716
// Validate fragment shaders after DCE to catch silent optimization failures
714-
validate_fragment_shader_outputs(sess, output)?;
717+
if !opts.allow_fragment_no_output {
718+
validate_fragment_shader_outputs(sess, output)?;
719+
}
715720

716721
{
717722
let _timer = sess.timer("link_remove_duplicate_debuginfo");
@@ -851,6 +856,8 @@ fn validate_fragment_shader_outputs(sess: &Session, module: &Module) -> Result<(
851856
"use complete assignment like `*out_frag_color = vec4(r, g, b, a)` instead of partial component assignments"
852857
).with_note(
853858
"partial component assignments may be optimized away if not all components are written"
859+
).with_note(
860+
"to disable this validation (e.g. for testing), use `--allow-fragment-no-output`"
854861
);
855862

856863
// Look for the function to provide better diagnostics
@@ -864,6 +871,8 @@ fn validate_fragment_shader_outputs(sess: &Session, module: &Module) -> Result<(
864871
"detected partial component writes (e.g., `out.x = value`) which were optimized away"
865872
).with_help(
866873
"write all components at once: `*out_frag_color = vec4(r, g, b, 1.0)`"
874+
).with_note(
875+
"alternatively, use `--allow-fragment-no-output` to disable this validation"
867876
);
868877
}
869878
}

tests/compiletests/ui/dis/issue-284-dead-fragment.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ error: fragment shader `main_fs` produces no output
33
= help: fragment shaders must write to output parameters to produce visible results
44
= note: use complete assignment like `*out_frag_color = vec4(r, g, b, a)` instead of partial component assignments
55
= note: partial component assignments may be optimized away if not all components are written
6+
= note: to disable this validation (e.g. for testing), use `--allow-fragment-no-output`
67

78
error: aborting due to 1 previous error
89

0 commit comments

Comments
 (0)