@@ -168,8 +168,9 @@ RuntimeEffectContents::CreatePipeline(const ContentContext& renderer,
168
168
const std::shared_ptr<Context>& context = renderer.GetContext ();
169
169
const std::shared_ptr<ShaderLibrary>& library = context->GetShaderLibrary ();
170
170
const std::shared_ptr<const Capabilities>& caps = context->GetCapabilities ();
171
- const auto color_attachment_format = caps->GetDefaultColorFormat ();
172
- const auto stencil_attachment_format = caps->GetDefaultDepthStencilFormat ();
171
+ const PixelFormat color_attachment_format = caps->GetDefaultColorFormat ();
172
+ const PixelFormat stencil_attachment_format =
173
+ caps->GetDefaultDepthStencilFormat ();
173
174
174
175
using VS = RuntimeEffectVertexShader;
175
176
@@ -233,25 +234,37 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
233
234
// /
234
235
BindFragmentCallback bind_callback = [this , &renderer,
235
236
&context](RenderPass& pass) {
236
- size_t minimum_sampler_index = 100000000 ;
237
237
size_t buffer_index = 0 ;
238
238
size_t buffer_offset = 0 ;
239
-
239
+ size_t sampler_location = 0 ;
240
+ size_t buffer_location = 0 ;
241
+
242
+ // Uniforms are ordered in the IPLR according to their
243
+ // declaration and the uniform location reflects the correct offset to
244
+ // be mapped to - except that it may include all proceeding
245
+ // uniforms of a different type. For example, a texture sampler that comes
246
+ // after 4 float uniforms may have a location of 4. Since we know that
247
+ // the declarations are already ordered, we can track the uniform location
248
+ // ourselves.
240
249
for (const auto & uniform : runtime_stage_->GetUniforms ()) {
241
250
std::unique_ptr<ShaderMetadata> metadata = MakeShaderMetadata (uniform);
242
251
switch (uniform.type ) {
243
252
case kSampledImage : {
244
- // Sampler uniforms are ordered in the IPLR according to their
245
- // declaration and the uniform location reflects the correct offset to
246
- // be mapped to - except that it may include all proceeding float
247
- // uniforms. For example, a float sampler that comes after 4 float
248
- // uniforms may have a location of 4. To convert to the actual offset
249
- // we need to find the largest location assigned to a float uniform
250
- // and then subtract this from all uniform locations. This is more or
251
- // less the same operation we previously performed in the shader
252
- // compiler.
253
- minimum_sampler_index =
254
- std::min (minimum_sampler_index, uniform.location );
253
+ FML_DCHECK (sampler_location < texture_inputs_.size ());
254
+ auto & input = texture_inputs_[sampler_location];
255
+
256
+ raw_ptr<const Sampler> sampler =
257
+ context->GetSamplerLibrary ()->GetSampler (
258
+ input.sampler_descriptor );
259
+
260
+ SampledImageSlot image_slot;
261
+ image_slot.name = uniform.name .c_str ();
262
+ image_slot.binding = uniform.binding ;
263
+ image_slot.texture_index = sampler_location;
264
+ pass.BindDynamicResource (ShaderStage::kFragment ,
265
+ DescriptorType::kSampledImage , image_slot,
266
+ std::move (metadata), input.texture , sampler);
267
+ sampler_location++;
255
268
break ;
256
269
}
257
270
case kFloat : {
@@ -268,12 +281,13 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
268
281
269
282
ShaderUniformSlot uniform_slot;
270
283
uniform_slot.name = uniform.name .c_str ();
271
- uniform_slot.ext_res_0 = uniform. location ;
284
+ uniform_slot.ext_res_0 = buffer_location ;
272
285
pass.BindDynamicResource (ShaderStage::kFragment ,
273
286
DescriptorType::kUniformBuffer , uniform_slot,
274
287
std::move (metadata), std::move (buffer_view));
275
288
buffer_index++;
276
289
buffer_offset += uniform.GetSize ();
290
+ buffer_location++;
277
291
break ;
278
292
}
279
293
case kStruct : {
@@ -292,34 +306,6 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
292
306
}
293
307
}
294
308
295
- size_t sampler_index = 0 ;
296
- for (const auto & uniform : runtime_stage_->GetUniforms ()) {
297
- std::unique_ptr<ShaderMetadata> metadata = MakeShaderMetadata (uniform);
298
-
299
- switch (uniform.type ) {
300
- case kSampledImage : {
301
- FML_DCHECK (sampler_index < texture_inputs_.size ());
302
- auto & input = texture_inputs_[sampler_index];
303
-
304
- raw_ptr<const Sampler> sampler =
305
- context->GetSamplerLibrary ()->GetSampler (
306
- input.sampler_descriptor );
307
-
308
- SampledImageSlot image_slot;
309
- image_slot.name = uniform.name .c_str ();
310
- image_slot.binding = uniform.binding ;
311
- image_slot.texture_index = uniform.location - minimum_sampler_index;
312
- pass.BindDynamicResource (ShaderStage::kFragment ,
313
- DescriptorType::kSampledImage , image_slot,
314
- std::move (metadata), input.texture , sampler);
315
-
316
- sampler_index++;
317
- break ;
318
- }
319
- default :
320
- continue ;
321
- }
322
- }
323
309
return true ;
324
310
};
325
311
0 commit comments