-
Notifications
You must be signed in to change notification settings - Fork 254
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
HLSL: Add 'f' suffix to float literals in code generation #6381
Conversation
cbe8d04
to
bbb1205
Compare
Here is the output of the hlsl shader:
|
Fixes shader-slang#6078 1) Previously, Slang would emit HLSL float literals without a suffix (e.g.,"1.5"), which caused DXC to interpret them as 64-bit doubles by default unless the -HV 202x flag was used. This could cause validation errors when these literals were used with intrinsics that only accept 32-bit floats (like ddx, ddy). This change modifies the HLSL emitter to explicitly add 'f' suffix to 32-bit float literals, ensuring they are correctly typed regardless of DXC's version or flags. For example: - "1.5" becomes "1.5f" - "(0.0 / 0.0)" becomes "(0.0f / 0.0f)" for NaN - "float4(1.0, 2.0, 3.0, 4.0)" becomes "float4(1.0f, 2.0f, 3.0f, 4.0f)" 2) Added a test case to verify the behavior with various float literal scenarios including basic literals, intrinsic calls, and vector construction. 3) Remove some tests that were marked as known failures
bbb1205
to
a83755a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to reproduce the error form DXC?
I am about to upgrade DXC from 1.7 to 1.9 and I like to know if the issue is specific to a certain version of DXC or not.
{ | ||
m_writer->emit("f"); | ||
} | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before your change, it was "break" instead of "return".
Your PR is making a change to the behavior that is not described on the PR description.
Can you explain why this change is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need return
here to avoid the fallback call to Super::emitSimpleValueImpl
since we are overriding the behavior for ordinary float literals here.
as long as all tests are passing, we are fine. |
Please use the following test, instead of one in this PR,
|
To answer my question, I was able to reproduce it with DXC 1.7. |
@jkwak-work - Yes I was able to reproduce the issue with dxc. I used this version of dxc:
Ok, you want to add dxil coverage too, right? |
Fixes #6078
Previously, Slang would emit HLSL float literals without a suffix (e.g.,"1.5"), which caused DXC to interpret them as 64-bit doubles by default unless the -HV 202x flag was used. This could cause validation errors when these literals were used with intrinsics that only accept 32-bit floats (like ddx, ddy).
This change modifies the HLSL emitter to explicitly add 'f' suffix to 32-bit float literals, ensuring they are correctly typed regardless of DXC's version or flags. For example:
Added a test case to verify the behavior with various float literal scenarios including basic literals, intrinsic calls, and vector construction.