공부중

[DirectX12]Hello Wolrd Sample - D3D12HelloTexture - 7 본문

Programing/DirectX

[DirectX12]Hello Wolrd Sample - D3D12HelloTexture - 7

곤란 2018. 6. 7. 14:58
반응형
	// Close the command list and execute it to begin the initial GPU setup.
	ThrowIfFailed(m_commandList->Close());
	ID3D12CommandList* ppCommandLists[] = { m_commandList.Get() };
	m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);

	// Create synchronization objects and wait until assets have been uploaded to the GPU.
	{
		ThrowIfFailed(m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence)));
		m_fenceValue = 1;

		// Create an event handle to use for frame synchronization.
		m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
		if (m_fenceEvent == nullptr)
		{
			ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
		}

		// Wait for the command list to execute; we are reusing the same command 
		// list in our main loop but for now, we just want to wait for setup to 
		// complete before continuing.
		WaitForPreviousFrame();
	}

 

이번 글에서 적어볼 코드 내용이다.

 

	// Close the command list and execute it to begin the initial GPU setup.
	ThrowIfFailed(m_commandList->Close());
	ID3D12CommandList* ppCommandLists[] = { m_commandList.Get() };
	m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);

위에서 m_commandList에 명령들을 추가 했었다.(텍스쳐 정보 업로드...상태 전이 등등)

기록할것이 끝났으므로 Close()로 닫아주는 모습이다.

위에서 생성한 commandList를 넣고 ExecuteCommandLists로 실행하고 있다.

 

	// Create synchronization objects and wait until assets have been uploaded to the GPU.
	{
		ThrowIfFailed(m_device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_fence)));
		m_fenceValue = 1;

		// Create an event handle to use for frame synchronization.
		m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
		if (m_fenceEvent == nullptr)
		{
			ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
		}

		// Wait for the command list to execute; we are reusing the same command 
		// list in our main loop but for now, we just want to wait for setup to 
		// complete before continuing.
		WaitForPreviousFrame();
	}

 

Fence를 생성하고 이것으로 싱크를 맞추는 것은 이전글에서 설명하였으므로 넘어가도록 한다

하단에 WaitForPreviousFrame이 있는데 혹시 변경된점이 있는지 확인해볼 필요가 있다.

 

 

void D3D12HelloTexture::WaitForPreviousFrame()
{
	// WAITING FOR THE FRAME TO COMPLETE BEFORE CONTINUING IS NOT BEST PRACTICE.
	// This is code implemented as such for simplicity. The D3D12HelloFrameBuffering
	// sample illustrates how to use fences for efficient resource usage and to
	// maximize GPU utilization.

	// Signal and increment the fence value.
	const UINT64 fence = m_fenceValue;
	ThrowIfFailed(m_commandQueue->Signal(m_fence.Get(), fence));
	m_fenceValue++;

	// Wait until the previous frame is finished.
	if (m_fence->GetCompletedValue() < fence)
	{
		ThrowIfFailed(m_fence->SetEventOnCompletion(fence, m_fenceEvent));
		WaitForSingleObject(m_fenceEvent, INFINITE);
	}

	m_frameIndex = m_swapChain->GetCurrentBackBufferIndex();
}

특별히 변한것은 없으므로 저번글의 설명과 변함이 없으므로 넘어간다.

 

이것으로 LoadAsset도 끝이 났으므로 OnInit이 끝이 났다.

 

이제 남은것은 OnUpdate와 OnRender가 남아있다.

 

// Update frame-based values.
void D3D12HelloTexture::OnUpdate()
{
}

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

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

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

	WaitForPreviousFrame();
}

 

Update와 Render도 큰 변화가 없다......

 

이것으로 HelloTexture가 끝이 났다

 

이번 프로젝트를 정리하면서 DX12책을 보면서 새로 글을 쓰며 뒤죽박중 엉망진창인것을 정리를 해야할지

 

아니면 이거 Sample을 다 마무리 짓고나서 해야될지 고민이다 -_-....

 

ㅂㄷㅂㄷ.....

 

 

아무튼 ... 끗.....

 

 

 

 

 

반응형