[GPU] Fix casting on shader, support reading gl_Position.w on fragment shader
This commit is contained in:
parent
0c9a88cce7
commit
a8076aaa2f
5 changed files with 55 additions and 20 deletions
|
@ -244,12 +244,16 @@ namespace Ryujinx.Core.OsHle.Services.Android
|
|||
{
|
||||
int Slot = ParcelReader.ReadInt32();
|
||||
|
||||
int BufferCount = ParcelReader.ReadInt32();
|
||||
long BufferSize = ParcelReader.ReadInt64();
|
||||
int BufferCount = ParcelReader.ReadInt32();
|
||||
|
||||
BufferQueue[Slot].State = BufferState.Free;
|
||||
if (BufferCount > 0)
|
||||
{
|
||||
long BufferSize = ParcelReader.ReadInt64();
|
||||
|
||||
BufferQueue[Slot].Data = new GbpBuffer(ParcelReader);
|
||||
BufferQueue[Slot].State = BufferState.Free;
|
||||
|
||||
BufferQueue[Slot].Data = new GbpBuffer(ParcelReader);
|
||||
}
|
||||
|
||||
return MakeReplyParcel(Context, 0);
|
||||
}
|
||||
|
@ -429,7 +433,7 @@ namespace Ryujinx.Core.OsHle.Services.Android
|
|||
break;
|
||||
}
|
||||
|
||||
Logging.Debug("Waiting for a free BufferQueue slot...");
|
||||
Logging.Info("Waiting for a free BufferQueue slot...");
|
||||
|
||||
if (!KeepRunning)
|
||||
{
|
||||
|
@ -443,7 +447,7 @@ namespace Ryujinx.Core.OsHle.Services.Android
|
|||
}
|
||||
while (KeepRunning);
|
||||
|
||||
Logging.Debug($"Found free BufferQueue slot {Slot}!");
|
||||
Logging.Info($"Found free BufferQueue slot {Slot}!");
|
||||
|
||||
return Slot;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
class GlslDecl
|
||||
{
|
||||
public const int VertexIdAttr = 0x2fc;
|
||||
public const int VertexIdAttr = 0x2fc;
|
||||
public const int GlPositionWAttr = 0x7c;
|
||||
|
||||
private const int AttrStartIndex = 8;
|
||||
private const int TexStartIndex = 8;
|
||||
|
|
|
@ -302,8 +302,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
throw new NotImplementedException(Op.Inst.ToString());
|
||||
}
|
||||
|
||||
if (!Entry && (Op.OperandB != null ||
|
||||
Op.OperandC != null))
|
||||
if (!Entry && NeedsParentheses(Op))
|
||||
{
|
||||
Expr = "(" + Expr + ")";
|
||||
}
|
||||
|
@ -314,6 +313,25 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
}
|
||||
}
|
||||
|
||||
private static bool NeedsParentheses(ShaderIrOp Op)
|
||||
{
|
||||
switch (Op.Inst)
|
||||
{
|
||||
case ShaderIrInst.Frcp:
|
||||
return true;
|
||||
|
||||
case ShaderIrInst.Ipa:
|
||||
case ShaderIrInst.Texr:
|
||||
case ShaderIrInst.Texg:
|
||||
case ShaderIrInst.Texb:
|
||||
case ShaderIrInst.Texa:
|
||||
return false;
|
||||
}
|
||||
|
||||
return Op.OperandB != null ||
|
||||
Op.OperandC != null;
|
||||
}
|
||||
|
||||
private string GetName(ShaderIrOperCbuf Cbuf)
|
||||
{
|
||||
if (!Decl.Uniforms.TryGetValue((Cbuf.Index, Cbuf.Offs), out ShaderDeclInfo DeclInfo))
|
||||
|
@ -331,16 +349,21 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
private string GetName(ShaderIrOperAbuf Abuf)
|
||||
{
|
||||
return GetName(Decl.InAttributes, Abuf);
|
||||
}
|
||||
if (Abuf.Offs == GlslDecl.GlPositionWAttr && Decl.ShaderType == GalShaderType.Fragment)
|
||||
{
|
||||
return "(1f / gl_FragCoord.w)";
|
||||
}
|
||||
|
||||
private string GetName(IReadOnlyDictionary<int, ShaderDeclInfo> Dict, ShaderIrOperAbuf Abuf)
|
||||
{
|
||||
if (Abuf.Offs == GlslDecl.VertexIdAttr)
|
||||
{
|
||||
return "gl_VertexID";
|
||||
}
|
||||
|
||||
return GetName(Decl.InAttributes, Abuf);
|
||||
}
|
||||
|
||||
private string GetName(IReadOnlyDictionary<int, ShaderDeclInfo> Dict, ShaderIrOperAbuf Abuf)
|
||||
{
|
||||
int Index = Abuf.Offs >> 4;
|
||||
int Elem = (Abuf.Offs >> 2) & 3;
|
||||
|
||||
|
@ -439,7 +462,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
private string GetFnegExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "-");
|
||||
|
||||
private string GetFrcpExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "1 / ");
|
||||
private string GetFrcpExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "1f / ");
|
||||
|
||||
private string GetFrsqExpr(ShaderIrOp Op) => GetUnaryCall(Op, "inversesqrt");
|
||||
|
||||
|
@ -451,16 +474,23 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
private string GetLsrExpr(ShaderIrOp Op)
|
||||
{
|
||||
return "(int)((uint)" + GetOperExpr(Op, Op.OperandA) + " >> " +
|
||||
GetOperExpr(Op, Op.OperandB) + ")";
|
||||
return "int(uint(" + GetOperExpr(Op, Op.OperandA) + ") >> " +
|
||||
GetOperExpr(Op, Op.OperandB) + ")";
|
||||
}
|
||||
|
||||
private string GetNotExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "~");
|
||||
|
||||
private string GetOrExpr(ShaderIrOp Op) => GetBinaryExpr(Op, "|");
|
||||
|
||||
private string GetStofExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "(float)");
|
||||
private string GetUtofExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "(float)(uint)");
|
||||
private string GetStofExpr(ShaderIrOp Op)
|
||||
{
|
||||
return "float(" + GetOperExpr(Op, Op.OperandA) + ")";
|
||||
}
|
||||
|
||||
private string GetUtofExpr(ShaderIrOp Op)
|
||||
{
|
||||
return "float(uint(" + GetOperExpr(Op, Op.OperandA) + "))";
|
||||
}
|
||||
|
||||
private string GetXorExpr(ShaderIrOp Op) => GetBinaryExpr(Op, "^");
|
||||
|
||||
|
|
|
@ -63,8 +63,6 @@ namespace Ryujinx.Graphics.Gpu
|
|||
}
|
||||
}
|
||||
|
||||
private const long GoodFbAddress = 0x1615b2a00;
|
||||
|
||||
private void VertexEndGl(AMemory Memory, NsGpuPBEntry PBEntry)
|
||||
{
|
||||
SetFrameBuffer(0);
|
||||
|
|
|
@ -12,6 +12,8 @@ namespace Ryujinx
|
|||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
//Ryujinx.Graphics.Gal.Shader.ShaderTest.PrintGlslProgram(File.ReadAllBytes("D:\\shbh_000000000048ba30.bin"));
|
||||
|
||||
Config.Read();
|
||||
|
||||
AOptimizations.DisableMemoryChecks = !Config.EnableMemoryChecks;
|
||||
|
|
Loading…
Add table
Reference in a new issue