mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-26 20:13:01 +00:00
80a879cb44
* Added .ToString overrides, to help diagnose and debug SpirV generated code. * Added Spirv to team shared dictionary, so the word will not show up as a warning. * Fixed bug where we were creating invalid constants (bool 0i and float 0i) * Update Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * Update Spv.Generator/Instruction.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * Adjusted spacing to match style of the rest of the code. * Added handler for FP64(double) as well, for undefined aggregate types. * Made the operand labels a static dictionary, to avoid re-allocation on each call. Replaced Contains/Get with a TryGetValue, to reduce the number of dictionary lookups. * Added newline between AllOperands and ToString(). Co-authored-by: gdkchan <gab.dark.100@gmail.com>
54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace Spv.Generator
|
|
{
|
|
public class LiteralString : Operand, IEquatable<LiteralString>
|
|
{
|
|
public OperandType Type => OperandType.String;
|
|
|
|
private string _value;
|
|
|
|
public LiteralString(string value)
|
|
{
|
|
_value = value;
|
|
}
|
|
|
|
public ushort WordCount => (ushort)(_value.Length / 4 + 1);
|
|
|
|
public void WriteOperand(BinaryWriter writer)
|
|
{
|
|
writer.Write(_value.AsSpan());
|
|
|
|
// String must be padded to the word size (which is 4 bytes).
|
|
int paddingSize = 4 - (Encoding.ASCII.GetByteCount(_value) % 4);
|
|
|
|
Span<byte> padding = stackalloc byte[paddingSize];
|
|
|
|
writer.Write(padding);
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return obj is LiteralString literalString && Equals(literalString);
|
|
}
|
|
|
|
public bool Equals(LiteralString cmpObj)
|
|
{
|
|
return Type == cmpObj.Type && _value.Equals(cmpObj._value);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return DeterministicHashCode.Combine(Type, DeterministicHashCode.GetHashCode(_value));
|
|
}
|
|
|
|
public bool Equals(Operand obj)
|
|
{
|
|
return obj is LiteralString literalString && Equals(literalString);
|
|
}
|
|
|
|
public override string ToString() => _value;
|
|
}
|
|
}
|