コード例 #1
0
        private void OutputDisassemblyItem(ITaskItem item)
        {
            string asmFileName = Path.ChangeExtension(ObjectFileOutput, ".h");

            Log.LogMessage(MessageImportance.Normal, $"{item.ItemSpec} -> {asmFileName}");

            byte[] code = File.ReadAllBytes(ObjectFileOutput);
            string asm  = D3DCompile.Disassemble(code);

            File.WriteAllText(asmFileName, asm);
        }
コード例 #2
0
        private void OutputDisassemblyHtmlItem(ITaskItem item)
        {
            string htmlFileName = Path.ChangeExtension(ObjectFileOutput, ".html");

            Log.LogMessage(MessageImportance.Normal, $"{item.ItemSpec} -> {htmlFileName}");

            byte[] code = File.ReadAllBytes(ObjectFileOutput);
            string html = D3DCompile.Disassemble(code, D3DDisassembleOptions.EnableColorCode);

            File.WriteAllText(htmlFileName, html);
        }
コード例 #3
0
        private bool CompileItem(ITaskItem item)
        {
            string fullPath = item.GetMetadata("FullPath");

            D3DShaderMacro[] defines = null;

            if (PreprocessorDefinitions != null)
            {
                defines = new D3DShaderMacro[PreprocessorDefinitions.Length];

                for (int i = 0; i < PreprocessorDefinitions.Length; i++)
                {
                    string   definition = PreprocessorDefinitions[i];
                    string[] parts      = definition.Split('=');

                    string key = parts[0];

                    if (parts.Length > 1)
                    {
                        defines[i] = new D3DShaderMacro(key, parts[1]);
                    }
                    else
                    {
                        defines[i] = new D3DShaderMacro(key, string.Empty);
                    }
                }
            }

            byte[] code;
            string errorMessages = null;

            try
            {
                D3DCompileOptions options = D3DCompileOptions.OptimizationLevel3;

                if (TreatWarningAsError)
                {
                    options |= D3DCompileOptions.WarningsAreErrors;
                }

                D3DCompile.CompileFromFile(
                    fullPath,
                    defines,
                    EntryPointName,
                    ShaderProfile,
                    options,
                    out code,
                    out errorMessages);
            }
            catch (Exception ex)
            {
                if (errorMessages == null)
                {
                    Log.LogError($"{item.ItemSpec}: {ex.Message}");
                }
                else
                {
                    Log.LogError($"{item.ItemSpec}: {errorMessages}");
                }

                return(false);
            }

            if (errorMessages != null)
            {
                if (TreatWarningAsError)
                {
                    Log.LogError($"{item.ItemSpec}: {errorMessages}");
                    return(false);
                }
                else
                {
                    Log.LogWarning($"{item.ItemSpec}: {errorMessages}");
                }
            }

            if (code != null)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(ObjectFileOutput));
                File.WriteAllBytes(ObjectFileOutput, code);
            }

            return(true);
        }