Beispiel #1
0
 public override void Dispose()
 {
     DisposeHelper.Dispose(ref _material);
     DisposeHelper.Dispose(ref _mirrorMaterial);
     DisposeHelper.Dispose(ref _debugMaterial);
     base.Dispose();
 }
Beispiel #2
0
        public void UpdateFilter()
        {
            var oldFilter = m_Filter;

            DisposeHelper.Dispose(ref m_SourceFilter);

            try
            {
                var input = MakeInitialFilter()
                            .MakeTagged();

                m_Filter = m_Chain
                           .Process(input)
                           .Apply(FinalizeOutput)
                           .Compile()
                           .InitializeFilter();
            }
            catch (Exception ex)
            {
                m_Filter = HandleError(ex).Compile().InitializeFilter();
                m_Filter.AddLabel(ErrorMessage(ex));
            }
            finally
            {
                DisposeHelper.Dispose(ref oldFilter);
            }
        }
Beispiel #3
0
        public void SetDebugMode(IDeviceContextHolder holder, bool enabled)
        {
            if (enabled == (_debugMaterial != null))
            {
                return;
            }

            if (enabled)
            {
                _debugMaterial = holder.Get <SharedMaterials>().GetMaterial(new Tuple <object, uint>(BasicMaterials.DebugKey, OriginalNode.MaterialId));
                if (_debugMaterial == null)
                {
                    return;
                }

                if (IsInitialized)
                {
                    _debugMaterial.Initialize(holder);
                    _debugMaterialInitialized = true;
                }
            }
            else
            {
                _debugMaterialInitialized = false;
                DisposeHelper.Dispose(ref _debugMaterial);
            }
        }
Beispiel #4
0
        protected override void ResizeBuffers(DeviceContextHolder holder, int size)
        {
            DisposeHelper.Dispose(ref _view);
            DisposeHelper.Dispose(ref _targetView);

            using (var cubeTex = new Texture2D(holder.Device, new Texture2DDescription {
                Width = size,
                Height = size,
                MipLevels = 1,
                ArraySize = 6,
                SampleDescription = new SampleDescription(1, 0),
                Format = Format.R24G8_Typeless,
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.ShaderResource | BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.TextureCube
            })) {
                _targetView = Enumerable.Range(0, 6).Select(x => new DepthStencilView(holder.Device, cubeTex,
                                                                                      new DepthStencilViewDescription {
                    Format          = Format.D24_UNorm_S8_UInt,
                    Dimension       = DepthStencilViewDimension.Texture2DArray,
                    ArraySize       = 1,
                    FirstArraySlice = x,
                    MipSlice        = 0
                })).ToArray();
                _view = new ShaderResourceView(holder.Device, cubeTex, new ShaderResourceViewDescription {
                    Format          = Format.R24_UNorm_X8_Typeless,
                    Dimension       = ShaderResourceViewDimension.TextureCube,
                    MostDetailedMip = 0,
                    MipLevels       = -1
                });
            }
        }
Beispiel #5
0
 public void Dispose()
 {
     try {
         DisposeHelper.Dispose(ref _normalDepthState);
         DisposeHelper.Dispose(ref _shadowsDepthState);
         DisposeHelper.Dispose(ref _readOnlyDepthState);
         DisposeHelper.Dispose(ref _greaterReadOnlyDepthState);
         DisposeHelper.Dispose(ref _lessEqualDepthState);
         DisposeHelper.Dispose(ref _lessEqualReadOnlyDepthState);
         DisposeHelper.Dispose(ref _transparentBlendState);
         DisposeHelper.Dispose(ref _addBlendState);
         DisposeHelper.Dispose(ref _addState);
         DisposeHelper.Dispose(ref _maxState);
         DisposeHelper.Dispose(ref _minState);
         DisposeHelper.Dispose(ref _multiplyState);
         DisposeHelper.Dispose(ref _doubleSidedState);
         DisposeHelper.Dispose(ref _doubleSidedSmoothLinesState);
         DisposeHelper.Dispose(ref _invertedState);
         DisposeHelper.Dispose(ref _wireframeState);
         DisposeHelper.Dispose(ref _wireframeInvertedState);
         DisposeHelper.Dispose(ref _ambientShadowState);
         DisposeHelper.Dispose(ref _shadowsState);
         DisposeHelper.Dispose(ref _shadowsPointState);
     } catch (Exception e) {
         AcToolsLogging.Write(e);
     }
 }
        private void UpdateGBuffers()
        {
            var value = UseSslr || UseAo;

            if (_gBufferNormals != null == value)
            {
                return;
            }

            if (value)
            {
                _gBufferNormals = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
                _gBufferDepth   = TargetResourceTexture.Create(Format.R32_Float);
            }
            else
            {
                DisposeHelper.Dispose(ref _gBufferNormals);
                DisposeHelper.Dispose(ref _gBufferDepth);
            }

            if (InitiallyResized)
            {
                ResizeGBuffers();
            }
        }
