Advertisement

DirectX 12 problem to create a pipeline state object

Started by January 01, 2021 10:19 AM
2 comments, last by theScore 4 years, 1 month ago

Hello !

My program fails on CreateGraphicsPipelineState and indicates an INVALID_ARG error. I don't manage to fix it.

Could you help me ?

This is my code :

D3D12_ROOT_SIGNATURE_DESC rootSignatureDesc;
	rootSignatureDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT;
	rootSignatureDesc.NumParameters = 0;
	rootSignatureDesc.pParameters = nullptr;
	rootSignatureDesc.NumStaticSamplers = 0;
	rootSignatureDesc.pStaticSamplers = nullptr;

	ID3DBlob* signature;
	HRESULT hr = D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, nullptr);
	if (FAILED(hr))
	{
		return false;
	}

	ID3D12RootSignature* rootSignature;
	hr = deviceDX12->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&rootSignature));
	if (FAILED(hr))
	{
		return false;
	}

	D3DReadFileToBlob((LPCWSTR)L"./Shaders/vsGBuffer.cso", blobVertexGBuffer.GetAddressOf());

	// fill out shader bytecode structure for shader
	D3D12_SHADER_BYTECODE GBufferVertexShaderBytecode;
	GBufferVertexShaderBytecode.BytecodeLength = blobVertexGBuffer->GetBufferSize();
	GBufferVertexShaderBytecode.pShaderBytecode = blobVertexGBuffer->GetBufferPointer();


	//D3DX11CompileFromFile((LPCSTR)"./Code Source/Shaders/vsGBufferNormalsMapping.hlsl", NULL, NULL, "main", "vs_5_0", D3DCOMPILE_OPTIMIZATION_LEVEL3, 0, NULL, blobVertexGBufferNormalsMapping.GetAddressOf(), errorBlob.GetAddressOf(), NULL);
	D3DReadFileToBlob((LPCWSTR)L"./Shaders/vsGBufferNormalsMapping.cso", blobVertexGBufferNormalsMapping.GetAddressOf());

	int indexLayout = 0;
	// Create our vertex input layout
	D3D12_INPUT_ELEMENT_DESC layout[2];
	layout[indexLayout].SemanticName = "POSITION";
	layout[indexLayout].SemanticIndex = 0;
	layout[indexLayout].Format = DXGI_FORMAT_R16G16B16A16_FLOAT;//8 bytes
	layout[indexLayout].InputSlot = 0;
	layout[indexLayout].AlignedByteOffset = 0;
	layout[indexLayout].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
	layout[indexLayout].InstanceDataStepRate = 0;
	indexLayout++;

	layout[indexLayout].SemanticName = "COLOR";
	layout[indexLayout].SemanticIndex = 0;
	layout[indexLayout].Format = DXGI_FORMAT_R16G16B16A16_FLOAT;//8 bytes
	layout[indexLayout].InputSlot = 0;
	layout[indexLayout].AlignedByteOffset = D3D12_APPEND_ALIGNED_ELEMENT;
	layout[indexLayout].InputSlotClass = D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA;
	layout[indexLayout].InstanceDataStepRate = 0;
	indexLayout++;

	/*******************************************************************************************************************************************/
	UINT numElement = ARRAYSIZE(layout);

	// fill out an input layout description structure
	D3D12_INPUT_LAYOUT_DESC inputLayoutGBufferDesc;

	inputLayoutGBufferDesc.NumElements = numElement;
	inputLayoutGBufferDesc.pInputElementDescs = layout;

	D3DReadFileToBlob((LPCWSTR)L"./Shaders/psGBufferTexturedPixels.cso", blobPixelGBufferTexturedPixels.GetAddressOf());

	// fill out shader bytecode structure for shader
	D3D12_SHADER_BYTECODE GBufferPixelShaderBytecode;
	GBufferPixelShaderBytecode.BytecodeLength = blobPixelGBufferTexturedPixels->GetBufferSize();
	GBufferPixelShaderBytecode.pShaderBytecode = blobPixelGBufferTexturedPixels->GetBufferPointer();

	D3D12_RASTERIZER_DESC rasterizerStateDesc;
	rasterizerStateDesc.FillMode = D3D12_FILL_MODE_SOLID;
	rasterizerStateDesc.CullMode = D3D12_CULL_MODE_FRONT;
	rasterizerStateDesc.FrontCounterClockwise = TRUE;
	rasterizerStateDesc.DepthBias = 0;
	rasterizerStateDesc.DepthBiasClamp = 0.0f;
	rasterizerStateDesc.SlopeScaledDepthBias = 0;
	rasterizerStateDesc.DepthClipEnable = true;

	rasterizerStateDesc.MultisampleEnable = false;
	rasterizerStateDesc.AntialiasedLineEnable = false;

	D3D12_BLEND_DESC blendDesc{};

	multiSamplingSampledesc.Count = 1;
	multiSamplingSampledesc.Quality = 0;

	D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc ; // a structure to define a pso
	psoDesc.InputLayout = inputLayoutGBufferDesc; // the structure describing our input layout
	psoDesc.pRootSignature = rootSignature; // the root signature that describes the input data this pso needs
	psoDesc.VS = GBufferVertexShaderBytecode; // structure describing where to find the vertex shader bytecode and how large it is
	psoDesc.PS = GBufferPixelShaderBytecode; // same as VS but for pixel shader
	psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; // type of topology we are drawing
	psoDesc.RTVFormats[0] = DXGI_FORMAT_R16G16B16A16_FLOAT; // format of the render target
	psoDesc.SampleDesc = multiSamplingSampledesc; // must be the same sample description as the swapchain and depth/stencil buffer
	psoDesc.SampleMask = 0xffffffff; // sample mask has to do with multi-sampling. 0xffffffff means point sampling is done
	psoDesc.RasterizerState = rasterizerStateDesc; // a default rasterizer state.
	psoDesc.BlendState = blendDesc; // a default blent state.
	psoDesc.NumRenderTargets = 1; // we are only binding one render target

	// create the pso
	hr = deviceDX12->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&pipelineState));
	if (FAILED(hr))
//fails here
	{
		return false;
	}

The vertex shader :

struct vsIn
{
	half4 position : POSITION ;
 	half4 color    : COLOR0 ;
};

struct vsOut
{
	half4 finalPos :SV_POSITION ;
	half4 color : COLOR0 ;
};


vsOut main(in vsIn input)
{
	vsOut output ;
	
 	output.color = input.color ;

	output.finalPos = input.position;//wrong but just for test
	
	return output ;
}

The pixel shader:

struct psIn
{
	half4 finalPos		: SV_POSITION;
	half4 color			: COLOR0;

};

struct psOut
{
	half4 color			: SV_Target0;
};

psOut main(psIn input)
{
	psOut output;

	output.color = half4(1.0, 0.0, 0.0, 1.0);
	
	return output;
}

There could be a few reasons why it's failing. Your root signature creation looks fine, and the pipeline description looks alright too from a hundred feet up. Though, probably best to initialize some of those structures like so psoDesc = {};. In addition, I'd recommend working with the debug layer enabled to get more detailed messages as to why your pipeline compilation is failing.

https://gamedev.net/forums/topic/672268-d3d12-debug-layers-how-to-get-id3d12debugdevice/5255763/

I've also have had some success to just adding my output build executable to the dx control panel app, and forcing the debug layer on.  But ymmv

 

Advertisement

I have found, it is D3D12_RASTERIZER_DESC which had two missing values.

Thanks.

This topic is closed to new replies.

Advertisement