-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conforming literals 0017 messes up code sharing between C++ and HLSL due to non portable float literal suffices #304
Comments
I'd actually implement this first https://en.cppreference.com/w/cpp/language/user_literal compiling with C++23 just to have f16,f32,f64 suffices on the Host side is a bit of a steep ask. |
On our side, the most important compatibility is with GLSL, MSL, Nvidia slang and a proprietary console shader language.
Compatibility with C++ on the literal side isn't quite important because there are a lot of other in compatibilities between HLSL and C++ like structure member alignment, no 8-bit types, In our case, we only ever need to share structure definitions with C++ not functions. This is not the same requirements as @devshgraphicsprogramming. I feel like we'd need a command line switch for the HLSL compilers to switch between the "shader standard" suffixes and the "C/C++" suffixes. |
This is the kind of thing I'm pretty vocally opposed to. We do not want flags to the compiler that change basic language behaviors. That dramatically increases our testing matrix and leads to difficult to identify, reproduce and resolve bugs. |
Understood. Well, we don't have control over C++ and changing the current behavior would bring us back to where we started with spurious So, I really wish we won't go back. But I also wish C++ had a suffix for doubles (and for short). |
C++23 has kinda low adoption, and doesn't introduce a suffix for short literals. So IMHO user defined literal suffices are probably the most useful for everyone. |
Which proposal does this relate to?
0017 - https://github.com/microsoft/hlsl-specs/blob/main/proposals/0017-conforming-literals.md
Describe the issue or outstanding question.
HLSL will now treat
4.5
as a float literal, while most C++ compilers treat4.5
as a double literal.This is an issue when one wants to share lets say a header of mathematical constants between HLSL and C++ (like our bezier and polynomial solvers).
No combination of suffices is portable across Clang, GCC and MSVC that would make the
4.5
a double both in HLSL and C++.While I understand that in HLSL the default literal type must be
float32
for performance reasons, we must have a solution thats more sane than wrapping every literal in aFLOAT64_LITERAL()
macro to get the correct compiler specific suffices.Additional context
Personally I'd add support for the sized
f16
,f32
andf64
suffices introduced by C++23.The text was updated successfully, but these errors were encountered: