D3D12: Remove increment during bindgroup population.

Simplifies descriptor heap allocations by removing increment which is
no longer required by Populate().

BUG=dawn:155

Change-Id: I1d9cd2c607691dc1bcffddd82aa46a10c2bf6fd3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/20048
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:
Bryan Bernhart 2020-04-21 22:07:59 +00:00 committed by Commit Bot service account
parent f204cf2c4f
commit c133cab158
6 changed files with 35 additions and 36 deletions

View File

@ -180,10 +180,10 @@ namespace dawn_native { namespace d3d12 {
}
d3d12Device->CopyDescriptorsSimple(
viewDescriptorCount, viewDescriptorHeapAllocation.GetCPUHandle(0),
mCPUViewAllocation.OffsetFrom(0, 0), D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
viewDescriptorCount, viewDescriptorHeapAllocation.GetBaseCPUDescriptor(),
mCPUViewAllocation.GetBaseDescriptor(), D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
mBaseViewDescriptor = viewDescriptorHeapAllocation.GetGPUHandle(0);
mBaseViewDescriptor = viewDescriptorHeapAllocation.GetBaseGPUDescriptor();
}
const uint32_t samplerDescriptorCount = bgl->GetSamplerDescriptorCount();
@ -197,10 +197,10 @@ namespace dawn_native { namespace d3d12 {
}
d3d12Device->CopyDescriptorsSimple(
samplerDescriptorCount, samplerDescriptorHeapAllocation.GetCPUHandle(0),
mCPUSamplerAllocation.OffsetFrom(0, 0), D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
samplerDescriptorCount, samplerDescriptorHeapAllocation.GetBaseCPUDescriptor(),
mCPUSamplerAllocation.GetBaseDescriptor(), D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
mBaseSamplerDescriptor = samplerDescriptorHeapAllocation.GetGPUHandle(0);
mBaseSamplerDescriptor = samplerDescriptorHeapAllocation.GetBaseGPUDescriptor();
}
// Record both the device and heap serials to determine later if the allocations are still

View File

@ -23,6 +23,11 @@ namespace dawn_native { namespace d3d12 {
: mBaseDescriptor(baseDescriptor), mHeapIndex(heapIndex) {
}
D3D12_CPU_DESCRIPTOR_HANDLE CPUDescriptorHeapAllocation::GetBaseDescriptor() const {
ASSERT(IsValid());
return mBaseDescriptor;
}
D3D12_CPU_DESCRIPTOR_HANDLE CPUDescriptorHeapAllocation::OffsetFrom(
uint32_t sizeIncrementInBytes,
uint32_t offsetInDescriptorCount) const {

View File

@ -27,6 +27,8 @@ namespace dawn_native { namespace d3d12 {
CPUDescriptorHeapAllocation() = default;
CPUDescriptorHeapAllocation(D3D12_CPU_DESCRIPTOR_HANDLE baseDescriptor, uint32_t heapIndex);
D3D12_CPU_DESCRIPTOR_HANDLE GetBaseDescriptor() const;
D3D12_CPU_DESCRIPTOR_HANDLE OffsetFrom(uint32_t sizeIncrementInBytes,
uint32_t offsetInDescriptorCount) const;
uint32_t GetHeapIndex() const;

View File

@ -17,30 +17,21 @@
namespace dawn_native { namespace d3d12 {
DescriptorHeapAllocation::DescriptorHeapAllocation() : mSizeIncrement(0) {
}
DescriptorHeapAllocation::DescriptorHeapAllocation(
uint32_t sizeIncrement,
D3D12_CPU_DESCRIPTOR_HANDLE baseCPUDescriptorHandle,
D3D12_GPU_DESCRIPTOR_HANDLE baseGPUDescriptorHandle)
: mSizeIncrement(sizeIncrement),
mBaseCPUDescriptorHandle(baseCPUDescriptorHandle),
: mBaseCPUDescriptorHandle(baseCPUDescriptorHandle),
mBaseGPUDescriptorHandle(baseGPUDescriptorHandle) {
}
D3D12_CPU_DESCRIPTOR_HANDLE DescriptorHeapAllocation::GetCPUHandle(uint32_t offset) const {
D3D12_GPU_DESCRIPTOR_HANDLE DescriptorHeapAllocation::GetBaseGPUDescriptor() const {
ASSERT(!IsInvalid());
D3D12_CPU_DESCRIPTOR_HANDLE cpuHandle = mBaseCPUDescriptorHandle;
cpuHandle.ptr += mSizeIncrement * offset;
return cpuHandle;
return mBaseGPUDescriptorHandle;
}
D3D12_GPU_DESCRIPTOR_HANDLE DescriptorHeapAllocation::GetGPUHandle(uint32_t offset) const {
D3D12_CPU_DESCRIPTOR_HANDLE DescriptorHeapAllocation::GetBaseCPUDescriptor() const {
ASSERT(!IsInvalid());
D3D12_GPU_DESCRIPTOR_HANDLE gpuHandle = mBaseGPUDescriptorHandle;
gpuHandle.ptr += mSizeIncrement * offset;
return gpuHandle;
return mBaseCPUDescriptorHandle;
}
bool DescriptorHeapAllocation::IsInvalid() const {

View File

@ -21,23 +21,20 @@
namespace dawn_native { namespace d3d12 {
// Wrapper for a handle into a descriptor heap.
// Wrapper for a handle into a GPU-only descriptor heap.
class DescriptorHeapAllocation {
public:
DescriptorHeapAllocation();
DescriptorHeapAllocation(uint32_t sizeIncrement,
D3D12_CPU_DESCRIPTOR_HANDLE baseCPUDescriptorHandle,
DescriptorHeapAllocation() = default;
DescriptorHeapAllocation(D3D12_CPU_DESCRIPTOR_HANDLE baseCPUDescriptorHandle,
D3D12_GPU_DESCRIPTOR_HANDLE baseGPUDescriptorHandle);
~DescriptorHeapAllocation() = default;
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUHandle(uint32_t offset) const;
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUHandle(uint32_t offset) const;
D3D12_GPU_DESCRIPTOR_HANDLE GetBaseGPUDescriptor() const;
D3D12_CPU_DESCRIPTOR_HANDLE GetBaseCPUDescriptor() const;
bool IsInvalid() const;
private:
uint32_t mSizeIncrement;
D3D12_CPU_DESCRIPTOR_HANDLE mBaseCPUDescriptorHandle = {0};
D3D12_GPU_DESCRIPTOR_HANDLE mBaseGPUDescriptorHandle = {0};
};

View File

@ -101,16 +101,20 @@ namespace dawn_native { namespace d3d12 {
ID3D12DescriptorHeap* descriptorHeap = mShaderVisibleBuffers[heapType].heap.Get();
D3D12_CPU_DESCRIPTOR_HANDLE baseCPUDescriptor =
descriptorHeap->GetCPUDescriptorHandleForHeapStart();
baseCPUDescriptor.ptr += mSizeIncrements[heapType] * startOffset;
const uint64_t heapOffset = mSizeIncrements[heapType] * startOffset;
D3D12_GPU_DESCRIPTOR_HANDLE baseGPUDescriptor =
descriptorHeap->GetGPUDescriptorHandleForHeapStart();
baseGPUDescriptor.ptr += mSizeIncrements[heapType] * startOffset;
// Check for 32-bit overflow since CPU heap start handle uses size_t.
const size_t cpuHeapStartPtr = descriptorHeap->GetCPUDescriptorHandleForHeapStart().ptr;
return DescriptorHeapAllocation{mSizeIncrements[heapType], baseCPUDescriptor,
baseGPUDescriptor};
ASSERT(heapOffset <= std::numeric_limits<size_t>::max() - cpuHeapStartPtr);
const D3D12_CPU_DESCRIPTOR_HANDLE baseCPUDescriptor = {cpuHeapStartPtr +
static_cast<size_t>(heapOffset)};
const D3D12_GPU_DESCRIPTOR_HANDLE baseGPUDescriptor = {
descriptorHeap->GetGPUDescriptorHandleForHeapStart().ptr + heapOffset};
return DescriptorHeapAllocation{baseCPUDescriptor, baseGPUDescriptor};
}
std::array<ID3D12DescriptorHeap*, 2> ShaderVisibleDescriptorAllocator::GetShaderVisibleHeaps()