/// <summary> /// Creates a new instance of the shader cache. /// </summary> /// <param name="context">GPU context that the shader cache belongs to</param> public ShaderCache(GpuContext context) { _context = context; _dumper = new ShaderDumper(); _cpPrograms = new Dictionary <ulong, List <ShaderBundle> >(); _gpPrograms = new Dictionary <ShaderAddresses, List <ShaderBundle> >(); }
/// <summary> /// Creates a new instance of the shader cache. /// </summary> /// <param name="context">GPU context that the shader cache belongs to</param> public ShaderCache(GpuContext context) { _context = context; _dumper = new ShaderDumper(); _cpPrograms = new Dictionary <ulong, List <ComputeShader> >(); _gpPrograms = new Dictionary <ShaderAddresses, List <GraphicsShader> >(); }
/// <summary> /// Creates a new instance of the shader cache. /// </summary> /// <param name="context">GPU context that the shader cache belongs to</param> public ShaderCache(GpuContext context) { _context = context; _cache = new ShaderMap <Shader>(); _dumper = new ShaderDumper(); Configuration = new ShaderCacheConfiguration(); }
/// <summary> /// Translates a previously generated translator context to something that the host API accepts. /// </summary> /// <param name="dumper">Optional shader code dumper</param> /// <param name="memoryManager">Memory manager used to access the GPU memory where the shader is located</param> /// <param name="stages">Translator context of all available shader stages</param> /// <param name="stageIndex">Index on the stages array to translate</param> /// <returns>Compiled graphics shader code</returns> private static ShaderCodeHolder TranslateShader( ShaderDumper dumper, MemoryManager memoryManager, TranslatorContext[] stages, int stageIndex) { TranslatorContext currentStage = stages[stageIndex]; TranslatorContext nextStage = GetNextStageContext(stages, stageIndex); TranslatorContext vertexA = stageIndex == 1 ? stages[0] : null; return(TranslateShader(dumper, memoryManager, currentStage, nextStage, vertexA)); }
/// <summary> /// Creates a new instance of the shader cache. /// </summary> /// <param name="context">GPU context that the shader cache belongs to</param> public ShaderCache(GpuContext context) { _context = context; _dumper = new ShaderDumper(); _cpPrograms = new Dictionary <ulong, List <ShaderBundle> >(); _gpPrograms = new Dictionary <ShaderAddresses, List <ShaderBundle> >(); _gpProgramsDiskCache = new Dictionary <Hash128, ShaderBundle>(); _cpProgramsDiskCache = new Dictionary <Hash128, ShaderBundle>(); _progressReportEvent = new AutoResetEvent(false); }
/// <summary> /// Translates a previously generated translator context to something that the host API accepts. /// </summary> /// <param name="dumper">Optional shader code dumper</param> /// <param name="memoryManager">Memory manager used to access the GPU memory where the shader is located</param> /// <param name="currentStage">Translator context of the stage to be translated</param> /// <param name="nextStage">Translator context of the next active stage, if existent</param> /// <param name="vertexA">Optional translator context of the shader that should be combined</param> /// <returns>Compiled graphics shader code</returns> private static ShaderCodeHolder TranslateShader( ShaderDumper dumper, MemoryManager memoryManager, TranslatorContext currentStage, TranslatorContext nextStage, TranslatorContext vertexA) { if (currentStage == null) { return(null); } if (vertexA != null) { byte[] codeA = memoryManager.GetSpan(vertexA.Address, vertexA.Size).ToArray(); byte[] codeB = memoryManager.GetSpan(currentStage.Address, currentStage.Size).ToArray(); ShaderDumpPaths pathsA = default; ShaderDumpPaths pathsB = default; if (dumper != null) { pathsA = dumper.Dump(codeA, compute: false); pathsB = dumper.Dump(codeB, compute: false); } ShaderProgram program = currentStage.Translate(out ShaderProgramInfo shaderProgramInfo, nextStage, vertexA); pathsB.Prepend(program); pathsA.Prepend(program); return(new ShaderCodeHolder(program, shaderProgramInfo, codeB, codeA)); } else { byte[] code = memoryManager.GetSpan(currentStage.Address, currentStage.Size).ToArray(); ShaderDumpPaths paths = dumper?.Dump(code, currentStage.Stage == ShaderStage.Compute) ?? default; ShaderProgram program = currentStage.Translate(out ShaderProgramInfo shaderProgramInfo, nextStage); paths.Prepend(program); return(new ShaderCodeHolder(program, shaderProgramInfo, code)); } }
/// <summary> /// Creates a new instance of the shader cache. /// </summary> /// <param name="context">GPU context that the shader cache belongs to</param> public ShaderCache(GpuContext context) { _context = context; _dumper = new ShaderDumper(); _cpPrograms = new Dictionary <ulong, CachedShaderProgram>(); _gpPrograms = new Dictionary <ShaderAddresses, CachedShaderProgram>(); _programsToSaveQueue = new Queue <ProgramToSave>(); string diskCacheTitleId = GetDiskCachePath(); _computeShaderCache = new ComputeShaderCacheHashTable(); _graphicsShaderCache = new ShaderCacheHashTable(); _diskCacheHostStorage = new DiskCacheHostStorage(diskCacheTitleId); if (_diskCacheHostStorage.CacheEnabled) { _cacheWriter = new BackgroundDiskCacheWriter(context, _diskCacheHostStorage); } }
/// <summary> /// Creates a new instance of the shader cache. /// </summary> /// <param name="context">GPU context that the shader cache belongs to</param> public ShaderCache(GpuContext context) { _context = context; _dumper = new ShaderDumper(); _cpPrograms = new Dictionary <ulong, CachedShaderProgram>(); _gpPrograms = new Dictionary <ShaderAddresses, CachedShaderProgram>(); _programsToSaveQueue = new Queue <ProgramToSave>(); string diskCacheTitleId = GraphicsConfig.EnableShaderCache && GraphicsConfig.TitleId != null ? CacheHelper.GetBaseCacheDirectory(GraphicsConfig.TitleId) : null; _computeShaderCache = new ComputeShaderCacheHashTable(); _graphicsShaderCache = new ShaderCacheHashTable(); _diskCacheHostStorage = new DiskCacheHostStorage(diskCacheTitleId); if (_diskCacheHostStorage.CacheEnabled) { _cacheWriter = new BackgroundDiskCacheWriter(context, _diskCacheHostStorage); } }