remove cgc (step 1)
This commit is contained in:
parent
1f966a4cc1
commit
b842f3ed16
|
@ -1,144 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
//todo - be able to run out of PATH too
|
||||
|
||||
namespace BizHawk.Bizware.BizwareGL
|
||||
{
|
||||
public class CGC
|
||||
{
|
||||
public CGC()
|
||||
{
|
||||
}
|
||||
|
||||
public static string CGCBinPath;
|
||||
|
||||
private static string[] Escape(IEnumerable<string> args)
|
||||
{
|
||||
return args.Select(s => s.Contains(" ") ? $"\"{s}\"" : s).ToArray();
|
||||
}
|
||||
|
||||
public class Results
|
||||
{
|
||||
public bool Succeeded;
|
||||
public string Code, Errors;
|
||||
public Dictionary<string, string> MapCodeToNative = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> MapNativeToCode = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
readonly Regex rxHlslSamplerCrashWorkaround = new Regex(@"\((.*?)(in sampler2D)(.*?)\)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
|
||||
|
||||
public Results Run(string code, string entry, string profile, bool hlslHacks)
|
||||
{
|
||||
//version=110; GLSL generates old fashioned semantic attributes and not generic attributes
|
||||
string[] args = new[]{"-profile", profile, "-entry", entry, "-po", "version=110"};
|
||||
|
||||
args = Escape(args);
|
||||
StringBuilder sbCmdline = new StringBuilder();
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
{
|
||||
sbCmdline.Append(args[i]);
|
||||
if (i != args.Length - 1) sbCmdline.Append(' ');
|
||||
}
|
||||
|
||||
//http://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why
|
||||
using var proc = new Process
|
||||
{
|
||||
StartInfo =
|
||||
{
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
Arguments = sbCmdline.ToString(),
|
||||
FileName = CGCBinPath
|
||||
}
|
||||
};
|
||||
|
||||
StringBuilder output = new StringBuilder(), error = new StringBuilder();
|
||||
|
||||
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
|
||||
{
|
||||
using var errorWaitHandle = new AutoResetEvent(false);
|
||||
proc.OutputDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data == null) outputWaitHandle.Set();
|
||||
else output.AppendLine(e.Data);
|
||||
};
|
||||
proc.ErrorDataReceived += (sender, e) =>
|
||||
{
|
||||
if (e.Data == null) errorWaitHandle.Set();
|
||||
else error.AppendLine(e.Data);
|
||||
};
|
||||
|
||||
|
||||
proc.Start();
|
||||
new Thread(() =>
|
||||
{
|
||||
proc.StandardInput.AutoFlush = true;
|
||||
proc.StandardInput.Write(code);
|
||||
proc.StandardInput.Flush();
|
||||
proc.StandardInput.Close();
|
||||
}).Start();
|
||||
|
||||
proc.BeginOutputReadLine();
|
||||
proc.BeginErrorReadLine();
|
||||
proc.WaitForExit();
|
||||
outputWaitHandle.WaitOne();
|
||||
errorWaitHandle.WaitOne();
|
||||
}
|
||||
|
||||
bool ok = (proc.ExitCode == 0);
|
||||
|
||||
var ret = new Results
|
||||
{
|
||||
Succeeded = ok,
|
||||
Code = output.ToString(),
|
||||
Errors = error.ToString()
|
||||
};
|
||||
|
||||
if (!ok)
|
||||
Console.WriteLine(ret.Errors);
|
||||
|
||||
if (hlslHacks)
|
||||
{
|
||||
ret.Code = rxHlslSamplerCrashWorkaround.Replace(ret.Code, m => $"({m.Groups[1].Value}uniform sampler2D{m.Groups[3].Value})");
|
||||
}
|
||||
|
||||
//make variable name map
|
||||
//loop until the first line that doesn't start with a comment
|
||||
var reader = new StringReader(ret.Code);
|
||||
for(;;)
|
||||
{
|
||||
var line = reader.ReadLine();
|
||||
if (line == null) break;
|
||||
if (!line.StartsWith("//")) break;
|
||||
if (!line.StartsWith("//var")) continue;
|
||||
var parts = line.Split(':');
|
||||
var native_name = parts[0].Split(' ')[2];
|
||||
var code_name = parts[1].Trim();
|
||||
if (code_name.StartsWith("TEXUNIT")) code_name = ""; //need parsing differently
|
||||
if (code_name == "")
|
||||
code_name = parts[2].Trim();
|
||||
|
||||
// remove some array indicators. example: `modelViewProj1[0], 4`
|
||||
code_name = code_name.Split(',')[0];
|
||||
code_name = code_name.Split(' ')[0];
|
||||
if (code_name != "")
|
||||
{
|
||||
ret.MapCodeToNative[code_name] = native_name;
|
||||
ret.MapNativeToCode[native_name] = code_name;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,8 +45,8 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
psProgram = DefaultPixelShader_gl;
|
||||
}
|
||||
|
||||
var vs = Owner.CreateVertexShader(false, vsProgram, "vsmain", true);
|
||||
var ps = Owner.CreateFragmentShader(false, psProgram, "psmain", true);
|
||||
var vs = Owner.CreateVertexShader(vsProgram, "vsmain", true);
|
||||
var ps = Owner.CreateFragmentShader(psProgram, "psmain", true);
|
||||
CurrPipeline = DefaultPipeline = Owner.CreatePipeline(VertexLayout, vs, ps, true, "xgui");
|
||||
}
|
||||
|
||||
|
|
|
@ -31,12 +31,12 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
/// <summary>
|
||||
/// compile a fragment shader. This is the simplified method. A more complex method may be added later which will accept multiple sources and preprocessor definitions independently
|
||||
/// </summary>
|
||||
Shader CreateFragmentShader(bool cg, string source, string entry, bool required);
|
||||
Shader CreateFragmentShader(string source, string entry, bool required);
|
||||
|
||||
/// <summary>
|
||||
/// compile a vertex shader. This is the simplified method. A more complex method may be added later which will accept multiple sources and preprocessor definitions independently
|
||||
/// </summary>
|
||||
Shader CreateVertexShader(bool cg, string source, string entry, bool required);
|
||||
Shader CreateVertexShader(string source, string entry, bool required);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a complete pipeline from the provided vertex and fragment shader handles
|
||||
|
|
|
@ -26,8 +26,8 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
string defines = "#define TEXCOORD TEXCOORD0\r\n"; //maybe not safe..
|
||||
string vsSource = $"#define VERTEX\r\n{defines}{source}";
|
||||
string psSource = $"#define FRAGMENT\r\n{defines}{source}";
|
||||
var vs = owner.CreateVertexShader(true, vsSource, "main_vertex", debug);
|
||||
var ps = owner.CreateFragmentShader(true, psSource, "main_fragment", debug);
|
||||
var vs = owner.CreateVertexShader(vsSource, "main_vertex", debug);
|
||||
var ps = owner.CreateFragmentShader(psSource, "main_fragment", debug);
|
||||
Pipeline = Owner.CreatePipeline(VertexLayout, vs, ps, debug, "retro");
|
||||
|
||||
if (!Pipeline.Available)
|
||||
|
|
|
@ -59,8 +59,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
tw.Dispose();
|
||||
}
|
||||
|
||||
public Shader CreateFragmentShader(bool cg, string source, string entry, bool required) => null;
|
||||
public Shader CreateVertexShader(bool cg, string source, string entry, bool required) => null;
|
||||
public Shader CreateFragmentShader(string source, string entry, bool required) => null;
|
||||
public Shader CreateVertexShader(string source, string entry, bool required) => null;
|
||||
|
||||
public void SetBlendState(IBlendState rsBlend)
|
||||
{
|
||||
|
|
|
@ -160,43 +160,21 @@ namespace BizHawk.Client.EmuHawk
|
|||
public VertexShader vs;
|
||||
public PixelShader ps;
|
||||
public Shader IGLShader;
|
||||
public Dictionary<string, string> MapCodeToNative;
|
||||
public Dictionary<string, string> MapNativeToCode;
|
||||
}
|
||||
|
||||
/// <exception cref="InvalidOperationException"><paramref name="required"/> is <see langword="true"/> and compilation error occurred</exception>
|
||||
public Shader CreateFragmentShader(bool cg, string source, string entry, bool required)
|
||||
public Shader CreateFragmentShader(string source, string entry, bool required)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sw = new ShaderWrapper();
|
||||
if (cg)
|
||||
{
|
||||
var cgc = new CGC();
|
||||
var results = cgc.Run(source, entry, "hlslf", true);
|
||||
source = results.Code;
|
||||
entry = "main";
|
||||
if (!results.Succeeded)
|
||||
{
|
||||
if (required) throw new InvalidOperationException(results.Errors);
|
||||
return new Shader(this, null, false);
|
||||
}
|
||||
|
||||
sw.MapCodeToNative = results.MapCodeToNative;
|
||||
sw.MapNativeToCode = results.MapNativeToCode;
|
||||
}
|
||||
|
||||
string errors = null;
|
||||
ShaderBytecode byteCode;
|
||||
|
||||
try
|
||||
{
|
||||
// cgc can create shaders that will need backwards compatibility...
|
||||
string profile = "ps_1_0";
|
||||
if (cg)
|
||||
{
|
||||
profile = "ps_3_0"; //todo - smarter logic somehow
|
||||
}
|
||||
string profile = "ps_3_0";
|
||||
|
||||
// ShaderFlags.EnableBackwardsCompatibility - used this once upon a time (please leave a note about why)
|
||||
byteCode = ShaderBytecode.Compile(source, null, null, entry, profile, ShaderFlags.UseLegacyD3DX9_31Dll, out errors);
|
||||
|
@ -224,39 +202,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
|
||||
/// <exception cref="InvalidOperationException"><paramref name="required"/> is <see langword="true"/> and compilation error occurred</exception>
|
||||
public Shader CreateVertexShader(bool cg, string source, string entry, bool required)
|
||||
public Shader CreateVertexShader(string source, string entry, bool required)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sw = new ShaderWrapper();
|
||||
if (cg)
|
||||
{
|
||||
var cgc = new CGC();
|
||||
var results = cgc.Run(source, entry, "hlslv", true);
|
||||
source = results.Code;
|
||||
entry = "main";
|
||||
if (!results.Succeeded)
|
||||
{
|
||||
if (required) throw new InvalidOperationException(results.Errors);
|
||||
return new Shader(this, null, false);
|
||||
}
|
||||
|
||||
sw.MapCodeToNative = results.MapCodeToNative;
|
||||
sw.MapNativeToCode = results.MapNativeToCode;
|
||||
}
|
||||
|
||||
string errors = null;
|
||||
ShaderBytecode byteCode;
|
||||
|
||||
try
|
||||
{
|
||||
// cgc can create shaders that will need backwards compatibility...
|
||||
string profile = "vs_1_1";
|
||||
if (cg)
|
||||
{
|
||||
profile = "vs_3_0"; //todo - smarter logic somehow
|
||||
}
|
||||
|
||||
string profile = "vs_3_0";
|
||||
byteCode = ShaderBytecode.Compile(source, null, null, entry, profile, ShaderFlags.EnableBackwardsCompatibility, out errors);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -480,16 +436,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
ui.Opaque = uw;
|
||||
string name = prefix + descr.Name;
|
||||
|
||||
// meh not happy about this stuff
|
||||
if (fs.MapCodeToNative != null || vs.MapCodeToNative != null)
|
||||
{
|
||||
string key = name.TrimStart('$');
|
||||
if (descr.Rows != 1)
|
||||
key += "[0]";
|
||||
if (fs.MapCodeToNative != null && ct == fsct) if (fs.MapCodeToNative.ContainsKey(key)) name = fs.MapCodeToNative[key];
|
||||
if (vs.MapCodeToNative != null && ct == vsct) if (vs.MapCodeToNative.ContainsKey(key)) name = vs.MapCodeToNative[key];
|
||||
}
|
||||
|
||||
ui.Name = name;
|
||||
uw.Description = descr;
|
||||
uw.EffectHandle = handle;
|
||||
|
|
|
@ -125,14 +125,14 @@ namespace BizHawk.Client.EmuHawk
|
|||
GL.DeleteTexture((int)tex.Opaque);
|
||||
}
|
||||
|
||||
public Shader CreateFragmentShader(bool cg, string source, string entry, bool required)
|
||||
public Shader CreateFragmentShader(string source, string entry, bool required)
|
||||
{
|
||||
return CreateShader(cg, ShaderType.FragmentShader, source, entry, required);
|
||||
return CreateShader(ShaderType.FragmentShader, source, entry, required);
|
||||
}
|
||||
|
||||
public Shader CreateVertexShader(bool cg, string source, string entry, bool required)
|
||||
public Shader CreateVertexShader(string source, string entry, bool required)
|
||||
{
|
||||
return CreateShader(cg, ShaderType.VertexShader, source, entry, required);
|
||||
return CreateShader(ShaderType.VertexShader, source, entry, required);
|
||||
}
|
||||
|
||||
public IBlendState CreateBlendState(BlendingFactorSrc colorSource, BlendEquationMode colorEquation, BlendingFactorDest colorDest,
|
||||
|
@ -691,25 +691,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
return glc;
|
||||
}
|
||||
|
||||
Shader CreateShader(bool cg, ShaderType type, string source, string entry, bool required)
|
||||
Shader CreateShader(ShaderType type, string source, string entry, bool required)
|
||||
{
|
||||
var sw = new ShaderWrapper();
|
||||
if (cg)
|
||||
{
|
||||
var cgc = new CGC();
|
||||
var results = cgc.Run(source, entry, type == ShaderType.FragmentShader ? "glslf" : "glslv", false);
|
||||
|
||||
if (!results.Succeeded)
|
||||
{
|
||||
Console.WriteLine("CGC failed");
|
||||
Console.WriteLine(results.Errors);
|
||||
return new Shader(this, null, false);
|
||||
}
|
||||
|
||||
source = results.Code;
|
||||
sw.MapCodeToNative = results.MapCodeToNative;
|
||||
sw.MapNativeToCode = results.MapNativeToCode;
|
||||
}
|
||||
|
||||
int sid = GL.CreateShader(type);
|
||||
bool ok = CompileShaderSimple(sid, source, required);
|
||||
|
|
|
@ -314,7 +314,6 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
// TODO GL - a lot of disorganized wiring-up here
|
||||
// installed separately on Unix (via package manager or from https://developer.nvidia.com/cg-toolkit-download), look in $PATH
|
||||
CGC.CGCBinPath = OSTailoredCode.IsUnixHost ? "cgc" : Path.Combine(PathUtils.DllDirectoryPath, "cgc.exe");
|
||||
PresentationPanel = new PresentationPanel(this, Config, GlobalWin.GL)
|
||||
{
|
||||
GraphicsControl = { MainWindow = true }
|
||||
|
|
|
@ -2,24 +2,24 @@
|
|||
|
||||
./configure-for-waterbox-phase--
|
||||
cd build-
|
||||
make
|
||||
make -j
|
||||
make install
|
||||
cd ..
|
||||
|
||||
./configure-for-waterbox-phase-0
|
||||
cd build0
|
||||
make
|
||||
make -j
|
||||
make install
|
||||
cd ..
|
||||
|
||||
./configure-for-waterbox-phase-1
|
||||
cd build1
|
||||
make
|
||||
make -j
|
||||
make install
|
||||
cd ..
|
||||
|
||||
./configure-for-waterbox-phase-2
|
||||
cd build2
|
||||
make
|
||||
make -j
|
||||
make install
|
||||
cd ..
|
||||
|
|
|
@ -1,13 +1,25 @@
|
|||
This is the native side of the experimental "waterbox" project for bizhawk.
|
||||
It consists of a modified musl libc, and build scripts to tie it all together.
|
||||
|
||||
How to use:
|
||||
The prescribed possibilities are not exhaustive. Other platforms may work.
|
||||
Here is what we're supporting:
|
||||
|
||||
1. Get a full Bizhawk checkout.
|
||||
* This needs to be in an NTFS path which is then foreign mounted in WSL2
|
||||
2. Get WSL2 + Ubuntu 20.4LTS
|
||||
* Other combinations may work. Shrug.
|
||||
3. Start running commands:
|
||||
PREPARE A WIN10 VM:
|
||||
1. Make sure the VM has virtualization enabled on the guest. For example in VMWare Workstation, "Virtualize Intel VT-X/EPT or AMD-V/RVI"
|
||||
2. Follow WIN10 Workstation preparation guide
|
||||
3. If you wish to clone bizhawk on your host system, you can use a VMWare shared folder and: `sudo mount -t drvfs Z: /mnt/z -o metadata` (WSL won't auto-mount the shared drive)
|
||||
3b. NO: it doesnt work. using `sudo nano /etc/fstab` you can add a line in this format: `Z: /mnt/z drvfs rw,relatime 0 0` (and then reboot your windows system) to get it to auto-mount
|
||||
|
||||
PREPARE A WIN10 WORKSTATION:
|
||||
|
||||
Using the guidance at (https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel & https://docs.microsoft.com/en-us/windows/wsl/install-win10):
|
||||
1. Install WSL2
|
||||
2. Install Ubuntu 20.04 LTS (https://www.microsoft.com/en-us/p/ubuntu-2004-lts/9n6svws3rx71)
|
||||
3. Clone the bizhawk repository. You can use it through /mnt or /home if you really like
|
||||
4. Install build tools: sudo apt-get update && sudo apt-get install gcc g++ make cmake
|
||||
5. Read the documentation in libcxx directory. Be prepared by having llvm-project in the correct location
|
||||
6. Build waterbox framework libraries and such:
|
||||
NOTE:
|
||||
|
||||
cd musl
|
||||
./configure-for-waterbox
|
||||
|
|
Loading…
Reference in New Issue