Beispiel #7
0
            public void SetMode(IDeviceContextHolder contextHolder, FlatMirrorMode mode)
            {
                if (_material != null && _mode == mode)
                {
                    return;
                }

                _mode = mode;
                DisposeHelper.Dispose(ref _material);

                switch (mode)
                {
                case FlatMirrorMode.TransparentMirror:
                    _material = new TransparentMirrorMaterial();
                    break;

                case FlatMirrorMode.SolidGround:
                    _material = new SolidGroundMaterial();
                    break;

                case FlatMirrorMode.TextureMirror:
                    _material = new TextureMirrorMaterial();
                    break;

                case FlatMirrorMode.BackgroundGround:
                    _material = new SemiTransparentGroundMaterial();
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
                }

                _material.Initialize(contextHolder);
            }
        private void UpdateBlurredFlatMirror()
        {
            var use = FlatMirror && FlatMirrorBlurred;

            if (use == (_mirrorBuffer != null))
            {
                return;
            }

            if (use)
            {
                _mirrorBuffer      = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
                _mirrorBlurBuffer  = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
                _temporaryBuffer   = TargetResourceTexture.Create(Format.R16G16B16A16_Float);
                _mirrorDepthBuffer = TargetResourceDepthTexture.Create();

                if (!InitiallyResized)
                {
                    return;
                }
                ResizeMirrorBuffers();
            }
            else
            {
                DisposeHelper.Dispose(ref _mirrorBuffer);
                DisposeHelper.Dispose(ref _mirrorBlurBuffer);
                DisposeHelper.Dispose(ref _temporaryBuffer);
                DisposeHelper.Dispose(ref _mirrorDepthBuffer);
            }
        }
        private void RecreateAoBuffer()
        {
            if (!UseAo)
            {
                DisposeHelper.Dispose(ref _aoBuffer);
                return;
            }

            Format format;

            switch (AoType)
            {
            case AoType.Ssao:
            case AoType.SsaoAlt:
                format = Format.R8_UNorm;
                break;

            default:
                format = Format.R8G8B8A8_UNorm;
                break;
            }

            _aoHelper = null;
            if (_aoBuffer == null || _aoBuffer.Format != format)
            {
                DisposeHelper.Dispose(ref _aoBuffer);
                _aoBuffer = TargetResourceTexture.Create(format);
            }

            if (InitiallyResized)
            {
                ResizeSsaoBuffers();
            }
        }
            public void Dispose()
            {
                // do not dispose _sharedCancellationTokenSource cause it’s shared

                DisposeHelper.Dispose(ref _keyboard);
                AcSharedMemory.Instance.Start -= OnStart;
            }
 public override void Dispose()
 {
     DisposeHelper.Dispose(ref _outlineBuffer);
     DisposeHelper.Dispose(ref _outlineDepthBuffer);
     DisposeHelper.Dispose(ref _mapsBase);
     base.Dispose();
 }
Beispiel #12
0
 public void Dispose()
 {
     DisposeHelper.Dispose(ref _override);
     DisposeHelper.Dispose(ref _resource);
     Debug.WriteLine("[RenderableTexture] DISPOSED: " + Name);
     IsDisposed = true;
 }
Beispiel #13
0
        /*private async Task PeriodicChecks() {
         *  while (!_cancelled) {
         *      await Task.Delay(1000);
         *      if (IsAcWindowActive()) {
         *          Run(false);
         *      }
         *  }
         * }*/

        private IDisposable SetSharedListener()
        {
            async void Handler(object sender, EventArgs args)
            {
                _cancelled = true;
                DisposeHelper.Dispose(ref _process);
                AcSharedMemory.Instance.Start -= Handler;

                var exitCounter = 0;

                for (var i = 0; i < 20; i++)
                {
                    Run(true);

                    var isInPit = AcSharedMemory.Instance.Shared?.Graphics.IsInPits;
                    if (isInPit == false && ++exitCounter > 5)
                    {
                        break;
                    }

                    await Task.Delay(30);
                }
            }

            AcSharedMemory.Instance.Start += Handler;
            // PeriodicChecks().Forget();

            return(new ActionAsDisposable(() => {
                _cancelled = true;
                DisposeHelper.Dispose(ref _process);
                AcSharedMemory.Instance.Start -= Handler;
            }));
        }
Beispiel #14
0
            public static T AddCompiled(string shaderPath, string key, Func <T> compileFunc, Func <string, T> loadFunc)
            {
                var lastMod = File.GetLastWriteTimeUtc(shaderPath);
                T   shader  = null;

                ShaderWithDateTime entry;

                if (s_CompiledShaders.TryGetValue(key, out entry) && entry.LastModified == lastMod)
                {
                    if (entry.Shader != null)
                    {
                        return(entry.Shader);
                    }

                    try
                    {
                        if (loadFunc != null)
                        {
                            shader = loadFunc(entry.CachePath);
                        }
                    }
                    catch
                    {
                        // Recompile if we encounter an error
                    }
                }

                if (shader == null)
                {
                    try
                    {
                        shader = compileFunc();
                    }
                    catch (CompilationException e)
                    {
                        throw new CompilationException(e.ResultCode, "Compilation Error in " + key + "\r\n\r\n" + e.Message);
                    }
                    catch (OpenClException e)
                    {
                        throw new OpenClException("Compilation Error in " + key + "\r\n\r\n" + e.Message, e.ErrorCode);
                    }
                    s_Saved = false;

                    // Remove obsolete cache file
                    if (entry != null && loadFunc != null)
                    {
                        File.Delete(entry.CachePath);
                    }
                }

                // Save / Replace Entry
                if (entry != null)
                {
                    DisposeHelper.Dispose(entry);
                    s_CompiledShaders.Remove(key);
                }

                s_CompiledShaders.Add(key, new ShaderWithDateTime(shader, lastMod, loadFunc != null));
                return(shader);
            }
Beispiel #15
0
        public override void Destroy()
        {
            DisposeHelper.Dispose(ref m_RarFileSourceFilter);

            Player.UnregisterMediaFileExtension(RAR_FILE_EXT);
            Media.Loading -= OnMediaLoading;
        }
Beispiel #16
0
 private void UnloadDriverModel()
 {
     Remove(_driver);
     DisposeHelper.Dispose(ref _driver);
     _driverSteerAnimator = null;
     ObjectsChanged?.Invoke(this, EventArgs.Empty);
 }
            public override void Reset()
            {
                DisposeHelper.Dispose(ref m_Buffer1);
                DisposeHelper.Dispose(ref m_Buffer2);

                base.Reset();
            }
Beispiel #18
0
        private void ApplyDynamicBackground([CanBeNull] string filename, double opacity = 0.5)
        {
            ActionExtension.InvokeInMainThreadAsync(() => {
                try {
                    if (filename == null)
                    {
                        DisposeHelper.Dispose(ref _dynamicBackground);
                        if (FancyBackgroundManager.Instance.Enabled)
                        {
                            FancyBackgroundManager.Instance.Recreate(this);
                        }
                        else
                        {
                            ClearValue(BackgroundContentProperty);
                        }
                    }
                    else
                    {
                        var animatedBackground = Regex.IsMatch(filename, @"\.(?:avi|flv|gif|m(?:4[pv]|kv|ov|p[4g])|og[vg]|qt|webm|wmv)$",
                                                               RegexOptions.IgnoreCase) ?
                                                 filename : null;
                        var staticBackground = animatedBackground == null ? filename : Regex.Replace(filename, @"\.\w+$", @".jpg");

                        _dynamicBackground?.Dispose();
                        BackgroundContent = _dynamicBackground = new DynamicBackground {
                            Animated = animatedBackground,
                            Static   = staticBackground,
                            Opacity  = opacity
                        };
                    }
                } catch (Exception e) {
                    Logging.Error(e);
                }
            });
        }
Beispiel #19
0
 public override void Dispose()
 {
     DisposeHelper.Dispose(ref _buffer0);
     DisposeHelper.Dispose(ref _buffer1);
     // DisposeHelper.Dispose(ref _materialsProvider);
     base.Dispose();
 }
Beispiel #20
0
 public override void ClearOverridesDirectory()
 {
     DisposeHelper.Dispose(ref _contentTexturesWatching);
     _skinIni = null;
     ContentTexturesDirectory = null;
     base.ClearOverridesDirectory();
 }
Beispiel #21
0
 private void DiscardTextures()
 {
     DisposeHelper.Dispose(m_Texture1);
     m_Texture1 = null;
     DisposeHelper.Dispose(m_Texture2);
     m_Texture2 = null;
 }
 private void ReloadSuspension()
 {
     _suspensionsPack = null;
     DisposeHelper.Dispose(ref _suspensionLines);
     ReupdatePreudoSteer();
     OnPropertyChanged(nameof(SuspensionsPack));
 }
        private async Task DisableRenderer()
        {
            if (_loaded)
            {
                await EnableRenderer();

                return;
            }

            if (_imageEx == null)
            {
                return;
            }

            try {
                DisposeHelper.Dispose(ref _renderer);

                CompositionTargetEx.Rendering -= OnRendering;
                Scene.Source = null;

                _imageEx.Lock();
                _imageEx.SetBackBufferEx(D3DResourceTypeEx.ID3D11Texture2D, IntPtr.Zero);
                _imageEx.Unlock();
                _imageEx = null;
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
            }
        }
Beispiel #24
0
        public void SetDebugMode(IDeviceContextHolder holder, bool enabled)
        {
            if (enabled == (_debugMaterial != null))
            {
                return;
            }

            if (enabled)
            {
                var material = holder.Get <SharedMaterials>().GetMaterial(new Tuple <object, uint>(BasicMaterials.DebugKey, OriginalNode.MaterialId));

                _debugMaterial = material as ISkinnedMaterial;
                if (_debugMaterial == null)
                {
                    AcToolsLogging.Write("Error: ISkinnedMaterial required for Kn5SkinnedObject!");
                    material.Dispose();
                    return;
                }

                if (IsInitialized)
                {
                    _debugMaterial.Initialize(holder);
                    _debugMaterialInitialized = true;
                }
            }
            else
            {
                _debugMaterialInitialized = false;
                DisposeHelper.Dispose(ref _debugMaterial);
            }
        }
        public void Dispose()
        {
            Debug.WriteLine("DeviceContextHolder.Dispose()");

            DisposeHelper.Dispose(ref _states);
            Debug.WriteLine("_states disposed");

            DisposeHelper.Dispose(ref _quadBuffers);
            Debug.WriteLine("_quadBuffers disposed");

            _effects.DisposeEverything();
            Debug.WriteLine("_effects disposed");

            _helpers.DisposeEverything();
            Debug.WriteLine("_helpers disposed");

            _randomTextures.DisposeEverything();
            Debug.WriteLine("_randomTextures disposed");

            DisposeHelper.Dispose(ref _flatNmView);
            Debug.WriteLine("_flatNm disposed");

            _something.Values.OfType <IDisposable>().DisposeEverything();
            _something.Clear();
            Debug.WriteLine("_something disposed");

            DeviceContext.ClearState();
            DeviceContext.Flush();
            // we don’t need to dispose deviceContext — it’s the same as device

            Device.Dispose();
            Debug.WriteLine("Device disposed");
        }
Beispiel #26
0
        private static int Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            try {
                var parsed = new Parser(with => {
                    with.EnableDashDash = true;
                    with.HelpWriter     = new FixedWriter();
                }).ParseArguments <Options>(args);
                return(parsed.MapResult(o => {
                    Run(o);
                    return 0;
                }, _ => 1));
            } catch (IOException e) {
                Console.Error.WriteLine(e.Message);
                return(2);
            } catch (Exception e) {
                Console.Error.WriteLine(e.ToString());
                return(2);
            } finally {
                DisposeHelper.Dispose(ref _textureReader);

                /*Console.WriteLine("<Press any key>");
                 * Console.ReadKey();*/
            }
        }
Beispiel #27
0
 public override void Dispose()
 {
     _effect = null;
     DisposeHelper.Dispose(ref _sphere);
     DisposeHelper.Dispose(ref _rasterizer);
     DisposeHelper.Dispose(ref _depth);
 }
Beispiel #28
0
        public void Initialize(DeviceContextHolder holder)
        {
            const Format format = Format.R16G16B16A16_Float;

            DisposeHelper.Dispose(ref _view);
            DisposeHelper.Dispose(ref _depthTargetView);
            DisposeHelper.Dispose(ref _targetView);

            using (var cubeTex = new Texture2D(holder.Device, new Texture2DDescription {
                Width = _cubeMapSize,
                Height = _cubeMapSize,
                MipLevels = GetMipLevels(_cubeMapSize, 4),
                ArraySize = 6,
                SampleDescription = new SampleDescription(1, 0),
                Format = format,
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.GenerateMipMaps | ResourceOptionFlags.TextureCube
            })) {
                _targetView = Enumerable.Range(0, 6).Select(x => new RenderTargetView(holder.Device, cubeTex,
                                                                                      new RenderTargetViewDescription {
                    Format          = format,
                    Dimension       = RenderTargetViewDimension.Texture2DArray,
                    ArraySize       = 1,
                    FirstArraySlice = x,
                    MipSlice        = 0
                })).ToArray();

                _view = new ShaderResourceView(holder.Device, cubeTex, new ShaderResourceViewDescription {
                    Format          = format,
                    Dimension       = ShaderResourceViewDimension.TextureCube,
                    MostDetailedMip = 0,
                    MipLevels       = -1
                });
            }

            const Format depthFormat = Format.D32_Float;

            using (var depthTex = new Texture2D(holder.Device, new Texture2DDescription {
                Width = _cubeMapSize,
                Height = _cubeMapSize,
                MipLevels = 1,
                ArraySize = 1,
                SampleDescription = new SampleDescription(1, 0),
                Format = depthFormat,
                Usage = ResourceUsage.Default,
                BindFlags = BindFlags.DepthStencil,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None
            })) {
                _depthTargetView = new DepthStencilView(holder.Device, depthTex, new DepthStencilViewDescription {
                    Format    = depthFormat,
                    Flags     = DepthStencilViewFlags.None,
                    Dimension = DepthStencilViewDimension.Texture2D,
                    MipSlice  = 0,
                });
            }
        }
            public override IFilter CreateFilter(IFilter input)
            {
                DisposeHelper.Dispose(ref m_Buffer1);
                DisposeHelper.Dispose(ref m_Buffer2);

                if (!Renderer.IsOpenClAvail || Renderer.RenderQuality.PerformanceMode())
                {
                    Renderer.FallbackOccurred = true; // Warn user via player stats OSD
                    return(input);                    // OpenCL is not available, or UNORM8 textures used (not supported); fallback
                }

                Func <TextureSize, TextureSize> transformWidth  = s => new TextureSize(2 * s.Width, s.Height);
                Func <TextureSize, TextureSize> transformHeight = s => new TextureSize(s.Width, 2 * s.Height);

                var kernel  = CompileKernel();
                var shaderH = kernel.Configure(transform: transformWidth);
                var shaderV = kernel.Configure(transform: transformHeight);

                var combine = CompileShader("Combine.hlsl");

                var neuronCount1 = s_NeuronCount[(int)Neurons1];
                var neuronCount2 = s_NeuronCount[(int)Neurons2];
                var weights1     = s_Weights[(int)Neurons1];

                m_Buffer1 = Renderer.CreateClBuffer(weights1);
                var differentWeights = neuronCount1 != neuronCount2;

                if (differentWeights)
                {
                    var weights2 = s_Weights[(int)Neurons2];
                    m_Buffer2 = Renderer.CreateClBuffer(weights2);
                }

                var sourceSize = input.OutputSize;

                if (!IsUpscalingFrom(sourceSize))
                {
                    return(input);
                }

                var yuv = input.ConvertToYuv();

                var chroma = new ResizeFilter(yuv, new TextureSize(sourceSize.Width * 2, sourceSize.Height * 2),
                                              TextureChannels.ChromaOnly, new Vector2(-0.25f, -0.25f), Renderer.ChromaUpscaler,
                                              Renderer.ChromaDownscaler);

                var localWorkSizes = new[] { 8, 8 };
                var nnedi3H        = new NNedi3HKernelFilter(shaderH, m_Buffer1, neuronCount1,
                                                             new TextureSize(yuv.OutputSize.Width, yuv.OutputSize.Height),
                                                             localWorkSizes, yuv);
                var nnedi3V = new NNedi3VKernelFilter(shaderV, m_Buffer2, neuronCount2, differentWeights,
                                                      new TextureSize(nnedi3H.OutputSize.Width, nnedi3H.OutputSize.Height),
                                                      localWorkSizes, nnedi3H);

                var result = new ShaderFilter(combine, nnedi3V, chroma);

                return(new ResizeFilter(result.ConvertToRgb(), result.OutputSize, new Vector2(0.5f, 0.5f),
                                        Renderer.LumaUpscaler, Renderer.LumaDownscaler));
            }
Beispiel #30
0
 public void Dispose()
 {
     DisposeHelper.Dispose(ref _timer);
     DisposeHelper.Dispose(ref _gameProcess);
     DisposeHelper.Dispose(ref _physicsFile);
     DisposeHelper.Dispose(ref _graphicsFile);
     DisposeHelper.Dispose(ref _staticInfoFile);
 }