Jump to content
  • Advertisement
Sign in to follow this  
theScore

DX11 creatInputLayout returns a NULL pointer

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

Hi !

// Create our vertex input layout
	D3D11_INPUT_ELEMENT_DESC layout[4];
	layout[0].SemanticName = "POSITION";
	layout[0].SemanticIndex = 0;
	layout[0].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	layout[0].InputSlot = 0;
	layout[0].AlignedByteOffset = 0;
	layout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	layout[0].InstanceDataStepRate = 0;

	layout[1].SemanticName = "TEXCOORD";
	layout[1].SemanticIndex = 0;
	layout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
	layout[1].InputSlot = 0;
	layout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	layout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	layout[1].InstanceDataStepRate = 0;

	layout[2].SemanticName = "NORMAL";
	layout[2].SemanticIndex = 0;
	layout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	layout[2].InputSlot = 0;
	layout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	layout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	layout[2].InstanceDataStepRate = 0;

	layout[3].SemanticName = "COLOR";
	layout[3].SemanticIndex = 0;
	layout[3].Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
	layout[3].InputSlot = 0;
	layout[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	layout[3].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	layout[3].InstanceDataStepRate = 0;

	UINT numElement = ARRAYSIZE( layout ) ;
	if(D3DERR_INVALIDCALL == deviceDX11->CreateInputLayout( layout, numElement, blobVertexGBuffer->GetBufferPointer(), blobVertexGBuffer->GetBufferSize(), &vertexGBufferLayout ))
		return ;

 

The variable "vertexGBufferLayout" has no adress (null pointer), after createInputLayout method. This vraiable is of type ID3D11InputLayout and is in "out" as described in the directx documentation.

 

The associated vertex shader is : 


struct vsIn
{
	float4 position : POSITION ;
	float2 texCoord : TEXCOORD0 ;
	float3 normal   : NORMAL   ;
	float4 color    : COLOR ;
};

struct vsOut
{
	float4 RTposition : POSITION1 ;
	float2 texCoord : TEXCOORD0 ;
	float4 color : COLOR0 ;
	float4 finalPos :SV_POSITION ;
	float3 normal   : NORMAL   ;
	float4 posInLightSpace	 : TEXCOORD1 ;
};

cbuffer globalMatrices
{
	float4x4 WorldView ;
	float4x4 WorldViewProj;
	float4x4 InverseTransposedWorld ;
	//float4x4 lightViewProj ;
}

vsOut vertex_main(in vsIn IN, vsOut OUT)//, in float4 position : POSITION0)
{
	
	//OUT.posInLightSpace = mul(position, lightViewProj); 
	OUT.RTposition = mul(IN.position, WorldView);
	OUT.color = IN.color ;
	OUT.color.w = 1.0 ; 
	//OUT.normal = mul(IN.normal, WorldView);
	OUT.normal = mul(IN.normal, InverseTransposedWorld);
	OUT.texCoord = IN.texCoord ;
	
    OUT.finalPos= mul( IN.position, WorldViewProj );

	return OUT ;
} 

Can you help me ? Did I do something wrong ?

I'm not sure that the pixel format is right as I did, specially for COLOR semantic (is it the right name for colors' semantic ?) where I put DXGI_FORMAT_R8G8B8A8_UNORM_SRGB

Share this post


Link to post
Share on other sites
Advertisement

What does this give you:  ARRAYSIZE( layout );

 

Are blobVertexGBuffer and blobVertexGBuffer valid pointers?

 

And have you tried declaring color without the type DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ?

Share this post


Link to post
Share on other sites

ARRAYSIZE makes a sizeof of the whole array (here the variable named "layout") divided by the sizeof the first element of this array. Here it gives me a size of 4.

blobVertexGBuffer has a valid adress, yes.

I would like to put something else than DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, but I don't know what to put : R8G8B8A8 it's sure, but in float ? UINT ? It is to store colors, and don't know what is appropriate or the most appropriate to store colors from a scene representation.

Share this post


Link to post
Share on other sites

Ok but why ? It stores colors on 128 bits, instead of 32 bits, so why ?

It tried but it don't work.

Share this post


Link to post
Share on other sites

Maybe instead of this:

