Esempio n. 1
0
        public void EndApplyBlend()
        {
            StateHash hash = GetBlendHash(
                AlphaBlendFunction,
                AlphaDestinationBlend,
                AlphaSourceBlend,
                ColorBlendFunction,
                ColorDestinationBlend,
                ColorSourceBlend,
                ColorWriteChannels,
                ColorWriteChannels1,
                ColorWriteChannels2,
                ColorWriteChannels3,
                BlendFactor,
                MultiSampleMask
                );
            BlendState newBlend;

            if (!blendCache.TryGetValue(hash, out newBlend))
            {
                newBlend = new BlendState();

                newBlend.AlphaBlendFunction    = AlphaBlendFunction;
                newBlend.AlphaDestinationBlend = AlphaDestinationBlend;
                newBlend.AlphaSourceBlend      = AlphaSourceBlend;
                newBlend.ColorBlendFunction    = ColorBlendFunction;
                newBlend.ColorDestinationBlend = ColorDestinationBlend;
                newBlend.ColorSourceBlend      = ColorSourceBlend;
                newBlend.ColorWriteChannels    = ColorWriteChannels;
                newBlend.ColorWriteChannels1   = ColorWriteChannels1;
                newBlend.ColorWriteChannels2   = ColorWriteChannels2;
                newBlend.ColorWriteChannels3   = ColorWriteChannels3;
                newBlend.BlendFactor           = BlendFactor;
                newBlend.MultiSampleMask       = MultiSampleMask;

                blendCache.Add(hash, newBlend);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo(
                    "New BlendState added to pipeline cache with hash:\n" +
                    hash.ToString()
                    );
                FNALoggerEXT.LogInfo(
                    "Updated size of BlendState cache: " +
                    blendCache.Count
                    );
            }
            else
            {
                FNALoggerEXT.LogInfo(
                    "Retrieved BlendState from pipeline cache with hash:\n" +
                    hash.ToString()
                    );
#endif
            }

            device.BlendState = newBlend;
        }
Esempio n. 2
0
        public void EndApplyBlend()
        {
            int funcs = ((int)AlphaBlendFunction << 4) | ((int)ColorBlendFunction);
            int blendsAndColorWriteChannels =
                ((int)AlphaDestinationBlend << (32 - 4))
                | ((int)AlphaSourceBlend << (32 - 8))
                | ((int)ColorDestinationBlend << (32 - 12))
                | ((int)ColorSourceBlend << (32 - 16))
                | ((int)ColorWriteChannels << (32 - 20))
                | ((int)ColorWriteChannels1 << (32 - 24))
                | ((int)ColorWriteChannels2 << (32 - 28))
                | ((int)ColorWriteChannels3);

            StateHash hash = new StateHash(
                funcs,
                blendsAndColorWriteChannels,
                (int)BlendFactor.PackedValue,
                MultiSampleMask
                );

            BlendState newBlend;

            if (!blendCache.TryGetValue(hash, out newBlend))
            {
                newBlend = new BlendState();

                newBlend.AlphaBlendFunction    = AlphaBlendFunction;
                newBlend.AlphaDestinationBlend = AlphaDestinationBlend;
                newBlend.AlphaSourceBlend      = AlphaSourceBlend;
                newBlend.ColorBlendFunction    = ColorBlendFunction;
                newBlend.ColorDestinationBlend = ColorDestinationBlend;
                newBlend.ColorSourceBlend      = ColorSourceBlend;
                newBlend.ColorWriteChannels    = ColorWriteChannels;
                newBlend.ColorWriteChannels1   = ColorWriteChannels1;
                newBlend.ColorWriteChannels2   = ColorWriteChannels2;
                newBlend.ColorWriteChannels3   = ColorWriteChannels3;
                newBlend.BlendFactor           = BlendFactor;
                newBlend.MultiSampleMask       = MultiSampleMask;

                blendCache.Add(hash, newBlend);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo("New BlendState added to pipeline cache with hash:\n"
                                     + hash.ToString());
                FNALoggerEXT.LogInfo("Updated size of BlendState cache: "
                                     + blendCache.Count);
            }
            else
            {
                FNALoggerEXT.LogInfo("Retrieved BlendState from pipeline cache with hash:\n"
                                     + hash.ToString());
#endif
            }

            device.BlendState = newBlend;
        }
Esempio n. 3
0
        public void EndApplyRasterizer()
        {
            // Bool -> Int32 conversion
            int multiSampleAntiAlias = (MultiSampleAntiAlias ? 1 : 0);
            int scissorTestEnable    = (ScissorTestEnable ? 1 : 0);

            int packedProperties =
                ((int)multiSampleAntiAlias << 4)
                | ((int)scissorTestEnable << 3)
                | ((int)CullMode << 1)
                | ((int)FillMode);

            StateHash hash = new StateHash(
                0,
                packedProperties,
                FloatToInt32(DepthBias),
                FloatToInt32(SlopeScaleDepthBias)
                );

            RasterizerState newRasterizer;

            if (!rasterizerCache.TryGetValue(hash, out newRasterizer))
            {
                newRasterizer = new RasterizerState();

                newRasterizer.CullMode             = CullMode;
                newRasterizer.FillMode             = FillMode;
                newRasterizer.DepthBias            = DepthBias;
                newRasterizer.MultiSampleAntiAlias = MultiSampleAntiAlias;
                newRasterizer.ScissorTestEnable    = ScissorTestEnable;
                newRasterizer.SlopeScaleDepthBias  = SlopeScaleDepthBias;

                rasterizerCache.Add(hash, newRasterizer);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo("New RasterizerState added to pipeline cache with hash:\n"
                                     + hash.ToString());
                FNALoggerEXT.LogInfo("Updated size of RasterizerState cache: "
                                     + rasterizerCache.Count);
            }
            else
            {
                FNALoggerEXT.LogInfo("Retrieved RasterizerState from pipeline cache with hash:\n"
                                     + hash.ToString());
#endif
            }

            device.RasterizerState = newRasterizer;
        }
Esempio n. 4
0
        public void EndApplySampler(SamplerStateCollection samplers, int register)
        {
            StateHash hash = GetSamplerHash(
                AddressU,
                AddressV,
                AddressW,
                MaxAnisotropy,
                MaxMipLevel,
                MipMapLODBias,
                Filter
                );
            SamplerState newSampler;

            if (!samplerCache.TryGetValue(hash, out newSampler))
            {
                newSampler = new SamplerState();

                newSampler.Filter                  = Filter;
                newSampler.AddressU                = AddressU;
                newSampler.AddressV                = AddressV;
                newSampler.AddressW                = AddressW;
                newSampler.MaxAnisotropy           = MaxAnisotropy;
                newSampler.MaxMipLevel             = MaxMipLevel;
                newSampler.MipMapLevelOfDetailBias = MipMapLODBias;

                samplerCache.Add(hash, newSampler);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo(
                    "New SamplerState added to pipeline cache with hash:\n" +
                    hash.ToString()
                    );
                FNALoggerEXT.LogInfo(
                    "Updated size of SamplerState cache: " +
                    samplerCache.Count
                    );
            }
            else
            {
                FNALoggerEXT.LogInfo(
                    "Retrieved SamplerState from pipeline cache with hash:\n" +
                    hash.ToString()
                    );
#endif
            }

            samplers[register] = newSampler;
        }
Esempio n. 5
0
        public void EndApplyRasterizer()
        {
            StateHash hash = GetRasterizerHash(
                CullMode,
                FillMode,
                DepthBias,
                MultiSampleAntiAlias,
                ScissorTestEnable,
                SlopeScaleDepthBias
                );
            RasterizerState newRasterizer;

            if (!rasterizerCache.TryGetValue(hash, out newRasterizer))
            {
                newRasterizer = new RasterizerState();

                newRasterizer.CullMode             = CullMode;
                newRasterizer.FillMode             = FillMode;
                newRasterizer.DepthBias            = DepthBias;
                newRasterizer.MultiSampleAntiAlias = MultiSampleAntiAlias;
                newRasterizer.ScissorTestEnable    = ScissorTestEnable;
                newRasterizer.SlopeScaleDepthBias  = SlopeScaleDepthBias;

                rasterizerCache.Add(hash, newRasterizer);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo(
                    "New RasterizerState added to pipeline cache with hash:\n" +
                    hash.ToString()
                    );
                FNALoggerEXT.LogInfo(
                    "Updated size of RasterizerState cache: " +
                    rasterizerCache.Count
                    );
            }
            else
            {
                FNALoggerEXT.LogInfo(
                    "Retrieved RasterizerState from pipeline cache with hash:\n" +
                    hash.ToString()
                    );
#endif
            }

            device.RasterizerState = newRasterizer;
        }
