Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8a5fe45

Browse files
committed
[Impeller] OpenGLES: Ensure frag/vert textures are bound with unique texture units.
1 parent 94f504f commit 8a5fe45

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

impeller/renderer/backend/gles/buffer_bindings_gles.cc

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,15 @@ bool BufferBindingsGLES::BindUniformData(
155155
}
156156
}
157157

158-
if (!BindTextures(gl, vertex_bindings, ShaderStage::kVertex)) {
158+
std::optional<size_t> next_unit_index =
159+
BindTextures(gl, vertex_bindings, ShaderStage::kVertex);
160+
if (!next_unit_index.has_value()) {
159161
return false;
160162
}
161163

162-
if (!BindTextures(gl, fragment_bindings, ShaderStage::kFragment)) {
164+
if (!BindTextures(gl, fragment_bindings, ShaderStage::kFragment,
165+
*next_unit_index)
166+
.has_value()) {
163167
return false;
164168
}
165169

@@ -295,23 +299,25 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
295299
return true;
296300
}
297301

298-
bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
299-
const Bindings& bindings,
300-
ShaderStage stage) const {
301-
size_t active_index = 0;
302+
std::optional<size_t> BufferBindingsGLES::BindTextures(
303+
const ProcTableGLES& gl,
304+
const Bindings& bindings,
305+
ShaderStage stage,
306+
size_t unit_start_index) const {
307+
size_t active_index = unit_start_index;
302308
for (const auto& data : bindings.sampled_images) {
303309
const auto& texture_gles = TextureGLES::Cast(*data.second.texture.resource);
304310
if (data.second.texture.GetMetadata() == nullptr) {
305311
VALIDATION_LOG << "No metadata found for texture binding.";
306-
return false;
312+
return std::nullopt;
307313
}
308314

309315
const auto uniform_key =
310316
CreateUniformMemberKey(data.second.texture.GetMetadata()->name);
311317
auto uniform = uniform_locations_.find(uniform_key);
312318
if (uniform == uniform_locations_.end()) {
313319
VALIDATION_LOG << "Could not find uniform for key: " << uniform_key;
314-
return false;
320+
return std::nullopt;
315321
}
316322

317323
//--------------------------------------------------------------------------
@@ -320,15 +326,15 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
320326
if (active_index >= gl.GetCapabilities()->GetMaxTextureUnits(stage)) {
321327
VALIDATION_LOG << "Texture units specified exceed the capabilities for "
322328
"this shader stage.";
323-
return false;
329+
return std::nullopt;
324330
}
325331
gl.ActiveTexture(GL_TEXTURE0 + active_index);
326332

327333
//--------------------------------------------------------------------------
328334
/// Bind the texture.
329335
///
330336
if (!texture_gles.Bind()) {
331-
return false;
337+
return std::nullopt;
332338
}
333339

334340
//--------------------------------------------------------------------------
@@ -337,7 +343,7 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
337343
///
338344
const auto& sampler_gles = SamplerGLES::Cast(*data.second.sampler.resource);
339345
if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
340-
return false;
346+
return std::nullopt;
341347
}
342348

343349
//--------------------------------------------------------------------------
@@ -350,7 +356,7 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
350356
///
351357
active_index++;
352358
}
353-
return true;
359+
return active_index;
354360
}
355361

356362
} // namespace impeller

impeller/renderer/backend/gles/buffer_bindings_gles.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ class BufferBindingsGLES {
6161
Allocator& transients_allocator,
6262
const BufferResource& buffer) const;
6363

64-
bool BindTextures(const ProcTableGLES& gl,
65-
const Bindings& bindings,
66-
ShaderStage stage) const;
64+
std::optional<size_t> BindTextures(const ProcTableGLES& gl,
65+
const Bindings& bindings,
66+
ShaderStage stage,
67+
size_t unit_start_index = 0) const;
6768

6869
FML_DISALLOW_COPY_AND_ASSIGN(BufferBindingsGLES);
6970
};

0 commit comments

Comments
 (0)