private void CopyUnsafe(GraphicsTextureView destination, GraphicsBufferView source) { var d3d12DestinationTextureCopyLocation = new D3D12_TEXTURE_COPY_LOCATION(destination.Resource.D3D12Resource, Sub: destination.D3D12SubresourceIndex); var d3d12SourceTextureCopyLocation = new D3D12_TEXTURE_COPY_LOCATION(source.Resource.D3D12Resource, in destination.D3D12PlacedSubresourceFootprints[0]); d3d12SourceTextureCopyLocation.PlacedFootprint.Offset = source.ByteOffset; D3D12GraphicsCommandList->CopyTextureRegion(&d3d12DestinationTextureCopyLocation, DstX: 0, DstY: 0, DstZ: 0, &d3d12SourceTextureCopyLocation, pSrcBox: null); }
/// <summary>Copies the contents from a buffer view to a texture view.</summary> /// <param name="destination">The destination texture view.</param> /// <param name="source">The source buffer view.</param> /// <exception cref="ArgumentNullException"><paramref name="destination" /> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException"><paramref name="source" /> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">The size <paramref name="destination" /> is less than the size of <paramref name="source" />.</exception> /// <exception cref="ObjectDisposedException">The copy context has been disposed.</exception> public void Copy(GraphicsTextureView destination, GraphicsBufferView source) { ThrowIfDisposed(); ThrowIfNull(destination); ThrowIfNull(source); ThrowIfNotInInsertBounds(source.ByteLength, destination.ByteLength); CopyUnsafe(destination, source); }
/// <summary>Binds an index buffer view to the context.</summary> /// <param name="indexBufferView">The index buffer view to set.</param> /// <exception cref="ArgumentNullException"><paramref name="indexBufferView" /> is <c>null</c>.</exception> public void BindIndexBufferView(GraphicsBufferView indexBufferView) { ThrowIfNull(indexBufferView); var d3d12IndexBufferView = new D3D12_INDEX_BUFFER_VIEW { BufferLocation = indexBufferView.D3D12GpuVirtualAddress, SizeInBytes = checked ((uint)indexBufferView.ByteLength), Format = indexBufferView.BytesPerElement == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, }; D3D12GraphicsCommandList->IASetIndexBuffer(&d3d12IndexBufferView); }
/// <summary>Binds a vertex buffer view to the context.</summary> /// <param name="vertexBufferView">The vertex buffer view to bind.</param> /// <param name="bindingSlot">The binding slot to which <paramref name="vertexBufferView" /> should be bound.</param> /// <exception cref="ArgumentNullException"><paramref name="vertexBufferView" /> is <c>null</c>.</exception> public void BindVertexBufferView(GraphicsBufferView vertexBufferView, uint bindingSlot = 0) { ThrowIfNull(vertexBufferView); var d3d12VertexBufferView = new D3D12_VERTEX_BUFFER_VIEW { BufferLocation = vertexBufferView.D3D12GpuVirtualAddress, StrideInBytes = vertexBufferView.BytesPerElement, SizeInBytes = checked ((uint)vertexBufferView.ByteLength), }; D3D12GraphicsCommandList->IASetVertexBuffers(bindingSlot, NumViews: 1, &d3d12VertexBufferView); }
/// <summary>Initializes a new instance of the <see cref="GraphicsPrimitive" /> class.</summary> /// <param name="pipeline">The pipeline for which the graphics primitive was created.</param> /// <param name="vertexBufferView">The vertex buffer view for the primitive.</param> /// <param name="indexBufferView">The index buffer view for the primitive or <c>null</c> if none exists.</param> /// <param name="resourceViews">The resource views for the primitive or <c>empty</c> if none exists.</param> public GraphicsPrimitive(GraphicsPipeline pipeline, GraphicsBufferView vertexBufferView, GraphicsBufferView?indexBufferView = null, ReadOnlySpan <GraphicsResourceView> resourceViews = default) : base(pipeline) { _indexBufferView = indexBufferView; _pipelineDescriptorSet = !resourceViews.IsEmpty ? pipeline.CreateDescriptorSet(resourceViews) : null; _vertexBufferView = vertexBufferView; }
private void CopyUnsafe(GraphicsBufferView destination, GraphicsBufferView source) { D3D12GraphicsCommandList->CopyBufferRegion(destination.Resource.D3D12Resource, destination.ByteOffset, source.Resource.D3D12Resource, source.ByteOffset, source.ByteLength); }