Skip to content

Improve handling of semantics through SROA - #1777

Merged
Tristan Labelle (tristanlabelle) merged 4 commits into
microsoft:masterfrom
tristanlabelle:semantics-sroa-improvements
Dec 19, 2018
Merged

Tristan Labelle (tristanlabelle) merged 4 commits into
microsoft:masterfrom
tristanlabelle:semantics-sroa-improvements

Conversation

@tristanlabelle

Copy link
Copy Markdown
Contributor

This mainly fixes a crash with this code:

struct Input { float a : TEXCOORD0; float b : TEXCOORD0; };
float main(Input input) : SV_Target { return 1; }

The crash happened because of our strategy for handling this:

struct Input { float a; float b; };
float main(Input input : TEXCOORD0) : SV_Target { return 1; }

When expanding Input, we would label every field with the original semantic, so we would end up with two parameters annotated TEXCOORD0, we would then run a pass on all adjacent TEXCOORD0 parameters and change them to properly number them. However, this couldn't detect the situation in my original snippet, where we have two 'TEXCOORD0' in a row that are not the expansion of a struct marked with that semantic. It incorrectly attempted to renumber b in a way that ended up crashing.

The solution is to change the strategy: when expanding a struct marked with a semantic, only the first field is now emitted with that same semantic, and all subsequent ones get assigned a dummy semantic ''. Once the parameter expansion completes, we do a pass and renumber all '' semantics based on their preceding legit semantic. Since '*' is not a valid semantic, we can't get confused with other fields having the same semantic.

I also added a warning for this case:

struct Input { float a : NORMAL0; };
float main(Input input : TEXCOORD0) : SV_Target { return 1; }

Fixes #1771
Fixes #1774

unsigned semGroupEnd = i + 1;
while (semGroupEnd < endArgIndex &&
FlatAnnotationList[semGroupEnd].GetSemanticString() == ContinuedPseudoSemantic) {
FlatAnnotationList[semGroupEnd].SetSemanticString(baseSemName);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This line is where I fix the '*' back to the proper semantic name (only the base name, the rest of the function handles the indices)

return V;
}

struct AnnotatedValue {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This supersedes the previous annotationMap in a cleaner way. It's helped me catch some bugs, too.

// TODO: warning for override the semantic in EltAnnotation.
// It doesn't look like we can provide source location information from here
F->getContext().emitWarning(
Twine("semantic '") + eltSem + "' on field overridden by function or enclosing type");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New warning.

@hekota Helena Kotas (hekota) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@AppVeyorBot

Copy link
Copy Markdown

✅ Build DirectXShaderCompiler 1.0.1114 completed (commit bfb1a02712 by @MrTrillian)

@tristanlabelle
Tristan Labelle (tristanlabelle) merged commit ed74e58 into microsoft:master Dec 19, 2018
@tristanlabelle
Tristan Labelle (tristanlabelle) deleted the semantics-sroa-improvements branch December 19, 2018 18:16
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.

DXC allows and ignores nested semantics Crash with duplicate semantics on struct fields

3 participants