Hash :
3b65b803
Author :
Date :
2022-04-27T11:04:22
Vulkan: Work around Qualcomm imprecision with dithering On qualcomm, sometimes the output is ceil()ed instead of round()ed. With ditering emulation affecting values, some dEQP tests fail due to the excessive change in value when dithering bumps the value slightly over to the next quantum. In this change, a workaround is added to round() the value before outputting it. Bug: angleproject:6953 Change-Id: Iae7df5ca20055b4db3185c6153f3c0bf4ba07f68 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3611064 Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderVk.cpp:
// Implements the class methods for ShaderVk.
//
#include "libANGLE/renderer/vulkan/ShaderVk.h"
#include "common/debug.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "platform/FeaturesVk_autogen.h"
namespace rx
{
ShaderVk::ShaderVk(const gl::ShaderState &state) : ShaderImpl(state) {}
ShaderVk::~ShaderVk() {}
std::shared_ptr<WaitableCompileEvent> ShaderVk::compile(const gl::Context *context,
gl::ShCompilerInstance *compilerInstance,
ShCompileOptions options)
{
ShCompileOptions compileOptions = 0;
ContextVk *contextVk = vk::GetImpl(context);
if (context->isWebGL())
{
// Only WebGL requires initialization of local variables, others don't.
// Extra initialization in spirv shader may affect performance.
compileOptions |= SH_INITIALIZE_UNINITIALIZED_LOCALS;
// WebGL shaders may contain OOB array accesses which in turn cause undefined behavior,
// which may result in security issues. See https://crbug.com/1189110.
compileOptions |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS;
if (mState.getShaderType() != gl::ShaderType::Compute)
{
compileOptions |= SH_INIT_OUTPUT_VARIABLES;
}
}
if (contextVk->getFeatures().clampPointSize.enabled)
{
compileOptions |= SH_CLAMP_POINT_SIZE;
}
if (contextVk->getFeatures().basicGLLineRasterization.enabled)
{
compileOptions |= SH_ADD_BRESENHAM_LINE_RASTER_EMULATION;
}
if (contextVk->getFeatures().emulateAdvancedBlendEquations.enabled)
{
compileOptions |= SH_ADD_ADVANCED_BLEND_EQUATIONS_EMULATION;
}
if (contextVk->emulateSeamfulCubeMapSampling())
{
compileOptions |= SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING;
}
if (!contextVk->getFeatures().enablePrecisionQualifiers.enabled)
{
compileOptions |= SH_IGNORE_PRECISION_QUALIFIERS;
}
if (contextVk->getFeatures().forceFragmentShaderPrecisionHighpToMediump.enabled)
{
compileOptions |= SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP;
}
// Let compiler detect and emit early fragment test execution mode. We will remove it if
// context state does not allow it
compileOptions |= SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION;
// Let compiler use specialized constant for pre-rotation.
if (!contextVk->getFeatures().forceDriverUniformOverSpecConst.enabled)
{
compileOptions |= SH_USE_SPECIALIZATION_CONSTANT;
}
if (contextVk->getFeatures().enablePreRotateSurfaces.enabled ||
contextVk->getFeatures().emulatedPrerotation90.enabled ||
contextVk->getFeatures().emulatedPrerotation180.enabled ||
contextVk->getFeatures().emulatedPrerotation270.enabled)
{
// Let compiler insert pre-rotation code.
compileOptions |= SH_ADD_PRE_ROTATION;
}
if (contextVk->getFeatures().supportsTransformFeedbackExtension.enabled)
{
compileOptions |= SH_ADD_VULKAN_XFB_EXTENSION_SUPPORT_CODE;
}
else if (mState.getShaderType() == gl::ShaderType::Vertex &&
contextVk->getFeatures().emulateTransformFeedback.enabled)
{
compileOptions |= SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE;
}
if (contextVk->getFeatures().generateSPIRVThroughGlslang.enabled)
{
compileOptions |= SH_GENERATE_SPIRV_THROUGH_GLSLANG;
}
if (contextVk->getFeatures().roundOutputAfterDithering.enabled)
{
compileOptions |= SH_ROUND_OUTPUT_AFTER_DITHERING;
}
return compileImpl(context, compilerInstance, mState.getSource(), compileOptions | options);
}
std::string ShaderVk::getDebugInfo() const
{
return mState.getCompiledBinary().empty() ? "" : "<binary blob>";
}
} // namespace rx