Commit 2eb85a5b by Charlie Lao Committed by Commit Bot

Vulkan: Experimental: forcing highp to mediump in fragment shader.

Handy code for debug/experiment that forces highp in fragment shader to mediump. Bug: b/173140243 Change-Id: I1841b67862343df8a12bf302066d7eefd7709604 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2537072 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 7c66cdf8
......@@ -26,7 +26,7 @@
// Version number for shader translation API.
// It is incremented every time the API changes.
#define ANGLE_SH_VERSION 240
#define ANGLE_SH_VERSION 241
enum ShShaderSpec
{
......@@ -341,6 +341,8 @@ const ShCompileOptions SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION = UINT64_C(1) << 55;
// Allow compiler to insert Android pre-rotation code.
const ShCompileOptions SH_ADD_PRE_ROTATION = UINT64_C(1) << 56;
const ShCompileOptions SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP = UINT64_C(1) << 57;
// Defines alternate strategies for implementing array index clamping.
enum ShArrayIndexClampingStrategy
{
......
......@@ -138,6 +138,8 @@ angle_translator_sources = [
"src/compiler/translator/tree_ops/FlagSamplersWithTexelFetch.h",
"src/compiler/translator/tree_ops/FoldExpressions.cpp",
"src/compiler/translator/tree_ops/FoldExpressions.h",
"src/compiler/translator/tree_ops/ForcePrecisionQualifier.cpp",
"src/compiler/translator/tree_ops/ForcePrecisionQualifier.h",
"src/compiler/translator/tree_ops/InitializeVariables.cpp",
"src/compiler/translator/tree_ops/InitializeVariables.h",
"src/compiler/translator/tree_ops/NameEmbeddedUniformStructs.cpp",
......
......@@ -31,6 +31,7 @@
#include "compiler/translator/tree_ops/EmulateMultiDrawShaderBuiltins.h"
#include "compiler/translator/tree_ops/EmulatePrecision.h"
#include "compiler/translator/tree_ops/FoldExpressions.h"
#include "compiler/translator/tree_ops/ForcePrecisionQualifier.h"
#include "compiler/translator/tree_ops/InitializeVariables.h"
#include "compiler/translator/tree_ops/PruneEmptyCases.h"
#include "compiler/translator/tree_ops/PruneNoOps.h"
......@@ -790,6 +791,14 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
}
}
if (compileOptions & SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP)
{
if (!ForceShaderPrecisionToMediump(root, &mSymbolTable, mShaderType))
{
return false;
}
}
if (shouldCollectVariables(compileOptions))
{
ASSERT(!mVariablesCollected);
......
//
// Copyright 2020 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.
//
#include "compiler/translator/tree_ops/ForcePrecisionQualifier.h"
#include "angle_gl.h"
#include "common/debug.h"
#include "compiler/translator/Compiler.h"
#include "compiler/translator/tree_util/IntermTraverse.h"
#include "compiler/translator/util.h"
namespace sh
{
namespace
{
class TPrecisionTraverser : public TIntermTraverser
{
public:
TPrecisionTraverser(TSymbolTable *symbolTable);
protected:
bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;
bool structDeclared(const TStructure *structure) const;
void overwriteVariablePrecision(TType *type) const;
private:
// This set contains all the ids of the structs from every scope.
std::set<int> mDeclaredStructs;
};
TPrecisionTraverser::TPrecisionTraverser(TSymbolTable *symbolTable)
: TIntermTraverser(true, true, true, symbolTable)
{}
bool TPrecisionTraverser::structDeclared(const TStructure *structure) const
{
ASSERT(structure);
if (structure->symbolType() == SymbolType::Empty)
{
return false;
}
return (mDeclaredStructs.count(structure->uniqueId().get()) > 0);
}
void TPrecisionTraverser::overwriteVariablePrecision(TType *type) const
{
if (type->getPrecision() == EbpHigh)
{
type->setPrecision(EbpMedium);
}
}
bool TPrecisionTraverser::visitDeclaration(Visit visit, TIntermDeclaration *node)
{
// Variable declaration.
if (visit == PreVisit)
{
const TIntermSequence &sequence = *(node->getSequence());
TIntermTyped *variable = sequence.front()->getAsTyped();
const TType &type = variable->getType();
TQualifier qualifier = variable->getQualifier();
// Don't modify uniform since it might be shared between vertex and fragment shader
if (qualifier == EvqUniform)
{
return true;
}
// Visit the struct if we have not done so already.
if (type.getBasicType() == EbtStruct && !structDeclared(type.getStruct()))
{
const TStructure *structure = type.getStruct();
const TFieldList &fields = structure->fields();
for (size_t i = 0; i < fields.size(); ++i)
{
const TField *field = fields[i];
const TType *fieldType = field->type();
overwriteVariablePrecision((TType *)fieldType);
}
mDeclaredStructs.insert(structure->uniqueId().get());
}
else if (type.getBasicType() == EbtInterfaceBlock)
{
const TInterfaceBlock *interfaceBlock = type.getInterfaceBlock();
const TFieldList &fields = interfaceBlock->fields();
for (const TField *field : fields)
{
const TType *fieldType = field->type();
overwriteVariablePrecision((TType *)fieldType);
}
}
else
{
overwriteVariablePrecision((TType *)&type);
}
}
return true;
}
} // namespace
bool ForceShaderPrecisionToMediump(TIntermNode *root, TSymbolTable *symbolTable, GLenum shaderType)
{
if (shaderType != GL_FRAGMENT_SHADER)
{
return true;
}
TPrecisionTraverser traverser(symbolTable);
root->traverse(&traverser);
return true;
}
} // namespace sh
//
// Copyright 2020 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.
//
#ifndef COMPILER_TRANSLATOR_TREEOPS_FORCEPRECISIONQUALIFIER_H_
#define COMPILER_TRANSLATOR_TREEOPS_FORCEPRECISIONQUALIFIER_H_
#include "compiler/translator/tree_util/IntermTraverse.h"
namespace sh
{
bool ForceShaderPrecisionToMediump(TIntermNode *root, TSymbolTable *symbolTable, GLenum shaderType);
} // namespace sh
#endif // COMPILER_TRANSLATOR_TREEOPS_FORCEPRECISIONQUALIFIER_H_
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