Beispiel #1
0
        public override void Initialize(Application application)
        {
            ExceptionUtilities.ThrowIfNull(application, nameof(application));

            var windowProvider = application.GetService <WindowProvider>();

            _window = windowProvider.CreateWindow();
            _window.Show();

            var graphicsProvider = application.GetService <GraphicsProvider>();
            var graphicsAdapter  = graphicsProvider.GraphicsAdapters.First();

            var graphicsDevice = graphicsAdapter.CreateGraphicsDevice(_window, graphicsContextCount: 2);

            _graphicsDevice     = graphicsDevice;
            _graphicsDeviceHeap = graphicsDevice.CreateGraphicsHeap(64 * 1024 * 5, GraphicsHeapCpuAccess.None);

            using (var graphicsStagingHeap = graphicsDevice.CreateGraphicsHeap(64 * 1024 * 5, GraphicsHeapCpuAccess.Write))
                using (var vertexStagingBuffer = graphicsStagingHeap.CreateGraphicsBuffer(GraphicsBufferKind.Staging, 64 * 1024, sizeof(byte)))
                    using (var textureStagingBuffer = graphicsStagingHeap.CreateGraphicsBuffer(GraphicsBufferKind.Staging, 64 * 1024 * 4, sizeof(byte)))
                    {
                        var currentGraphicsContext = graphicsDevice.CurrentGraphicsContext;
                        currentGraphicsContext.BeginFrame();

                        _trianglePrimitive = CreateTrianglePrimitive(currentGraphicsContext, vertexStagingBuffer, textureStagingBuffer);

                        currentGraphicsContext.EndFrame();

                        graphicsDevice.Signal(currentGraphicsContext.GraphicsFence);
                        graphicsDevice.WaitForIdle();
                    }

            base.Initialize(application);
        }
Beispiel #2
0
    /// <summary>Initializes the GUI for this sample.</summary>
    /// <param name="application">The hosting <see cref="Application" />.</param>
    /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
    /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
    /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
    public override void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
    {
        base.Initialize(application, timeout, windowLocation, windowSize);

        var graphicsDevice = GraphicsDevice;

        _indexBuffer  = graphicsDevice.CreateIndexBuffer(64 * 1024);
        _uploadBuffer = graphicsDevice.CreateUploadBuffer(64 * 1024);
        _vertexBuffer = graphicsDevice.CreateVertexBuffer(64 * 1024);

        var copyCommandQueue = graphicsDevice.CopyCommandQueue;
        var copyContext      = copyCommandQueue.RentContext();

        {
            copyContext.Reset();
            {
                _quadPrimitive = CreateQuadPrimitive(copyContext);
            }
            copyContext.Close();
            copyContext.Execute();
        }
        copyCommandQueue.ReturnContext(copyContext);

        _uploadBuffer.DisposeAllViews();
    }
Beispiel #3
0
    /// <summary>Initializes the GUI for this sample.</summary>
    /// <param name="application">The hosting <see cref="Application" />.</param>
    /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
    /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
    /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
    public override void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
    {
        base.Initialize(application, timeout, windowLocation, windowSize);

        var graphicsDevice = GraphicsDevice;

        _constantBuffer = graphicsDevice.CreateConstantBuffer(64 * 1024, GraphicsCpuAccess.Write);
        _texture2D      = graphicsDevice.CreateTexture2D(GraphicsFormat.R8G8B8A8_UNORM, 256, 256);
        _uploadBuffer   = graphicsDevice.CreateUploadBuffer(1 * 1024 * 1024);
        _vertexBuffer   = graphicsDevice.CreateVertexBuffer(64 * 1024);

        var copyCommandQueue = graphicsDevice.CopyCommandQueue;
        var copyContext      = copyCommandQueue.RentContext();

        {
            copyContext.Reset();
            {
                _trianglePrimitive = CreateTrianglePrimitive(copyContext);
            }
            copyContext.Close();
            copyContext.Execute();
        }
        copyCommandQueue.ReturnContext(copyContext);

        _uploadBuffer.DisposeAllViews();
    }
        /// <summary>Initializes the GUI for this sample.</summary>
        /// <param name="application">The hosting <see cref="Application" />.</param>
        /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
        /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
        /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
        public override void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
        {
            base.Initialize(application, timeout, windowLocation, windowSize);

            var graphicsDevice         = GraphicsDevice;
            var currentGraphicsContext = graphicsDevice.CurrentContext;

            var vertices         = 2 * 12 * (ulong)MathF.Pow(4, _recursionDepth);
            var vertexBufferSize = vertices * SizeOf <PosNormTex3DVertex>();
            var indexBufferSize  = vertices * SizeOf <uint>(); // matches vertices count because vertices are replicated, three unique ones per triangle

            using var vertexStagingBuffer  = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.CpuToGpu, vertexBufferSize);
            using var indexStagingBuffer   = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.CpuToGpu, indexBufferSize);
            using var textureStagingBuffer = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.CpuToGpu, 64 * 1024 * 1024);

            _constantBuffer = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Constant, GraphicsResourceCpuAccess.CpuToGpu, 64 * 1024);
            _indexBuffer    = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Index, GraphicsResourceCpuAccess.GpuOnly, indexBufferSize);
            _vertexBuffer   = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Vertex, GraphicsResourceCpuAccess.GpuOnly, vertexBufferSize);

            currentGraphicsContext.BeginFrame();
            _pyramid = CreateGraphicsPrimitive(currentGraphicsContext, vertexStagingBuffer, indexStagingBuffer, textureStagingBuffer);
            currentGraphicsContext.EndFrame();

            graphicsDevice.Signal(currentGraphicsContext.Fence);
            graphicsDevice.WaitForIdle();
        }
Beispiel #5
0
    /// <summary>Initializes the GUI for this sample.</summary>
    /// <param name="application">The hosting <see cref="Application" />.</param>
    /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
    /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
    /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
    public override void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
    {
        base.Initialize(application, timeout, windowLocation, windowSize);

        var graphicsDevice = GraphicsDevice;

        var verticeCount = 2 * 12 * (nuint)MathF.Pow(4, _recursionDepth);

        _constantBuffer = graphicsDevice.CreateConstantBuffer(64 * 1024, GraphicsCpuAccess.Write);
        _indexBuffer    = graphicsDevice.CreateIndexBuffer(verticeCount * SizeOf <uint>());
        _texture3D      = graphicsDevice.CreateTexture3D(GraphicsFormat.R8G8B8A8_UNORM, 256, 256, 256);
        _uploadBuffer   = graphicsDevice.CreateUploadBuffer(128 * 1024 * 1024);
        _vertexBuffer   = graphicsDevice.CreateVertexBuffer(verticeCount * SizeOf <PosNormTex3DVertex>());

        var copyCommandQueue = graphicsDevice.CopyCommandQueue;
        var copyContext      = copyCommandQueue.RentContext();

        {
            copyContext.Reset();
            {
                _sierpinskiPrimitive = CreateSierpinskiPrimitive(copyContext);
            }
            copyContext.Close();
            copyContext.Execute();
        }
        copyCommandQueue.ReturnContext(copyContext);

        _uploadBuffer.DisposeAllViews();
    }
Beispiel #6
0
    /// <summary>Initializes the GUI for this sample.</summary>
    /// <param name="application">The hosting <see cref="Application" />.</param>
    /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
    /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
    /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
    public override void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
    {
        base.Initialize(application, timeout, windowLocation, windowSize);

        var graphicsDevice = GraphicsDevice;

        _constantBuffer = graphicsDevice.CreateConstantBuffer(64 * 1024, GraphicsCpuAccess.Write);
        _uploadBuffer   = graphicsDevice.CreateUploadBuffer(64 * 1024);
        _vertexBuffer   = graphicsDevice.CreateVertexBuffer(64 * 1024);

        var copyCommandQueue = graphicsDevice.CopyCommandQueue;
        var copyContext      = copyCommandQueue.RentContext();

        {
            copyContext.Reset();
            {
                _trianglePrimitive               = CreateInstancedTrianglePrimitive(copyContext, InstanceCount);
                _trianglePrimitiveTransforms     = new UnmanagedArray <AffineTransform>(InstanceCount);
                _trianglePrimitivePerSecondDelta = new UnmanagedArray <AffineTransform>(InstanceCount);

                var triangleTransform = AffineTransform.Identity;

                for (var index = 0u; index < InstanceCount; index++)
                {
                    triangleTransform.Translation = Vector3.Create(
                        GetRandomInBoundsSingle(),
                        GetRandomInBoundsSingle(),
                        0.0f
                        );

                    _trianglePrimitiveTransforms[index] = triangleTransform;

                    triangleTransform.Translation = Vector3.Create(
                        GetRandomInBoundsSingle(),
                        GetRandomInBoundsSingle(),
                        0.0f
                        );

                    triangleTransform.Scale = Vector3.One;

                    triangleTransform.Rotation = Quaternion.CreateFromAxisAngle(
                        Vector3.Create(GetRandomInBoundsSingle(), GetRandomInBoundsSingle(), 0.0f),
                        _rng.NextSingle()
                        );

                    _trianglePrimitivePerSecondDelta[index] = triangleTransform;
                }
            }
            copyContext.Close();
            copyContext.Execute();
        }
        copyCommandQueue.ReturnContext(copyContext);

        _uploadBuffer.DisposeAllViews();
    }
        public override void Initialize(Application application)
        {
            ExceptionUtilities.ThrowIfNull(application, nameof(application));

            var windowProvider = application.GetService <WindowProvider>();

            _window = windowProvider.CreateWindow();
            _window.Show();

            var graphicsProvider = application.GetService <GraphicsProvider>();
            var graphicsAdapter  = graphicsProvider.GraphicsAdapters.First();

            _graphicsDevice    = graphicsAdapter.CreateGraphicsDevice(_window, graphicsContextCount: 2);
            _trianglePrimitive = CreateTrianglePrimitive();

            base.Initialize(application);
        }
        public override void Initialize(Application application)
        {
            base.Initialize(application);

            var graphicsDevice = GraphicsDevice;

            using (var vertexStagingBuffer = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.Write, 64 * 1024))
            {
                var currentGraphicsContext = graphicsDevice.CurrentContext;

                currentGraphicsContext.BeginFrame();
                _trianglePrimitive = CreateTrianglePrimitive(currentGraphicsContext, vertexStagingBuffer);
                currentGraphicsContext.EndFrame();

                graphicsDevice.Signal(currentGraphicsContext.Fence);
                graphicsDevice.WaitForIdle();
            }
        }
Beispiel #9
0
        /// <summary>Initializes the GUI for this sample.</summary>
        /// <param name="application">The hosting <see cref="Application" />.</param>
        /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
        /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
        /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
        public override void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
        {
            base.Initialize(application, timeout, windowLocation, windowSize);

            var graphicsDevice         = GraphicsDevice;
            var currentGraphicsContext = graphicsDevice.CurrentContext;

            using var vertexStagingBuffer = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.CpuToGpu, 64 * 1024);

            _vertexBuffer = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Vertex, GraphicsResourceCpuAccess.GpuOnly, 64 * 1024);

            currentGraphicsContext.BeginFrame();
            _trianglePrimitive = CreateTrianglePrimitive(currentGraphicsContext, vertexStagingBuffer);
            currentGraphicsContext.EndFrame();

            graphicsDevice.Signal(currentGraphicsContext.Fence);
            graphicsDevice.WaitForIdle();
        }
Beispiel #10
0
        /// <summary>Initializes the GUI for this sample.</summary>
        /// <param name="application">The hosting <see cref="Application" />.</param>
        /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
        /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
        /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
        public override void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
        {
            base.Initialize(application, timeout, windowLocation, windowSize);

            var graphicsDevice         = GraphicsDevice;
            var currentGraphicsContext = graphicsDevice.CurrentContext;
            var textureSize            = 64 * 1024 * 16 * (_isQuickAndDirty ? 1 : 64);

            using var vertexStagingBuffer  = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.CpuToGpu, 64 * 1024);
            using var indexStagingBuffer   = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.CpuToGpu, 64 * 1024);
            using var textureStagingBuffer = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Default, GraphicsResourceCpuAccess.CpuToGpu, (ulong)textureSize);

            _constantBuffer = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Constant, GraphicsResourceCpuAccess.CpuToGpu, 64 * 1024);
            _indexBuffer    = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Index, GraphicsResourceCpuAccess.GpuOnly, 64 * 1024);
            _vertexBuffer   = graphicsDevice.MemoryAllocator.CreateBuffer(GraphicsBufferKind.Vertex, GraphicsResourceCpuAccess.GpuOnly, 64 * 1024);

            currentGraphicsContext.BeginFrame();
            _quadPrimitive = CreateQuadPrimitive(currentGraphicsContext, vertexStagingBuffer, indexStagingBuffer, textureStagingBuffer);
            currentGraphicsContext.EndFrame();

            graphicsDevice.Signal(currentGraphicsContext.Fence);
            graphicsDevice.WaitForIdle();
        }
Beispiel #11
0
 /// <inheritdoc />
 public override void Draw(GraphicsPrimitive graphicsPrimitive) => Draw((VulkanGraphicsPrimitive)graphicsPrimitive);
Beispiel #12
0
 /// <inheritdoc />
 public override void Draw(GraphicsPrimitive graphicsPrimitive) => Draw((D3D12GraphicsPrimitive)graphicsPrimitive);