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

Things that I think could be improved in gfx-rs #216

Closed
12 of 20 tasks
tomaka opened this issue Aug 15, 2014 · 11 comments
Closed
12 of 20 tasks

Things that I think could be improved in gfx-rs #216

tomaka opened this issue Aug 15, 2014 · 11 comments

Comments

@tomaka
Copy link
Contributor

tomaka commented Aug 15, 2014

@kvark encouraged me to post a mega-issue about things that I don't like with gfx-rs, so here it is.

Documentation

  • More examples.
  • Document the differences between device, render and gfx and what each of these crates is supposed to do. It took me some time to figure out that only gfx is supposed to be used.
  • Not only document what a trait/enum is, but also where and how it should be used. For example if an object doesn't have a constructor (like FrontEnd or DrawList), it should be documented how to create one.
  • Everything that shouldn't be used by the user must be either private or marked with #[doc(hidden)]. This includes Handle and VertexFormat.
  • Document a little bit what a buffer, a surface, a frame buffer, etc. are. Don't assume that all gfx-rs users will be experts in 3D rendering.
  • Document whether [[f32, ..4], ..4] is supposed to be row-major or column-major.
  • The Frame type is too confusing. The front end returns "the main frame", but frames can be created with Frame::new(). The docs say it's "the result of rendering", but I'd expect the pixel data to be in there if it was the case. What exactly is a frame?
  • Same for Mesh.
  • I have never heard the Shell word before when talking about 3D rendering. This word is confusing.

Safety

  • Remove all type Foo = Bar in favor of struct Foo(Bar).
  • Remove all delete_* functions. RAII should handle everything.
  • Rust doesn't allow "empty" objects (eg. null pointers), so gfx-rx shouldn't allow empty textures or empty buffers either.
  • Texture data format should be inferred using Rust's type system. For example if the user uploads some texture data whose type is &[(f32, f32, f32)] or &[[f32, ..3]], you can infer that it has 3 gl_float components.
  • Similarly, the type of the texture (1D, 2D, 3D) can be auto-detected depending on the function parameters. If the user passes a height of 1 and a depth of 1 to create_texture, then it's a 1D texture.
  • Why does DrawList have a reset method? The user should just create a new list instead of resetting it.
  • Index buffer are too difficult to use and too unsafe. Just like textures, the type of indices should be inferred from the rust type used in the buffer instead of requiring the user to pass a U16 or U32 enum value.
  • create_frame_buffer should not return a u32.
  • Mesh should contain the BufferHandle to ensure that the buffer is not destroyed as long as the mesh exists.

Usability

  • Why is connect_program not part of the draw list? More often than not, you have a matrix uniform which must be updated at each frame. The fact that it's not part of the draw list makes draw list not reusable because you need to recreate a new CustomShell object at each frame.
  • ParamDirectory should be much easier to create.
@kvark
Copy link
Member

kvark commented Aug 15, 2014

This is an impressive list! Let me address some of its points (other points I mainly agree with):

More examples.

We have #210, which will show multi-threading and working with frames. Anything else you think requires explicit coverage?

It took me some time to figure out that only gfx is supposed to be used.

This is arguable. All examples use only gfx now, and the tutorial (in our blog) also used only this crate. There is no reason to think you need anything else, but I do agree that we could have said it more explicitly in the docs.

#[doc(hidden)]. This includes Handle and VertexFormat.

Users may find the second one useful, but I agree on the Handle.

Same for Mesh

Mesh seems to be pretty well documented. Could you revisit mesh.rs?

Remove all delete_* functions. RAII should handle everything.

I wish we had this level of convenience, but it's by far not trivial to provide this as an alternative that is only suitable for single-threaded execution.

If the user passes a height of 1 and a depth of 1 to create_texture, then it's a 1D texture.

This is possible, but there are more types. How do you infer Texture2DArray or TextureCube?

Why does DrawList have a reset method? The user should just create a new list instead of resetting it.

Because resetting the draw list avoids re-allocating the memory. Besides, we are going to have the create_draw_list on the Device, which might live in a separate thread from the one that populates the draw list.

Why is connect_program not part of the draw list?

You are only supposed to use it once when the program is linked. Today, we have a convenient link_program which does both linking and connection with parameters. Once you got the Shell (to be renamed into Program), you can either re-use it (program.data.your_matrix = each frame), or clone() it to use with different parameters.

I realize that this needs to be demonstrated and explained. We've been in flux, and my article draft on shader parameters is still a draft. I'll update it once we stabilize more.

@kvark
Copy link
Member

kvark commented Aug 18, 2014

Rust doesn't allow "empty" objects (eg. null pointers), so gfx-rx shouldn't allow empty textures or empty buffers either.

Fixed by #220

Index buffer are too difficult to use and too unsafe.

Fixed by #217

@brendanzab
Copy link
Contributor

Thanks a bunch for the feedback!

@kvark
Copy link
Member

kvark commented Aug 19, 2014

create_frame_buffer should not return a u32.

Fixed by #240

@kvark kvark added the D-hard label Aug 19, 2014
@tomaka
Copy link
Contributor Author

tomaka commented Aug 20, 2014

This is possible, but there are more types. How do you infer Texture2DArray or TextureCube?

In simple-gl-rs, I'm passing an additional arraySize parameter when creating textures.
TextureCube would need a separate function.

We have #210, which will show multi-threading and working with frames. Anything else you think requires explicit coverage?

Ideally most OpenGL features should be covered by examples, but this is a lot of work and is not urgent.

@kvark
Copy link
Member

kvark commented Aug 20, 2014

In simple-gl-rs, I'm passing an additional arraySize parameter when creating textures.
TextureCube would need a separate function.

To be fair, I believe we did consider that before implementing the texturing support, because that's pretty much what Claymore had. I can't tell you why we ended up settling with an explicit kind in TextureInfo, but we are going to re-evaluate it for sure. @cmr what do you think?

@emberian
Copy link
Contributor

I chose to do the explicit kind because I feel it is less error-prone and is easier to read/understand.

@kvark
Copy link
Member

kvark commented Aug 26, 2014

Remove all delete_* functions. RAII should handle everything.
Mesh should contain the BufferHandle to ensure that the buffer is not destroyed as long as the mesh exists.

Moved into a separate issue #288 for RAII.

@kvark
Copy link
Member

kvark commented Aug 27, 2014

Remove all type Foo = Bar in favor of struct Foo(Bar).

Covered by #145

@kvark
Copy link
Member

kvark commented Feb 19, 2016

This becomes slightly obsolete, and a lot of points are already done. Lowering the priority.

@kvark
Copy link
Member

kvark commented Feb 12, 2019

Not planning on doing these changes in pre-ll

@kvark kvark closed this as completed Feb 12, 2019
adamnemecek pushed a commit to adamnemecek/gfx that referenced this issue Apr 1, 2021
216: Add Naïve Debug Derives Where Possible r=kvark a=arashikou

This adds `#[derive(Debug)]` to all public structs and enums possible. This also required adding it to some private types that they transitively depend on. However, the following types depend on types from external crates that do not implement Debug:

* `device::Device`
* `hub::Hub`
* `swap_chain::Surface`
* `swap_chain::SwapChain`

To support these types, we would need to use either custom `Debug` impls or something like [Derivative](https://mcarton.github.io/rust-derivative/).

This helps improve the situation in gfx-rs#76.

Co-authored-by: John W. Bruce <arashikou@gmail.com>
adamnemecek pushed a commit to adamnemecek/gfx that referenced this issue Apr 1, 2021
226: Tracking Rewrite r=grovesNL a=kvark

Fixes gfx-rs#44

The idea is to support independent tracking of sub-resources. Today, this is needed for textures, which can have individual layers and mipmap levels in different states at a time. Tomorrow, this will be needed for buffer sub-ranges.

The intent to hack it in grew into a complete rewrite of the tracker... The new approach is cleaner in a few places (e.g. `TrackPermit` is gone), but the implementation is obviously more complex. I tried to separate the levels from each other (see `ResourceState` and `RangedStates`) to fight complexity, but it requires a whole lot of testing infrastructure to be solid.

Also regresses gfx-rs#216 a bit, cc @arashikou : tracker is a relatively complex structure. I somehow doubt it's useful to look at it in debug spew. We may need to implement `Debug` manually for it before re-adding `Debug` derives on passes and command buffers.

TODO:
  - [x] documentation of tracking types
  - [x] unit tests for tracking logic
  - [x] actual testing with existing apps, ensure no regressions
  - [x] write a mipmap generation example

Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
adamnemecek pushed a commit to adamnemecek/gfx that referenced this issue Apr 1, 2021
With gfx-hal 0.2.1 and the various backend releases on 2019-06-28, all
of the gfx-hal types that wgpu depends on implement Debug. Thus, some
types that could not derive Debug in gfx-rs#216 can now derive Debug.

This patch also adds Debug implementations for a few types that were
recently added to wgpu.

Fixes gfx-rs#76.
adamnemecek pushed a commit to adamnemecek/gfx that referenced this issue Apr 1, 2021
223: Derive Debug for All Remaining Public Types r=kvark a=arashikou

With gfx-hal 0.2.1 and the various backend releases on 2019-06-28, all of the gfx-hal types that wgpu depends on implement `Debug`. Thus, some types that could not derive `Debug` in gfx-rs#216 can now derive `Debug`.

This patch also adds `Debug` implementations for a few types that were recently added to wgpu.

Fixes gfx-rs#76.

Co-authored-by: John W. Bruce <arashikou@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants