Commit e469de8a by Martin Radev Committed by Commit Bot

Refactor translator construction

The patch adds functionality to determine whether compiler output belongs to the ESSL, GLSL, HLSL or Vulkan output family. The new functions can be now used in other parts of the compiler in which code paths are selected based on the compiler output. BUG=angleproject:2062 TEST=angle_unittests Change-Id: I45ccf63f0a756c60df47a679c2da9f60856d5918 Reviewed-on: https://chromium-review.googlesource.com/558990Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent cccf2b00
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "compiler/translator/TranslatorVulkan.h" #include "compiler/translator/TranslatorVulkan.h"
#endif // ANGLE_ENABLE_VULKAN #endif // ANGLE_ENABLE_VULKAN
#include "compiler/translator/util.h"
namespace sh namespace sh
{ {
...@@ -30,60 +32,36 @@ namespace sh ...@@ -30,60 +32,36 @@ namespace sh
// //
TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output) TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
{ {
switch (output)
{
case SH_ESSL_OUTPUT:
#ifdef ANGLE_ENABLE_ESSL #ifdef ANGLE_ENABLE_ESSL
return new TranslatorESSL(type, spec); if (IsOutputESSL(output))
#else {
// This compiler is not supported in this configuration. Return NULL per the return new TranslatorESSL(type, spec);
// sh::ConstructCompiler API. }
return nullptr;
#endif // ANGLE_ENABLE_ESSL #endif // ANGLE_ENABLE_ESSL
case SH_GLSL_130_OUTPUT:
case SH_GLSL_140_OUTPUT:
case SH_GLSL_150_CORE_OUTPUT:
case SH_GLSL_330_CORE_OUTPUT:
case SH_GLSL_400_CORE_OUTPUT:
case SH_GLSL_410_CORE_OUTPUT:
case SH_GLSL_420_CORE_OUTPUT:
case SH_GLSL_430_CORE_OUTPUT:
case SH_GLSL_440_CORE_OUTPUT:
case SH_GLSL_450_CORE_OUTPUT:
case SH_GLSL_COMPATIBILITY_OUTPUT:
#ifdef ANGLE_ENABLE_GLSL #ifdef ANGLE_ENABLE_GLSL
return new TranslatorGLSL(type, spec, output); if (IsOutputGLSL(output))
#else {
// This compiler is not supported in this configuration. Return NULL per the return new TranslatorGLSL(type, spec, output);
// sh::ConstructCompiler API. }
return nullptr;
#endif // ANGLE_ENABLE_GLSL #endif // ANGLE_ENABLE_GLSL
case SH_HLSL_3_0_OUTPUT:
case SH_HLSL_4_1_OUTPUT:
case SH_HLSL_4_0_FL9_3_OUTPUT:
#ifdef ANGLE_ENABLE_HLSL #ifdef ANGLE_ENABLE_HLSL
return new TranslatorHLSL(type, spec, output); if (IsOutputHLSL(output))
#else {
// This compiler is not supported in this configuration. Return NULL per the return new TranslatorHLSL(type, spec, output);
// sh::ConstructCompiler API. }
return nullptr;
#endif // ANGLE_ENABLE_HLSL #endif // ANGLE_ENABLE_HLSL
case SH_GLSL_VULKAN_OUTPUT:
#ifdef ANGLE_ENABLE_VULKAN #ifdef ANGLE_ENABLE_VULKAN
return new TranslatorVulkan(type, spec); if (IsOutputVulkan(output))
#else {
// This compiler is not supported in this configuration. Return NULL per the return new TranslatorVulkan(type, spec);
// ShConstructCompiler API. }
return nullptr;
#endif // ANGLE_ENABLE_VULKAN #endif // ANGLE_ENABLE_VULKAN
default: // Unsupported compiler or unknown format. Return nullptr per the sh::ConstructCompiler API.
// Unknown format. Return NULL per the sh::ConstructCompiler API. return nullptr;
return nullptr;
}
} }
// //
......
...@@ -625,4 +625,49 @@ bool IsBuiltinFragmentInputVariable(TQualifier qualifier) ...@@ -625,4 +625,49 @@ bool IsBuiltinFragmentInputVariable(TQualifier qualifier)
} }
return false; return false;
} }
bool IsOutputESSL(ShShaderOutput output)
{
return output == SH_ESSL_OUTPUT;
}
bool IsOutputGLSL(ShShaderOutput output)
{
switch (output)
{
case SH_GLSL_130_OUTPUT:
case SH_GLSL_140_OUTPUT:
case SH_GLSL_150_CORE_OUTPUT:
case SH_GLSL_330_CORE_OUTPUT:
case SH_GLSL_400_CORE_OUTPUT:
case SH_GLSL_410_CORE_OUTPUT:
case SH_GLSL_420_CORE_OUTPUT:
case SH_GLSL_430_CORE_OUTPUT:
case SH_GLSL_440_CORE_OUTPUT:
case SH_GLSL_450_CORE_OUTPUT:
case SH_GLSL_COMPATIBILITY_OUTPUT:
return true;
default:
break;
}
return false;
}
bool IsOutputHLSL(ShShaderOutput output)
{
switch (output)
{
case SH_HLSL_3_0_OUTPUT:
case SH_HLSL_4_1_OUTPUT:
case SH_HLSL_4_0_FL9_3_OUTPUT:
return true;
default:
break;
}
return false;
}
bool IsOutputVulkan(ShShaderOutput output)
{
return output == SH_GLSL_VULKAN_OUTPUT;
}
} // namespace sh } // namespace sh
...@@ -47,6 +47,10 @@ bool IsBuiltinOutputVariable(TQualifier qualifier); ...@@ -47,6 +47,10 @@ bool IsBuiltinOutputVariable(TQualifier qualifier);
bool IsBuiltinFragmentInputVariable(TQualifier qualifier); bool IsBuiltinFragmentInputVariable(TQualifier qualifier);
bool CanBeInvariantESSL1(TQualifier qualifier); bool CanBeInvariantESSL1(TQualifier qualifier);
bool CanBeInvariantESSL3OrGreater(TQualifier qualifier); bool CanBeInvariantESSL3OrGreater(TQualifier qualifier);
bool IsOutputESSL(ShShaderOutput output);
bool IsOutputGLSL(ShShaderOutput output);
bool IsOutputHLSL(ShShaderOutput output);
bool IsOutputVulkan(ShShaderOutput output);
} // namespace sh } // namespace sh
#endif // COMPILER_TRANSLATOR_UTIL_H_ #endif // COMPILER_TRANSLATOR_UTIL_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