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

Constant unsigned integer expressions in HLSL unsupported #3089

Closed
TheJackiMonster opened this issue Dec 12, 2022 · 1 comment
Closed

Constant unsigned integer expressions in HLSL unsupported #3089

TheJackiMonster opened this issue Dec 12, 2022 · 1 comment

Comments

@TheJackiMonster
Copy link

I was trying to compile the shadow denoiser shaders from here with Glslang but I ran into an issue:

[ERROR]: Shader parsing failed {
ERROR: /tmp/vkcv_tmp_VlNB6M/ffx_denoiser_shadows_tileclassification.h:293: ':' : Expected 
ERROR: /tmp/vkcv_tmp_VlNB6M/ffx_denoiser_shadows_tileclassification.h:293: 'initializer' : Expected 
ERROR: /tmp/vkcv_tmp_VlNB6M/ffx_denoiser_shadows_tileclassification.h:293: 'b10u' : unknown variable 
ERROR: /tmp/vkcv_tmp_VlNB6M/ffx_denoiser_shadows_tileclassification.h:293: ';' : Expected 
ERROR: /tmp/vkcv_tmp_VlNB6M/ffx_denoiser_shadows_tileclassification.h:293: 'then statement' : Expected 
ERROR: /tmp/vkcv_tmp_VlNB6M/ffx_denoiser_shadows_tileclassification.h:293: 'declaration' : Expected 
/tmp/vkcv_tmp_VlNB6M/ffx_denoiser_shadows_tileclassification.h(293): error at column 47, HLSL parsing failed.
ERROR: 7 compilation errors.  No code generated.

For context: I compile shaders in a temporary directory to handle include paths without the need of shipping the shaders in local directories as permanent files.

Anyway the causing problem is that these HLSL shaders utilize constant expression for their bitmasks like this:

#define TILE_META_DATA_CLEAR_MASK 0b01u
#define TILE_META_DATA_LIGHT_MASK 0b10u

These constant expressions seem not be handled properly though. Because the parser tells me, it wouldn't expect such an expression or it tries to parse it as a variable which it can't find. I'm usually not working with HLSL. So I'm not sure whether these expressions are in spec or not. But I assume it should be interpreted as binary values (0b01u -> 1) and (0b10u -> 2).

@greg-lunarg
Copy link
Contributor

Yes, you have found an issue. The following is correctly compiled by dxc but glslang gives errors as above:

float4 MainPs(void) : SV_Target0
{
float4 vTest = float4(0.0,0.0,0.0,0.0);
uint u = vTest.x > 0.0 ? 0b010101u : 0u;

  return vTest;

}

FWIW, the 0b syntax seems to be accepted as an initializer by glslang, but is not correctly generating the right value to store into u. The following compiles with compiler error, but does not generate the correct value for the 0b constant:

float4 MainPs(void) : SV_Target0
{
float4 vTest = float4(0.0,0.0,0.0,0.0);
uint u = 0b010101u;

  return vTest;

}

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

No branches or pull requests

2 participants