I'm implementing an algorithm called Fast3x3 SVD on my compute shader. However, while I was debugging my compute shader in RenderDoc, I noticed some assignment operators were completely getting skipped.
void SortSingularValues(inout float3x3 B, inout float3x3 V)
{
float rho1 = DistSquared(float3(B[0][0], B[1][0], B[2][0]));
float rho2 = DistSquared(float3(B[0][1], B[1][1], B[2][1]));
float rho3 = DistSquared(float3(B[0][2], B[1][2], B[2][2]));
bool c = rho1 < rho2;
float z = -B[0][0];
B[0][0] = c ? B[0][1]: B[0][0];
B[0][1] = c ? z : B[0][1];
z = -B[1][0];
B[1][0] = c ? B[1][1]: B[1][0];
B[1][1] = c ? z : B[1][1];
z = -B[2][0];
B[2][0] = c ? B[2][1] : B[2][0];
B[2][1] = c ? z : B[2][1];
z = -V[0][0];
V[0][0] = c ? V[0][1] : V[0][0];
V[0][1] = c ? z : V[0][1];
z = -V[1][0];
V[1][0] = c ? V[1][1] : V[1][0];
V[1][1] = c ? z : V[1][1];
z = -V[2][0];
V[2][0] = c ? V[2][1] : V[2][0];
V[2][1] = c ? z : V[2][1];
CondSwap(c, rho1, rho2);
c = rho1 < rho3;
z = -B[0][0];
B[0][0] = c ? B[0][2] : B[0][0];
B[0][2] = c ? z : B[0][2];
z = -B[1][0];
B[1][0] = c ? B[1][2] : B[1][0];
B[1][2] = c ? z : B[1][2];
z = -B[2][0];
B[2][0] = c ? B[2][2] : B[2][0];
B[2][2] = c ? z : B[2][2];
z = -V[0][0];
V[0][0] = c ? V[0][2] : V[0][0];
V[0][2] = c ? z : V[0][2];
z = -V[1][0];
V[1][0] = c ? V[1][2] : V[1][0];
V[1][2] = c ? z : V[1][2];
z = -V[2][0];
V[2][0] = c ? V[2][2] : V[2][0];
V[2][2] = c ? z : V[2][2];
CondSwap(c, rho1, rho3);
/*-----------This is where the skipping happens!-------------------*/
c = rho2 < rho3;
z = -B[0][1]; // <- Skipped
B[0][1] = c ? B[0][2] : B[0][1];
B[0][2] = c ? z : B[0][2]; // <- Skipped
z = -B[1][1]; // <- Skipped
B[1][1] = c ? B[1][2] : B[1][1];
B[1][2] = c ? z : B[1][2]; // <- Skipped
z = -B[2][1]; // <- Skipped
B[2][1] = c ? B[2][2] : B[2][1];
B[2][2] = c ? z : B[2][2]; // <- Skipped
//Everything else get hit from here...
z = -V[0][1];
V[0][1] = c ? V[0][2] : V[0][1];
V[0][2] = c ? z : V[0][2];
z = -V[1][1];
V[1][1] = c ? V[1][2] : V[1][1];
V[1][2] = c ? z : V[1][2];
z = -V[2][1];
V[2][1] = c ? V[2][2] : V[2][1];
V[2][2] = c ? z : V[2][2];
}
I call the function above as follows...
void FastSVD(in float3x3 A, out float3x3 U, out float3x3 S, out float3x3 V)
{
float3x3 At = GetTranspose(A);
float3x3 AtA = mul(At, A);
float4 qV;
qV.x = 0.0;
qV.y = 0.0;
qV.z = 0.0;
qV.w = 1.0;
JacobiEigenAnalysis(
AtA[0][0], AtA[1][0], AtA[1][1], AtA[2][0], AtA[2][1], AtA[2][2], qV
);
V = GetMat3x3FromQuat(qV);
float3x3 B = mul(A, V);
SortSingularValues(V, B);
QRDecomposition(B, U, S);
}
I even looked at the disassembly code for the corresponding skipped lines but they did not exist at the disassembly level. I'm so lost to why the shader compiler won't even generate disassembly code for those lines... And what's even confusing is that all the code works for the V matrix, but not the B matrix. Any leads in why this might be happening would be greatly appreciated!