Skip to content

Commit

Permalink
Add a proposal on how to handle the loop unroll factor in HLSL 202x (#…
Browse files Browse the repository at this point in the history
…276)

* Add a proposal on how to handle the loop unroll factor in HLSL 202x

* update proposal
  • Loading branch information
farzonl authored Aug 30, 2024
1 parent af243b0 commit 41feb45
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions proposals/0020-hlsl-202x-202y.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ DXC and it is expected to cause potential disruption.
Existing proposals that fall into this category are:
* [Numeric Constants](/proposals/0003-numeric-constants.md)
* [Conforming Literals](/proposals/0017-conforming-literals.md)
* [Loop Unroll Factor](/proposals/0022-hlsl-loop-unroll-factor.md)

HLSL 202x will not include features for all differences between DXC and Clang.
Some of the
Expand Down
40 changes: 40 additions & 0 deletions proposals/0022-hlsl-loop-unroll-factor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# HLSL Loop Unroll Factor

* Proposal: [0022](0022-hlsl-loop-unroll-factor.md)
* Author(s): [Farzon Lotfi](https://github.com/farzonl)
* Sponsor: [Farzon Lotfi](https://github.com/farzonl)
* Status: **Accepted**
* Impacted Projects: DXC & Clang

## Introduction

This proposal seeks to unify the diverging behaviors between the agreed upon
[spec for HLSL loop unroll](https://github.com/microsoft/hlsl-specs/pull/263)
and the current behavior of DXC.

The new spec wants to treat the unroll factor as a hint to the compiler for
partial loop unroll. The current behavior in dxc is that the unroll factor
specifies the maximum number of times the loop is to execute.

The DXC behavior was determined to violate user expectations by overriding
the existing loop termination conditions. Further the DXC behavior diverges
from how both clang and openCL treat the loop unroll factor which would have
made our port of HLSL loop unroll a bunch special cases instead of just
syntactic sugar that could sit on top of the existing loop unroll
implementations that exist in LLVM.

## Motivation
The HLSL compilers transition to clang has resulted in a compat break between
the [HLSL loop unroll implementation in clang](https://github.com/llvm/llvm-project/pull/93879)
and the one in DXC. While there is an expectation that the new compiler will
not be fully compatible with the previous compilers, These compat breaks should
be minimized when possible.

## Proposed solution
In [HLSL 202X](0020-hlsl-202x-202y.md) the DXC implementation of the loop
unroll factor should no longer alter the number of iteration executions.
Ideally the loop unroll factor will also become a compiler hint for partial
loop unroll. If this can not be done because of concerns of invalid DXIL
generation then the loop unroll factor as a feature should be removed from DXC.
Removal in this case means ignoring the unroll factor and issuing a warning to
inform the user.

0 comments on commit 41feb45

Please sign in to comment.