Index constant buffer vec4s using ternary expressions.
This commit is contained in:
parent
9a208c4fb5
commit
0663d29795
1 changed files with 19 additions and 2 deletions
|
@ -114,6 +114,24 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
return ubName + "." + GetSwizzleMask(offset & 3);
|
return ubName + "." + GetSwizzleMask(offset & 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetVec4Indexed(string vectorName, string indexExpr)
|
||||||
|
{
|
||||||
|
bool canIndexVec4 = false;
|
||||||
|
if (canIndexVec4)
|
||||||
|
{
|
||||||
|
return $"{vectorName}[{indexExpr}]";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string result = $"{vectorName}.x";
|
||||||
|
for (int i = 1; i < 4; i++)
|
||||||
|
{
|
||||||
|
result = $"(({indexExpr}) == {i}) ? ({vectorName}.{GetSwizzleMask(i)}) : ({result})";
|
||||||
|
}
|
||||||
|
return $"({result})";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetConstantBufferName(IAstNode slot, string offsetExpr, ShaderStage stage)
|
public static string GetConstantBufferName(IAstNode slot, string offsetExpr, ShaderStage stage)
|
||||||
{
|
{
|
||||||
// Non-constant slots are not supported.
|
// Non-constant slots are not supported.
|
||||||
|
@ -124,9 +142,8 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
string ubName = GetUbName(stage, operand.Value);
|
string ubName = GetUbName(stage, operand.Value);
|
||||||
|
|
||||||
string index0 = "[" + offsetExpr + " >> 2]";
|
string index0 = "[" + offsetExpr + " >> 2]";
|
||||||
string index1 = "[" + offsetExpr + " & 3]";
|
|
||||||
|
|
||||||
return ubName + index0 + index1;
|
return GetVec4Indexed(ubName + index0, offsetExpr + " & 3");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetOutAttributeName(AstOperand attr, ShaderStage stage)
|
public static string GetOutAttributeName(AstOperand attr, ShaderStage stage)
|
||||||
|
|
Loading…
Reference in a new issue