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

Moved gl_device out #598

Merged
merged 8 commits into from
Feb 27, 2015
Merged

Moved gl_device out #598

merged 8 commits into from
Feb 27, 2015

Conversation

kvark
Copy link
Member

@kvark kvark commented Feb 24, 2015

Closes #80
Depends on https://github.com/gfx-rs/gfx_device_gl/pull/1

The biggest problem is security. Once device_gl is in a separate crate, it can no longer construct Handle and *Mapping types, since they have private fields. Making the fields public could be a temporary solution but I wish we had something more secure to offer.

@brendanzab
Copy link
Contributor

Maybe they could be unsafe getters/setters?

@brendanzab
Copy link
Contributor

I will think on this.

@kvark
Copy link
Member Author

kvark commented Feb 24, 2015

@bjz I think I know a good solution:

  • Add a DeviceInternal trait, implement create_handle and create_mapping_* in it (default implementation that doesn't need to be overwritten)
  • Auto-implement it for everything that implements Device
  • Don't re-export it in gfx root, but it's still accessible via gfx::device::DeviceInternal

It's unlikely that anyone will try to reach for it, but even one does - one probably knows what one is doing. There is gonna be near zero chance of "accidental" creation of invalid handles and such.

@kvark
Copy link
Member Author

kvark commented Feb 24, 2015

Note to self: cleanup instancing parameters in the renderer.

@kvark
Copy link
Member Author

kvark commented Feb 25, 2015

Ok, the last problem now is with macros. Having a code like this doesn't really compile:

impl<R: gfx::Resources> gfx::VertexFormat for Foo {
   type Resources = R;
   ...
}

Because Rust doesn't know how to constrain R:

the type parameter R is not constrained by the impl trait, self type, or predicates [E0207]

Any ideas?

@kvark
Copy link
Member Author

kvark commented Feb 25, 2015

Here is a standalone snippet exposing the problem:

trait Foo {}
trait Bar {
    type F: Foo;
    fn fun(&self, Self::F);
}
impl<F: Foo> Bar for () {
    type F = F;
    fn fun(&self, _:F) {}
}

One straightforward solution would be to provide an exact Resources type to the macros: #[shader_param(gfx_device_gl::Resources)]

However, I don't like where this is going. Not only it is already verbose, even if you do a typedef, it would be the hell in a complex application with many vertex/shader formats and multiple supported backends. Too much noise, especially since it's not obvious why the original one shouldn't work.

@cmr halp

@kvark
Copy link
Member Author

kvark commented Feb 25, 2015

@Kimundi provided a good explanation on why this is not sound:

I don't think this can be made to work, since you'd have many possible associated items for the same type ()

The solution, as it seems, could be to remove the associated type from VertexFormat, making R a generic parameter.

@kvark kvark changed the title [WIP] Moved gl_device out Moved gl_device out Feb 26, 2015
@kvark
Copy link
Member Author

kvark commented Feb 26, 2015

@bjz @csherratt - this is ready

I fought with ShaderParam a lot, ending up just with a parameter as proposed earlier. It's gonna take us a while to reach the limitations of this model.

@kvark
Copy link
Member Author

kvark commented Feb 26, 2015

Also, deferred example doesn't work for me. When rendering to Gbuffer, we get an exception saying the target frame doesn't have depth (mask = 64). I tried logging it up in the example code, and the mask seems to be 71, so something happens inside the submission. I blame that Rust bug.

@@ -14,10 +14,10 @@

[package]
name = "gfx"
version = "0.1.7"
version = "0.2.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay~

@ghost
Copy link

ghost commented Feb 27, 2015

LGTM. I'd like @bjz to look over it too.

@kvark
Copy link
Member Author

kvark commented Feb 27, 2015

@csherratt sure thing. Thanks!

@@ -84,7 +86,7 @@ struct CubeVertex {
pos: [i8; 3],
}

#[shader_param]
#[shader_param(R)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok for now, but it would be nice to have a better way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I just wasn't able to come up with anything better than that... The problem comes from the fact that this structure has to implement ShaderParam for every device. We need to somehow make it device-independent.

brendanzab added a commit that referenced this pull request Feb 27, 2015
@brendanzab brendanzab merged commit 79e00b2 into gfx-rs:master Feb 27, 2015
@kvark kvark deleted the device_gl branch February 27, 2015 23:58
adamnemecek pushed a commit to adamnemecek/gfx that referenced this pull request Apr 1, 2021
598: Enable READ access for texture storage r=kvark a=kvark

This is a short-term workaround until we properly implement gfx-rs#597 

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
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

Successfully merging this pull request may close these issues.

Move gl device implementation into separate crate
2 participants