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

[SPIR-V] HLSL round intrinsic is translated to "Round" instead of to "RoundEven" which is incorrect based on the HLSL docs (works with the DXIL backend and FXC) #4368

Closed
Dredhog opened this issue Mar 31, 2022 · 1 comment · Fixed by #4515
Labels
spirv Work related to SPIR-V

Comments

@Dredhog
Copy link

Dredhog commented Mar 31, 2022

Title

[SPIR-V] HLSL round intrinsic is translated to "Round" instead of to "RoundEven" which is incorrect based on the HLSL docs (works with the DXIL backend and FXC)

Functional impact

Functional parity when using the HLSL round intrinsic is lost between the DXIL and SPIR-V backends for floating-point arguments exactly in between integers.

Based on the HLSL docs for round: Halfway cases are rounded to the nearest even.
and indeed FXC and the DXIL backend generate round_ne (which means "round to nearest even")

Minimal repro steps

  1. Compile the following shader with dxc.exe -T ps_6_0 -E PSMain -spirv repro_shader.txt:
float4 PSMain(float4 color : COLOR) : SV_TARGET
{
	return round(color);
}

Expected result

The generated SPIR-V should use the RoundEven instruction from the GLSL.std.450 extended instruction set

Actual result

The generated SPIR-V generates the following instructions:

 %1 = OpExtInstImport "GLSL.std.450"
...
%13 = OpExtInst %v4float %1 Round %12

Further technical details

Used DXC binary from the latest official release v1.6.2112

@jaebaek jaebaek added the spirv Work related to SPIR-V label Apr 4, 2022
sudonatalie added a commit to sudonatalie/DirectXShaderCompiler that referenced this issue Jun 16, 2022
The specification for the HLSL round intrinsic function states "Rounds
the specified value to the nearest integer. Halfway cases are rounded to
the nearest even.", so translate it to RoundEven SPIR-V extended
instruction rather than Round.

Fixes microsoft#4368
@sudonatalie
Copy link
Collaborator

Thanks for identifying this issue @Dredhog ! A fix is currently in review.

sudonatalie added a commit that referenced this issue Jun 16, 2022
The specification for the HLSL round intrinsic function states "Rounds
the specified value to the nearest integer. Halfway cases are rounded to
the nearest even.", so translate it to RoundEven SPIR-V extended
instruction rather than Round.

Fixes #4368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spirv Work related to SPIR-V
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants