Refactor shader GPU state and memory access (#1203)
* Refactor shader GPU state and memory access * Fix NVDEC project build * Address PR feedback and add missing XML comments
This commit is contained in:
parent
7f500e7cae
commit
b8eb6abecc
35 changed files with 633 additions and 684 deletions
|
@ -1,4 +1,3 @@
|
|||
using Ryujinx.Graphics.Shader.Translation;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
|
@ -11,13 +10,19 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
{
|
||||
private string _runtimeDir;
|
||||
private string _dumpPath;
|
||||
private int _dumpIndex;
|
||||
|
||||
public int CurrentDumpIndex => _dumpIndex;
|
||||
/// <summary>
|
||||
/// Current index of the shader dump binary file.
|
||||
/// This is incremented after each save, in order to give unique names to the files.
|
||||
/// </summary>
|
||||
public int CurrentDumpIndex { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the shader dumper.
|
||||
/// </summary>
|
||||
public ShaderDumper()
|
||||
{
|
||||
_dumpIndex = 1;
|
||||
CurrentDumpIndex = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -27,7 +32,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// <param name="compute">True for compute shader code, false for graphics shader code</param>
|
||||
/// <param name="fullPath">Output path for the shader code with header included</param>
|
||||
/// <param name="codePath">Output path for the shader code without header</param>
|
||||
public void Dump(ReadOnlySpan<byte> code, bool compute, out string fullPath, out string codePath)
|
||||
public void Dump(byte[] code, bool compute, out string fullPath, out string codePath)
|
||||
{
|
||||
_dumpPath = GraphicsConfig.ShadersDumpPath;
|
||||
|
||||
|
@ -39,38 +44,34 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
return;
|
||||
}
|
||||
|
||||
string fileName = "Shader" + _dumpIndex.ToString("d4") + ".bin";
|
||||
string fileName = "Shader" + CurrentDumpIndex.ToString("d4") + ".bin";
|
||||
|
||||
fullPath = Path.Combine(FullDir(), fileName);
|
||||
codePath = Path.Combine(CodeDir(), fileName);
|
||||
|
||||
_dumpIndex++;
|
||||
CurrentDumpIndex++;
|
||||
|
||||
code = Translator.ExtractCode(code, compute, out int headerSize);
|
||||
using MemoryStream stream = new MemoryStream(code);
|
||||
BinaryReader codeReader = new BinaryReader(stream);
|
||||
|
||||
using (MemoryStream stream = new MemoryStream(code.ToArray()))
|
||||
using FileStream fullFile = File.Create(fullPath);
|
||||
using FileStream codeFile = File.Create(codePath);
|
||||
BinaryWriter fullWriter = new BinaryWriter(fullFile);
|
||||
BinaryWriter codeWriter = new BinaryWriter(codeFile);
|
||||
|
||||
int headerSize = compute ? 0 : 0x50;
|
||||
|
||||
fullWriter.Write(codeReader.ReadBytes(headerSize));
|
||||
|
||||
byte[] temp = codeReader.ReadBytes(code.Length - headerSize);
|
||||
|
||||
fullWriter.Write(temp);
|
||||
codeWriter.Write(temp);
|
||||
|
||||
// Align to meet nvdisasm requirements.
|
||||
while (codeFile.Length % 0x20 != 0)
|
||||
{
|
||||
BinaryReader codeReader = new BinaryReader(stream);
|
||||
|
||||
using (FileStream fullFile = File.Create(fullPath))
|
||||
using (FileStream codeFile = File.Create(codePath))
|
||||
{
|
||||
BinaryWriter fullWriter = new BinaryWriter(fullFile);
|
||||
BinaryWriter codeWriter = new BinaryWriter(codeFile);
|
||||
|
||||
fullWriter.Write(codeReader.ReadBytes(headerSize));
|
||||
|
||||
byte[] temp = codeReader.ReadBytes(code.Length - headerSize);
|
||||
|
||||
fullWriter.Write(temp);
|
||||
codeWriter.Write(temp);
|
||||
|
||||
// Align to meet nvdisasm requirements.
|
||||
while (codeFile.Length % 0x20 != 0)
|
||||
{
|
||||
codeWriter.Write(0);
|
||||
}
|
||||
}
|
||||
codeWriter.Write(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue