retro shaders no longer need sampler to be named s_p

This commit is contained in:
zeromus 2015-10-15 20:10:58 -05:00
parent 7f5546fac4
commit 19b3f8b205
6 changed files with 49 additions and 4 deletions

View File

@ -51,6 +51,8 @@ namespace BizHawk.Client.EmuHawk.Filters
Shaders[i] = shader;
if (!shader.Pipeline.Available)
ok = false;
if (!shader.Available)
ok = false;
}
Available = ok;

View File

@ -311,6 +311,8 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK
if (type == ActiveUniformType.Sampler2D)
{
ui.IsSampler = true;
ui.Index = loc;
ui.Opaque = loc | (samplers.Count << 24);
samplers.Add(loc);
}

View File

@ -476,7 +476,11 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.SlimDX
uw.FS = (ct == fsct);
uw.CT = ct;
if (descr.Type == ParameterType.Sampler2D)
{
ui.IsSampler = true;
ui.Index = descr.RegisterIndex;
uw.SamplerIndex = descr.RegisterIndex;
}
uniforms.Add(ui);
}
}

View File

@ -69,6 +69,15 @@ namespace BizHawk.Bizware.BizwareGL
SpecialWorkingDictionary UniformsDictionary;
IDictionary<string, PipelineUniform> Uniforms { get { return UniformsDictionary; } }
public IEnumerable<PipelineUniform> GetUniforms() { return Uniforms.Values; }
public PipelineUniform TryGetUniform(string name)
{
PipelineUniform ret = null;
Uniforms.TryGetValue(name,out ret);
return ret;
}
public PipelineUniform this[string key]
{
get { return UniformsDictionary[key]; }

View File

@ -30,7 +30,33 @@ namespace BizHawk.Bizware.BizwareGL
var vs = owner.CreateVertexShader(true, vsSource, "main_vertex", debug);
var ps = owner.CreateFragmentShader(true, psSource, "main_fragment", debug);
Pipeline = Owner.CreatePipeline(VertexLayout, vs, ps, debug, "retro");
}
//retroarch shaders will sometimes not have the right sampler name
//it's unclear whether we should bind to s_p or sampler0
//lets bind to sampler0 in case we dont have s_p
sampler0 = Pipeline.TryGetUniform("s_p");
if (sampler0 == null)
{
//sampler wasn't named correctly. this can happen on some retroarch shaders
foreach (var u in Pipeline.GetUniforms())
{
if (u.Sole.IsSampler && u.Sole.Index == 0)
{
sampler0 = u;
break;
}
}
}
if (sampler0 == null)
return;
Available = true;
}
public bool Available { get; private set; }
PipelineUniform sampler0;
public void Dispose()
{
@ -64,9 +90,9 @@ namespace BizHawk.Bizware.BizwareGL
mat.Transpose();
Pipeline["modelViewProj"].Set(mat, true);
Owner.SetTextureWrapMode(tex, true);
Pipeline["s_p"].Set(tex);
Owner.SetTextureWrapMode(tex, true);
sampler0.Set(tex);
Owner.SetViewport(OutputSize);
int w = OutputSize.Width;

View File

@ -7,5 +7,7 @@ namespace BizHawk.Bizware.BizwareGL
{
public object Opaque;
public string Name;
public int Index;
public bool IsSampler;
}
}