2019-12-16 04:59:46 +00:00
|
|
|
using System;
|
2019-10-13 06:02:07 +00:00
|
|
|
|
2019-12-29 17:41:50 +00:00
|
|
|
namespace Ryujinx.Graphics.Shader.Translation
|
2019-10-13 06:02:07 +00:00
|
|
|
{
|
|
|
|
struct ShaderConfig
|
|
|
|
{
|
|
|
|
public ShaderStage Stage { get; }
|
|
|
|
|
2019-12-16 04:59:46 +00:00
|
|
|
public OutputTopology OutputTopology { get; }
|
|
|
|
|
|
|
|
public int MaxOutputVertices { get; }
|
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
public int LocalMemorySize { get; }
|
|
|
|
|
2019-12-16 04:59:46 +00:00
|
|
|
public OutputMapTarget[] OmapTargets { get; }
|
|
|
|
public bool OmapSampleMask { get; }
|
|
|
|
public bool OmapDepth { get; }
|
2019-12-01 02:53:09 +00:00
|
|
|
|
2019-10-13 06:02:07 +00:00
|
|
|
public TranslationFlags Flags { get; }
|
|
|
|
|
2020-01-01 15:39:09 +00:00
|
|
|
private TranslatorCallbacks _callbacks;
|
2019-10-13 06:02:07 +00:00
|
|
|
|
2020-01-01 15:39:09 +00:00
|
|
|
public ShaderConfig(TranslationFlags flags, TranslatorCallbacks callbacks)
|
2019-12-16 04:59:46 +00:00
|
|
|
{
|
2020-01-01 15:39:09 +00:00
|
|
|
Stage = ShaderStage.Compute;
|
|
|
|
OutputTopology = OutputTopology.PointList;
|
|
|
|
MaxOutputVertices = 0;
|
2020-02-02 03:25:52 +00:00
|
|
|
LocalMemorySize = 0;
|
2020-01-01 15:39:09 +00:00
|
|
|
OmapTargets = null;
|
|
|
|
OmapSampleMask = false;
|
|
|
|
OmapDepth = false;
|
|
|
|
Flags = flags;
|
|
|
|
_callbacks = callbacks;
|
2019-12-16 04:59:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 15:39:09 +00:00
|
|
|
public ShaderConfig(ShaderHeader header, TranslationFlags flags, TranslatorCallbacks callbacks)
|
2019-12-16 04:59:46 +00:00
|
|
|
{
|
2020-01-01 15:39:09 +00:00
|
|
|
Stage = header.Stage;
|
|
|
|
OutputTopology = header.OutputTopology;
|
|
|
|
MaxOutputVertices = header.MaxOutputVertexCount;
|
2020-02-02 03:25:52 +00:00
|
|
|
LocalMemorySize = header.ShaderLocalMemoryLowSize + header.ShaderLocalMemoryHighSize;
|
2020-01-01 15:39:09 +00:00
|
|
|
OmapTargets = header.OmapTargets;
|
|
|
|
OmapSampleMask = header.OmapSampleMask;
|
|
|
|
OmapDepth = header.OmapDepth;
|
|
|
|
Flags = flags;
|
|
|
|
_callbacks = callbacks;
|
2019-12-16 04:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int GetDepthRegister()
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (int index = 0; index < OmapTargets.Length; index++)
|
|
|
|
{
|
|
|
|
for (int component = 0; component < 4; component++)
|
|
|
|
{
|
|
|
|
if (OmapTargets[index].ComponentEnabled(component))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The depth register is always two registers after the last color output.
|
|
|
|
return count + 1;
|
|
|
|
}
|
2019-10-13 06:02:07 +00:00
|
|
|
|
2019-12-16 04:59:46 +00:00
|
|
|
public bool QueryInfoBool(QueryInfoName info, int index = 0)
|
2019-10-13 06:02:07 +00:00
|
|
|
{
|
2019-12-16 04:59:46 +00:00
|
|
|
return Convert.ToBoolean(QueryInfo(info, index));
|
|
|
|
}
|
|
|
|
|
|
|
|
public int QueryInfo(QueryInfoName info, int index = 0)
|
|
|
|
{
|
2020-01-01 15:39:09 +00:00
|
|
|
if (_callbacks.QueryInfo != null)
|
2019-12-16 04:59:46 +00:00
|
|
|
{
|
2020-01-01 15:39:09 +00:00
|
|
|
return _callbacks.QueryInfo(info, index);
|
2019-12-16 04:59:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (info)
|
|
|
|
{
|
|
|
|
case QueryInfoName.ComputeLocalSizeX:
|
|
|
|
case QueryInfoName.ComputeLocalSizeY:
|
|
|
|
case QueryInfoName.ComputeLocalSizeZ:
|
|
|
|
return 1;
|
2020-02-02 03:25:52 +00:00
|
|
|
case QueryInfoName.ComputeLocalMemorySize:
|
|
|
|
return 0x1000;
|
2019-12-16 04:59:46 +00:00
|
|
|
case QueryInfoName.ComputeSharedMemorySize:
|
|
|
|
return 0xc000;
|
|
|
|
case QueryInfoName.IsTextureBuffer:
|
|
|
|
return Convert.ToInt32(false);
|
|
|
|
case QueryInfoName.IsTextureRectangle:
|
|
|
|
return Convert.ToInt32(false);
|
|
|
|
case QueryInfoName.PrimitiveTopology:
|
|
|
|
return (int)InputTopology.Points;
|
|
|
|
case QueryInfoName.StorageBufferOffsetAlignment:
|
|
|
|
return 16;
|
|
|
|
case QueryInfoName.SupportsNonConstantTextureOffset:
|
|
|
|
return Convert.ToInt32(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2019-10-13 06:02:07 +00:00
|
|
|
}
|
2020-01-01 15:39:09 +00:00
|
|
|
|
|
|
|
public void PrintLog(string message)
|
|
|
|
{
|
|
|
|
_callbacks.PrintLog?.Invoke(message);
|
|
|
|
}
|
2019-10-13 06:02:07 +00:00
|
|
|
}
|
|
|
|
}
|