< Summary

Class:ShaderVariantTracker
Assembly:ShaderVariantTracker
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Utils/ShaderVariantTracker/ShaderVariantTracker.cs
Covered lines:0
Uncovered lines:16
Coverable lines:16
Total lines:42
Line coverage:0% (0 of 16)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ShaderVariantTracker(...)0%2100%
OnMaterialProcess(...)0%6200%
CreateVariant(...)0%2100%
Dispose()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Rendering/Utils/ShaderVariantTracker/ShaderVariantTracker.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using DCL.Helpers;
 5using UnityEngine;
 6using UnityEngine.Diagnostics;
 7using UnityEngine.Rendering;
 8
 9public class ShaderVariantTracker : IDisposable
 10{
 11    private ShaderVariantCollection collection;
 12
 013    public ShaderVariantTracker (ShaderVariantCollection collection)
 14    {
 015        this.collection = collection;
 16
 017        SRPBatchingHelper.OnMaterialProcess += OnMaterialProcess;
 018    }
 19
 20    private void OnMaterialProcess(Material mat)
 21    {
 022        var variant = CreateVariant(mat);
 23
 024        if ( !collection.Contains(variant) )
 25        {
 026            collection.Add(variant);
 027            var keywordsString = JsonUtility.ToJson(variant.keywords, true);
 028            Debug.Log($"New variant found!\nShader: {variant.shader.name}\nKeywords:{keywordsString}");
 29        }
 030    }
 31
 32    static ShaderVariantCollection.ShaderVariant CreateVariant(Material mat)
 33    {
 034        var result = new ShaderVariantCollection.ShaderVariant();
 035        result.shader = mat.shader;
 036        result.keywords = mat.shaderKeywords;
 037        result.passType = PassType.ScriptableRenderPipeline;
 038        return result;
 39    }
 40
 041    public void Dispose() { SRPBatchingHelper.OnMaterialProcess -= OnMaterialProcess; }
 42}