Ejemplo n.º 1
0
        public void Dispose()
        {
            DXDebug.CheckAccess(graphicsHost.Device);

            constantBuffer.Dispose();
            pipelineState.Dispose();
            vertexBuffer.Dispose();
        }
Ejemplo n.º 2
0
        public override Texture <SharpDX.Direct3D12.Resource> CreateTexture(TextureContent data)
        {
            DXDebug.CheckAccess(graphicsHost.Device);

            SharpDX.Direct3D12.Resource texture = null;

            var textureDesc = ResourceDescription.Texture2D(Format.R8G8B8A8_UNorm, data.Width, data.Height);

            texture = graphicsHost.Device.CreateCommittedResource(new HeapProperties(HeapType.Default), HeapFlags.None, textureDesc, ResourceStates.CopyDestination);

            long uploadBufferSize = GetRequiredIntermediateSize(texture, 0, 1);

            // Create the GPU upload buffer.
            var textureUploadHeap = graphicsHost.Device.CreateCommittedResource(new HeapProperties(CpuPageProperty.WriteBack, MemoryPool.L0), HeapFlags.None,
                                                                                ResourceDescription.Texture2D(Format.R8G8B8A8_UNorm, data.Width, data.Height), ResourceStates.GenericRead);

            // Copy data to the intermediate upload heap and then schedule a copy
            // from the upload heap to the Texture2D.
            var handle = GCHandle.Alloc(data.Pixels, GCHandleType.Pinned);
            var ptr    = Marshal.UnsafeAddrOfPinnedArrayElement(data.Pixels, 0);

            textureUploadHeap.WriteToSubresource(0, null, ptr, (sizeof(byte) * 4) * data.Width, data.Pixels.Length);
            handle.Free();

            // TODO: Runtime invalid call error below

            //var commandList = graphicsHost.RequestCommandList();
            //commandList.CopyTextureRegion(new TextureCopyLocation(texture, 0), 0, 0, 0, new TextureCopyLocation(textureUploadHeap, 0), null);
            //commandList.ResourceBarrierTransition(texture, ResourceStates.CopyDestination, ResourceStates.PixelShaderResource);

            //// Describe and create a SRV for the texture.
            //var srvDesc = new ShaderResourceViewDescription
            //{
            //    Shader4ComponentMapping = DXHelper.DefaultComponentMapping(),
            //    Format = textureDesc.Format,
            //    Dimension = ShaderResourceViewDimension.Texture2D,
            //    Texture2D = { MipLevels = 1 },
            //};

            //graphicsHost.Device.CreateShaderResourceView(texture, srvDesc, graphicsHost.SRVHeap.CPUDescriptorHandleForHeapStart);

            //// Command lists are created in the recording state, but there is nothing
            //// to record yet. The main loop expects it to be closed, so close it now.
            //commandList.Close();

            //graphicsHost.CommandQueue.ExecuteCommandList(commandList);

            textureUploadHeap.Dispose();

            return(new Texture <SharpDX.Direct3D12.Resource>(texture, data.Width, data.Height, data.Left, data.Right, data.Top, data.Bottom, data.IsTransparent));
        }
Ejemplo n.º 3
0
        protected override unsafe void BeginDraw(ref Matrix4x4 projection, ushort *pIndex, int indexCount)
        {
            DXDebug.CheckAccess(graphicsHost.Device);

            // Update constant buffer resource.
            constantBufferData.transform = projection;
            SharpDX.Utilities.Write(mappedConstantBuffer, ref constantBufferData);

            // Request a new bundle.
            commandList = graphicsHost.RequestBundle(pipelineState);

            // Record the commands.
            commandList.SetGraphicsRootDescriptorTable(0, graphicsHost.CBVHeap.GPUDescriptorHandleForHeapStart);
            commandList.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleStrip;
        }
Ejemplo n.º 4
0
        protected override unsafe void Draw(Vertex2D *pVertex, int vertexCount, SharpDX.Direct3D12.Resource texture, bool isTransparent)
        {
            DXDebug.CheckAccess(graphicsHost.Device);

            // TODO: texture, isTransparent

            commandList.SetGraphicsRootDescriptorTable(1, graphicsHost.SRVHeap.GPUDescriptorHandleForHeapStart);

            // Update the vertex buffer
            IntPtr dataBegin = vertexBuffer.Map(0);

            SharpDX.Utilities.CopyMemory(dataBegin, new IntPtr(pVertex), vertexCount * Vertex2D.SizeInBytes);
            vertexBuffer.Unmap(0);

            // Record the commands.
            commandList.SetVertexBuffer(0, vertexBufferView);

            // Call draw.
            commandList.DrawInstanced(vertexCount / 4 * 6, 1, 0, 0);
        }