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

deduplicate OpVariable #396

Merged
merged 1 commit into from
Jan 26, 2021
Merged

deduplicate OpVariable #396

merged 1 commit into from
Jan 26, 2021

Conversation

khyperia
Copy link
Contributor

@khyperia khyperia commented Jan 26, 2021

I believe this may help getting things working on Android.

On an internal issue, @VZout said:

My minimal test case right now is just 2 entry points with vertex index to reproduce the pipeline creation failure

Here's my theory. If you have two shaders set up like this:

#[spirv(vertex)]
pub fn vs_1(#[spirv(vertex_index)] vert_id: Input<i32>) { }
#[spirv(vertex)]
pub fn vs_2(#[spirv(vertex_index)] vert_id: Input<i32>) { }

then right now, rust-gpu will generate two OpVariables: one per entry point. Each OpVariable will get used in their respective vertex shader, and all is well and good... until we arrive at buggy android shader compilers. My guess is that it emits some automatic intrinsic code, or something, idk, when it encounters a vertex index OpVariable. Then, it hits another vertex index OpVariable, and says "wait we already did that, oops, crash", even though they're only used in separate shaders, never at the same time.

My theory is that emitting a single OpVariable for both shaders will make it happy. But, I don't have @VZout's testing code, so I'm putting this up and seeing if it works~

However! An open question is what to deduplicate on. If the descriptor set, binding, location, type, or any other decoration differs, then obviously we shouldn't deduplicate it. But... what if it has a different OpName? For some use cases, we should keep both around! They're different names, different things, shows up differently in OpenGL when searching for uniforms by name! But for some use cases, we should deduplicate them - for example, the following would generate two vertex index OpVariables, which isn't great!

#[spirv(vertex)]
pub fn vs_1(#[spirv(vertex_index)] one: Input<i32>) { }
#[spirv(vertex)]
pub fn vs_2(#[spirv(vertex_index)] two: Input<i32>) { }

Right now, this code does consider name to be part of the unique key of an OpVariable - so it will not deduplicate the above, and keep two around.


Amusingly, I got this idea from a completely unrelated issue with a community member having issues with I think spirv-cross, which dumped out two identical variables in the source (because there's two OpVariables), which got sad. Context in the arkadia discord here.

@khyperia khyperia added the c: rustc_codegen_spirv Issues specific to the rustc_codegen_spirv crate. label Jan 26, 2021
@khyperia khyperia requested a review from VZout January 26, 2021 13:43
@khyperia khyperia requested a review from eddyb as a code owner January 26, 2021 13:43
Comment on lines +157 to +163
let slice = match *chunk {
[a] => [a, 0, 0, 0],
[a, b] => [a, b, 0, 0],
[a, b, c] => [a, b, c, 0],
[a, b, c, d] => [a, b, c, d],
_ => bug!(),
};
Copy link
Contributor

@eddyb eddyb Jan 26, 2021

Choose a reason for hiding this comment

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

Might be simpler to start with a [0; 4] and write the bytes into it (with copy_from_slice IIRC)?

Copy link
Member

@VZout VZout left a comment

Choose a reason for hiding this comment

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

Great success! it renders. (Didn't read through the code)

@mergify mergify bot merged commit d883799 into main Jan 26, 2021
@mergify mergify bot deleted the deduplicate-opvariable branch January 26, 2021 16:03
@VZout
Copy link
Member

VZout commented Jan 26, 2021

Why did it merge.... @eddyb didn't aprove it.

@XAMPPRocky
Copy link
Member

@VZout We only have 1 required reviewer, so if you request more than that, whoever approves first will cause it to be merged.

@eddyb
Copy link
Contributor

eddyb commented Jan 26, 2021

Why did it merge.... @eddyb didn't aprove it.

FWIW I was fine with merging it, and the only code change I might've requested was #396 (comment) - but I expected more discussion might be needed on whether we should do this in the first place.

@khyperia
Copy link
Contributor Author

@VZout We only have 1 required reviewer, so if you request more than that, whoever approves first will cause it to be merged.

Do note that we also have a requirement of 0 requested reviewers (and 0 requested changes), which means that 1 person approving will not cause it to be merged. But, @eddyb commented (like a reasonable person), and github says that clears the review request, so 0 requested reviews left, and merge.

FWIW I was fine with merging it, and the only code change I might've requested was #396 (comment) - but I expected more discussion might be needed on whether we should do this in the first place.

Yeah, was planning on doing that, as well as more discussion around OpName handling. Oh well I guess, can do that in a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: rustc_codegen_spirv Issues specific to the rustc_codegen_spirv crate.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants