From a3fcbb54f4b0dac7f9104d5f45c8540e9764e46d Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Mon, 4 Jan 2021 11:41:54 +0100 Subject: GPU: Add HQ normals workaround. This change makes it possible for platforms to only support high quality normal rendering. This is part of {T82856} where current AMD drivers running on the polaris architecture does not support the low quality setting due to a driver bug. In a next commit the work around will be enabled. --- source/blender/draw/intern/draw_cache_extract_mesh.c | 3 ++- source/blender/draw/intern/draw_cache_impl_curve.c | 5 +++-- source/blender/draw/intern/draw_cache_impl_displist.c | 6 ++++-- source/blender/draw/intern/draw_cache_impl_volume.c | 4 +++- source/blender/gpu/GPU_capabilities.h | 1 + source/blender/gpu/intern/gpu_capabilities.cc | 5 +++++ source/blender/gpu/intern/gpu_capabilities_private.hh | 1 + 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c index 7766ce906b8..576c029390c 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh.c +++ b/source/blender/draw/intern/draw_cache_extract_mesh.c @@ -5578,7 +5578,8 @@ static void extract_task_create(struct TaskGraph *task_graph, int32_t *task_counter) { BLI_assert(scene != NULL); - const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0; + const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0 || + GPU_use_hq_normals_workaround(); if (do_hq_normals && (extract == &extract_lnor)) { extract = &extract_lnor_hq; } diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c index b9585aec0b2..3ccada23d47 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.c +++ b/source/blender/draw/intern/draw_cache_impl_curve.c @@ -36,6 +36,7 @@ #include "BKE_font.h" #include "GPU_batch.h" +#include "GPU_capabilities.h" #include "GPU_material.h" #include "GPU_texture.h" @@ -634,11 +635,11 @@ static void curve_create_edit_curves_nor(CurveRenderData *rdata, GPUVertBuf *vbo_curves_nor, const Scene *scene) { - const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0; + const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0 || + GPU_use_hq_normals_workaround(); static GPUVertFormat format = {0}; static GPUVertFormat format_hq = {0}; - /* TODO(jeroen): add support for high quality normals */ static struct { uint pos, nor, tan, rad; uint pos_hq, nor_hq, tan_hq, rad_hq; diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c index e1dbbe2c2be..72f3e7b0fa8 100644 --- a/source/blender/draw/intern/draw_cache_impl_displist.c +++ b/source/blender/draw/intern/draw_cache_impl_displist.c @@ -177,7 +177,8 @@ static int displist_indexbufbuilder_tess_set( void DRW_displist_vertbuf_create_pos_and_nor(ListBase *lb, GPUVertBuf *vbo, const Scene *scene) { - const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0; + const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0 || + GPU_use_hq_normals_workaround(); static GPUVertFormat format = {0}; static GPUVertFormat format_hq = {0}; @@ -485,7 +486,8 @@ void DRW_displist_vertbuf_create_loop_pos_and_nor_and_uv_and_tan(ListBase *lb, GPUVertBuf *vbo_tan, const Scene *scene) { - const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0; + const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0 || + GPU_use_hq_normals_workaround(); static GPUVertFormat format_pos_nor = {0}; static GPUVertFormat format_pos_nor_hq = {0}; diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c index e90282a269a..1119e0458a5 100644 --- a/source/blender/draw/intern/draw_cache_impl_volume.c +++ b/source/blender/draw/intern/draw_cache_impl_volume.c @@ -40,6 +40,7 @@ #include "BKE_volume_render.h" #include "GPU_batch.h" +#include "GPU_capabilities.h" #include "GPU_texture.h" #include "DEG_depsgraph_query.h" @@ -157,7 +158,8 @@ static void drw_volume_wireframe_cb( Scene *scene = data->scene; Volume *volume = data->volume; VolumeBatchCache *cache = volume->batch_cache; - const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0; + const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0 || + GPU_use_hq_normals_workaround(); /* Create vertex buffer. */ static GPUVertFormat format = {0}; diff --git a/source/blender/gpu/GPU_capabilities.h b/source/blender/gpu/GPU_capabilities.h index 9d55fe73708..e02fbaa6d04 100644 --- a/source/blender/gpu/GPU_capabilities.h +++ b/source/blender/gpu/GPU_capabilities.h @@ -43,6 +43,7 @@ int GPU_texture_size_with_limit(int res); bool GPU_mip_render_workaround(void); bool GPU_depth_blitting_workaround(void); bool GPU_use_main_context_workaround(void); +bool GPU_use_hq_normals_workaround(void); bool GPU_crappy_amd_driver(void); bool GPU_shader_image_load_store_support(void); diff --git a/source/blender/gpu/intern/gpu_capabilities.cc b/source/blender/gpu/intern/gpu_capabilities.cc index 63e29654e1c..1d2b0e5c7a8 100644 --- a/source/blender/gpu/intern/gpu_capabilities.cc +++ b/source/blender/gpu/intern/gpu_capabilities.cc @@ -102,6 +102,11 @@ bool GPU_crappy_amd_driver(void) return GCaps.broken_amd_driver; } +bool GPU_use_hq_normals_workaround(void) +{ + return GCaps.use_hq_normals_workaround; +} + bool GPU_shader_image_load_store_support(void) { return GCaps.shader_image_load_store_support; diff --git a/source/blender/gpu/intern/gpu_capabilities_private.hh b/source/blender/gpu/intern/gpu_capabilities_private.hh index 3c758c4ac4a..2b3292749f8 100644 --- a/source/blender/gpu/intern/gpu_capabilities_private.hh +++ b/source/blender/gpu/intern/gpu_capabilities_private.hh @@ -48,6 +48,7 @@ struct GPUCapabilities { bool depth_blitting_workaround = false; bool use_main_context_workaround = false; bool broken_amd_driver = false; + bool use_hq_normals_workaround = false; /* Vulkan related workarounds. */ }; -- cgit v1.2.3