Support for small resource placement for MSAA textures.
Enables use of 64KB texture alignments where permitted. This saves heap memory (64KB vs 4MB per allocation) and improves re-use. BUG=dawn:27 Change-Id: Ief4c531446788284e69ec1646cfe2ea7a25c7bb2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14683 Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com>
This commit is contained in:
parent
f58f69f66b
commit
cd1152fb9b
|
@ -108,6 +108,28 @@ namespace dawn_native { namespace d3d12 {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t GetResourcePlacementAlignment(ResourceHeapKind resourceHeapKind,
|
||||||
|
uint32_t sampleCount,
|
||||||
|
uint64_t requestedAlignment) {
|
||||||
|
switch (resourceHeapKind) {
|
||||||
|
// Small resources can take advantage of smaller alignments. For example,
|
||||||
|
// if the most detailed mip can fit under 64KB, 4KB alignments can be used.
|
||||||
|
// Must be non-depth or without render-target to use small resource alignment.
|
||||||
|
// This also applies to MSAA textures (4MB => 64KB).
|
||||||
|
//
|
||||||
|
// Note: Only known to be used for small textures; however, MSDN suggests
|
||||||
|
// it could be extended for more cases. If so, this could default to always
|
||||||
|
// attempt small resource placement.
|
||||||
|
// https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_resource_desc
|
||||||
|
case Default_OnlyNonRenderableOrDepthTextures:
|
||||||
|
return (sampleCount > 1) ? D3D12_SMALL_MSAA_RESOURCE_PLACEMENT_ALIGNMENT
|
||||||
|
: D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT;
|
||||||
|
default:
|
||||||
|
return requestedAlignment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ResourceAllocatorManager::ResourceAllocatorManager(Device* device) : mDevice(device) {
|
ResourceAllocatorManager::ResourceAllocatorManager(Device* device) : mDevice(device) {
|
||||||
|
@ -191,31 +213,21 @@ namespace dawn_native { namespace d3d12 {
|
||||||
D3D12_HEAP_TYPE heapType,
|
D3D12_HEAP_TYPE heapType,
|
||||||
const D3D12_RESOURCE_DESC& requestedResourceDescriptor,
|
const D3D12_RESOURCE_DESC& requestedResourceDescriptor,
|
||||||
D3D12_RESOURCE_STATES initialUsage) {
|
D3D12_RESOURCE_STATES initialUsage) {
|
||||||
const size_t resourceHeapKindIndex =
|
const ResourceHeapKind resourceHeapKind =
|
||||||
GetResourceHeapKind(requestedResourceDescriptor.Dimension, heapType,
|
GetResourceHeapKind(requestedResourceDescriptor.Dimension, heapType,
|
||||||
requestedResourceDescriptor.Flags, mResourceHeapTier);
|
requestedResourceDescriptor.Flags, mResourceHeapTier);
|
||||||
|
|
||||||
// Small resources can take advantage of smaller alignments. For example,
|
|
||||||
// if the most detailed mip can fit under 64KB, 4KB alignments can be used.
|
|
||||||
// Must be non-depth or without render-target to use small resource alignment.
|
|
||||||
//
|
|
||||||
// Note: Only known to be used for small textures; however, MSDN suggests
|
|
||||||
// it could be extended for more cases. If so, this could default to always attempt small
|
|
||||||
// resource placement.
|
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_resource_desc
|
|
||||||
D3D12_RESOURCE_DESC resourceDescriptor = requestedResourceDescriptor;
|
D3D12_RESOURCE_DESC resourceDescriptor = requestedResourceDescriptor;
|
||||||
resourceDescriptor.Alignment =
|
resourceDescriptor.Alignment = GetResourcePlacementAlignment(
|
||||||
(resourceHeapKindIndex == Default_OnlyNonRenderableOrDepthTextures)
|
resourceHeapKind, requestedResourceDescriptor.SampleDesc.Count,
|
||||||
? D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT
|
requestedResourceDescriptor.Alignment);
|
||||||
: requestedResourceDescriptor.Alignment;
|
|
||||||
|
|
||||||
D3D12_RESOURCE_ALLOCATION_INFO resourceInfo =
|
D3D12_RESOURCE_ALLOCATION_INFO resourceInfo =
|
||||||
mDevice->GetD3D12Device()->GetResourceAllocationInfo(0, 1, &resourceDescriptor);
|
mDevice->GetD3D12Device()->GetResourceAllocationInfo(0, 1, &resourceDescriptor);
|
||||||
|
|
||||||
// If the request for small resource alignment was rejected, let D3D tell us what the
|
// If the requested resource alignment was rejected, let D3D tell us what the
|
||||||
// required alignment is for this resource.
|
// required alignment is for this resource.
|
||||||
if (resourceHeapKindIndex == Default_OnlyNonRenderableOrDepthTextures &&
|
if (resourceDescriptor.Alignment != resourceInfo.Alignment) {
|
||||||
resourceInfo.Alignment != D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT) {
|
|
||||||
resourceDescriptor.Alignment = 0;
|
resourceDescriptor.Alignment = 0;
|
||||||
resourceInfo =
|
resourceInfo =
|
||||||
mDevice->GetD3D12Device()->GetResourceAllocationInfo(0, 1, &resourceDescriptor);
|
mDevice->GetD3D12Device()->GetResourceAllocationInfo(0, 1, &resourceDescriptor);
|
||||||
|
@ -225,7 +237,7 @@ namespace dawn_native { namespace d3d12 {
|
||||||
}
|
}
|
||||||
|
|
||||||
BuddyMemoryAllocator* allocator =
|
BuddyMemoryAllocator* allocator =
|
||||||
mSubAllocatedResourceAllocators[resourceHeapKindIndex].get();
|
mSubAllocatedResourceAllocators[static_cast<size_t>(resourceHeapKind)].get();
|
||||||
|
|
||||||
ResourceMemoryAllocation allocation;
|
ResourceMemoryAllocation allocation;
|
||||||
DAWN_TRY_ASSIGN(allocation,
|
DAWN_TRY_ASSIGN(allocation,
|
||||||
|
|
Loading…
Reference in New Issue