Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a uniform block with lifetime parameters #2049

Open
fcrisafulli-dev opened this issue Mar 18, 2023 · 2 comments
Open

Creating a uniform block with lifetime parameters #2049

fcrisafulli-dev opened this issue Mar 18, 2023 · 2 comments

Comments

@fcrisafulli-dev
Copy link

I am trying to streamline my uniform pipeline by using uniform blocks. I want to create a block called StaticUniforms which is created using glium::uniforms::UniformBuffer::immutable. Based on the documentation this should be reserved for uniforms which do not change much if at all.

My current layout looks like this:

use glium::{implement_uniform_block, uniforms::Sampler, texture::SrgbCubemap};

#[derive(Clone, Copy)]
pub struct StaticUniforms<'a> {
    pub u_perspective: [[f32;4];4],
    pub u_skybox: Sampler<'a, SrgbCubemap>
}
implement_uniform_block!(StaticUniforms,u_perspective, u_skybox);

I am able to successfully create and use this uniform block with just the perspective matrix.

However, when I try to add a Sampler<'_, T> the implement_uniform_block! macro yields the compiler error: the trait bound 'Sampler<'_, glium::texture::SrgbCubemap>: glium::uniforms::UniformBlock' is not satisfied

Further investigation shows that this might be an issue with the macro itself as the full diagnostic yields:

error[E0726]: implicit elided lifetime not allowed here
 --> src\glib\uniform.rs:8:1
  |
8 | implement_uniform_block!(StaticUniforms,u_perspective, u_skybox);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected lifetime parameter
  |
  = note: assuming a `'static` lifetime...
  = note: this error originates in the macro `$crate::implement_uniform_block` which comes from the expansion of the macro `implement_uniform_block` (in Nightly builds, run with -Z macro-backtrace for more info)
help: indicate the anonymous lifetime
 --> C:\Users\usr\.cargo\git\checkouts\glium-77a94afc886844c8\bdb70bc\src\macros.rs:369:75
  |
36|             impl<$($gs)*> $crate::uniforms::UniformBlock for $struct_name<'_, $($gs)*> {
  |                                                                           +++

Should I simply modify the macro as the compiler suggests? Or is there a different way to use structs with lifetime parameters within a uniform block?

@Melchizedek6809
Copy link
Member

Thank you for opening this issue. It does sound like a problem with glium, I'll try and look into it on the weekend. Could you maybe upload a full example somewhere? That way it's easier for me to test whether it fixes the actual issue.

@fcrisafulli-dev
Copy link
Author

It might not actually be an issue with Glium. The shader compiler doesn't allow for samplers to be used within a uniform block anyways.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants