public void Init() { // Create and mount database file system var objDatabase = ObjectDatabase.CreateDefaultDatabase(); var databaseFileProvider = new DatabaseFileProvider(objDatabase); ContentManager.GetFileProvider = () => databaseFileProvider; Compiler = new EffectCompiler(); Compiler.SourceDirectories.Add("shaders"); MixinParameters = new CompilerParameters(); MixinParameters.EffectParameters.Platform = GraphicsPlatform.Direct3D11; MixinParameters.EffectParameters.Profile = GraphicsProfile.Level_11_0; ResultLogger = new LoggerResult(); }
public static void Main3() { // Create and mount database file system var objDatabase = ObjectDatabase.CreateDefaultDatabase(); var assetIndexMap = AssetIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath); var databaseFileProvider = new DatabaseFileProvider(assetIndexMap, objDatabase); ContentManager.GetFileProvider = () => databaseFileProvider; compiler = new EffectCompiler(); compiler.SourceDirectories.Add("shaders"); var shaderMixinSource = new ShaderMixinSource(); shaderMixinSource.Mixins.Add(new ShaderClassSource("ShaderBase")); shaderMixinSource.Mixins.Add(new ShaderClassSource("TransformationWVP")); shaderMixinSource.Mixins.Add(new ShaderClassSource("ShadingBase")); var shaderMixinSource2 = new ShaderMixinSource(); shaderMixinSource2.Mixins.Add(new ShaderClassSource("ShaderBase")); shaderMixinSource2.Mixins.Add(new ShaderClassSource("TransformationWVP")); shaderMixinSource2.Mixins.Add(new ShaderClassSource("ShadingBase")); shaderMixinSource2.Mixins.Add(new ShaderClassSource("ShadingOverlay")); var allThreads = new List<Thread>(); for (int i = 0; i < NumThreads; ++i) { CompilerThread compilerThread; if (i % 2 == 0) compilerThread = new CompilerThread(compiler, shaderMixinSource); else compilerThread = new CompilerThread(compiler, shaderMixinSource2); allThreads.Add(new Thread(compilerThread.Compile)); } foreach (var thread in allThreads) { thread.Start(); } }
public CompilerThread(EffectCompiler compiler, ShaderMixinSource source) { effectCompiler = compiler; mixinSource = source; }
public void TestMaterial() { var compiler = new EffectCompiler { UseFileSystem = true }; compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Xenko.Graphics\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Xenko.Engine\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Core"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Lights"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Materials"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Shadows"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\ComputeColor"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Skinning"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Shading"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Transformation"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Utils"); var compilerParameters = new CompilerParameters { Platform = GraphicsPlatform.Direct3D11 }; var layers = new MaterialBlendLayers(); layers.Add(new MaterialBlendLayer { BlendMap = new ComputeFloat(0.5f), Material = AttachedReferenceManager.CreateSerializableVersion<Material>(Guid.Empty, "fake") }); var materialAsset = new MaterialAsset { Attributes = new MaterialAttributes() { Diffuse = new MaterialDiffuseMapFeature() { DiffuseMap = new ComputeColor(Color4.White) }, DiffuseModel = new MaterialDiffuseLambertModelFeature() }, Layers = layers }; var fakeAsset = new MaterialAsset { Attributes = new MaterialAttributes() { Diffuse = new MaterialDiffuseMapFeature() { DiffuseMap = new ComputeColor(Color.Blue) }, } }; var context = new MaterialGeneratorContext { FindAsset = reference => fakeAsset }; var result = MaterialGenerator.Generate(new MaterialDescriptor { Attributes = materialAsset.Attributes, Layers = materialAsset.Layers }, context, "TestMaterial"); compilerParameters.Set(MaterialKeys.PixelStageSurfaceShaders, result.Material.Parameters.Get(MaterialKeys.PixelStageSurfaceShaders)); var directionalLightGroup = new ShaderClassSource("LightDirectionalGroup", 1); compilerParameters.Set(LightingKeys.DirectLightGroups, new List<ShaderSource> { directionalLightGroup }); //compilerParameters.Set(LightingKeys.CastShadows, false); //compilerParameters.Set(MaterialParameters.HasSkinningPosition, true); //compilerParameters.Set(MaterialParameters.HasSkinningNormal, true); compilerParameters.Set(MaterialKeys.HasNormalMap, true); var results = compiler.Compile(new ShaderMixinGeneratorSource("XenkoEffectBase"), compilerParameters); Assert.IsFalse(results.HasErrors); }
public void TestShaderCompilation() { var generics = new string[3]; generics[0] = "Texturing.Texture1"; generics[1] = "TEXCOORD0"; generics[2] = "float4(2.0,1,1,1)"; var compilerParameters = new CompilerParameters(); compilerParameters.Set(EffectSourceCodeKeys.Enable, true); compilerParameters.EffectParameters.Profile = GraphicsProfile.Level_11_0; var mixinSource = new ShaderMixinSource { Name = "TestShaderCompilationGenericClass" }; mixinSource.Mixins.Add(new ShaderClassSource("GenericClass2", generics)); var log = new CompilerResults(); var compiler = new EffectCompiler(); compiler.SourceDirectories.Add("shaders"); var effectByteCode = compiler.Compile(mixinSource, compilerParameters.EffectParameters, compilerParameters); }
public void TestNoClean(out CompilerResults left, out CompilerResults right) { // Create and mount database file system var objDatabase = ObjectDatabase.CreateDefaultDatabase(); using (var assetIndexMap = AssetIndexMap.Load(VirtualFileSystem.ApplicationDatabaseIndexPath)) { var database = new DatabaseFileProvider(assetIndexMap, objDatabase); AssetManager.GetFileProvider = () => database; foreach (var shaderName in Directory.EnumerateFiles(@"..\..\sources\shaders", "*.xksl")) CopyStream(database, shaderName); foreach (var shaderName in Directory.EnumerateFiles(@"..\..\sources\engine\SiliconStudio.Xenko.Shaders.Tests\GameAssets\Compiler", "*.xksl")) CopyStream(database, shaderName); var compiler = new EffectCompiler(); compiler.SourceDirectories.Add("assets/shaders"); var compilerCache = new EffectCompilerCache(compiler); var compilerParameters = new CompilerParameters {Platform = GraphicsPlatform.Direct3D11}; left = compilerCache.Compile(new ShaderMixinGeneratorSource("SimpleEffect"), compilerParameters); right = compilerCache.Compile(new ShaderMixinGeneratorSource("SimpleEffect"), compilerParameters); } }
public void TestGlslESCompiler() { VirtualFileSystem.RemountFileSystem("/shaders", "../../../../shaders"); VirtualFileSystem.RemountFileSystem("/baseShaders", "../../../../engine/SiliconStudio.Xenko.Graphics/Shaders"); VirtualFileSystem.RemountFileSystem("/compiler", "Compiler"); var compiler = new EffectCompiler(); compiler.SourceDirectories.Add("shaders"); compiler.SourceDirectories.Add("compiler"); compiler.SourceDirectories.Add("baseShaders"); var compilerParameters = new CompilerParameters { Platform = GraphicsPlatform.OpenGLES }; var results = compiler.Compile(new ShaderMixinGeneratorSource("ToGlslEffect"), compilerParameters); }
public void TestMixinAndComposeKeys() { var compiler = new EffectCompiler { UseFileSystem = true }; compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Xenko.Graphics\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Xenko.Shaders.Tests\GameAssets\Mixins"); var compilerParameters = new CompilerParameters {Platform = GraphicsPlatform.Direct3D11}; var subCompute1Key = TestABC.TestParameters.UseComputeColor2.ComposeWith("SubCompute1"); var subCompute2Key = TestABC.TestParameters.UseComputeColor2.ComposeWith("SubCompute2"); var subComputesKey = TestABC.TestParameters.UseComputeColorRedirect.ComposeWith("SubComputes[0]"); compilerParameters.Set(subCompute1Key, true); compilerParameters.Set(subComputesKey, true); var results = compiler.Compile(new ShaderMixinGeneratorSource("test_mixin_compose_keys"), compilerParameters); Assert.IsFalse(results.HasErrors); var mainBytecode = results.Bytecode.WaitForResult(); Assert.IsFalse(mainBytecode.CompilationLog.HasErrors); Assert.NotNull(mainBytecode.Bytecode.Reflection.ConstantBuffers); Assert.AreEqual(1, mainBytecode.Bytecode.Reflection.ConstantBuffers.Count); var cbuffer = mainBytecode.Bytecode.Reflection.ConstantBuffers[0]; Assert.NotNull(cbuffer.Members); Assert.AreEqual(2, cbuffer.Members.Length); // Check that ComputeColor2.Color is correctly composed for variables var computeColorSubCompute2 = ComputeColor2Keys.Color.ComposeWith("SubCompute1"); var computeColorSubComputes = ComputeColor2Keys.Color.ComposeWith("ColorRedirect.SubComputes[0]"); var members = cbuffer.Members.Select(member => member.Param.KeyName).ToList(); Assert.IsTrue(members.Contains(computeColorSubCompute2.Name)); Assert.IsTrue(members.Contains(computeColorSubComputes.Name)); }
public void TestStream() { var compiler = new EffectCompiler { UseFileSystem = true }; compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Xenko.Shaders.Tests\GameAssets\Compiler"); compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Xenko.Graphics\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\engine\SiliconStudio.Xenko.Engine\Shaders"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Core"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Lights"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Materials"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Shadows"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\ComputeColor"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Skinning"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Shading"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Transformation"); compiler.SourceDirectories.Add(@"..\..\sources\shaders\Utils"); var compilerParameters = new CompilerParameters { Platform = GraphicsPlatform.Direct3D11 }; var results = compiler.Compile(new ShaderClassSource("TestStream"), compilerParameters); Assert.IsFalse(results.HasErrors); }
/// <inheritdoc/> protected override async void HandleClient(SimpleSocket clientSocket, string url) { string[] urlSegments; string urlParameters; RouterHelper.ParseUrl(url, out urlSegments, out urlParameters); var parameters = RouterHelper.ParseQueryString(urlParameters); var mode = parameters["mode"]; // We accept everything await AcceptConnection(clientSocket); var socketMessageLayer = new SocketMessageLayer(clientSocket, true); Guid? packageId = null; { Guid packageIdParsed; if (Guid.TryParse(parameters["packageid"], out packageIdParsed)) packageId = packageIdParsed; } if (mode == "gamestudio") { Console.WriteLine(@"GameStudio mode started!"); if (!packageId.HasValue) return; lock (gameStudioPerPackageId) { gameStudioPerPackageId[packageId.Value] = socketMessageLayer; } } else { // Create an effect compiler per connection var effectCompiler = new EffectCompiler(); Console.WriteLine(@"Client connected"); // TODO: This should come from an "init" packet effectCompiler.SourceDirectories.Add(EffectCompilerBase.DefaultSourceShaderFolder); // Make a VFS that will access remotely the DatabaseFileProvider // TODO: Is that how we really want to do that in the future? var networkVFS = new NetworkVirtualFileProvider(socketMessageLayer, "/asset"); VirtualFileSystem.RegisterProvider(networkVFS); effectCompiler.FileProvider = networkVFS; socketMessageLayer.AddPacketHandler<RemoteEffectCompilerEffectRequest>(packet => ShaderCompilerRequestHandler(socketMessageLayer, effectCompiler, packet)); socketMessageLayer.AddPacketHandler<RemoteEffectCompilerEffectRequested>(packet => { if (!packageId.HasValue) return; SocketMessageLayer gameStudio; lock (gameStudioPerPackageId) { if (!gameStudioPerPackageId.TryGetValue(packageId.Value, out gameStudio)) return; } // Forward to game studio gameStudio.Send(packet); }); } Task.Run(() => socketMessageLayer.MessageLoop()); }
private static async Task ShaderCompilerRequestHandler(SocketMessageLayer socketMessageLayer, EffectCompiler effectCompiler, RemoteEffectCompilerEffectRequest remoteEffectCompilerEffectRequest) { // Yield so that this socket can continue its message loop to answer to shader file request // TODO: maybe not necessary anymore with RouterServiceServer? await Task.Yield(); Console.WriteLine($"Compiling shader: {remoteEffectCompilerEffectRequest.MixinTree.Name}"); // A shader has been requested, compile it (asynchronously)! var precompiledEffectShaderPass = await effectCompiler.Compile(remoteEffectCompilerEffectRequest.MixinTree, remoteEffectCompilerEffectRequest.EffectParameters, null).AwaitResult(); // Send compiled shader await socketMessageLayer.Send(new RemoteEffectCompilerEffectAnswer { StreamId = remoteEffectCompilerEffectRequest.StreamId, EffectBytecode = precompiledEffectShaderPass.Bytecode }); }
private static async Task ShaderCompilerRequestHandler(SocketMessageLayer socketMessageLayer, EffectLogStore recordedEffectCompile, EffectCompiler effectCompiler, RemoteEffectCompilerEffectRequest remoteEffectCompilerEffectRequest) { // Yield so that this socket can continue its message loop to answer to shader file request // TODO: maybe not necessary anymore with RouterServiceServer? await Task.Yield(); Console.WriteLine("Compiling shader"); // Restore MixinTree.UsedParameters (since it is DataMemberIgnore) remoteEffectCompilerEffectRequest.MixinTree.UsedParameters = remoteEffectCompilerEffectRequest.UsedParameters; // A shader has been requested, compile it (asynchronously)! var precompiledEffectShaderPass = await effectCompiler.Compile(remoteEffectCompilerEffectRequest.MixinTree, null).AwaitResult(); // Record compilation to asset file (only if parent) recordedEffectCompile[new EffectCompileRequest(remoteEffectCompilerEffectRequest.MixinTree.Name, remoteEffectCompilerEffectRequest.MixinTree.UsedParameters)] = true; // Send compiled shader socketMessageLayer.Send(new RemoteEffectCompilerEffectAnswer { StreamId = remoteEffectCompilerEffectRequest.StreamId, EffectBytecode = precompiledEffectShaderPass.Bytecode }); }