mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-01-07 16:33:05 +00:00
5626f2ca1c
* Introduce ResourceLayout * Part 1: Use new ResourceSegments array on UpdateAndBind * Part 2: Use ResourceLayout to build PipelineLayout * Delete old code * XML docs * Fix shader cache load NRE * Fix typo
51 lines
No EOL
1.5 KiB
C#
51 lines
No EOL
1.5 KiB
C#
using Ryujinx.Common;
|
|
using Ryujinx.Common.Memory;
|
|
using Ryujinx.Graphics.GAL;
|
|
using Ryujinx.Graphics.Shader;
|
|
using Ryujinx.Graphics.Shader.Translation;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
|
|
{
|
|
static class ShaderBinarySerializer
|
|
{
|
|
public static byte[] Pack(ShaderSource[] sources)
|
|
{
|
|
using MemoryStream output = MemoryStreamManager.Shared.GetStream();
|
|
|
|
output.Write(sources.Length);
|
|
|
|
foreach (ShaderSource source in sources)
|
|
{
|
|
output.Write((int)source.Stage);
|
|
output.Write(source.BinaryCode.Length);
|
|
output.Write(source.BinaryCode);
|
|
}
|
|
|
|
return output.ToArray();
|
|
}
|
|
|
|
public static ShaderSource[] Unpack(CachedShaderStage[] stages, byte[] code)
|
|
{
|
|
using MemoryStream input = new MemoryStream(code);
|
|
using BinaryReader reader = new BinaryReader(input);
|
|
|
|
List<ShaderSource> output = new List<ShaderSource>();
|
|
|
|
int count = reader.ReadInt32();
|
|
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
ShaderStage stage = (ShaderStage)reader.ReadInt32();
|
|
int binaryCodeLength = reader.ReadInt32();
|
|
byte[] binaryCode = reader.ReadBytes(binaryCodeLength);
|
|
|
|
output.Add(new ShaderSource(binaryCode, stage, TargetLanguage.Spirv));
|
|
}
|
|
|
|
return output.ToArray();
|
|
}
|
|
}
|
|
} |