Exemple #1
0
        public ImageBlurApp()
        {
            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null);

            var rootParams = new RootParameter[]
            {
                RootParameter.CreateConstants <Settings>(0, 0),
                RootParameter.CreateDescriptorTable(DescriptorRangeType.ShaderResourceView, 0, 1, 0),
                RootParameter.CreateDescriptorTable(DescriptorRangeType.UnorderedAccessView, 0, 1, 1)
            };

            var rootSig = _device.CreateRootSignature(rootParams);

            var psoDesc = new ComputePipelineDesc
            {
                RootSignature = rootSig,
                ComputeShader = ShaderManager.CompileShader("ImageBlur/ImageBlur.hlsl", ShaderType.Compute, entrypoint: "BlurHorizontal"),
            };

            _horizontalBlurPso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "BlurHorizontal");

            psoDesc = new ComputePipelineDesc
            {
                RootSignature = rootSig,
                ComputeShader = ShaderManager.CompileShader("ImageBlur/ImageBlur.hlsl", ShaderType.Compute, entrypoint: "BlurVertical"),
            };
            _verticalBlurPso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "BlurVertical");

            _settings = new Settings
            {
                BlurRadius = 8
            };
            GetWeights();
        }
        public override void Initialize(Size outputSize, IOutputOwner output)
        {
#if DEBUG
            var debug = DebugLayerConfiguration.Debug.AddDebugFlags(DebugFlags.GpuBasedValidation);
#else
            var debug = DebugLayerConfiguration.None;
#endif

            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null, debug);
            _output = Output.Create(OutputConfiguration.Default, _device, output);

            using (var copy = _device.BeginUploadContext())
            {
                _colors = copy.UploadBuffer(GetColors());
            }

            var @params = new RootParameter[]
            {
                RootParameter.CreateDescriptor(RootParameterType.ShaderResourceView, 0, 0, ShaderVisibility.Pixel),
                RootParameter.CreateConstants <MandelbrotConstants>(0, 0, ShaderVisibility.Pixel),
            };

            var rootSig = _device.CreateRootSignature(@params, null);

            var flags = new ShaderCompileFlag[]
            {
                ShaderCompileFlag.EnableDebugInformation,
                ShaderCompileFlag.WriteDebugInformationToFile(),
                ShaderCompileFlag.DefineMacro("ITER", IterCount.ToString()),
#if DOUBLE
                ShaderCompileFlag.DefineMacro("DOUBLE")
#endif
            };

            var psoDesc = new GraphicsPipelineDesc
            {
                RootSignature       = rootSig,
                Topology            = TopologyClass.Triangle,
                DepthStencil        = DepthStencilDesc.DisableDepthStencil,
                RenderTargetFormats = BackBufferFormat.R8G8B8A8UnsignedNormalized,
                VertexShader        = ShaderManager.CompileShader("Shaders/Mandelbrot/EntireScreenCopyVS.hlsl", ShaderType.Vertex, flags),
                PixelShader         = ShaderManager.CompileShader("Shaders/Mandelbrot/Mandelbrot.hlsl", ShaderType.Pixel, flags),
                Rasterizer          = RasterizerDesc.Default.WithFrontFaceType(FaceType.Anticlockwise)
            };

            _pso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "Mandelbrot");

            _constants = new MandelbrotConstants
            {
                Scale      = (FloatType)1,
                CenterX    = (FloatType)(-1.789169018604823106674468341188838763),
                CenterY    = (FloatType)(0.00000033936851576718256602823026614),
                ColorCount = _colors.LengthAs <Rgba128>()
            };

            OnResize(outputSize);
        }