protected override void OnUpdate() { if (BuildContext == null) { return; } if (!BuildContext.TryGetComponent <DotsRuntimeBuildProfile>(out var profile)) { return; } if (!AssemblyCache.HasType <PrecompiledShader>()) { return; } if (!AssemblyCache.HasType <SpriteRenderer>()) { return; } InitShaderCompiler(); var rendererTypes = ShaderCompilerClient.GetSupportedPlatforms(profile.Target); CreateShaderDataEntity(ShaderGuid.SpriteDefault, Path.Combine(k_ShaderSourceFolderPath, "SpriteDefault.cg"), rendererTypes); ShutdownShaderCompiler(); }
protected override void OnUpdate() { if (BuildContext == null) { return; } if (!BuildContext.TryGetComponent <DotsRuntimeBuildProfile>(out var profile)) { return; } if (!AssemblyCache.HasType <PrecompiledShader>()) { return; } if (!AssemblyCache.HasType <Text.TextRenderer>()) { return; } InitShaderCompiler(); var platforms = ShaderCompilerClient.GetSupportedPlatforms(profile.Target); CreateShaderDataEntity(BitmapFontMaterial.ShaderGuid, @"Packages/com.unity.tiny/Unity.Tiny.Text.Native/shadersrc~/text.cg", platforms); CreateShaderDataEntity(SDFFontMaterial.ShaderGuid, @"Packages/com.unity.tiny/Unity.Tiny.Text.Native/shadersrc~/textsdf.cg", platforms); ShutdownShaderCompiler(); }
protected override void OnUpdate() { if (BuildContext == null) { return; } if (!BuildContext.TryGetComponent <DotsRuntimeBuildProfile>(out var profile)) { return; } if (!AssemblyCache.HasType <PrecompiledShader>()) { return; } InitShaderCompiler(); bool includeAllPlatform = false; if (BuildContext.TryGetComponent <TinyShaderSettings>(out var shaderSettings)) { includeAllPlatform = shaderSettings.PackageShadersForAllPlatforms; } var platforms = ShaderCompilerClient.GetSupportedPlatforms(profile.Target, includeAllPlatform); CreateShaderDataEntity(BuiltInShaderType.simple, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/simple.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.simplegpuskinning, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/simplegpuskinning.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.simplelit, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/simplelit.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.simplelitgpuskinning, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/simplelitgpuskinning.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.line, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/line.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.zonly, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/zonly.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.blitsrgb, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/blitsrgb.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.shadowmap, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/shadowmap.cg", platforms); CreateShaderDataEntity(BuiltInShaderType.shadowmapgpuskinning, @"Packages/com.unity.tiny/Unity.Tiny.Rendering.Native/shadersrc~/shadowmapgpuskinning.cg", platforms); ShutdownShaderCompiler(); }
protected override void OnUpdate() { if (GetEntityQuery(ComponentType.ReadOnly <UnityEngine.Shader>()).CalculateEntityCount() == 0) { return; } if (!TryGetBuildConfigurationComponent <DotsRuntimeBuildProfile>(out var profile)) { return; } bool includeAllPlatform = false; if (TryGetBuildConfigurationComponent <TinyShaderSettings>(out var shaderSettings)) { includeAllPlatform = shaderSettings.PackageShadersForAllPlatforms; } var platforms = ShaderCompilerClient.GetSupportedPlatforms(profile.Target, includeAllPlatform); var context = new BlobAssetComputationContext <ShaderSettings, PrecompiledShaderPipeline>(BlobAssetStore, 128, Allocator.Temp); Entities.ForEach((UnityEngine.Shader uShader) => { if (MaterialConversion.GetMaterialType(uShader) != MaterialConversion.SupportedMaterialType.Custom) { return; } var entity = GetPrimaryEntity(uShader); // Note: all shader stages are in a single source file string filepath = Path.GetFullPath(AssetDatabase.GetAssetPath(uShader)); if (!File.Exists(filepath)) { throw new InvalidDataException($"Could not open shader file '{filepath}'"); } string shaderSrc = File.ReadAllText(filepath); if (m_Client == null) { InitShaderCompiler(); } m_Client.Preprocess(shaderSrc, filepath, uShader.name, out string hlslSrc, out int startLine, out uint[] includeHash); Hash128 includeHash128 = new Hash128(includeHash[0], includeHash[1], includeHash[2], includeHash[3]); Hash128 hash = new Hash128(); unsafe { fixed(char *p = shaderSrc) { UnityEngine.HashUnsafeUtilities.ComputeHash128(p, (ulong)shaderSrc.Length, &hash); UnityEngine.HashUtilities.AppendHash(ref includeHash128, ref hash); } } context.AssociateBlobAssetWithUnityObject(hash, uShader); if (context.NeedToComputeBlobAsset(hash)) { context.AddBlobAssetToCompute(hash, default); var blobAsset = m_Client.CompileShaderForPlatforms(hlslSrc, platforms, filepath, startLine, uShader.name); if (!blobAsset.IsCreated) { return; } context.AddComputedBlobAsset(hash, blobAsset); } context.GetBlobAsset(hash, out var shaderBlob); DstEntityManager.AddComponentData(entity, new CustomShader { Status = ShaderStatus.Invalid, Name = Path.GetFileNameWithoutExtension(filepath) }); DstEntityManager.AddComponentData(entity, new ShaderBinData { shaders = shaderBlob }); }); ShutdownShaderCompiler(); context.Dispose(); }