In the `shared` crate: Annotate functions/methods with `#[inline(always)]`

Open
#15 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust

Research direction

Start by locating the shared crate and reviewing its small functions and methods that are used when compiling Rust shaders to GLSL. Compare generated shader output for representative functions such as shared_saturate, shared_smoothstep, and shared_mix_f32_f32_; done means the relevant functions are annotated and the resulting SPIR-V still passes validation.

Written by the indexing model from the issue text.

Description

When compiling Rust shaders to GLSL I noticed that a lot of functions are not inlined by default that should be.
I used the shared crate from this repo when porting some shadertoy shaders to Rust, e.g.
https://www.shadertoy.com/view/tsyBDm
You can see it has a lot of small functions that should be inlined (several of them from the shared crate), like:

float shared_saturate(float _3518)
{
    return min(max(_3518, 0.0), 1.0);
}
float shared_smoothstep(float _3522, float _3523, float _3524)
{
    float _3529 = shared_saturate((_3524 - _3522) / (_3523 - _3522));
    return (_3529 * _3529) * (3.0 - (2.0 * _3529));
}
float shared_mix_f32_f32_(float _394, float _395, float _396)
{
    return (_394 - (_394 * _396)) + (_395 * _396);
}

Inlining is especially important considering that the spirv backend doesn't really optimize much at the moment, and spirv-opt often produces invalid output (on which spirv validation fails).

Dominant language
Rust
Stars
165
Forks
13
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from Rust-GPU/rust-gpu-shadertoys

All issues in Rust-GPU/rust-gpu-shadertoys

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.