Avoid querying and setting texture bindings in hot code (#376)
This commit is contained in:
parent
57dfa09e3a
commit
1cd7aaf504
3 changed files with 29 additions and 13 deletions
|
@ -11,8 +11,6 @@ namespace Ryujinx.Graphics.Gal
|
||||||
IEnumerable<ShaderDeclInfo> GetConstBufferUsage(long Key);
|
IEnumerable<ShaderDeclInfo> GetConstBufferUsage(long Key);
|
||||||
IEnumerable<ShaderDeclInfo> GetTextureUsage(long Key);
|
IEnumerable<ShaderDeclInfo> GetTextureUsage(long Key);
|
||||||
|
|
||||||
void EnsureTextureBinding(string UniformName, int Value);
|
|
||||||
|
|
||||||
void Bind(long Key);
|
void Bind(long Key);
|
||||||
|
|
||||||
void Unbind(GalShaderType Type);
|
void Unbind(GalShaderType Type);
|
||||||
|
|
|
@ -96,15 +96,6 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
return Enumerable.Empty<ShaderDeclInfo>();
|
return Enumerable.Empty<ShaderDeclInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnsureTextureBinding(string UniformName, int Value)
|
|
||||||
{
|
|
||||||
BindProgram();
|
|
||||||
|
|
||||||
int Location = GL.GetUniformLocation(CurrentProgramHandle, UniformName);
|
|
||||||
|
|
||||||
GL.Uniform1(Location, Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe void SetFlip(float X, float Y)
|
public unsafe void SetFlip(float X, float Y)
|
||||||
{
|
{
|
||||||
BindProgram();
|
BindProgram();
|
||||||
|
@ -188,6 +179,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
CheckProgramLink(Handle);
|
CheckProgramLink(Handle);
|
||||||
|
|
||||||
BindUniformBlocks(Handle);
|
BindUniformBlocks(Handle);
|
||||||
|
BindTextureLocations(Handle);
|
||||||
|
|
||||||
Programs.Add(Current, Handle);
|
Programs.Add(Current, Handle);
|
||||||
}
|
}
|
||||||
|
@ -258,6 +250,34 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
||||||
BindUniformBlocksIfNotNull(Current.Fragment);
|
BindUniformBlocksIfNotNull(Current.Fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BindTextureLocations(int ProgramHandle)
|
||||||
|
{
|
||||||
|
int Index = 0;
|
||||||
|
|
||||||
|
void BindTexturesIfNotNull(OGLShaderStage Stage)
|
||||||
|
{
|
||||||
|
if (Stage != null)
|
||||||
|
{
|
||||||
|
foreach (ShaderDeclInfo Decl in Stage.TextureUsage)
|
||||||
|
{
|
||||||
|
int Location = GL.GetUniformLocation(ProgramHandle, Decl.Name);
|
||||||
|
|
||||||
|
GL.Uniform1(Location, Index);
|
||||||
|
|
||||||
|
Index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GL.UseProgram(ProgramHandle);
|
||||||
|
|
||||||
|
BindTexturesIfNotNull(Current.Vertex);
|
||||||
|
BindTexturesIfNotNull(Current.TessControl);
|
||||||
|
BindTexturesIfNotNull(Current.TessEvaluation);
|
||||||
|
BindTexturesIfNotNull(Current.Geometry);
|
||||||
|
BindTexturesIfNotNull(Current.Fragment);
|
||||||
|
}
|
||||||
|
|
||||||
private static void CheckProgramLink(int Handle)
|
private static void CheckProgramLink(int Handle)
|
||||||
{
|
{
|
||||||
int Status = 0;
|
int Status = 0;
|
||||||
|
|
|
@ -442,8 +442,6 @@ namespace Ryujinx.HLE.Gpu.Engines
|
||||||
|
|
||||||
UploadTexture(Vmm, TexIndex, TextureHandle);
|
UploadTexture(Vmm, TexIndex, TextureHandle);
|
||||||
|
|
||||||
Gpu.Renderer.Shader.EnsureTextureBinding(DeclInfo.Name, TexIndex);
|
|
||||||
|
|
||||||
TexIndex++;
|
TexIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue