Hash :
6f80f0f0
Author :
Date :
2022-08-06T02:29:19
Translator: Clean up the compile flag passing interface Historically, compile flags were sent to the translator as a bitmask. Recently, we were getting close to running out of bits. Additionally, direct-to-metal work had started to introduce constants to be passed to the translator, which were misplaced in ShBuiltInResources and Caps. Recent work on Pixel Local Storage adds even more constants, aggravating the situation. In this change, the interface to passing compile flags is reworked. A struct is passed (instead of a bitmask) that has one bit for each flag. This can be indefinitely extended. Additionally, the constants needed by metal and PLS are also placed in this struct. In turn, the backends can set these options directly, and don't have to hack them into Caps to further get hacked into ShBuiltInResources. Bug: angleproject:7559 Change-Id: If93f1e1b8818ad3a0ac708ab04ab93b4b397d114 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3812562 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Amirali Abdolrashidi <abdolrashidi@google.com> Commit-Queue: Amirali Abdolrashidi <abdolrashidi@google.com> Auto-Submit: 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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
//
// 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.
//
// APPLE_clip_distance_test.cpp:
// Test for APPLE_clip_distance
//
#include "tests/test_utils/ShaderExtensionTest.h"
namespace
{
const char EXTPragma[] = "#extension GL_APPLE_clip_distance : require\n";
// Shader using gl_ClipDistance
const char ESSL100_APPLEClipDistanceShader1[] =
R"(
uniform vec4 uPlane;
attribute vec4 aPosition;
void main()
{
gl_Position = aPosition;
gl_ClipDistance[1] = dot(aPosition, uPlane);
})";
// Shader redeclares gl_ClipDistance
const char ESSL100_APPLEClipDistanceShader2[] =
R"(
uniform vec4 uPlane;
attribute vec4 aPosition;
varying highp float gl_ClipDistance[4];
void main()
{
gl_Position = aPosition;
gl_ClipDistance[gl_MaxClipDistances - 6 + 1] = dot(aPosition, uPlane);
gl_ClipDistance[gl_MaxClipDistances - int(aPosition.x)] = dot(aPosition, uPlane);
})";
class APPLEClipDistanceTest : public sh::ShaderExtensionTest
{
public:
void InitializeCompiler() { InitializeCompiler(SH_GLSL_130_OUTPUT); }
void InitializeCompiler(ShShaderOutput shaderOutputType)
{
DestroyCompiler();
mCompiler = sh::ConstructCompiler(GL_VERTEX_SHADER, testing::get<0>(GetParam()),
shaderOutputType, &mResources);
ASSERT_TRUE(mCompiler != nullptr) << "Compiler could not be constructed.";
}
testing::AssertionResult TestShaderCompile(const char *pragma)
{
const char *shaderStrings[] = {testing::get<1>(GetParam()), pragma,
testing::get<2>(GetParam())};
ShCompileOptions compileOptions = {};
compileOptions.objectCode = true;
compileOptions.variables = true;
bool success = sh::Compile(mCompiler, shaderStrings, 3, compileOptions);
if (success)
{
return ::testing::AssertionSuccess() << "Compilation success";
}
return ::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);
}
};
// Extension flag is required to compile properly. Expect failure when it is
// not present.
TEST_P(APPLEClipDistanceTest, CompileFailsWithoutExtension)
{
mResources.APPLE_clip_distance = 0;
InitializeCompiler();
EXPECT_FALSE(TestShaderCompile(EXTPragma));
}
// Extension directive is required to compile properly. Expect failure when
// it is not present.
TEST_P(APPLEClipDistanceTest, CompileFailsWithExtensionWithoutPragma)
{
mResources.APPLE_clip_distance = 1;
InitializeCompiler();
EXPECT_FALSE(TestShaderCompile(""));
}
// With extension flag and extension directive, compiling succeeds.
// Also test that the extension directive state is reset correctly.
TEST_P(APPLEClipDistanceTest, CompileSucceedsWithExtensionAndPragma)
{
mResources.APPLE_clip_distance = 1;
mResources.MaxClipDistances = 8;
InitializeCompiler();
EXPECT_TRUE(TestShaderCompile(EXTPragma));
// Test reset functionality.
EXPECT_FALSE(TestShaderCompile(""));
EXPECT_TRUE(TestShaderCompile(EXTPragma));
}
#if defined(ANGLE_ENABLE_VULKAN)
// With extension flag and extension directive, compiling using TranslatorVulkan succeeds.
TEST_P(APPLEClipDistanceTest, CompileSucceedsVulkan)
{
mResources.APPLE_clip_distance = 1;
mResources.MaxClipDistances = 8;
InitializeCompiler(SH_SPIRV_VULKAN_OUTPUT);
EXPECT_TRUE(TestShaderCompile(EXTPragma));
}
// Test that the SPIR-V gen path can compile a shader when this extension is not supported.
TEST_P(APPLEClipDistanceTest, CompileSucceedsWithoutExtSupportVulkan)
{
mResources.APPLE_clip_distance = 0;
mResources.MaxClipDistances = 0;
mResources.MaxCullDistances = 0;
InitializeCompiler(SH_SPIRV_VULKAN_OUTPUT);
constexpr char kNoClipCull[] = R"(
void main()
{
gl_Position = vec4(0);
})";
const char *shaderStrings[] = {kNoClipCull};
ShCompileOptions compileOptions = {};
compileOptions.objectCode = true;
bool success = sh::Compile(mCompiler, shaderStrings, 1, compileOptions);
if (success)
{
::testing::AssertionSuccess() << "Compilation success";
}
else
{
::testing::AssertionFailure() << sh::GetInfoLog(mCompiler);
}
EXPECT_TRUE(success);
}
#endif
#if defined(ANGLE_ENABLE_METAL)
// With extension flag and extension directive, compiling using TranslatorMetalDirect succeeds.
TEST_P(APPLEClipDistanceTest, CompileSucceedsMetal)
{
mResources.APPLE_clip_distance = 1;
mResources.MaxClipDistances = 8;
InitializeCompiler(SH_MSL_METAL_OUTPUT);
EXPECT_TRUE(TestShaderCompile(EXTPragma));
}
#endif
#if defined(ANGLE_ENABLE_METAL_SPIRV)
// With extension flag and extension directive, compiling using TranslatorMetal succeeds.
TEST_P(APPLEClipDistanceTest, CompileSucceedsMetalSPIRV)
{
mResources.APPLE_clip_distance = 1;
mResources.MaxClipDistances = 8;
InitializeCompiler(SH_SPIRV_METAL_OUTPUT);
EXPECT_TRUE(TestShaderCompile(EXTPragma));
}
#endif
// The SL #version 100 shaders that are correct work similarly
// in both GL2 and GL3, with and without the version string.
INSTANTIATE_TEST_SUITE_P(CorrectESSL100Shaders,
APPLEClipDistanceTest,
Combine(Values(SH_GLES2_SPEC),
Values(sh::ESSLVersion100),
Values(ESSL100_APPLEClipDistanceShader1,
ESSL100_APPLEClipDistanceShader2)));
} // anonymous namespace