• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By turanszkij
      Hi,
      I finally managed to get the DX11 emulating Vulkan device working but everything is flipped vertically now because Vulkan has a different clipping space. What are the best practices out there to keep these implementation consistent? I tried using a vertically flipped viewport, and while it works on Nvidia 1050, the Vulkan debug layer is throwing error messages that this is not supported in the spec so it might not work on others. There is also the possibility to flip the clip scpace position Y coordinate before writing out with vertex shader, but that requires changing and recompiling every shader. I could also bake it into the camera projection matrices, though I want to avoid that because then I need to track down for the whole engine where I upload matrices... Any chance of an easy extension or something? If not, I will probably go with changing the vertex shaders.
    • By NikiTo
      Some people say "discard" has not a positive effect on optimization. Other people say it will at least spare the fetches of textures.
       
      if (color.A < 0.1f) { //discard; clip(-1); } // tons of reads of textures following here // and loops too
      Some people say that "discard" will only mask out the output of the pixel shader, while still evaluates all the statements after the "discard" instruction.

      MSN>
      discard: Do not output the result of the current pixel.
      clip: Discards the current pixel..
      <MSN

      As usual it is unclear, but it suggests that "clip" could discard the whole pixel(maybe stopping execution too)

      I think, that at least, because of termal and energy consuming reasons, GPU should not evaluate the statements after "discard", but some people on internet say that GPU computes the statements anyways. What I am more worried about, are the texture fetches after discard/clip.

      (what if after discard, I have an expensive branch decision that makes the approved cheap branch neighbor pixels stall for nothing? this is crazy)
    • By NikiTo
      I have a problem. My shaders are huge, in the meaning that they have lot of code inside. Many of my pixels should be completely discarded. I could use in the very beginning of the shader a comparison and discard, But as far as I understand, discard statement does not save workload at all, as it has to stale until the long huge neighbor shaders complete.
      Initially I wanted to use stencil to discard pixels before the execution flow enters the shader. Even before the GPU distributes/allocates resources for this shader, avoiding stale of pixel shaders execution flow, because initially I assumed that Depth/Stencil discards pixels before the pixel shader, but I see now that it happens inside the very last Output Merger state. It seems extremely inefficient to render that way a little mirror in a scene with big viewport. Why they've put the stencil test in the output merger anyway? Handling of Stencil is so limited compared to other resources. Does people use Stencil functionality at all for games, or they prefer discard/clip?

      Will GPU stale the pixel if I issue a discard in the very beginning of the pixel shader, or GPU will already start using the freed up resources to render another pixel?!?!



       
    • By Axiverse
      I'm wondering when upload buffers are copied into the GPU. Basically I want to pool buffers and want to know when I can reuse and write new data into the buffers.
    • By NikiTo
      AMD forces me to use MipLevels in order to can read from a heap previously used as RTV. Intel's integrated GPU works fine with MipLevels = 1 inside the D3D12_RESOURCE_DESC. For AMD I have to set it to 0(or 2). MSDN says 0 means max levels. With MipLevels = 1, AMD is rendering fine to the RTV, but reading from the RTV it shows the image reordered.

      Is setting MipLevels to something other than 1 going to cost me too much memory or execution time during rendering to RTVs, because I really don't need mipmaps at all(not for the 99% of my app)?

      (I use the same 2D D3D12_RESOURCE_DESC for both the SRV and RTV sharing the same heap. Using 1 for MipLevels in that D3D12_RESOURCE_DESC gives me results like in the photos attached below. Using 0 or 2 makes AMD read fine from the RTV. I wish I could sort this somehow, but in the last two days I've tried almost anything to sort this problem, and this is the only way it works on my machine.)


  • Advertisement
  • Advertisement
Sign in to follow this  

DX12 [D3D12] Minimal Tiled Resources implementation

This topic is 899 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