Пример #1
0
        // Get's a handle to assosiate with the BackBuffer and Prepares Devices
        private void Initialize(IntPtr outputHandle)
        {
            // SwapChain Description
            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(0, 0, new Rational(0, 0), Format.B8G8R8A8_UNorm),   // RBGA | BGRA 32-bit
                IsWindowed        = true,
                OutputHandle      = outputHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            // Create Device, SwapChain & BackBuffer
            Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, desc, out _device, out _swapChain);
            _backBuffer = Texture2D.FromSwapChain <Texture2D>(_swapChain, 0);

            // Creates Association between outputHandle and BackBuffer
            var factory = _swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(outputHandle, WindowAssociationFlags.IgnoreAll);

            // Video Device | Video Context
            videoDevice1  = _device.QueryInterface <VideoDevice1>();
            videoContext1 = _device.ImmediateContext.QueryInterface <VideoContext1>();

            // Creates Video Processor Enumerator
            vpcd = new VideoProcessorContentDescription()
            {
                Usage            = VideoUsage.PlaybackNormal,
                InputFrameFormat = VideoFrameFormat.Progressive,

                InputFrameRate  = new Rational(1, 1),
                OutputFrameRate = new Rational(1, 1),

                // We Set those later
                InputWidth   = 1,
                OutputWidth  = 1,
                InputHeight  = 1,
                OutputHeight = 1
            };
            videoDevice1.CreateVideoProcessorEnumerator(ref vpcd, out vpe);
            videoDevice1.CreateVideoProcessor(vpe, 0, out videoProcessor);

            // Prepares Video Processor Input View Description for Video Processor Input View that we pass Shared NV12 Texture (nv12SharedResource) each time
            vpivd = new VideoProcessorInputViewDescription()
            {
                FourCC    = 0,
                Dimension = VpivDimension.Texture2D,
                Texture2D = new Texture2DVpiv()
                {
                    MipSlice = 0, ArraySlice = 0
                }
            };

            // Creates Video Processor Output to our BackBuffer
            vpovd = new VideoProcessorOutputViewDescription()
            {
                Dimension = VpovDimension.Texture2D
            };
            videoDevice1.CreateVideoProcessorOutputView((Resource)_backBuffer, vpe, vpovd, out vpov);

            // Prepares Streams Array
            vpsa = new VideoProcessorStream[1];
        }
Пример #2
0
 public Result CreateVideoProcessorEnumerator(VideoProcessorContentDescription description, out ID3D11VideoProcessorEnumerator enumerator)
 {
     return(CreateVideoProcessorEnumerator(ref description, out enumerator));
 }
Пример #3
0
 public ID3D11VideoProcessorEnumerator CreateVideoProcessorEnumerator(VideoProcessorContentDescription description)
 {
     CreateVideoProcessorEnumerator(ref description, out ID3D11VideoProcessorEnumerator enumerator).CheckError();
     return(enumerator);
 }
Пример #4
0
        private void Initialize()
        {
            factory2d = new Factory2D(SharpDX.Direct2D1.FactoryType.MultiThreaded, DebugLevel.Information);

            HookControl         = Control.FromHandle(HookHandle);
            HookControl.Resize += HookResized;

            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(0, 0, new Rational(0, 0), Format.B8G8R8A8_UNorm),   // BGRA | Required for Direct2D/DirectWrite (<Win8)
                IsWindowed        = true,
                OutputHandle      = HookHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            /* [Enable Debug Layer]
             *
             * https://docs.microsoft.com/en-us/windows/win32/direct3d11/using-the-debug-layer-to-test-apps
             * To use this flag, you must have D3D11*SDKLayers.dll installed; otherwise, device creation fails. To get D3D11_1SDKLayers.dll, install the SDK for Windows 8.
             */

            // Enable on-demand to avoid "Failed to create device issue"
            //#if DEBUG
            //    Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, desc, out device, out swapChain);
            //#else
            Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, out device, out swapChain);
            //#endif

            var factory = swapChain.GetParent <FactoryDX>();

            factory.MakeWindowAssociation(HookHandle, WindowAssociationFlags.IgnoreAll);

            backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
            rtv        = new RenderTargetView(device, backBuffer);
            context    = device.ImmediateContext;

            factoryWrite = new FactoryDW();
            surface      = backBuffer.QueryInterface <Surface>();
            rtv2d        = new RenderTarget(factory2d, surface, new RenderTargetProperties(new SharpDX.Direct2D1.PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)));
            brush2d      = new SolidColorBrush(rtv2d, Color.White);

            var VertexShaderByteCode = ShaderBytecode.Compile(Properties.Resources.VertexShader, "main", "vs_5_0", ShaderFlags.Debug);

            vertexLayout = new InputLayout(device, VertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0, InputClassification.PerVertexData, 0),
            });
            vertexShader = new VertexShader(device, VertexShaderByteCode);

            var PixelShaderByteCode = ShaderBytecode.Compile(Properties.Resources.PixelShader, "main", "ps_5_0", ShaderFlags.Debug);

            pixelShader = new PixelShader(device, PixelShaderByteCode);

            var PixelShaderByteCodeYUV = ShaderBytecode.Compile(Properties.Resources.PixelShader_YUV, "main", "ps_5_0", ShaderFlags.Debug);

            pixelShaderYUV = new PixelShader(device, PixelShaderByteCodeYUV);

            vertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, new[]
            {
                -1.0f, -1.0f, 0, 0.0f, 1.0f,
                -1.0f, 1.0f, 0, 0.0f, 0.0f,
                1.0f, -1.0f, 0, 1.0f, 1.0f,

                1.0f, -1.0f, 0, 1.0f, 1.0f,
                -1.0f, 1.0f, 0, 0.0f, 0.0f,
                1.0f, 1.0f, 0, 1.0f, 0.0f
            });

            SamplerState textureSampler = new SamplerState(device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.MinMagMipLinear,
                MaximumAnisotropy  = 1,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            });

            context.InputAssembler.InputLayout       = vertexLayout;
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <float>() * 5, 0));

            context.VertexShader.Set(vertexShader);
            context.PixelShader.SetSampler(0, textureSampler);

            textureRGB = new Texture2D(device, new Texture2DDescription()
            {
                Usage  = ResourceUsage.Default,
                Format = Format.R8G8B8A8_UNorm,

                Width  = HookControl.Width,
                Height = HookControl.Height,

                BindFlags      = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,

                SampleDescription = new SampleDescription(1, 0),
                ArraySize         = 1,
                MipLevels         = 1
            });

            srvDescYUV           = new ShaderResourceViewDescription();
            srvDescYUV.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
            srvDescYUV.Format    = Format.R8_UNorm;
            srvDescYUV.Texture2D.MostDetailedMip = 0;
            srvDescYUV.Texture2D.MipLevels       = 1;

            videoDevice1  = device.QueryInterface <VideoDevice1>();
            videoContext1 = device.ImmediateContext.QueryInterface <VideoContext1>();

            vpcd = new VideoProcessorContentDescription()
            {
                Usage            = VideoUsage.PlaybackNormal,
                InputFrameFormat = VideoFrameFormat.Progressive,
                InputFrameRate   = new Rational(1, 1),
                OutputFrameRate  = new Rational(1, 1),
                InputWidth       = 1,
                OutputWidth      = 1,
                InputHeight      = 1,
                OutputHeight     = 1
            };
            videoDevice1.CreateVideoProcessorEnumerator(ref vpcd, out vpe);
            videoDevice1.CreateVideoProcessor(vpe, 0, out videoProcessor);

            vpivd = new VideoProcessorInputViewDescription()
            {
                FourCC    = 0,
                Dimension = VpivDimension.Texture2D,
                Texture2D = new Texture2DVpiv()
                {
                    MipSlice = 0, ArraySlice = 0
                }
            };
            vpovd = new VideoProcessorOutputViewDescription()
            {
                Dimension = VpovDimension.Texture2D
            };
            vpsa = new VideoProcessorStream[1];

            SetViewport();

            //foreach (var osdsurf in osd)
            //osdsurf.Value.Init();
        }
Пример #5
0
        private void Initialize()
        {
            factory2d = new Factory2D(SharpDX.Direct2D1.FactoryType.MultiThreaded, DebugLevel.Information);

            HookControl         = Control.FromHandle(HookHandle);
            HookControl.Resize += HookResized;

            var desc = new SwapChainDescription()
            {
                BufferCount       = 1,
                ModeDescription   = new ModeDescription(0, 0, new Rational(0, 0), Format.B8G8R8A8_UNorm),   // BGRA | Required for Direct2D/DirectWrite (<Win8)
                IsWindowed        = true,
                OutputHandle      = HookHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            /* [Enable Debug Layer]
             * https://docs.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-devices-layers
             * https://docs.microsoft.com/en-us/windows/win32/direct3d11/using-the-debug-layer-to-test-apps
             *
             * For Windows 7 with Platform Update for Windows 7 (KB2670838) or Windows 8.x, to create a device that supports the debug layer, install the Windows Software Development Kit (SDK) for Windows 8.x to get D3D11_1SDKLayers.dll
             * For Windows 10, to create a device that supports the debug layer, enable the "Graphics Tools" optional feature. Go to the Settings panel, under System, Apps & features, Manage optional Features, Add a feature, and then look for "Graphics Tools".
             *
             */

            // Enable on-demand to avoid "Failed to create device issue"
            //#if DEBUG
            //    Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.Debug | DeviceCreationFlags.BgraSupport, desc, out device, out swapChain);
            //#else
            Device.CreateWithSwapChain(SharpDX.Direct3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport, desc, out device, out swapChain);
            //#endif

            var factory = swapChain.GetParent <FactoryDX>();

            factory.MakeWindowAssociation(HookHandle, WindowAssociationFlags.IgnoreAll);

            backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0);
            rtv        = new RenderTargetView(device, backBuffer);
            context    = device.ImmediateContext;

            factoryWrite   = new FactoryDW();
            surface        = backBuffer.QueryInterface <Surface>();
            rtv2d          = new RenderTarget(factory2d, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, SharpDX.Direct2D1.AlphaMode.Premultiplied)));
            brush2d        = new SolidColorBrush(rtv2d, Color.White);
            brush2dOutline = new SolidColorBrush(rtv2d, Color.Gray);

            outlineRenderer.renderer = this;

            string vertexProfile = "vs_5_0";
            string pixelProfile  = "ps_5_0";

            if (device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_9_1 ||
                device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_9_2 ||
                device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_9_3 ||
                device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_10_0 ||
                device.FeatureLevel == SharpDX.Direct3D.FeatureLevel.Level_10_1)
            {
                vertexProfile = "vs_4_0_level_9_1";
                pixelProfile  = "ps_4_0_level_9_1";
            }

            var VertexShaderByteCode = ShaderBytecode.Compile(Properties.Resources.VertexShader, "main", vertexProfile, ShaderFlags.Debug);

            vertexLayout = new InputLayout(device, VertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0, InputClassification.PerVertexData, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 12, 0, InputClassification.PerVertexData, 0),
            });
            vertexShader = new VertexShader(device, VertexShaderByteCode);

            var PixelShaderByteCode = ShaderBytecode.Compile(Properties.Resources.PixelShader, "main", pixelProfile, ShaderFlags.Debug);

            pixelShader = new PixelShader(device, PixelShaderByteCode);

            var PixelShaderByteCodeYUV = ShaderBytecode.Compile(Properties.Resources.PixelShader_YUV, "main", pixelProfile, ShaderFlags.Debug);

            pixelShaderYUV = new PixelShader(device, PixelShaderByteCodeYUV);

            vertexBuffer = Buffer.Create(device, BindFlags.VertexBuffer, new[]
            {
                -1.0f, -1.0f, 0, 0.0f, 1.0f,
                -1.0f, 1.0f, 0, 0.0f, 0.0f,
                1.0f, -1.0f, 0, 1.0f, 1.0f,

                1.0f, -1.0f, 0, 1.0f, 1.0f,
                -1.0f, 1.0f, 0, 0.0f, 0.0f,
                1.0f, 1.0f, 0, 1.0f, 0.0f
            });

            SamplerState textureSampler = new SamplerState(device, new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.MinMagMipLinear,
                MaximumAnisotropy  = 1,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            });

            context.InputAssembler.InputLayout       = vertexLayout;
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Utilities.SizeOf <float>() * 5, 0));

            context.VertexShader.Set(vertexShader);
            context.PixelShader.SetSampler(0, textureSampler);

            textureRGB = new Texture2D(device, new Texture2DDescription()
            {
                Usage  = ResourceUsage.Default,
                Format = Format.R8G8B8A8_UNorm,

                Width  = HookControl.Width,
                Height = HookControl.Height,

                BindFlags      = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,

                SampleDescription = new SampleDescription(1, 0),
                ArraySize         = 1,
                MipLevels         = 1
            });

            srvDescYUV           = new ShaderResourceViewDescription();
            srvDescYUV.Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D;
            srvDescYUV.Format    = Format.R8_UNorm;
            srvDescYUV.Texture2D.MostDetailedMip = 0;
            srvDescYUV.Texture2D.MipLevels       = 1;

            // Falling back from videoDevice1/videoContext1 to videoDevice/videoContext to ensure backwards compatibility
            videoDevice1  = device.QueryInterfaceOrNull <VideoDevice>();
            videoContext1 = device.ImmediateContext.QueryInterfaceOrNull <VideoContext>();

            if (videoDevice1 == null || videoContext1 == null)
            {
                SetViewport(); return;
            }

            vpcd = new VideoProcessorContentDescription()
            {
                Usage            = VideoUsage.PlaybackNormal,
                InputFrameFormat = VideoFrameFormat.Progressive,
                InputFrameRate   = new Rational(1, 1),
                OutputFrameRate  = new Rational(1, 1),
                InputWidth       = 1,
                OutputWidth      = 1,
                InputHeight      = 1,
                OutputHeight     = 1
            };
            videoDevice1.CreateVideoProcessorEnumerator(ref vpcd, out vpe);
            videoDevice1.CreateVideoProcessor(vpe, 0, out videoProcessor);

            vpivd = new VideoProcessorInputViewDescription()
            {
                FourCC    = 0,
                Dimension = VpivDimension.Texture2D,
                Texture2D = new Texture2DVpiv()
                {
                    MipSlice = 0, ArraySlice = 0
                }
            };
            vpovd = new VideoProcessorOutputViewDescription()
            {
                Dimension = VpovDimension.Texture2D
            };
            vpsa = new VideoProcessorStream[1];

            SetViewport();
        }
Пример #6
0
 public T CreateVideoProcessorEnumerator <T>(VideoProcessorContentDescription description) where T : ID3D11VideoProcessorEnumerator
 {
     using ID3D11VideoProcessorEnumerator enumerator = CreateVideoProcessorEnumerator(description);
     return(enumerator.QueryInterface <T>());
 }