@@ -151,30 +151,26 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
151151 // / Fragment stage uniforms.
152152 // /
153153
154+ size_t minimum_sampler_index = 100000000 ;
154155 size_t buffer_index = 0 ;
155156 size_t buffer_offset = 0 ;
156- size_t sampler_index = 0 ;
157157 for (auto uniform : runtime_stage_->GetUniforms ()) {
158158 // TODO(113715): Populate this metadata once GLES is able to handle
159159 // non-struct uniform names.
160160 ShaderMetadata metadata;
161161
162162 switch (uniform.type ) {
163163 case kSampledImage : {
164- FML_DCHECK (sampler_index < texture_inputs_.size ());
165- auto & input = texture_inputs_[sampler_index];
166-
167- auto sampler =
168- context->GetSamplerLibrary ()->GetSampler (input.sampler_descriptor );
169-
170- SampledImageSlot image_slot;
171- image_slot.name = uniform.name .c_str ();
172- image_slot.texture_index = sampler_index;
173- image_slot.sampler_index = sampler_index;
174- cmd.BindResource (ShaderStage::kFragment , image_slot, metadata,
175- input.texture , sampler);
176-
177- sampler_index++;
164+ // Sampler uniforms are ordered in the IPLR according to their
165+ // declaration and the uniform location reflects the correct offset to
166+ // be mapped to - except that it may include all proceeding float
167+ // uniforms. For example, a float sampler that comes after 4 float
168+ // uniforms may have a location of 4. To convert to the actual offset we
169+ // need to find the largest location assigned to a float uniform and
170+ // then subtract this from all uniform locations. This is more or less
171+ // the same operation we previously performed in the shader compiler.
172+ minimum_sampler_index =
173+ std::min (minimum_sampler_index, uniform.location );
178174 break ;
179175 }
180176 case kFloat : {
@@ -210,6 +206,35 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
210206 }
211207 }
212208
209+ size_t sampler_index = 0 ;
210+ for (auto uniform : runtime_stage_->GetUniforms ()) {
211+ // TODO(113715): Populate this metadata once GLES is able to handle
212+ // non-struct uniform names.
213+ ShaderMetadata metadata;
214+
215+ switch (uniform.type ) {
216+ case kSampledImage : {
217+ FML_DCHECK (sampler_index < texture_inputs_.size ());
218+ auto & input = texture_inputs_[sampler_index];
219+
220+ auto sampler =
221+ context->GetSamplerLibrary ()->GetSampler (input.sampler_descriptor );
222+
223+ SampledImageSlot image_slot;
224+ image_slot.name = uniform.name .c_str ();
225+ image_slot.texture_index = uniform.location - minimum_sampler_index;
226+ image_slot.sampler_index = uniform.location - minimum_sampler_index;
227+ cmd.BindResource (ShaderStage::kFragment , image_slot, metadata,
228+ input.texture , sampler);
229+
230+ sampler_index++;
231+ break ;
232+ }
233+ default :
234+ continue ;
235+ }
236+ }
237+
213238 pass.AddCommand (std::move (cmd));
214239
215240 if (geometry_result.prevent_overdraw ) {
0 commit comments