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

check max mipmap level for texture creation #16783

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion native/cocos/renderer/gfx-validator/TextureValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ void TextureValidator::doInit(const TextureInfo &info) {
}

if (hasFlag(info.flags, TextureFlagBit::GEN_MIPMAP)) {
CC_ASSERT(info.levelCount > 1);
auto maxLevelCount = std::floor(std::log2(std::max({ info.width, info.height, info.depth }))) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think don't have to +1 for some situations, for example std::max({ info.width, info.height, info.depth }) == 8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

check here:

uint32_t getLevelCount(uint32_t width, uint32_t height) {
return static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
}

and this method actually could be moved to somewhere for common use.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, I think it is better to use _actor->getLevelCount() to get the value. And we may fix the logic of _actor->getLevelCount() in future.

CC_ASSERT(info.levelCount > 1 && info.levelCount <= maxLevelCount);

bool isCompressed = GFX_FORMAT_INFOS[static_cast<int>(info.format)].isCompressed;
CC_ASSERT(!isCompressed);
Expand Down