Skip to content

Commit

Permalink
Revert "Remove five gpu workarounds."
Browse files Browse the repository at this point in the history
This reverts commit e2c2849.
  • Loading branch information
blueboxd committed Feb 3, 2024
1 parent 7a9694a commit c083a11
Show file tree
Hide file tree
Showing 17 changed files with 478 additions and 10 deletions.
1 change: 1 addition & 0 deletions content/test/gpu/gpu_tests/fake_win_amd_gpu_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
],
'driver_bug_workarounds':
[
'clear_uniforms_before_first_program_use',
'exit_on_context_lost',
'force_cube_complete',
'scalarize_vec_and_mat_constructor_args',
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/service/feature_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,7 @@ void FeatureInfo::InitializeFeatures() {
bool is_webgl_compatibility_context =
gfx::HasExtension(extensions, "GL_ANGLE_webgl_compatibility");
bool have_es2_draw_buffers =
!workarounds_.disable_ext_draw_buffers &&
(have_es2_draw_buffers_vendor_agnostic ||
can_emulate_es2_draw_buffers_on_es3_nv) &&
(context_type_ == CONTEXT_TYPE_OPENGLES2 ||
Expand Down
6 changes: 6 additions & 0 deletions gpu/command_buffer/service/gles2_cmd_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8842,6 +8842,10 @@ void GLES2DecoderImpl::DoLinkProgram(GLuint program_id) {
LogClientServiceForInfo(program, program_id, "glLinkProgram");
if (program->Link(shader_manager(),
client())) {
if (program == state_.current_program.get()) {
if (workarounds().clear_uniforms_before_first_program_use)
program_manager()->ClearUniforms(program);
}
if (features().webgl_multi_draw)
program_manager()->UpdateDrawIDUniformLocation(program);
if (features().webgl_draw_instanced_base_vertex_base_instance ||
Expand Down Expand Up @@ -9555,6 +9559,8 @@ void GLES2DecoderImpl::DoUseProgram(GLuint program_id) {
api()->glUseProgramFn(service_id);
if (state_.current_program.get()) {
program_manager()->UseProgram(state_.current_program.get());
if (workarounds().clear_uniforms_before_first_program_use)
program_manager()->ClearUniforms(program);
}
}

Expand Down
46 changes: 46 additions & 0 deletions gpu/command_buffer/service/gles2_cmd_decoder_unittest_programs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,52 @@ TEST_P(GLES2DecoderWithShaderTest, BindUniformLocationCHROMIUMBucket) {
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}

TEST_P(GLES2DecoderManualInitTest, ClearUniformsBeforeFirstProgramUse) {
gpu::GpuDriverBugWorkarounds workarounds;
workarounds.clear_uniforms_before_first_program_use = true;
InitState init;
init.has_alpha = true;
init.request_alpha = true;
init.bind_generates_resource = true;
InitDecoderWithWorkarounds(init, workarounds);
{
static AttribInfo attribs[] = {
{
kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location,
},
{
kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location,
},
{
kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location,
},
};
static UniformInfo uniforms[] = {
{kUniform1Name, kUniform1Size, kUniform1Type, kUniform1FakeLocation,
kUniform1RealLocation, kUniform1DesiredLocation},
{kUniform2Name, kUniform2Size, kUniform2Type, kUniform2FakeLocation,
kUniform2RealLocation, kUniform2DesiredLocation},
{kUniform3Name, kUniform3Size, kUniform3Type, kUniform3FakeLocation,
kUniform3RealLocation, kUniform3DesiredLocation},
};
SetupShader(attribs, std::size(attribs), uniforms, std::size(uniforms),
client_program_id_, kServiceProgramId, client_vertex_shader_id_,
kServiceVertexShaderId, client_fragment_shader_id_,
kServiceFragmentShaderId);
TestHelper::SetupExpectationsForClearingUniforms(gl_.get(), uniforms,
std::size(uniforms));
}

{
EXPECT_CALL(*gl_, UseProgram(kServiceProgramId))
.Times(1)
.RetiresOnSaturation();
cmds::UseProgram cmd;
cmd.Init(client_program_id_);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
}
}

TEST_P(GLES2DecoderWithShaderTest, UseDeletedProgram) {
DoDeleteProgram(client_program_id_, kServiceProgramId);
{
Expand Down
129 changes: 129 additions & 0 deletions gpu/command_buffer/service/program_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,130 @@ void Program::UpdateLogInfo() {
set_log_info(log.empty() ? nullptr : log.c_str());
}

void Program::ClearUniforms(std::vector<uint8_t>* zero_buffer) {
DCHECK(zero_buffer);
if (uniforms_cleared_) {
return;
}
uniforms_cleared_ = true;
for (const UniformInfo& uniform_info : uniform_infos_) {
GLint location = uniform_info.element_locations[0];
GLsizei size = uniform_info.size;
uint32_t unit_size =
GLES2Util::GetElementCountForUniformType(uniform_info.type) *
GLES2Util::GetElementSizeForUniformType(uniform_info.type);
DCHECK_LT(0u, unit_size);
uint32_t size_needed = size * unit_size;
if (size_needed > zero_buffer->size()) {
zero_buffer->resize(size_needed, 0u);
}
const void* zero = &(*zero_buffer)[0];
switch (uniform_info.type) {
case GL_FLOAT:
glUniform1fv(location, size, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_VEC2:
glUniform2fv(location, size, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_VEC3:
glUniform3fv(location, size, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_VEC4:
glUniform4fv(location, size, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_INT:
case GL_BOOL:
case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES: // extension.
case GL_SAMPLER_2D_RECT_ARB: // extension.
glUniform1iv(location, size, reinterpret_cast<const GLint*>(zero));
break;
case GL_INT_VEC2:
case GL_BOOL_VEC2:
glUniform2iv(location, size, reinterpret_cast<const GLint*>(zero));
break;
case GL_INT_VEC3:
case GL_BOOL_VEC3:
glUniform3iv(location, size, reinterpret_cast<const GLint*>(zero));
break;
case GL_INT_VEC4:
case GL_BOOL_VEC4:
glUniform4iv(location, size, reinterpret_cast<const GLint*>(zero));
break;
case GL_FLOAT_MAT2:
glUniformMatrix2fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_MAT3:
glUniformMatrix3fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_MAT4:
glUniformMatrix4fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;

// ES3 types.
case GL_UNSIGNED_INT:
glUniform1uiv(location, size, reinterpret_cast<const GLuint*>(zero));
break;
case GL_SAMPLER_3D:
case GL_SAMPLER_2D_SHADOW:
case GL_SAMPLER_2D_ARRAY:
case GL_SAMPLER_2D_ARRAY_SHADOW:
case GL_SAMPLER_CUBE_SHADOW:
case GL_INT_SAMPLER_2D:
case GL_INT_SAMPLER_3D:
case GL_INT_SAMPLER_CUBE:
case GL_INT_SAMPLER_2D_ARRAY:
case GL_UNSIGNED_INT_SAMPLER_2D:
case GL_UNSIGNED_INT_SAMPLER_3D:
case GL_UNSIGNED_INT_SAMPLER_CUBE:
case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY:
glUniform1iv(location, size, reinterpret_cast<const GLint*>(zero));
break;
case GL_UNSIGNED_INT_VEC2:
glUniform2uiv(location, size, reinterpret_cast<const GLuint*>(zero));
break;
case GL_UNSIGNED_INT_VEC3:
glUniform3uiv(location, size, reinterpret_cast<const GLuint*>(zero));
break;
case GL_UNSIGNED_INT_VEC4:
glUniform4uiv(location, size, reinterpret_cast<const GLuint*>(zero));
break;
case GL_FLOAT_MAT2x3:
glUniformMatrix2x3fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_MAT3x2:
glUniformMatrix3x2fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_MAT2x4:
glUniformMatrix2x4fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_MAT4x2:
glUniformMatrix4x2fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_MAT3x4:
glUniformMatrix3x4fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;
case GL_FLOAT_MAT4x3:
glUniformMatrix4x3fv(
location, size, false, reinterpret_cast<const GLfloat*>(zero));
break;

default:
NOTREACHED();
break;
}
}
}

void Program::Update() {
Reset();
UpdateLogInfo();
Expand Down Expand Up @@ -2429,6 +2553,11 @@ void ProgramManager::UnuseProgram(
RemoveProgramInfoIfUnused(shader_manager, program);
}

void ProgramManager::ClearUniforms(Program* program) {
DCHECK(program);
program->ClearUniforms(&zero_);
}

void ProgramManager::UpdateDrawIDUniformLocation(Program* program) {
DCHECK(program);
program->UpdateDrawIDUniformLocation();
Expand Down
6 changes: 6 additions & 0 deletions gpu/command_buffer/service/program_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ class GPU_GLES2_EXPORT Program : public base::RefCounted<Program> {
// Updates the program log info from GL
void UpdateLogInfo();

// Clears all the uniforms.
void ClearUniforms(std::vector<uint8_t>* zero_buffer);

// Updates the draw id uniform location used by ANGLE_multi_draw
void UpdateDrawIDUniformLocation();

Expand Down Expand Up @@ -678,6 +681,9 @@ class GPU_GLES2_EXPORT ProgramManager {
// Makes a program as unused. If deleted the program will be removed.
void UnuseProgram(ShaderManager* shader_manager, Program* program);

// Clears the uniforms for this program.
void ClearUniforms(Program* program);

// Updates the draw id location for this program for ANGLE_multi_draw
void UpdateDrawIDUniformLocation(Program* program);

Expand Down
6 changes: 6 additions & 0 deletions gpu/command_buffer/service/program_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ class ProgramManagerWithShaderTest : public ProgramManagerTestBase {
service_id);
}

void SetupExpectationsForClearingUniforms(
UniformInfo* uniforms, size_t num_uniforms) {
TestHelper::SetupExpectationsForClearingUniforms(
gl_.get(), uniforms, num_uniforms);
}

// Return true if link status matches expected_link_status
bool LinkAsExpected(Program* program,
bool expected_link_status) {
Expand Down
13 changes: 11 additions & 2 deletions gpu/command_buffer/service/renderbuffer_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,26 @@ Renderbuffer::Renderbuffer(RenderbufferManager* manager,

bool Renderbuffer::RegenerateAndBindBackingObjectIfNeeded(
const GpuDriverBugWorkarounds& workarounds) {
// There are two workarounds which need this code path:
// depth_stencil_renderbuffer_resize_emulation
// multisample_renderbuffer_resize_emulation
bool multisample_workaround =
workarounds.multisample_renderbuffer_resize_emulation;
if (!multisample_workaround) {
bool depth_stencil_workaround =
workarounds.depth_stencil_renderbuffer_resize_emulation;
if (!multisample_workaround && !depth_stencil_workaround) {
return false;
}

if (!allocated_ || !has_been_bound_) {
return false;
}

bool workaround_needed = (multisample_workaround && samples_ > 0);
bool workaround_needed = (multisample_workaround && samples_ > 0) ||
(depth_stencil_workaround &&
TextureManager::ExtractFormatFromStorageFormat(
internal_format_) == GL_DEPTH_STENCIL);

if (!workaround_needed) {
return false;
}
Expand Down
Loading

0 comments on commit c083a11

Please sign in to comment.