/// <summary>
        /// Compile the shader file using the given compilation function
        /// </summary>
        public void CompileShaders(List <ShaderFile> shaderFiles, CompileFunc compileFunc)
        {
            string title = name;
            string msg;

            if (ReferenceCompiler.Locate() == null)
            {
                msg = "Could not locate the glslang reference compiler (glslangvalidator.exe) in system path!";
                VsShellUtilities.ShowMessageBox(ServiceProvider, msg, title, OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                OutputWindow.Add(msg);
                return;
            }

            ErrorList.Clear();

            bool success = true;

            msg = "";
            foreach (var shaderFile in shaderFiles)
            {
                List <string> validatorOutput;
                bool          compiled = compileFunc(shaderFile.fileName, out validatorOutput);
                if (compiled)
                {
                    OutputWindow.Add(string.Join("\n", validatorOutput));
                }
                else
                {
                    msg += string.Format(CultureInfo.CurrentCulture, "Shader \"{0}\" could not be compiled to SPIR-V!", shaderFile.fileName) + "\n";
                    Debug.Write(msg);
                    ParseErrors(validatorOutput, shaderFile);
                    OutputWindow.Add(shaderFile.fileName + "\n" + string.Join("\n", validatorOutput));
                    success = false;
                }
            }

            if (success)
            {
                if (shaderFiles.Count == 1)
                {
                    msg = string.Format(CultureInfo.CurrentCulture, "Shader successfully compiled to \"{0}\"", shaderFiles[0].fileName + ".spv");
                }
                else
                {
                    msg = "All shaders successfully compiled to SPIR-V";
                }
                VsShellUtilities.ShowMessageBox(ServiceProvider, msg, title, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }
            else
            {
                VsShellUtilities.ShowMessageBox(ServiceProvider, msg, title, OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
            }

            if (ErrorList.ErrorCount() > 0)
            {
                ErrorList.Show();
            }
        }
예제 #2
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            List <ShaderFile> selectedShaderFiles = new List <ShaderFile>();

            if (GetSelectedShaderFiles(selectedShaderFiles))
            {
                ErrorList.Clear();
                foreach (var shaderFile in selectedShaderFiles)
                {
                    List <string> spirvOutput = new List <string>();
                    if (GetReadableSPIRV(shaderFile, out spirvOutput))
                    {
                        string fileName = Path.GetTempPath() + Path.GetFileName(shaderFile.fileName) + ".spirv.readable";
                        File.WriteAllLines(fileName, spirvOutput);
                        VsShellUtilities.OpenDocument(ServiceProvider, fileName);
                    }
                }
                if (ErrorList.ErrorCount() > 0)
                {
                    ErrorList.Show();
                }
            }
        }