Rust-GPU / Rust-GPU/rust-gpu

Fragment shader just copying values doesn't compile

Open
#185 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
3.4k
Forks
125
PR merge metrics
No merged PRs in 30d

Description

Expected Behaviour

The following code snippet defines 3 fragment shaders, but the middle one does not get compiled / emit an entry point / generates a spv (with multibuilder true). Looks like it's somehow getting inlined / optimized away before monomorphization, so it's not picked up as an entry point?

#[spirv(fragment)]
pub fn fragment_works(v_color: Vec4, frag_color: &mut Vec4) {
  *frag_color = v_color +1.;
}

#[spirv(fragment)]
pub fn fragment_doesnt(v_color: Vec4, frag_color: &mut Vec4) {
  *frag_color = v_color;
}

/// causes a warning by rust-gpu about having to be inlined anyway
#[inline(never)]
#[spirv(fragment)]
pub fn fragment_works_again(v_color: Vec4, frag_color: &mut Vec4) {
  *frag_color = v_color;
}

Found while investigating an issue with hadronized on discord.

System Info

  • cargo-gpu main
  • I have no idea what rust-gpu version this is, cargo-gpu doesn't tell, apparently it's pointing to the git repo but it can't be main as the toolchains would mismatch.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the three fragment entry points from the issue using cargo-gpu at the referenced main commit, with multibuilder enabled, and compare their compilation and SPIR-V output. Focus on why fragment_doesnt is omitted while fragment_works_again is retained despite both copying v_color. Done means all three functions compile, emit entry points, and generate valid SPIR-V without requiring inline(never).

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.