Esempio n. 6
0
        public void EndApplyDepthStencil()
        {
            // Bool -> Int32 conversion
            int depthBufferEnable      = DepthBufferEnable ? 1 : 0;
            int depthBufferWriteEnable = DepthBufferWriteEnable ? 1 : 0;
            int stencilEnable          = StencilEnable ? 1 : 0;
            int twoSidedStencilMode    = TwoSidedStencilMode ? 1 : 0;

            int packedProperties =
                ((int)depthBufferEnable << 32 - 2)
                | ((int)depthBufferWriteEnable << 32 - 3)
                | ((int)stencilEnable << 32 - 4)
                | ((int)twoSidedStencilMode << 32 - 5)
                | ((int)DepthBufferFunction << 32 - 8)
                | ((int)StencilFunction << 32 - 11)
                | ((int)CCWStencilFunction << 32 - 14)
                | ((int)StencilPass << 32 - 17)
                | ((int)StencilFail << 32 - 20)
                | ((int)StencilDepthBufferFail << 32 - 23)
                | ((int)CCWStencilFail << 32 - 26)
                | ((int)CCWStencilPass << 32 - 29)
                | ((int)CCWStencilDepthBufferFail);

            StateHash hash = new StateHash(
                packedProperties,
                StencilMask,
                StencilWriteMask,
                ReferenceStencil
                );

            DepthStencilState newDepthStencil;

            if (!depthStencilCache.TryGetValue(hash, out newDepthStencil))
            {
                newDepthStencil = new DepthStencilState();

                newDepthStencil.DepthBufferEnable                      = DepthBufferEnable;
                newDepthStencil.DepthBufferWriteEnable                 = DepthBufferWriteEnable;
                newDepthStencil.DepthBufferFunction                    = DepthBufferFunction;
                newDepthStencil.StencilEnable                          = StencilEnable;
                newDepthStencil.StencilFunction                        = StencilFunction;
                newDepthStencil.StencilPass                            = StencilPass;
                newDepthStencil.StencilFail                            = StencilFail;
                newDepthStencil.StencilDepthBufferFail                 = StencilDepthBufferFail;
                newDepthStencil.TwoSidedStencilMode                    = TwoSidedStencilMode;
                newDepthStencil.CounterClockwiseStencilFunction        = CCWStencilFunction;
                newDepthStencil.CounterClockwiseStencilFail            = CCWStencilFail;
                newDepthStencil.CounterClockwiseStencilPass            = CCWStencilPass;
                newDepthStencil.CounterClockwiseStencilDepthBufferFail = CCWStencilDepthBufferFail;
                newDepthStencil.StencilMask                            = StencilMask;
                newDepthStencil.StencilWriteMask                       = StencilWriteMask;
                newDepthStencil.ReferenceStencil                       = ReferenceStencil;

                depthStencilCache.Add(hash, newDepthStencil);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo("New DepthStencilState added to pipeline cache with hash:\n"
                                     + hash.ToString());
                FNALoggerEXT.LogInfo("Updated size of DepthStencilState cache: "
                                     + depthStencilCache.Count);
            }
            else
            {
                FNALoggerEXT.LogInfo("Retrieved DepthStencilState from pipeline cache with hash:\n"
                                     + hash.ToString());
#endif
            }

            device.DepthStencilState = newDepthStencil;
        }
Esempio n. 7
0
        public void EndApplyDepthStencil()
        {
            StateHash hash = GetDepthStencilHash(
                DepthBufferEnable,
                DepthBufferWriteEnable,
                DepthBufferFunction,
                StencilEnable,
                StencilFunction,
                StencilPass,
                StencilFail,
                StencilDepthBufferFail,
                TwoSidedStencilMode,
                CCWStencilFunction,
                CCWStencilPass,
                CCWStencilFail,
                CCWStencilDepthBufferFail,
                StencilMask,
                StencilWriteMask,
                ReferenceStencil
                );
            DepthStencilState newDepthStencil;

            if (!depthStencilCache.TryGetValue(hash, out newDepthStencil))
            {
                newDepthStencil = new DepthStencilState();

                newDepthStencil.DepthBufferEnable                      = DepthBufferEnable;
                newDepthStencil.DepthBufferWriteEnable                 = DepthBufferWriteEnable;
                newDepthStencil.DepthBufferFunction                    = DepthBufferFunction;
                newDepthStencil.StencilEnable                          = StencilEnable;
                newDepthStencil.StencilFunction                        = StencilFunction;
                newDepthStencil.StencilPass                            = StencilPass;
                newDepthStencil.StencilFail                            = StencilFail;
                newDepthStencil.StencilDepthBufferFail                 = StencilDepthBufferFail;
                newDepthStencil.TwoSidedStencilMode                    = TwoSidedStencilMode;
                newDepthStencil.CounterClockwiseStencilFunction        = CCWStencilFunction;
                newDepthStencil.CounterClockwiseStencilFail            = CCWStencilFail;
                newDepthStencil.CounterClockwiseStencilPass            = CCWStencilPass;
                newDepthStencil.CounterClockwiseStencilDepthBufferFail = CCWStencilDepthBufferFail;
                newDepthStencil.StencilMask                            = StencilMask;
                newDepthStencil.StencilWriteMask                       = StencilWriteMask;
                newDepthStencil.ReferenceStencil                       = ReferenceStencil;

                depthStencilCache.Add(hash, newDepthStencil);
#if VERBOSE_PIPELINECACHE
                FNALoggerEXT.LogInfo(
                    "New DepthStencilState added to pipeline cache with hash:\n" +
                    hash.ToString()
                    );
                FNALoggerEXT.LogInfo(
                    "Updated size of DepthStencilState cache: " +
                    depthStencilCache.Count
                    );
            }
            else
            {
                FNALoggerEXT.LogInfo(
                    "Retrieved DepthStencilState from pipeline cache with hash:\n" +
                    hash.ToString()
                    );
#endif
            }

            device.DepthStencilState = newDepthStencil;
        }