Jump to content
  • Advertisement
Sign in to follow this  
TheSubtleMachine

DX12 [D3D12] Minimal Tiled Resources implementation

This topic is 1142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all,

 

I'm attempting to get a simple implementation of tiled resources working in Direct3D12. I implemented much of this in a standalone project but for discussion purposes I chose the D3D12HelloTexture project as a starting point, you can find it here: https://github.com/Microsoft/DirectX-Graphics-Samples/tree/master/Samples/D3D12HelloWorld. I'm stuck trying to figure out what specifically I've done to cause the following error:
 

D3D12: Removing Device.
D3D12 ERROR: ID3D12Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_DEVICE_HUNG: The Device took an unreasonable amount of time to execute its commands, or the hardware crashed/hung. As a result, the TDR (Timeout Detection and Recovery) mechanism has been triggered. The current Device Context was executing commands when the hang occurred. The application may want to respawn and fallback to less aggressive use of the display hardware). [ EXECUTION ERROR #232: DEVICE_REMOVAL_PROCESS_AT_FAULT]

My modifications to D3D12HelloTexture.cpp are as follows:
1.) Use feature level 12_1 instead of 11_1

 

2.) To allow creation of reserved resource, change the texture layout to D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE.

 

3.) To allow clearing of the reserved resource after a call to UpdateTileMappings, use texture flag D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET and add a render target view to the RTV descriptor heap.

 

4.) To create the tile pool for the reserved resource, create a heap with type default and flags D3D12_HEAP_FLAG_ALLOW_ONLY_RT_DS_TEXTURES. The size of this tile pool is calculated using GetRequiredIntermediateSize on the reserved resource.

 

5.) After creating reserved texture, upload heap, and tile pool, synchronize using WaitForPreviousFrame. Then this code:

	// update the tile mapping
	m_commandQueue->UpdateTileMappings(m_texture.Get(),
		1, NULL, NULL,
		tilePool.Get(),
		1, NULL, NULL, NULL,
		D3D12_TILE_MAPPING_FLAG_NONE);	

	D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = {};
	rtvDesc.Format = texFormat;
	rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;

	CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(m_rtvHeap->GetCPUDescriptorHandleForHeapStart());
	rtvHandle.Offset(FrameCount, m_rtvDescriptorSize);
	m_device->CreateRenderTargetView(m_texture.Get(), &rtvDesc, rtvHandle);

	ThrowIfFailed(m_commandAllocator->Reset());
	ThrowIfFailed(m_commandList->Reset(m_commandAllocator.Get(), m_pipelineState.Get()));
	
	float clearColor[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
	m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_texture.Get(), D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, D3D12_RESOURCE_STATE_RENDER_TARGET));
	m_commandList->ClearRenderTargetView(rtvHandle, clearColor, 0, NULL);
	m_commandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_texture.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE));
	
	ThrowIfFailed(m_commandList->Close());
	
	// Execute the command list.
	m_commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
	
	WaitForPreviousFrame();

Full source of the modified D3D12HelloTexture.cpp can be found here: http://codeshare.io/2j1Lg

I can run all of this code, and if I avoid actually drawing anything, the device is happy. As soon as I try to draw a triangle with this tiled texture, I get the aforementioned error, found through an exception on the call m_swapChain->Present(1, 0).

If anyone has their own example of D3D12 tiled resources I'd love to see it. In searching for examples, I can only find DX11 implementations that vary enough from DX12 that I can't figure out how to apply that information successfully.

Share this post


Link to post
Share on other sites
Advertisement
I downloaded your code, and I get the same result on my GTX 970. I tried changing a bunch of things, (completely filling out UpdateTileMappings, making the reserved texture a static read-only texture instead of a render target), and it still causes a device removed. The only way it works is if I map all of the tiles to NULL.

So I guess I would also be interested in seeing a simple DX12 tiles resources example, since I'm also failing to get them working! smile.png

Share this post


Link to post
Share on other sites

I also downloaded the code and failed to get it working on my GTX 980 Ti, however I do have a working implementation of Tiled Resources (both 2D and 3D) that still runs on my PC, but no source code out right now. I tried many of the same things MJP did, as well as moving the UpdateTileMappings to before you call UpdateSubresources.

 

The debug layer seems to run clean, however I was getting failures on WARP as well. Weirdly though I was getting different behaviour on WARP depending on whether I was using VS 2015's Graphics Debugger or not, which was strange. I'll see if I can take another look tonight.

Share this post


Link to post
Share on other sites

I downloaded your code, and I get the same result on my GTX 970. I tried changing a bunch of things, (completely filling out UpdateTileMappings, making the reserved texture a static read-only texture instead of a render target), and it still causes a device removed. The only way it works is if I map all of the tiles to NULL.

So I guess I would also be interested in seeing a simple DX12 tiles resources example, since I'm also failing to get them working! smile.png

 

You should put that request here! https://github.com/Microsoft/DirectX-Graphics-Samples/issues

 

Hopefully they will also public a new dedicated video sometime https://www.youtube.com/channel/UCiaX2B8XiXR70jaN7NK-FpA

Share this post


Link to post
Share on other sites

Thanks for checking it out folks, onto the newly discovered reserved resources sample! I'll try and use that to get my example working, and see if I can't figure out where I went wrong using the documentation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!