Removed unnecessary types
このコミットが含まれているのは:
1 親
08ed370fd8
コミット
d75e84c618
6ファイル変更
-321
検索条件に一致するファイルはありません
@@ -1,18 +0,0 @@
|
||||
namespace ComputeSharp.Graphics
|
||||
{
|
||||
public struct BufferDescription
|
||||
{
|
||||
public BufferDescription(int sizeInBytes, BufferFlags bufferFlags, GraphicsHeapType heapType)
|
||||
{
|
||||
SizeInBytes = sizeInBytes;
|
||||
Flags = bufferFlags;
|
||||
HeapType = heapType;
|
||||
}
|
||||
|
||||
public int SizeInBytes;
|
||||
|
||||
public BufferFlags Flags;
|
||||
|
||||
public GraphicsHeapType HeapType;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Graphics
|
||||
{
|
||||
[Flags]
|
||||
public enum BufferFlags
|
||||
{
|
||||
None = 0,
|
||||
ConstantBuffer = 1,
|
||||
IndexBuffer = 2,
|
||||
VertexBuffer = 4,
|
||||
RenderTarget = 8,
|
||||
ShaderResource = 16,
|
||||
UnorderedAccess = 32,
|
||||
StructuredBuffer = 64,
|
||||
RawBuffer = 512,
|
||||
ArgumentBuffer = 1024
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers
|
||||
{
|
||||
public partial class Buffer
|
||||
{
|
||||
public static class Constant
|
||||
{
|
||||
public static unsafe Buffer New(GraphicsDevice device, int size, GraphicsHeapType heapType = GraphicsHeapType.Upload)
|
||||
{
|
||||
return Buffer.New(device, size, BufferFlags.ConstantBuffer, heapType);
|
||||
}
|
||||
|
||||
public static unsafe Buffer<T> New<T>(GraphicsDevice device, in T data, GraphicsHeapType heapType = GraphicsHeapType.Upload) where T : unmanaged
|
||||
{
|
||||
return Buffer.New(device, data, BufferFlags.ConstantBuffer, heapType);
|
||||
}
|
||||
|
||||
public static unsafe Buffer<T> New<T>(GraphicsDevice device, Span<T> data, GraphicsHeapType heapType = GraphicsHeapType.Upload) where T : unmanaged
|
||||
{
|
||||
return Buffer.New(device, data, BufferFlags.ConstantBuffer, heapType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers
|
||||
{
|
||||
public partial class Buffer
|
||||
{
|
||||
public static class UnorderedAccess
|
||||
{
|
||||
public static unsafe Buffers.Buffer New(GraphicsDevice device, int size, GraphicsHeapType heapType = GraphicsHeapType.Default)
|
||||
{
|
||||
return Buffers.Buffer.New(device, size, BufferFlags.UnorderedAccess, heapType);
|
||||
}
|
||||
|
||||
public static unsafe Buffer<T> New<T>(GraphicsDevice device, in T data, GraphicsHeapType heapType = GraphicsHeapType.Default) where T : unmanaged
|
||||
{
|
||||
return Buffers.Buffer.New(device, data, BufferFlags.UnorderedAccess, heapType);
|
||||
}
|
||||
|
||||
public static unsafe Buffer<T> New<T>(GraphicsDevice device, Span<T> data, GraphicsHeapType heapType = GraphicsHeapType.Default) where T : unmanaged
|
||||
{
|
||||
return Buffers.Buffer.New(device, data, BufferFlags.UnorderedAccess, heapType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.Graphics.Buffers.Abstract;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using SharpDX.Direct3D12;
|
||||
|
||||
namespace ComputeSharp.Graphics.Buffers
|
||||
{
|
||||
public partial class Buffer : GraphicsResource
|
||||
{
|
||||
protected Buffer(GraphicsDevice device) : base(device)
|
||||
{
|
||||
}
|
||||
|
||||
public BufferDescription Description { get; private set; }
|
||||
|
||||
public int SizeInBytes => Description.SizeInBytes;
|
||||
|
||||
public BufferFlags Flags => Description.Flags;
|
||||
|
||||
public GraphicsHeapType Usage => Description.HeapType;
|
||||
|
||||
public int ElementCount { get; protected set; }
|
||||
|
||||
public T[] GetData<T>() where T : unmanaged
|
||||
{
|
||||
T[] data = new T[SizeInBytes / Unsafe.SizeOf<T>()];
|
||||
GetData(data.AsSpan());
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public unsafe void GetData<T>(ref T data, int offsetInBytes = 0) where T : unmanaged
|
||||
{
|
||||
fixed (T* pointer = &data)
|
||||
{
|
||||
GetData(new Span<T>(pointer, 1), offsetInBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void GetData<T>(Span<T> data, int offsetInBytes = 0) where T : unmanaged
|
||||
{
|
||||
if (Usage == GraphicsHeapType.Default)
|
||||
{
|
||||
using Buffer<T> readbackBaffer = New<T>(GraphicsDevice, data.Length, BufferFlags.None, GraphicsHeapType.Readback);
|
||||
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
|
||||
|
||||
copyCommandList.CopyBufferRegion(this, offsetInBytes, readbackBaffer, 0, data.Length * Unsafe.SizeOf<T>());
|
||||
copyCommandList.Flush(true);
|
||||
|
||||
readbackBaffer.GetData(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Map(0);
|
||||
MemoryHelper.Copy(MappedResource + offsetInBytes, data);
|
||||
Unmap(0);
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe void SetData<T>(in T data, int offsetInBytes = 0) where T : unmanaged
|
||||
{
|
||||
fixed (T* pointer = &data)
|
||||
{
|
||||
SetData(new Span<T>(pointer, 1), offsetInBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetData<T>(Span<T> data, int offsetInBytes = 0) where T : unmanaged
|
||||
{
|
||||
if (Usage == GraphicsHeapType.Default)
|
||||
{
|
||||
using Buffer<T> uploadBuffer = New(GraphicsDevice, data, BufferFlags.None, GraphicsHeapType.Upload);
|
||||
using CommandList copyCommandList = new CommandList(GraphicsDevice, CommandListType.Copy);
|
||||
|
||||
copyCommandList.CopyBufferRegion(uploadBuffer, 0, this, offsetInBytes, data.Length * Unsafe.SizeOf<T>());
|
||||
copyCommandList.Flush(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Map(0);
|
||||
MemoryHelper.Copy(data, MappedResource + offsetInBytes);
|
||||
Unmap(0);
|
||||
}
|
||||
}
|
||||
|
||||
public Buffers.Buffer ToReadback()
|
||||
{
|
||||
BufferDescription description = Description;
|
||||
description.HeapType = GraphicsHeapType.Readback;
|
||||
description.Flags = BufferFlags.None;
|
||||
|
||||
return New(GraphicsDevice, description);
|
||||
}
|
||||
|
||||
public static Buffers.Buffer New(GraphicsDevice device, BufferDescription description)
|
||||
{
|
||||
return new Buffers.Buffer(device).InitializeFrom(description);
|
||||
}
|
||||
|
||||
public static Buffers.Buffer New(GraphicsDevice device, int size, BufferFlags bufferFlags, GraphicsHeapType heapType = GraphicsHeapType.Default)
|
||||
{
|
||||
return New(device, new BufferDescription(size, bufferFlags, heapType));
|
||||
}
|
||||
|
||||
public static Buffer<T> New<T>(GraphicsDevice device, int elementCount, BufferFlags bufferFlags, GraphicsHeapType heapType = GraphicsHeapType.Default) where T : unmanaged
|
||||
{
|
||||
int bufferSize = elementCount * Unsafe.SizeOf<T>();
|
||||
|
||||
return new Buffer<T>(device, bufferSize, bufferFlags, heapType);
|
||||
}
|
||||
|
||||
public static unsafe Buffer<T> New<T>(GraphicsDevice device, in T data, BufferFlags bufferFlags, GraphicsHeapType heapType = GraphicsHeapType.Default) where T : unmanaged
|
||||
{
|
||||
fixed (T* pointer = &data)
|
||||
{
|
||||
return New(device, new Span<T>(pointer, 1), bufferFlags, heapType);
|
||||
}
|
||||
}
|
||||
|
||||
public static Buffer<T> New<T>(GraphicsDevice device, Span<T> data, BufferFlags bufferFlags, GraphicsHeapType heapType = GraphicsHeapType.Default) where T : unmanaged
|
||||
{
|
||||
Buffer<T> buffer = New<T>(device, data.Length, bufferFlags, heapType);
|
||||
buffer.SetData(data);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
protected internal Buffers.Buffer InitializeFrom(BufferDescription description)
|
||||
{
|
||||
ResourceStates resourceStates = ResourceStates.Common;
|
||||
|
||||
if (description.HeapType == GraphicsHeapType.Upload)
|
||||
{
|
||||
resourceStates = ResourceStates.GenericRead;
|
||||
}
|
||||
else if (description.HeapType == GraphicsHeapType.Readback)
|
||||
{
|
||||
resourceStates = ResourceStates.CopyDestination;
|
||||
}
|
||||
|
||||
NativeResource ??= GraphicsDevice.NativeDevice.CreateCommittedResource(
|
||||
new HeapProperties((HeapType)description.HeapType), HeapFlags.None,
|
||||
ConvertToNativeDescription(description), resourceStates);
|
||||
|
||||
Description = description;
|
||||
|
||||
(NativeCpuDescriptorHandle, NativeGpuDescriptorHandle) = description.Flags switch
|
||||
{
|
||||
BufferFlags.ConstantBuffer => CreateConstantBufferView(),
|
||||
BufferFlags.ShaderResource => CreateShaderResourceView(),
|
||||
BufferFlags.UnorderedAccess => CreateUnorderedAccessView(),
|
||||
_ => default
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private static ResourceDescription ConvertToNativeDescription(BufferDescription description)
|
||||
{
|
||||
int size = description.SizeInBytes;
|
||||
ResourceFlags flags = ResourceFlags.None;
|
||||
|
||||
if (description.Flags.HasFlag(BufferFlags.UnorderedAccess))
|
||||
{
|
||||
flags |= ResourceFlags.AllowUnorderedAccess;
|
||||
//flags |= ResourceFlags.AllowSimultaneousAccess;
|
||||
}
|
||||
|
||||
return ResourceDescription.Buffer(size, flags);
|
||||
}
|
||||
|
||||
private (CpuDescriptorHandle, GpuDescriptorHandle) CreateConstantBufferView()
|
||||
{
|
||||
(CpuDescriptorHandle cpuHandle, GpuDescriptorHandle gpuHandle) = GraphicsDevice.ShaderResourceViewAllocator.Allocate(1);
|
||||
|
||||
int constantBufferSize = (SizeInBytes + 255) & ~255;
|
||||
|
||||
ConstantBufferViewDescription cbvDescription = new ConstantBufferViewDescription
|
||||
{
|
||||
BufferLocation = NativeResource.GPUVirtualAddress,
|
||||
SizeInBytes = constantBufferSize
|
||||
};
|
||||
|
||||
GraphicsDevice.NativeDevice.CreateConstantBufferView(cbvDescription, cpuHandle);
|
||||
|
||||
return (cpuHandle, gpuHandle);
|
||||
}
|
||||
|
||||
private (CpuDescriptorHandle, GpuDescriptorHandle) CreateShaderResourceView()
|
||||
{
|
||||
(CpuDescriptorHandle cpuHandle, GpuDescriptorHandle gpuHandle) = GraphicsDevice.ShaderResourceViewAllocator.Allocate(1);
|
||||
GraphicsDevice.NativeDevice.CreateShaderResourceView(NativeResource, null, cpuHandle);
|
||||
|
||||
return (cpuHandle, gpuHandle);
|
||||
}
|
||||
|
||||
private (CpuDescriptorHandle, GpuDescriptorHandle) CreateUnorderedAccessView()
|
||||
{
|
||||
(CpuDescriptorHandle cpuHandle, GpuDescriptorHandle gpuHandle) = GraphicsDevice.ShaderResourceViewAllocator.Allocate(1);
|
||||
|
||||
var description = new UnorderedAccessViewDescription
|
||||
{
|
||||
Format = SharpDX.DXGI.Format.R32_Float,
|
||||
Dimension = UnorderedAccessViewDimension.Buffer,
|
||||
Buffer =
|
||||
{
|
||||
ElementCount = ElementCount,
|
||||
}
|
||||
};
|
||||
|
||||
GraphicsDevice.NativeDevice.CreateUnorderedAccessView(NativeResource, null, description, cpuHandle);
|
||||
|
||||
return (cpuHandle, gpuHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public class Buffer<T> : Buffers.Buffer where T : unmanaged
|
||||
{
|
||||
protected internal Buffer(GraphicsDevice device, int size, BufferFlags bufferFlags, GraphicsHeapType heapType = GraphicsHeapType.Default) : base(device)
|
||||
{
|
||||
ElementSize = Unsafe.SizeOf<T>();
|
||||
ElementCount = size / ElementSize;
|
||||
|
||||
InitializeFrom(new BufferDescription(size, bufferFlags, heapType));
|
||||
}
|
||||
|
||||
public int ElementSize { get; }
|
||||
|
||||
public T[] GetData() => GetData<T>();
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@
|
||||
using System.Linq;
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.Graphics.Buffers;
|
||||
using ComputeSharp.Shaders;
|
||||
using Buffer = ComputeSharp.Graphics.Buffers.Buffer;
|
||||
|
||||
namespace DirectX12ComputeShaderSample
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする