Skip to content

Commit 9f43bf4

Browse files
committed
Merge pull request #45 from Microsoft/develop
merge develop into master for 10/30 release
2 parents 5b45a22 + c30e1a5 commit 9f43bf4

File tree

64 files changed

+6927
-55
lines changed

Some content is hidden

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

64 files changed

+6927
-55
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# DirectX-Graphics-Samples
2-
This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications for Windows 10.
2+
This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications for Windows 10. We also have a YouTube channel! Visit us here: https://www.youtube.com/MicrosoftDirectX12andGraphicsEducation
33

44
## API Samples
55
In the Samples directory, you will find samples that attempt to break off specific features and specific usage scenarios into bite sized chunks. For example, the ExecuteIndirect sample will show you just enough about execute indirect to get started with that feature without diving too deep into multiengine whereas the nBodyGravity sample will delve into multiengine without touching on the execute indirect feature etc. By doing this, we hope to make it easier to get started with DirectX 12.
@@ -33,4 +33,5 @@ It came from a desire to quickly dive into graphics and performance experiments.
3333
## Contributing
3434
We're always looking for your help to fix bugs and improve the samples. File those pull requests and we'll be happy to take a look.
3535

36-
Find more information on DirectX 12 on our blog: http://blogs.msdn.com/b/directx/
36+
Find more information on DirectX 12 on our blog: http://blogs.msdn.com/b/directx/
37+

Samples/D3D1211On12/src/D3D1211On12.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ void D3D1211on12::LoadAssets()
285285
ThrowIfFailed(m_textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER));
286286
}
287287

288+
// Note: ComPtr's are CPU objects but this resource needs to stay in scope until
289+
// the command list that references it has finished executing on the GPU.
290+
// We will flush the GPU at the end of this method to ensure the resource is not
291+
// prematurely destroyed.
288292
ComPtr<ID3D12Resource> vertexBufferUpload;
289293

290294
// Create the vertex buffer.
@@ -413,7 +417,8 @@ void D3D1211on12::RenderUI()
413417

414418
void D3D1211on12::OnDestroy()
415419
{
416-
// Wait for the GPU to be done with all resources.
420+
// Ensure that the GPU is no longer referencing resources that are about to be
421+
// cleaned up by the destructor.
417422
WaitForGpu();
418423

419424
CloseHandle(m_fenceEvent);

Samples/D3D1211On12/src/D3D1211On12.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
#include "DXSample.h"
1515

1616
using namespace DirectX;
17-
using namespace Microsoft::WRL;
17+
18+
// Note that while ComPtr is used to manage the lifetime of resources on the CPU,
19+
// it has no understanding of the lifetime of resources on the GPU. Apps must account
20+
// for the GPU lifetime of resources to avoid destroying objects that may still be
21+
// referenced by the GPU.
22+
// An example of this can be found in the class method: OnDestroy().
23+
using Microsoft::WRL::ComPtr;
1824

1925
class D3D1211on12 : public DXSample
2026
{

Samples/D3D12Bundles/src/D3D12Bundles.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ void D3D12Bundles::LoadPipeline()
156156
// Load the sample assets.
157157
void D3D12Bundles::LoadAssets()
158158
{
159-
// These upload heaps are only needed during loading.
159+
// Note: ComPtr's are CPU objects but these resources need to stay in scope until
160+
// the command list that references them has finished executing on the GPU.
161+
// We will flush the GPU at the end of this method to ensure the resources are not
162+
// prematurely destroyed.
160163
ComPtr<ID3D12Resource> vertexBufferUploadHeap;
161164
ComPtr<ID3D12Resource> indexBufferUploadHeap;
162165
ComPtr<ID3D12Resource> textureUploadHeap;
@@ -496,7 +499,8 @@ void D3D12Bundles::OnRender()
496499

497500
void D3D12Bundles::OnDestroy()
498501
{
499-
// Wait for the GPU to be done with all resources.
502+
// Ensure that the GPU is no longer referencing resources that are about to be
503+
// cleaned up by the destructor.
500504
{
501505
const UINT64 fence = m_fenceValue;
502506
const UINT64 lastCompletedFence = m_fence->GetCompletedValue();

Samples/D3D12Bundles/src/D3D12Bundles.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
#include "SimpleCamera.h"
1818

1919
using namespace DirectX;
20-
using namespace std;
21-
using namespace Microsoft::WRL;
20+
21+
// Note that while ComPtr is used to manage the lifetime of resources on the CPU,
22+
// it has no understanding of the lifetime of resources on the GPU. Apps must account
23+
// for the GPU lifetime of resources to avoid destroying objects that may still be
24+
// referenced by the GPU.
25+
// An example of this can be found in the class method: OnDestroy().
26+
using Microsoft::WRL::ComPtr;
2227

2328
class D3D12Bundles : public DXSample
2429
{
@@ -69,7 +74,7 @@ class D3D12Bundles : public DXSample
6974
SimpleCamera m_camera;
7075

7176
// Frame resources.
72-
vector<FrameResource*> m_frameResources;
77+
std::vector<FrameResource*> m_frameResources;
7378
FrameResource* m_pCurrentFrameResource;
7479
UINT m_currentFrameResourceIndex;
7580

Samples/D3D12Bundles/src/FrameResource.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
#include "DXSampleHelper.h"
1515

1616
using namespace DirectX;
17-
using namespace std;
18-
using namespace Microsoft::WRL;
17+
using Microsoft::WRL::ComPtr;
1918

2019
class FrameResource
2120
{
@@ -36,7 +35,7 @@ class FrameResource
3635
ConstantBuffer* m_pConstantBuffers;
3736
UINT64 m_fenceValue;
3837

39-
vector<XMFLOAT4X4> m_modelMatrices;
38+
std::vector<XMFLOAT4X4> m_modelMatrices;
4039
UINT m_cityRowCount;
4140
UINT m_cityColumnCount;
4241

Samples/D3D12DynamicIndexing/src/D3D12DynamicIndexing.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ void D3D12DynamicIndexing::LoadPipeline()
160160
// Load the sample assets.
161161
void D3D12DynamicIndexing::LoadAssets()
162162
{
163-
// These upload heaps are only needed during loading.
163+
// Note: ComPtr's are CPU objects but these resources need to stay in scope until
164+
// the command list that references them has finished executing on the GPU.
165+
// We will flush the GPU at the end of this method to ensure the resources are not
166+
// prematurely destroyed.
164167
ComPtr<ID3D12Resource> vertexBufferUploadHeap;
165168
ComPtr<ID3D12Resource> indexBufferUploadHeap;
166169
ComPtr<ID3D12Resource> textureUploadHeap;
@@ -330,7 +333,7 @@ void D3D12DynamicIndexing::LoadAssets()
330333
float materialGradStep = (1.0f / static_cast<float>(CityMaterialCount));
331334

332335
// Generate texture data.
333-
vector<vector<unsigned char>> cityTextureData;
336+
std::vector<std::vector<unsigned char>> cityTextureData;
334337
cityTextureData.resize(CityMaterialCount);
335338
for (int i = 0; i < CityMaterialCount; ++i)
336339
{
@@ -594,7 +597,8 @@ void D3D12DynamicIndexing::OnRender()
594597

595598
void D3D12DynamicIndexing::OnDestroy()
596599
{
597-
// Wait for the GPU to be done with all resources.
600+
// Ensure that the GPU is no longer referencing resources that are about to be
601+
// cleaned up by the destructor.
598602
{
599603
const UINT64 fence = m_fenceValue;
600604
const UINT64 lastCompletedFence = m_fence->GetCompletedValue();

Samples/D3D12DynamicIndexing/src/D3D12DynamicIndexing.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@
1717
#include "SimpleCamera.h"
1818

1919
using namespace DirectX;
20-
using namespace std;
21-
using namespace Microsoft::WRL;
20+
21+
// Note that while ComPtr is used to manage the lifetime of resources on the CPU,
22+
// it has no understanding of the lifetime of resources on the GPU. Apps must account
23+
// for the GPU lifetime of resources to avoid destroying objects that may still be
24+
// referenced by the GPU.
25+
// An example of this can be found in the class method: OnDestroy().
26+
using Microsoft::WRL::ComPtr;
2227

2328
class D3D12DynamicIndexing : public DXSample
2429
{
@@ -74,7 +79,7 @@ class D3D12DynamicIndexing : public DXSample
7479
SimpleCamera m_camera;
7580

7681
// Frame resources.
77-
vector<FrameResource*> m_frameResources;
82+
std::vector<FrameResource*> m_frameResources;
7883
FrameResource* m_pCurrentFrameResource;
7984
UINT m_currentFrameResourceIndex;
8085

Samples/D3D12DynamicIndexing/src/FrameResource.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
#include "DXSampleHelper.h"
1515

1616
using namespace DirectX;
17-
using namespace std;
18-
using namespace Microsoft::WRL;
17+
using Microsoft::WRL::ComPtr;
1918

2019
class FrameResource
2120
{
@@ -36,7 +35,7 @@ class FrameResource
3635
ConstantBuffer* m_pConstantBuffers;
3736
UINT64 m_fenceValue;
3837

39-
vector<XMFLOAT4X4> m_modelMatrices;
38+
std::vector<XMFLOAT4X4> m_modelMatrices;
4039
UINT m_cityRowCount;
4140
UINT m_cityColumnCount;
4241
UINT m_cityMaterialCount;

Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ void D3D12ExecuteIndirect::LoadAssets()
266266
ThrowIfFailed(m_device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, m_computeCommandAllocators[m_frameIndex].Get(), m_computeState.Get(), IID_PPV_ARGS(&m_computeCommandList)));
267267
ThrowIfFailed(m_computeCommandList->Close());
268268

269+
// Note: ComPtr's are CPU objects but these resources need to stay in scope until
270+
// the command list that references them has finished executing on the GPU.
271+
// We will flush the GPU at the end of this method to ensure the resources are not
272+
// prematurely destroyed.
269273
ComPtr<ID3D12Resource> vertexBufferUpload;
270274
ComPtr<ID3D12Resource> commandBufferUpload;
271275

@@ -603,7 +607,8 @@ void D3D12ExecuteIndirect::OnRender()
603607

604608
void D3D12ExecuteIndirect::OnDestroy()
605609
{
606-
// Wait for the GPU to be done with all resources.
610+
// Ensure that the GPU is no longer referencing resources that are about to be
611+
// cleaned up by the destructor.
607612
WaitForGpu();
608613

609614
CloseHandle(m_fenceEvent);

0 commit comments

Comments
 (0)