// Render the scene.
void D3D12ExecuteIndirect::OnRender()
{
	// Record all the commands we need to render the scene into the command list.
	PopulateCommandLists();

	// Execute the compute work.
	if (m_enableCulling)
	{
		ID3D12CommandList* ppCommandLists[] = { m_computeCommandList.Get() };
		m_computeCommandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
		m_computeCommandQueue->Signal(m_computeFence.Get(), m_fenceValues[m_frameIndex]);

		// Execute the rendering work only when the compute work is complete.
		m_commandQueue->Wait(m_computeFence.Get(), m_fenceValues[m_frameIndex]);
	}

	// Execute the rendering work.
	ID3D12CommandList* ppCommandLists[] = { m_commandList.Get() };
	m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);

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

	MoveToNextFrame();
}
// Render the scene.
void D3D12Fullscreen::OnRender()
{
	if (m_windowVisible)
	{
		PIXBeginEvent(m_commandQueue.Get(), 0, L"Render");

		// Record all the commands we need to render the scene into the command lists.
		PopulateCommandLists();

		// Execute the command lists.
		ID3D12CommandList* ppCommandLists[] = { m_sceneCommandList.Get(), m_postCommandList.Get() };
		m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);

		PIXEndEvent(m_commandQueue.Get());

		// When using sync interval 0, it is recommended to always pass the tearing
		// flag when it is supported, even when presenting in windowed mode.
		// However, this flag cannot be used if the app is in fullscreen mode as a
		// result of calling SetFullscreenState.
		UINT presentFlags = (m_tearingSupport && m_windowedMode) ? DXGI_PRESENT_ALLOW_TEARING : 0;

		// Present the frame.
		ThrowIfFailed(m_swapChain->Present(0, presentFlags));

		MoveToNextFrame();
	}
}
// Render the scene.
void D3D12HeterogeneousMultiadapter::OnRender()
{
	// Record all the commands we need to render the scene into the command lists.
	PopulateCommandLists();

	// Execute the command lists.
	{
		{
			ID3D12CommandList* ppRenderCommandLists[] = { m_directCommandLists[Primary].Get() };
			m_directCommandQueues[Primary]->ExecuteCommandLists(_countof(ppRenderCommandLists), ppRenderCommandLists);

			// Signal the copy queue to indicate render is complete.
			ThrowIfFailed(m_directCommandQueues[Primary]->Signal(m_renderFence.Get(), m_currentRenderFenceValue));
		}

		{
			// GPU Wait for the primary adapter to finish rendering.
			ThrowIfFailed(m_copyCommandQueue->Wait(m_renderFence.Get(), m_currentRenderFenceValue));
			m_currentRenderFenceValue++;

			ID3D12CommandList* ppCopyCommandLists[] = { m_copyCommandList.Get() };
			m_copyCommandQueue->ExecuteCommandLists(_countof(ppCopyCommandLists), ppCopyCommandLists);

			// Signal the secondary adapter to indicate the copy is complete.
			ThrowIfFailed(m_copyCommandQueue->Signal(m_crossAdapterFences[Primary].Get(), m_currentCrossAdapterFenceValue));
		}

		{
			// GPU Wait for the primary adapter to finish copying.
			ThrowIfFailed(m_directCommandQueues[Secondary]->Wait(m_crossAdapterFences[Secondary].Get(), m_currentCrossAdapterFenceValue));
			m_currentCrossAdapterFenceValue++;

			ID3D12CommandList* ppBlurCommandLists[] = { m_directCommandLists[Secondary].Get() };
			m_directCommandQueues[Secondary]->ExecuteCommandLists(_countof(ppBlurCommandLists), ppBlurCommandLists);
		}
	}

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

	// Signal the frame is complete.
	ThrowIfFailed(m_directCommandQueues[Secondary]->Signal(m_frameFence.Get(), m_currentPresentFenceValue));
	m_frameFenceValues[m_frameIndex] = m_currentPresentFenceValue;
	m_currentPresentFenceValue++;

	MoveToNextFrame();
}
示例#4
0
void AppTest::Render()
{
	PopulateCommandLists();

	//Execute command lists
	std::vector<ID3D12CommandList*> commandLists;
	commandLists.push_back(CommandList.Get());

	for (auto const& it : CommandListArray)
	{
		commandLists.push_back(it.Get());
	}

	CommandQueue->ExecuteCommandLists((UINT)commandLists.size(), &commandLists[0]);

	//Swap back and front buffers
	SwapChain->Present(1, 0);
	IndexLastSwapBuf = (1 + IndexLastSwapBuf) % NumSwapBufs;
	SwapChain->GetBuffer(IndexLastSwapBuf, IID_PPV_ARGS(RenderTarget.ReleaseAndGetAddressOf()));
	Device->CreateRenderTargetView(RenderTarget.Get(), nullptr, DescriptorHeap->GetCPUDescriptorHandleForHeapStart());

	WaitForGPU();
}