Exemplo n.º 1
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 || isOpenGLES3,
                    TextureFunctionsCompatibilityProfile = isOpenGLES && !isOpenGLES3,
                    NoSwapForBinaryMatrixOperation       = true,
                    UseBindingLayout                = false,
                    UseLocationLayout               = false,
                    UseSemanticForVariable          = true,
                    IsPointSpriteShader             = false,
                    ViewFrustumRemap                = true,
                    KeepNonUniformArrayInitializers = !isOpenGLES,
                    IsOpenGLES2 = isOpenGLES && !isOpenGLES3
                };
                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);
            }
        }
Exemplo n.º 2
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 = null)
        {
            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)
                {
                    throw new NotImplementedException("Logging");
                    //DisplayError(log, result, "Error while parsing file:");
                    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)
                {
                    throw new NotImplementedException("Logging");
                    //DisplayError(log, result, "Error with type inferencing:");
                }

                return(Convert(result, hlslEntryPoint, stage, inputHlslFilepath));
            }
            catch (Exception ex)
            {
                throw new NotImplementedException("Logging");
                //log.WriteLine("Unexpected error while converting file [{0}] with entry point [{1}] : {2}", inputHlslFilepath, hlslEntryPoint, ex.Message);
                return(null);
            }
        }
Exemplo n.º 3
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, IDictionary <int, string> inputAttributeNames, 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, inputAttributeNames, log));
            }
            catch (Exception ex)
            {
                log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
            }
            return(null);
        }
Exemplo n.º 4
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, IDictionary <int, string> inputAttributeNames, LoggerResult log)
        {
            try
            {
                var convertor = new HlslToGlslConvertor(shaderPlatform, shaderVersion, hlslEntryPoint, stage, ShaderModel.Model40) // TODO HARDCODED VALUE to change
                {
                    // Those settings are now default values
                    //NoSwapForBinaryMatrixOperation = true,
                    //UnrollForLoops = true,
                    //ViewFrustumRemap = true,
                    //FlipRenderTarget = true,
                    //KeepConstantBuffer = !isOpenGLES || isOpenGLES3,
                    //TextureFunctionsCompatibilityProfile = isOpenGLES && !isOpenGLES3,
                    //KeepNonUniformArrayInitializers = !isOpenGLES,

                    UseBindingLayout       = false,
                    UseSemanticForVariable = true,
                    IsPointSpriteShader    = false,
                    InputAttributeNames    = inputAttributeNames
                };
                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);
            }
        }
Exemplo n.º 5
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 || isOpenGLES3,
                    TextureFunctionsCompatibilityProfile = isOpenGLES && !isOpenGLES3,
                    NoSwapForBinaryMatrixOperation = true,
                    UseBindingLayout = false,
                    UseLocationLayout = false,
                    UseSemanticForVariable = true,
                    IsPointSpriteShader = false,
                    ViewFrustumRemap = true,
                    FlipRenderTargetFlag = "ParadoxFlipRendertarget",
                    KeepNonUniformArrayInitializers = !isOpenGLES,
                    IsOpenGLES2 = isOpenGLES && !isOpenGLES3
                };
                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;
            }
        }
Exemplo n.º 6
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, IDictionary<int, string> inputAttributeNames, LoggerResult log)
        {
            try
            {
                var convertor = new HlslToGlslConvertor(shaderPlatform, shaderVersion, hlslEntryPoint, stage, ShaderModel.Model40) // TODO HARDCODED VALUE to change
                {
                    // Those settings are now default values
                    //NoSwapForBinaryMatrixOperation = true,
                    //UnrollForLoops = true,
                    //ViewFrustumRemap = true,
                    //FlipRenderTarget = true,
                    //KeepConstantBuffer = !isOpenGLES || isOpenGLES3,
                    //TextureFunctionsCompatibilityProfile = isOpenGLES && !isOpenGLES3,
                    //KeepNonUniformArrayInitializers = !isOpenGLES,

                    UseBindingLayout = false,
                    UseSemanticForVariable = true,
                    IsPointSpriteShader = false,
                    InputAttributeNames = inputAttributeNames
                };
                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;
            }
        }