improve d3d shader compatibility: add workaround to replace "in sampler2D", a magic phrase which crashes the hlsl compiler, with "uniform sampler2D", a magic phrase which soothes the hlsl compiler

This commit is contained in:
zeromus 2015-10-20 21:21:07 -05:00
parent 3dd0ab2008
commit 1dfa0f7fc0
3 changed files with 13 additions and 6 deletions

View File

@ -677,7 +677,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
if (cg)
{
var cgc = new CGC();
var results = cgc.Run(source, entry, type == ShaderType.FragmentShader ? "glslf" : "glslv");
var results = cgc.Run(source, entry, type == ShaderType.FragmentShader ? "glslf" : "glslv", false);
if (!results.Succeeded)
return new Shader(this, null, false);

View File

@ -169,7 +169,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX
if (cg)
{
var cgc = new CGC();
var results = cgc.Run(source, entry, "hlslf");
var results = cgc.Run(source, entry, "hlslf", true);
source = results.Code;
entry = "main";
if (!results.Succeeded)
@ -222,7 +222,7 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX
if (cg)
{
var cgc = new CGC();
var results = cgc.Run(source, entry, "hlslv");
var results = cgc.Run(source, entry, "hlslv", true);
source = results.Code;
entry = "main";
if (!results.Succeeded)

View File

@ -5,6 +5,7 @@ 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
@ -29,9 +30,11 @@ namespace BizHawk.Bizware.BizwareGL
public string Code, Errors;
public Dictionary<string, string> MapCodeToNative = new Dictionary<string, string>();
public Dictionary<string, string> MapNativeToCode = new Dictionary<string, string>();
}
}
Regex rxHlslSamplerCrashWorkaround = new Regex(@"\((.*?)(in sampler2D)(.*?)\)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
public Results Run(string code, string entry, string profile)
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"};
@ -100,6 +103,11 @@ namespace BizHawk.Bizware.BizwareGL
if (!ok)
Console.WriteLine(ret.Errors);
if (hlslHacks)
{
ret.Code = rxHlslSamplerCrashWorkaround.Replace(ret.Code, m => string.Format("({0}uniform sampler2D{1})", m.Groups[1].Value, m.Groups[3].Value));
}
//make variable name map
//loop until the first line that doesnt start with a comment
var reader = new StringReader(ret.Code);
@ -127,7 +135,6 @@ namespace BizHawk.Bizware.BizwareGL
return ret;
}
}
}
}