Skip to content

Commit 4a15a7c

Browse files
Limit default CBV range by 64Kb in D3D12
1 parent 3f7d118 commit 4a15a7c

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -410,7 +410,10 @@ void BufferD3D12Impl::CreateCBV(D3D12_CPU_DESCRIPTOR_HANDLE CBVDescriptor,
410410
VERIFY((Offset % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) == 0, "Offset (", Offset, ") must be ", D3D12_TEXTURE_DATA_PITCH_ALIGNMENT, "-aligned");
411411
VERIFY(Offset + Size <= m_Desc.Size, "Range is out of bounds");
412412
if (Size == 0)
413-
Size = m_Desc.Size - Offset;
413+
{
414+
// CBV can be at most 65536 bytes (D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16 bytes)
415+
Size = std::min(m_Desc.Size - Offset, Uint64{D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT} * 16u);
416+
}
414417

415418
D3D12_CONSTANT_BUFFER_VIEW_DESC D3D12_CBVDesc;
416419
D3D12_CBVDesc.BufferLocation = m_pd3d12Resource->GetGPUVirtualAddress() + Offset;

Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -411,6 +411,7 @@ const ShaderResourceCacheD3D12::Resource& ShaderResourceCacheD3D12::CopyResource
411411
VERIFY(DstRes.Type == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, "Null CPU descriptor is only allowed for constant buffers");
412412
const auto* pBuffer = DstRes.pObject.ConstPtr<BufferD3D12Impl>();
413413
VERIFY(DstRes.BufferRangeSize < pBuffer->GetDesc().Size, "Null CPU descriptor is only allowed for partial views of constant buffers");
414+
VERIFY(DstRes.BufferRangeSize < D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16, "Constant buffer range must not exceed 64Kb");
414415
pBuffer->CreateCBV(DstDescrHandle, DstRes.BufferBaseOffset, DstRes.BufferRangeSize);
415416
}
416417
}

0 commit comments

Comments
 (0)