Merge pull request #2780 from Noisyfox:bugfix/amd-png

Fix PNG build plate texture not rendering on AMD GPUs
This commit is contained in:
SoftFever 2023-11-19 19:08:04 +08:00 committed by GitHub
commit 93f62a47f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 360 additions and 168 deletions

View file

@ -1,3 +1,7 @@
///|/ Copyright (c) Prusa Research 2018 - 2023 Enrico Turri @enricoturri1966, Oleksandra Iushchenko @YuSanka, Lukáš Matěna @lukasmatena, Lukáš Hejl @hejllukas, Vojtěch Bubník @bubnikv, Vojtěch Král @vojtechkral
///|/
///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
///|/
#include "libslic3r/libslic3r.h"
#include "OpenGLManager.hpp"
@ -212,7 +216,7 @@ std::string OpenGLManager::GLInfo::to_string(bool for_github) const
OpenGLManager::GLInfo OpenGLManager::s_gl_info;
bool OpenGLManager::s_compressed_textures_supported = false;
bool OpenGLManager::m_use_manually_generated_mipmaps = true;
bool OpenGLManager::s_force_power_of_two_textures = false;
OpenGLManager::EMultisampleState OpenGLManager::s_multisample = OpenGLManager::EMultisampleState::Unknown;
OpenGLManager::EFramebufferType OpenGLManager::s_framebuffers_type = OpenGLManager::EFramebufferType::Unknown;
@ -295,31 +299,22 @@ bool OpenGLManager::init_gl(bool popup_error)
#ifdef _WIN32
// Since AMD driver version 22.7.1, there is probably some bug in the driver that causes the issue with the missing
// texture of the bed. It seems that this issue only triggers when mipmaps are generated manually
// (combined with a texture compression) and when mipmaps are generated through OpenGL glGenerateMipmap is working.
// So, for newer drivers than 22.6.1, the last working driver version, we use mipmaps generated through OpenGL.
if (const auto gl_info = OpenGLManager::get_gl_info(); boost::contains(gl_info.get_vendor(), "ATI Technologies Inc.")) {
// WHQL drivers seem to have one more version number at the end besides non-WHQL drivers.
// WHQL: 4.6.14800 Compatibility Profile Context 22.6.1 30.0.21023.1015
// Non-WHQL: 4.6.0 Compatibility Profile Context 22.8.1.220810
std::regex version_rgx(R"(Compatibility\sProfile\sContext\s(\d+)\.(\d+)\.(\d+))");
if (std::smatch matches; std::regex_search(gl_info.get_version(), matches, version_rgx) && matches.size() == 4) {
int version_major = std::stoi(matches[1].str());
int version_minor = std::stoi(matches[2].str());
int version_patch = std::stoi(matches[3].str());
BOOST_LOG_TRIVIAL(debug) << "Found AMD driver version: " << version_major << "." << version_minor << "." << version_patch;
if (version_major > 22 || (version_major == 22 && version_minor > 6) || (version_major == 22 && version_minor == 6 && version_patch > 1)) {
m_use_manually_generated_mipmaps = false;
BOOST_LOG_TRIVIAL(debug) << "Mipmapping through OpenGL was enabled.";
}
} else {
BOOST_LOG_TRIVIAL(error) << "Not recognized format of version.";
}
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "not AMD driver.";
}
#endif
// texture of the bed (see: https://github.com/prusa3d/PrusaSlicer/issues/8417).
// It seems that this issue only triggers when mipmaps are generated manually
// (combined with a texture compression) with texture size not being power of two.
// When mipmaps are generated through OpenGL function glGenerateMipmap() the driver works fine,
// but the mipmap generation is quite slow on some machines.
// There is no an easy way to detect the driver version without using Win32 API because the strings returned by OpenGL
// have no standardized format, only some of them contain the driver version.
// Until we do not know that driver will be fixed (if ever) we force the use of power of two textures on all cards
// 1) containing the string 'Radeon' in the string returned by glGetString(GL_RENDERER)
// 2) containing the string 'Custom' in the string returned by glGetString(GL_RENDERER)
const auto& gl_info = OpenGLManager::get_gl_info();
if (boost::contains(gl_info.get_vendor(), "ATI Technologies Inc.") &&
(boost::contains(gl_info.get_renderer(), "Radeon") ||
boost::contains(gl_info.get_renderer(), "Custom")))
s_force_power_of_two_textures = true;
#endif // _WIN32
}
return true;