[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
|
@ -245,11 +245,15 @@ namespace Ryujinx.Core.OsHle.Services.Android
|
||||||
int Slot = ParcelReader.ReadInt32();
|
int Slot = ParcelReader.ReadInt32();
|
||||||
|
|
||||||
int BufferCount = ParcelReader.ReadInt32();
|
int BufferCount = ParcelReader.ReadInt32();
|
||||||
|
|
||||||
|
if (BufferCount > 0)
|
||||||
|
{
|
||||||
long BufferSize = ParcelReader.ReadInt64();
|
long BufferSize = ParcelReader.ReadInt64();
|
||||||
|
|
||||||
BufferQueue[Slot].State = BufferState.Free;
|
BufferQueue[Slot].State = BufferState.Free;
|
||||||
|
|
||||||
BufferQueue[Slot].Data = new GbpBuffer(ParcelReader);
|
BufferQueue[Slot].Data = new GbpBuffer(ParcelReader);
|
||||||
|
}
|
||||||
|
|
||||||
return MakeReplyParcel(Context, 0);
|
return MakeReplyParcel(Context, 0);
|
||||||
}
|
}
|
||||||
|
@ -429,7 +433,7 @@ namespace Ryujinx.Core.OsHle.Services.Android
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.Debug("Waiting for a free BufferQueue slot...");
|
Logging.Info("Waiting for a free BufferQueue slot...");
|
||||||
|
|
||||||
if (!KeepRunning)
|
if (!KeepRunning)
|
||||||
{
|
{
|
||||||
|
@ -443,7 +447,7 @@ namespace Ryujinx.Core.OsHle.Services.Android
|
||||||
}
|
}
|
||||||
while (KeepRunning);
|
while (KeepRunning);
|
||||||
|
|
||||||
Logging.Debug($"Found free BufferQueue slot {Slot}!");
|
Logging.Info($"Found free BufferQueue slot {Slot}!");
|
||||||
|
|
||||||
return Slot;
|
return Slot;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
||||||
class GlslDecl
|
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 AttrStartIndex = 8;
|
||||||
private const int TexStartIndex = 8;
|
private const int TexStartIndex = 8;
|
||||||
|
|
|
@ -302,8 +302,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
||||||
throw new NotImplementedException(Op.Inst.ToString());
|
throw new NotImplementedException(Op.Inst.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Entry && (Op.OperandB != null ||
|
if (!Entry && NeedsParentheses(Op))
|
||||||
Op.OperandC != null))
|
|
||||||
{
|
{
|
||||||
Expr = "(" + Expr + ")";
|
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)
|
private string GetName(ShaderIrOperCbuf Cbuf)
|
||||||
{
|
{
|
||||||
if (!Decl.Uniforms.TryGetValue((Cbuf.Index, Cbuf.Offs), out ShaderDeclInfo DeclInfo))
|
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)
|
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)
|
if (Abuf.Offs == GlslDecl.VertexIdAttr)
|
||||||
{
|
{
|
||||||
return "gl_VertexID";
|
return "gl_VertexID";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return GetName(Decl.InAttributes, Abuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetName(IReadOnlyDictionary<int, ShaderDeclInfo> Dict, ShaderIrOperAbuf Abuf)
|
||||||
|
{
|
||||||
int Index = Abuf.Offs >> 4;
|
int Index = Abuf.Offs >> 4;
|
||||||
int Elem = (Abuf.Offs >> 2) & 3;
|
int Elem = (Abuf.Offs >> 2) & 3;
|
||||||
|
|
||||||
|
@ -439,7 +462,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
||||||
|
|
||||||
private string GetFnegExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "-");
|
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");
|
private string GetFrsqExpr(ShaderIrOp Op) => GetUnaryCall(Op, "inversesqrt");
|
||||||
|
|
||||||
|
@ -451,7 +474,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
||||||
|
|
||||||
private string GetLsrExpr(ShaderIrOp Op)
|
private string GetLsrExpr(ShaderIrOp Op)
|
||||||
{
|
{
|
||||||
return "(int)((uint)" + GetOperExpr(Op, Op.OperandA) + " >> " +
|
return "int(uint(" + GetOperExpr(Op, Op.OperandA) + ") >> " +
|
||||||
GetOperExpr(Op, Op.OperandB) + ")";
|
GetOperExpr(Op, Op.OperandB) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,8 +482,15 @@ namespace Ryujinx.Graphics.Gal.Shader
|
||||||
|
|
||||||
private string GetOrExpr(ShaderIrOp Op) => GetBinaryExpr(Op, "|");
|
private string GetOrExpr(ShaderIrOp Op) => GetBinaryExpr(Op, "|");
|
||||||
|
|
||||||
private string GetStofExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "(float)");
|
private string GetStofExpr(ShaderIrOp Op)
|
||||||
private string GetUtofExpr(ShaderIrOp Op) => GetUnaryExpr(Op, "(float)(uint)");
|
{
|
||||||
|
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, "^");
|
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)
|
private void VertexEndGl(AMemory Memory, NsGpuPBEntry PBEntry)
|
||||||
{
|
{
|
||||||
SetFrameBuffer(0);
|
SetFrameBuffer(0);
|
||||||
|
|
|
@ -12,6 +12,8 @@ namespace Ryujinx
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
//Ryujinx.Graphics.Gal.Shader.ShaderTest.PrintGlslProgram(File.ReadAllBytes("D:\\shbh_000000000048ba30.bin"));
|
||||||
|
|
||||||
Config.Read();
|
Config.Read();
|
||||||
|
|
||||||
AOptimizations.DisableMemoryChecks = !Config.EnableMemoryChecks;
|
AOptimizations.DisableMemoryChecks = !Config.EnableMemoryChecks;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue