I'm very new to D3D12-programming, and is just beginning to set up a little dummy-project to get the hang of the general process.
However, I have gotten stuck.
Currently, when debugging my little program in PIX, I can confirm that the Vertex Shader is running as it should, but the Pixel Shader does not get invoked.
I have tried checking my Scissor, Viewports and Depthbuffer, to confirm that the vertices does not get clipped, but I have not managed to solve the issue.
Does anyone have any idea what to check for here?
Thank you in advance!
Pipeline state in PIX Vertex shader output in PIX
A few code fragments which i think is relevant:
(Rasterizer state, DepthStencil state, Swapchain creation, RTV creation)
D3D12_RASTERIZER_DESC rasterizer{};
rasterizer.FillMode = D3D12_FILL_MODE_SOLID;
rasterizer.CullMode = D3D12_CULL_MODE_NONE;
rasterizer.FrontCounterClockwise = FALSE;
rasterizer.DepthClipEnable = TRUE;
rasterizer.MultisampleEnable = FALSE;
rasterizer.ConservativeRaster = D3D12_CONSERVATIVE_RASTERIZATION_MODE_OFF;
pipelineDesc.RasterizerState = rasterizer;
D3D12_DEPTH_STENCIL_DESC depthStencil{};
depthStencil.DepthEnable = TRUE;
depthStencil.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
depthStencil.DepthFunc = D3D12_COMPARISON_FUNC_LESS;
depthStencil.StencilEnable = FALSE;
depthStencil.FrontFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;
depthStencil.BackFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;
depthStencil.FrontFace.StencilPassOp = D3D12_STENCIL_OP_KEEP;
depthStencil.BackFace.StencilPassOp = D3D12_STENCIL_OP_KEEP;
depthStencil.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
depthStencil.BackFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;
DXGI_SWAP_CHAIN_DESC1 swapchainDescription{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullscreenDescription{};
swapchainDescription.Width = 0;
swapchainDescription.Height = 0;
swapchainDescription.Format = DXGI_FORMAT_R16G16B16A16_FLOAT;
swapchainDescription.Stereo = FALSE;
swapchainDescription.SampleDesc = { 1, 0 };
swapchainDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapchainDescription.BufferCount = 2;
swapchainDescription.Scaling = DXGI_SCALING_NONE;
swapchainDescription.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapchainDescription.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
swapchainDescription.Flags = 0;
fullscreenDescription.RefreshRate = { 1, 60 };
fullscreenDescription.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE;
fullscreenDescription.Scaling = DXGI_MODE_SCALING_CENTERED;
fullscreenDescription.Windowed = TRUE;
CheckHresult(factory->CreateSwapChainForHwnd(commandQueue, hwnd, &swapchainDescription, &fullscreenDescription, NULL, &t_swapchain));
HRESULT sres = t_swapchain->QueryInterface(IID_PPV_ARGS(&swapchain));
D3D12_DESCRIPTOR_HEAP_DESC descriptorHeapInfoRtv{};
descriptorHeapInfoRtv.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
descriptorHeapInfoRtv.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
descriptorHeapInfoRtv.NumDescriptors = 2;
descriptorHeapInfoRtv.NodeMask = 0;
device->CreateDescriptorHeap(&descriptorHeapInfoRtv, IID_PPV_ARGS(&rtv_descriptorHeap.descriptorHeap));
rtv_descriptorHeap.incrementSize = device->GetDescriptorHandleIncrementSize(descriptorHeapInfoRtv.Type);
rtv_descriptorHeap.startHandle = rtv_descriptorHeap.descriptorHeap->GetCPUDescriptorHandleForHeapStart();
device->CreateRenderTargetView(swapchainBuffers[0], NULL, rtv_descriptorHeap.startHandle);
device->CreateRenderTargetView(swapchainBuffers[1], NULL, rtv_descriptorHeap.AddOffset(1));
Shader code:
// Vertex Shader
struct VS_IN
{
float4 pos : POSITION;
};
struct VS_OUT
{
float4 pos : SV_Position;
};
VS_OUT main(VS_IN inp)
{
VS_OUT outp;
outp.pos = float4(inp.pos.x, inp.pos.y, inp.pos.z, 1.0f);
return outp;
}
// Pixel Shader
struct PS_OUT
{
float4 col_in : COLOR;
};
struct VS_OUT
{
float4 pos : SV_Position;
};
float4 main(VS_OUT inp) : SV_Target
{
PS_OUT outp;
outp.col_in = float4(1.0f, 1.0f, 1.0f, 1.0f);
return outp.col_in;
}
I have tried using both default settings (passing NULL in device->CreateRenderTargetView) and also passing in a custom description. I have tried disabling depth testing, and changed the pipeline states samplemask.
Found the problem: I called commandList->ClearDepthStencilView(dsv_descriptorHeap.startHandle, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, &rect); With the 1.0f, 0, 0 parameters in the wrong order. I had them 0, 1, 0, thus giving the effect of clearing the depth buffer to the wrong value, presumably causing my pixels to fail the depth test.