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

Using legacy VFACE semantic does not work but compiler error is not printed (affects both DXIL and SPIR-V backends) #3494

Closed
Dredhog opened this issue Feb 23, 2021 · 4 comments

Comments

@Dredhog
Copy link

Dredhog commented Feb 23, 2021

Title

Using legacy VFACE semantic does not work but compiler error is not printed (affects both DXIL and SPIR-V backends)

Functional impact

When porting FXC shaders which use VFACE (which has modern equivalent SV_IsFrontFace) DXC does not warn that these shaders will not work as they did with FXC. With D3D12 a shader which uses VFACE crashes in the driver during graphics pipeline creation (i.e. call to CreateGraphicsPipelineState fails). On Vulkan with the SPIR-V backend the argument decorated with VFACE appears to be zero at runtime (it should be either negative or positive) so it does not work as well.

Minimal repro steps

  1. Compile the following shader with dxc.exe -T ps_6_0 -E PSMain shader.txt:
float4 PSMain(float4 color : COLOR, float vface : VFACE) : SV_TARGET
{
	return (vface > 0) ? color : (color*2);
}

Expected result

DXC compilation fails and a descriptive error message about the legacy VFACE semantic no longer being supported is printed.

Actual result

Compilation succeeds but the VFACE semantic does not work with either D3D12 or Vulkan (as detailed in the functional impact section)

Further technical details

N.B. Optionally DXC could add a compiler flag which would emulateVFACE with SV_IsFrontFace as it contains the same information. The fact that the VFACE argument is of float type can be worked around by creating a temporary float which is positive when SV_IsFrontFace is true and negative when SV_IsFrontFace is false. The SPIR-V backend can do the same but by emulating VFACE with gl_FrontFacing.

@jaebaek
Copy link
Collaborator

jaebaek commented Feb 24, 2021

@Dredhog Thank you for reporting this issue. I will check the SPIR-V backend.

jaebaek added a commit to jaebaek/DirectXShaderCompiler that referenced this issue Mar 25, 2021
VFACE is not obsolete. See microsoft#3494.
jaebaek added a commit that referenced this issue Mar 31, 2021
@pow2clk
Copy link
Member

pow2clk commented Apr 6, 2021

@jaebaek I think we can close this?

To give a bit of background, arbitrary semantics are allowed. As such, we can't reject this semantic just because it used to be a builtin semantic. Instead, Jaebaek added a warning that this may not be doing what you're expecting.

@tex3d
Copy link
Contributor

tex3d commented Apr 6, 2021

Yes, fxc allows VFACE and interprets it as an arbitrary semantic unless using -Gec. With -Gec, it emulates it with SV_IsFrontFace. So the real bug is that we should emulate it when using -Gec. Note also that fxc dropped support for -Gec on SM 5.1.

@jaebaek
Copy link
Collaborator

jaebaek commented Apr 20, 2021

Sorry for this late reply. Yes. Let me close it.

@jaebaek jaebaek closed this as completed Apr 20, 2021
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

No branches or pull requests

4 participants