vsOut vertex_main(in vsIn IN, vsOut OUT)//, in float4 position : POSITION0)
{

 

 
try this:
vsOut vertex_main(in vsIn IN)
{
    vsOut OUT;

 

 

It could work...

Share this post


Link to post
Share on other sites

Not all DXGI formats are supported for use in a vertex buffer. You need to look at the table entitled "Input assembler vertex buffer resources" from here to see which formats are supported. In your particular case the issue is that _SRGB formats aren't supported. You need to use DXGI_FORMAT_R8G8B8A8_UNORM instead, and then apply sRGB->Linear conversion manually in the shader.

Also you should consider turning on the debug device by passing
D3D11_CREATE_DEVICE_DEBUG when creating your device. When you do this, you'll get helpful error messages in your debugger output window whenever you do something wrong.
 

Share this post


Link to post
Share on other sites

vertexGBufferLayout has no value (null pointer), I tried with DXGI_FORMAT_R8G8B8A8_UNORM and vertexGBufferLayout has still no value, I tried also by removing all lines concerning colors in the vertex shader and this code from C++ code :

layout[3].SemanticName = "COLOR";
layout[3].SemanticIndex = 0;
layout[3].Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
layout[3].InputSlot = 0;
layout[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
layout[3].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
layout[3].InstanceDataStepRate = 0;

 

And it still doesn't work sad.png

I tried to put D3D11_CREATE_DEVICE_DEBUG and my program crashes sooner in my code at a place where it usually doesn't crash. And I have no more messages in the output than before. sad.png 

Share this post


Link to post
Share on other sites

Can you show your initialization code for directx 11?

What IDE are you using?

 

Have you tried to initialize your input layout without the Semantic COLOR ?

 

So it would look like this:

 

D3D11_INPUT_ELEMENT_DESC layout[3];
	layout[0].SemanticName = "POSITION";
	layout[0].SemanticIndex = 0;
	layout[0].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	layout[0].InputSlot = 0;
	layout[0].AlignedByteOffset = 0;
	layout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	layout[0].InstanceDataStepRate = 0;

	layout[1].SemanticName = "TEXCOORD";
	layout[1].SemanticIndex = 0;
	layout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
	layout[1].InputSlot = 0;
	layout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	layout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	layout[1].InstanceDataStepRate = 0;

	layout[2].SemanticName = "NORMAL";
	layout[2].SemanticIndex = 0;
	layout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
	layout[2].InputSlot = 0;
	layout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	layout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	layout[2].InstanceDataStepRate = 0;

	UINT numElement = ARRAYSIZE( layout ) ;
	if(D3DERR_INVALIDCALL == deviceDX11->CreateInputLayout( layout, numElement, blobVertexGBuffer->GetBufferPointer(), blobVertexGBuffer->GetBufferSize(), &vertexGBufferLayout ))
		return ;

 

 

And then the shader as the following:

 

struct vsIn
{
	float4 position : POSITION ;
	float2 texCoord : TEXCOORD0 ;
	float3 normal   : NORMAL   ;
};

struct vsOut
{
	float4 RTposition : POSITION1 ;
	float2 texCoord : TEXCOORD0 ;
	float4 color : COLOR0 ;
	float4 finalPos :SV_POSITION ;
	float3 normal   : NORMAL   ;
	float4 posInLightSpace	 : TEXCOORD1 ;
};

cbuffer globalMatrices
{
	float4x4 WorldView ;
	float4x4 WorldViewProj;
	float4x4 InverseTransposedWorld ;
	//float4x4 lightViewProj ;
}

vsOut vertex_main(in vsIn IN, vsOut OUT)//, in float4 position : POSITION0)
{
	
	//OUT.posInLightSpace = mul(position, lightViewProj); 
	OUT.RTposition = mul(IN.position, WorldView);
	OUT.color = float4(1, 1, 1, 1) ;
	OUT.color.w = 1.0 ; 
	//OUT.normal = mul(IN.normal, WorldView);
	OUT.normal = mul(IN.normal, InverseTransposedWorld);
	OUT.texCoord = IN.texCoord ;
	
    OUT.finalPos= mul( IN.position, WorldViewProj );

	return OUT ;
} 

 

 

Just to see if COLOR is the issue.

Edited by Migi0027

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!