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

Commit 787f9ef

Browse files
authored
[Impeller] OpenGLES: Ensure frag/vert textures are bound with unique texture units. (#47218)
The fragment shader texture bindings will smash into the texture units used for the vertex shader bindings if the vertex and fragment shaders both have textures. Entities doesn't use any pipelines that tickle this case.
1 parent c562fd7 commit 787f9ef

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(const ProcTableGLES& gl,
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

@@ -334,20 +338,22 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl,
334338
return true;
335339
}
336340

337-
bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
338-
const Bindings& bindings,
339-
ShaderStage stage) {
340-
size_t active_index = 0;
341+
std::optional<size_t> BufferBindingsGLES::BindTextures(
342+
const ProcTableGLES& gl,
343+
const Bindings& bindings,
344+
ShaderStage stage,
345+
size_t unit_start_index) {
346+
size_t active_index = unit_start_index;
341347
for (const auto& data : bindings.sampled_images) {
342348
const auto& texture_gles = TextureGLES::Cast(*data.second.texture.resource);
343349
if (data.second.texture.GetMetadata() == nullptr) {
344350
VALIDATION_LOG << "No metadata found for texture binding.";
345-
return false;
351+
return std::nullopt;
346352
}
347353

348354
auto location = ComputeTextureLocation(data.second.texture.GetMetadata());
349355
if (location == -1) {
350-
return false;
356+
return std::nullopt;
351357
}
352358

353359
//--------------------------------------------------------------------------
@@ -356,15 +362,15 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
356362
if (active_index >= gl.GetCapabilities()->GetMaxTextureUnits(stage)) {
357363
VALIDATION_LOG << "Texture units specified exceed the capabilities for "
358364
"this shader stage.";
359-
return false;
365+
return std::nullopt;
360366
}
361367
gl.ActiveTexture(GL_TEXTURE0 + active_index);
362368

363369
//--------------------------------------------------------------------------
364370
/// Bind the texture.
365371
///
366372
if (!texture_gles.Bind()) {
367-
return false;
373+
return std::nullopt;
368374
}
369375

370376
//--------------------------------------------------------------------------
@@ -373,7 +379,7 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
373379
///
374380
const auto& sampler_gles = SamplerGLES::Cast(*data.second.sampler.resource);
375381
if (!sampler_gles.ConfigureBoundTexture(texture_gles, gl)) {
376-
return false;
382+
return std::nullopt;
377383
}
378384

379385
//--------------------------------------------------------------------------
@@ -386,7 +392,7 @@ bool BufferBindingsGLES::BindTextures(const ProcTableGLES& gl,
386392
///
387393
active_index++;
388394
}
389-
return true;
395+
return active_index;
390396
}
391397

392398
} // namespace impeller

impeller/renderer/backend/gles/buffer_bindings_gles.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ class BufferBindingsGLES {
7070
Allocator& transients_allocator,
7171
const BufferResource& buffer);
7272

73-
bool BindTextures(const ProcTableGLES& gl,
74-
const Bindings& bindings,
75-
ShaderStage stage);
73+
std::optional<size_t> BindTextures(const ProcTableGLES& gl,
74+
const Bindings& bindings,
75+
ShaderStage stage,
76+
size_t unit_start_index = 0);
7677

7778
BufferBindingsGLES(const BufferBindingsGLES&) = delete;
7879

0 commit comments

Comments
 (0)