Implement SULD shader instruction (#1117)
* Implement SULD shader instruction * Some nits
This commit is contained in:
parent
4738113f29
commit
03711dd7b5
15 changed files with 620 additions and 109 deletions
|
@ -326,9 +326,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
continue;
|
||||
}
|
||||
|
||||
string imageTypeName = GetImageTypeName(texOp.Type);
|
||||
string layout = texOp.Format.ToGlslFormat();
|
||||
|
||||
context.AppendLine("writeonly uniform " + imageTypeName + " " + imageName + ";");
|
||||
if (!string.IsNullOrEmpty(layout))
|
||||
{
|
||||
layout = "layout(" + layout + ") ";
|
||||
}
|
||||
|
||||
string imageTypeName = GetImageTypeName(texOp.Type, texOp.Format.GetComponentType());
|
||||
|
||||
context.AppendLine("uniform " + layout + imageTypeName + " " + imageName + ";");
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, AstTextureOperation> kv in images)
|
||||
|
@ -455,7 +462,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
return typeName;
|
||||
}
|
||||
|
||||
private static string GetImageTypeName(SamplerType type)
|
||||
private static string GetImageTypeName(SamplerType type, VariableType componentType)
|
||||
{
|
||||
string typeName;
|
||||
|
||||
|
@ -480,6 +487,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
typeName += "Array";
|
||||
}
|
||||
|
||||
switch (componentType)
|
||||
{
|
||||
case VariableType.U32: typeName = 'u' + typeName; break;
|
||||
case VariableType.S32: typeName = 'i' + typeName; break;
|
||||
}
|
||||
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System;
|
|||
|
||||
using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenHelper;
|
||||
using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenMemory;
|
||||
using static Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions.InstGenPacking;
|
||||
using static Ryujinx.Graphics.Shader.StructuredIr.InstructionInfo;
|
||||
|
||||
namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
||||
|
@ -115,53 +116,56 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
{
|
||||
switch (inst)
|
||||
{
|
||||
case Instruction.ImageLoad:
|
||||
return ImageLoadOrStore(context, operation);
|
||||
|
||||
case Instruction.ImageStore:
|
||||
return InstGenMemory.ImageStore(context, operation);
|
||||
return ImageLoadOrStore(context, operation);
|
||||
|
||||
case Instruction.LoadAttribute:
|
||||
return InstGenMemory.LoadAttribute(context, operation);
|
||||
return LoadAttribute(context, operation);
|
||||
|
||||
case Instruction.LoadConstant:
|
||||
return InstGenMemory.LoadConstant(context, operation);
|
||||
return LoadConstant(context, operation);
|
||||
|
||||
case Instruction.LoadLocal:
|
||||
return InstGenMemory.LoadLocal(context, operation);
|
||||
return LoadLocal(context, operation);
|
||||
|
||||
case Instruction.LoadShared:
|
||||
return InstGenMemory.LoadShared(context, operation);
|
||||
return LoadShared(context, operation);
|
||||
|
||||
case Instruction.LoadStorage:
|
||||
return InstGenMemory.LoadStorage(context, operation);
|
||||
return LoadStorage(context, operation);
|
||||
|
||||
case Instruction.Lod:
|
||||
return InstGenMemory.Lod(context, operation);
|
||||
return Lod(context, operation);
|
||||
|
||||
case Instruction.PackDouble2x32:
|
||||
return InstGenPacking.PackDouble2x32(context, operation);
|
||||
return PackDouble2x32(context, operation);
|
||||
|
||||
case Instruction.PackHalf2x16:
|
||||
return InstGenPacking.PackHalf2x16(context, operation);
|
||||
return PackHalf2x16(context, operation);
|
||||
|
||||
case Instruction.StoreLocal:
|
||||
return InstGenMemory.StoreLocal(context, operation);
|
||||
return StoreLocal(context, operation);
|
||||
|
||||
case Instruction.StoreShared:
|
||||
return InstGenMemory.StoreShared(context, operation);
|
||||
return StoreShared(context, operation);
|
||||
|
||||
case Instruction.StoreStorage:
|
||||
return InstGenMemory.StoreStorage(context, operation);
|
||||
return StoreStorage(context, operation);
|
||||
|
||||
case Instruction.TextureSample:
|
||||
return InstGenMemory.TextureSample(context, operation);
|
||||
return TextureSample(context, operation);
|
||||
|
||||
case Instruction.TextureSize:
|
||||
return InstGenMemory.TextureSize(context, operation);
|
||||
return TextureSize(context, operation);
|
||||
|
||||
case Instruction.UnpackDouble2x32:
|
||||
return InstGenPacking.UnpackDouble2x32(context, operation);
|
||||
return UnpackDouble2x32(context, operation);
|
||||
|
||||
case Instruction.UnpackHalf2x16:
|
||||
return InstGenPacking.UnpackHalf2x16(context, operation);
|
||||
return UnpackHalf2x16(context, operation);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,16 +9,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
{
|
||||
static class InstGenMemory
|
||||
{
|
||||
public static string ImageStore(CodeGenContext context, AstOperation operation)
|
||||
public static string ImageLoadOrStore(CodeGenContext context, AstOperation operation)
|
||||
{
|
||||
AstTextureOperation texOp = (AstTextureOperation)operation;
|
||||
|
||||
bool isBindless = (texOp.Flags & TextureFlags.Bindless) != 0;
|
||||
|
||||
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
||||
bool isArray = (texOp.Type & SamplerType.Array) != 0;
|
||||
bool isIndexed = (texOp.Type & SamplerType.Indexed) != 0;
|
||||
|
||||
string texCall = "imageStore";
|
||||
string texCall = texOp.Inst == Instruction.ImageLoad ? "imageLoad" : "imageStore";
|
||||
|
||||
int srcIndex = isBindless ? 1 : 0;
|
||||
|
||||
|
@ -40,14 +40,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
|
||||
int coordsCount = texOp.Type.GetDimensions();
|
||||
|
||||
int pCount = coordsCount;
|
||||
|
||||
int arrayIndexElem = -1;
|
||||
|
||||
if (isArray)
|
||||
{
|
||||
arrayIndexElem = pCount++;
|
||||
}
|
||||
int pCount = coordsCount + (isArray ? 1 : 0);
|
||||
|
||||
void Append(string str)
|
||||
{
|
||||
|
@ -70,23 +63,40 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
|
|||
Append(Src(VariableType.S32));
|
||||
}
|
||||
|
||||
string[] cElems = new string[4];
|
||||
|
||||
for (int index = 0; index < 4; index++)
|
||||
if (texOp.Inst == Instruction.ImageStore)
|
||||
{
|
||||
if (srcIndex < texOp.SourcesCount)
|
||||
VariableType type = texOp.Format.GetComponentType();
|
||||
|
||||
string[] cElems = new string[4];
|
||||
|
||||
for (int index = 0; index < 4; index++)
|
||||
{
|
||||
cElems[index] = Src(VariableType.F32);
|
||||
if (srcIndex < texOp.SourcesCount)
|
||||
{
|
||||
cElems[index] = Src(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
cElems[index] = type switch
|
||||
{
|
||||
VariableType.S32 => NumberFormatter.FormatInt(0),
|
||||
VariableType.U32 => NumberFormatter.FormatUint(0),
|
||||
_ => NumberFormatter.FormatFloat(0)
|
||||
};
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
string prefix = type switch
|
||||
{
|
||||
cElems[index] = NumberFormatter.FormatFloat(0);
|
||||
}
|
||||
VariableType.S32 => "i",
|
||||
VariableType.U32 => "u",
|
||||
_ => string.Empty
|
||||
};
|
||||
|
||||
Append(prefix + "vec4(" + string.Join(", ", cElems) + ")");
|
||||
}
|
||||
|
||||
Append("vec4(" + string.Join(", ", cElems) + ")");
|
||||
|
||||
texCall += ")";
|
||||
texCall += ")" + (texOp.Inst == Instruction.ImageLoad ? GetMask(texOp.Index) : "");
|
||||
|
||||
return texCall;
|
||||
}
|
||||
|
|
|
@ -280,6 +280,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|||
{
|
||||
return GetOperandVarType((AstOperand)operation.GetSource(0));
|
||||
}
|
||||
else if (operation is AstTextureOperation texOp &&
|
||||
(texOp.Inst == Instruction.ImageLoad ||
|
||||
texOp.Inst == Instruction.ImageStore))
|
||||
{
|
||||
return texOp.Format.GetComponentType();
|
||||
}
|
||||
|
||||
return GetDestVarType(operation.Inst);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue