From 41feb45ff02777102e762b7ab3345b5c634811d5 Mon Sep 17 00:00:00 2001 From: Farzon Lotfi <1802579+farzonl@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:53:59 -0400 Subject: [PATCH] Add a proposal on how to handle the loop unroll factor in HLSL 202x (#276) * Add a proposal on how to handle the loop unroll factor in HLSL 202x * update proposal --- proposals/0020-hlsl-202x-202y.md | 1 + proposals/0022-hlsl-loop-unroll-factor.md | 40 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 proposals/0022-hlsl-loop-unroll-factor.md diff --git a/proposals/0020-hlsl-202x-202y.md b/proposals/0020-hlsl-202x-202y.md index 646d8c47..999a6c07 100644 --- a/proposals/0020-hlsl-202x-202y.md +++ b/proposals/0020-hlsl-202x-202y.md @@ -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 diff --git a/proposals/0022-hlsl-loop-unroll-factor.md b/proposals/0022-hlsl-loop-unroll-factor.md new file mode 100644 index 00000000..2c3b9e11 --- /dev/null +++ b/proposals/0022-hlsl-loop-unroll-factor.md @@ -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. \ No newline at end of file