diff --git a/Samples/D3D12Bundles/src/FrameResource.cpp b/Samples/D3D12Bundles/src/FrameResource.cpp index db59a297a..95bbae613 100644 --- a/Samples/D3D12Bundles/src/FrameResource.cpp +++ b/Samples/D3D12Bundles/src/FrameResource.cpp @@ -40,7 +40,8 @@ FrameResource::FrameResource(ID3D12Device* pDevice, UINT cityRowCount, UINT city // does not need to be unmapped for use by the GPU. In this sample, // the resource stays 'permenantly' mapped to avoid overhead with // mapping/unmapping each frame. - ThrowIfFailed(m_cbvUploadHeap->Map(0, nullptr, reinterpret_cast(&m_pConstantBuffers))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_cbvUploadHeap->Map(0, &readRange, reinterpret_cast(&m_pConstantBuffers))); // Update all of the model matrices once; our cities don't move so // we don't need to do this ever again. diff --git a/Samples/D3D12DynamicIndexing/src/FrameResource.cpp b/Samples/D3D12DynamicIndexing/src/FrameResource.cpp index f8c2944d7..81002ca51 100644 --- a/Samples/D3D12DynamicIndexing/src/FrameResource.cpp +++ b/Samples/D3D12DynamicIndexing/src/FrameResource.cpp @@ -41,7 +41,8 @@ FrameResource::FrameResource(ID3D12Device* pDevice, UINT cityRowCount, UINT city // does not need to be unmapped for use by the GPU. In this sample, // the resource stays 'permenantly' mapped to avoid overhead with // mapping/unmapping each frame. - ThrowIfFailed(m_cbvUploadHeap->Map(0, nullptr, reinterpret_cast(&m_pConstantBuffers))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_cbvUploadHeap->Map(0, &readRange, reinterpret_cast(&m_pConstantBuffers))); // Update all of the model matrices once; our cities don't move so // we don't need to do this ever again. diff --git a/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.cpp b/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.cpp index 905ab3cde..46ec9e0ea 100644 --- a/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.cpp +++ b/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.cpp @@ -349,9 +349,6 @@ void D3D12ExecuteIndirect::LoadAssets() nullptr, IID_PPV_ARGS(&m_constantBuffer))); - CD3DX12_CPU_DESCRIPTOR_HANDLE cpuHandle(m_cbvSrvUavHeap->GetCPUDescriptorHandleForHeapStart()); - D3D12_GPU_VIRTUAL_ADDRESS gpuAddress = m_constantBuffer->GetGPUVirtualAddress(); - D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc = {}; cbvDesc.SizeInBytes = sizeof(ConstantBufferData); @@ -362,20 +359,12 @@ void D3D12ExecuteIndirect::LoadAssets() m_constantBufferData[n].offset = XMFLOAT4(GetRandomFloat(-5.0f, -1.5f), GetRandomFloat(-1.0f, 1.0f), GetRandomFloat(0.0f, 2.0f), 0.0f); m_constantBufferData[n].color = XMFLOAT4(GetRandomFloat(0.5f, 1.0f), GetRandomFloat(0.5f, 1.0f), GetRandomFloat(0.5f, 1.0f), 1.0f); XMStoreFloat4x4(&m_constantBufferData[n].projection, XMMatrixTranspose(XMMatrixPerspectiveFovLH(XM_PIDIV4, m_aspectRatio, 0.01f, 20.0f))); - - for (int frame = 0; frame < FrameCount; frame++) - { - cbvDesc.BufferLocation = gpuAddress + (cbvDesc.SizeInBytes * TriangleCount * frame); - m_device->CreateConstantBufferView(&cbvDesc, CD3DX12_CPU_DESCRIPTOR_HANDLE(cpuHandle, CbvSrvUavDescriptorCountPerFrame * frame, m_cbvSrvUavDescriptorSize)); - } - - cpuHandle.Offset(m_cbvSrvUavDescriptorSize); - gpuAddress += cbvDesc.SizeInBytes; } // Map the constant buffers. We don't unmap this until the app closes. // Keeping things mapped for the lifetime of the resource is okay. - ThrowIfFailed(m_constantBuffer->Map(0, nullptr, reinterpret_cast(&m_pCbvDataBegin))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_constantBuffer->Map(0, &readRange, reinterpret_cast(&m_pCbvDataBegin))); memcpy(m_pCbvDataBegin, &m_constantBufferData[0], TriangleCount * sizeof(ConstantBufferData)); // Create shader resource views (SRV) of the constant buffers for the @@ -525,7 +514,8 @@ void D3D12ExecuteIndirect::LoadAssets() IID_PPV_ARGS(&m_processedCommandBufferCounterReset))); UINT8* pMappedCounterReset = nullptr; - ThrowIfFailed(m_processedCommandBufferCounterReset->Map(0, nullptr, reinterpret_cast(&pMappedCounterReset))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_processedCommandBufferCounterReset->Map(0, &readRange, reinterpret_cast(&pMappedCounterReset))); ZeroMemory(pMappedCounterReset, sizeof(UINT)); m_processedCommandBufferCounterReset->Unmap(0, nullptr); } diff --git a/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.h b/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.h index 9869509b5..78a6084f4 100644 --- a/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.h +++ b/Samples/D3D12ExecuteIndirect/src/D3D12ExecuteIndirect.h @@ -90,8 +90,7 @@ class D3D12ExecuteIndirect : public DXSample // CBV/SRV/UAV desciptor heap offsets. enum HeapOffsets { - CbvOffset = 0, - CbvSrvOffset = CbvOffset + TriangleCount, // SRV that points to the constant buffers used by the rendering thread. + CbvSrvOffset = 0, // SRV that points to the constant buffers used by the rendering thread. CommandsOffset = CbvSrvOffset + 1, // SRV that points to all of the indirect commands. ProcessedCommandsOffset = CommandsOffset + 1, // UAV that records the commands we actually want to execute. CbvSrvUavDescriptorCountPerFrame = ProcessedCommandsOffset + 1 // 1 CBV per triangle + [2 SRVs + 1 UAV for the compute shader]. diff --git a/Samples/D3D12Fullscreen/src/D3D12Fullscreen.cpp b/Samples/D3D12Fullscreen/src/D3D12Fullscreen.cpp index d2436ff82..6458c4319 100644 --- a/Samples/D3D12Fullscreen/src/D3D12Fullscreen.cpp +++ b/Samples/D3D12Fullscreen/src/D3D12Fullscreen.cpp @@ -270,7 +270,8 @@ void D3D12Fullscreen::LoadSizeDependentResources() // Copy data to the intermediate upload heap and then schedule a copy // from the upload heap to the vertex buffer. UINT8* pVertexDataBegin; - ThrowIfFailed(m_vertexBufferUpload->Map(0, &CD3DX12_RANGE(0, vertexBufferSize), reinterpret_cast(&pVertexDataBegin))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_vertexBufferUpload->Map(0, &readRange, reinterpret_cast(&pVertexDataBegin))); memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices)); m_vertexBufferUpload->Unmap(0, nullptr); diff --git a/Samples/D3D12Fullscreen/src/D3D12Fullscreen.vcxproj.filters b/Samples/D3D12Fullscreen/src/D3D12Fullscreen.vcxproj.filters index 16b26446d..b345761f0 100644 --- a/Samples/D3D12Fullscreen/src/D3D12Fullscreen.vcxproj.filters +++ b/Samples/D3D12Fullscreen/src/D3D12Fullscreen.vcxproj.filters @@ -24,9 +24,6 @@ - - Header Files - Header Files\Util @@ -42,14 +39,14 @@ Header Files\Util + + Header Files + Source Files - - Source Files - Source Files @@ -59,6 +56,9 @@ Source Files\Util + + Source Files + diff --git a/Samples/D3D12HelloWorld/src/HelloBundles/D3D12HelloBundles.cpp b/Samples/D3D12HelloWorld/src/HelloBundles/D3D12HelloBundles.cpp index dd5399c89..be413bd24 100644 --- a/Samples/D3D12HelloWorld/src/HelloBundles/D3D12HelloBundles.cpp +++ b/Samples/D3D12HelloWorld/src/HelloBundles/D3D12HelloBundles.cpp @@ -222,7 +222,8 @@ void D3D12HelloBundles::LoadAssets() // Copy the triangle data to the vertex buffer. UINT8* pVertexDataBegin; - ThrowIfFailed(m_vertexBuffer->Map(0, nullptr, reinterpret_cast(&pVertexDataBegin))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_vertexBuffer->Map(0, &readRange, reinterpret_cast(&pVertexDataBegin))); memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices)); m_vertexBuffer->Unmap(0, nullptr); diff --git a/Samples/D3D12HelloWorld/src/HelloConstBuffers/D3D12HelloConstBuffers.cpp b/Samples/D3D12HelloWorld/src/HelloConstBuffers/D3D12HelloConstBuffers.cpp index 326f592a5..8a395d2bd 100644 --- a/Samples/D3D12HelloWorld/src/HelloConstBuffers/D3D12HelloConstBuffers.cpp +++ b/Samples/D3D12HelloWorld/src/HelloConstBuffers/D3D12HelloConstBuffers.cpp @@ -246,7 +246,8 @@ void D3D12HelloConstBuffers::LoadAssets() // Copy the triangle data to the vertex buffer. UINT8* pVertexDataBegin; - ThrowIfFailed(m_vertexBuffer->Map(0, nullptr, reinterpret_cast(&pVertexDataBegin))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_vertexBuffer->Map(0, &readRange, reinterpret_cast(&pVertexDataBegin))); memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices)); m_vertexBuffer->Unmap(0, nullptr); @@ -275,7 +276,9 @@ void D3D12HelloConstBuffers::LoadAssets() // Initialize and map the constant buffers. We don't unmap this until the // app closes. Keeping things mapped for the lifetime of the resource is okay. ZeroMemory(&m_constantBufferData, sizeof(m_constantBufferData)); - ThrowIfFailed(m_constantBuffer->Map(0, nullptr, reinterpret_cast(&m_pCbvDataBegin))); + + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_constantBuffer->Map(0, &readRange, reinterpret_cast(&m_pCbvDataBegin))); memcpy(m_pCbvDataBegin, &m_constantBufferData, sizeof(m_constantBufferData)); } diff --git a/Samples/D3D12HelloWorld/src/HelloTexture/D3D12HelloTexture.cpp b/Samples/D3D12HelloWorld/src/HelloTexture/D3D12HelloTexture.cpp index c0a8dfd32..38ebc0ab0 100644 --- a/Samples/D3D12HelloWorld/src/HelloTexture/D3D12HelloTexture.cpp +++ b/Samples/D3D12HelloWorld/src/HelloTexture/D3D12HelloTexture.cpp @@ -245,7 +245,8 @@ void D3D12HelloTexture::LoadAssets() // Copy the triangle data to the vertex buffer. UINT8* pVertexDataBegin; - ThrowIfFailed(m_vertexBuffer->Map(0, nullptr, reinterpret_cast(&pVertexDataBegin))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_vertexBuffer->Map(0, &readRange, reinterpret_cast(&pVertexDataBegin))); memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices)); m_vertexBuffer->Unmap(0, nullptr); diff --git a/Samples/D3D12HelloWorld/src/HelloTriangle/D3D12HelloTriangle.cpp b/Samples/D3D12HelloWorld/src/HelloTriangle/D3D12HelloTriangle.cpp index 4e8a934ee..27c32117e 100644 --- a/Samples/D3D12HelloWorld/src/HelloTriangle/D3D12HelloTriangle.cpp +++ b/Samples/D3D12HelloWorld/src/HelloTriangle/D3D12HelloTriangle.cpp @@ -221,7 +221,8 @@ void D3D12HelloTriangle::LoadAssets() // Copy the triangle data to the vertex buffer. UINT8* pVertexDataBegin; - ThrowIfFailed(m_vertexBuffer->Map(0, nullptr, reinterpret_cast(&pVertexDataBegin))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_vertexBuffer->Map(0, &readRange, reinterpret_cast(&pVertexDataBegin))); memcpy(pVertexDataBegin, triangleVertices, sizeof(triangleVertices)); m_vertexBuffer->Unmap(0, nullptr); diff --git a/Samples/D3D12Multithreading/src/FrameResource.cpp b/Samples/D3D12Multithreading/src/FrameResource.cpp index 18463d826..cb4cd41c7 100644 --- a/Samples/D3D12Multithreading/src/FrameResource.cpp +++ b/Samples/D3D12Multithreading/src/FrameResource.cpp @@ -130,8 +130,9 @@ FrameResource::FrameResource(ID3D12Device* pDevice, ID3D12PipelineState* pPso, I IID_PPV_ARGS(&m_sceneConstantBuffer))); // Map the constant buffers and cache their heap pointers. - ThrowIfFailed(m_shadowConstantBuffer->Map(0, nullptr, reinterpret_cast(&mp_shadowConstantBufferWO))); - ThrowIfFailed(m_sceneConstantBuffer->Map(0, nullptr, reinterpret_cast(&mp_sceneConstantBufferWO))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_shadowConstantBuffer->Map(0, &readRange, reinterpret_cast(&mp_shadowConstantBufferWO))); + ThrowIfFailed(m_sceneConstantBuffer->Map(0, &readRange, reinterpret_cast(&mp_sceneConstantBufferWO))); // Create the constant buffer views: one for the shadow pass and // another for the scene pass. diff --git a/Samples/D3D12PipelineStateCache/src/D3D12PipelineStateCache.cpp b/Samples/D3D12PipelineStateCache/src/D3D12PipelineStateCache.cpp index 734f7f9e9..2f624bfc8 100644 --- a/Samples/D3D12PipelineStateCache/src/D3D12PipelineStateCache.cpp +++ b/Samples/D3D12PipelineStateCache/src/D3D12PipelineStateCache.cpp @@ -294,7 +294,8 @@ void D3D12PipelineStateCache::LoadAssets() IID_PPV_ARGS(&vertexIndexBufferUpload))); UINT8* mappedUploadHeap = nullptr; - ThrowIfFailed(vertexIndexBufferUpload->Map(0, nullptr, reinterpret_cast(&mappedUploadHeap))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(vertexIndexBufferUpload->Map(0, &readRange, reinterpret_cast(&mappedUploadHeap))); // Fill in part of the upload heap with our index and vertex data. UINT8* heapLocation = static_cast(mappedUploadHeap); diff --git a/Samples/D3D12PipelineStateCache/src/DynamicConstantBuffer.cpp b/Samples/D3D12PipelineStateCache/src/DynamicConstantBuffer.cpp index d463bfdc7..916408215 100644 --- a/Samples/D3D12PipelineStateCache/src/DynamicConstantBuffer.cpp +++ b/Samples/D3D12PipelineStateCache/src/DynamicConstantBuffer.cpp @@ -44,7 +44,8 @@ void DynamicConstantBuffer::Init(ID3D12Device* pDevice) IID_PPV_ARGS(&m_constantBuffer) )); - ThrowIfFailed(m_constantBuffer->Map(0, nullptr, reinterpret_cast(&m_pMappedConstantBuffer))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_constantBuffer->Map(0, &readRange, reinterpret_cast(&m_pMappedConstantBuffer))); } void* DynamicConstantBuffer::GetMappedMemory(UINT drawIndex, UINT frameIndex) diff --git a/Samples/D3D12PredicationQueries/src/D3D12PredicationQueries.cpp b/Samples/D3D12PredicationQueries/src/D3D12PredicationQueries.cpp index 6b051f6f9..0775aa103 100644 --- a/Samples/D3D12PredicationQueries/src/D3D12PredicationQueries.cpp +++ b/Samples/D3D12PredicationQueries/src/D3D12PredicationQueries.cpp @@ -321,7 +321,8 @@ void D3D12PredicationQueries::LoadAssets() // Initialize and map the constant buffers. We don't unmap this until the // app closes. Keeping things mapped for the lifetime of the resource is okay. ZeroMemory(&m_constantBufferData, sizeof(m_constantBufferData)); - ThrowIfFailed(m_constantBuffer->Map(0, nullptr, reinterpret_cast(&m_pCbvDataBegin))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_constantBuffer->Map(0, &readRange, reinterpret_cast(&m_pCbvDataBegin))); ZeroMemory(m_pCbvDataBegin, FrameCount * sizeof(m_constantBufferData)); // Create constant buffer views to access the upload buffer. diff --git a/Samples/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp b/Samples/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp index d843cdf41..99ad8d1c9 100644 --- a/Samples/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp +++ b/Samples/D3D12nBodyGravity/src/D3D12nBodyGravity.cpp @@ -331,7 +331,8 @@ void D3D12nBodyGravity::LoadAssets() IID_PPV_ARGS(&m_constantBufferGS) )); - ThrowIfFailed(m_constantBufferGS->Map(0, nullptr, reinterpret_cast(&m_pConstantBufferGSData))); + CD3DX12_RANGE readRange(0, 0); // We do not intend to read from this resource on the CPU. + ThrowIfFailed(m_constantBufferGS->Map(0, &readRange, reinterpret_cast(&m_pConstantBufferGSData))); ZeroMemory(m_pConstantBufferGSData, constantBufferGSSize); }