Jump to content
  • Advertisement
VietNN

DX12 [D3D12 SOLVED] Could not render triangles, no error output (debug enabled)

This topic is 427 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 everyone,

I am new to DX12, I download sample project from MSDN and it can run and draw triangles successfully.

But when I create new project and copy code from MSDN sample (Hello Triangles Project). I do not know why it could not render anything to screen except clearing the screen with blue color.

Could you have a look at my code to see what problem is... I got stuck here for 2 days.

 

TestD3D12.7z

Edited by VietNN

Share this post


Link to post
Share on other sites
Advertisement

One thing that stands out to me:

struct Vertex {
	XMFLOAT3 position;
	XMFLOAT4 color;
};

Here you have a float3 for position; which is matched by your input-signature declaration.

PSInput VSMain(float4 position : POSITION, float4 color : COLOR)
{
	PSInput result;

	result.position = position;
	result.color = color;

	return result;
}

But the Vertex-shader receives a float4. Even if this were technically legal (not sure in DX12), this probably means that the w-component is 0.0f, while it should actually be 1.0f when output from the vertex-shader w/o any persective transform, as is the case for you. I'd suggest trying:

PSInput VSMain(float3 position : POSITION, float4 color : COLOR)
{
	PSInput result;

	result.position.xyz = position;
        result.position.w = 1.0f;
	result.color = color;

	return result;

and see if this works.

 

Share this post


Link to post
Share on other sites

Where are you setting your viewport and scissor rectangle? (m_viewport and m_scissorRect)

This is exactly what happens when you copy from multiple sources and smash it all together without reading things through.

Anyway, it will work once you initialize those

Edit: 

Juliean is write about using a float3 instead of a float4. Weird enough though, the w component actually gets default initialized to 1.0f, and as Juliean mentioned you would have assumed it was being zero initialized, this is a good reason to be explicit

Share this post


Link to post
Share on other sites

First, I want to thank  iedoc and Juliean

That was my ridiculous mistake when quickly copy and paste

Actuallly, I was working on a bigger project, porting that project from D3D11 to D3D12 and met such an issue. Do not know why it could not render anything to screen. Because resource is huge, I can not upload it all here.

I am sure that I set m_viewport and m_scissorRect already on that project :). Here is my work:

- On init: (using commandlist 1, commandAllocator1)

     +Create Vertex buffer (default heap and upload heap)

     +Execute commandlist

     +Sleep(1000): maybe do not need but just to make sure init command was finished on GPU before render.

- On Render: (using commandlist 2, commandAllocator 2, same commandQueue)

      +Transition Vertex buffer from COPY_DEST to VERTEX_BUFFER

      +Transition backbuffer to PRESENT to RENDER_TARGET

      +OMSetRenderTargets

      +ClearRendertarget

      +SetViewport and scissor (sure it has value)

      +SetGraphicsRootSignature and PipelineState (using same root and pipeline as above example because I just want to draw triangle, VertexShader use position as float3 and inputlayout is float3 also)

      +IASetVertexBuffers

      +IASetPrimitiveTopology

      +DrawInstanced

      +Transition backbuffer to RENDER_TARGET to PRESENT

      +Execute commandlist

      +Present()

      +Update frame index

- I can see clear color, if I set clear color different each frame and set break point at present(), i can see it changed color each times but no triangles. Could you guys please show me if i miss any step.

Note: Sometimes, I can see that triangles blink at first launch and disappear.

Edited by VietNN

Share this post


Link to post
Share on other sites

I think I found problem with VertexBuffers, if I use a temp VertexBuffers it can draw. Need more time to investigate, thank you all :)

Edited by VietNN

Share this post


Link to post
Share on other sites

Thank you all, problem solved. I forgot the cull mode, using default rasterize state set cullmode to BACK. That make me can not draw anything

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!