diff --git a/Assets/Shaders/BizHawk/BizScanlines.cg b/Assets/Shaders/BizHawk/BizScanlines.hlsl similarity index 100% rename from Assets/Shaders/BizHawk/BizScanlines.cg rename to Assets/Shaders/BizHawk/BizScanlines.hlsl diff --git a/Assets/Shaders/BizHawk/bicubic-fast.cg b/Assets/Shaders/BizHawk/bicubic-fast.hlsl similarity index 100% rename from Assets/Shaders/BizHawk/bicubic-fast.cg rename to Assets/Shaders/BizHawk/bicubic-fast.hlsl diff --git a/Assets/Shaders/BizHawk/bicubic-normal.cg b/Assets/Shaders/BizHawk/bicubic-normal.hlsl similarity index 100% rename from Assets/Shaders/BizHawk/bicubic-normal.cg rename to Assets/Shaders/BizHawk/bicubic-normal.hlsl diff --git a/Assets/Shaders/BizHawk/hq2x.cg b/Assets/Shaders/BizHawk/hq2x.hlsl similarity index 100% rename from Assets/Shaders/BizHawk/hq2x.cg rename to Assets/Shaders/BizHawk/hq2x.hlsl diff --git a/src/BizHawk.Bizware.BizwareGL/CGC.cs b/src/BizHawk.Bizware.BizwareGL/CGC.cs deleted file mode 100644 index 0f085bc8ed..0000000000 --- a/src/BizHawk.Bizware.BizwareGL/CGC.cs +++ /dev/null @@ -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 args) - { - return args.Select(s => s.Contains(" ") ? $"\"{s}\"" : s).ToArray(); - } - - public class Results - { - public bool Succeeded; - public string Code, Errors; - public Dictionary MapCodeToNative = new Dictionary(); - public Dictionary MapNativeToCode = new Dictionary(); - } - - 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; - } - } -} diff --git a/src/BizHawk.Bizware.BizwareGL/GuiRenderer.cs b/src/BizHawk.Bizware.BizwareGL/GuiRenderer.cs index 7ff095b4d9..7f18a7ab33 100644 --- a/src/BizHawk.Bizware.BizwareGL/GuiRenderer.cs +++ b/src/BizHawk.Bizware.BizwareGL/GuiRenderer.cs @@ -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"); } diff --git a/src/BizHawk.Bizware.BizwareGL/IGL.cs b/src/BizHawk.Bizware.BizwareGL/IGL.cs index d40e9f3744..a3c886bdcc 100644 --- a/src/BizHawk.Bizware.BizwareGL/IGL.cs +++ b/src/BizHawk.Bizware.BizwareGL/IGL.cs @@ -31,12 +31,12 @@ namespace BizHawk.Bizware.BizwareGL /// /// 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 /// - Shader CreateFragmentShader(bool cg, string source, string entry, bool required); + Shader CreateFragmentShader(string source, string entry, bool required); /// /// 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 /// - Shader CreateVertexShader(bool cg, string source, string entry, bool required); + Shader CreateVertexShader(string source, string entry, bool required); /// /// Creates a complete pipeline from the provided vertex and fragment shader handles diff --git a/src/BizHawk.Bizware.BizwareGL/RetroShader.cs b/src/BizHawk.Bizware.BizwareGL/RetroShader.cs index 201719c050..9f31e5b8d1 100644 --- a/src/BizHawk.Bizware.BizwareGL/RetroShader.cs +++ b/src/BizHawk.Bizware.BizwareGL/RetroShader.cs @@ -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) diff --git a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs index a734f11d32..b86cf79e88 100644 --- a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs +++ b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_GdiPlus.cs @@ -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) { diff --git a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs index eb885304eb..9479fc087b 100644 --- a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs +++ b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_SlimDX9.cs @@ -160,43 +160,21 @@ namespace BizHawk.Client.EmuHawk public VertexShader vs; public PixelShader ps; public Shader IGLShader; - public Dictionary MapCodeToNative; - public Dictionary MapNativeToCode; } /// is and compilation error occurred - 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 } /// is and compilation error occurred - 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; diff --git a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs index cf8bd09fd1..c4a68e6988 100644 --- a/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs +++ b/src/BizHawk.Client.EmuHawk/GraphicsImplementations/IGL_TK.cs @@ -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); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index a2c3ab1a9a..2e2591c3b4 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -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 } diff --git a/waterbox/libcxx/do-everything.sh b/waterbox/libcxx/do-everything.sh index cf3a59cc7f..d38c04e512 100644 --- a/waterbox/libcxx/do-everything.sh +++ b/waterbox/libcxx/do-everything.sh @@ -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 .. diff --git a/waterbox/readme.txt b/waterbox/readme.txt index c5b792629b..306fac911c 100644 --- a/waterbox/readme.txt +++ b/waterbox/readme.txt @@ -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