thanpv-lifortevn / angleproject

Automatically exported from code.google.com/p/angleproject
Other
0 stars 0 forks source link

Implement support for assigning arrays in the HLSL output #960

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The ESSL3 compiler needs to support assigning arrays. This is fairly complex, 
since HLSL doesn't have support for assigning arrays or arrays as function 
return values. Array assignments need to be replaced with function calls where 
the target array is an out parameter. So:

float a[3];
float b[3];
a = b;

becomes

float a[3];
float b[3];
angle_assign_3_float(a, b);

This gets complex when the return value of the assignment gets used. Take the 
following source for example:

float a[3];
float b[3];
float c[3];
bool d = foo && (c == (a = b));

This needs to become something like:

float a[3];
float b[3];
bool s0;
{
  s0 = foo;
  if (s0) {
    angle_assign_3_float(a, b);
    s0 = angle_eq_3_float(c, a);
  }
}
bool d = s0;

This means that handling array assignment needs to work together with unfolding 
short circuiting operators. The cleanest way to implement this would probably 
be:

1. Reimplement unfolding short circuiting operators as an AST mutation, remove 
the current UnfoldShortCircuit code from OutputHLSL.
2. Implement removing usage of array assignment return values as an AST 
mutation and run that after short circuiting operators have been unfolded.

Alternatives are:
B) To disallow referencing return values of array assignment.
C) To integrate array assignment tightly with the current short circuiting 
operator unfolding, which would probably result in an unmaintainable mess.

Original issue reported on code.google.com by oetu...@nvidia.com on 30 Mar 2015 at 1:57

GoogleCodeExporter commented 9 years ago

Original comment by oetu...@nvidia.com on 30 Mar 2015 at 1:58

GoogleCodeExporter commented 9 years ago
Another complex type of case is:

float a[3];
float b[3];
float c[3];
bool d = (a = b) == (a = c);

In this case, at least one temporary variable is needed to store one of the 
results of the assignment. For simplicity, it might be the best to always use 
temporary variables for storing results of assignment, so that the above code 
would become:

float a[3];
float b[3];
float c[3];
float a0[3];
angle_assign_3_float(a0, b);
float a1[3];
angle_assign_3_float(a1, c);
bool d = angle_eq_3_float(a0, a1);
angle_assign_3_float(a, a0);
angle_assign_3_float(a, a1);

Original comment by oetu...@nvidia.com on 30 Mar 2015 at 2:25

GoogleCodeExporter commented 9 years ago
Project: angle/angle
Branch : master
Author : Olli Etuaho <oetuaho@nvidia.com>
Commit : 1269076cbfe23a1a87487eca8315e5786de01f66

Code-Review  0 : Nicolas Capens, Olli Etuaho
Code-Review  +1: Jamie Madill
Code-Review  +2: Geoff Lang
Verified     0 : Geoff Lang, Jamie Madill, Nicolas Capens
Verified     +1: Olli Etuaho
Commit Queue   : Chumped
Change-Id      : Ibf9d71a75d27d139d2aabb5162ab04a0974321d3
Reviewed-at    : https://chromium-review.googlesource.com/263222

Add basic support for assigning arrays in HLSL output

Implement support for assignments where the return value of the assignment
is not used in another part of the expression.

TEST=WebGL conformance tests
BUG=angleproject:960

src/compiler/translator/OutputHLSL.cpp
src/compiler/translator/OutputHLSL.h

Original comment by bugdro...@chromium.org on 2 Apr 2015 at 4:47

GoogleCodeExporter commented 9 years ago
Project: angle/angle
Branch : master
Author : Olli Etuaho <oetuaho@nvidia.com>
Commit : b2d6a9be287f04a596871cabfa5d69ae6a390ba1

Code-Review  0 : Nicolas Capens, Olli Etuaho
Code-Review  +1: Jamie Madill
Code-Review  +2: Geoff Lang
Verified     0 : Geoff Lang, Jamie Madill, Nicolas Capens
Verified     +1: Olli Etuaho
Commit Queue   : Chumped
Change-Id      : I11353d7ed7160c853e58a0ef3471ca439cb314c8
Reviewed-at    : https://chromium-review.googlesource.com/263070

Stub simplifying array assignment for HLSL output

Add an AST traverser that rejects shaders with expressions that use the return
value of an assignment where an array is assigned to another array. In the
future this should be made into a tool that can simplify these expressions so
that return values of array assignments are not used.

In its current form this code prevents OutputHLSL from producing garbage code
when the original code contains expressions like a = (b = c); where a, b, and c
are all arrays.

BUG=angleproject:960

src/compiler.gypi
src/compiler/translator/SimplifyArrayAssignment.cpp
src/compiler/translator/SimplifyArrayAssignment.h
src/compiler/translator/TranslatorHLSL.cpp

Original comment by bugdro...@chromium.org on 2 Apr 2015 at 4:50