Fix constant buffer allocation with invalid alignment
このコミットが含まれているのは:
1 親
e3c79f4170
コミット
adde64fdeb
3ファイル変更
+44
-15
検索条件に一致するファイルはありません
@@ -21,6 +21,19 @@ internal static class AlignmentHelper
|
||||
return (size + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads the input size so that its pitch is aligned to a multiple of a specified length.
|
||||
/// </summary>
|
||||
/// <param name="size">The input size to pad, if needed.</param>
|
||||
/// <param name="alignment">The target alignment.</param>
|
||||
/// <returns>The padded value relative to the given inputs.</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static nint Pad(nint size, nint alignment)
|
||||
{
|
||||
return (size + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aligns a given offset to a specified boundary, if a given size increment would have crossed it.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.Core.Helpers;
|
||||
using ComputeSharp.Exceptions;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
@@ -72,11 +73,14 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
UnsupportedDoubleOperationsException.Throw<T>();
|
||||
}
|
||||
|
||||
SizeInBytes = checked((nint)(length * elementSizeInBytes));
|
||||
nint usableSizeInBytes = checked((nint)(length * elementSizeInBytes));
|
||||
nint effectiveSizeInBytes = resourceType == ResourceType.Constant ? AlignmentHelper.Pad(usableSizeInBytes, Windows.D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT) : usableSizeInBytes;
|
||||
|
||||
SizeInBytes = usableSizeInBytes;
|
||||
GraphicsDevice = device;
|
||||
Length = length;
|
||||
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)SizeInBytes);
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)effectiveSizeInBytes);
|
||||
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
@@ -85,7 +89,7 @@ public unsafe abstract class Buffer<T> : NativeObject
|
||||
switch (resourceType)
|
||||
{
|
||||
case ResourceType.Constant:
|
||||
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), SizeInBytes, D3D12CpuDescriptorHandle);
|
||||
device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), effectiveSizeInBytes, D3D12CpuDescriptorHandle);
|
||||
break;
|
||||
case ResourceType.ReadOnly:
|
||||
device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする