Skip to content

Commit 64d4f74

Browse files
committed
Merge pull request #81 from Microsoft/develop
merge develop 1/15/16
2 parents 670fc61 + f6d8c9e commit 64d4f74

File tree

69 files changed

+3408
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+3408
-525
lines changed

MiniEngine/Core/pch.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,9 @@
1717
#pragma warning(disable:4328) // nonstandard extension used : class rvalue used as lvalue
1818
#pragma warning(disable:4324) // structure was padded due to __declspec(align())
1919

20-
#include <winapifamily.h> // for WINAPI_FAMILY
21-
#include <wrl.h>
22-
2320
#ifndef WIN32_LEAN_AND_MEAN
2421
#define WIN32_LEAN_AND_MEAN
2522
#endif
26-
#ifndef NOMINMAX
27-
#define NOMINMAX
28-
#endif
2923
#include <windows.h>
3024

3125
#include <d3d12.h>
@@ -51,6 +45,7 @@
5145
#include <exception>
5246

5347
#include <ppltasks.h>
48+
#include <wrl.h>
5449

5550
#include "Utility.h"
5651
#include "VectorMath.h"

Samples/D3D1211On12/src/D3D1211On12.cpp

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void D3D1211on12::LoadPipeline()
8989
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
9090

9191
ThrowIfFailed(m_d3d12Device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue)));
92+
NAME_D3D12_OBJECT(m_commandQueue);
9293

9394
// Describe the swap chain.
9495
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
@@ -180,6 +181,12 @@ void D3D1211on12::LoadPipeline()
180181
ThrowIfFailed(m_swapChain->GetBuffer(n, IID_PPV_ARGS(&m_renderTargets[n])));
181182
m_d3d12Device->CreateRenderTargetView(m_renderTargets[n].Get(), nullptr, rtvHandle);
182183

184+
WCHAR name[25];
185+
if (swprintf_s(name, L"m_renderTargets[%u]", n) > 0)
186+
{
187+
SetName(m_renderTargets[n].Get(), name);
188+
}
189+
183190
// Create a wrapped 11On12 resource of this back buffer. Since we are
184191
// rendering all D3D12 content first and then all D2D content, we specify
185192
// the In resource state as RENDER_TARGET - because D3D12 will have last
@@ -223,6 +230,7 @@ void D3D1211on12::LoadAssets()
223230
ComPtr<ID3DBlob> error;
224231
ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
225232
ThrowIfFailed(m_d3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature)));
233+
NAME_D3D12_OBJECT(m_rootSignature);
226234
}
227235

228236
// Create the pipeline state, which includes compiling and loading shaders.
@@ -264,9 +272,11 @@ void D3D1211on12::LoadAssets()
264272
psoDesc.SampleDesc.Count = 1;
265273

266274
ThrowIfFailed(m_d3d12Device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState)));
275+
NAME_D3D12_OBJECT(m_pipelineState);
267276
}
268277

269278
ThrowIfFailed(m_d3d12Device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocators[m_frameIndex].Get(), m_pipelineState.Get(), IID_PPV_ARGS(&m_commandList)));
279+
NAME_D3D12_OBJECT(m_commandList);
270280

271281
// Create D2D/DWrite objects for rendering text.
272282
{
@@ -319,6 +329,8 @@ void D3D1211on12::LoadAssets()
319329
nullptr,
320330
IID_PPV_ARGS(&vertexBufferUpload)));
321331

332+
NAME_D3D12_OBJECT(m_vertexBuffer);
333+
322334
// Copy data to the intermediate upload heap and then schedule a copy
323335
// from the upload heap to the vertex buffer.
324336
D3D12_SUBRESOURCE_DATA vertexData = {};
@@ -368,53 +380,27 @@ void D3D1211on12::OnUpdate()
368380
// Render the scene.
369381
void D3D1211on12::OnRender()
370382
{
383+
PIXBeginEvent(m_commandQueue.Get(), 0, L"Render 3D");
384+
371385
// Record all the commands we need to render the scene into the command list.
372386
PopulateCommandList();
373387

374388
// Execute the command list.
375389
ID3D12CommandList* ppCommandLists[] = { m_commandList.Get() };
376390
m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
377391

392+
PIXEndEvent(m_commandQueue.Get());
393+
394+
PIXBeginEvent(m_commandQueue.Get(), 0, L"Render UI");
378395
RenderUI();
396+
PIXEndEvent(m_commandQueue.Get());
379397

380398
// Present the frame.
381399
ThrowIfFailed(m_swapChain->Present(1, 0));
382400

383401
MoveToNextFrame();
384402
}
385403

386-
// Render text over D3D12 using D2D via the 11On12 device.
387-
void D3D1211on12::RenderUI()
388-
{
389-
D2D1_SIZE_F rtSize = m_d2dRenderTargets[m_frameIndex]->GetSize();
390-
D2D1_RECT_F textRect = D2D1::RectF(0, 0, rtSize.width, rtSize.height);
391-
static const WCHAR text[] = L"11On12";
392-
393-
// Acquire our wrapped render target resource for the current back buffer.
394-
m_d3d11On12Device->AcquireWrappedResources(m_wrappedBackBuffers[m_frameIndex].GetAddressOf(), 1);
395-
396-
// Render text directly to the back buffer.
397-
m_d2dDeviceContext->SetTarget(m_d2dRenderTargets[m_frameIndex].Get());
398-
m_d2dDeviceContext->BeginDraw();
399-
m_d2dDeviceContext->SetTransform(D2D1::Matrix3x2F::Identity());
400-
m_d2dDeviceContext->DrawTextW(
401-
text,
402-
_countof(text) - 1,
403-
m_textFormat.Get(),
404-
&textRect,
405-
m_textBrush.Get()
406-
);
407-
ThrowIfFailed(m_d2dDeviceContext->EndDraw());
408-
409-
// Release our wrapped render target resource. Releasing
410-
// transitions the back buffer resource to the state specified
411-
// as the OutState when the wrapped resource was created.
412-
m_d3d11On12Device->ReleaseWrappedResources(m_wrappedBackBuffers[m_frameIndex].GetAddressOf(), 1);
413-
414-
// Flush to submit the 11 command list to the shared command queue.
415-
m_d3d11DeviceContext->Flush();
416-
}
417-
418404
void D3D1211on12::OnDestroy()
419405
{
420406
// Ensure that the GPU is no longer referencing resources that are about to be
@@ -461,6 +447,38 @@ void D3D1211on12::PopulateCommandList()
461447
ThrowIfFailed(m_commandList->Close());
462448
}
463449

450+
// Render text over D3D12 using D2D via the 11On12 device.
451+
void D3D1211on12::RenderUI()
452+
{
453+
D2D1_SIZE_F rtSize = m_d2dRenderTargets[m_frameIndex]->GetSize();
454+
D2D1_RECT_F textRect = D2D1::RectF(0, 0, rtSize.width, rtSize.height);
455+
static const WCHAR text[] = L"11On12";
456+
457+
// Acquire our wrapped render target resource for the current back buffer.
458+
m_d3d11On12Device->AcquireWrappedResources(m_wrappedBackBuffers[m_frameIndex].GetAddressOf(), 1);
459+
460+
// Render text directly to the back buffer.
461+
m_d2dDeviceContext->SetTarget(m_d2dRenderTargets[m_frameIndex].Get());
462+
m_d2dDeviceContext->BeginDraw();
463+
m_d2dDeviceContext->SetTransform(D2D1::Matrix3x2F::Identity());
464+
m_d2dDeviceContext->DrawTextW(
465+
text,
466+
_countof(text) - 1,
467+
m_textFormat.Get(),
468+
&textRect,
469+
m_textBrush.Get()
470+
);
471+
ThrowIfFailed(m_d2dDeviceContext->EndDraw());
472+
473+
// Release our wrapped render target resource. Releasing
474+
// transitions the back buffer resource to the state specified
475+
// as the OutState when the wrapped resource was created.
476+
m_d3d11On12Device->ReleaseWrappedResources(m_wrappedBackBuffers[m_frameIndex].GetAddressOf(), 1);
477+
478+
// Flush to submit the 11 command list to the shared command queue.
479+
m_d3d11DeviceContext->Flush();
480+
}
481+
464482
// Wait for pending GPU work to complete.
465483
void D3D1211on12::WaitForGpu()
466484
{

Samples/D3D1211On12/src/DXSampleHelper.h

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ inline void GetAssetsPath(_Out_writes_(pathSize) WCHAR* path, UINT pathSize)
2727
}
2828

2929
DWORD size = GetModuleFileName(nullptr, path, pathSize);
30-
3130
if (size == 0 || size == pathSize)
3231
{
3332
// Method failed or path was truncated.
@@ -37,44 +36,30 @@ inline void GetAssetsPath(_Out_writes_(pathSize) WCHAR* path, UINT pathSize)
3736
WCHAR* lastSlash = wcsrchr(path, L'\\');
3837
if (lastSlash)
3938
{
40-
*(lastSlash+1) = NULL;
39+
*(lastSlash + 1) = L'\0';
4140
}
4241
}
4342

4443
inline HRESULT ReadDataFromFile(LPCWSTR filename, byte** data, UINT* size)
4544
{
4645
using namespace Microsoft::WRL;
4746

48-
CREATEFILE2_EXTENDED_PARAMETERS extendedParams = { 0 };
47+
CREATEFILE2_EXTENDED_PARAMETERS extendedParams = {};
4948
extendedParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
5049
extendedParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
5150
extendedParams.dwFileFlags = FILE_FLAG_SEQUENTIAL_SCAN;
5251
extendedParams.dwSecurityQosFlags = SECURITY_ANONYMOUS;
5352
extendedParams.lpSecurityAttributes = nullptr;
5453
extendedParams.hTemplateFile = nullptr;
5554

56-
Wrappers::FileHandle file(
57-
CreateFile2(
58-
filename,
59-
GENERIC_READ,
60-
FILE_SHARE_READ,
61-
OPEN_EXISTING,
62-
&extendedParams
63-
)
64-
);
65-
55+
Wrappers::FileHandle file(CreateFile2(filename, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, &extendedParams));
6656
if (file.Get() == INVALID_HANDLE_VALUE)
6757
{
6858
throw new std::exception();
6959
}
7060

71-
FILE_STANDARD_INFO fileInfo = { 0 };
72-
if (!GetFileInformationByHandleEx(
73-
file.Get(),
74-
FileStandardInfo,
75-
&fileInfo,
76-
sizeof(fileInfo)
77-
))
61+
FILE_STANDARD_INFO fileInfo = {};
62+
if (!GetFileInformationByHandleEx(file.Get(), FileStandardInfo, &fileInfo, sizeof(fileInfo)))
7863
{
7964
throw new std::exception();
8065
}
@@ -87,16 +72,26 @@ inline HRESULT ReadDataFromFile(LPCWSTR filename, byte** data, UINT* size)
8772
*data = reinterpret_cast<byte*>(malloc(fileInfo.EndOfFile.LowPart));
8873
*size = fileInfo.EndOfFile.LowPart;
8974

90-
if (!ReadFile(
91-
file.Get(),
92-
*data,
93-
fileInfo.EndOfFile.LowPart,
94-
nullptr,
95-
nullptr
96-
))
75+
if (!ReadFile(file.Get(), *data, fileInfo.EndOfFile.LowPart, nullptr, nullptr))
9776
{
9877
throw new std::exception();
9978
}
10079

10180
return S_OK;
10281
}
82+
83+
// Assign a name to the object to aid with debugging.
84+
#if defined(_DEBUG)
85+
inline void SetName(ID3D12Object* pObject, LPCWSTR name)
86+
{
87+
pObject->SetName(name);
88+
}
89+
#else
90+
inline void SetName(ID3D12Object*, LPCWSTR)
91+
{
92+
}
93+
#endif
94+
95+
// Naming helper for ComPtr<T>.
96+
// Assigns the name of the variable as the name of the object.
97+
#define NAME_D3D12_OBJECT(x) SetName(x.Get(), L#x)

Samples/D3D1211On12/src/stdafx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <D3Dcompiler.h>
3030
#include <DirectXMath.h>
3131
#include "d3dx12.h"
32+
#include <pix.h>
3233

3334
#include <string>
3435
#include <wrl.h>

Samples/D3D12Bundles/src/D3D12Bundles.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ void D3D12Bundles::LoadPipeline()
8686
queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
8787

8888
ThrowIfFailed(m_device->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&m_commandQueue)));
89+
NAME_D3D12_OBJECT(m_commandQueue);
8990

9091
// Describe and create the swap chain.
9192
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
@@ -138,6 +139,7 @@ void D3D12Bundles::LoadPipeline()
138139
cbvSrvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
139140
cbvSrvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
140141
ThrowIfFailed(m_device->CreateDescriptorHeap(&cbvSrvHeapDesc, IID_PPV_ARGS(&m_cbvSrvHeap)));
142+
NAME_D3D12_OBJECT(m_cbvSrvHeap);
141143

142144
// Describe and create a sampler descriptor heap.
143145
D3D12_DESCRIPTOR_HEAP_DESC samplerHeapDesc = {};
@@ -183,6 +185,7 @@ void D3D12Bundles::LoadAssets()
183185
ComPtr<ID3DBlob> error;
184186
ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
185187
ThrowIfFailed(m_device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&m_rootSignature)));
188+
NAME_D3D12_OBJECT(m_rootSignature);
186189
}
187190

188191
// Create the pipeline state, which includes loading shaders.
@@ -219,18 +222,22 @@ void D3D12Bundles::LoadAssets()
219222
psoDesc.SampleDesc.Count = 1;
220223

221224
ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState1)));
225+
NAME_D3D12_OBJECT(m_pipelineState1);
222226

223227
// Modify the description to use an alternate pixel shader and create
224228
// a second PSO.
225229
psoDesc.PS = CD3DX12_SHADER_BYTECODE(pPixelShaderData2, pixelShaderDataLength2);
230+
226231
ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&m_pipelineState2)));
232+
NAME_D3D12_OBJECT(m_pipelineState2);
227233

228234
delete pVertexShaderData;
229235
delete pPixelShaderData1;
230236
delete pPixelShaderData2;
231237
}
232238

233239
ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, m_commandAllocator.Get(), nullptr, IID_PPV_ARGS(&m_commandList)));
240+
NAME_D3D12_OBJECT(m_commandList);
234241

235242
// Create render target views (RTVs).
236243
CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart());
@@ -239,6 +246,12 @@ void D3D12Bundles::LoadAssets()
239246
ThrowIfFailed(m_swapChain->GetBuffer(i, IID_PPV_ARGS(&m_renderTargets[i])));
240247
m_device->CreateRenderTargetView(m_renderTargets[i].Get(), nullptr, rtvHandle);
241248
rtvHandle.Offset(1, m_rtvDescriptorSize);
249+
250+
WCHAR name[25];
251+
if (swprintf_s(name, L"m_renderTargets[%u]", i) > 0)
252+
{
253+
SetName(m_renderTargets[i].Get(), name);
254+
}
242255
}
243256

244257
// Read in mesh data for vertex/index buffers.
@@ -264,6 +277,8 @@ void D3D12Bundles::LoadAssets()
264277
nullptr,
265278
IID_PPV_ARGS(&vertexBufferUploadHeap)));
266279

280+
NAME_D3D12_OBJECT(m_vertexBuffer);
281+
267282
// Copy data to the intermediate upload heap and then schedule a copy
268283
// from the upload heap to the vertex buffer.
269284
D3D12_SUBRESOURCE_DATA vertexData = {};
@@ -298,6 +313,8 @@ void D3D12Bundles::LoadAssets()
298313
nullptr,
299314
IID_PPV_ARGS(&indexBufferUploadHeap)));
300315

316+
NAME_D3D12_OBJECT(m_indexBuffer);
317+
301318
// Copy data to the intermediate upload heap and then schedule a copy
302319
// from the upload heap to the index buffer.
303320
D3D12_SUBRESOURCE_DATA indexData = {};
@@ -338,6 +355,8 @@ void D3D12Bundles::LoadAssets()
338355
nullptr,
339356
IID_PPV_ARGS(&m_texture)));
340357

358+
NAME_D3D12_OBJECT(m_texture);
359+
341360
const UINT subresourceCount = textureDesc.DepthOrArraySize * textureDesc.MipLevels;
342361
const UINT64 uploadBufferSize = GetRequiredIntermediateSize(m_texture.Get(), 0, subresourceCount);
343362

@@ -404,6 +423,8 @@ void D3D12Bundles::LoadAssets()
404423
IID_PPV_ARGS(&m_depthStencil)
405424
));
406425

426+
NAME_D3D12_OBJECT(m_depthStencil);
427+
407428
m_device->CreateDepthStencilView(m_depthStencil.Get(), &depthStencilDesc, m_dsvHeap->GetCPUDescriptorHandleForHeapStart());
408429
}
409430

@@ -480,13 +501,17 @@ void D3D12Bundles::OnUpdate()
480501
// Render the scene.
481502
void D3D12Bundles::OnRender()
482503
{
504+
PIXBeginEvent(m_commandQueue.Get(), 0, L"Render");
505+
483506
// Record all the commands we need to render the scene into the command list.
484507
PopulateCommandList(m_pCurrentFrameResource);
485508

486509
// Execute the command list.
487510
ID3D12CommandList* ppCommandLists[] = { m_commandList.Get() };
488511
m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
489512

513+
PIXEndEvent(m_commandQueue.Get());
514+
490515
// Present and update the frame index for the next frame.
491516
ThrowIfFailed(m_swapChain->Present(1, 0));
492517
m_frameIndex = m_swapChain->GetCurrentBackBufferIndex();

0 commit comments

Comments
 (0)