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

Allow to customize float literals in output #2230

Merged

Conversation

chirsz-ever
Copy link
Contributor

This PR does not change the current behavior. It only works when invoking set_float_formatter() with initiative.

I use std::shared_ptr to store a FloatFormatter virtual base object, because it can use customized deleter (compare to std::unique_ptr). Would it be better to just use a raw pointer FloatFormatter* and require the user to keep it valid?

Related issues: #2132 #1599

spirv_glsl.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@HansKristian-Work HansKristian-Work left a comment

Choose a reason for hiding this comment

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

As mentioned, this is simple enough, see comments though.

{
public:
virtual ~FloatFormatter() = default;
virtual std::string format_float(float value) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is one needed for fp16, or will that hit the format_float part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently float16_t will be converted to float before be converted to string:

SPIRV-Cross/spirv_glsl.cpp

Lines 5910 to 5913 in 42aac91

string CompilerGLSL::convert_half_to_string(const SPIRConstant &c, uint32_t col, uint32_t row)
{
string res;
float float_value = c.scalar_f16(col, row);

I think format_float16 is not needed.

@chirsz-ever chirsz-ever force-pushed the chirsz/custom-float-formater branch from 27c99f3 to aaddc49 Compare November 22, 2023 12:07
@chirsz-ever
Copy link
Contributor Author

I use "build" subdirectory to generated CMake files, so I added it to .gitignore. Please point out if it conflicts with something.

@chirsz-ever chirsz-ever force-pushed the chirsz/custom-float-formater branch from aaddc49 to 20dd53b Compare November 22, 2023 14:17
spirv_glsl.hpp Outdated Show resolved Hide resolved
spirv_glsl.hpp Outdated Show resolved Hide resolved
spirv_glsl.hpp Outdated Show resolved Hide resolved
@HansKristian-Work HansKristian-Work merged commit 42299f9 into KhronosGroup:main Nov 24, 2023
5 checks passed
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.

2 participants