Skip to content

[SPIR-V] Fix invalid isnan codegen - #6754

Merged
Steven Perron (s-perron) merged 1 commit into
microsoft:mainfrom
Keenuts:fix-6712
Jul 19, 2024
Merged

Steven Perron (s-perron) merged 1 commit into
microsoft:mainfrom
Keenuts:fix-6712

Conversation

@Keenuts

Copy link
Copy Markdown
Collaborator

IsNan returns a boolean, even is the input-type is a float. This was working in most cases except:

  • if the layout was not Void
  • if the input type was not a matrix

The first bug is because a bool memory layout/representation is not specified, and shall never be exposed to externaly-accessible memory. Hence, if we saw a layout rule != Void, we converted it to a UINT. When calling isnan, the layout rule should not be propagated as we loose any layout info.

The second is because our codegen assumed matrix operations returned a matrix with the same type as the input parameters. In the case of isnan, this was just wrong.

Fixes #6712

IsNan returns a boolean, even is the input-type is a float.
This was working in most cases except:
 - if the layout was not Void
 - if the input type was not a matrix

The first bug is because a bool memory layout/representation is not
specified, and shall never be exposed to externaly-accessible memory.
Hence, if we saw a layout rule != Void, we converted it to a UINT.
When calling isnan, the layout rule should not be propagated as we loose
any layout info.

The second is because our codegen assumed matrix operations returned a
matrix with the same type as the input parameters. In the case of isnan,
this was just wrong.

Fixes microsoft#6712

Signed-off-by: Nathan Gauër <[email protected]>

@s-perron Steven Perron (s-perron) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. We will need to follow up with other similar bugs.

Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
@Keenuts

Copy link
Copy Markdown
Collaborator Author

Cassandra Beckley (@cassiebeckley) in case you missed it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@s-perron
Steven Perron (s-perron) merged commit 1028410 into microsoft:main Jul 19, 2024
Mxr (SjMxr233) pushed a commit to ShaderHelper/DirectXShaderCompiler that referenced this pull request Jul 24, 2025
IsNan returns a boolean, even is the input-type is a float. This was
working in most cases except:
 - if the layout was not Void
 - if the input type was not a matrix

The first bug is because a bool memory layout/representation is not
specified, and shall never be exposed to externaly-accessible memory.
Hence, if we saw a layout rule != Void, we converted it to a UINT. When
calling isnan, the layout rule should not be propagated as we loose any
layout info.

The second is because our codegen assumed matrix operations returned a
matrix with the same type as the input parameters. In the case of isnan,
this was just wrong.

Fixes microsoft#6712

Signed-off-by: Nathan Gauër <[email protected]>
@Keenuts
Nathan Gauër (Keenuts) deleted the fix-6712 branch September 9, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[SPIR-V] Invalid SPIR-V operand with isnan()

3 participants