Exemplo n.º 1
0
        private CompilerResults GetCompilerResults(string effectName, CompilerParameters compilerParameters)
        {
            compilerParameters.Profile = GraphicsDevice.ShaderProfile.HasValue ? GraphicsDevice.ShaderProfile.Value : GraphicsDevice.Features.Profile;
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLCORE
            compilerParameters.Platform = GraphicsPlatform.OpenGL;
#endif
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            compilerParameters.Platform = GraphicsPlatform.OpenGLES;
#endif

            // Compile shader
            var isPdxfx = ShaderMixinManager.Contains(effectName);

            // getting the effect from the used parameters only makes sense when the source files are the same
            // TODO: improve this by updating earlyCompilerCache - cache can still be relevant

            CompilerResults compilerResult = null;

            if (isPdxfx)
            {
                // perform an early test only based on the parameters
                compilerResult = GetShaderFromParameters(effectName, compilerParameters);
            }

            if (compilerResult == null)
            {
                var source = isPdxfx ? new ShaderMixinGeneratorSource(effectName) : (ShaderSource) new ShaderClassSource(effectName);
                compilerResult = compiler.Compile(source, compilerParameters);

#if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP
                // If enabled, request this effect compile
                // TODO: For now we save usedParameters, but ideally we probably want to have a list of everything that might be use by a given
                //       pdxfx and filter against this, so that branches not taken on a specific situation/platform can still be reproduced on another.
                // Alternatively, we could save full compilerParameters, but we would have to ignore certain things that are not serializable, such as Texture.
                lock (effectCompileRecordLock)
                {
                    if (recordedEffectCompile != null)
                    {
                        var effectCompileRequest = new EffectCompileRequest(effectName, compilerResult.UsedParameters);
                        if (!recordedEffectCompile.Contains(effectCompileRequest))
                        {
                            recordedEffectCompile[effectCompileRequest] = true;
                        }
                    }
                }
#endif

                if (!compilerResult.HasErrors && isPdxfx)
                {
                    lock (earlyCompilerCache)
                    {
                        List <CompilerResults> effectCompilerResults;
                        if (!earlyCompilerCache.TryGetValue(effectName, out effectCompilerResults))
                        {
                            effectCompilerResults = new List <CompilerResults>();
                            earlyCompilerCache.Add(effectName, effectCompilerResults);
                        }

                        // Register bytecode used parameters so that they are checked when another effect is instanced
                        effectCompilerResults.Add(compilerResult);
                    }
                }
            }

            foreach (var message in compilerResult.Messages)
            {
                Log.Log(message);
            }

            return(compilerResult);
        }