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

[0017] Investigate catastrophic failures more cloesly #184

Closed
llvm-beanz opened this issue Mar 28, 2024 · 1 comment · Fixed by #187
Closed

[0017] Investigate catastrophic failures more cloesly #184

llvm-beanz opened this issue Mar 28, 2024 · 1 comment · Fixed by #187
Assignees
Labels
active proposal Issues relating to active proposals needs-triage

Comments

@llvm-beanz
Copy link
Collaborator

Which proposal does this relate to?
0017 Conforming Literals

Describe the issue or outstanding question.
During experimentation with existing shaders we discovered several cases with catastrophic rendering defects. We should investigate them to determine if we need to do additional mitigations.

@llvm-beanz llvm-beanz added active proposal Issues relating to active proposals needs-triage labels Mar 28, 2024
@llvm-beanz llvm-beanz self-assigned this Mar 28, 2024
llvm-beanz added a commit that referenced this issue Mar 30, 2024
This adds a bunch of detail about experiments that were run to assess
the potential impact of this language change on existing shader code.

The TL;DR is that the thesis holds that few shaders in production
titles are expected to be significantly impacted.

Issues tracking additional follow-up: #183 & #184
@llvm-beanz
Copy link
Collaborator Author

Investigating this a bit further this is not at all what I expected. The problematic behavior change occurs with code like this:

export float Fn(int inInt, inFloat) {
  int Val = (inInt & 0xffff0000) >> 16);
  return Val* inFloat
}

Compiler Explorer

With HLSL's literal int type 0xffff0000 is signed, which means the bit shifts are arithmetic shifts filling in the sign bit.

define float @"\01?Fn@@YAMHM@Z"(i32 %inInt, float %inFloat) #0 {
  %1 = ashr i32 %inInt, 16
  %2 = sitofp i32 %1 to float
  %3 = fmul fast float %2, %inFloat
  ret float %3
}

With C's rules 0xffff0000 is unsigned, and the logical operators produce an unsigned result with 0's shifted in at the most significant bits.

define float @"\01?Fn@@YAMHM@Z"(i32 %inInt, float %inFloat) #0 {
  %1 = lshr i32 %inInt, 16
  %2 = sitofp i32 %1 to float
  %3 = fmul fast float %2, %inFloat
  ret float %3
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
active proposal Issues relating to active proposals needs-triage
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant