Skip to content

Commit

Permalink
Merge pull request #669 from microsoft/master
Browse files Browse the repository at this point in the history
Bring bug fixes and readme updates to the develop branch
  • Loading branch information
sebmerry authored Nov 6, 2020
2 parents 73271c9 + 69c728e commit ab453c0
Show file tree
Hide file tree
Showing 54 changed files with 1,103 additions and 323 deletions.
47 changes: 14 additions & 33 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
# This .gitignore file is manually maintained
################################################################################

/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingMiniEngineSample/dxcompiler.dll
/Libraries/D3D12RaytracingFallback/src/FallbackLayerUnitTests/x64/
/Packages
/Samples/Desktop/D3D12Raytracing/src/.vs/D3D12Raytracing/v16
/Samples/Desktop/D3D12xGPU/src/D3D12xGPU.vcxproj.user
/.vs/VSWorkspaceState.json
/.vs/slnx.sqlite
/.vs/ProjectSettings.json
/.vs/DirectX-Graphics-Samples/v16/Browse.VC.db
/.vs/DirectX-Graphics-Samples/v16/.suo
/.vs/DirectX-Graphics-Samples/v16
/.vs
/MiniEngine/ModelViewer/.vs/ModelViewer_VS16/v16/Browse.VC.opendb
/MiniEngine/Build_VS16/x64/Release/Intermediate
/MiniEngine/Build_VS16/x64/Release/Output
/MiniEngine/Build_VS16/x64
/Samples/Desktop/D3D12Raytracing/Build_VS16/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/obj/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/D3D12RaytracingHelloWorld.vcxproj.user
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingHelloWorld/bin/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingLibrarySubobjects/obj/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingLibrarySubobjects/D3D12RaytracingLibrarySubobjects.vcxproj.user
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingLibrarySubobjects/bin/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingMiniEngineSample/ModelViewer_VS16.vcxproj.user
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingProceduralGeometry/obj/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingProceduralGeometry/D3D12RaytracingProceduralGeometry.vcxproj.user
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingProceduralGeometry/bin/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/Profile.csv
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/obj/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/D3D12RaytracingRealTimeDenoisedAmbientOcclusion.vcxproj.user
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingRealTimeDenoisedAmbientOcclusion/bin/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingSimpleLighting/obj/x64
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingSimpleLighting/D3D12RaytracingSimpleLighting.vcxproj.user
/Samples/Desktop/D3D12Raytracing/src/D3D12RaytracingSimpleLighting/bin/x64
/Samples/Desktop/D3D12Raytracing/src/.vs/D3D12Raytracing/v15

**/bin/x64
**/obj/x64
**/src/packages
**/src/bin
**/src/obj
**/.vs

*.hlsl.h
**/Build_VS16

*.vcxproj.user
*.opendb
157 changes: 152 additions & 5 deletions Libraries/D3DX12/d3dx12.h
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,29 @@ inline void MemcpySubresource(
}
}

//------------------------------------------------------------------------------------------------
// Row-by-row memcpy
inline void MemcpySubresource(
_In_ const D3D12_MEMCPY_DEST* pDest,
_In_ const void* pResourceData,
_In_ const D3D12_SUBRESOURCE_INFO* pSrc,
SIZE_T RowSizeInBytes,
UINT NumRows,
UINT NumSlices) noexcept
{
for (UINT z = 0; z < NumSlices; ++z)
{
auto pDestSlice = static_cast<BYTE*>(pDest->pData) + pDest->SlicePitch * z;
auto pSrcSlice = (static_cast<const BYTE*>(pResourceData) + pSrc->Offset) + pSrc->DepthPitch * LONG_PTR(z);
for (UINT y = 0; y < NumRows; ++y)
{
memcpy(pDestSlice + pDest->RowPitch * y,
pSrcSlice + pSrc->RowPitch * LONG_PTR(y),
RowSizeInBytes);
}
}
}

//------------------------------------------------------------------------------------------------
// Returns required size of a buffer to be used for data upload
inline UINT64 GetRequiredIntermediateSize(
Expand Down Expand Up @@ -2076,6 +2099,65 @@ inline UINT64 UpdateSubresources(
return RequiredSize;
}

//------------------------------------------------------------------------------------------------
// All arrays must be populated (e.g. by calling GetCopyableFootprints)
inline UINT64 UpdateSubresources(
_In_ ID3D12GraphicsCommandList* pCmdList,
_In_ ID3D12Resource* pDestinationResource,
_In_ ID3D12Resource* pIntermediate,
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
UINT64 RequiredSize,
_In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts,
_In_reads_(NumSubresources) const UINT* pNumRows,
_In_reads_(NumSubresources) const UINT64* pRowSizesInBytes,
_In_ const void* pResourceData,
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
{
// Minor validation
auto IntermediateDesc = pIntermediate->GetDesc();
auto DestinationDesc = pDestinationResource->GetDesc();
if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER ||
IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
RequiredSize > SIZE_T(-1) ||
(DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER &&
(FirstSubresource != 0 || NumSubresources != 1)))
{
return 0;
}

BYTE* pData;
HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast<void**>(&pData));
if (FAILED(hr))
{
return 0;
}

for (UINT i = 0; i < NumSubresources; ++i)
{
if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0;
D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i]) };
MemcpySubresource(&DestData, pResourceData, &pSrcData[i], static_cast<SIZE_T>(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth);
}
pIntermediate->Unmap(0, nullptr);

if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
{
pCmdList->CopyBufferRegion(
pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
}
else
{
for (UINT i = 0; i < NumSubresources; ++i)
{
CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource);
CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]);
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr);
}
}
return RequiredSize;
}

//------------------------------------------------------------------------------------------------
// Heap-allocating UpdateSubresources implementation
inline UINT64 UpdateSubresources(
Expand All @@ -2088,7 +2170,7 @@ inline UINT64 UpdateSubresources(
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
{
UINT64 RequiredSize = 0;
UINT64 MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
if (MemToAlloc > SIZE_MAX)
{
return 0;
Expand All @@ -2099,8 +2181,8 @@ inline UINT64 UpdateSubresources(
return 0;
}
auto pLayouts = static_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
UINT64* pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
UINT* pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);
auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);

auto Desc = pDestinationResource->GetDesc();
ID3D12Device* pDevice = nullptr;
Expand All @@ -2113,6 +2195,44 @@ inline UINT64 UpdateSubresources(
return Result;
}

//------------------------------------------------------------------------------------------------
// Heap-allocating UpdateSubresources implementation
inline UINT64 UpdateSubresources(
_In_ ID3D12GraphicsCommandList* pCmdList,
_In_ ID3D12Resource* pDestinationResource,
_In_ ID3D12Resource* pIntermediate,
UINT64 IntermediateOffset,
_In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource,
_In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources,
_In_ const void* pResourceData,
_In_reads_(NumSubresources) D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
{
UINT64 RequiredSize = 0;
auto MemToAlloc = static_cast<UINT64>(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources;
if (MemToAlloc > SIZE_MAX)
{
return 0;
}
void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast<SIZE_T>(MemToAlloc));
if (pMem == nullptr)
{
return 0;
}
auto pLayouts = reinterpret_cast<D3D12_PLACED_SUBRESOURCE_FOOTPRINT*>(pMem);
auto pRowSizesInBytes = reinterpret_cast<UINT64*>(pLayouts + NumSubresources);
auto pNumRows = reinterpret_cast<UINT*>(pRowSizesInBytes + NumSubresources);

auto Desc = pDestinationResource->GetDesc();
ID3D12Device* pDevice = nullptr;
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
pDevice->Release();

UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pResourceData, pSrcData);
HeapFree(GetProcessHeap(), 0, pMem);
return Result;
}

//------------------------------------------------------------------------------------------------
// Stack-allocating UpdateSubresources implementation
template <UINT MaxSubresources>
Expand All @@ -2121,8 +2241,8 @@ inline UINT64 UpdateSubresources(
_In_ ID3D12Resource* pDestinationResource,
_In_ ID3D12Resource* pIntermediate,
UINT64 IntermediateOffset,
_In_range_(0, MaxSubresources) UINT FirstSubresource,
_In_range_(1, MaxSubresources - FirstSubresource) UINT NumSubresources,
_In_range_(0,MaxSubresources) UINT FirstSubresource,
_In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources,
_In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept
{
UINT64 RequiredSize = 0;
Expand All @@ -2139,6 +2259,33 @@ inline UINT64 UpdateSubresources(
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
}

//------------------------------------------------------------------------------------------------
// Stack-allocating UpdateSubresources implementation
template <UINT MaxSubresources>
inline UINT64 UpdateSubresources(
_In_ ID3D12GraphicsCommandList* pCmdList,
_In_ ID3D12Resource* pDestinationResource,
_In_ ID3D12Resource* pIntermediate,
UINT64 IntermediateOffset,
_In_range_(0,MaxSubresources) UINT FirstSubresource,
_In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources,
_In_ const void* pResourceData,
_In_reads_(NumSubresources) D3D12_SUBRESOURCE_INFO* pSrcData) noexcept
{
UINT64 RequiredSize = 0;
D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources];
UINT NumRows[MaxSubresources];
UINT64 RowSizesInBytes[MaxSubresources];

auto Desc = pDestinationResource->GetDesc();
ID3D12Device* pDevice = nullptr;
pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast<void**>(&pDevice));
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
pDevice->Release();

return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pResourceData, pSrcData);
}

//------------------------------------------------------------------------------------------------
inline constexpr bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout ) noexcept
{ return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; }
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ It came from a desire to quickly dive into graphics and performance experiments.
## Requirements
### Master branch
This branch is intended for the latest [released](https://docs.microsoft.com/en-us/windows/release-information/) Windows 10 version.
* Windows 10 version 2004
* Windows 10 version 20H2
* [Visual Studio 2019](https://www.visualstudio.com/) with the [Windows 10 SDK version 2004(19041)](https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk)
### Develop branch
This branch is intented for features available in the latest Windows Insider Preview
* [Windows 10 Insider Preview builds](https://insider.windows.com/en-us/how-to-pc/#install-windows-10-insider-preview) ([Fast ring](https://insider.windows.com/en-us/how-to-pc/#working-with-rings))
* [Windows 10 Insider Preview builds](https://docs.microsoft.com/en-us/windows-insider/developers/get-started) ([Dev Channel](https://docs.microsoft.com/en-us/windows-insider/flighting))
* [Visual Studio 2019](https://www.visualstudio.com/) with the [Windows 10 Insider Preview SDK](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewSDK)

## Contributing
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.

Find more information on DirectX 12 on our blog: http://blogs.msdn.com/b/directx/
Find more information on DirectX 12 on our blog: https://devblogs.microsoft.com/directx/

Troubleshooting information for this repository can be found in the site [Wiki](https://github.com/Microsoft/DirectX-Graphics-Samples/wiki).

Expand Down
19 changes: 17 additions & 2 deletions Samples/Desktop/D3D1211On12/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
# 11 on 12 Sample
---
page_type: sample
languages:
- cpp
products:
- windows-api-win32
name: Direct3D 12 11-on-12 sample
urlFragment: d3d12-11-on-12-sample-win32
description: Demonstrates how to use Direct3D 11-based rendering in combination with Direct3D 12.
extendedZipContent:
- path: LICENSE
target: LICENSE
---

# Direct3D 12 11-on-12 sample

![11On12 GUI](src/D3D1211On12.png)

This sample demonstrates how to use Direct3D 11 based rendering in combination with Direct3D 12 by sharing devices, command queues and resources between the 2 API versions. The sample illustrates this by using Direct2D to render a UI over Direct3D 12 content. This ability to share resources between runtimes makes porting apps/engines to 12 simpler as entire 11-based components, such as a UI system, can remain virtually untouched.
This sample demonstrates how to use Direct3D 11 based rendering in combination with Direct3D 12 by sharing devices, command queues and resources between the 2 API versions. The sample illustrates this by using Direct2D to render a UI over Direct3D 12 content. This ability to share resources between runtimes makes porting apps/engines to 12 simpler as entire 11-based components, such as a UI system, can remain virtually untouched.
24 changes: 20 additions & 4 deletions Samples/Desktop/D3D12Bundles/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# Bundles Sample
---
page_type: sample
languages:
- cpp
products:
- windows-api-win32
name: Direct3D 12 bundles sample
urlFragment: d3d12-bundles-sample-win32
description: Demonstrates the use of Direct3D 12 bundles.
extendedZipContent:
- path: LICENSE
target: LICENSE
---

# Direct3D 12 bundles sample

![Bundles GUI](src/D3D12Bundles.png)

This sample demonstrates the use of Direct3D 12 Bundles. An app can use Bundles to group a small number of API commands together for execution later. When a Bundle is created, the driver will perform as much pre-processing as possible to make it inexpensive to execute the Bundle later. Part of this pre-processing means that there are certain restrictions on what operations can be performed within a Bundle.
This sample demonstrates the use of Direct3D 12 bundles. An app can use bundles to group a small number of API commands together for execution later. When a bundle is created, the driver will perform as much pre-processing as possible to make it inexpensive to execute the bundle later. Part of this pre-processing means that there are certain restrictions on what operations can be performed within a bundle.

## Optional features

### Optional Features
This sample has been updated to build against the Windows 10 Anniversary Update SDK. In this SDK a new revision of Root Signatures is available for Direct3D 12 apps to use. Root Signature 1.1 allows for apps to declare when descriptors in a descriptor heap won't change or the data descriptors point to won't change. This allows the option for drivers to make optimizations that might be possible knowing that something (like a descriptor or the memory it points to) is static for some period of time.
This sample has been updated to build against the Windows 10 Anniversary Update SDK. In this SDK a new revision of Root Signatures is available for Direct3D 12 apps to use. Root Signature 1.1 allows for apps to declare when descriptors in a descriptor heap won't change or the data descriptors point to won't change. This allows the option for drivers to make optimizations that might be possible knowing that something (like a descriptor or the memory it points to) is static for some period of time.
18 changes: 16 additions & 2 deletions Samples/Desktop/D3D12DepthBoundsTest/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Depth Bounds Test Sample
---
page_type: sample
languages:
- cpp
products:
- windows-api-win32
name: Direct3D 12 depth bounds test sample
urlFragment: d3d12-depth-bounds-test-sample-win32
description: Demonstrates the depth bound test in Direct3D 12.
extendedZipContent:
- path: LICENSE
target: LICENSE
---

# Direct3D 12 depth bounds test sample
![DepthBounds GUI](src/D3D12DepthBoundsTest.png)

This sample demonstrates the depth bound test in Direct3D 12.
Depth-bounds testing allows pixels to be discarded if the currently-stored depth value is outside the range specified by Min and Max, inclusive.

See more detail about depth bounds test in the following page. https://msdn.microsoft.com/en-us/library/windows/desktop/mt492658(v=vs.85).aspx
For more detail about depth bounds test, see [**ID3D12GraphicsCommandList1::OMSetDepthBounds**](https://docs.microsoft.com/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist1-omsetdepthbounds).
Loading

0 comments on commit ab453c0

Please sign in to comment.