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

#include file pathnames are being processed for escapes #2142

Open
Xottab-DUTY opened this issue Mar 20, 2020 · 8 comments
Open

#include file pathnames are being processed for escapes #2142

Xottab-DUTY opened this issue Mar 20, 2020 · 8 comments
Labels

Comments

@Xottab-DUTY
Copy link
Contributor

Problematic code:

HLSL shader with this:

#include "shared\common.h"

Expected behaviour

Successful preprocessing and compilation.

Current behaviour:

Preprocessing errors:

ERROR: common.h:4: 'string' : Invalid escape sequence 
ERROR: common.h:4: 'string' : End of line in string 

glslang version

Built from commit 3bf1dab

Misc

Seems to be related with #2108.

@Xottab-DUTY
Copy link
Contributor Author

Xottab-DUTY commented Mar 20, 2020

int TPpContext::CPPinclude(TPpToken* ppToken) correctly uses scanHeaderName to scan includes and this function is fine.

The problem is in TokenizableIncludeFile class, which still uses generic scan function from tStringInput class.

@Xottab-DUTY
Copy link
Contributor Author

Xottab-DUTY commented Mar 20, 2020

A quick fix is just setting disableEscapeSequences to true in the TokenizableIncludeFile::scan function:

int scan(TPpToken* t) override
{
	pp->disableEscapeSequences = true;
	const int result = stringInput.scan(t);
	pp->disableEscapeSequences = false;
	return result;
}

But I'm not sure if it's suitable, but should be good, since it used it 1344454 too.

@johnkslang
Copy link
Member

What method are you using to get this error?

When I try compiling an HLSL shader with a backslash in a header name, it works.

@Xottab-DUTY
Copy link
Contributor Author

Xottab-DUTY commented Apr 7, 2020

I'm using this:
OpenXRay/xray-16@868c4e5#diff-cc81b7b644fee5f6c5342a78c387ba9dR635

Interesting fact: when I use shaderc to compile the same shader, it compiles it successfully.
If it would be helpful, the code for shaderc:
OpenXRay/xray-16@aa78550#diff-cc81b7b644fee5f6c5342a78c387ba9dR639
P.S. the glslang branch is much more WIP than shaderc branch, because I didn't managed to compile the shader with glslang.
Will post a problematic shader in a separate post, which I will delete.

@johnkslang
Copy link
Member

I grabbed it.

@johnkslang
Copy link
Member

Note that #include is a special case where first shaderc just put hooks in glslang, such that shaderc could implement #include without glslang actually having the functionality. But, glslang needed it anyway, so now there are two implementations of it, and this was destabilized by printf adding escape sequences.

@johnkslang
Copy link
Member

Using the set of files you previously posted and the latest glslang, it successfully compiles the #include "shared\common.h", so I'm not sure what the actual issue is.

I used the command line glslangValidator.exe -D -e main -V -S frag dumb.ps.

@Xottab-DUTY
Copy link
Contributor Author

Xottab-DUTY commented Apr 21, 2020

and this was destabilized by printf adding escape sequences.

So, the log wasn't telling the truth about why it really fails?

While debugging it, I've found a way to fix the first message about escape sequences with the quick fix I provided above.
Then, I've found that it fails on parsing almost every HLSL type, so, probably that quick fix broke something.. But I just want to highlight this: it fails when I compile vertex shader that uses technique and that's reasonable.. But I've found (after applying that quick fix) that it also fails on techniques when I compile that pixel shader. (but they are unused in it)

// common.h, in the end of file:
#define FXPS technique _render{pass _code{PixelShader=compile ps_3_0 main();}}
#define FXVS technique _render{pass _code{VertexShader=compile vs_3_0 main();}}

techniques are not supported and probably they are the reason of failure?
But this becomes strange, when standard glslangValidator and custom compiled shaderc both compile the pixel shader successfully, but custom compiled glslang doesn't.

P.S. I can't modify shaders (including removal of that defines) 🙂

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