Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glsl-in: Perform output parameters implicit casts #2063

Merged
merged 2 commits into from
Feb 8, 2023

Conversation

JCapucho
Copy link
Collaborator

Rant: this is incredibly cursed and I wouldn't even believe this existed if I hadn't ran into a shader that used this.

Glsl defines under Function Definitions (Paragraph 6.1 in glsl 4.60),
the following:

When function calls are resolved, an exact type match for all the arguments is sought.
(...)
If no exact match is found, then the implicit conversions in section “Implicit Conversions” will be applied to find a match.
(...)
Mismatched types on output parameters (out or inout) must have a conversion from the formal parameter type to the calling argument type.

The glsl frontend wasn't performing this implicit cast for output parameters.

They are now implemented trough a proxy write (like when swizzling for output parameters), where a spill variable with the correct type is passed and on the call prologue a conversion back to the original type is performed and the value stored in the original variable.

Furthermore if the variable in declared inout, a conversion is also made in the call prelude from the original type to the correct type and the value is stored in the spill variable.

@JCapucho JCapucho force-pushed the glsl-out-casts branch 2 times, most recently from 157c13d to 7bc7b79 Compare September 18, 2022 10:39
Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rant: this is incredibly cursed and I wouldn't even believe this existed if I hadn't ran into a shader that used this.

That's indeed quite some magic the GLSL spec mandates 😅

@teoxoy
Copy link
Member

teoxoy commented Dec 2, 2022

Looks like there are some test conflicts, feel free to merge once resolved.

src/front/glsl/functions.rs Outdated Show resolved Hide resolved
src/front/glsl/functions.rs Outdated Show resolved Hide resolved
src/front/glsl/functions.rs Outdated Show resolved Hide resolved
@jimblandy
Copy link
Member

(I had this review sitting there since forever, and didn't realize I hadn't posted it)

@JCapucho JCapucho force-pushed the glsl-out-casts branch 5 times, most recently from b3d2ee2 to e260a5c Compare January 17, 2023 23:12
@jimblandy
Copy link
Member

It looks like the log message on commit e260a5c isn't right.

@JCapucho
Copy link
Collaborator Author

JCapucho commented Feb 3, 2023

It looks like the log message on commit e260a5c isn't right.

Oh no, seems like I did something that made git override the commit message with one of another commit that was merged by master (It also seems to have squashed commits 😞)

@JCapucho JCapucho force-pushed the glsl-out-casts branch 2 times, most recently from 1c1364c to f12409e Compare February 3, 2023 14:41
@JCapucho
Copy link
Collaborator Author

JCapucho commented Feb 3, 2023

@jimblandy should be fixed and rebased

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to land.

src/front/glsl/functions.rs Outdated Show resolved Hide resolved
src/front/glsl/functions.rs Outdated Show resolved Hide resolved
Glsl defines under `Function Definitions` (Paragraph 6.1 in glsl 4.60),
the following:

> When function calls are resolved, an exact type match for all
> the arguments is sought.
> (...)
> If no exact match is found, then the implicit conversions in
> section “Implicit Conversions” will be applied to find a match.
> (...)
> Mismatched types on output parameters (out or inout) must have a
> conversion from the formal parameter type to the calling argument type.

The glsl frontend wasn't performing this implicit cast for output parameters.

This commit fixes that by using a proxy write, this
creates a spill variable with the correct type and in the call
prologue a conversion is made back to the original type and the
value is stored in the original variable.
@JCapucho JCapucho enabled auto-merge (rebase) February 8, 2023 11:38
@JCapucho JCapucho merged commit f038537 into gfx-rs:master Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants