Esempio n. 1
0
 /// <summary>
 /// Computes a hash <see cref="ObjectId"/> for the specified effect and compiler parameters.
 /// </summary>
 /// <param name="effectName">Name of the effect.</param>
 /// <param name="compilerParameters">The compiler parameters.</param>
 /// <returns>
 /// EffectObjectIds.
 /// </returns>
 public static ObjectId Compute(string effectName, ShaderMixinParameters compilerParameters)
 {
     lock (generatorLock)
     {
         if (generator == null)
         {
             generator = new ShaderMixinObjectId();
         }
         return generator.ComputeInternal(effectName, compilerParameters);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Computes a hash <see cref="ObjectId"/> for the specified mixin.
 /// </summary>
 /// <param name="mixin">The mixin.</param>
 /// <param name="mixinParameters">The mixin parameters.</param>
 /// <returns>EffectObjectIds.</returns>
 public static ObjectId Compute(ShaderMixinSource mixin, ShaderMixinParameters mixinParameters)
 {
     lock (generatorLock)
     {
         if (generator == null)
         {
             generator = new ShaderMixinObjectId();
         }
         return generator.ComputeInternal(mixin, mixinParameters);
     }
 }
Esempio n. 3
0
        private unsafe ObjectId ComputeInternal(ShaderMixinSource mixin, ShaderMixinParameters mixinParameters)
        {
            // Write to memory stream
            memStream.Position = 0;
            writer.Write(EffectBytecode.MagicHeader); // Write the effect bytecode magic header
            writer.Write(mixin);

            parameters.Clear();
            parameters.Set(CompilerParameters.GraphicsPlatformKey, mixinParameters.Get(CompilerParameters.GraphicsPlatformKey));
            parameters.Set(CompilerParameters.GraphicsProfileKey, mixinParameters.Get(CompilerParameters.GraphicsProfileKey));
            parameters.Set(CompilerParameters.DebugKey, mixinParameters.Get(CompilerParameters.DebugKey));
            writer.Write(parameters);

            // Compute hash
            objectIdBuilder.Reset();
            objectIdBuilder.Write((byte*)buffer, (int)memStream.Position);

            return objectIdBuilder.ComputeHash();
        }
Esempio n. 4
0
        private unsafe ObjectId ComputeInternal(ShaderMixinSource mixin, ShaderMixinParameters mixinParameters)
        {
            // Write to memory stream
            memStream.Position = 0;
            writer.Write(EffectBytecode.MagicHeader); // Write the effect bytecode magic header
            writer.Write(mixin);

            parameters.Clear();
            parameters.Set(CompilerParameters.GraphicsPlatformKey, mixinParameters.Get(CompilerParameters.GraphicsPlatformKey));
            parameters.Set(CompilerParameters.GraphicsProfileKey, mixinParameters.Get(CompilerParameters.GraphicsProfileKey));
            parameters.Set(CompilerParameters.DebugKey, mixinParameters.Get(CompilerParameters.DebugKey));
            writer.Write(parameters);

            // Compute hash
            objectIdBuilder.Reset();
            objectIdBuilder.Write((byte *)buffer, (int)memStream.Position);

            return(objectIdBuilder.ComputeHash());
        }
Esempio n. 5
0
        /// <summary>
        /// Generates a <see cref="ShaderMixinSourceTree"/> for the specified names and parameters.
        /// </summary>
        /// <param name="pdxfxEffectName">The name.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="mainUsedParameters">The parameters when prcessing the mixin.</param>
        /// <returns>The result of the mixin.</returns>
        public static ShaderMixinSourceTree Generate(string pdxfxEffectName, ParameterCollection properties, out ShaderMixinParameters mainUsedParameters, out List <ShaderMixinParameters> usedParameters)
        {
            if (pdxfxEffectName == null)
            {
                throw new ArgumentNullException("pdxfxEffectName");
            }

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            IShaderMixinBuilder builder;
            Dictionary <string, IShaderMixinBuilder> builders;

            lock (RegisteredBuilders)
            {
                if (!TryGet(pdxfxEffectName, out builder))
                {
                    throw new ArgumentException(string.Format("Pdxfx effect [{0}] not found", pdxfxEffectName), "pdxfxEffectName");
                }

                builders = new Dictionary <string, IShaderMixinBuilder>(RegisteredBuilders);
            }

            var context   = new ShaderMixinContext(properties, builders, pdxfxEffectName);
            var mixinTree = new ShaderMixinSourceTree()
            {
                Name = pdxfxEffectName
            };

            builder.Generate(mixinTree, context);

            mainUsedParameters = context.GetMainUsedParameters();
            usedParameters     = context.GetUsedParameters();
            return(mixinTree);
        }
Esempio n. 6
0
        private unsafe ObjectId ComputeInternal(string effectName, ShaderMixinParameters compilerParameters)
        {
            // Write to memory stream
            memStream.Position = 0;
            writer.Write(EffectBytecode.MagicHeader); // Write the effect bytecode magic header
            writer.Write(effectName);

            writer.Write(compilerParameters);

            // Compute hash
            objectIdBuilder.Reset();
            objectIdBuilder.Write((byte*)buffer, (int)memStream.Position);

            return objectIdBuilder.ComputeHash();
        }