Exemple #1
0
        public override unsafe void Initialize(Size data, IOutputOwner output)
        {
            using var factory = DeviceFactory.Create();
            foreach (var device in factory)
            {
                Console.WriteLine(device);
            }

            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null);

            var desc = new OutputConfiguration
            {
                BackBufferFormat = BackBufferFormat.R8G8B8A8UnsignedNormalized,
                BackBufferCount  = 3,
                SyncInterval     = 0
            };

            _output = Output.Create(desc, _device, output);

            _settings = new PipelineSettings
            {
                Msaa        = MsaaDesc.None,
                Resolution  = _output.Resolution,
                AspectRatio = _output.AspectRatio
            };


            _renderer   = new BasicSceneRenderer(_device);
            _msaaPass   = new MsaaPass();
            _outputPass = new TonemapPass(_output);

            _graph = new RenderGraph(_device, _output.Configuration.BackBufferCount);
        }
        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);
        }
Exemple #3
0
        internal SwapChainOutput(GraphicsDevice device, Size size, IOutputOwner owner, OutputConfiguration desc) : base(device, desc)
        {
            _device = device;

            var swapChainDesc = CreateDesc(desc, size);

            if (UseSeperatePresentQueue())
            {
                _presentQueue           = new CommandQueue(device, ExecutionContext.Graphics, enableTdr: true);
                _presentQueueIsSeperate = true;
            }
            else
            {
                _presentQueue = device.GraphicsQueue;
            }

            using var factory = CreateFactory();
            using UniqueComPtr <IDXGISwapChain1> swapChain = default;

            var pQueue  = (IUnknown *)_presentQueue.GetQueue();
            var ppChain = (IDXGISwapChain1 **)&swapChain;

            IDXGIOutput *pRestrict = null;

            Guard.ThrowIfFailed(
                owner.Type switch
            {
                OutputType.Hwnd => factory.Ptr->CreateSwapChainForHwnd(
                    pQueue,
                    owner.GetOutput(),
                    &swapChainDesc,
                    null,
                    pRestrict,
                    ppChain
                    ),

                OutputType.ICoreWindow => factory.Ptr->CreateSwapChainForCoreWindow(
                    pQueue,
                    (IUnknown *)owner.GetOutput(),
                    &swapChainDesc,
                    pRestrict,
                    ppChain
                    ),

                OutputType.SwapChainPanel => factory.Ptr->CreateSwapChainForComposition(
                    pQueue,
                    &swapChainDesc,
                    pRestrict,
                    ppChain
                    ),

                _ => E_INVALIDARG,     // this way we fail if weird enum arg provided
            }
Exemple #4
0
        public override void Initialize(Size outputSize, IOutputOwner outputOwner)
        {
            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null, DebugLayerConfiguration.Debug.WithDebugFlags(DebugFlags.DebugLayer | DebugFlags.GpuBasedValidation));
            _output = Output.Create(OutputConfiguration.Default, _device, outputOwner);

            _camera = new();

            const uint latency = 1;

            _graph      = new RenderGraph(_device, latency);
            _worldPass  = new WorldPass(_device, _camera);
            _fxaaPass   = new FxaaPass(_device);
            _outputPass = new TonemapPass(_output);
        }
        public override unsafe void Initialize(Size data, IOutputOwner output)
        {
            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null);

            var desc = new OutputConfiguration
            {
                BackBufferFormat = BackBufferFormat.R16G16B16A16Single,
                BackBufferCount  = 3,
                SyncInterval     = 0
            };

            _output = Output.Create(desc, _device, output);

            _renderer.Init(_device, data);
        }
        public unsafe override void Initialize(Size outputSize, IOutputOwner output)
        {
            var debug = new DebugLayerConfiguration()
                        .WithDebugFlags(DebugFlags.DebugLayer)
                        .WithDredFlags(DredFlags.All)
                        .WithBreakpointLogLevel(LogLevel.None);

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

            OnResize(outputSize);

            ReadOnlySpan <Vertex> vertices = stackalloc Vertex[3]
            {
                new Vertex {
                    Position = new Vector3(+0.25f, -0.25f, +0.0f), Color = (Vector4)Rgba128.Blue
                },
                new Vertex {
                    Position = new Vector3(-0.25f, -0.25f, +0.0f), Color = (Vector4)Rgba128.Green
                },
                new Vertex {
                    Position = new Vector3(+0.0f, +0.25f, +0.0f), Color = (Vector4)Rgba128.Red
                },
            };

            // Allocate the vertices, using the overload which takes some initial data
            _vertices = _device.Allocator.AllocateUploadBuffer(vertices);
            _indirect = _device.Allocator.AllocateUploadBuffer <IndirectDrawArguments>();

            // The pipeline description. We compile shaders at runtime here, which is simpler but less efficient
            var psoDesc = new GraphicsPipelineDesc
            {
                Topology            = TopologyClass.Triangle,
                VertexShader        = ShaderManager.CompileShader("HelloTriangle/Shader.hlsl", ShaderType.Vertex, entrypoint: "VertexMain"),
                PixelShader         = ShaderManager.CompileShader("HelloTriangle/Shader.hlsl", ShaderType.Pixel, entrypoint: "PixelMain"),
                RenderTargetFormats = _output.Configuration.BackBufferFormat,
                DepthStencil        = DepthStencilDesc.DisableDepthStencil,
                Inputs = InputLayout.FromType <Vertex>(),
            };

            _pso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, nameof(_pso));
        }
        public override unsafe void Initialize(Size data, IOutputOwner output)
        {
            _device = GraphicsDevice.Create(FeatureLevel.GraphicsLevel11_0, null);

            var desc = new OutputConfiguration
            {
                BackBufferFormat = BackBufferFormat.R8G8B8A8UnsignedNormalized,
                BackBufferCount  = 3,
                SyncInterval     = 0
            };

            _settings = new PipelineSettings
            {
                Msaa = MsaaDesc.None
            };

            _output = Output.Create(desc, _device, output);

            //_renderer = null!;
            //new MandelbrotRenderPass(_device, data);
            _outputPass = new TonemapPass(_output);
        }
Exemple #8
0
 /// <summary>
 /// Creates a new <see cref="Output"/> to a WinRT ISwapChainPanelNative
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/> that will output to this buffer</param>
 /// <param name="desc">The <see cref="OutputConfiguration"/> for this output</param>
 /// <param name="swapChainPanelNative">The IUnknown* for the ISwapChainPanelNative to bind to</param>
 /// <param name="outputArea">The <see cref="Size"/> of the rendered output</param>
 /// <returns>A new <see cref="Output"/></returns>
 public static Output CreateForSwapChainPanel(GraphicsDevice device, OutputConfiguration desc, void *swapChainPanelNative, Size outputArea)
 {
     return(new SwapChainOutput(device, outputArea, IOutputOwner.FromSwapChainPanel(swapChainPanelNative), desc));
 }
Exemple #9
0
 /// <summary>
 /// Creates a new <see cref="Output"/> to a WinRT ICoreWindow
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/> that will output to this buffer</param>
 /// <param name="desc">The <see cref="OutputConfiguration"/> for this output</param>
 /// <param name="window">The IUnknown* for the window to bind to</param>
 /// <param name="outputArea">Optionally, the <see cref="Size"/> of the rendered output. By default, this will be the entire window</param>
 /// <returns>A new <see cref="Output"/></returns>
 public static Output CreateForWinRT(GraphicsDevice device, OutputConfiguration desc, void *window, Size outputArea = default)
 {
     return(new SwapChainOutput(device, outputArea, IOutputOwner.FromICoreWindow(window), desc));
 }
Exemple #10
0
 /// <summary>
 /// Creates a new <see cref="Output"/> to a Win32 Window backed by a HWND
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/> that will output to this buffer</param>
 /// <param name="desc">The <see cref="OutputConfiguration"/> for this output</param>
 /// <param name="window">The HWND for the window to bind to</param>
 /// <param name="outputArea">Optionally, the <see cref="Size"/> of the rendered output. By default, this will be the entire window</param>
 /// <returns>A new <see cref="Output"/></returns>
 public static Output CreateForWin32(GraphicsDevice device, OutputConfiguration desc, IntPtr window, Size outputArea = default)
 {
     return(new SwapChainOutput(device, outputArea, IOutputOwner.FromHwnd(window), desc));
 }
Exemple #11
0
 /// <summary>
 /// Creates a new <see cref="Output"/> to a <see cref="IOutputOwner"/>
 /// </summary>
 /// <param name="desc">The <see cref="OutputConfiguration"/> for this output</param>
 /// <param name="device">The <see cref="GraphicsDevice"/> that will output to this buffer</param>
 /// <param name="window">The <see cref="IOutputOwner"/> that owns the window</param>
 /// <param name="outputArea">Optionally, the <see cref="Size"/> of the rendered output. By default, this will be the entire window</param>
 /// <returns>A new <see cref="Output"/></returns>
 public static Output Create(OutputConfiguration desc, GraphicsDevice device, IOutputOwner window, Size outputArea = default)
 {
     return(new SwapChainOutput(device, outputArea, window, desc));
 }
Exemple #12
0
 public abstract void Initialize(Size outputSize, IOutputOwner output);