예제 #1
0
        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);
        }
예제 #2
0
        //[MemberNotNull(nameof(_tex), nameof(_texMsaa8x))]
        public void CreatePipelines()
        {
            var rootParams = new[]
            {
                RootParameter.CreateDescriptor(RootParameterType.ConstantBufferView, 0, 0),
                RootParameter.CreateDescriptor(RootParameterType.ConstantBufferView, 1, 0),
                RootParameter.CreateDescriptor(RootParameterType.ConstantBufferView, 2, 0),
                RootParameter.CreateDescriptorTable(DescriptorRangeType.ShaderResourceView, 0, 1, 0)
            };

            var samplers = new[]
            {
                new StaticSampler(
                    TextureAddressMode.Clamp,
                    SamplerFilterType.Anistropic,
                    shaderRegister: 0,
                    registerSpace: 0,
                    ShaderVisibility.All,
                    StaticSampler.OpaqueWhite
                    )
            };

            _rootSig = _device.CreateRootSignature(rootParams, samplers);

            var compilationFlags = new[]
            {
                ShaderCompileFlag.PackMatricesInRowMajorOrder,
                ShaderCompileFlag.AllResourcesBound,
                ShaderCompileFlag.EnableDebugInformation,
                ShaderCompileFlag.WriteDebugInformationToFile()
                //ShaderCompileFlag.DefineMacro("NORMALS")
            };

            var vertexShader = ShaderManager.CompileShader("Shaders/SimpleTexture/TextureVertexShader.hlsl", ShaderModel.Vs_6_0, compilationFlags);
            var pixelShader  = ShaderManager.CompileShader("Shaders/SimpleTexture/TexturePixelShader.hlsl", ShaderModel.Ps_6_0, compilationFlags);

            var psoDesc = new GraphicsPipelineDesc
            {
                RootSignature       = _rootSig,
                RenderTargetFormats = RenderTargetFormat,
                DepthStencilFormat  = DepthStencilFormat,
                VertexShader        = vertexShader,
                PixelShader         = pixelShader,
                Topology            = TopologyClass.Triangle,
                Inputs = InputLayout.FromType <TexturedVertex>()
            };

            _tex = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "Texture");

            //psoDesc.Msaa = MultisamplingDesc.X8;
            _texMsaa8x = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "Texture_MSAA8X");
        }
예제 #3
0
        public WorldPass(GraphicsDevice device, Camera camera)
        {
            _device = device;
            _camera = camera;

            _rtvs = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1);
            _dsvs = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1);

            var @params = new RootParameter[]
            {
                RootParameter.CreateDescriptor(RootParameterType.ConstantBufferView, 0, 0),
                RootParameter.CreateDescriptor(RootParameterType.ConstantBufferView, 1, 0),
                RootParameter.CreateDescriptor(RootParameterType.ShaderResourceView, 0, 0, ShaderVisibility.Pixel),
                RootParameter.CreateDescriptorTable(DescriptorRangeType.ShaderResourceView, 1, 2, 0, visibility: ShaderVisibility.Pixel)
            };

            var samplers = new StaticSampler[]
            {
                new StaticSampler(TextureAddressMode.Clamp, SamplerFilterType.MagPoint | SamplerFilterType.MinPoint | SamplerFilterType.MipLinear, 0, 0, ShaderVisibility.Pixel)
            };

            RootSignature = _device.CreateRootSignature(@params, samplers);

            var shaderFlags = new[]
            {
                ShaderCompileFlag.PackMatricesInRowMajorOrder,
                ShaderCompileFlag.DisableOptimizations,
                ShaderCompileFlag.EnableDebugInformation,
                ShaderCompileFlag.WriteDebugInformationToFile()
            };

            var psoDesc = new GraphicsPipelineDesc
            {
                RootSignature       = RootSignature,
                Topology            = TopologyClass.Triangle,
                RenderTargetFormats = BackBufferFormat.R8G8B8A8UnsignedNormalized,

                DepthStencilFormat = DataFormat.Depth32Single,

                VertexShader = ShaderManager.CompileShader("Shaders/ChunkShader.hlsl", ShaderType.Vertex, shaderFlags, "VertexMain"),
                PixelShader  = ShaderManager.CompileShader("Shaders/ChunkShader.hlsl", ShaderType.Pixel, shaderFlags, "PixelMain"),
                Inputs       = InputLayout.FromType <BlockVertex>()
            };

            Pso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "ChunkPso");

            psoDesc.Msaa = MsaaDesc.X8;

            MsaaPso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "MsaaChunkPso");

            UploadTextures();

            Chunks = new[] { new RenderChunk() };
            Chunks[0].Chunk.Blocks       = new Block?[Width * Height * Depth];
            Chunks[0].Chunk.NeedsRebuild = true;

            var rng = new Random();

            foreach (ref readonly var block in Chunks[0].Chunk.Blocks.Span)
            {
                Unsafe.AsRef(in block) = new Block {
                    TextureId = (uint)rng.Next(0, _textures.Length)
                };
            }

            SetConstants();
        }