Added TextureType enum and D3D12Device extensions
このコミットが含まれているのは:
1 親
6534a34efb
コミット
5fdf6d4c5c
2ファイル変更
+110
-3
検索条件に一致するファイルはありません
@@ -0,0 +1,20 @@
|
||||
namespace ComputeSharp.Graphics.Buffers.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see langword="enum"/> that indicates the type of a given HLSL texture.
|
||||
/// </summary>
|
||||
internal enum TextureType
|
||||
{
|
||||
/// <summary>
|
||||
/// A readonly texture, that can store arbitrary arrays of supported values and can only be read from by the GPU.
|
||||
/// This is mapped to a <see langword="TextureND<T>"/> in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
|
||||
/// </summary>
|
||||
ReadOnly,
|
||||
|
||||
/// <summary>
|
||||
/// A read write buffer, that can store arbitrary arrays with both read and write access for the GPU.
|
||||
/// This is mapped to a <see langword="RWSTextureND<T>"/> in <see cref="TerraFX.Interop.D3D12_HEAP_TYPE.D3D12_HEAP_TYPE_DEFAULT"/>.
|
||||
/// </summary>
|
||||
ReadWrite
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_FLAGS;
|
||||
using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE;
|
||||
using static TerraFX.Interop.D3D12_FENCE_FLAGS;
|
||||
using static TerraFX.Interop.D3D12_MEMORY_POOL;
|
||||
using static TerraFX.Interop.D3D12_HEAP_FLAGS;
|
||||
using static TerraFX.Interop.D3D12_HEAP_TYPE;
|
||||
using static TerraFX.Interop.D3D12_RESOURCE_FLAGS;
|
||||
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
|
||||
@@ -88,7 +89,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3d12device.CreateDescriptorHeap(
|
||||
&d3d12DescriptorHeapDesc,
|
||||
FX.__uuidof< ID3D12DescriptorHeap>(),
|
||||
FX.__uuidof<ID3D12DescriptorHeap>(),
|
||||
d3d12DescriptorHeap.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3d12DescriptorHeap.Move();
|
||||
@@ -130,7 +131,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_NONE,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
@@ -140,6 +141,51 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
return d3D12Resource.Move();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a committed resource for a given 2D texture type.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="textureType">The texture type currently in use.</param>
|
||||
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
|
||||
/// <param name="height">The height of the texture resource.</param>
|
||||
/// <param name="width">The width of the texture resource.</param>
|
||||
/// <returns>An <see cref="ID3D12Resource"/> reference for the current texture.</returns>
|
||||
public static ComPtr<ID3D12Resource> CreateCommittedResource(
|
||||
this ref ID3D12Device d3D12Device,
|
||||
TextureType textureType,
|
||||
DXGI_FORMAT dxgiFormat,
|
||||
uint height,
|
||||
uint width)
|
||||
{
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags = textureType switch
|
||||
{
|
||||
TextureType.ReadOnly => D3D12_RESOURCE_FLAG_NONE,
|
||||
TextureType.ReadWrite => D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS,
|
||||
_ => ThrowHelper.ThrowArgumentException<D3D12_RESOURCE_FLAGS>()
|
||||
};
|
||||
|
||||
using ComPtr<ID3D12Resource> d3D12Resource = default;
|
||||
|
||||
D3D12_HEAP_PROPERTIES d3D12HeapProperties;
|
||||
d3D12HeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
d3D12HeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
|
||||
d3D12HeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
|
||||
d3D12HeapProperties.CreationNodeMask = 1;
|
||||
d3D12HeapProperties.VisibleNodeMask = 1;
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Tex2D(dxgiFormat, width, height, flags: d3D12ResourceFlags);
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&d3D12ResourceDescription,
|
||||
D3D12_RESOURCE_STATE_COMMON,
|
||||
null,
|
||||
FX.__uuidof<ID3D12Resource>(),
|
||||
d3D12Resource.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3D12Resource.Move();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a view for a constant buffer.
|
||||
/// </summary>
|
||||
@@ -187,7 +233,28 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a view for a buffer than be both read and written to.
|
||||
/// Creates a view for a readonly texture.
|
||||
/// </summary>
|
||||
/// <param name="d3d12Device">The target <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="d3d12resource">The <see cref="ID3D12Resource"/> to create a view for.</param>
|
||||
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.</param>
|
||||
public static void CreateShaderResourceView(
|
||||
this ref ID3D12Device d3d12Device,
|
||||
ID3D12Resource* d3d12resource,
|
||||
DXGI_FORMAT dxgiFormat,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle)
|
||||
{
|
||||
D3D12_SHADER_RESOURCE_VIEW_DESC d3D12ShaderResourceViewDescription = default;
|
||||
d3D12ShaderResourceViewDescription.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
|
||||
d3D12ShaderResourceViewDescription.Format = dxgiFormat;
|
||||
d3D12ShaderResourceViewDescription.Shader4ComponentMapping = FX.D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
|
||||
d3d12Device.CreateShaderResourceView(d3d12resource, &d3D12ShaderResourceViewDescription, d3D12CpuDescriptorHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a view for a buffer that can be both read and written to.
|
||||
/// </summary>
|
||||
/// <param name="d3d12Device">The target <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="d3d12resource">The <see cref="ID3D12Resource"/> to create a view for.</param>
|
||||
@@ -209,6 +276,26 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
d3d12Device.CreateUnorderedAccessView(d3d12resource, null, &d3D12UnorderedAccessViewDescription, d3D12CpuDescriptorHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a view for a texture that can be both read and written to.
|
||||
/// </summary>
|
||||
/// <param name="d3d12Device">The target <see cref="ID3D12Device"/> instance in use.</param>
|
||||
/// <param name="d3d12resource">The <see cref="ID3D12Resource"/> to create a view for.</param>
|
||||
/// <param name="dxgiFormat">The <see cref="DXGI_FORMAT"/> value to use.</param>
|
||||
/// <param name="d3D12CpuDescriptorHandle">The <see cref="D3D12_CPU_DESCRIPTOR_HANDLE"/> instance for the current resource.</param>
|
||||
public static void CreateUnorderedAccessView(
|
||||
this ref ID3D12Device d3d12Device,
|
||||
ID3D12Resource* d3d12resource,
|
||||
DXGI_FORMAT dxgiFormat,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE d3D12CpuDescriptorHandle)
|
||||
{
|
||||
D3D12_UNORDERED_ACCESS_VIEW_DESC d3D12UnorderedAccessViewDescription = default;
|
||||
d3D12UnorderedAccessViewDescription.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2D;
|
||||
d3D12UnorderedAccessViewDescription.Format = dxgiFormat;
|
||||
|
||||
d3d12Device.CreateUnorderedAccessView(d3d12resource, null, &d3D12UnorderedAccessViewDescription, d3D12CpuDescriptorHandle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ID3D12CommandAllocator"/> for a given device.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする