Skip to content

Conversation

@ltjax
Copy link

@ltjax ltjax commented Dec 30, 2025

PR for Issue #1101
Pretty superficial fixes, e.g. formatOptionalFileOffset could probably be refactored to work without fmt::runtime, but this was less invasive.

Unfortunately, it doesn't compile with C++ 20 and 23 for me anymore after I rebased onto main, but due to different problems, i.e.:

/home/ltjax/code/KTX-Software/tools/ktx/command_convert.cpp:208:65: error: no matching function for call to ‘ktx::OutputStreamEx::OutputStreamEx(std::u8string, ktx::CommandConvert&)’
  208 |     OutputStreamEx outputStream(outputFilepath.u8string(), *this);
      |                                                                 ^
/home/ltjax/code/KTX-Software/tools/ktx/command_convert.cpp:82:5: note: candidate: ‘ktx::OutputStreamEx::OutputStreamEx(const std::string&, ktx::Reporter&)’
   82 |     OutputStreamEx(const std::string& filepath, Reporter& report)
      |     ^~~~~~~~~~~~~~
/home/ltjax/code/KTX-Software/tools/ktx/command_convert.cpp:82:39: note:   no known conversion for argument 1 from ‘std::u8string’ {aka ‘std::__cxx11::basic_string<char8_t>’} to ‘const std::string&’ {aka ‘const std::__cxx11::basic_string<char>&’}
   82 |     OutputStreamEx(const std::string& filepath, Reporter& report)
      |                    ~~~~~~~~~~~~~~~~~~~^~~~~~~~

I don't know how to proceed there. You seem to have put some thought into utf8 handling and might better know how to fix that one.

@CLAassistant
Copy link

CLAassistant commented Dec 30, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@MarkCallow MarkCallow left a comment

Choose a reason for hiding this comment

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

I have only the one question.

virtual std::string value(std::size_t index, OutputFormat format) const override {
if (format == OutputFormat::text) {
return fmt::format(fmt::format("0x{{:0{}x}}", sizeof(T) << 1), DiffBase<T>::rawValue(index));
return fmt::format(fmt::runtime(fmt::format("0x{{:0{}x}}", sizeof(T) << 1)), DiffBase<T>::rawValue(index));
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the fmt::runtime for?

Copy link
Author

@ltjax ltjax Jan 2, 2026

Choose a reason for hiding this comment

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

It just turns off the compile-time checking of the format string for the outer format call. I basically added it whenever the format string was runtime-generated.

Actually, I think in this case, you can probably get away with just a single format call and get rid of fmt::runtime. AFAIK, fmt can deal with placeholders in placeholders just fine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer if we can get rid of it.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, done.

@MarkCallow
Copy link
Collaborator

/home/ltjax/code/KTX-Software/tools/ktx/command_convert.cpp:208:65: error: no matching function for call to > ‘ktx::OutputStreamEx::OutputStreamEx(std::u8string, ktx::CommandConvert&)’
 208 |     OutputStreamEx outputStream(outputFilepath.u8string(), *this);
     |                                                                 ^

Sorry. I did not pay proper attention to your description. I initially thought this was a problem this PR fixes.

The issue is that c++20 supports the new u8string type and filesystem::path::u8string() returns a u8string instead of a string. The fix is to add an overload for the OutputStreamEx constructor that takes a u8string. Implementation may require u8string-supporting versions of our utf8 file handling utilities. I have just created those, but they are in a branch I'm working on. I'll make a PR as soon as I can with those, some fixes I am already making in command.cpp where OutputStreamEx is defined, and a fix for this issue. I'll ask you to rebase when that is done. In the meantime please answer the question in my review.

@MarkCallow
Copy link
Collaborator

The fix for the OutputStreamEx constructor for c++20 is now in main from PR #1103. Please rebase this.

@ltjax
Copy link
Author

ltjax commented Jan 3, 2026

Ok, I rebased and removed that fmt::runtime, but it still does not compile with C++20 and C++23, albeit with different errors:

For CMAKE_CXX_STANDARD=23 I'm getting:

/home/ltjax/code/KTX-Software/external/basis_universal/encoder/cppspmd_sse.h:496:24: error: cannot bind non-const lvalue reference of type ‘cppspmd_sse41::spmd_kernel::vfloat&’ to an rvalue of type ‘cppspmd_sse41::spmd_kernel::vfloat’
  496 |                 return dst;
      |                        ^~~
/home/ltjax/code/KTX-Software/external/basis_universal/encoder/cppspmd_sse.h: In member function ‘cppspmd_sse41::spmd_kernel::vfloat& cppspmd_sse41::spmd_kernel::store_all(vfloat&&, const vfloat&)’:
/home/ltjax/code/KTX-Software/external/basis_universal/encoder/cppspmd_sse.h:508:24: error: cannot bind non-const lvalue reference of type ‘cppspmd_sse41::spmd_kernel::vfloat&’ to an rvalue of type ‘cppspmd_sse41::spmd_kernel::vfloat’
  508 |                 return dst;
      |    

Not sure what the intention is with those, since the type does not really seem movable? But it's an external anyways, so I'm not sure whether you want that fixed.

For CMAKE_CXX_STANDARD=20, the first error I'm getting is:

/home/ltjax/code/KTX-Software/utils/platform_utils.h:125:21: error: could not convert ‘std::__cxx11::basic_string<char8_t>((& s)->std::__cxx11::basic_string<char>::begin(), (& s)->std::__cxx11::basic_string<char>::end(), std::allocator<char8_t>())’ from ‘basic_string<char8_t>’ to ‘basic_string<char>’
  125 |         return std::u8string(s.begin(), s.end());
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                     |
      |                     basic_string<char8_t>

I think the return type should be std::u8string, but even after fixing that there are still a lot of utf8 related errors, e.g. the additional OutputStream (without Ex) constructor has OutputStream::, but it defined in the class. And InputStream and fmtInFile in command_compare still cannot deal with std::u8string.

@MarkCallow
Copy link
Collaborator

I think the return type should be std::u8string

Sorry for the stupid copy and paste error. The return type should indeed be std::u8string. Please fix it in this PR.

e.g. the additional OutputStream (without Ex) constructor has OutputStream::, but it defined in the class.

Sorry about that too. I started implementation in command.cpp but when I realized it would simply convert the input and call the other constructor I moved it to the class definition.

I do not understand how everything built in our CI. All of the libktx tests use c++20 and two of them include platform_utils.h.Most peculiar.

I have fixed the InputStream and fmtInFile issues. Please see the c++fixes branch for the fixes. I am leaving tomorrow for a 10-day trip. I'm not sure I will have time to merge this to main before I leave. Should I not, please feel free to include the fixes directly in this PR.

I won't run the workflows until the fixes are in this PR.

I could not thoroughly test building the ktx tool with the above changes because of all the fmt related issues whose fixes are in this PR.

As for the C++23 issue with cppspmd_sse.h, please report it to https://github.com/BinomialLLC/basis_universal/.

@MarkCallow
Copy link
Collaborator

I'm not sure I will have time to merge this to main before I leave.

The fixes are merged. See PR #1104.

@ltjax
Copy link
Author

ltjax commented Jan 4, 2026

Great! It works for C++17 and C++20 for me now, C++23 if I fix or disable (via BASISU_SSE=OFF) the SSE stuff

@ltjax
Copy link
Author

ltjax commented Jan 4, 2026

Interestingly, it seems like you already reported the build problem in basisu a while ago: BinomialLLC/basis_universal#366

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