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

remove d3dx dependency, severely improve memory usage but loading takes a long time initially #19

Merged
merged 27 commits into from
Dec 4, 2023

Conversation

DubbleClick
Copy link
Member

No description provided.

fails when using std::launch::async though, maybe something in the directxtex library is not thread safe
@DubbleClick DubbleClick added the enhancement New feature or request label Dec 3, 2023
}
std::vector<std::future<unsigned>> futures;
for (const auto modfile : modfiles) {
futures.emplace_back(std::async(std::launch::deferred, ProcessModfile, std::ref(*this), modfile, files_size > 400'000'000));
Copy link
Member Author

Choose a reason for hiding this comment

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

I think 400'000'000 bytes is a sensible value. 450mb load to roughly 850mb of non-compressed memory and around 250mb of compressed memory. With 850mb of texmod data, worst case, we still have 1gb free for gw itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

launching this deferred instead of async because some part of the directxtex library doesn't seem work when using its functions asynchronously

Comment on lines +267 to +274
if (image.GetMetadata().format == DXGI_FORMAT_B8G8R8X8_UNORM) {
// todo: this is undefined behaviour, but we must force them to be interpreted as BGRA instead of BGRX
const_cast<DXGI_FORMAT&>(image.GetMetadata().format) = DXGI_FORMAT_B8G8R8A8_UNORM;
const auto images = image.GetImages();
for (int i = 0; i < image.GetImageCount(); ++i) {
const_cast<DXGI_FORMAT&>(images[i].format) = DXGI_FORMAT_B8G8R8A8_UNORM;
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

don't see any way around undefined behaviour here. unfortunately, we're forced to do this.

Comment on lines +99 to +102
const static std::regex re(R"(0x[0-9a-f]{8})", std::regex::optimize | std::regex::icase);
std::smatch match;
if (!std::regex_search(name, match, re)) {
continue;
Copy link
Member Author

Choose a reason for hiding this comment

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

texmod/umod always saved them padded to 8 chars, right?

DirectX::ScratchImage ImageConvertToBGRA(DirectX::ScratchImage& image, const TexEntry& entry)
{
if (image.GetMetadata().format == DXGI_FORMAT_B8G8R8A8_UNORM || image.GetMetadata().format == DXGI_FORMAT_BC3_UNORM) {
return std::move(image);
Copy link
Member Author

Choose a reason for hiding this comment

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

ye, I know... unfortunately not much of a choice, it would be better to not call the function if it wasn't necessary, but the check is more appropriate here

@DubbleClick DubbleClick merged commit 9e593e8 into master Dec 4, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant