• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Jason Smith
      While working on a project using D3D12 I was getting an exception being thrown while trying to get a D3D12_CPU_DESCRIPTOR_HANDLE. The project is using plain C so it uses the COBJMACROS. The following application replicates the problem happening in the project.
      #define COBJMACROS #pragma warning(push, 3) #include <Windows.h> #include <d3d12.h> #include <dxgi1_4.h> #pragma warning(pop) IDXGIFactory4 *factory; ID3D12Device *device; ID3D12DescriptorHeap *rtv_heap; int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE pinst, PWSTR cline, int cshow) { (hinst), (pinst), (cline), (cshow); HRESULT hr = CreateDXGIFactory1(&IID_IDXGIFactory4, (void **)&factory); hr = D3D12CreateDevice(0, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, &device); D3D12_DESCRIPTOR_HEAP_DESC desc; desc.NumDescriptors = 1; desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV; desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; desc.NodeMask = 0; hr = ID3D12Device_CreateDescriptorHeap(device, &desc, &IID_ID3D12DescriptorHeap, (void **)&rtv_heap); D3D12_CPU_DESCRIPTOR_HANDLE rtv = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(rtv_heap); (rtv); } The call to ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart throws an exception. Stepping into the disassembly for ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart show that the error occurs on the instruction
      mov  qword ptr [rdx],rax
      which seems odd since rdx doesn't appear to be used. Any help would be greatly appreciated. Thank you.
       
    • By lubbe75
      As far as I understand there is no real random or noise function in HLSL. 
      I have a big water polygon, and I'd like to fake water wave normals in my pixel shader. I know it's not efficient and the standard way is really to use a pre-calculated noise texture, but anyway...
      Does anyone have any quick and dirty HLSL shader code that fakes water normals, and that doesn't look too repetitious? 
    • 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?!?!



       
  • Advertisement
  • Advertisement
Sign in to follow this  

DX12 DX12 SkyBox

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

In a previous iteration of my code, I would have done the following

  • Clear Color
  • Render SkyBox
  • Clear Depth
  • Render Scene

But it strikes me that with DX12, I could just create a PipelineState that disables the depth write.  First of all, is that a better way to do things now?  And second, I get a crash on CreateGraphicsPipelineState when trying to use a shader with 0 descriptor heaps (it's a basic shader that has 3 floats for position.  No textures, buffers, samplers at the moment.  It gives me E_INVALIDARGS:

	ComPtr<ID3DBlob> signature, error;
	CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc = CD3DX12_ROOT_SIGNATURE_DESC(D3D12_DEFAULT);
	ThrowIfFailed(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
	ThrowIfFailed(device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature)));

	const D3D12_INPUT_ELEMENT_DESC VertexElements[] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0 },
	};
	D3D12_INPUT_LAYOUT_DESC inputLayoutDesc;
	inputLayoutDesc.pInputElementDescs = VertexElements;
	inputLayoutDesc.NumElements = _countof(VertexElements);

	D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
	psoDesc.VS = { reinterpret_cast<UINT8*>(vsBlob->GetBufferPointer()), vsBlob->GetBufferSize() };
	psoDesc.PS = { reinterpret_cast<UINT8*>(psBlob->GetBufferPointer()), psBlob->GetBufferSize() };
	psoDesc.InputLayout = inputLayoutDesc;
	psoDesc.pRootSignature = rootSignature.Get();
	psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
	psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
	psoDesc.DepthStencilState.DepthEnable = FALSE;
	psoDesc.DepthStencilState.StencilEnable = FALSE;
	psoDesc.SampleMask = UINT_MAX;
	psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
	psoDesc.NumRenderTargets = 1;
	psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
	psoDesc.SampleDesc.Count = 1;
	ThrowIfFailed(device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState)));

Share this post


Link to post
Share on other sites
Advertisement

Okay, but I'd still like to know:

 

  • Is it expensive to switch pipeline states?
  • Is there any obvious reason why my call to CreateGraphicsPipelineState crashes with E_INVALIDARGS?
  • How are you proposing that I should render the sky?
Edited by Funkymunky

Share this post


Link to post
Share on other sites
&nbsp;

<p>

Okay, but I'd still like to know:
&nbsp;

  • Is it expensive to switch pipeline states?
  • Is there any obvious reason why my call to CreateGraphicsPipelineState crashes with E_INVALIDARGS?
  • How are you proposing that I should render the sky?

1 - Expensive is a "relative" term, it's more expensive than not switching them, so you should avoid doing it if you can without adding too much extra cost to do that. On the other hand setting states and drawing things is much more efficient with d3d12 compared to d3d11 so you have more of a margin there before hitting hard limits. If objects share the same pipeline states try drawing them together if you can. But you do not have to go out of your way to merge different pipeline states by artificial means (not unless you find that is becoming a problem).

2 - I'd suggest turning on the debug runtime.

3 - Try to render the sky as the last opaque thing. (you could also use a Z only pass). The culling of pixels (not rendering unnecessary pixels) is more efficient if opaque objects are rendered front to back (in a rough order but you know that the sky is always the background so it's not complicated to find out when to draw it). The z-only pass helps if you can't for some reason guarantee a very good front to back order. But it can be more expensive if you don't gain any more pixel culling after it (it's two passes instead of one).

We realize that some advice can appear contradictory. It's because you always have to make trade-offs. The preferred order for X is different than the perfect order for Y. It's why you always profile (if possible with your final load) and before you can profile you build things that are more flexible and/or with good guesstimates. See for example this benchmark : http://www.anandtech.com/show/9112/exploring-dx12-3dmark-api-overhead-feature-test/3 it shows that the engine can render 300k draw calls per frame. Grouping one more draw call the wrong way is not necessarily going to affect performance that much (especially if you are far from the theoretical limit). On the other hand if your sky is expensive to draw per pixel then drawing it after everything makes sense.

Share this post


Link to post
Share on other sites
If your problem is to "how in practice" draw the skybox as the last thing (without it intersecting other geometry) you probably have many solutions to choose from.


You can choose some range to draw the main scene and some other range to draw the skybox. You can modify your vertex shader to make sure your skybox always end up near the max z value (not exactly the max z-value as that could result in z-fighting and clipping on some hardware). You can also render your skybox as a quad near the max z value (a cube has a varying depth unless you use previous tip, the quad can be drawn at constant depth) and use texture coordinates to point to the right texel in the cubemap and so on.


If you're unsure on how to modify your vertex shader, remember that the W value that you write determines the proper position on the screen (perspective correction and X/W Y/W screen coordinates after a conic projection) and that the Z/W value is what ends up being written in the depth buffer and/or tested against the depth buffer.

Share this post


Link to post
Share on other sites

I haven't done any D3D 12 yet but I see no reason why my usual advice for a skybox won't work - set a depth range (minz/maxz in your viewport) of 1,1, draw it last and draw it as a small cube (how small depends on znear in your projection) centered on the viewpoint.  The depth range will ensure that the skybox is always behind other geometry, drawing it as a small cube will ensure that you don't need to worry about positioning and sizing relative to other geometry and it will never z-fight, and the two work together to give the desired result.  If you can, use a cubemap for the skybox texture rather than 6 individual textures.

Share this post


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

  • Advertisement