Since some ASTs are now disabled on certain conditions, this change lets
the fuzzer know when it has generated invalid translator options.

Bug: chromium:1164448
Change-Id: I1f1b120c33fb70f9776df858db033ec914d7ad89
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2618203
Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Shahbaz Youssefi 2021-01-08 16:35:29 -05:00 коммит произвёл Commit Bot
Родитель 767af74ec9
Коммит 2aa4f7e521
1 изменённых файлов: 69 добавлений и 3 удалений

Просмотреть файл

@ -19,6 +19,53 @@
using namespace sh;
namespace
{
// Options supported by any output
constexpr ShCompileOptions kCommonOptions =
SH_VALIDATE | SH_VALIDATE_LOOP_INDEXING | SH_INTERMEDIATE_TREE | SH_OBJECT_CODE | SH_VARIABLES |
SH_LINE_DIRECTIVES | SH_SOURCE_PATH | SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT |
SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3 | SH_EMULATE_ABS_INT_FUNCTION |
SH_ENFORCE_PACKING_RESTRICTIONS | SH_CLAMP_INDIRECT_ARRAY_BOUNDS |
SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH | SH_INIT_GL_POSITION |
SH_INIT_OUTPUT_VARIABLES | SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS |
SH_DONT_PRUNE_UNUSED_FUNCTIONS | SH_REMOVE_POW_WITH_CONSTANT_EXPONENT |
SH_FLATTEN_PRAGMA_STDGL_INVARIANT_ALL | SH_HLSL_GET_DIMENSIONS_IGNORES_BASE_LEVEL |
SH_REWRITE_TEXELFETCHOFFSET_TO_TEXELFETCH | SH_EMULATE_ISNAN_FLOAT_FUNCTION |
SH_INITIALIZE_UNINITIALIZED_LOCALS | SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW |
SH_CLAMP_POINT_SIZE | SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES |
SH_SKIP_D3D_CONSTANT_REGISTER_ZERO | SH_EMULATE_GL_DRAW_ID | SH_INIT_SHARED_VARIABLES |
SH_FORCE_ATOMIC_VALUE_RESOLUTION | SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE |
SH_TAKE_VIDEO_TEXTURE_AS_EXTERNAL_OES | SH_VALIDATE_AST | SH_ADD_BASE_VERTEX_TO_VERTEX_ID |
SH_REMOVE_DYNAMIC_INDEXING_OF_SWIZZLED_VECTOR | SH_DISABLE_ARB_TEXTURE_RECTANGLE |
SH_IGNORE_PRECISION_QUALIFIERS | SH_FORCE_SHADER_PRECISION_HIGHP_TO_MEDIUMP;
// Options supported by GLSL or ESSL only
constexpr ShCompileOptions kGLSLOrESSLOnlyOptions =
SH_EMULATE_ATAN2_FLOAT_FUNCTION | SH_CLAMP_FRAG_DEPTH | SH_REGENERATE_STRUCT_NAMES |
SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED | SH_USE_UNUSED_STANDARD_SHARED_BLOCKS |
SH_REWRITE_VECTOR_SCALAR_ARITHMETIC | SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER;
#if defined(ANGLE_PLATFORM_APPLE)
// Options supported by GLSL only on mac
constexpr ShCompileOptions kGLSLMacOnlyOptions =
SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR | SH_ADD_AND_TRUE_TO_LOOP_CONDITION |
SH_REWRITE_DO_WHILE_LOOPS | SH_UNFOLD_SHORT_CIRCUIT | SH_REWRITE_ROW_MAJOR_MATRICES;
#endif
// Options supported by Vulkan GLSL only
constexpr ShCompileOptions kVulkanGLSLOnlyOptions =
SH_ADD_PRE_ROTATION | SH_USE_OLD_REWRITE_STRUCT_SAMPLERS |
SH_EMULATE_SEAMFUL_CUBE_MAP_SAMPLING | SH_ADD_BRESENHAM_LINE_RASTER_EMULATION |
SH_EARLY_FRAGMENT_TESTS_OPTIMIZATION | SH_USE_SPECIALIZATION_CONSTANT |
SH_ADD_VULKAN_XFB_EMULATION_SUPPORT_CODE;
// Options supported by HLSL output only
constexpr ShCompileOptions kHLSLOnlyOptions = SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS |
SH_ALLOW_TRANSLATE_UNIFORM_BLOCK_TO_STRUCTUREDBUFFER |
SH_REWRITE_INTEGER_UNARY_MINUS_OPERATOR;
struct TranslatorCacheKey
{
bool operator==(const TranslatorCacheKey &other) const
@ -30,6 +77,7 @@ struct TranslatorCacheKey
uint32_t spec = 0;
uint32_t output = 0;
};
} // anonymous namespace
namespace std
{
@ -83,10 +131,28 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
}
ShShaderOutput shaderOutput = static_cast<ShShaderOutput>(output);
if (!(IsOutputGLSL(shaderOutput) || IsOutputESSL(shaderOutput)) &&
(options & SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER) != 0u)
ShCompileOptions supportedOptions = kCommonOptions;
if (IsOutputGLSL(shaderOutput) || IsOutputESSL(shaderOutput))
{
supportedOptions |= kGLSLOrESSLOnlyOptions;
#if defined(ANGLE_PLATFORM_APPLE)
supportedOptions |= kGLSLMacOnlyOptions;
#endif
}
else if (IsOutputVulkan(shaderOutput))
{
supportedOptions |= kVulkanGLSLOnlyOptions;
}
else if (IsOutputHLSL(shaderOutput))
{
supportedOptions |= kHLSLOnlyOptions;
}
// If there are any options not supported with this output, don't attempt to run the translator.
if ((options & ~supportedOptions) != 0)
{
// This compiler option is only available in ESSL and GLSL.
return 0;
}