Fix T71576 Mesh error on mutimaterial Meshes on legacy nvidia drivers

Differential Revision: https://developer.blender.org/D6351
This commit is contained in:
Clément Foucault 2019-12-03 15:22:02 +01:00
parent 6ba09f8515
commit cf77b67c45
Notes: blender-bot 2023-02-14 04:10:15 +01:00
Referenced by commit e2806b7429, Revert "Fix T71576 Mesh error on mutimaterial Meshes on legacy nvidia drivers"
Referenced by issue #71576, Viewport/crash artefacts with multiple materials and legacy NVIDIA drivers
4 changed files with 26 additions and 4 deletions

View File

@ -80,7 +80,7 @@ uniform int baseInstance;
# if defined(IN_PLACE_INSTANCES) || defined(INSTANCED_ATTRIB)
/* When drawing instances of an object at the same position. */
# define instanceId 0
# elif defined(GPU_DEPRECATED_AMD_DRIVER)
# elif defined(GPU_DEPRECATED_AMD)
/* A driver bug make it so that when using an attribute with GL_INT_2_10_10_10_REV as format,
* the gl_InstanceID is incremented by the 2 bit component of the attrib.
* Ignore gl_InstanceID then. */
@ -115,8 +115,11 @@ flat in int resourceIDFrag;
# define resource_id resourceIDFrag
#endif
#if !defined(GPU_INTEL) && !defined(GPU_DEPRECATED_AMD_DRIVER) && !defined(OS_MAC) && \
!defined(INSTANCED_ATTRIB)
#if !defined(GPU_INTEL) && !defined(GPU_DEPRECATED_AMD) && !defined(GPU_DEPRECATED_NVIDIA)
# define USE_INDEXED_MODELMAT
#endif
#if defined(USE_INDEXED_MODELMAT) && !defined(OS_MAC) && !defined(INSTANCED_ATTRIB)
struct ObjectMatrices {
mat4 drw_modelMatrix;
mat4 drw_modelMatrixInverse;

View File

@ -48,6 +48,7 @@ bool GPU_mip_render_workaround(void);
bool GPU_depth_blitting_workaround(void);
bool GPU_unused_fb_slot_workaround(void);
bool GPU_context_local_shaders_workaround(void);
bool GPU_legacy_nvidia_driver(void);
bool GPU_crappy_amd_driver(void);
bool GPU_mem_stats_supported(void);

View File

@ -93,6 +93,8 @@ static struct GPUGlobal {
/* Some crappy Intel drivers don't work well with shaders created in different
* rendering contexts. */
bool context_local_shaders_workaround;
/* Unmaintained NVIDIA drivers contain certain bugs we need to workaround. */
bool legacy_nvidia_driver;
} GG = {1, 0};
static void gpu_detect_mip_render_workaround(void)
@ -216,6 +218,11 @@ bool GPU_context_local_shaders_workaround(void)
return GG.context_local_shaders_workaround;
}
bool GPU_legacy_nvidia_driver(void)
{
return GG.legacy_nvidia_driver;
}
bool GPU_crappy_amd_driver(void)
{
/* Currently are the same drivers with the `unused_fb_slot` problem. */
@ -281,6 +288,14 @@ void gpu_extensions_init(void)
GG.glew_arb_base_instance_is_supported = GLEW_ARB_base_instance;
gpu_detect_mip_render_workaround();
if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_OFFICIAL)) {
char *driver_version_str = strstr(version, "NVIDIA ") + 7;
int driver_major_version = (int)strtol(driver_version_str, NULL, 10);
if (driver_major_version > 0 && driver_major_version < 400) {
GG.legacy_nvidia_driver = true;
}
}
if (G.debug & G_DEBUG_GPU_FORCE_WORKAROUNDS) {
printf("\n");
printf("GPU: Bypassing workaround detection.\n");

View File

@ -243,11 +243,14 @@ static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH])
if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
strcat(defines, "#define GPU_ATI\n");
if (GPU_crappy_amd_driver()) {
strcat(defines, "#define GPU_DEPRECATED_AMD_DRIVER\n");
strcat(defines, "#define GPU_DEPRECATED_AMD\n");
}
}
else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY)) {
strcat(defines, "#define GPU_NVIDIA\n");
if (GPU_legacy_nvidia_driver()) {
strcat(defines, "#define GPU_DEPRECATED_NVIDIA\n");
}
}
else if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) {
strcat(defines, "#define GPU_INTEL\n");