예제 #1
0
        public EffectParameterUpdater(EffectParameterUpdaterLayout updaterLayout, ParameterCollection parameters) : this()
        {
            this.updaterLayout = updaterLayout;

            this.resourceGroups = new ResourceGroup[updaterLayout.Layouts.Length];
            for (int i = 0; i < resourceGroups.Length; ++i)
            {
                resourceGroups[i] = new ResourceGroup();
            }

            parameters.UpdateLayout(updaterLayout.ParameterCollectionLayout);
        }
예제 #2
0
        /// <summary>
        /// Compiles or recompiles the effect if necesssary.
        /// </summary>
        /// <param name="graphicsDevice"></param>
        /// <returns>True if the effect was recompiled, false otherwise.</returns>
        public bool UpdateEffect(GraphicsDevice graphicsDevice)
        {
            if (effect == null || permutationCounter != Parameters.PermutationCounter || (effect != null && effect.SourceChanged))
            {
                permutationCounter = Parameters.PermutationCounter;

                var oldEffect = effect;
                ChooseEffect(graphicsDevice);

                // Early exit: same effect, and already initialized
                if (oldEffect == effect && descriptorReflection != null)
                {
                    return(false);
                }

                // Update reflection and rearrange buffers/resources
                var layoutNames = effect.Bytecode.Reflection.ResourceBindings.Select(x => x.ResourceGroup ?? "Globals").Distinct().ToList();
                descriptorReflection = EffectDescriptorSetReflection.New(graphicsDevice, effect.Bytecode, layoutNames, "Globals");

                RootSignature?.Dispose();
                RootSignature = RootSignature.New(graphicsDevice, descriptorReflection);

                bufferUploader.Clear();
                bufferUploader.Compile(graphicsDevice, descriptorReflection, effect.Bytecode);

                // Create parameter updater
                var layouts = new DescriptorSetLayoutBuilder[descriptorReflection.Layouts.Count];
                for (int i = 0; i < descriptorReflection.Layouts.Count; ++i)
                {
                    layouts[i] = descriptorReflection.Layouts[i].Layout;
                }
                var parameterUpdaterLayout = new EffectParameterUpdaterLayout(graphicsDevice, effect, layouts);
                parameterUpdater = new EffectParameterUpdater(parameterUpdaterLayout, Parameters);

                descriptorSets = new DescriptorSet[parameterUpdater.ResourceGroups.Length];

                return(true);
            }

            return(false);
        }