Skip to content

Commit

Permalink
Merge pull request #5978 from smoogipoo/shader-cache-version
Browse files Browse the repository at this point in the history
Add a cache busting mechanism to the shader compilation cache
  • Loading branch information
peppy authored Aug 23, 2023
2 parents d3ff218 + 88b8555 commit 08fd5fa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions osu.Framework/Graphics/Shaders/ShaderCompilationStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ namespace osu.Framework.Graphics.Shaders
{
public class ShaderCompilationStore
{
/// <summary>
/// A cache-busting mechanism to be used for when the cross-compilation output changes (i.e. a change to the cross-compiler itself), but the input is not affected.
/// </summary>
private const int cache_version = 1;

public Storage? CacheStorage { private get; set; }

public VertexFragmentShaderCompilation CompileVertexFragment(string vertexText, string fragmentText, CrossCompileTarget target)
{
// vertexHash#fragmentHash#target
string filename = $"{vertexText.ComputeMD5Hash()}#{fragmentText.ComputeMD5Hash()}#{(int)target}";
string filename = $"{vertexText.ComputeMD5Hash()}#{fragmentText.ComputeMD5Hash()}#{(int)target}#{cache_version}";

if (tryGetCached(filename, out VertexFragmentShaderCompilation? existing))
{
Expand Down Expand Up @@ -50,7 +55,7 @@ public VertexFragmentShaderCompilation CompileVertexFragment(string vertexText,
public ComputeProgramCompilation CompileCompute(string programText, CrossCompileTarget target)
{
// programHash#target
string filename = $"{programText.ComputeMD5Hash()}#{(int)target}";
string filename = $"{programText.ComputeMD5Hash()}#{(int)target}#{cache_version}";

if (tryGetCached(filename, out ComputeProgramCompilation? existing))
{
Expand Down

0 comments on commit 08fd5fa

Please sign in to comment.