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

GLSL/HLSL out pass through the modulus operator on integers #4398

Closed
kvark opened this issue Nov 7, 2022 · 1 comment
Closed

GLSL/HLSL out pass through the modulus operator on integers #4398

kvark opened this issue Nov 7, 2022 · 1 comment
Labels
area: naga back-end Outputs of naga shader conversion lang: GLSL OpenGL Shading Language lang: HLSL D3D Shading Language naga Shader Translator type: bug Something isn't working

Comments

@kvark
Copy link
Member

kvark commented Nov 7, 2022

"a % b" expression gets passed through form WGSL to GLSL, e.g.

@vertex
fn main() -> @builtin(position) vec4<f32> {
	let x: i32 = -4 % 5;
	return vec4<f32>(0.0);
}

Produces:

#version 310 es

precision highp float;
precision highp int;


void main() {
    int x = (-4 % 5);
    gl_Position = vec4(0.0);
    gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
    return;
}

Problem is - the semantics of "%" is different. In GLSL it's "x - y * floor(x/y)", while in WGSL it's meant to be "x - y * trunc(x/y)".

Edit: same for HLSL, with a little difference that this is UB:

The % operator is defined only in cases where either both sides are positive or both sides are negative.

@kvark kvark added kind: bug area: naga back-end Outputs of naga shader conversion lang: GLSL OpenGL Shading Language lang: HLSL D3D Shading Language labels Nov 7, 2022
@kvark kvark changed the title GLSL out passes through the modulus operator on integers GLSL/HLSL out pass through the modulus operator on integers Nov 7, 2022
@cwfitzgerald cwfitzgerald transferred this issue from gfx-rs/naga Oct 25, 2023
@cwfitzgerald cwfitzgerald added naga Shader Translator type: bug Something isn't working and removed kind: bug labels Oct 25, 2023
@teoxoy teoxoy added this to the WebGPU Specification V1 milestone Nov 3, 2023
@teoxoy
Copy link
Member

teoxoy commented Dec 14, 2023

This has been resolved by: c584331 (gfx-rs/naga#1867) & 943235c (gfx-rs/naga#1452).

@teoxoy teoxoy closed this as completed Dec 14, 2023
@teoxoy teoxoy removed this from the WebGPU Specification V1 milestone Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga back-end Outputs of naga shader conversion lang: GLSL OpenGL Shading Language lang: HLSL D3D Shading Language naga Shader Translator type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants