Commit a42e8b2c by Olli Etuaho Committed by Commit Bot

Support precision emulation on HLSL

Add precision emulation support to HLSL 4.1 output. This makes it possible for developers to test their shaders for precision issues easily on Chrome on Windows without having to use the GL backend. The patch has been verified with Chrome on Windows to reproduce some precision bugs in real-world WebGL content, including old versions of the babylon.js library. The EmulatePrecision AST transformation still relies on writing out raw shader code for the rounding functions, with raw HLSL code added alongside pre-existing GLSL and ESSL code. In some ways it would be nicer to do the EmulatePrecision step as a pure AST transformation, but on the other hand the raw code is much more readable and easier to optimize. To better support multiple output languages in EmulatePrecision, add a RoundingHelperWriter class that has different subclasses for writing the rounding functions in different languages. The unit tests are expanded to cover the HLSL output of precision emulation. The parts of the tests that require the HLSL output are only active on Windows where ANGLE_ENABLE_HLSL define is added to the unit tests. Putting the HLSL tests in an entirely separate file is a worse alternative, since it would require either a lot of code duplication or add a lot of boilerplate to the individual tests. BUG=angleproject:1437 TEST=angle_unittests Change-Id: Ia4ba0374cd415908f16f34752321af1cb93525a5 Reviewed-on: https://chromium-review.googlesource.com/358473Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent fea6e952
......@@ -1677,6 +1677,12 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << DisambiguateFunctionName(node->getSequence());
out << (lod0 ? "Lod0(" : "(");
}
else if (node->getNameObj().isInternal())
{
// This path is used for internal functions that don't have their definitions in the
// AST, such as precision emulation functions.
out << DecorateFunctionIfNeeded(node->getNameObj()) << "(";
}
else
{
TString name = TFunction::unmangleName(node->getNameObj().getString());
......
......@@ -7,6 +7,7 @@
#include "compiler/translator/TranslatorHLSL.h"
#include "compiler/translator/ArrayReturnValueToOutParameter.h"
#include "compiler/translator/EmulatePrecision.h"
#include "compiler/translator/OutputHLSL.h"
#include "compiler/translator/RemoveDynamicIndexing.h"
#include "compiler/translator/RewriteElseBlocks.h"
......@@ -52,6 +53,18 @@ void TranslatorHLSL::translate(TIntermNode *root, int compileOptions)
sh::RewriteElseBlocks(root, getTemporaryIndex());
}
bool precisionEmulation =
getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision;
if (precisionEmulation)
{
EmulatePrecision emulatePrecision(getSymbolTable(), getShaderVersion());
root->traverse(&emulatePrecision);
emulatePrecision.updateTree();
emulatePrecision.writeEmulationHelpers(getInfoSink().obj, getShaderVersion(),
getOutputType());
}
sh::OutputHLSL outputHLSL(getShaderType(), getShaderVersion(), getExtensionBehavior(),
getSourcePath(), getOutputType(), numRenderTargets, getUniforms(), compileOptions);
......
......@@ -25,6 +25,7 @@ test("angle_unittests") {
if (angle_enable_hlsl) {
sources +=
rebase_path(unittests_gypi.angle_unittests_hlsl_sources, ".", "../..")
defines = [ "ANGLE_ENABLE_HLSL" ]
}
sources += [ "//gpu/angle_unittest_main.cc" ]
......
......@@ -136,6 +136,10 @@
['OS=="win"',
{
# TODO(cwallez): make this angle_enable_hlsl instead (requires gyp file refactoring)
'defines':
[
'ANGLE_ENABLE_HLSL',
],
'sources':
[
'<@(angle_unittests_hlsl_sources)',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment