writer/hlsl: Emit for-loops where possible.

Use the new transforms to try and simplify loops into for-loops.
Emit loops when the initialiser, condition and continuing are simple enough to do so.

Bug: tint:952
Change-Id: I5b3c225b245ffa72996abf6a70f52a9cd25b748e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56772
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-07-02 22:17:25 +00:00
parent 9ad49e43c1
commit 0e41747281
27 changed files with 1163 additions and 657 deletions

View File

@@ -33,17 +33,11 @@ static bool2 v2b = bool2(false, false);
void foo() {
{
int i = 0;
while (true) {
if (!((i < 2))) {
break;
}
for(; !(!((i < 2))); i = (i + 1)) {
Set_float2(v2f, i, 1.0f);
Set_int3(v3i, i, 1);
Set_uint4(v4u, i, 1u);
Set_bool2(v2b, i, true);
{
i = (i + 1);
}
}
}
}
@@ -52,14 +46,8 @@ void foo() {
void main() {
{
int i = 0;
while (true) {
if (!((i < 2))) {
break;
}
for(; !(!((i < 2))); i = (i + 1)) {
foo();
{
i = (i + 1);
}
}
}
return;

View File

@@ -15,14 +15,8 @@ void foo() {
void main() {
{
int i = 0;
while (true) {
if (!((i < 2))) {
break;
}
for(; !(!((i < 2))); i = (i + 1)) {
foo();
{
i = (i + 1);
}
}
}
return;

View File

@@ -98,10 +98,7 @@ void main() {
bool4 v4b = bool4(false, false, false, false);
{
int i = 0;
while (true) {
if (!((i < 2))) {
break;
}
for(; !(!((i < 2))); i = (i + 1)) {
Set_float2(v2f, i, 1.0f);
Set_float3(v3f, i, 1.0f);
Set_float4(v4f, i, 1.0f);
@@ -114,9 +111,6 @@ void main() {
Set_bool2(v2b, i, true);
Set_bool3(v3b, i, true);
Set_bool4(v4b, i, true);
{
i = (i + 1);
}
}
}
return;

View File

@@ -37,10 +37,7 @@ void main() {
bool2 v2b_2 = bool2(false, false);
{
int i = 0;
while (true) {
if (!((i < 2))) {
break;
}
for(; !(!((i < 2))); i = (i + 1)) {
Set_float2(v2f, i, 1.0f);
Set_int3(v3i, i, 1);
Set_uint4(v4u, i, 1u);
@@ -49,9 +46,6 @@ void main() {
Set_int3(v3i_2, i, 1);
Set_uint4(v4u_2, i, 1u);
Set_bool2(v2b_2, i, true);
{
i = (i + 1);
}
}
}
return;

View File

@@ -38,17 +38,11 @@ void main() {
bool4 v4b = bool4(false, false, false, false);
{
int i = 0;
while (true) {
if (!((i < 2))) {
break;
}
for(; !(!((i < 2))); i = (i + 1)) {
Set_float2(v2f, i, 1.0f);
Set_int2(v2i, i, 1);
Set_uint2(v2u, i, 1u);
Set_bool2(v2b, i, true);
{
i = (i + 1);
}
}
}
int i = 0;