From 0721cc8ba09b9c67208d07fa9726b7cc9412465c Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Fri, 3 Jan 2020 23:26:08 -0500 Subject: [PATCH] Vulkan: No line raster emulation code if extension A flag is added to the translator to disable generation of Bresenham line raster emulation code when the Bresenham line raster Vulkan extension is present. This is primarily for the sake of conversion of line raster emulation condition to specialization constant: - Avoid dead SPIR-V code in every shader - Avoid ANGLEUniforms being active in every shader stage even if it's not used anywhere but in line raster emulation. - Optimize SPIR-V transformations by both having fewer instructions to iterate through, and to avoid generating line raster patches. - Reduce the severity of anglebug.com/4251 where the location assignment of ANGLEPosition can incorrectly overlap a varying array or struct, by making only platforms without Bresenham extension afflicted by the bug. Bug: angleproject:3394 Change-Id: Ic0ae6ce0392b4eae0cc79cb94bbcd0805b276a31 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1986379 Reviewed-by: Cody Northrop Reviewed-by: Jamie Madill Commit-Queue: Shahbaz Youssefi --- include/GLSLANG/ShaderLang.h | 7 ++++++- src/compiler/translator/TranslatorVulkan.cpp | 16 +++++++++++----- src/libANGLE/renderer/vulkan/ShaderVk.cpp | 5 +++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/GLSLANG/ShaderLang.h b/include/GLSLANG/ShaderLang.h index 0a20a135b..f9bd1314c 100644 --- a/include/GLSLANG/ShaderLang.h +++ b/include/GLSLANG/ShaderLang.h @@ -26,7 +26,7 @@ // Version number for shader translation API. // It is incremented every time the API changes. -#define ANGLE_SH_VERSION 221 +#define ANGLE_SH_VERSION 222 enum ShShaderSpec { @@ -318,6 +318,11 @@ const ShCompileOptions SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR = UINT64_C( // on Windows 7 and earlier. const ShCompileOptions SH_DONT_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER = UINT64_C(1) << 50; +// This flag indicates whether Bresenham line raster emulation code should be generated. This +// emulation is necessary if the backend uses a differnet algorithm to draw lines. Currently only +// implemented for the Vulkan backend. +const ShCompileOptions SH_ADD_BRESENHAM_LINE_RASTER_EMULATION = UINT64_C(1) << 51; + // Defines alternate strategies for implementing array index clamping. enum ShArrayIndexClampingStrategy { diff --git a/src/compiler/translator/TranslatorVulkan.cpp b/src/compiler/translator/TranslatorVulkan.cpp index 94037949f..1719200e9 100644 --- a/src/compiler/translator/TranslatorVulkan.cpp +++ b/src/compiler/translator/TranslatorVulkan.cpp @@ -870,10 +870,13 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root, } } - if (!AddBresenhamEmulationFS(this, sink, root, &getSymbolTable(), driverUniforms, - usesFragCoord)) + if (compileOptions & SH_ADD_BRESENHAM_LINE_RASTER_EMULATION) { - return false; + if (!AddBresenhamEmulationFS(this, sink, root, &getSymbolTable(), driverUniforms, + usesFragCoord)) + { + return false; + } } bool hasGLFragColor = false; @@ -936,9 +939,12 @@ bool TranslatorVulkan::translateImpl(TIntermBlock *root, } else if (getShaderType() == GL_VERTEX_SHADER) { - if (!AddBresenhamEmulationVS(this, root, &getSymbolTable(), driverUniforms)) + if (compileOptions & SH_ADD_BRESENHAM_LINE_RASTER_EMULATION) { - return false; + if (!AddBresenhamEmulationVS(this, root, &getSymbolTable(), driverUniforms)) + { + return false; + } } // Add a macro to declare transform feedback buffers. diff --git a/src/libANGLE/renderer/vulkan/ShaderVk.cpp b/src/libANGLE/renderer/vulkan/ShaderVk.cpp index fc96301f5..d777cd1f5 100644 --- a/src/libANGLE/renderer/vulkan/ShaderVk.cpp +++ b/src/libANGLE/renderer/vulkan/ShaderVk.cpp @@ -40,6 +40,11 @@ std::shared_ptr ShaderVk::compile(const gl::Context *conte compileOptions |= SH_CLAMP_POINT_SIZE; } + if (contextVk->getFeatures().basicGLLineRasterization.enabled) + { + compileOptions |= SH_ADD_BRESENHAM_LINE_RASTER_EMULATION; + } + if (contextVk->emulateSeamfulCubeMapSampling()) { compileOptions |= SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING;