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

[spv-in] Properly parse empty names and set entry point function name #789

Merged
merged 2 commits into from
May 4, 2021

Conversation

Gordon-F
Copy link
Collaborator

I'm not sure about these changes at all. Found these issues when developing wgsl-out.

@@ -2371,7 +2371,8 @@ impl<I: Iterator<Item = u32>> Parser<I> {
if left != 0 {
return Err(Error::InvalidOperand);
}
self.future_decor.entry(id).or_default().name = Some(name);
self.future_decor.entry(id).or_default().name =
if name.is_empty() { None } else { Some(name) };
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is needed. We are parsing OpName here. If the incoming SPIRV has an empty name, so be it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's better to fix this issue in backend side like we discuss in matrix? Otherwise we have variables with name _. quad-vert.msl in diff for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it better to fix in Namer, not in spv frontend. Will do in next PR.

Copy link
Member

Choose a reason for hiding this comment

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

Does this actually need to be solved? If the backend ends up generating the name "_", so be it, given that the input annotated something with an empty string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does this actually need to be solved?

It's only about readability.

gl_PerVertex _ = {};
type10 {v_uv, _.gl_Position, _.gl_PointSize, {_.gl_ClipDistance[0]}};
gl_PerVertex global = {};
type10 {v_uv, global.gl_Position, global.gl_PointSize, {global.gl_ClipDistance[0]}};

Copy link
Member

Choose a reason for hiding this comment

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

Ok. I think we can assume that an empty name (that we want to handle) is only coming from SPIR-V, and only from the gl_PerVertex struct. Could we then have the code in place in spv-in specifically that is as narrow (for this use case) as possible? I don't think we want any sort of generic mechanism to eliminate empty names, that doesn't make sense. So a very specialized piece in the spv-in for this gl_PerVertex struct should be most appropriate.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I decided to fix it on namer side. If it's ok, we can merge PR, or we or can leave it as is and close PR. It's not such an important issue.

@@ -2371,7 +2371,8 @@ impl<I: Iterator<Item = u32>> Parser<I> {
if left != 0 {
return Err(Error::InvalidOperand);
}
self.future_decor.entry(id).or_default().name = Some(name);
self.future_decor.entry(id).or_default().name =
if name.is_empty() { None } else { Some(name) };
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's better to fix this issue in backend side like we discuss in matrix? Otherwise we have variables with name _. quad-vert.msl in diff for example.

src/front/spv/function.rs Outdated Show resolved Hide resolved
@@ -57,7 +57,14 @@ impl Namer {

fn call_or(&mut self, label: &Option<String>, fallback: &str) -> String {
self.call(match *label {
Some(ref name) => name,
Some(ref name) => {
// Name can be empty for some cases in SPIR-V
Copy link
Member

Choose a reason for hiding this comment

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

there is only one case where this happens in practice, and spv frontend should be handling it, not Namer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One more try. Thank you for your patience 😄

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

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.

2 participants