Skip to content

Commit 9a0c279

Browse files
Minor fixes
Cherry-picked from branch "feature/resource-tight-alignment".
1 parent 1509c78 commit 9a0c279

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/D3D12Sample.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ inline UINT64 UpdateSubresources(
438438
UINT* pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
439439

440440
D3D12_RESOURCE_DESC Desc = pDestinationResource->GetDesc();
441+
442+
// Needed because of the D3D Debug Layer error:
443+
// D3D12 ERROR: ID3D12Device::GetCopyableFootprints: D3D12_RESOURCE_DESC::Alignment is invalid. The value is 16. When D3D12_RESOURCE_DESC::Flag bit for D3D12_RESOURCE_FLAG_USE_TIGHT_ALIGNMENT is set, Alignment must be 0. [ STATE_CREATION ERROR #721: CREATERESOURCE_INVALIDALIGNMENT]
444+
Desc.Alignment = 0;
445+
441446
ID3D12Device* pDevice;
442447
pDestinationResource->GetDevice(__uuidof(*pDevice), reinterpret_cast<void**>(&pDevice));
443448
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
@@ -1052,8 +1057,7 @@ static void InitD3D() // initializes direct3d 12
10521057
CHECK_HR( g_Allocator->CreateResource(
10531058
&vertexBufferAllocDesc,
10541059
&vertexBufferResourceDesc, // resource description for a buffer
1055-
D3D12_RESOURCE_STATE_COPY_DEST, // we will start this heap in the copy destination state since we will copy data
1056-
// from the upload heap to this heap
1060+
D3D12_RESOURCE_STATE_COMMON,
10571061
nullptr, // optimized clear value must be null for this type of resource. used for render targets and depth/stencil buffers
10581062
&g_VertexBufferAllocation,
10591063
IID_PPV_ARGS(&vertexBufferPtr)) );
@@ -1165,7 +1169,7 @@ static void InitD3D() // initializes direct3d 12
11651169
CHECK_HR( g_Allocator->CreateResource(
11661170
&indexBufferAllocDesc,
11671171
&indexBufferResourceDesc, // resource description for a buffer
1168-
D3D12_RESOURCE_STATE_COPY_DEST, // start in the copy destination state
1172+
D3D12_RESOURCE_STATE_COMMON,
11691173
nullptr, // optimized clear value must be null for this type of resource
11701174
&g_IndexBufferAllocation,
11711175
IID_PPV_ARGS(&g_IndexBuffer)) );

src/Tests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ static constexpr UINT64 MEGABYTE = 1024 * KILOBYTE;
5151
static constexpr CONFIG_TYPE ConfigType = CONFIG_TYPE_AVERAGE;
5252
static const char* FREE_ORDER_NAMES[] = { "FORWARD", "BACKWARD", "RANDOM", };
5353

54+
// Indexes match enum D3D12_HEAP_TYPE.
55+
static const WCHAR* const HEAP_TYPE_NAMES[] =
56+
{
57+
L"",
58+
L"DEFAULT",
59+
L"UPLOAD",
60+
L"READBACK",
61+
L"CUSTOM",
62+
L"GPU_UPLOAD",
63+
};
64+
5465
static void CurrentTimeToStr(std::string& out)
5566
{
5667
time_t rawTime; time(&rawTime);

0 commit comments

Comments
 (0)