Esempio n. 1
0
        public override bool Execute()
        {
            var result = new LoggerResult();
            var package = Package.Load(result, File.ItemSpec, new PackageLoadParameters()
                {
                    AutoCompileProjects = false,
                    LoadAssemblyReferences = false,
                    AutoLoadTemporaryAssets = false,
                });

            foreach (var message in result.Messages)
            {
                if (message.Type >= LogMessageType.Error)
                {
                    Log.LogError(message.ToString());
                }
                else if (message.Type == LogMessageType.Warning)
                {
                    Log.LogWarning(message.ToString());
                }
                else
                {
                    Log.LogMessage(message.ToString());
                }
            }

            // If we have errors loading the package, exit
            if (result.HasErrors)
            {
                return false;
            }

            Version = package.Meta.Version.ToString();
            return true;
        }
Esempio n. 2
0
 public static LoggerResult FixAssetReferences(IEnumerable<AssetItem> items)
 {
     var parameters = new AssetAnalysisParameters() { IsProcessingAssetReferences = true, IsLoggingAssetNotFoundAsError =  true};
     var result = new LoggerResult();
     Run(items, result, parameters);
     return result;
 }
Esempio n. 3
0
        public static int RunProcessAndRedirectToLogger(string command, string parameters, string workingDirectory, LoggerResult logger)
        {
            var process = new Process
            {
                StartInfo = new ProcessStartInfo(command)
                {
                    UseShellExecute = false,
                    CreateNoWindow = true,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    WorkingDirectory = workingDirectory,
                    Arguments = parameters,
                }
            };

            process.Start();

            DataReceivedEventHandler outputDataReceived = (_, args) => LockProcessAndAddDataToLogger(process, logger, false, args);
            DataReceivedEventHandler errorDataReceived = (_, args) => LockProcessAndAddDataToLogger(process, logger, true, args);

            process.OutputDataReceived += outputDataReceived;
            process.ErrorDataReceived += errorDataReceived;
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
            process.CancelOutputRead();
            process.CancelErrorRead();

            process.OutputDataReceived -= outputDataReceived;
            process.ErrorDataReceived -= errorDataReceived;

            return process.ExitCode;
        }
Esempio n. 4
0
 public static Builder CreateBuilder()
 {
     var logger = new LoggerResult();
     logger.ActivateLog(LogMessageType.Debug);
     var builder = new Builder(BuildPath, "Windows", "index", logger) { BuilderName = "TestBuilder", SlaveBuilderPath = @"SiliconStudio.BuildEngine.exe" };
     return builder;
 }
Esempio n. 5
0
 public SettingsContainer()
 {
     rootProfile = new SettingsProfile(this, null);
     profileList.Add(rootProfile);
     currentProfile = rootProfile;
     Logger = new LoggerResult();
 }
Esempio n. 6
0
        public void Test()
        {
            var logger = new LoggerResult();
            var context = new AssetMigrationContext(null, logger);

            var files = Directory.EnumerateFiles(@"..\..\samples", "*.xkscene", SearchOption.AllDirectories);

            foreach (var sceneFile in files)
            {
                logger.HasErrors = false;
                logger.Clear();
                Console.WriteLine($"Checking file {sceneFile}");

                var file = new PackageLoadingAssetFile(sceneFile, null);

                var needMigration = AssetMigration.MigrateAssetIfNeeded(context, file, "Xenko");

                foreach (var message in logger.Messages)
                {
                    Console.WriteLine(message);
                }

                Assert.False(logger.HasErrors);

                if (needMigration)
                {
                    var result = Encoding.UTF8.GetString(file.AssetContent);
                    Console.WriteLine(result);

                    // We cannot load the Package here, as the package can use code/scripts that are only available when you actually compile project assmeblies
                }
            }
        }
 /// <summary>
 /// Performs a wide package validation analysis.
 /// </summary>
 /// <returns>Result of the validation.</returns>
 public LoggerResult Run()
 {
     if (packageSession == null) throw new InvalidOperationException("packageSession is null");
     var results = new LoggerResult();
     Run(results);
     return results;
 }
Esempio n. 8
0
 public SettingsGroup()
 {
     defaultProfile = new SettingsProfile(this, null);
     profileList.Add(defaultProfile);
     currentProfile = defaultProfile;
     Logger = new LoggerResult();
 }
Esempio n. 9
0
 public static Builder CreateBuilder(bool createIndexFile)
 {
     var logger = new LoggerResult();
     logger.ActivateLog(LogMessageType.Debug);
     var indexName = createIndexFile ? VirtualFileSystem.ApplicationDatabaseIndexName : null;
     var builder = new Builder(logger, BuildPath, "Windows", indexName) { BuilderName = "TestBuilder", SlaveBuilderPath = @"SiliconStudio.BuildEngine.exe" };
     return builder;
 }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PackageStore"/> class.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Unable to find a valid Xenko installation path</exception>
        private PackageStore(string installationPath = null, string defaultPackageName = "Xenko", string defaultPackageVersion = XenkoVersion.CurrentAsText)
        {
            // TODO: these are currently hardcoded to Xenko
            DefaultPackageName = defaultPackageName;
            DefaultPackageVersion = new PackageVersion(defaultPackageVersion);
            defaultPackageDirectory = DirectoryHelper.GetPackageDirectory(defaultPackageName);
   
            // 1. Try to use the specified installation path
            if (installationPath != null)
            {
                if (!DirectoryHelper.IsInstallationDirectory(installationPath))
                {
                    throw new ArgumentException("Invalid Xenko installation path [{0}]".ToFormat(installationPath), "installationPath");
                }

                globalInstallationPath = installationPath;
            }

            // 2. Try to resolve an installation path from the path of this assembly
            // We need to be able to use the package manager from an official Xenko install as well as from a developer folder
            if (globalInstallationPath == null)
            {
                globalInstallationPath = DirectoryHelper.GetInstallationDirectory(DefaultPackageName);
            }

            // If there is no root, this is an error
            if (globalInstallationPath == null)
            {
                throw new InvalidOperationException("Unable to find a valid Xenko installation or dev path");
            }

            // Preload default package
            var logger = new LoggerResult();
            var defaultPackageFile = DirectoryHelper.GetPackageFile(defaultPackageDirectory, DefaultPackageName);
            defaultPackage = Package.Load(logger, defaultPackageFile, GetDefaultPackageLoadParameters());
            if (defaultPackage == null)
            {
                throw new InvalidOperationException("Error while loading default package from [{0}]: {1}".ToFormat(defaultPackageFile, logger.ToText()));
            }
            defaultPackage.IsSystem = true;

            // A flag variable just to know if it is a bare bone development directory
            isDev = defaultPackageDirectory != null && DirectoryHelper.IsRootDevDirectory(defaultPackageDirectory);

            // Check if we are in a root directory with store/packages facilities
            if (NugetStore.IsStoreDirectory(globalInstallationPath))
            {
                packagesDirectory = UPath.Combine(globalInstallationPath, (UDirectory)NugetStore.DefaultGamePackagesDirectory);
                store = new NugetStore(globalInstallationPath);
            }
            else
            {
                // We should exit from here if NuGet is not configured.
                MessageBox.Show($"Unexpected installation. Cannot find a proper NuGet configuration for [{defaultPackageName}] in [{globalInstallationPath}]", "Installation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(1);
            }
        }
Esempio n. 11
0
        public static LoggerResult Run(IEnumerable<AssetItem> items, AssetAnalysisParameters parameters)
        {
            if (items == null) throw new ArgumentNullException("items");
            if (parameters == null) throw new ArgumentNullException("parameters");

            var result = new LoggerResult();
            Run(items, result, parameters);
            return result;
        }
Esempio n. 12
0
        /// <summary>
        /// Generates this project template to the specified output directory.
        /// </summary>
        /// <param name="outputDirectory">The output directory.</param>
        /// <param name="projectName">Name of the project.</param>
        /// <param name="projectGuid">The project unique identifier.</param>
        /// <param name="options">The options arguments that will be made available through the Session property in each template.</param>
        /// <returns>LoggerResult.</returns>
        /// <exception cref="System.ArgumentNullException">outputDirectory
        /// or
        /// projectName</exception>
        /// <exception cref="System.InvalidOperationException">FilePath cannot be null on this instance</exception>
        public LoggerResult Generate(string outputDirectory, string projectName, Guid projectGuid, Dictionary<string, object> options = null)
        {
            if (outputDirectory == null) throw new ArgumentNullException("outputDirectory");
            if (projectName == null) throw new ArgumentNullException("projectName");
            if (FilePath == null) throw new InvalidOperationException("FilePath cannot be null on this instance");

            var result = new LoggerResult();
            Generate(outputDirectory, projectName, projectGuid, result, options);
            return result;
        }
 internal AssetToImportMergeGroup(AssetToImportByImporter parent, AssetItem item)
 {
     if (parent == null) throw new ArgumentNullException("parent");
     if (item == null) throw new ArgumentNullException("item");
     this.Parent = parent;
     Item = item;
     Merges = new List<AssetToImportMerge>();
     Enabled = true;
     var assetDescription = DisplayAttribute.GetDisplay(item.Asset.GetType());
     Log = new LoggerResult(string.Format("Import {0} {1}", assetDescription != null ? assetDescription.Name : "Asset" , item));
 }
 internal AssetToImportByImporter(AssetToImport parent, IAssetImporter importer, AssetItem previousItem = null)
 {
     if (parent == null) throw new ArgumentNullException("parent");
     if (importer == null) throw new ArgumentNullException("importer");
     this.Parent = parent;
     this.importer = importer;
     this.Items = new List<AssetToImportMergeGroup>();
     Enabled = true;
     Log = new LoggerResult(string.Format("{0} Importer", importer.Name));
     ImporterParameters = importer.GetDefaultParameters(previousItem != null);
     ImporterParameters.Logger = Log;
     PreviousItem = previousItem;
 }
Esempio n. 15
0
        public void Init()
        {
            // Create and mount database file system
            var objDatabase = new ObjectDatabase("/data/db", "index", "/local/db");
            var databaseFileProvider = new DatabaseFileProvider(objDatabase);
            AssetManager.GetFileProvider = () => databaseFileProvider;

            Compiler = new EffectCompiler();
            Compiler.SourceDirectories.Add("shaders");
            MixinParameters = new ShaderMixinParameters();
            MixinParameters.Add(CompilerParameters.GraphicsPlatformKey, GraphicsPlatform.Direct3D11);
            MixinParameters.Add(CompilerParameters.GraphicsProfileKey, GraphicsProfile.Level_11_0);
            ResultLogger = new LoggerResult();
        }
Esempio n. 16
0
        private static int Main(string[] args)
        {
            Console.WriteLine(@"Bootstrapping: " + args[0]);

            var xenkoDir = Environment.GetEnvironmentVariable("SiliconStudioXenkoDir");
            var xenkoPkgPath = UPath.Combine(xenkoDir, new UFile("Xenko.xkpkg"));

            var session = PackageSession.Load(xenkoPkgPath);

            var generator = TemplateSampleGenerator.Default;

            var logger = new LoggerResult();

            var parameters = new TemplateGeneratorParameters { Session = session.Session };

            var outputPath = UPath.Combine(new UDirectory(xenkoDir), new UDirectory("samplesGenerated"));
            outputPath = UPath.Combine(outputPath, new UDirectory(args[0]));

            var xenkoTemplates = session.Session.Packages.First().Templates;
            parameters.Description = xenkoTemplates.First(x => x.Group.StartsWith("Samples") && x.Id == new Guid(args[1]));
            parameters.Name = args[0];
            parameters.Namespace = args[0];
            parameters.OutputDirectory = outputPath;
            parameters.Logger = logger;

            generator.Generate(parameters);

            var updaterTemplate = xenkoTemplates.First(x => x.FullPath.ToString().EndsWith("UpdatePlatforms.xktpl"));
            parameters.Description = updaterTemplate;

            var updater = UpdatePlatformsTemplateGenerator.Default;

            var gameSettingsAsset = session.Session.Packages.Last().GetGameSettingsAsset();

            var updateParams = new GameTemplateParameters
            {
                Common = parameters,
                ForcePlatformRegeneration = true,
                GraphicsProfile = gameSettingsAsset.DefaultGraphicsProfile,
                IsHDR = false,
                Orientation = gameSettingsAsset.DisplayOrientation,
                Platforms = AssetRegistry.SupportedPlatforms.ToList()
            };

            updater.Generate(updateParams);

            Console.WriteLine(logger.ToText());

            return logger.HasErrors ? 1 : 0;
        }
        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();
        }
Esempio n. 18
0
        private void UpdateReflection(ShaderBytecode shaderBytecode, EffectReflection effectReflection, LoggerResult log)
        {
            var shaderReflectionRaw = new SharpDX.D3DCompiler.ShaderReflection(shaderBytecode);
            var shaderReflectionRawDesc = shaderReflectionRaw.Description;

            // Constant Buffers
            for (int i = 0; i < shaderReflectionRawDesc.ConstantBuffers; ++i)
            {
                var constantBufferRaw = shaderReflectionRaw.GetConstantBuffer(i);
                var constantBufferRawDesc = constantBufferRaw.Description;
                var linkBuffer = effectReflection.ConstantBuffers.FirstOrDefault(buffer => buffer.Name == constantBufferRawDesc.Name && buffer.Stage == ShaderStage.None);

                var constantBuffer = GetConstantBufferReflection(constantBufferRaw, ref constantBufferRawDesc, linkBuffer, log);
                constantBuffer.Stage = shaderBytecode.Stage;
                effectReflection.ConstantBuffers.Add(constantBuffer);
            }

            // BoundResources
            for (int i = 0; i < shaderReflectionRawDesc.BoundResources; ++i)
            {
                var boundResourceDesc = shaderReflectionRaw.GetResourceBindingDescription(i);

                string linkKeyName = null;
                foreach (var linkResource in effectReflection.ResourceBindings)
                {
                    if (linkResource.Param.RawName == boundResourceDesc.Name && linkResource.Stage == ShaderStage.None)
                    {
                        linkKeyName = linkResource.Param.KeyName;
                        break;
                    }

                }

                if (linkKeyName == null)
                {
                    log.Error("Resource [{0}] has no link", boundResourceDesc.Name);
                }
                else
                {

                    var binding = GetResourceBinding(boundResourceDesc, linkKeyName, log);
                    binding.Stage = shaderBytecode.Stage;

                    effectReflection.ResourceBindings.Add(binding);
                }
            }
        }
Esempio n. 19
0
        public void TestLocalLogger()
        {
            var log = new LoggerResult();

            log.Info("#0");
            Assert.That(log.Messages.Count, Is.EqualTo(1));
            Assert.That(log.Messages[0].Type, Is.EqualTo(LogMessageType.Info));
            Assert.That(log.Messages[0].Text, Is.EqualTo("#0"));

            log.Info("#{0}", 1);
            Assert.That(log.Messages.Count, Is.EqualTo(2));
            Assert.That(log.Messages[1].Type, Is.EqualTo(LogMessageType.Info));
            Assert.That(log.Messages[1].Text, Is.EqualTo("#1"));

            Assert.That(log.HasErrors, Is.False);

            log.Error("#2");
            Assert.That(log.Messages.Count, Is.EqualTo(3));
            Assert.That(log.Messages[2].Type, Is.EqualTo(LogMessageType.Error));
            Assert.That(log.Messages[2].Text, Is.EqualTo("#2"));

            Assert.That(log.HasErrors, Is.True);

            log.Error("#{0}", 3);
            Assert.That(log.Messages.Count, Is.EqualTo(4));
            Assert.That(log.Messages[3].Type, Is.EqualTo(LogMessageType.Error));
            Assert.That(log.Messages[3].Text, Is.EqualTo("#3"));

            // Activate log from Info to Fatal. Verbose won't be logged.
            log.ActivateLog(LogMessageType.Info);
            log.Verbose("#4");
            Assert.That(log.Messages.Count, Is.EqualTo(4));

            // Activate log from Verbose to Fatal. Verbose will be logged
            log.ActivateLog(LogMessageType.Verbose);
            log.Verbose("#4");
            Assert.That(log.Messages.Count, Is.EqualTo(5));

            // Activate log from Info to Fatal and only Debug. Verbose won't be logged.
            log.ActivateLog(LogMessageType.Info);
            log.ActivateLog(LogMessageType.Debug, true);
            log.Verbose("#5");
            log.Debug("#6");
            Assert.That(log.Messages.Count, Is.EqualTo(6));
            Assert.That(log.Messages[5].Text, Is.EqualTo("#6"));
        }
Esempio n. 20
0
        public override bool Execute()
        {

            var result = new LoggerResult();
            var package = Package.Load(result, File.ItemSpec, new PackageLoadParameters()
                {
                    AutoCompileProjects = false,
                    LoadAssemblyReferences = false,
                    AutoLoadTemporaryAssets = false,
                });

            foreach (var message in result.Messages)
            {
                if (message.Type >= LogMessageType.Error)
                {
                    Log.LogError(message.ToString());
                }
                else if (message.Type == LogMessageType.Warning)
                {
                    Log.LogWarning(message.ToString());
                }
                else
                {
                    Log.LogMessage(message.ToString());
                }
            }

            // If we have errors loading the package, exit
            if (result.HasErrors)
            {
                return false;
            }

            // Override version with task SpecialVersion (if specified by user)
            if (!string.IsNullOrEmpty(SpecialVersion))
            {
                package.Meta.Version = new PackageVersion(package.Meta.Version.Version, SpecialVersion);
            }

            Log.LogMessage(MessageImportance.High, "Packaging [{0}] version [{1}]", package.Meta.Name, package.Meta.Version);

            // Build the package
            PackageArchive.Build(package);
            return true;
        }
Esempio n. 21
0
        public override bool Execute()
        {
            var result = new LoggerResult();
            var package = Package.Load(result, File.ItemSpec, new PackageLoadParameters()
                {
                    AutoCompileProjects = false,
                    LoadAssemblyReferences = false,
                    AutoLoadTemporaryAssets = false,
                });

            foreach (var message in result.Messages)
            {
                if (message.Type >= LogMessageType.Error)
                {
                    Log.LogError(message.ToString());
                }
                else if (message.Type == LogMessageType.Warning)
                {
                    Log.LogWarning(message.ToString());
                }
                else
                {
                    Log.LogMessage(message.ToString());
                }
            }

            // If we have errors loading the package, exit
            if (result.HasErrors)
            {
                return false;
            }

            var version = package.Meta.Version;

            // Override version with task SpecialVersion (if specified by user)
            if (!string.IsNullOrEmpty(SpecialVersion))
            {
                version = new PackageVersion(version.ToString().Split('-').First() + "-" + SpecialVersion);
            }

            Version = version.ToString();
            return true;
        }
Esempio n. 22
0
        public Assembly LoadAssemblyFromPath(string assemblyFullPath, ILogger outputLog = null, List<string> lookupDirectoryList = null)
        {
            if (assemblyFullPath == null) throw new ArgumentNullException("assemblyFullPath");

            log = new LoggerResult();

            lookupDirectoryList = lookupDirectoryList ?? new List<string>();
            assemblyFullPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, assemblyFullPath));
            var assemblyDirectory = Path.GetDirectoryName(assemblyFullPath);

            if (assemblyDirectory == null || !Directory.Exists(assemblyDirectory))
            {
                throw new ArgumentException("Invalid assembly path. Doesn't contain directory information");
            }

            if (!lookupDirectoryList.Contains(assemblyDirectory, StringComparer.InvariantCultureIgnoreCase))
            {
                lookupDirectoryList.Add(assemblyDirectory);
            }

            var previousLookupList = searchDirectoryList;
            try
            {
                loadingInstance = this;
                searchDirectoryList = lookupDirectoryList;

                return LoadAssemblyFromPathInternal(assemblyFullPath);
            }
            finally
            {
                loadingInstance = null;
                searchDirectoryList = previousLookupList;

                if (outputLog != null)
                {
                    log.CopyTo(outputLog);
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Converts the specified hlsl source code to glsl.
        /// </summary>
        /// <param name="hlslSourcecode">The HLSL source code.</param>
        /// <param name="hlslEntryPoint">The HLSL entry point.</param>
        /// <param name="stage">The stage to convert.</param>
        /// <param name="shader">The shader.</param>
        /// <param name="inputHlslFilepath">The input HLSL filepath.</param>
        /// <returns>
        /// The resulting glsl AST tree.
        /// </returns>
        public global::SiliconStudio.Shaders.Ast.Shader Convert(string hlslSourcecode, string hlslEntryPoint, PipelineStage stage, string inputHlslFilepath, LoggerResult log)
        {
            try
            {
                // Convert from Framework.Graphics ShaderMacro to Framework.Shaders ShaderMacro
                var macros = new global::SiliconStudio.Shaders.Parser.ShaderMacro[Macros.Count];
                for (int index = 0; index < Macros.Count; index++)
                    macros[index] = new global::SiliconStudio.Shaders.Parser.ShaderMacro(Macros[index].Name, Macros[index].Definition);

                var result = HlslParser.TryPreProcessAndParse(hlslSourcecode, inputHlslFilepath, macros, IncludeDirectories);

                if (result.HasErrors)
                {
                    log.Error(result.ToString());
                    return null;
                }

                // Prepare the shader before type inference analysis
                HlslToGlslConvertor.Prepare(result.Shader);

                HlslSemanticAnalysis.Run(result);

                // If there are any type inference analysis, just display all errors but ytu
                if (result.HasErrors)
                {
                    log.Error(result.ToString());
                    return null;
                }

                return Convert(result, hlslEntryPoint, stage, inputHlslFilepath, log);
            }
            catch (Exception ex)
            {
                log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
            }
            return null;
        }
Esempio n. 24
0
        private ShaderConstantBufferDescription GetConstantBufferReflection(ConstantBuffer constantBufferRaw, ref ConstantBufferDescription constantBufferRawDesc, ShaderConstantBufferDescription linkBuffer, LoggerResult log)
        {
            var constantBuffer = new ShaderConstantBufferDescription
            {
                Name = constantBufferRawDesc.Name,
                Size = constantBufferRawDesc.Size,
            };

            switch (constantBufferRawDesc.Type)
            {
            case SharpDX.D3DCompiler.ConstantBufferType.ConstantBuffer:
                constantBuffer.Type = ConstantBufferType.ConstantBuffer;
                break;

            case SharpDX.D3DCompiler.ConstantBufferType.TextureBuffer:
                constantBuffer.Type = ConstantBufferType.TextureBuffer;
                break;

            default:
                constantBuffer.Type = ConstantBufferType.Unknown;
                break;
            }

            // ConstantBuffers variables
            var members = new List <EffectParameterValueData>();

            for (int i = 0; i < constantBufferRawDesc.VariableCount; i++)
            {
                var variable                = constantBufferRaw.GetVariable(i);
                var variableType            = variable.GetVariableType();
                var variableDescription     = variable.Description;
                var variableTypeDescription = variableType.Description;

                var parameter = new EffectParameterValueData()
                {
                    Param =
                    {
                        Class   = (EffectParameterClass)variableTypeDescription.Class,
                        Type    = ConvertVariableValueType(variableTypeDescription.Type, log),
                        RawName = variableDescription.Name,
                    },
                    Offset      = variableDescription.StartOffset,
                    Size        = variableDescription.Size,
                    Count       = variableTypeDescription.ElementCount == 0 ? 1 : variableTypeDescription.ElementCount,
                    RowCount    = (byte)variableTypeDescription.RowCount,
                    ColumnCount = (byte)variableTypeDescription.ColumnCount,
                };

                if (variableTypeDescription.Offset != 0)
                {
                    log.Error("Unexpected offset [{0}] for variable [{1}] in constant buffer [{2}]", variableTypeDescription.Offset, variableDescription.Name, constantBuffer.Name);
                }

                bool bindingNotFound = true;
                // Retrieve Link Member
                foreach (var binding in linkBuffer.Members)
                {
                    if (binding.Param.RawName == variableDescription.Name)
                    {
                        // TODO: should we replicate linkMember.Count/RowCount/ColumnCount? or use what is retrieved by D3DCompiler reflection
                        parameter.Param.KeyName = binding.Param.KeyName;
                        bindingNotFound         = false;
                        break;
                    }
                }

                if (bindingNotFound)
                {
                    log.Error("Variable [{0}] in constant buffer [{1}] has no link", variableDescription.Name, constantBuffer.Name);
                }

                members.Add(parameter);
            }
            constantBuffer.Members = members.ToArray();

            return(constantBuffer);
        }
Esempio n. 25
0
        public int Run(string[] args)
        {
            // This is used by ExecServer to retrieve the logs directly without using the console redirect (which is not working well
            // in a multi-domain scenario)
            var redirectLogToAppDomainAction = AppDomain.CurrentDomain.GetData("AppDomainLogToAction") as Action <string, ConsoleColor>;

            clock = Stopwatch.StartNew();

            // TODO this is hardcoded. Check how to make this dynamic instead.
            RuntimeHelpers.RunModuleConstructor(typeof(IProceduralModel).Module.ModuleHandle);
            RuntimeHelpers.RunModuleConstructor(typeof(MaterialKeys).Module.ModuleHandle);
            RuntimeHelpers.RunModuleConstructor(typeof(SpriteFontAsset).Module.ModuleHandle);
            RuntimeHelpers.RunModuleConstructor(typeof(ModelAsset).Module.ModuleHandle);
            RuntimeHelpers.RunModuleConstructor(typeof(SpriteStudioAnimationAsset).Module.ModuleHandle);
            RuntimeHelpers.RunModuleConstructor(typeof(ParticleSystem).Module.ModuleHandle);
            //var project = new Package();
            //project.Save("test.xkpkg");

            //Thread.Sleep(10000);
            //var spriteFontAsset = StaticFontAsset.New();
            //Content.Save("test.xkfnt", spriteFontAsset);
            //project.Refresh();

            //args = new string[] { "test.xkpkg", "-o:app_data", "-b:tmp", "-t:1" };

            var exeName           = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
            var showHelp          = false;
            var packMode          = false;
            var buildEngineLogger = GlobalLogger.GetLogger("BuildEngine");
            var options           = new PackageBuilderOptions(new ForwardingLoggerResult(buildEngineLogger));

            var p = new OptionSet
            {
                "Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp) All Rights Reserved",
                "Xenko Build Tool - Version: "
                +
                String.Format(
                    "{0}.{1}.{2}",
                    typeof(Program).Assembly.GetName().Version.Major,
                    typeof(Program).Assembly.GetName().Version.Minor,
                    typeof(Program).Assembly.GetName().Version.Build) + string.Empty,
                string.Format("Usage: {0} inputPackageFile [options]* -b buildPath", exeName),
                string.Empty,
                "=== Options ===",
                string.Empty,
                { "h|help", "Show this message and exit", v => showHelp = v != null },
                { "v|verbose", "Show more verbose progress logs", v => options.Verbose = v != null },
                { "d|debug", "Show debug logs (imply verbose)", v => options.Debug = v != null },
                { "log", "Enable file logging", v => options.EnableFileLogging = v != null },
                { "disable-auto-compile", "Disable auto-compile of projects", v => options.DisableAutoCompileProjects = v != null },
                { "project-configuration=", "Project configuration", v => options.ProjectConfiguration = v },
                { "platform=", "Platform name", v => options.Platform = (PlatformType)Enum.Parse(typeof(PlatformType), v) },
                { "solution-file=", "Solution File Name", v => options.SolutionFile = v },
                { "package-id=", "Package Id from the solution file", v => options.PackageId = Guid.Parse(v) },
                { "package-file=", "Input Package File Name", v => options.PackageFile = v },
                { "o|output-path=", "Output path", v => options.OutputDirectory = v },
                { "b|build-path=", "Build path", v => options.BuildDirectory = v },
                { "log-file=", "Log build in a custom file.", v =>
                  {
                      options.EnableFileLogging = v != null;
                      options.CustomLogFileName = v;
                  } },
                { "log-pipe=", "Log pipe.", v =>
                  {
                      if (!string.IsNullOrEmpty(v))
                      {
                          options.LogPipeNames.Add(v);
                      }
                  } },
                { "monitor-pipe=", "Monitor pipe.", v =>
                  {
                      if (!string.IsNullOrEmpty(v))
                      {
                          options.MonitorPipeNames.Add(v);
                      }
                  } },
                { "slave=", "Slave pipe", v => options.SlavePipe = v }, // Benlitz: I don't think this should be documented
                { "server=", "This Compiler is launched as a server", v => { } },
                { "pack", "Special mode to copy assets and resources in a folder for NuGet packaging", v => packMode = true },
                { "t|threads=", "Number of threads to create. Default value is the number of hardware threads available.", v => options.ThreadCount = int.Parse(v) },
                { "test=", "Run a test session.", v => options.TestName = v },
                { "property:", "Properties. Format is name1=value1;name2=value2", v =>
                  {
                      if (!string.IsNullOrEmpty(v))
                      {
                          foreach (var nameValue in v.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                          {
                              var equalIndex = nameValue.IndexOf('=');
                              if (equalIndex == -1)
                              {
                                  throw new OptionException("Expect name1=value1;name2=value2 format.", "property");
                              }

                              options.Properties.Add(nameValue.Substring(0, equalIndex), nameValue.Substring(equalIndex + 1));
                          }
                      }
                  } },
                { "compile-property:", "Compile properties. Format is name1=value1;name2=value2", v =>
                  {
                      if (!string.IsNullOrEmpty(v))
                      {
                          if (options.ExtraCompileProperties == null)
                          {
                              options.ExtraCompileProperties = new Dictionary <string, string>();
                          }

                          foreach (var nameValue in v.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                          {
                              var equalIndex = nameValue.IndexOf('=');
                              if (equalIndex == -1)
                              {
                                  throw new OptionException("Expect name1=value1;name2=value2 format.", "property");
                              }

                              options.ExtraCompileProperties.Add(nameValue.Substring(0, equalIndex), nameValue.Substring(equalIndex + 1));
                          }
                      }
                  } },
                {
                    "reattach-debugger=", "Reattach to a Visual Studio debugger", v =>
                    {
                        int debuggerProcessId;
                        if (!string.IsNullOrEmpty(v) && int.TryParse(v, out debuggerProcessId))
                        {
                            if (!Debugger.IsAttached)
                            {
                                using (var debugger = VisualStudioDebugger.GetByProcess(debuggerProcessId))
                                {
                                    debugger?.Attach();
                                }
                            }
                        }
                    }
                },
            };

            TextWriterLogListener fileLogListener = null;

            BuildResultCode exitCode;

            RemoteLogForwarder assetLogger = null;

            try
            {
                var unexpectedArgs = p.Parse(args);

                // Set remote logger
                assetLogger = new RemoteLogForwarder(options.Logger, options.LogPipeNames);
                GlobalLogger.GlobalMessageLogged += assetLogger;

                // Activate proper log level
                buildEngineLogger.ActivateLog(options.LoggerType);

                // Output logs to the console with colored messages
                if (options.SlavePipe == null && !options.LogPipeNames.Any())
                {
                    if (redirectLogToAppDomainAction != null)
                    {
                        globalLoggerOnGlobalMessageLogged = new LogListenerRedirectToAction(redirectLogToAppDomainAction);
                    }
                    else
                    {
                        globalLoggerOnGlobalMessageLogged = new ConsoleLogListener {
                            LogMode = ConsoleLogMode.Always
                        };
                    }
                    globalLoggerOnGlobalMessageLogged.TextFormatter = FormatLog;
                    GlobalLogger.GlobalMessageLogged += globalLoggerOnGlobalMessageLogged;
                }

                if (unexpectedArgs.Any())
                {
                    throw new OptionException("Unexpected arguments [{0}]".ToFormat(string.Join(", ", unexpectedArgs)), "args");
                }
                try
                {
                    options.ValidateOptions();
                }
                catch (ArgumentException ex)
                {
                    throw new OptionException(ex.Message, ex.ParamName);
                }

                if (showHelp)
                {
                    p.WriteOptionDescriptions(Console.Out);
                    return((int)BuildResultCode.Successful);
                }
                else if (packMode)
                {
                    PackageSessionPublicHelper.FindAndSetMSBuildVersion();

                    var csprojFile = options.PackageFile;
                    var intermediatePackagePath = options.BuildDirectory;
                    var generatedItems          = new List <(string SourcePath, string PackagePath)>();
                    var logger = new LoggerResult();
                    if (!PackAssetsHelper.Run(logger, csprojFile, intermediatePackagePath, generatedItems))
                    {
                        foreach (var message in logger.Messages)
                        {
                            Console.WriteLine(message);
                        }
                        return((int)BuildResultCode.BuildError);
                    }
                    foreach (var generatedItem in generatedItems)
                    {
                        Console.WriteLine($"{generatedItem.SourcePath}|{generatedItem.PackagePath}");
                    }
                    return((int)BuildResultCode.Successful);
                }

                // Also write logs from master process into a file
                if (options.SlavePipe == null)
                {
                    if (options.EnableFileLogging)
                    {
                        string logFileName = options.CustomLogFileName;
                        if (string.IsNullOrEmpty(logFileName))
                        {
                            string inputName = Path.GetFileNameWithoutExtension(options.PackageFile);
                            logFileName = "Logs/Build-" + inputName + "-" + DateTime.Now.ToString("yy-MM-dd-HH-mm") + ".txt";
                        }

                        string dirName = Path.GetDirectoryName(logFileName);
                        if (dirName != null)
                        {
                            Directory.CreateDirectory(dirName);
                        }

                        fileLogListener = new TextWriterLogListener(new FileStream(logFileName, FileMode.Create))
                        {
                            TextFormatter = FormatLog
                        };
                        GlobalLogger.GlobalMessageLogged += fileLogListener;
                    }

                    options.Logger.Info("BuildEngine arguments: " + string.Join(" ", args));
                    options.Logger.Info("Starting builder.");

                    var      baseDirectory = Path.Combine(options.BuildDirectory, @"../../../../../");
                    var      changeFile = baseDirectory + "/files_changed";
                    var      buildFile = baseDirectory + "/files_built";
                    var      skipFile = baseDirectory + "/always_build";
                    long     files_changed_ticks = 0, files_built_ticks = 0;
                    string[] buildlines = null;
                    string   platform   = options.Platform.ToString() + "-" + options.ProjectConfiguration;

                    if (File.Exists(changeFile))
                    {
                        long.TryParse(File.ReadAllText(changeFile), out files_changed_ticks);
                    }

                    if (File.Exists(buildFile))
                    {
                        buildlines = File.ReadAllLines(buildFile);
                        for (int i = 0; i < buildlines.Length; i += 2)
                        {
                            if (buildlines[i] == platform)
                            {
                                long.TryParse(buildlines[i + 1], out files_built_ticks);
                                // also update with now time
                                buildlines[i + 1] = System.DateTime.Now.Ticks.ToString();
                            }
                        }
                    }

                    if (File.Exists(skipFile))
                    {
                        options.Logger.Info("Found always_build, so always building assets.");
                    }
                    else if (Process.GetProcessesByName("Focus.GameStudio").Length == 0)
                    {
                        options.Logger.Warning("Focus.GameStudio does not appear to be running, so the AssetCompiler will always rebuild assets.");
                    }
                    else if (files_changed_ticks > 0 && files_built_ticks > 0 && files_built_ticks > files_changed_ticks)
                    {
                        options.Logger.Info("All Assets/ and Resources/ appear up date for " + platform + ", so skipping recompilation. If this is a mistake, delete files_changed and files_built in the root project directory. If you want to always build assets, make a file called always_build in the root project directory.");
                        return(0);
                    }

                    // if there was no changefile, do it now
                    if (File.Exists(changeFile) == false)
                    {
                        File.WriteAllText(changeFile, System.DateTime.Now.Ticks.ToString());
                    }

                    // update file with changes
                    if (File.Exists(buildFile) == false)
                    {
                        File.WriteAllText(buildFile, platform + "\n" + System.DateTime.Now.Ticks.ToString());
                    }
                    else
                    {
                        File.WriteAllLines(buildFile, buildlines);
                        if (files_built_ticks <= 0)
                        {
                            File.AppendAllText(buildFile, platform + "\n" + System.DateTime.Now.Ticks.ToString());
                        }
                    }
                }
                else
                {
                    IsSlave = true;
                }

                if (!string.IsNullOrEmpty(options.TestName))
                {
                    var test = new TestSession();
                    test.RunTest(options.TestName, options.Logger);
                    exitCode = BuildResultCode.Successful;
                }
                else
                {
                    builder = new PackageBuilder(options);
                    if (!IsSlave && redirectLogToAppDomainAction == null)
                    {
                        Console.CancelKeyPress += OnConsoleOnCancelKeyPress;
                    }
                    exitCode = builder.Build();
                }
            }
            catch (OptionException e)
            {
                options.Logger.Error($"Command option '{e.OptionName}': {e.Message}");
                exitCode = BuildResultCode.CommandLineError;
            }
            catch (Exception e)
            {
                options.Logger.Error($"Unhandled exception", e);
                exitCode = BuildResultCode.BuildError;
            }
            finally
            {
                // Flush and close remote logger
                if (assetLogger != null)
                {
                    GlobalLogger.GlobalMessageLogged -= assetLogger;
                    assetLogger.Dispose();
                }

                if (fileLogListener != null)
                {
                    GlobalLogger.GlobalMessageLogged -= fileLogListener;
                    fileLogListener.LogWriter.Close();
                }

                // Output logs to the console with colored messages
                if (globalLoggerOnGlobalMessageLogged != null)
                {
                    GlobalLogger.GlobalMessageLogged -= globalLoggerOnGlobalMessageLogged;
                }
                if (builder != null && !IsSlave && redirectLogToAppDomainAction == null)
                {
                    Console.CancelKeyPress -= OnConsoleOnCancelKeyPress;
                }

                // Reset cache hold by YamlSerializer
                YamlSerializer.Default.ResetCache();
            }
            return((int)exitCode);
        }
 public EffectBytecodeCompilerResult(EffectBytecode bytecode) : this()
 {
     Bytecode       = bytecode;
     CompilationLog = emptyLoggerResult;
 }
Esempio n. 27
0
        /// <summary>
        /// Loads the <see cref="ShaderClassType" />.
        /// </summary>
        /// <param name="shaderClassSource">The shader class source.</param>
        /// <param name="shaderMacros">The shader macros.</param>
        /// <param name="log">The log to output error logs.</param>
        /// <param name="autoGenericInstances"></param>
        /// <returns>A ShaderClassType or null if there was some errors.</returns>
        /// <exception cref="System.ArgumentNullException">shaderClassSource</exception>
        public LoadedShaderClassType LoadClassSource(ShaderClassCode shaderClassSource, Stride.Core.Shaders.Parser.ShaderMacro[] shaderMacros, LoggerResult log, bool autoGenericInstances)
        {
            if (shaderClassSource == null)
            {
                throw new ArgumentNullException("shaderClassSource");
            }

            string generics = null;

            if (shaderClassSource.GenericArguments != null)
            {
                generics = "";
                foreach (var gen in shaderClassSource.GenericArguments)
                {
                    generics += "___" + gen;
                }
            }
            var shaderClassType = LoadShaderClass(shaderClassSource, generics, log, shaderMacros);

            if (shaderClassType == null)
            {
                return(null);
            }

            // Instantiate generic class
            if (shaderClassSource.GenericArguments != null || (shaderClassType.Type.ShaderGenerics.Count > 0 && autoGenericInstances))
            {
                if (shaderClassType.IsInstanciated)
                {
                    return(shaderClassType);
                }

                // If we want to automatically generate a generic instance (in case we just want to parse and verify the generic)
                if (autoGenericInstances)
                {
                    shaderClassSource.GenericArguments = new string[shaderClassType.Type.ShaderGenerics.Count];
                    for (int i = 0; i < shaderClassSource.GenericArguments.Length; i++)
                    {
                        var variableGeneric = shaderClassType.Type.ShaderGenerics[i];
                        shaderClassSource.GenericArguments[i] = GetDefaultConstValue(variableGeneric);
                    }
                }

                if (shaderClassSource.GenericArguments.Length != shaderClassType.Type.ShaderGenerics.Count)
                {
                    log.Error(StrideMessageCode.WrongGenericNumber, shaderClassType.Type.Span, shaderClassSource.ClassName);
                    return(null);
                }

                // check the name of the generics
                foreach (var generic in shaderClassType.Type.ShaderGenerics)
                {
                    foreach (var genericCompare in shaderClassType.Type.ShaderGenerics.Where(x => x != generic))
                    {
                        if (generic.Name.Text == genericCompare.Name.Text)
                        {
                            log.Error(StrideMessageCode.SameNameGenerics, generic.Span, generic, genericCompare, shaderClassSource.ClassName);
                        }
                    }
                }

                if (log.HasErrors)
                {
                    return(null);
                }

                // When we use an actual generic instance, we replace the name with the name of the class + a hash of the generic parameters
                if (!autoGenericInstances)
                {
                    var className = GenerateGenericClassName(shaderClassSource);
                    shaderClassType.Type.Name = new Identifier(className);
                }

                var genericAssociation = CreateGenericAssociation(shaderClassType.Type.ShaderGenerics, shaderClassSource.GenericArguments);
                var identifierGenerics = GenerateIdentifierFromGenerics(genericAssociation);
                var expressionGenerics = GenerateGenericsExpressionValues(shaderClassType.Type.ShaderGenerics, shaderClassSource.GenericArguments);
                StrideClassInstantiator.Instantiate(shaderClassType.Type, expressionGenerics, identifierGenerics, autoGenericInstances, log);
                shaderClassType.Type.ShaderGenerics.Clear();
                shaderClassType.IsInstanciated = true;
            }
            return(shaderClassType);
        }
Esempio n. 28
0
        private LoadedShaderClassType LoadShaderClass(ShaderClassCode classSource, string generics, LoggerResult log, Stride.Core.Shaders.Parser.ShaderMacro[] macros = null)
        {
            var type = classSource.ClassName;

            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            var shaderSourceKey = new ShaderSourceKey(type, generics, macros);

            lock (loadedShaders)
            {
                // Already instantiated
                LoadedShaderClassType shaderClass;

                if (loadedShaders.TryGetValue(shaderSourceKey, out shaderClass))
                {
                    return(shaderClass);
                }

                ShaderSourceManager.ShaderSourceWithHash shaderSource;

                // Load shader source code
                if (classSource is ShaderClassString shaderClassString)
                {
                    shaderSource = SourceManager.LoadShaderSource(type, shaderClassString.ShaderSourceCode);
                }
                else
                {
                    shaderSource = SourceManager.LoadShaderSource(type);
                }

                string preprocessedSource;
                try
                {
                    preprocessedSource = PreProcessor.Run(shaderSource.Source, shaderSource.Path, macros);
                }
                catch (Exception ex)
                {
                    log.Error(MessageCode.ErrorUnexpectedException, new SourceSpan(new SourceLocation(shaderSource.Path, 0, 1, 1), 1), ex);
                    return(null);
                }

                byte[] byteArray            = Encoding.UTF8.GetBytes(preprocessedSource);
                var    hashPreprocessSource = ObjectId.FromBytes(byteArray);

                // Compile
                var parsingResult = StrideShaderParser.TryParse(preprocessedSource, shaderSource.Path);
                parsingResult.CopyTo(log);

                if (parsingResult.HasErrors)
                {
                    return(null);
                }

                var shader = parsingResult.Shader;

                // As shaders can be embedded in namespaces, get only the shader class and make sure there is only one in a sdsl.
                var shaderClassTypes = StrideShaderParser.GetShaderClassTypes(shader.Declarations).ToList();
                if (shaderClassTypes.Count != 1)
                {
                    var sourceSpan = new SourceSpan(new SourceLocation(shaderSource.Path, 0, 0, 0), 1);
                    if (shaderClassTypes.Count > 1)
                    {
                        sourceSpan = shaderClassTypes[1].Span;
                    }
                    log.Error(StrideMessageCode.ShaderMustContainSingleClassDeclaration, sourceSpan, type);
                    return(null);
                }

                shaderClass                        = new LoadedShaderClassType();
                shaderClass.Type                   = shaderClassTypes.First();
                shaderClass.SourcePath             = shaderSource.Path;
                shaderClass.SourceHash             = shaderSource.Hash;
                shaderClass.PreprocessedSourceHash = hashPreprocessSource;
                shaderClass.IsInstanciated         = false;

                // TODO: We should not use Console. Change the way we log things here
                // Console.WriteLine("Loading Shader {0}{1}", type, macros != null && macros.Length > 0 ? String.Format("<{0}>", string.Join(", ", macros)) : string.Empty);

                // If the file name is not matching the class name, provide an error
                if (shaderClass.Type.Name.Text != type)
                {
                    log.Error(StrideMessageCode.FileNameNotMatchingClassName, shaderClass.Type.Name.Span, type, shaderClass.Type.Name.Text);
                    return(null);
                }

                loadedShaders.Add(shaderSourceKey, shaderClass);

                return(shaderClass);
            }
        }
Esempio n. 29
0
 public XenkoStreamAnalyzer(LoggerResult errorLog)
     : base(false, true)
 {
     errorWarningLog = errorLog ?? new LoggerResult();
 }
Esempio n. 30
0
        /// <summary>
        /// Merge with a local virtual table =  need to check override keywords
        /// </summary>
        /// <param name="virtualTable">the virtual table to add</param>
        /// <param name="mixinName">the name of the mixin</param>
        /// <param name="log">the error logger</param>
        public void MergeWithLocalVirtualTable(MixinVirtualTable virtualTable, string mixinName, LoggerResult log)
        {
            foreach (var method in virtualTable.Methods)
            {
                var methodDecl = Methods.LastOrDefault(x => x.Method.IsSameSignature(method.Method));
                if (methodDecl != null)
                {
                    var isBaseMethod = method.Shader.BaseClasses.Any(x => x.Name.Text == methodDecl.Shader.Name.Text);

                    if (isBaseMethod)
                    {
                        if (methodDecl.Method is MethodDefinition)
                        {
                            if (!method.Method.Qualifiers.Contains(ParadoxStorageQualifier.Override))
                            {
                                log.Error(ParadoxMessageCode.ErrorMissingOverride, method.Method.Span, method.Method, mixinName);
                                continue;
                            }
                        }
                        else if (method.Method.Qualifiers.Contains(ParadoxStorageQualifier.Override))
                        {
                            log.Error(ParadoxMessageCode.ErrorOverrideDeclaration, method.Method.Span, method.Method, mixinName);
                            continue;
                        }
                    }

                    Methods.Remove(methodDecl);
                }
                else
                {
                    if (method.Method.Qualifiers.Contains(ParadoxStorageQualifier.Override))
                    {
                        log.Error(ParadoxMessageCode.ErrorNoMethodToOverride, method.Method.Span, method.Method, mixinName);
                        continue;
                    }
                }

                Methods.Add(method);

                // TODO: handle declarations vs definitions
            }

            Variables.UnionWith(virtualTable.Variables.Where(x => !Variables.Contains(x)));
            StructureTypes.AddRange(virtualTable.StructureTypes.Where(x => !StructureTypes.Contains(x)));
            Typedefs.AddRange(virtualTable.Typedefs.Where(x => !Typedefs.Contains(x)));
        }
Esempio n. 31
0
 public GameDebuggerHost(LoggerResult logger)
 {
     Log = logger;
 }
Esempio n. 32
0
        public static int RunProcessAndRedirectToLogger(string command, string parameters, string workingDirectory, LoggerResult logger)
        {
            var process = new Process
            {
                StartInfo = new ProcessStartInfo(command)
                {
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    WorkingDirectory       = workingDirectory,
                    Arguments = parameters,
                }
            };

            process.Start();

            DataReceivedEventHandler outputDataReceived = (_, args) => LockProcessAndAddDataToLogger(process, logger, false, args);
            DataReceivedEventHandler errorDataReceived  = (_, args) => LockProcessAndAddDataToLogger(process, logger, true, args);

            process.OutputDataReceived += outputDataReceived;
            process.ErrorDataReceived  += errorDataReceived;
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            process.WaitForExit();
            process.CancelOutputRead();
            process.CancelErrorRead();

            process.OutputDataReceived -= outputDataReceived;
            process.ErrorDataReceived  -= errorDataReceived;

            return(process.ExitCode);
        }
Esempio n. 33
0
        private static PackageSession GenerateSample(UDirectory outputPath, Guid templateGuid, string sampleName, LoggerResult logger)
        {
            // Make output path absolute
            if (!outputPath.IsAbsolute)
            {
                outputPath = UPath.Combine(Environment.CurrentDirectory, outputPath);
            }

            Console.WriteLine(@"Bootstrapping: " + sampleName);

            var session   = new PackageSession();
            var generator = TemplateSampleGenerator.Default;

            // Ensure progress is shown while it is happening.
            logger.MessageLogged += (sender, eventArgs) => Console.WriteLine(eventArgs.Message.Text);

            var parameters = new SessionTemplateGeneratorParameters {
                Session = session
            };

            parameters.Unattended = true;
            TemplateSampleGenerator.SetParameters(
                parameters,
                AssetRegistry.SupportedPlatforms.Where(x => x.Type == Core.PlatformType.Windows).Select(x => new SelectedSolutionPlatform(x, x.Templates.FirstOrDefault())).ToList(),
                addGamesTesting: true);

            session.SolutionPath = UPath.Combine <UFile>(outputPath, sampleName + ".sln");

            // Properly delete previous version
            if (Directory.Exists(outputPath))
            {
                try
                {
                    Directory.Delete(outputPath, true);
                }
                catch (Exception)
                {
                    logger.Warning($"Unable to delete directory [{outputPath}]");
                }
            }

            // Load templates
            XenkoDefaultAssetsPlugin.LoadDefaultTemplates();
            var xenkoTemplates = TemplateManager.FindTemplates(session);

            parameters.Description     = xenkoTemplates.First(x => x.Id == templateGuid);
            parameters.Name            = sampleName;
            parameters.Namespace       = sampleName;
            parameters.OutputDirectory = outputPath;
            parameters.Logger          = logger;

            if (!generator.PrepareForRun(parameters).Result)
            {
                logger.Error("PrepareForRun returned false for the TemplateSampleGenerator");
            }

            if (!generator.Run(parameters))
            {
                logger.Error("Run returned false for the TemplateSampleGenerator");
            }

            var updaterTemplate = xenkoTemplates.First(x => x.FullPath.ToString().EndsWith("UpdatePlatforms.xktpl"));

            parameters.Description = updaterTemplate;

            if (logger.HasErrors)
            {
                throw new InvalidOperationException($"Error generating sample {sampleName} from template:\r\n{logger.ToText()}");
            }

            return(session);
        }
Esempio n. 34
0
        private void UpdateReflection(ShaderBytecode shaderBytecode, EffectReflection effectReflection, LoggerResult log)
        {
            var shaderReflectionRaw     = new SharpDX.D3DCompiler.ShaderReflection(shaderBytecode);
            var shaderReflectionRawDesc = shaderReflectionRaw.Description;

            // Constant Buffers
            for (int i = 0; i < shaderReflectionRawDesc.ConstantBuffers; ++i)
            {
                var constantBufferRaw     = shaderReflectionRaw.GetConstantBuffer(i);
                var constantBufferRawDesc = constantBufferRaw.Description;
                var linkBuffer            = effectReflection.ConstantBuffers.FirstOrDefault(buffer => buffer.Name == constantBufferRawDesc.Name && buffer.Stage == ShaderStage.None);

                var constantBuffer = GetConstantBufferReflection(constantBufferRaw, ref constantBufferRawDesc, linkBuffer, log);
                constantBuffer.Stage = shaderBytecode.Stage;
                effectReflection.ConstantBuffers.Add(constantBuffer);
            }

            // BoundResources
            for (int i = 0; i < shaderReflectionRawDesc.BoundResources; ++i)
            {
                var boundResourceDesc = shaderReflectionRaw.GetResourceBindingDescription(i);

                string linkKeyName = null;
                foreach (var linkResource in effectReflection.ResourceBindings)
                {
                    if (linkResource.Param.RawName == boundResourceDesc.Name && linkResource.Stage == ShaderStage.None)
                    {
                        linkKeyName = linkResource.Param.KeyName;
                        break;
                    }
                }

                if (linkKeyName == null)
                {
                    log.Error("Resource [{0}] has no link", boundResourceDesc.Name);
                }
                else
                {
                    var binding = GetResourceBinding(boundResourceDesc, linkKeyName, log);
                    binding.Stage = shaderBytecode.Stage;

                    effectReflection.ResourceBindings.Add(binding);
                }
            }
        }
Esempio n. 35
0
        private EffectParameterType ConvertVariableValueType(ShaderVariableType type, LoggerResult log)
        {
            EffectParameterType effectParameterType;

            if (!MapTypes.TryGetValue(type, out effectParameterType))
            {
                log.Error("Type [{0}] from D3DCompiler not supported", type);
            }
            return(effectParameterType);
        }
Esempio n. 36
0
        public static bool EnsureRouterLaunched(bool attachChildJob = false, bool checkIfPortOpen = true)
        {
            try
            {
                // Try to connect to router
                FileVersionInfo runningRouterVersion = null;
                Process         runningRouterProcess = null;
                foreach (var process in Process.GetProcessesByName("Stride.ConnectionRouter"))
                {
                    try
                    {
                        runningRouterVersion = process.MainModule.FileVersionInfo;
                        runningRouterProcess = process;
                        break;
                    }
                    catch (Exception)
                    {
                    }
                }

                // Make sure to use .exe rather than .dll (.NET Core)
                var defaultRouterAssemblyLocation = LoaderToolLocator.GetExecutable(typeof(Router).Assembly.Location);
                if (defaultRouterAssemblyLocation == null)
                {
                    throw new InvalidOperationException("Could not find Connection Router assembly location");
                }

                // Setup with default locations
                var routerAssemblyLocation = defaultRouterAssemblyLocation;
                var routerAssemblyExe      = Path.GetFileName(routerAssemblyLocation);

                // Try to locate using Stride.ConnectionRouter package
                var logger  = new LoggerResult();
                var package = PackageStore.Instance.FindLocalPackage("Stride.ConnectionRouter", new PackageVersionRange(new PackageVersion(StrideVersion.NuGetVersion)));
                if (package != null)
                {
                    routerAssemblyLocation = package.GetFiles().FirstOrDefault(x => string.Compare(Path.GetFileName(x.Path), routerAssemblyExe, true) == 0)?.FullPath ?? routerAssemblyLocation;
                }

                // If already started, check if found version is same that we wanted to start
                if (runningRouterVersion != null)
                {
                    var routerAssemblyFileVersionInfo = FileVersionInfo.GetVersionInfo(routerAssemblyLocation);

                    // Check that current router is at least as good as the one of latest found Stride
                    if (new PackageVersion(routerAssemblyFileVersionInfo.FileVersion) <= new PackageVersion(runningRouterVersion.FileVersion))
                    {
                        return(true);
                    }
                }

                // Kill previous router process (if any)
                if (runningRouterProcess != null)
                {
                    runningRouterProcess.Kill();
                    runningRouterProcess.WaitForExit();
                }

                // Start new router process
                var spawnedRouterProcess = Process.Start(routerAssemblyLocation);

                // If we are in "developer" mode, attach job so that it gets killed with editor
                if (attachChildJob && spawnedRouterProcess != null)
                {
                    new AttachedChildProcessJob(spawnedRouterProcess);
                }

                if (checkIfPortOpen)
                {
                    using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                    {
                        // Try during 5 seconds (10 * 500 msec)
                        for (int i = 0; i < 10; ++i)
                        {
                            try
                            {
                                socket.Connect("localhost", RouterClient.DefaultPort);
                            }
                            catch (SocketException)
                            {
                                // Try again in 500 msec
                                Thread.Sleep(500);
                                continue;
                            }
                            break;
                        }
                    }
                }

                return(spawnedRouterProcess != null);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 37
0
 public PackageBuilderOptions(LoggerResult logger)
 {
     if (logger == null) throw new ArgumentNullException("logger");
     Logger = logger;
 }
Esempio n. 38
0
        /// <summary>
        /// Find the base definition of the method and override its occurrence
        /// </summary>
        /// <param name="methodDeclaration"></param>
        /// <param name="errorLogger"></param>
        private void LookForBaseDeclarationMixin(MethodDeclaration methodDeclaration, LoggerResult errorLogger)
        {
            foreach (var dict in VirtualTableGroup.Select(x => x.Value))
            {
                for (int i = 0; i < dict.Length; ++i)
                {
                    var method = dict[i];
                    var baseDeclarationMixin = (string)method.GetTag(StrideTags.BaseDeclarationMixin);

                    // TODO: take typedefs into account...
                    if (method.IsSameSignature(methodDeclaration))
                    {
                        var sourceShader = ((ModuleMixin)methodDeclaration.GetTag(StrideTags.ShaderScope)).MixinName;

                        // test override
                        if (methodDeclaration is MethodDefinition && method is MethodDefinition && !methodDeclaration.Qualifiers.Contains(StrideStorageQualifier.Override))
                        {
                            errorLogger.Error(StrideMessageCode.ErrorMissingOverride, method.Span, methodDeclaration, sourceShader);
                        }
                        if (!(methodDeclaration is MethodDefinition))
                        {
                            errorLogger.Error(StrideMessageCode.ErrorOverrindingDeclaration, method.Span, methodDeclaration, sourceShader);
                        }

                        if (method.Qualifiers.Contains(StrideStorageQualifier.Stage) && !methodDeclaration.Qualifiers.Contains(StrideStorageQualifier.Stage))
                        {
                            errorLogger.Warning(StrideMessageCode.WarningMissingStageKeyword, methodDeclaration.Span, methodDeclaration, (methodDeclaration.GetTag(StrideTags.ShaderScope) as ModuleMixin).MixinName);
                            methodDeclaration.Qualifiers |= StrideStorageQualifier.Stage;
                        }
                        else if (!method.Qualifiers.Contains(StrideStorageQualifier.Stage) && methodDeclaration.Qualifiers.Contains(StrideStorageQualifier.Stage))
                        {
                            errorLogger.Error(StrideMessageCode.ErrorExtraStageKeyword, methodDeclaration.Span, methodDeclaration, method, (methodDeclaration.GetTag(StrideTags.ShaderScope) as ModuleMixin).MixinName);
                            methodDeclaration.Qualifiers.Values.Remove(StrideStorageQualifier.Stage);
                        }

                        dict[i] = methodDeclaration;
                        methodDeclaration.SetTag(StrideTags.BaseDeclarationMixin, baseDeclarationMixin);
                    }
                }
            }
        }
Esempio n. 39
0
 public LocalCommandContext(IExecuteContext executeContext, CommandBuildStep step, BuilderContext builderContext) : base(step.Command, builderContext)
 {
     this.executeContext = executeContext;
     logger = new ForwardingLoggerResult(executeContext.Logger);
     Step   = step;
 }
Esempio n. 40
0
 public ShaderNavigationResult()
 {
     Messages = new LoggerResult();
 }
Esempio n. 41
0
        /// <summary>
        /// Adds the methods defined in the final mixin
        /// </summary>
        /// <param name="methodDeclarations">a list of MethodDeclaration</param>
        /// <param name="className">the name of the class</param>
        /// <param name="errorLogger">the logger for errors and warnings</param>
        public void AddFinalDeclarations(List <MethodDeclaration> methodDeclarations, string className, LoggerResult errorLogger)
        {
            var finalDict = new MethodDeclaration[methodDeclarations.Count];

            foreach (var methodDecl in methodDeclarations)
            {
                var vtableReference = (VTableReference)methodDecl.GetTag(StrideTags.VirtualTableReference);
                finalDict[vtableReference.Slot] = methodDecl;

                // TODO: override/abstract behavior
                //if (methodDecl.Qualifiers.Contains(StrideStorageQualifier.Override))
                LookForBaseDeclarationMixin(methodDecl, errorLogger);
            }

            VirtualTableGroup.Add(className, finalDict);
        }
Esempio n. 42
0
        private EffectBytecodeCompilerResult CompileBytecode(ShaderMixinSource mixinTree, EffectCompilerParameters effectParameters, CompilerParameters compilerParameters, ObjectId mixinObjectId, DatabaseFileProvider database, string compiledUrl)
        {
            // Open the database for writing
            var log       = new LoggerResult();
            var effectLog = GlobalLogger.GetLogger("EffectCompilerCache");

            // Note: this compiler is expected to not be async and directly write stuff in localLogger
            var compiledShader = base.Compile(mixinTree, effectParameters, compilerParameters).WaitForResult();

            compiledShader.CompilationLog.CopyTo(log);

            // If there are any errors, return immediately
            if (log.HasErrors)
            {
                lock (compilingShaders)
                {
                    compilingShaders.Remove(mixinObjectId);
                }

                log.CopyTo(effectLog);
                return(new EffectBytecodeCompilerResult(null, log));
            }

            // Compute the bytecodeId
            var newBytecodeId = compiledShader.Bytecode.ComputeId();

            // Check if we really need to store the bytecode
            lock (bytecodes)
            {
                // Using custom serialization to the database to store an object with a custom id
                // TODO: Check if we really need to write the bytecode everytime even if id is not changed
                var memoryStream = new MemoryStream();
                compiledShader.Bytecode.WriteTo(memoryStream);

                // Write current cache at the end (not part of the pure bytecode, but we use this as meta info)
                var writer = new BinarySerializationWriter(memoryStream);
                writer.Write(CurrentCache);

                memoryStream.Position = 0;
                database.ObjectDatabase.Write(memoryStream, newBytecodeId, true);
                database.ContentIndexMap[compiledUrl] = newBytecodeId;

                // Save bytecode Id to the database cache as well
                memoryStream.SetLength(0);
                memoryStream.Write((byte[])newBytecodeId, 0, ObjectId.HashSize);
                memoryStream.Position = 0;
                database.ObjectDatabase.Write(memoryStream, mixinObjectId, true);

                if (!bytecodes.ContainsKey(newBytecodeId))
                {
                    log.Verbose($"New effect compiled #{effectCompileCount} [{mixinObjectId}] (db: {newBytecodeId})\r\n{compilerParameters?.ToStringPermutationsDetailed()}");
                    Interlocked.Increment(ref effectCompileCount);

                    // Replace or add new bytecode
                    bytecodes[newBytecodeId] = new KeyValuePair <EffectBytecode, EffectBytecodeCacheLoadSource>(compiledShader.Bytecode, EffectBytecodeCacheLoadSource.JustCompiled);
                }
            }

            lock (compilingShaders)
            {
                compilingShaders.Remove(mixinObjectId);
            }

            log.CopyTo(effectLog);
            return(compiledShader);
        }
Esempio n. 43
0
 public ModuleMixinInfo()
 {
     Log          = new LoggerResult();
     Instanciated = true;
 }
Esempio n. 44
0
        public static void Instantiate(ShaderClassType classType, Dictionary <string, Expression> expressions, Dictionary <string, Identifier> identifiers, bool autoGenericInstances, LoggerResult log)
        {
            var instantiator = new XenkoClassInstantiator(classType, expressions, identifiers, autoGenericInstances, log);

            instantiator.Run();
        }
 public EffectBytecodeCompilerResult(EffectBytecode bytecode, LoggerResult compilationLog)
 {
     Bytecode       = bytecode;
     CompilationLog = compilationLog;
 }
Esempio n. 46
0
        private EffectParameterResourceData GetResourceBinding(SharpDX.D3DCompiler.InputBindingDescription bindingDescriptionRaw, string name, LoggerResult log)
        {
            var paramClass = EffectParameterClass.Object;
            var paramType = EffectParameterType.Void;

            switch (bindingDescriptionRaw.Type)
            {
                case SharpDX.D3DCompiler.ShaderInputType.TextureBuffer:
                    paramType = EffectParameterType.TextureBuffer;
                    paramClass = EffectParameterClass.TextureBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.ConstantBuffer:
                    paramType = EffectParameterType.ConstantBuffer;
                    paramClass = EffectParameterClass.ConstantBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.Texture:
                    paramClass = EffectParameterClass.ShaderResourceView;
                    switch (bindingDescriptionRaw.Dimension)
                    {
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Buffer:
                            paramType = EffectParameterType.Buffer;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1D:
                            paramType = EffectParameterType.Texture1D;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1DArray:
                            paramType = EffectParameterType.Texture1DArray;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D:
                            paramType = EffectParameterType.Texture2D;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray:
                            paramType = EffectParameterType.Texture2DArray;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DMultisampled:
                            paramType = EffectParameterType.Texture2DMultisampled;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DMultisampledArray:
                            paramType = EffectParameterType.Texture2DMultisampledArray;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D:
                            paramType = EffectParameterType.Texture3D;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube:
                            paramType = EffectParameterType.TextureCube;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray:
                            paramType = EffectParameterType.TextureCubeArray;
                            break;
                    }
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.Structured:
                    paramClass = EffectParameterClass.ShaderResourceView;
                    paramType = EffectParameterType.StructuredBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.ByteAddress:
                    paramClass = EffectParameterClass.ShaderResourceView;
                    paramType = EffectParameterType.ByteAddressBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWTyped:
                    paramClass = EffectParameterClass.UnorderedAccessView;
                    switch (bindingDescriptionRaw.Dimension)
                    {
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Buffer:
                            paramType = EffectParameterType.RWBuffer;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1D:
                            paramType = EffectParameterType.RWTexture1D;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1DArray:
                            paramType = EffectParameterType.RWTexture1DArray;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D:
                            paramType = EffectParameterType.RWTexture2D;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray:
                            paramType = EffectParameterType.RWTexture2DArray;
                            break;
                        case SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D:
                            paramType = EffectParameterType.RWTexture3D;
                            break;
                    }
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWStructured:
                    paramClass = EffectParameterClass.UnorderedAccessView;
                    paramType = EffectParameterType.RWStructuredBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWByteAddress:
                    paramClass = EffectParameterClass.UnorderedAccessView;
                    paramType = EffectParameterType.RWByteAddressBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewAppendStructured:
                    paramClass = EffectParameterClass.UnorderedAccessView;
                    paramType = EffectParameterType.AppendStructuredBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewConsumeStructured:
                    paramClass = EffectParameterClass.UnorderedAccessView;
                    paramType = EffectParameterType.ConsumeStructuredBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWStructuredWithCounter:
                    paramClass = EffectParameterClass.UnorderedAccessView;
                    paramType = EffectParameterType.RWStructuredBuffer;
                    break;
                case SharpDX.D3DCompiler.ShaderInputType.Sampler:
                    paramClass = EffectParameterClass.Sampler;
                    paramType = EffectParameterType.Sampler;
                    break;
            }

            var binding = new EffectParameterResourceData()
                {
                    Param =
                        {
                            KeyName = name,
                            RawName = bindingDescriptionRaw.Name,
                            Class = paramClass,
                            Type = paramType
                        },
                    SlotStart = bindingDescriptionRaw.BindPoint,
                    SlotCount = bindingDescriptionRaw.BindCount,
                };

            return binding;
        }
Esempio n. 47
0
        public static void Build(ILogger log, Package package, string outputDirectory = null)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            var meta = new ManifestMetadata();

            PackageStore.ToNugetManifest(package.Meta, meta);

            // Sanity check: Xenko version should be same between NuGet package and Xenko package
            var nugetVersion   = new PackageVersion(XenkoVersion.NuGetVersion).Version;
            var packageVersion = package.Meta.Version.Version;

            if (nugetVersion != packageVersion)
            {
                log.Error($"Package has mismatching version: NuGet package version is {nugetVersion} and Xenko Package version is {packageVersion}");
                return;
            }

            if (nugetVersion.Revision <= 0)
            {
                // If 0, we have special cases with NuGet dropping it in install path, could be dangerous and lead to bugs if not properly tested.
                log.Error($"Package has revision {nugetVersion} but 4th digit needs to be at least 1.");
                return;
            }

            // Override version with NuGet version (4th number is different in Xenko package)
            meta.Version = XenkoVersion.NuGetVersion;

            var builder = new NugetPackageBuilder();

            builder.Populate(meta);

            var currentAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            var mainPlatformDirectory   = Path.GetFileName(Path.GetDirectoryName(currentAssemblyLocation));

            // TODO this is not working
            // We are excluding everything that is in a folder that starts with a dot (ie. .shadow, .vs)
            var files = new List <ManifestFile>()
            {
                NewFile(@"Bin\**\*.exe", "Bin", @"Bin\**\.*\**\*.exe;Bin\**\Tools\**.exe"),
                NewFile(@"Bin\**\*.so", "Bin", @"Bin\**\.*\**\*.so;Bin\Windows\lib\**\*.so"),
                NewFile(@"Bin\**\*.ssdeps", "Bin", @"Bin\**\.*\**\*.ssdeps"),
                NewFile(@"Bin\**\*.a", "Bin", @"Bin\**\.*\**\*.a"),
                NewFile(@"Bin\**\*.md", "Bin", @"Bin\**\.*\**\*.md"),
                NewFile(@"Bin\**\*.html", "Bin", @"Bin\**\.*\**\*.html"),
                NewFile(@"Bin\**\*.config", "Bin", @"Bin\**\.*\**\*.config"),
                NewFile(@"Bin\**\*.dll", "Bin", @"Bin\**\.*\**\*.dll;Bin\Windows\lib\**\*.dll"),
                NewFile(@"Bin\**\*.xml", "Bin", @"Bin\**\.*\**\*.xml"),
                NewFile(@"Bin\**\*.usrdoc", "Bin", @"Bin\**\.*\**\*.usrdoc"),
                NewFile(@"Bin\**\*.winmd", "Bin", @"Bin\**\.*\**\*.winmd"),
                NewFile(@"Bin\**\*.sh", "Bin", @"Bin\**\.*\**\*.sh"),
                NewFile(@"Bin\**\*.json", "Bin", @"Bin\**\.*\**\*.json"),
                NewFile(@"deps\AssemblyProcessor\*.exe", @"deps/AssemblyProcessor"),
                NewFile(@"deps\AssemblyProcessor\*.dll", @"deps/AssemblyProcessor"),
                NewFile(@"deps\CoreFX\**\*.*", @"deps\CoreFX"),
                NewFile($@"Bin\{mainPlatformDirectory}\ios-tcprelay\*.py", $@"Bin\{mainPlatformDirectory}\ios-tcprelay"),
                NewFile(@"Targets\*.targets", "Targets"),
                NewFile($@"Bin\{mainPlatformDirectory}\SiliconStudio.*.pdb", $@"Bin\{mainPlatformDirectory}", @"Bin\**\SiliconStudio.Xenko.Importer*.pdb;Bin\**\SiliconStudio.Xenko.Assimp.Translation.pdb"),
            };

            // Handle Assets
            var rootDir = package.RootDirectory;


            var newPackage = new Package {
                Meta = package.Meta
            };

            foreach (var profile in package.Profiles)
            {
                var target = "Assets/" + profile.Name;
                foreach (var assetFolder in profile.AssetFolders)
                {
                    // TODO: handle exclude in asset folders
                    //files.Add(NewFile(source, target, @"**\*.cs;**\*.hlsl;**\*.csproj;**\*.csproj.user;**\obj\**"));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xksl", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkfx", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkfnt", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xksheet", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkuilib", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkgfxcomp", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xktex", target));
                    var resourceFolder = UPath.Combine(assetFolder.Path, new UDirectory("../../Resources"));
                    if (Directory.Exists(resourceFolder.ToWindowsPath()))
                    {
                        files.Add(NewFile(resourceFolder.MakeRelative(rootDir) + "/**/*.*", "Resources"));
                    }
                }
                var targetProfile = new PackageProfile(profile.Name);
                targetProfile.AssetFolders.Add(new AssetFolder(target));
                newPackage.Profiles.Add(targetProfile);
            }

            //Handle RootAssets
            foreach (var rootAsset in package.RootAssets)
            {
                newPackage.RootAssets.Add(rootAsset);
            }

            // Handle templates
            var targetFolder = new TemplateFolder("Templates");

            foreach (var templateFolder in package.TemplateFolders)
            {
                var        source = templateFolder.Path.MakeRelative(rootDir) + "/**";
                UDirectory target = targetFolder.Path;
                if (templateFolder.Group != null)
                {
                    target = UPath.Combine(target, templateFolder.Group);
                }

                var excludeFiles = templateFolder.Exclude;
                files.Add(NewFile(source, target, excludeFiles));

                // Add template files
                foreach (var templateFile in templateFolder.Files)
                {
                    var newTemplateFile = templateFile.MakeRelative(templateFolder.Path);
                    if (templateFolder.Group != null)
                    {
                        newTemplateFile = UPath.Combine(templateFolder.Group, newTemplateFile);
                    }

                    newTemplateFile = UPath.Combine(targetFolder.Path, newTemplateFile);
                    targetFolder.Files.Add(newTemplateFile);
                }
            }

            // Add files
            builder.PopulateFiles(package.RootDirectory, files);
            files.Clear();

            var dataFiles = builder.Files.ToList();

            builder.ClearFiles();

            // Create temp package for archive
            newPackage.TemplateFolders.Add(targetFolder);
            var newPackageFileName = "temp" + Guid.NewGuid() + ".xkpkg";

            newPackage.FullPath = package.RootDirectory + "/" + newPackageFileName;
            var result = new LoggerResult();

            newPackage.Save(result);
            if (result.HasErrors)
            {
                throw new InvalidOperationException(result.ToText());
                // TODO throw error
            }

            // Add the package file
            files.Add(NewFile(newPackageFileName, package.Meta.Name + Package.PackageFileExtension));
            // Add entry point to decompress LZMA
            files.Add(NewFile(@"tools\**\*.exe", "tools"));
            files.Add(NewFile(@"tools\**\*.dll", "tools"));
            // Add an empty .xz file so that it gets added to [Content_Types].xml
            // This file will be removed later
            files.Add(NewFile(@"tools\data_empty.xz", string.Empty));

            // Repopulate with .xkpkg file
            builder.PopulateFiles(package.RootDirectory, files);

            outputDirectory = outputDirectory ?? Environment.CurrentDirectory;

            // Save the nupkg
            var  outputPath        = GetOutputPath(builder, outputDirectory);
            bool isExistingPackage = File.Exists(outputPath);

            if (isExistingPackage)
            {
                File.Delete(outputPath);
            }
            try
            {
                using (Stream stream = File.Create(outputPath))
                {
                    builder.Save(stream);

                    stream.Position = 0;

                    // Add LZMA file as update so that it is stored without compression
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Update, true))
                    {
                        // Delete data_empty.xz
                        var dataEntry = archive.GetEntry("data_empty.xz");
                        dataEntry.Delete();

                        // Create data.xz (no compression since .xz is already compressed)
                        dataEntry = archive.CreateEntry("data.xz", CompressionLevel.NoCompression);
                        using (var dataStream = dataEntry.Open())
                        {
                            // Generate LZMA
                            using (var indexedArchive = new IndexedArchive())
                            {
                                foreach (var file in dataFiles)
                                {
                                    indexedArchive.AddFile(Path.Combine(package.RootDirectory, file.SourcePath), file.Path);
                                }
                                indexedArchive.Save(dataStream, new ConsoleProgressReport());
                            }
                        }
                    }
                }
            }
            catch
            {
                if (!isExistingPackage && File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }
                throw;
            }

            File.Delete(newPackage.FullPath);
        }
Esempio n. 48
0
 private EffectParameterType ConvertVariableValueType(ShaderVariableType type, LoggerResult log)
 {
     EffectParameterType effectParameterType;
     if (!MapTypes.TryGetValue(type, out effectParameterType))
     {
         log.Error("Type [{0}] from D3DCompiler not supported", type);
     }
     return effectParameterType;
 }
Esempio n. 49
0
 private XenkoClassInstantiator(ShaderClassType classType, Dictionary <string, Expression> expressions, Dictionary <string, Identifier> identifiers, bool autoGenericInstances, LoggerResult log)
     : base(false, false)
 {
     shaderClassType           = classType;
     expressionGenerics        = expressions;
     identifiersGenerics       = identifiers;
     this.autoGenericInstances = autoGenericInstances;
     logger           = log;
     variableGenerics = shaderClassType.ShaderGenerics.ToDictionary(x => x.Name.Text, x => x);
 }
Esempio n. 50
0
        private EffectParameterResourceData GetResourceBinding(SharpDX.D3DCompiler.InputBindingDescription bindingDescriptionRaw, string name, LoggerResult log)
        {
            var paramClass = EffectParameterClass.Object;
            var paramType  = EffectParameterType.Void;

            switch (bindingDescriptionRaw.Type)
            {
            case SharpDX.D3DCompiler.ShaderInputType.TextureBuffer:
                paramType  = EffectParameterType.TextureBuffer;
                paramClass = EffectParameterClass.TextureBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.ConstantBuffer:
                paramType  = EffectParameterType.ConstantBuffer;
                paramClass = EffectParameterClass.ConstantBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.Texture:
                paramClass = EffectParameterClass.ShaderResourceView;
                switch (bindingDescriptionRaw.Dimension)
                {
                case SharpDX.Direct3D.ShaderResourceViewDimension.Buffer:
                    paramType = EffectParameterType.Buffer;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1D:
                    paramType = EffectParameterType.Texture1D;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1DArray:
                    paramType = EffectParameterType.Texture1DArray;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D:
                    paramType = EffectParameterType.Texture2D;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray:
                    paramType = EffectParameterType.Texture2DArray;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DMultisampled:
                    paramType = EffectParameterType.Texture2DMultisampled;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DMultisampledArray:
                    paramType = EffectParameterType.Texture2DMultisampledArray;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D:
                    paramType = EffectParameterType.Texture3D;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.TextureCube:
                    paramType = EffectParameterType.TextureCube;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.TextureCubeArray:
                    paramType = EffectParameterType.TextureCubeArray;
                    break;
                }
                break;

            case SharpDX.D3DCompiler.ShaderInputType.Structured:
                paramClass = EffectParameterClass.ShaderResourceView;
                paramType  = EffectParameterType.StructuredBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.ByteAddress:
                paramClass = EffectParameterClass.ShaderResourceView;
                paramType  = EffectParameterType.ByteAddressBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWTyped:
                paramClass = EffectParameterClass.UnorderedAccessView;
                switch (bindingDescriptionRaw.Dimension)
                {
                case SharpDX.Direct3D.ShaderResourceViewDimension.Buffer:
                    paramType = EffectParameterType.RWBuffer;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1D:
                    paramType = EffectParameterType.RWTexture1D;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture1DArray:
                    paramType = EffectParameterType.RWTexture1DArray;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D:
                    paramType = EffectParameterType.RWTexture2D;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture2DArray:
                    paramType = EffectParameterType.RWTexture2DArray;
                    break;

                case SharpDX.Direct3D.ShaderResourceViewDimension.Texture3D:
                    paramType = EffectParameterType.RWTexture3D;
                    break;
                }
                break;

            case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWStructured:
                paramClass = EffectParameterClass.UnorderedAccessView;
                paramType  = EffectParameterType.RWStructuredBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWByteAddress:
                paramClass = EffectParameterClass.UnorderedAccessView;
                paramType  = EffectParameterType.RWByteAddressBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewAppendStructured:
                paramClass = EffectParameterClass.UnorderedAccessView;
                paramType  = EffectParameterType.AppendStructuredBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewConsumeStructured:
                paramClass = EffectParameterClass.UnorderedAccessView;
                paramType  = EffectParameterType.ConsumeStructuredBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.UnorderedAccessViewRWStructuredWithCounter:
                paramClass = EffectParameterClass.UnorderedAccessView;
                paramType  = EffectParameterType.RWStructuredBuffer;
                break;

            case SharpDX.D3DCompiler.ShaderInputType.Sampler:
                paramClass = EffectParameterClass.Sampler;
                paramType  = EffectParameterType.Sampler;
                break;
            }

            var binding = new EffectParameterResourceData()
            {
                Param =
                {
                    KeyName = name,
                    RawName = bindingDescriptionRaw.Name,
                    Class   = paramClass,
                    Type    = paramType
                },
                SlotStart = bindingDescriptionRaw.BindPoint,
                SlotCount = bindingDescriptionRaw.BindCount,
            };

            return(binding);
        }
Esempio n. 51
0
        private ShaderConstantBufferDescription GetConstantBufferReflection(ConstantBuffer constantBufferRaw, ref ConstantBufferDescription constantBufferRawDesc, ShaderConstantBufferDescription linkBuffer, LoggerResult log)
        {
            var constantBuffer = new ShaderConstantBufferDescription
            {
                Name = constantBufferRawDesc.Name,
                Size = constantBufferRawDesc.Size,
            };

            switch (constantBufferRawDesc.Type)
            {
                case SharpDX.D3DCompiler.ConstantBufferType.ConstantBuffer:
                    constantBuffer.Type = ConstantBufferType.ConstantBuffer;
                    break;
                case SharpDX.D3DCompiler.ConstantBufferType.TextureBuffer:
                    constantBuffer.Type = ConstantBufferType.TextureBuffer;
                    break;
                default:
                    constantBuffer.Type = ConstantBufferType.Unknown;
                    break;
            }

            // ConstantBuffers variables
            var members = new List<EffectParameterValueData>();
            for (int i = 0; i < constantBufferRawDesc.VariableCount; i++)
            {
                var variable = constantBufferRaw.GetVariable(i);
                var variableType = variable.GetVariableType();
                var variableDescription = variable.Description;
                var variableTypeDescription = variableType.Description;

                var parameter = new EffectParameterValueData()
                {
                    Param =
                    {
                        Class = (EffectParameterClass)variableTypeDescription.Class,
                        Type = ConvertVariableValueType(variableTypeDescription.Type, log),
                        RawName = variableDescription.Name,
                    },
                    Offset = variableDescription.StartOffset,
                    Size = variableDescription.Size,
                    Count = variableTypeDescription.ElementCount == 0 ? 1 : variableTypeDescription.ElementCount,
                    RowCount = (byte)variableTypeDescription.RowCount,
                    ColumnCount = (byte)variableTypeDescription.ColumnCount,
                };

                if (variableTypeDescription.Offset != 0)
                {
                    log.Error("Unexpected offset [{0}] for variable [{1}] in constant buffer [{2}]", variableTypeDescription.Offset, variableDescription.Name, constantBuffer.Name);
                }

                bool bindingNotFound = true;
                // Retrieve Link Member
                foreach (var binding in linkBuffer.Members)
                {
                    if (binding.Param.RawName == variableDescription.Name)
                    {
                        // TODO: should we replicate linkMember.Count/RowCount/ColumnCount? or use what is retrieved by D3DCompiler reflection
                        parameter.Param.KeyName = binding.Param.KeyName;
                        bindingNotFound = false;
                        break;
                    }
                }

                if (bindingNotFound)
                {
                    log.Error("Variable [{0}] in constant buffer [{1}] has no link", variableDescription.Name, constantBuffer.Name);
                }

                members.Add(parameter);
            }
            constantBuffer.Members = members.ToArray();

            return constantBuffer;
        }
Esempio n. 52
0
 public override EffectBytecode Compile(ShaderMixinSource mixin, string fullEffectName, ShaderMixinParameters compilerParameters, HashSet <string> modifiedShaders, HashSet <string> recentlyModifiedShaders, LoggerResult log)
 {
     throw new NotSupportedException("Shader Compilation is not allowed at run time on this platform.");
 }
Esempio n. 53
0
        /// <summary>
        /// Converts the specified hlsl source code to glsl.
        /// </summary>
        /// <param name="hlslSourcecode">The HLSL source code.</param>
        /// <param name="hlslEntryPoint">The HLSL entry point.</param>
        /// <param name="stage">The stage to convert.</param>
        /// <param name="shader">The shader.</param>
        /// <param name="inputHlslFilepath">The input HLSL filepath.</param>
        /// <returns>
        /// The resulting glsl AST tree.
        /// </returns>
        public global::SiliconStudio.Shaders.Ast.Shader Convert(string hlslSourcecode, string hlslEntryPoint, PipelineStage stage, string inputHlslFilepath, LoggerResult log)
        {
            try
            {
                // Convert from Framework.Graphics ShaderMacro to Framework.Shaders ShaderMacro
                var macros = new global::SiliconStudio.Shaders.Parser.ShaderMacro[Macros.Count];
                for (int index = 0; index < Macros.Count; index++)
                {
                    macros[index] = new global::SiliconStudio.Shaders.Parser.ShaderMacro(Macros[index].Name, Macros[index].Definition);
                }

                var result = HlslParser.TryPreProcessAndParse(hlslSourcecode, inputHlslFilepath, macros, IncludeDirectories);

                if (result.HasErrors)
                {
                    log.Error(result.ToString());
                    return(null);
                }

                // Prepare the shader before type inference analysis
                HlslToGlslConvertor.Prepare(result.Shader);

                HlslSemanticAnalysis.Run(result);

                // If there are any type inference analysis, just display all errors but ytu
                if (result.HasErrors)
                {
                    log.Error(result.ToString());
                    return(null);
                }

                return(Convert(result, hlslEntryPoint, stage, inputHlslFilepath, log));
            }
            catch (Exception ex)
            {
                log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
            }
            return(null);
        }
 public LocalCommandContext(IExecuteContext executeContext, CommandBuildStep step, BuilderContext builderContext) : base(step.Command, builderContext)
 {
     this.executeContext = executeContext;
     logger = new ForwardingLoggerResult(executeContext.Logger);
     Step = step;
 }
Esempio n. 55
0
        private BuildResultCode BuildGetGraphicsPlatform()
        {
            var localLogger = new LoggerResult();
            var simplePackage = Package.Load(localLogger, builderOptions.PackageFile, new PackageLoadParameters { AutoLoadTemporaryAssets = false, LoadAssemblyReferences = false, AutoCompileProjects = false });
            if (simplePackage == null
                || localLogger.HasErrors)
            {
                localLogger.CopyTo(builderOptions.Logger);
                return BuildResultCode.BuildError;
            }

            var buildProfile = simplePackage.Profiles.FirstOrDefault(pair => pair.Name == builderOptions.BuildProfile);
            if (buildProfile == null)
            {
                builderOptions.Logger.Error("Package {0} did not contain platform {1}", builderOptions.PackageFile, builderOptions.BuildProfile);
                return BuildResultCode.BuildError;
            }

            // For now, graphics platform is implicit.
            // It will need to be readded to GameSettingsAsset at some point.
            var graphicsPlatform = builderOptions.Platform.GetDefaultGraphicsPlatform();

            Console.WriteLine(graphicsPlatform);
            return BuildResultCode.Successful;
        }
Esempio n. 56
0
        /// <summary>
        /// Converts the specified hlsl source code to glsl.
        /// </summary>
        /// <param name="hlslEntryPoint">The HLSL entry point.</param>
        /// <param name="stage">The stage to convert.</param>
        /// <param name="shader">The shader.</param>
        /// <param name="inputHlslFilepath">The input HLSL filepath.</param>
        /// <returns>
        /// The resulting glsl AST tree.
        /// </returns>
        private global::SiliconStudio.Shaders.Ast.Shader Convert(ParsingResult result, string hlslEntryPoint, PipelineStage stage, string inputHlslFilepath, LoggerResult log)
        {
            try
            {
                var convertor = new HlslToGlslConvertor(hlslEntryPoint, stage, ShaderModel.Model40) // TODO HARDCODED VALUE to change
                {
                    KeepConstantBuffer = !isOpenGLES,
                    TextureFunctionsCompatibilityProfile = isOpenGLES,
                    NoSwapForBinaryMatrixOperation       = true,
                    UseBindingLayout                = false,
                    UseLocationLayout               = false,
                    UseSemanticForVariable          = true,
                    IsPointSpriteShader             = false,
                    ViewFrustumRemap                = true,
                    KeepNonUniformArrayInitializers = !isOpenGLES
                };
                convertor.Run(result);

                // After the converter we display the errors but we don't stop writing output glsl
                if (result.HasErrors)
                {
                    //DisplayError(log, result, "Error while converting file:");
                }


                return(result.Shader);
            }
            catch (Exception ex)
            {
                log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
                return(null);
            }
        }
 public GameDebuggerHost(LoggerResult logger)
 {
     Log = logger;
 }
Esempio n. 58
0
        private static void GenerateUnitTestProject(string outputDirectory, string templateFile, string name)
        {
            var projectTemplate = ProjectTemplate.Load(templateFile);

            // Force reference to Paradox.Assets (to have acess to SolutionPlatform)
            projectTemplate.Assemblies.Add(typeof(GraphicsProfile).Assembly.FullName);
            projectTemplate.Assemblies.Add(typeof(ParadoxConfig).Assembly.FullName);

            var options = new Dictionary <string, object>();

            var session = new PackageSession();
            var result  = new LoggerResult();

            var templateGeneratorParameters = new TemplateGeneratorParameters();

            templateGeneratorParameters.OutputDirectory = outputDirectory;
            templateGeneratorParameters.Session         = session;
            templateGeneratorParameters.Name            = name;
            templateGeneratorParameters.Logger          = result;
            templateGeneratorParameters.Description     = new TemplateDescription();

            PackageUnitTestGenerator.Default.Generate(templateGeneratorParameters);
            if (result.HasErrors)
            {
                Console.WriteLine("Error generating package: {0}", result.ToText());
                return;
            }

            var package = templateGeneratorParameters.Package;

            var previousCurrent = session.CurrentPackage;

            session.CurrentPackage = package;

            // Compute Paradox Sdk relative path
            // We are supposed to be in standard output binary folder, so Paradox root should be at ..\..
            var paradoxPath         = UDirectory.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), new UDirectory(@"..\.."));
            var paradoxRelativePath = new UDirectory(paradoxPath)
                                      .MakeRelative(outputDirectory)
                                      .ToString()
                                      .Replace('/', '\\');

            paradoxRelativePath = paradoxRelativePath.TrimEnd('\\');

            options["Namespace"]             = name;
            options["Package"]               = package;
            options["Platforms"]             = new List <SolutionPlatform>(AssetRegistry.SupportedPlatforms);
            options["ParadoxSdkRelativeDir"] = paradoxRelativePath;

            // Generate project template
            var projectGuid = Guid.NewGuid();

            result = projectTemplate.Generate(outputDirectory, name, projectGuid, options);
            if (result.HasErrors)
            {
                Console.WriteLine("Error generating solution: {0}", result.ToText());
                return;
            }

            var sharedProfile = package.Profiles.FindSharedProfile();

            // Setup the assets folder
            Directory.CreateDirectory(UPath.Combine(outputDirectory, (UDirectory)"Assets/Shared"));

            // Add Windows test as Shared library
            var projectWindowsRef = new ProjectReference();

            projectWindowsRef.Id       = projectGuid;
            projectWindowsRef.Location = UPath.Combine(outputDirectory, (UFile)(name + ".Windows.csproj"));
            projectWindowsRef.Type     = SiliconStudio.Assets.ProjectType.Library;
            sharedProfile.ProjectReferences.Add(projectWindowsRef);

            // Generate executable projects for each platform
            foreach (var platform in AssetRegistry.SupportedPlatforms)
            {
                var platformProfile = new PackageProfile(platform.Name)
                {
                    Platform = platform.Type
                };
                platformProfile.AssetFolders.Add(new AssetFolder("Assets/" + platform.Name));

                // Log progress
                var projectName = name + "." + platform.Type;

                // Create project reference
                var projectPlatformRef = new ProjectReference();
                projectPlatformRef.Id       = projectGuid;
                projectPlatformRef.Location = UPath.Combine(outputDirectory, (UFile)(projectName + ".csproj"));
                projectPlatformRef.Type     = SiliconStudio.Assets.ProjectType.Executable;

                platformProfile.ProjectReferences.Add(projectPlatformRef);

                // Add build configuration per platform
                platform.Properties.CopyTo(platformProfile.Properties, true);

                package.Profiles.Add(platformProfile);
            }

            session.CurrentPackage = previousCurrent;

            result = session.Save();
            if (result.HasErrors)
            {
                Console.WriteLine("Error saving package: {0}", result.ToText());
                return;
            }
        }
Esempio n. 59
0
        /// <summary>
        /// Adds the virtual table of the mixin
        /// </summary>
        /// <param name="shaderVirtualTable"></param>
        /// <param name="className"></param>
        /// <param name="errorLogger"></param>
        public void AddVirtualTable(ShaderVirtualTable shaderVirtualTable, string className, LoggerResult errorLogger)
        {
            var newVT = shaderVirtualTable.VirtualTableGroup[className].ToArray();

            VirtualTableGroup.Add(className, newVT);

            foreach (var methodDecl in newVT)
            {
                ReplaceVirtualMethod(methodDecl, errorLogger);
            }
        }
Esempio n. 60
0
        /// <summary>
        /// Get a compilation context based on the macros
        /// </summary>
        /// <param name="mixinToAnalyze">List of mixin to analyze</param>
        /// <param name="log">The log.</param>
        /// <returns>the correct compilation context</returns>
        private ShaderCompilationContext GetCompilationContext(IEnumerable <ModuleMixinInfo> mixinToAnalyze, LoggerResult log)
        {
            var mixinInfos = new HashSet <ModuleMixinInfo>();

            foreach (var mixin in mixinToAnalyze)
            {
                mixinInfos.UnionWith(mixin.MinimalContext);
            }

            var context = new ShaderCompilationContext(log);

            context.Preprocess(mixinInfos);
            return(context);
        }