public void OnProcessComputeShader(ComputeShader shader, string kernelName, IList <ShaderCompilerData> inputData) { if (HDRenderPipeline.currentAsset == null) { return; } if (HDRenderPipelineGlobalSettings.Ensure(canCreateNewAsset: false) == null) { return; } // Discard any compute shader use for raytracing if none of the RP asset required it ComputeShader unused; if (!ShaderBuildPreprocessor.playerNeedRaytracing && ShaderBuildPreprocessor.computeShaderCache.TryGetValue(shader.GetInstanceID(), out unused)) { return; } var exportLog = ShaderBuildPreprocessor.hdrpAssets.Count > 0 && (HDRenderPipelineGlobalSettings.instance.shaderVariantLogLevel != ShaderVariantLogLevel.Disabled); Stopwatch shaderStripingWatch = new Stopwatch(); shaderStripingWatch.Start(); using (new ExportComputeShaderStrip(exportLog, "Temp/compute-shader-strip.json", shader, kernelName, inputData, this)) { var inputShaderVariantCount = inputData.Count; var hdPipelineAssets = ShaderBuildPreprocessor.hdrpAssets; if (hdPipelineAssets.Count == 0) { return; } uint preStrippingCount = (uint)inputData.Count; for (int i = 0; i < inputShaderVariantCount;) { ShaderCompilerData input = inputData[i]; bool removeInput = true; foreach (var hdAsset in hdPipelineAssets) { if (!StripShader(hdAsset, shader, kernelName, input)) { removeInput = false; break; } } if (removeInput) { inputData[i] = inputData[--inputShaderVariantCount]; } else { ++i; } } if (inputData is List <ShaderCompilerData> inputDataList) { inputDataList.RemoveRange(inputShaderVariantCount, inputDataList.Count - inputShaderVariantCount); } else { for (int i = inputData.Count - 1; i >= inputShaderVariantCount; --i) { inputData.RemoveAt(i); } } if (HDRenderPipelineGlobalSettings.instance.shaderVariantLogLevel != ShaderVariantLogLevel.Disabled) { foreach (var hdAsset in hdPipelineAssets) { m_TotalVariantsInputCount += preStrippingCount; m_TotalVariantsOutputCount += (uint)inputData.Count; LogShaderVariants(shader, kernelName, HDRenderPipelineGlobalSettings.instance.shaderVariantLogLevel, preStrippingCount, (uint)inputData.Count); } } } }
private void ShowCompiledCodeSection(ComputeShader cs) { ComputeShaderImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(cs.GetInstanceID())) as ComputeShaderImporter; s_PreprocessOnly = EditorGUILayout.Toggle(Styles.togglePreprocess, s_PreprocessOnly); if (s_PreprocessOnly) { s_StripLineDirectives = EditorGUILayout.Toggle(Styles.toggleStripLineDirective, s_StripLineDirectives); } GUILayout.Space(kSpace); if (GUILayout.Button(Styles.showCompiled, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { ShaderUtil.OpenCompiledComputeShader(cs, true, s_PreprocessOnly, s_StripLineDirectives); GUIUtility.ExitGUI(); } }
private void ShowCompiledCodeSection(ComputeShader cs) { ComputeShaderImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(cs.GetInstanceID())) as ComputeShaderImporter; using (new EditorGUI.DisabledScope(!EditorSettings.cachingShaderPreprocessor && importer && importer.preprocessorOverride != PreprocessorOverride.ForceCachingPreprocessor)) m_PreprocessOnly = EditorGUILayout.Toggle(Styles.togglePreprocess, m_PreprocessOnly); GUILayout.Space(kSpace); if (GUILayout.Button(Styles.showCompiled, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { ShaderUtil.OpenCompiledComputeShader(cs, true, m_PreprocessOnly); GUIUtility.ExitGUI(); } }
public void OnProcessComputeShader(ComputeShader shader, string kernelName, IList <ShaderCompilerData> inputData) { if (HDRenderPipeline.currentAsset == null) { return; } if (HDRenderPipelineGlobalSettings.Ensure(canCreateNewAsset: false) == null) { return; } // Discard any compute shader use for raytracing if none of the RP asset required it ComputeShader unused; if (!ShaderBuildPreprocessor.playerNeedRaytracing && ShaderBuildPreprocessor.computeShaderCache.TryGetValue(shader.GetInstanceID(), out unused)) { return; } using (new ExportComputeShaderStrip("Temp/compute-shader-strip.json", shader, kernelName, inputData, this)) { var inputShaderVariantCount = inputData.Count; var hdPipelineAssets = ShaderBuildPreprocessor.hdrpAssets; if (hdPipelineAssets.Count == 0) { return; } uint preStrippingCount = (uint)inputData.Count; double stripTimeMs = 0; using (TimedScope.FromRef(ref stripTimeMs)) { for (int i = 0; i < inputShaderVariantCount;) { ShaderCompilerData input = inputData[i]; bool removeInput = true; foreach (var hdAsset in hdPipelineAssets) { if (!StripShader(hdAsset, shader, kernelName, input)) { removeInput = false; break; } } if (removeInput) { inputData[i] = inputData[--inputShaderVariantCount]; } else { ++i; } } if (inputData is List <ShaderCompilerData> inputDataList) { inputDataList.RemoveRange(inputShaderVariantCount, inputDataList.Count - inputShaderVariantCount); } else { for (int i = inputData.Count - 1; i >= inputShaderVariantCount; --i) { inputData.RemoveAt(i); } } } LogShaderVariants(shader, kernelName, preStrippingCount, (uint)inputData.Count, stripTimeMs); } }