Add ShaderConfig, used to pass shader type and maximum cbuffer size
This commit is contained in:
parent
4ffaaf0cd5
commit
1a675a104a
10 changed files with 62 additions and 33 deletions
|
@ -52,28 +52,30 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
bool isDualVp,
|
bool isDualVp,
|
||||||
GalShaderType type)
|
GalShaderType type)
|
||||||
{
|
{
|
||||||
ShaderProgram program;
|
ShaderConfig config = new ShaderConfig(type, OglLimit.MaxUboSize);
|
||||||
|
|
||||||
int shaderDumpIndex = ShaderDumper.DumpIndex;
|
ShaderProgram program;
|
||||||
|
|
||||||
if (isDualVp)
|
if (isDualVp)
|
||||||
{
|
{
|
||||||
ShaderDumper.Dump(memory, position, type, "a");
|
ShaderDumper.Dump(memory, position, type, "a");
|
||||||
ShaderDumper.Dump(memory, positionB, type, "b");
|
ShaderDumper.Dump(memory, positionB, type, "b");
|
||||||
|
|
||||||
program = Translator.Translate(memory, (ulong)position, (ulong)positionB, type);
|
program = Translator.Translate(memory, (ulong)position, (ulong)positionB, config);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ShaderDumper.Dump(memory, position, type);
|
ShaderDumper.Dump(memory, position, type);
|
||||||
|
|
||||||
program = Translator.Translate(memory, (ulong)position, type);
|
program = Translator.Translate(memory, (ulong)position, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
string code = program.Code;
|
string code = program.Code;
|
||||||
|
|
||||||
if (ShaderDumper.IsDumpEnabled())
|
if (ShaderDumper.IsDumpEnabled())
|
||||||
{
|
{
|
||||||
|
int shaderDumpIndex = ShaderDumper.DumpIndex;
|
||||||
|
|
||||||
code = "//Shader " + shaderDumpIndex + Environment.NewLine + code;
|
code = "//Shader " + shaderDumpIndex + Environment.NewLine + code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
using Ryujinx.Graphics.Gal;
|
|
||||||
using Ryujinx.Graphics.Shader.StructuredIr;
|
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -9,7 +8,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
{
|
{
|
||||||
private const string Tab = " ";
|
private const string Tab = " ";
|
||||||
|
|
||||||
public GalShaderType ShaderType { get; }
|
public ShaderConfig Config { get; }
|
||||||
|
|
||||||
public List<CBufferDescriptor> CBufferDescriptors { get; }
|
public List<CBufferDescriptor> CBufferDescriptors { get; }
|
||||||
public List<TextureDescriptor> TextureDescriptors { get; }
|
public List<TextureDescriptor> TextureDescriptors { get; }
|
||||||
|
@ -22,9 +21,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
private string _identation;
|
private string _identation;
|
||||||
|
|
||||||
public CodeGenContext(GalShaderType shaderType)
|
public CodeGenContext(ShaderConfig config)
|
||||||
{
|
{
|
||||||
ShaderType = shaderType;
|
Config = config;
|
||||||
|
|
||||||
CBufferDescriptors = new List<CBufferDescriptor>();
|
CBufferDescriptors = new List<CBufferDescriptor>();
|
||||||
TextureDescriptors = new List<TextureDescriptor>();
|
TextureDescriptors = new List<TextureDescriptor>();
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
context.AppendLine();
|
context.AppendLine();
|
||||||
|
|
||||||
if (context.ShaderType == GalShaderType.Geometry)
|
if (context.Config.Type == GalShaderType.Geometry)
|
||||||
{
|
{
|
||||||
context.AppendLine("layout (points) in;");
|
context.AppendLine("layout (points) in;");
|
||||||
context.AppendLine("layout (triangle_strip, max_vertices = 4) out;");
|
context.AppendLine("layout (triangle_strip, max_vertices = 4) out;");
|
||||||
|
@ -94,7 +94,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
{
|
{
|
||||||
foreach (int cbufSlot in info.CBuffers.OrderBy(x => x))
|
foreach (int cbufSlot in info.CBuffers.OrderBy(x => x))
|
||||||
{
|
{
|
||||||
string ubName = OperandManager.GetShaderStagePrefix(context.ShaderType);
|
string ubName = OperandManager.GetShaderStagePrefix(context.Config.Type);
|
||||||
|
|
||||||
ubName += "_" + DefaultNames.UniformNamePrefix + cbufSlot;
|
ubName += "_" + DefaultNames.UniformNamePrefix + cbufSlot;
|
||||||
|
|
||||||
|
@ -104,7 +104,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
context.EnterScope();
|
context.EnterScope();
|
||||||
|
|
||||||
context.AppendLine("vec4 " + OperandManager.GetUbName(context.ShaderType, cbufSlot) + "[4096];");
|
string ubSize = "[" + NumberFormatter.FormatInt(context.Config.MaxCBufferSize / 16) + "]";
|
||||||
|
|
||||||
|
context.AppendLine("vec4 " + OperandManager.GetUbName(context.Config.Type, cbufSlot) + ubSize + ";");
|
||||||
|
|
||||||
context.LeaveScope(";");
|
context.LeaveScope(";");
|
||||||
}
|
}
|
||||||
|
@ -116,7 +118,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
foreach (AstTextureOperation texOp in info.Samplers.OrderBy(x => x.Handle))
|
foreach (AstTextureOperation texOp in info.Samplers.OrderBy(x => x.Handle))
|
||||||
{
|
{
|
||||||
string samplerName = OperandManager.GetSamplerName(context.ShaderType, texOp);
|
string samplerName = OperandManager.GetSamplerName(context.Config.Type, texOp);
|
||||||
|
|
||||||
if (!samplers.TryAdd(samplerName, texOp))
|
if (!samplers.TryAdd(samplerName, texOp))
|
||||||
{
|
{
|
||||||
|
@ -153,7 +155,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info)
|
private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info)
|
||||||
{
|
{
|
||||||
string suffix = context.ShaderType == GalShaderType.Geometry ? "[]" : string.Empty;
|
string suffix = context.Config.Type == GalShaderType.Geometry ? "[]" : string.Empty;
|
||||||
|
|
||||||
foreach (int attr in info.IAttributes.OrderBy(x => x))
|
foreach (int attr in info.IAttributes.OrderBy(x => x))
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,9 +10,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
{
|
{
|
||||||
static class GlslGenerator
|
static class GlslGenerator
|
||||||
{
|
{
|
||||||
public static GlslProgram Generate(StructuredProgramInfo info, GalShaderType shaderType)
|
public static GlslProgram Generate(StructuredProgramInfo info, ShaderConfig config)
|
||||||
{
|
{
|
||||||
CodeGenContext context = new CodeGenContext(shaderType);
|
CodeGenContext context = new CodeGenContext(config);
|
||||||
|
|
||||||
Declarations.Declare(context, info);
|
Declarations.Declare(context, info);
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
private static void PrepareForReturn(CodeGenContext context)
|
private static void PrepareForReturn(CodeGenContext context)
|
||||||
{
|
{
|
||||||
if (context.ShaderType == GalShaderType.Vertex)
|
if (context.Config.Type == GalShaderType.Vertex)
|
||||||
{
|
{
|
||||||
context.AppendLine("gl_Position.xy *= flip;");
|
context.AppendLine("gl_Position.xy *= flip;");
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
||||||
return NumberFormatter.FormatInt(operand.Value);
|
return NumberFormatter.FormatInt(operand.Value);
|
||||||
|
|
||||||
case OperandType.ConstantBuffer:
|
case OperandType.ConstantBuffer:
|
||||||
return OperandManager.GetConstantBufferName(context.ShaderType, operand);
|
return OperandManager.GetConstantBufferName(context.Config.Type, operand);
|
||||||
|
|
||||||
case OperandType.LocalVariable:
|
case OperandType.LocalVariable:
|
||||||
return context.GetLocalName(operand);
|
return context.GetLocalName(operand);
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
||||||
bool isMultisample = (texOp.Type & TextureType.Multisample) != 0;
|
bool isMultisample = (texOp.Type & TextureType.Multisample) != 0;
|
||||||
bool isShadow = (texOp.Type & TextureType.Shadow) != 0;
|
bool isShadow = (texOp.Type & TextureType.Shadow) != 0;
|
||||||
|
|
||||||
string samplerName = OperandManager.GetSamplerName(context.ShaderType, texOp);
|
string samplerName = OperandManager.GetSamplerName(context.Config.Type, texOp);
|
||||||
|
|
||||||
string texCall = intCoords ? "texelFetch" : "texture";
|
string texCall = intCoords ? "texelFetch" : "texture";
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
||||||
|
|
||||||
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
|
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
|
||||||
|
|
||||||
string samplerName = OperandManager.GetSamplerName(context.ShaderType, texOp);
|
string samplerName = OperandManager.GetSamplerName(context.Config.Type, texOp);
|
||||||
|
|
||||||
IAstNode src0 = operation.GetSource(isBindless ? 1 : 0);
|
IAstNode src0 = operation.GetSource(isBindless ? 1 : 0);
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
//slot access.
|
//slot access.
|
||||||
AstOperand operand = (AstOperand)slot;
|
AstOperand operand = (AstOperand)slot;
|
||||||
|
|
||||||
string ubName = GetUbName(context.ShaderType, operand.Value);
|
string ubName = GetUbName(context.Config.Type, operand.Value);
|
||||||
|
|
||||||
string index0 = "[" + offsetExpr + " >> 4]";
|
string index0 = "[" + offsetExpr + " >> 4]";
|
||||||
string index1 = "[" + offsetExpr + " >> 2 & 3]";
|
string index1 = "[" + offsetExpr + " >> 2 & 3]";
|
||||||
|
@ -90,7 +90,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
string name = $"{prefix}{(value >> 4)}";
|
string name = $"{prefix}{(value >> 4)}";
|
||||||
|
|
||||||
if (context.ShaderType == GalShaderType.Geometry && !isOutAttr)
|
if (context.Config.Type == GalShaderType.Geometry && !isOutAttr)
|
||||||
{
|
{
|
||||||
name += "[0]";
|
name += "[0]";
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
else if (_builtInAttributes.TryGetValue(value & ~3, out BuiltInAttribute builtInAttr))
|
else if (_builtInAttributes.TryGetValue(value & ~3, out BuiltInAttribute builtInAttr))
|
||||||
{
|
{
|
||||||
//TODO: There must be a better way to handle this...
|
//TODO: There must be a better way to handle this...
|
||||||
if (context.ShaderType == GalShaderType.Fragment)
|
if (context.Config.Type == GalShaderType.Fragment)
|
||||||
{
|
{
|
||||||
switch (value & ~3)
|
switch (value & ~3)
|
||||||
{
|
{
|
||||||
|
@ -124,7 +124,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
||||||
|
|
||||||
string name = builtInAttr.Name;
|
string name = builtInAttr.Name;
|
||||||
|
|
||||||
if (context.ShaderType == GalShaderType.Geometry && !isOutAttr)
|
if (context.Config.Type == GalShaderType.Geometry && !isOutAttr)
|
||||||
{
|
{
|
||||||
name = "gl_in[0]." + name;
|
name = "gl_in[0]." + name;
|
||||||
}
|
}
|
||||||
|
|
23
Ryujinx.Graphics/Shader/ShaderConfig.cs
Normal file
23
Ryujinx.Graphics/Shader/ShaderConfig.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using Ryujinx.Graphics.Gal;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Ryujinx.Graphics.Shader
|
||||||
|
{
|
||||||
|
public struct ShaderConfig
|
||||||
|
{
|
||||||
|
public GalShaderType Type { get; }
|
||||||
|
|
||||||
|
public int MaxCBufferSize;
|
||||||
|
|
||||||
|
public ShaderConfig(GalShaderType type, int maxCBufferSize)
|
||||||
|
{
|
||||||
|
if (maxCBufferSize <= 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(maxCBufferSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
Type = type;
|
||||||
|
MaxCBufferSize = maxCBufferSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,23 +13,23 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
{
|
{
|
||||||
public static class Translator
|
public static class Translator
|
||||||
{
|
{
|
||||||
public static ShaderProgram Translate(IGalMemory memory, ulong address, GalShaderType shaderType)
|
public static ShaderProgram Translate(IGalMemory memory, ulong address, ShaderConfig config)
|
||||||
{
|
{
|
||||||
return Translate(memory, address, 0, shaderType);
|
return Translate(memory, address, 0, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ShaderProgram Translate(
|
public static ShaderProgram Translate(
|
||||||
IGalMemory memory,
|
IGalMemory memory,
|
||||||
ulong address,
|
ulong address,
|
||||||
ulong addressB,
|
ulong addressB,
|
||||||
GalShaderType shaderType)
|
ShaderConfig config)
|
||||||
{
|
{
|
||||||
Operation[] shaderOps = DecodeShader(memory, address, shaderType);
|
Operation[] shaderOps = DecodeShader(memory, address, config.Type);
|
||||||
|
|
||||||
if (addressB != 0)
|
if (addressB != 0)
|
||||||
{
|
{
|
||||||
//Dual vertex shader.
|
//Dual vertex shader.
|
||||||
Operation[] shaderOpsB = DecodeShader(memory, addressB, shaderType);
|
Operation[] shaderOpsB = DecodeShader(memory, addressB, config.Type);
|
||||||
|
|
||||||
shaderOps = Combine(shaderOps, shaderOpsB);
|
shaderOps = Combine(shaderOps, shaderOpsB);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
|
|
||||||
StructuredProgramInfo sInfo = StructuredProgram.MakeStructuredProgram(irBlocks);
|
StructuredProgramInfo sInfo = StructuredProgram.MakeStructuredProgram(irBlocks);
|
||||||
|
|
||||||
GlslProgram program = GlslGenerator.Generate(sInfo, shaderType);
|
GlslProgram program = GlslGenerator.Generate(sInfo, config);
|
||||||
|
|
||||||
ShaderProgramInfo spInfo = new ShaderProgramInfo(
|
ShaderProgramInfo spInfo = new ShaderProgramInfo(
|
||||||
program.CBufferDescriptors,
|
program.CBufferDescriptors,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Ryujinx.Graphics.Gal;
|
using Ryujinx.Graphics.Gal;
|
||||||
|
using Ryujinx.Graphics.Shader;
|
||||||
using Ryujinx.Graphics.Shader.Translation;
|
using Ryujinx.Graphics.Shader.Translation;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -26,7 +27,9 @@ namespace Ryujinx.ShaderTools
|
||||||
{
|
{
|
||||||
Memory mem = new Memory(fs);
|
Memory mem = new Memory(fs);
|
||||||
|
|
||||||
string code = Translator.Translate(mem, 0, type).Code;
|
ShaderConfig config = new ShaderConfig(type, 65536);
|
||||||
|
|
||||||
|
string code = Translator.Translate(mem, 0, config).Code;
|
||||||
|
|
||||||
Console.WriteLine(code);
|
Console.WriteLine(code);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue