Address PR feedback
This commit is contained in:
@ -13,6 +13,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
private ShaderConfig _config;
|
||||
|
||||
public ShaderConfig Config => _config;
|
||||
|
||||
private List<Operation> _operations;
|
||||
|
||||
private Dictionary<ulong, Operand> _labels;
|
||||
|
@ -16,30 +16,30 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
public TranslationFlags Flags { get; }
|
||||
|
||||
private QueryInfoCallback _queryInfoCallback;
|
||||
private TranslatorCallbacks _callbacks;
|
||||
|
||||
public ShaderConfig(TranslationFlags flags, QueryInfoCallback queryInfoCallback)
|
||||
public ShaderConfig(TranslationFlags flags, TranslatorCallbacks callbacks)
|
||||
{
|
||||
Stage = ShaderStage.Compute;
|
||||
OutputTopology = OutputTopology.PointList;
|
||||
MaxOutputVertices = 0;
|
||||
OmapTargets = null;
|
||||
OmapSampleMask = false;
|
||||
OmapDepth = false;
|
||||
Flags = flags;
|
||||
_queryInfoCallback = queryInfoCallback;
|
||||
Stage = ShaderStage.Compute;
|
||||
OutputTopology = OutputTopology.PointList;
|
||||
MaxOutputVertices = 0;
|
||||
OmapTargets = null;
|
||||
OmapSampleMask = false;
|
||||
OmapDepth = false;
|
||||
Flags = flags;
|
||||
_callbacks = callbacks;
|
||||
}
|
||||
|
||||
public ShaderConfig(ShaderHeader header, TranslationFlags flags, QueryInfoCallback queryInfoCallback)
|
||||
public ShaderConfig(ShaderHeader header, TranslationFlags flags, TranslatorCallbacks callbacks)
|
||||
{
|
||||
Stage = header.Stage;
|
||||
OutputTopology = header.OutputTopology;
|
||||
MaxOutputVertices = header.MaxOutputVertexCount;
|
||||
OmapTargets = header.OmapTargets;
|
||||
OmapSampleMask = header.OmapSampleMask;
|
||||
OmapDepth = header.OmapDepth;
|
||||
Flags = flags;
|
||||
_queryInfoCallback = queryInfoCallback;
|
||||
Stage = header.Stage;
|
||||
OutputTopology = header.OutputTopology;
|
||||
MaxOutputVertices = header.MaxOutputVertexCount;
|
||||
OmapTargets = header.OmapTargets;
|
||||
OmapSampleMask = header.OmapSampleMask;
|
||||
OmapDepth = header.OmapDepth;
|
||||
Flags = flags;
|
||||
_callbacks = callbacks;
|
||||
}
|
||||
|
||||
public int GetDepthRegister()
|
||||
@ -68,9 +68,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
public int QueryInfo(QueryInfoName info, int index = 0)
|
||||
{
|
||||
if (_queryInfoCallback != null)
|
||||
if (_callbacks.QueryInfo != null)
|
||||
{
|
||||
return _queryInfoCallback(info, index);
|
||||
return _callbacks.QueryInfo(info, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -86,8 +86,6 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
return Convert.ToInt32(false);
|
||||
case QueryInfoName.IsTextureRectangle:
|
||||
return Convert.ToInt32(false);
|
||||
case QueryInfoName.MaximumViewportDimensions:
|
||||
return 0x8000;
|
||||
case QueryInfoName.PrimitiveTopology:
|
||||
return (int)InputTopology.Points;
|
||||
case QueryInfoName.StorageBufferOffsetAlignment:
|
||||
@ -99,5 +97,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void PrintLog(string message)
|
||||
{
|
||||
_callbacks.PrintLog?.Invoke(message);
|
||||
}
|
||||
}
|
||||
}
|
@ -40,21 +40,17 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
return code.Slice(0, headerSize + (int)endAddress);
|
||||
}
|
||||
|
||||
public static ShaderProgram Translate(Span<byte> code, QueryInfoCallback queryInfoCallback, TranslationFlags flags)
|
||||
public static ShaderProgram Translate(Span<byte> code, TranslatorCallbacks callbacks, TranslationFlags flags)
|
||||
{
|
||||
bool compute = (flags & TranslationFlags.Compute) != 0;
|
||||
|
||||
Operation[] ops = DecodeShader(code, queryInfoCallback, flags, out ShaderConfig config, out int size);
|
||||
Operation[] ops = DecodeShader(code, callbacks, flags, out ShaderConfig config, out int size);
|
||||
|
||||
return Translate(ops, config, size);
|
||||
}
|
||||
|
||||
public static ShaderProgram Translate(Span<byte> vpACode, Span<byte> vpBCode, QueryInfoCallback queryInfoCallback, TranslationFlags flags)
|
||||
public static ShaderProgram Translate(Span<byte> vpACode, Span<byte> vpBCode, TranslatorCallbacks callbacks, TranslationFlags flags)
|
||||
{
|
||||
bool debugMode = (flags & TranslationFlags.DebugMode) != 0;
|
||||
|
||||
Operation[] vpAOps = DecodeShader(vpACode, queryInfoCallback, flags, out _, out _);
|
||||
Operation[] vpBOps = DecodeShader(vpBCode, queryInfoCallback, flags, out ShaderConfig config, out int sizeB);
|
||||
Operation[] vpAOps = DecodeShader(vpACode, callbacks, flags, out _, out _);
|
||||
Operation[] vpBOps = DecodeShader(vpBCode, callbacks, flags, out ShaderConfig config, out int sizeB);
|
||||
|
||||
return Translate(Combine(vpAOps, vpBOps), config, sizeB);
|
||||
}
|
||||
@ -94,34 +90,34 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
}
|
||||
|
||||
private static Operation[] DecodeShader(
|
||||
Span<byte> code,
|
||||
QueryInfoCallback queryInfoCallback,
|
||||
TranslationFlags flags,
|
||||
out ShaderConfig config,
|
||||
out int size)
|
||||
Span<byte> code,
|
||||
TranslatorCallbacks callbacks,
|
||||
TranslationFlags flags,
|
||||
out ShaderConfig config,
|
||||
out int size)
|
||||
{
|
||||
Block[] cfg;
|
||||
|
||||
if ((flags & TranslationFlags.Compute) != 0)
|
||||
{
|
||||
config = new ShaderConfig(flags, queryInfoCallback);
|
||||
config = new ShaderConfig(flags, callbacks);
|
||||
|
||||
cfg = Decoder.Decode(code, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new ShaderConfig(new ShaderHeader(code), flags, queryInfoCallback);
|
||||
config = new ShaderConfig(new ShaderHeader(code), flags, callbacks);
|
||||
|
||||
cfg = Decoder.Decode(code, HeaderSize);
|
||||
}
|
||||
|
||||
if (cfg == null)
|
||||
{
|
||||
// TODO: Error.
|
||||
config.PrintLog("Invalid branch detected, failed to build CFG.");
|
||||
|
||||
size = 0;
|
||||
|
||||
return new Operation[0];
|
||||
return Array.Empty<Operation>();
|
||||
}
|
||||
|
||||
EmitterContext context = new EmitterContext(config);
|
||||
@ -156,6 +152,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
else
|
||||
{
|
||||
instName = "???";
|
||||
|
||||
config.PrintLog($"Invalid instruction at 0x{op.Address:X6} (0x{op.RawOpCode:X16}).");
|
||||
}
|
||||
|
||||
string dbgComment = $"0x{op.Address:X6}: 0x{op.RawOpCode:X16} {instName}";
|
||||
@ -210,10 +208,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||
|
||||
context.CurrOp = op;
|
||||
|
||||
if (op.Emitter != null)
|
||||
{
|
||||
op.Emitter(context);
|
||||
}
|
||||
op.Emitter?.Invoke(context);
|
||||
|
||||
if (predSkipLbl != null)
|
||||
{
|
||||
|
17
Ryujinx.Graphics.Shader/Translation/TranslatorCallbacks.cs
Normal file
17
Ryujinx.Graphics.Shader/Translation/TranslatorCallbacks.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.Translation
|
||||
{
|
||||
public struct TranslatorCallbacks
|
||||
{
|
||||
internal Func<QueryInfoName, int, int> QueryInfo { get; }
|
||||
|
||||
internal Action<string> PrintLog { get; }
|
||||
|
||||
public TranslatorCallbacks(Func<QueryInfoName, int, int> queryInfoCallback, Action<string> printLogCallback)
|
||||
{
|
||||
QueryInfo = queryInfoCallback;
|
||||
PrintLog = printLogCallback;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user