-
Notifications
You must be signed in to change notification settings - Fork 441
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
Mesh shading example #2437
Mesh shading example #2437
Conversation
Please be so kind as to rebase so Rua's commits aren't mixed in. It can be done without any merge conflicts by rebasing onto Rua's branch first (for a remote named
Then squashing her commits (pick her first commit and squash all her other commits into it):
Then you can rebase onto master without conflicts (making sure it's the upstream master not some outdated fork's):
There may be some more ergonomic way to go about it but this I've found works 100% of the time. |
70e024d
to
db078f0
Compare
Sure, I've squashed Rua's PR. Otherwise it was already rebased on Rua's PR, which was already rebased on current master. |
But now this PR still contains the same changes as my PR, which makes reviewing it more difficult, as it's hard to separate your changes from mine. |
You need to rebase onto master as well. |
As for the first step, that's needed because Rua's branch has had more commits added to it than your fork. If you didn't rebase onto Rua's updated branch, you would get a merge conflict along the way. |
Ohhhh.. my remote for vulkano didn't update for some reason, I didn't notice you've merged ext_mesh_shaders already |
…struct alignment issues
db078f0
to
032f777
Compare
That's why I say to make sure to use upstream master ;) Because this happens every time. I suggest making your local master branch track upstream/master, that is, our remote, and have all the other branches track your remote. |
That's already how my setup works, it's just that Intellij Idea's "update project" button seems to only fetch the origin of the checked out branch, not all branches... |
I'm not submitting this PR because it is ready, but because there is a weird struct layout issue here. vulkano/examples/mesh-shader/shader.mesh Line 47 in 032f777
First turn on LOAD_FROM_INSTANCE_BUFFER, which it is on the current latest commit, to use instance data loaded from buffers instead of generating all the geometry dynamically in the mesh shader. vulkano/examples/mesh-shader/shader.mesh Lines 18 to 22 in 032f777
On the GPU side this Instance struct uses STD140 layout, which causes it's alignment to be 16 bytes, but on the CPU it's aligned to 12 bytes. In the main.rs the InstanceData struct is currently defined manually, but even if I define it as // also move the shaders here it still is misalignend, producing garbage output. Manually using repr(C, alignn(16)) also does not help. |
I see, that is the default behavior of |
I think the shaders should be named |
Co-authored-by: marc0246 <[email protected]>
73af6b1
to
cc7fed1
Compare
Wouldn't it be more consistent if we've used glslang's file endings?
The last two options could also be a good alternative. |
examples/mesh-shader/shader.mesh
Outdated
float scale; | ||
|
||
const bool LOAD_FROM_INSTANCE_BUFFER = true; | ||
if (LOAD_FROM_INSTANCE_BUFFER) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not that happy with this if being semi-hidden in the shader code. It's hopefully obvious what it does once you read the shader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it could be made into a specialization constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice you'd make it a SpecConstant, but I feel like for an example it's overkill and only complicates it further.
Instead I'd propose two possible solutions:
- uniform bool toggled with a keyboard press: But that key would have to be known to the user, and the current state needs to be visualized. As we can't exactly render text easily, likely changing the color of the triangles.
- Keep it as is: At the end of the day the if should switch between the two main use-cases of mesh shaders: reading vertex (& other) data manually and generating completely dynamic geometry. And those investigating mesh shaders will read the code and understand what the simple
const bool
does, and is likely less complicated than following where a uniform came from.
I'm currently leaning more on 2, especially with maybe some more docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented variant 2 as follows:
vulkano/examples/mesh-shader/mesh.glsl
Lines 54 to 61 in e89f419
// There are two main use-cases for mesh shaders, switch in between them here. | |
// They should both draw the same triangles, but with different colors. | |
const bool LOAD_FROM_INSTANCE_BUFFER = false; | |
if (LOAD_FROM_INSTANCE_BUFFER) { | |
// Use-case 1: load instance data from buffers, similarly to doing an instanced draw | |
// color triangles red | |
color = vec4(1.0, 0.0, 0.0, 1.0); |
vulkano/examples/mesh-shader/mesh.glsl
Lines 67 to 70 in e89f419
} else { | |
// Use-case 2: generate the geometry dynamically in the mesh shader | |
// color triangles green | |
color = vec4(0.0, 1.0, 0.0, 1.0); |
Those file endings are for automatic stage resolution, which we don't have, and I wouldn't call those endings standard at all. They don't even tell you what language it is. And as I already mentioned, syntax highlighting becomes harder. See for example how GitHub doesn't support the mesh extension yet. Granted, I use those extensions in my own projects, but I've had to do additional configuration in at least 2 editors I used. That's not exactly a quality I would be looking for in examples. |
Can you please name the file |
Awesome, thanks. The only other thing that needs to be changed IMO is the formatting of the shaders. Namely, please use 4 spaces instead of the tabs like the other examples, and remove the multiple consecutive linefeeds. |
I've also added an output variable to the mesh shader, simply passing the triangle color, so that pretty much everything you may want to do with mesh shaders is covered. Apart from task shaders, but those aren't super complicated to understand, and should easily be transferable from any other example or tutorial. vulkano/examples/mesh-shader/mesh.glsl Lines 38 to 39 in e89f419
|
Actually something else I forgot, the Rust formatting is not like ours either. I assume this is rust-analyzer's formatting work. If you look in the |
Thank you for the very nice work! I really appreciate it ❤️ Let's keep the one comment unresolved for a possible future alteration. I think it's fine as is. |
* mesh-shader-triangle example: copied from instancing example * mesh-shader-triangle example: move shaders to separate files * mesh-shader example: rename example * mesh-shader example: implement mesh shader generating geometry * mesh-shader example: fix instance data indexing partially, still has struct alignment issues * mesh-shader example: fixed instance buffer alignment issues * remove unnecessary things Co-authored-by: marc0246 <[email protected]> * mesh-shader example: cargo fmt * mesh-shader example: rename shaders to end in .glsl * mesh-shader example: added color out variable, docs * mesh-shader example: rename shader again * mesh-shader example: reformat shader code * mesh-shader example: cargo fmt with nightly --------- Co-authored-by: Firestar99 <[email protected]> Co-authored-by: marc0246 <[email protected]>
Update documentation to reflect any user-facing changes - in this repository. - None
Make sure that the changes are covered by unit-tests. - None
Run
cargo fmt
on the changes.Please put changelog entries in the description of this Pull Request
if knowledge of this change could be valuable to users. No need to put the
entries to the changelog directly, they will be transferred to the changelog
file by maintainers right after the Pull Request merge.
Please remove any items from the template below that are not applicable.
Describe in common words what is the purpose of this change, related
Github Issues, and highlight important implementation aspects.
Changelog: