Skip to content

Commit

Permalink
Update ANGLE translator compile options interface
Browse files Browse the repository at this point in the history
Bug: angleproject:7559
Change-Id: I76a9f77018e8ace17e2178c4fb1b27fd71a573fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3815262
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
Auto-Submit: Shahbaz Youssefi <syoussefi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1032401}
  • Loading branch information
ShabbyX authored and Chromium LUCI CQ committed Aug 8, 2022
1 parent 275e88b commit b2c8655
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 31 deletions.
37 changes: 36 additions & 1 deletion gpu/command_buffer/service/gles2_cmd_decoder.cc
Expand Up @@ -4532,7 +4532,8 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() {
resources.HashFunction = nullptr;
}

ShCompileOptions driver_bug_workarounds = 0;
ShCompileOptions driver_bug_workarounds{};
#if ANGLE_SH_VERSION < 300
if (workarounds().init_gl_position_in_vertex_shader)
driver_bug_workarounds |= SH_INIT_GL_POSITION;
if (workarounds().unfold_short_circuit_as_ternary_operation)
Expand Down Expand Up @@ -4565,6 +4566,40 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() {
// Initialize uninitialized locals by default
if (!workarounds().dont_initialize_uninitialized_locals)
driver_bug_workarounds |= SH_INITIALIZE_UNINITIALIZED_LOCALS;
#else
if (workarounds().init_gl_position_in_vertex_shader)
driver_bug_workarounds.initGLPosition = true;
if (workarounds().unfold_short_circuit_as_ternary_operation)
driver_bug_workarounds.unfoldShortCircuit = true;
if (workarounds().scalarize_vec_and_mat_constructor_args)
driver_bug_workarounds.scalarizeVecAndMatConstructorArgs = true;
if (workarounds().regenerate_struct_names)
driver_bug_workarounds.regenerateStructNames = true;
if (workarounds().emulate_abs_int_function)
driver_bug_workarounds.emulateAbsIntFunction = true;
if (workarounds().rewrite_texelfetchoffset_to_texelfetch)
driver_bug_workarounds.rewriteTexelFetchOffsetToTexelFetch = true;
if (workarounds().add_and_true_to_loop_condition)
driver_bug_workarounds.addAndTrueToLoopCondition = true;
if (workarounds().rewrite_do_while_loops)
driver_bug_workarounds.rewriteDoWhileLoops = true;
if (workarounds().emulate_isnan_on_float)
driver_bug_workarounds.emulateIsnanFloatFunction = true;
if (workarounds().use_unused_standard_shared_blocks)
driver_bug_workarounds.useUnusedStandardSharedBlocks = true;
if (workarounds().remove_invariant_and_centroid_for_essl3)
driver_bug_workarounds.removeInvariantAndCentroidForESSL3 = true;
if (workarounds().rewrite_float_unary_minus_operator)
driver_bug_workarounds.rewriteFloatUnaryMinusOperator = true;
if (workarounds().dont_use_loops_to_initialize_variables)
driver_bug_workarounds.dontUseLoopsToInitializeVariables = true;
if (workarounds().remove_dynamic_indexing_of_swizzled_vector)
driver_bug_workarounds.removeDynamicIndexingOfSwizzledVector = true;

// Initialize uninitialized locals by default
if (!workarounds().dont_initialize_uninitialized_locals)
driver_bug_workarounds.initializeUninitializedLocals = true;
#endif

ShShaderOutput shader_output_language =
ShaderTranslator::GetShaderOutputLanguageForContext(gl_version_info());
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/service/mocks.h
Expand Up @@ -98,7 +98,7 @@ class MockShaderTranslator : public ShaderTranslatorInterface {
ShShaderSpec shader_spec,
const ShBuiltInResources* resources,
ShShaderOutput shader_output_language,
ShCompileOptions driver_bug_workarounds,
const ShCompileOptions& driver_bug_workarounds,
bool gl_shader_interm_output));
MOCK_CONST_METHOD9(Translate,
bool(const std::string& shader_source,
Expand Down
47 changes: 39 additions & 8 deletions gpu/command_buffer/service/shader_translator.cc
Expand Up @@ -141,14 +141,13 @@ ShaderTranslator::DestructionObserver::DestructionObserver() = default;

ShaderTranslator::DestructionObserver::~DestructionObserver() = default;

ShaderTranslator::ShaderTranslator()
: compiler_(nullptr), compile_options_(0) {}
ShaderTranslator::ShaderTranslator() : compiler_(nullptr), compile_options_{} {}

bool ShaderTranslator::Init(GLenum shader_type,
ShShaderSpec shader_spec,
const ShBuiltInResources* resources,
ShShaderOutput shader_output_language,
ShCompileOptions driver_bug_workarounds,
const ShCompileOptions& driver_bug_workarounds,
bool gl_shader_interm_output) {
// Make sure Init is called only once.
DCHECK(compiler_ == nullptr);
Expand All @@ -166,14 +165,15 @@ bool ShaderTranslator::Init(GLenum shader_type,
shader_output_language, resources);
}

compile_options_ =
compile_options_ = driver_bug_workarounds;
#if ANGLE_SH_VERSION < 300
compile_options_ |=
SH_OBJECT_CODE | SH_VARIABLES | SH_ENFORCE_PACKING_RESTRICTIONS |
SH_LIMIT_EXPRESSION_COMPLEXITY | SH_LIMIT_CALL_STACK_DEPTH |
SH_CLAMP_INDIRECT_ARRAY_BOUNDS | SH_EMULATE_GL_DRAW_ID |
SH_EMULATE_GL_BASE_VERTEX_BASE_INSTANCE;
if (gl_shader_interm_output)
compile_options_ |= SH_INTERMEDIATE_TREE;
compile_options_ |= driver_bug_workarounds;
switch (shader_spec) {
case SH_WEBGL_SPEC:
case SH_WEBGL2_SPEC:
Expand All @@ -182,19 +182,50 @@ bool ShaderTranslator::Init(GLenum shader_type,
default:
break;
}
std::string compile_options_string =
base::NumberToString(GetCompileOptions());
#else
compile_options_.objectCode = true;
compile_options_.variables = true;
compile_options_.enforcePackingRestrictions = true;
compile_options_.limitExpressionComplexity = true;
compile_options_.limitCallStackDepth = true;
compile_options_.clampIndirectArrayBounds = true;
compile_options_.emulateGLDrawID = true;
compile_options_.emulateGLBaseVertexBaseInstance = true;

std::string compile_options_string =
"objectCode:variables:enforcePackingRestrictions:"
"limitExpressionComplexity:limitCallStackDepth:clampIndirectArrayBounds:"
"emulateGLDrawID:emulateGLBaseVertexBaseInstance";

if (gl_shader_interm_output) {
compile_options_.intermediateTree = true;
compile_options_string += ":intermediateTree";
}

switch (shader_spec) {
case SH_WEBGL_SPEC:
case SH_WEBGL2_SPEC:
compile_options_.initOutputVariables = true;
compile_options_string += ":initOutputVariables";
break;
default:
break;
}
#endif

if (compiler_) {
options_affecting_compilation_ =
base::MakeRefCounted<OptionsAffectingCompilationString>(
std::string(":CompileOptions:" +
base::NumberToString(GetCompileOptions())) +
":CompileOptions:" + compile_options_string +
sh::GetBuiltInResourcesString(compiler_));
}

return compiler_ != nullptr;
}

ShCompileOptions ShaderTranslator::GetCompileOptions() const {
const ShCompileOptions& ShaderTranslator::GetCompileOptions() const {
return compile_options_;
}

Expand Down
6 changes: 3 additions & 3 deletions gpu/command_buffer/service/shader_translator.h
Expand Up @@ -45,7 +45,7 @@ class ShaderTranslatorInterface
ShShaderSpec shader_spec,
const ShBuiltInResources* resources,
ShShaderOutput shader_output_language,
ShCompileOptions driver_bug_workarounds,
const ShCompileOptions& driver_bug_workarounds,
bool gl_shader_interm_output) = 0;

// Translates the given shader source.
Expand Down Expand Up @@ -101,7 +101,7 @@ class GPU_GLES2_EXPORT ShaderTranslator : public ShaderTranslatorInterface {
ShShaderSpec shader_spec,
const ShBuiltInResources* resources,
ShShaderOutput shader_output_language,
ShCompileOptions driver_bug_workarounds,
const ShCompileOptions& driver_bug_workarounds,
bool gl_shader_interm_output) override;

// Overridden from ShaderTranslatorInterface.
Expand All @@ -124,7 +124,7 @@ class GPU_GLES2_EXPORT ShaderTranslator : public ShaderTranslatorInterface {
private:
~ShaderTranslator() override;

ShCompileOptions GetCompileOptions() const;
const ShCompileOptions& GetCompileOptions() const;

ShHandle compiler_;
ShCompileOptions compile_options_;
Expand Down
2 changes: 1 addition & 1 deletion gpu/command_buffer/service/shader_translator_cache.cc
Expand Up @@ -32,7 +32,7 @@ scoped_refptr<ShaderTranslator> ShaderTranslatorCache::GetTranslator(
ShShaderSpec shader_spec,
const ShBuiltInResources* resources,
ShShaderOutput shader_output_language,
ShCompileOptions driver_bug_workarounds) {
const ShCompileOptions& driver_bug_workarounds) {
ShaderTranslatorInitParams params(shader_type, shader_spec, *resources,
shader_output_language,
driver_bug_workarounds);
Expand Down
4 changes: 2 additions & 2 deletions gpu/command_buffer/service/shader_translator_cache.h
Expand Up @@ -44,7 +44,7 @@ class GPU_GLES2_EXPORT ShaderTranslatorCache
ShShaderSpec shader_spec,
const ShBuiltInResources* resources,
ShShaderOutput shader_output_language,
ShCompileOptions driver_bug_workarounds);
const ShCompileOptions& driver_bug_workarounds);

private:
friend class ShaderTranslatorCacheTest_InitParamComparable_Test;
Expand All @@ -61,7 +61,7 @@ class GPU_GLES2_EXPORT ShaderTranslatorCache
ShShaderSpec shader_spec,
const ShBuiltInResources& resources,
ShShaderOutput shader_output_language,
ShCompileOptions driver_bug_workarounds) {
const ShCompileOptions& driver_bug_workarounds) {
memset(this, 0, sizeof(*this));
this->shader_type = shader_type;
this->shader_spec = shader_spec;
Expand Down
Expand Up @@ -23,7 +23,7 @@ TEST(ShaderTranslatorCacheTest, InitParamComparable) {

EXPECT_TRUE(memcmp(&a_resources, &b_resources, sizeof(a_resources)) == 0);

ShCompileOptions driver_bug_workarounds = 0;
ShCompileOptions driver_bug_workarounds{};

char a_storage[sizeof(ShaderTranslatorCache::ShaderTranslatorInitParams)];
memset(a_storage, 55, sizeof(a_storage));
Expand Down
30 changes: 16 additions & 14 deletions gpu/command_buffer/service/shader_translator_unittest.cc
Expand Up @@ -32,12 +32,10 @@ class ShaderTranslatorTest : public testing::Test {

ASSERT_TRUE(vertex_translator_->Init(GL_VERTEX_SHADER, SH_GLES2_SPEC,
&resources, shader_output_language_,
static_cast<ShCompileOptions>(0),
false));
{}, false));
ASSERT_TRUE(fragment_translator_->Init(GL_FRAGMENT_SHADER, SH_GLES2_SPEC,
&resources, shader_output_language_,
static_cast<ShCompileOptions>(0),
false));
{}, false));
}
void TearDown() override {
vertex_translator_ = nullptr;
Expand Down Expand Up @@ -71,12 +69,10 @@ class ES3ShaderTranslatorTest : public testing::Test {

ASSERT_TRUE(vertex_translator_->Init(GL_VERTEX_SHADER, SH_GLES3_SPEC,
&resources, shader_output_language_,
static_cast<ShCompileOptions>(0),
false));
{}, false));
ASSERT_TRUE(fragment_translator_->Init(GL_FRAGMENT_SHADER, SH_GLES3_SPEC,
&resources, shader_output_language_,
static_cast<ShCompileOptions>(0),
false));
{}, false));
}
void TearDown() override {
vertex_translator_ = nullptr;
Expand Down Expand Up @@ -405,18 +401,14 @@ TEST_F(ShaderTranslatorTest, OptionsString) {
sh::InitBuiltInResources(&resources);

ASSERT_TRUE(translator_1->Init(GL_VERTEX_SHADER, SH_GLES2_SPEC, &resources,
SH_GLSL_150_CORE_OUTPUT,
static_cast<ShCompileOptions>(0),
false));
SH_GLSL_150_CORE_OUTPUT, {}, false));
ASSERT_TRUE(translator_2->Init(GL_FRAGMENT_SHADER, SH_GLES2_SPEC, &resources,
SH_GLSL_150_CORE_OUTPUT,
SH_INIT_OUTPUT_VARIABLES,
false));
resources.EXT_draw_buffers = 1;
ASSERT_TRUE(translator_3->Init(GL_VERTEX_SHADER, SH_GLES2_SPEC, &resources,
SH_GLSL_150_CORE_OUTPUT,
static_cast<ShCompileOptions>(0),
false));
SH_GLSL_150_CORE_OUTPUT, {}, false));

std::string options_1(
translator_1->GetStringForOptionsThatWouldAffectCompilation()->data);
Expand All @@ -443,7 +435,12 @@ class ShaderTranslatorOutputVersionTest
TEST_F(ShaderTranslatorOutputVersionTest, DISABLED_CompatibilityOutput) {
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
#if ANGLE_SH_VERSION < 300
ShCompileOptions compile_options = SH_OBJECT_CODE;
#else
ShCompileOptions compile_options{};
compile_options.objectCode = true;
#endif
ShShaderOutput shader_output_language = SH_GLSL_COMPATIBILITY_OUTPUT;
scoped_refptr<ShaderTranslator> vertex_translator = new ShaderTranslator();
ASSERT_TRUE(vertex_translator->Init(GL_VERTEX_SHADER, SH_GLES2_SPEC,
Expand Down Expand Up @@ -512,7 +509,12 @@ TEST_P(ShaderTranslatorOutputVersionTest, HasCorrectOutputGLSLVersion) {
scoped_refptr<ShaderTranslator> translator = new ShaderTranslator();
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
#if ANGLE_SH_VERSION < 300
ShCompileOptions compile_options = SH_OBJECT_CODE;
#else
ShCompileOptions compile_options{};
compile_options.objectCode = true;
#endif
ShShaderOutput shader_output_language =
ShaderTranslator::GetShaderOutputLanguageForContext(
output_context_version);
Expand Down

0 comments on commit b2c8655

Please sign in to comment.