mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-24 22:26:03 +00:00
Vertex Input Attributes
This commit is contained in:
parent
f07327166c
commit
bbc2ac2e9b
6 changed files with 46 additions and 16 deletions
|
@ -1,6 +1,9 @@
|
||||||
using Ryujinx.Graphics.Shader.StructuredIr;
|
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||||
using Ryujinx.Graphics.Shader.Translation;
|
using Ryujinx.Graphics.Shader.Translation;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
{
|
{
|
||||||
|
@ -12,11 +15,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
context.AppendLine("#include <simd/simd.h>");
|
context.AppendLine("#include <simd/simd.h>");
|
||||||
context.AppendLine();
|
context.AppendLine();
|
||||||
context.AppendLine("using namespace metal;");
|
context.AppendLine("using namespace metal;");
|
||||||
|
context.AppendLine();
|
||||||
|
|
||||||
if ((info.HelperFunctionsMask & HelperFunctionsMask.SwizzleAdd) != 0)
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.SwizzleAdd) != 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeclareInputAttributes(context, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeclareLocals(CodeGenContext context, StructuredFunction function)
|
public static void DeclareLocals(CodeGenContext context, StructuredFunction function)
|
||||||
|
@ -53,5 +59,28 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
_ => throw new ArgumentException($"Invalid variable type \"{type}\"."),
|
_ => throw new ArgumentException($"Invalid variable type \"{type}\"."),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info)
|
||||||
|
{
|
||||||
|
if (context.Config.UsedInputAttributes != 0)
|
||||||
|
{
|
||||||
|
context.AppendLine("struct VertexIn");
|
||||||
|
context.EnterScope();
|
||||||
|
|
||||||
|
int usedAttributes = context.Config.UsedInputAttributes | context.Config.PassthroughAttributes;
|
||||||
|
while (usedAttributes != 0)
|
||||||
|
{
|
||||||
|
int index = BitOperations.TrailingZeroCount(usedAttributes);
|
||||||
|
|
||||||
|
string name = $"{DefaultNames.IAttributePrefix}{index}";
|
||||||
|
var type = context.Config.GpuAccessor.QueryAttributeType(index).ToVec4Type(TargetLanguage.Msl);
|
||||||
|
context.AppendLine($"{type} {name} [[attribute({index})]];");
|
||||||
|
|
||||||
|
usedAttributes &= ~(1 << index);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.LeaveScope(";");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ using Ryujinx.Graphics.Shader.CodeGen.Msl.Instructions;
|
||||||
using Ryujinx.Graphics.Shader.StructuredIr;
|
using Ryujinx.Graphics.Shader.StructuredIr;
|
||||||
using Ryujinx.Graphics.Shader.Translation;
|
using Ryujinx.Graphics.Shader.Translation;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using static Ryujinx.Graphics.Shader.CodeGen.Msl.TypeConversion;
|
using static Ryujinx.Graphics.Shader.CodeGen.Msl.TypeConversion;
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
|
@ -77,6 +77,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
|
|
||||||
string funcKeyword = "inline";
|
string funcKeyword = "inline";
|
||||||
string funcName = null;
|
string funcName = null;
|
||||||
|
|
||||||
if (isMainFunc)
|
if (isMainFunc)
|
||||||
{
|
{
|
||||||
if (stage == ShaderStage.Vertex)
|
if (stage == ShaderStage.Vertex)
|
||||||
|
@ -89,6 +90,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
funcKeyword = "fragment";
|
funcKeyword = "fragment";
|
||||||
funcName = "fragmentMain";
|
funcName = "fragmentMain";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.Config.UsedInputAttributes != 0)
|
||||||
|
{
|
||||||
|
args = args.Prepend("VertexIn in [[stage_in]]").ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $"{funcKeyword} {Declarations.GetVarTypeName(context, function.ReturnType)} {funcName ?? function.Name}({string.Join(", ", args)})";
|
return $"{funcKeyword} {Declarations.GetVarTypeName(context, function.ReturnType)} {funcName ?? function.Name}({string.Join(", ", args)})";
|
||||||
|
|
|
@ -99,8 +99,6 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
IoVariable ioVariable = (IoVariable)varId.Value;
|
IoVariable ioVariable = (IoVariable)varId.Value;
|
||||||
bool isOutput = operation.StorageKind == StorageKind.Output || operation.StorageKind == StorageKind.OutputPerPatch;
|
bool isOutput = operation.StorageKind == StorageKind.Output || operation.StorageKind == StorageKind.OutputPerPatch;
|
||||||
bool isPerPatch = operation.StorageKind == StorageKind.InputPerPatch || operation.StorageKind == StorageKind.OutputPerPatch;
|
bool isPerPatch = operation.StorageKind == StorageKind.InputPerPatch || operation.StorageKind == StorageKind.OutputPerPatch;
|
||||||
int location = 0;
|
|
||||||
int component = 0;
|
|
||||||
|
|
||||||
if (context.Config.HasPerLocationInputOrOutput(ioVariable, isOutput))
|
if (context.Config.HasPerLocationInputOrOutput(ioVariable, isOutput))
|
||||||
{
|
{
|
||||||
|
@ -109,14 +107,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
throw new InvalidOperationException($"Second input of {operation.Inst} with {operation.StorageKind} storage must be a constant operand.");
|
throw new InvalidOperationException($"Second input of {operation.Inst} with {operation.StorageKind} storage must be a constant operand.");
|
||||||
}
|
}
|
||||||
|
|
||||||
location = vecIndex.Value;
|
int location = vecIndex.Value;
|
||||||
|
|
||||||
if (operation.SourcesCount > 2 &&
|
if (operation.SourcesCount > 2 &&
|
||||||
operation.GetSource(2) is AstOperand elemIndex &&
|
operation.GetSource(2) is AstOperand elemIndex &&
|
||||||
elemIndex.Type == OperandType.Constant &&
|
elemIndex.Type == OperandType.Constant &&
|
||||||
context.Config.HasPerLocationInputOrOutputComponent(ioVariable, location, elemIndex.Value, isOutput))
|
context.Config.HasPerLocationInputOrOutputComponent(ioVariable, location, elemIndex.Value, isOutput))
|
||||||
{
|
{
|
||||||
component = elemIndex.Value;
|
int component = elemIndex.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Msl
|
||||||
{
|
{
|
||||||
static class TypeConversion
|
static class TypeConversion
|
||||||
{
|
{
|
||||||
public static string ReinterpretCast(
|
public static string ReinterpretCast(
|
||||||
CodeGenContext context,
|
CodeGenContext context,
|
||||||
IAstNode node,
|
IAstNode node,
|
||||||
AggregateType srcType,
|
AggregateType srcType,
|
||||||
|
|
|
@ -34,10 +34,7 @@ namespace Ryujinx.Headless.SDL2.Metal
|
||||||
_caMetalLayer = new CAMetalLayer(SDL_Metal_GetLayer(SDL_Metal_CreateView(WindowHandle)));
|
_caMetalLayer = new CAMetalLayer(SDL_Metal_GetLayer(SDL_Metal_CreateView(WindowHandle)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL2Driver.MainThreadDispatcher != null)
|
SDL2Driver.MainThreadDispatcher?.Invoke(CreateLayer);
|
||||||
{
|
|
||||||
SDL2Driver.MainThreadDispatcher(CreateLayer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void InitializeRenderer() { }
|
protected override void InitializeRenderer() { }
|
||||||
|
|
Loading…
Reference in a new issue