HLSL: force FXC to never unroll loops

Emit the "[loop]" attribute on "for" and "while" so that FXC does not
attempt to unroll them. This is to work around an FXC bug where it fails
to unroll loops with gradient operations.

FXC ostensibly unrolls such loops because gradient operations require
uniform control flow, and loops that have varying iterations may
possibly not be uniform. Tint will eventually validate that control flow
is indeed uniform, so forcing FXC to avoid unrolling in these cases
should be fine.

Bug: tint:1112
Change-Id: I10077f8b62fbbb230a0003f3864c75a8fe0e1d18
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69880
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano
2021-11-18 13:50:12 +00:00
committed by Tint LUCI CQ
parent 1704fe53f5
commit 11d09f2fe7
49 changed files with 117 additions and 110 deletions

View File

@@ -16,7 +16,7 @@ typedef int4 tint_symbol_11_ret[4];
tint_symbol_11_ret tint_symbol_11(ByteAddressBuffer buffer, uint offset) {
int4 arr_1[4] = (int4[4])0;
{
for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
[loop] for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
arr_1[i_1] = asint(buffer.Load4((offset + (i_1 * 16u))));
}
}

View File

@@ -18,7 +18,7 @@ void tint_symbol_9(RWByteAddressBuffer buffer, uint offset, float3x2 value) {
void tint_symbol_11(RWByteAddressBuffer buffer, uint offset, int4 value[4]) {
int4 array[4] = value;
{
for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
[loop] for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
buffer.Store4((offset + (i_1 * 16u)), asuint(array[i_1]));
}
}

View File

@@ -24,7 +24,7 @@ typedef tint_padded_array_element tint_symbol_10_ret[4];
tint_symbol_10_ret tint_symbol_10(ByteAddressBuffer buffer, uint offset) {
tint_padded_array_element arr[4] = (tint_padded_array_element[4])0;
{
for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
[loop] for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
arr[i_1].el = tint_symbol_9(buffer, (offset + (i_1 * 16u)));
}
}

View File

@@ -25,7 +25,7 @@ void tint_symbol_9(RWByteAddressBuffer buffer, uint offset, Inner value) {
void tint_symbol_10(RWByteAddressBuffer buffer, uint offset, tint_padded_array_element value[4]) {
tint_padded_array_element array[4] = value;
{
for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
[loop] for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
tint_symbol_9(buffer, (offset + (i_1 * 16u)), array[i_1].el);
}
}

View File

@@ -26,7 +26,7 @@ typedef int4 tint_symbol_12_ret[4];
tint_symbol_12_ret tint_symbol_12(uint4 buffer[96], uint offset) {
int4 arr_1[4] = (int4[4])0;
{
for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
[loop] for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
const uint scalar_offset_5 = ((offset + (i_1 * 16u))) / 4;
arr_1[i_1] = asint(buffer[scalar_offset_5 / 4]);
}

View File

@@ -35,7 +35,7 @@ typedef tint_padded_array_element tint_symbol_11_ret[4];
tint_symbol_11_ret tint_symbol_11(uint4 buffer[13], uint offset) {
tint_padded_array_element arr[4] = (tint_padded_array_element[4])0;
{
for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
[loop] for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) {
arr[i_1].el = tint_symbol_10(buffer, (offset + (i_1 * 16u)));
}
}