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

Interpolation modifier being recognized as keyword #98

Open
Xottab-DUTY opened this issue Dec 11, 2020 · 3 comments
Open

Interpolation modifier being recognized as keyword #98

Xottab-DUTY opened this issue Dec 11, 2020 · 3 comments
Labels

Comments

@Xottab-DUTY
Copy link

Cannot use certain words when naming a function or variable.

XSC fails, allowed in FXC.

Example shader:

//////////////////////////////////////////////////////////////////////////////////////////
// Pixel

float sample(float2 tc)
{
	return 0.f;
}

float4 main() : SV_Target
{
	float sample = 0; // if we comment out the 'sample' function, XSC will fail on this variable..
	return	0;
}

Error log:

syntax error (test.ps:4:7) : unexpected token: interpolation modifier (expected identifier)
float sample(float2 tc)
      ^~~~~~
@LukasBanana
Copy link
Owner

I'm not sure anymore how XSC treats the sample keyword but since it's already used as an interpolation modifier, I suggest to avoid using this name for both functions and variables. HLSL has a weird case where sample float sample : Sample is a valid declaration but sample float sample : sample confuses DXC while FXC accepts it. This is one of many examples in which HLSL lacks a clear definition.

@Xottab-DUTY
Copy link
Author

i suggest to avoid using this name for both functions and variables.

Unfortunately, it is not possible, we need to compile unmodified shaders. 🙁
It seems we will need to patch some existing cross-compiler or to write our own. 🙃

HLSL has a weird case where sample float sample : Sample is a valid declaration but sample float sample : sample confuses DXC while FXC accepts it. This is one of many examples in which HLSL lacks a clear definition.

Interesting case... Thank you 😃

@LukasBanana
Copy link
Owner

Unfortunately, it is not possible, we need to compile unmodified shaders.

In that case, I suggest to add another token type like InterpModifierOrIdent alongside InterpModifier just for the keyword sample and handle it at places like this one.

I see you already considered ShaderConductor/DXC for your purpose. I would recommend that compiler toolchain as its more advanced and has a strong support from Microsoft and Google. Only downside is that it's a much larger code base and not a small single library project, i.e. it takes some effort to integrate it into a graphics pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants