internal D3D12GraphicsBuffer(D3D12GraphicsDevice graphicsDevice, GraphicsBufferKind kind, ulong size, ulong stride) : base(graphicsDevice, kind, size, stride) { _d3d12Resource = new ValueLazy <Pointer <ID3D12Resource> >(CreateD3D12Resource); _ = _state.Transition(to: Initialized); }
/// <inheritdoc /> public override D3D12GraphicsBuffer CreateBuffer(GraphicsBufferKind kind, GraphicsResourceCpuAccess cpuAccess, ulong size, ulong alignment = 0, GraphicsMemoryAllocationFlags allocationFlags = GraphicsMemoryAllocationFlags.None) { var index = GetBlockCollectionIndex(cpuAccess, 0); var resourceDesc = D3D12_RESOURCE_DESC.Buffer(size, D3D12_RESOURCE_FLAG_NONE, alignment); var resourceAllocationInfo = Device.D3D12Device->GetResourceAllocationInfo(visibleMask: 0, numResourceDescs: 1, &resourceDesc); ref readonly var blockCollection = ref _blockCollections[index];
internal D3D12GraphicsBuffer(GraphicsBufferKind kind, D3D12GraphicsHeap graphicsHeap, ulong offset, ulong size, ulong stride) : base(kind, graphicsHeap, offset, size, stride) { _d3d12Resource = new ValueLazy <Pointer <ID3D12Resource> >(CreateD3D12Resource); _d3d12ResourceState = new ValueLazy <D3D12_RESOURCE_STATES>(GetD3D12ResourceState); _ = _state.Transition(to: Initialized); }
/// <summary>Initializes a new instance of the <see cref="GraphicsBuffer" /> class.</summary> /// <param name="kind">The buffer kind.</param> /// <param name="graphicsHeap">The graphics heap on which the buffer was created.</param> /// <param name="offset">The offset, in bytes, of the buffer in relation to <paramref name="graphicsHeap" />.</param> /// <param name="size">The size, in bytes, of the buffer.</param> /// <param name="stride">The size, in bytes, of the elements contained by the buffer.</param> /// <exception cref="ArgumentNullException"><paramref name="graphicsHeap" /> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="kind" /> is <see cref="GraphicsBufferKind.Index" /> and <paramref name="stride" /> is not <c>2</c> or <c>4</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="kind" /> is <see cref="GraphicsBufferKind.Staging" /> and <paramref name="graphicsHeap" /> is not <see cref="GraphicsHeapCpuAccess.Write" />.</exception> protected GraphicsBuffer(GraphicsBufferKind kind, GraphicsHeap graphicsHeap, ulong offset, ulong size, ulong stride) : base(graphicsHeap, offset, size) { switch (kind) { case GraphicsBufferKind.Index: { if ((stride != 2) && (stride != 4)) { ThrowArgumentOutOfRangeException(nameof(stride), stride); } break; } case GraphicsBufferKind.Staging: { if (graphicsHeap.CpuAccess != GraphicsHeapCpuAccess.Write) { ThrowArgumentOutOfRangeException(nameof(graphicsHeap), graphicsHeap); } break; } } _stride = stride; _kind = kind; }
public static uint GetVulkanBufferUsageKind(GraphicsBufferKind kind, GraphicsResourceCpuAccess cpuAccess) { var vulkanBufferUsageKind = kind switch { GraphicsBufferKind.Vertex => VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, GraphicsBufferKind.Index => VK_BUFFER_USAGE_INDEX_BUFFER_BIT, GraphicsBufferKind.Constant => VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, _ => default,
internal VulkanGraphicsBuffer(VulkanGraphicsDevice graphicsDevice, GraphicsBufferKind kind, ulong size, ulong stride) : base(graphicsDevice, kind, size, stride) { _vulkanBuffer = new ValueLazy <VkBuffer>(CreateVulkanBuffer); _vulkanDeviceMemory = new ValueLazy <VkDeviceMemory>(CreateVulkanDeviceMemory); _ = _state.Transition(to: Initialized); }
/// <inheritdoc cref="CreateGraphicsBuffer(GraphicsBufferKind, ulong, ulong)" /> public D3D12GraphicsBuffer CreateD3D12GraphicsBuffer(GraphicsBufferKind kind, ulong size, ulong stride) { _state.ThrowIfDisposedOrDisposing(); var offset = _offset; size = (size + D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT - 1) & ~(D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT - 1u); _offset = offset + size; return(new D3D12GraphicsBuffer(kind, this, offset, size, stride)); }
/// <summary>Initializes a new instance of the <see cref="GraphicsBuffer" /> class.</summary> /// <param name="graphicsDevice">The graphics device for which the buffer was created.</param> /// <param name="kind">The buffer kind.</param> /// <param name="size">The size, in bytes, of the buffer.</param> /// <param name="stride">The size, in bytes, of the buffer elements.</param> /// <exception cref="ArgumentNullException"><paramref name="graphicsDevice" /> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="kind" /> is <see cref="GraphicsBufferKind.Index" /> and <paramref name="stride" /> is not <c>2</c> or <c>4</c>.</exception> protected GraphicsBuffer(GraphicsDevice graphicsDevice, GraphicsBufferKind kind, ulong size, ulong stride) { ThrowIfNull(graphicsDevice, nameof(graphicsDevice)); if ((kind == GraphicsBufferKind.Index) && (stride != 2) && (stride != 4)) { ThrowArgumentOutOfRangeException(nameof(stride), stride); } _size = size; _stride = stride; _graphicsDevice = graphicsDevice; _kind = kind; }
/// <inheritdoc cref="CreateGraphicsBuffer(GraphicsBufferKind, ulong, ulong)" /> public VulkanGraphicsBuffer CreateVulkanGraphicsBuffer(GraphicsBufferKind kind, ulong size, ulong stride) { _state.ThrowIfDisposedOrDisposing(); var vulkanGraphicsAdapter = VulkanGraphicsDevice.VulkanGraphicsAdapter; var nonCoherentAtomSize = 64 * 1024ul; var offset = _offset; size = (size + nonCoherentAtomSize - 1) & ~(nonCoherentAtomSize - 1); _offset = offset + size; return(new VulkanGraphicsBuffer(kind, this, offset, size, stride)); }
static uint GetVulkanBufferUsageKind(GraphicsHeapCpuAccess cpuAccess, GraphicsBufferKind kind) { var vulkanBufferUsageKind = cpuAccess switch { GraphicsHeapCpuAccess.Read => VK_BUFFER_USAGE_TRANSFER_DST_BIT, GraphicsHeapCpuAccess.Write => VK_BUFFER_USAGE_TRANSFER_SRC_BIT, _ => VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, }; if (cpuAccess != GraphicsHeapCpuAccess.Read) { vulkanBufferUsageKind |= kind switch { GraphicsBufferKind.Vertex => VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, GraphicsBufferKind.Index => VK_BUFFER_USAGE_INDEX_BUFFER_BIT, GraphicsBufferKind.Constant => VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, _ => default,
/// <inheritdoc /> public override VulkanGraphicsBuffer CreateBuffer(GraphicsBufferKind kind, GraphicsResourceCpuAccess cpuAccess, ulong size, ulong alignment = 0, GraphicsMemoryAllocationFlags allocationFlags = GraphicsMemoryAllocationFlags.None) { var vulkanDevice = Device.VulkanDevice; var bufferCreateInfo = new VkBufferCreateInfo { sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, size = size, usage = GetVulkanBufferUsageKind(kind, cpuAccess) }; VkBuffer vulkanBuffer; ThrowExternalExceptionIfNotSuccess(nameof(vkCreateBuffer), vkCreateBuffer(vulkanDevice, &bufferCreateInfo, pAllocator: null, (ulong *)&vulkanBuffer)); VkMemoryRequirements memoryRequirements; vkGetBufferMemoryRequirements(vulkanDevice, vulkanBuffer, &memoryRequirements); var index = GetBlockCollectionIndex(cpuAccess, memoryRequirements.memoryTypeBits); ref readonly var blockCollection = ref _blockCollections[index];
internal VulkanGraphicsBuffer(GraphicsBufferKind kind, VulkanGraphicsHeap graphicsHeap, ulong offset, ulong size, ulong stride) : base(kind, graphicsHeap, offset, size, stride) { _vulkanBuffer = new ValueLazy <VkBuffer>(CreateVulkanBuffer); _ = _state.Transition(to: Initialized); }
/// <summary>Initializes a new instance of the <see cref="GraphicsBuffer" /> class.</summary> /// <param name="kind">The buffer kind.</param> /// <param name="cpuAccess">The CPU access capabilities of the resource.</param> /// <param name="memoryBlockRegion">The memory block region in which the resource exists.</param> /// <inheritdoc cref="GraphicsResource(GraphicsResourceCpuAccess, in GraphicsMemoryBlockRegion)" /> protected GraphicsBuffer(GraphicsBufferKind kind, GraphicsResourceCpuAccess cpuAccess, in GraphicsMemoryBlockRegion memoryBlockRegion)
private protected VulkanGraphicsBuffer(VulkanGraphicsDevice device, GraphicsBufferKind kind, in GraphicsMemoryRegion <GraphicsMemoryBlock> blockRegion, GraphicsResourceCpuAccess cpuAccess, VkBuffer vulkanBuffer)
/// <inheritdoc /> public override GraphicsBuffer CreateGraphicsBuffer(GraphicsBufferKind kind, ulong size, ulong stride) => CreateD3D12GraphicsBuffer(kind, size, stride);
/// <summary>Initializes a new instance of the <see cref="GraphicsBuffer" /> class.</summary> /// <param name="device">The device for which the buffer was created.</param> /// <param name="kind">The buffer kind.</param> /// <param name="blockRegion">The memory block region in which the resource exists.</param> /// <param name="cpuAccess">The CPU access capabilities of the resource.</param> /// <exception cref="ArgumentNullException"><paramref name="device" /> is <c>null</c></exception> /// <exception cref="ArgumentNullException"><paramref name="blockRegion" />.<see cref="GraphicsMemoryRegion{TCollection}.Collection"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="blockRegion" /> was not created for <paramref name="device" />.</exception> protected GraphicsBuffer(GraphicsDevice device, GraphicsBufferKind kind, in GraphicsMemoryRegion <GraphicsMemoryBlock> blockRegion, GraphicsResourceCpuAccess cpuAccess)
#pragma warning restore IDE0044 internal D3D12GraphicsBuffer(D3D12GraphicsDevice device, GraphicsBufferKind kind, in GraphicsMemoryRegion <GraphicsMemoryBlock> blockRegion, GraphicsResourceCpuAccess cpuAccess)
/// <summary>Creates a new graphics buffer for the device.</summary> /// <param name="kind">The kind of graphics buffer to create.</param> /// <param name="size">The size, in bytes, of the graphics buffer.</param> /// <param name="stride">The size, in bytes, of the graphics buffer elements.</param> /// <returns>A new graphics buffer created for the device.</returns> /// <exception cref="ArgumentOutOfRangeException"><paramref name="kind" /> is unsupported.</exception> /// <exception cref="ObjectDisposedException">The device has been disposed.</exception> public abstract GraphicsBuffer CreateGraphicsBuffer(GraphicsBufferKind kind, ulong size, ulong stride);
internal D3D12GraphicsBuffer(GraphicsBufferKind kind, GraphicsResourceCpuAccess cpuAccess, in GraphicsMemoryBlockRegion memoryBlockRegion)
internal VulkanGraphicsBuffer(GraphicsBufferKind kind, GraphicsResourceCpuAccess cpuAccess, in GraphicsMemoryBlockRegion memoryBlockRegion, VkBuffer vulkanBuffer)