Commit b03e05c1 authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

Reset all sampler units to ground state for GrContext

Skia uses multiple texture units, so we need to reset all
sampler units. This is a temporary workaround. We will create
GrContext for ES 3.0 soon, after SkiaRenderer + GL is shipped.

Bug: 1057271
Change-Id: I38fe243f86e91868226780960ddc997401ea3a1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2150816
Commit-Queue: Peng Huang <penghuang@chromium.org>
Commit-Queue: Kenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759412}
parent 62c8d62b
...@@ -334,22 +334,15 @@ void ContextState::RestoreSamplerBinding(GLuint unit, ...@@ -334,22 +334,15 @@ void ContextState::RestoreSamplerBinding(GLuint unit,
const ContextState* prev_state) const { const ContextState* prev_state) const {
if (!feature_info_->IsES3Capable()) if (!feature_info_->IsES3Capable())
return; return;
DCHECK(track_texture_and_sampler_units || unit == 0);
GLuint cur_id = 0u; GLuint cur_id = 0u;
if (track_texture_and_sampler_units) { if (const auto& cur_sampler = sampler_units[unit])
if (const auto& cur_sampler = sampler_units[unit]) cur_id = cur_sampler->service_id();
cur_id = cur_sampler->service_id();
}
base::Optional<GLuint> prev_id; base::Optional<GLuint> prev_id;
if (prev_state) { if (prev_state) {
if (prev_state->track_texture_and_sampler_units) { const auto& prev_sampler = prev_state->sampler_units[unit];
const auto& prev_sampler = prev_state->sampler_units[unit]; prev_id.emplace(prev_sampler ? prev_sampler->service_id() : 0);
prev_id.emplace(prev_sampler ? prev_sampler->service_id() : 0);
} else if (prev_state->sampler_units_in_ground_state) {
prev_id.emplace(0);
}
} }
if (!prev_id || cur_id != *prev_id) if (!prev_id || cur_id != *prev_id)
...@@ -459,8 +452,6 @@ void ContextState::RestoreAllTextureUnitAndSamplerBindings( ...@@ -459,8 +452,6 @@ void ContextState::RestoreAllTextureUnitAndSamplerBindings(
if (!prev_state->track_texture_and_sampler_units) { if (!prev_state->track_texture_and_sampler_units) {
texture_units_in_ground_state = texture_units_in_ground_state =
prev_state->texture_units_in_ground_state; prev_state->texture_units_in_ground_state;
sampler_units_in_ground_state =
prev_state->sampler_units_in_ground_state;
return; return;
} }
...@@ -471,22 +462,22 @@ void ContextState::RestoreAllTextureUnitAndSamplerBindings( ...@@ -471,22 +462,22 @@ void ContextState::RestoreAllTextureUnitAndSamplerBindings(
break; break;
} }
} }
sampler_units_in_ground_state = true;
for (size_t i = 1; i < prev_state->sampler_units.size(); ++i) { // Make sure all texture units are in ground state, we need to reset the
const auto& sampler = prev_state->sampler_units[i]; // 0th texture units. If some of non zero textures aren't in ground state,
if (sampler && sampler->service_id() != 0) { // when another context is being make current, we will restore all texture
sampler_units_in_ground_state = false; // units, then it is not necessary to reset the 0th texture units anymore.
break; if (texture_units_in_ground_state)
} RestoreTextureUnitBindings(0, prev_state);
}
} else { } else {
texture_units_in_ground_state = false; texture_units_in_ground_state = false;
sampler_units_in_ground_state = false;
} }
// Even if |track_texture_and_sampler_units| is false, we still need to
// reset texture unit 0 and sampler unit 0 to ground state. // GrContext is not aware of sampler objects and skia will not restore them,
RestoreTextureUnitBindings(0, prev_state); // so we need to reset them to ground state.
RestoreSamplerBinding(0, prev_state); // TODO(penghuang): Remove it when GrContext is created for ES 3.0.
for (size_t i = 0; i < sampler_units.size(); ++i)
RestoreSamplerBinding(i, prev_state);
} else { } else {
// Restore Texture state. // Restore Texture state.
for (size_t i = 0; i < texture_units.size(); ++i) { for (size_t i = 0; i < texture_units.size(); ++i) {
......
...@@ -364,7 +364,6 @@ struct GPU_GLES2_EXPORT ContextState { ...@@ -364,7 +364,6 @@ struct GPU_GLES2_EXPORT ContextState {
// Which samplers are bound to each texture unit; // Which samplers are bound to each texture unit;
std::vector<scoped_refptr<Sampler>> sampler_units; std::vector<scoped_refptr<Sampler>> sampler_units;
mutable bool sampler_units_in_ground_state = true;
// We create a transform feedback as the default one per ES3 enabled context // We create a transform feedback as the default one per ES3 enabled context
// instead of using GL's default one to make context switching easier. // instead of using GL's default one to make context switching easier.
......
...@@ -172,6 +172,9 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) { ...@@ -172,6 +172,9 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _)) EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _))
.WillOnce(SetArgPointee<1>(8u)) .WillOnce(SetArgPointee<1>(8u))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, _))
.WillOnce(SetArgPointee<1>(8u))
.RetiresOnSaturation();
ContextStateTestHelpers::SetupInitState(gl_.get(), feature_info(), ContextStateTestHelpers::SetupInitState(gl_.get(), feature_info(),
gfx::Size(1, 1)); gfx::Size(1, 1));
......
...@@ -279,6 +279,18 @@ bool SharedContextState::InitializeGL( ...@@ -279,6 +279,18 @@ bool SharedContextState::InitializeGL(
return false; return false;
} }
const GLint kGLES2RequiredMinimumTextureUnits = 8u;
GLint max_texture_units = 0;
api->glGetIntegervFn(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_texture_units);
if (max_texture_units < kGLES2RequiredMinimumTextureUnits) {
LOG(ERROR)
<< "SharedContextState::InitializeGL failure max_texture_units : "
<< max_texture_units << " is less that minimum required : "
<< kGLES2RequiredMinimumTextureUnits;
feature_info_ = nullptr;
return false;
}
context_state_ = std::make_unique<gles2::ContextState>( context_state_ = std::make_unique<gles2::ContextState>(
feature_info_.get(), false /* track_texture_and_sampler_units */); feature_info_.get(), false /* track_texture_and_sampler_units */);
...@@ -291,6 +303,11 @@ bool SharedContextState::InitializeGL( ...@@ -291,6 +303,11 @@ bool SharedContextState::InitializeGL(
context_state_->InitCapabilities(nullptr); context_state_->InitCapabilities(nullptr);
context_state_->InitState(nullptr); context_state_->InitState(nullptr);
// Init |sampler_units|, ContextState uses the size of it to reset sampler to
// ground state.
// TODO(penghuang): remove it when GrContext is created with ES 3.0.
context_state_->sampler_units.resize(max_texture_units);
GLenum driver_status = real_context_->CheckStickyGraphicsResetStatus(); GLenum driver_status = real_context_->CheckStickyGraphicsResetStatus();
if (driver_status != GL_NO_ERROR) { if (driver_status != GL_NO_ERROR) {
// If the context was lost at any point before or during initialization, // If the context was lost at any point before or during initialization,
......
...@@ -74,6 +74,9 @@ TEST_F(SharedContextStateTest, InitFailsIfLostContext) { ...@@ -74,6 +74,9 @@ TEST_F(SharedContextStateTest, InitFailsIfLostContext) {
EXPECT_CALL(gl_interface, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _)) EXPECT_CALL(gl_interface, GetIntegerv(GL_MAX_VERTEX_ATTRIBS, _))
.WillOnce(SetArgPointee<1>(8u)) .WillOnce(SetArgPointee<1>(8u))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(gl_interface, GetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, _))
.WillOnce(SetArgPointee<1>(8u))
.RetiresOnSaturation();
ContextStateTestHelpers::SetupInitState(&gl_interface, feature_info.get(), ContextStateTestHelpers::SetupInitState(&gl_interface, feature_info.get(),
gfx::Size(1, 1)); gfx::Size(1, 1));
......
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