Check contents of a Vertex Buffer

Started by
26 comments, last by AussieSpoon 11 years, 3 months ago

Ok I think I did this right,

z41iW.jpg?1

and:

h5HO1.jpg?1

and:

41Pzq.jpg?1

The values do seem right so I'm not sure, what else is potentially wrong

Thanks

EDIT: Actually my index buffer has incorrect values, the array values I create are correct , then I just memcpy the array to a pointer. But the index buffer is wrong, so I will work on that

Advertisement

If you actually browse to your drawcall you can get a lot more detailed information about the vertex buffer, by doing what you are currently doing you will only see the input buffer not the transformed one after the VS has run. And it can well be that your input buffer is correct but the output of the vertex shader isn't, I am assuming you are using a vertex shader here. Even if you are not using a vertex shader looking at when the drawcall is submitted will give you an idea of whether your transforms are correctly transforming your vertices in the buffer. Also it will tell you whether they are within the viewport or not which can also affect what you see on screen.
So just hit the plus on that frame you captured and look through the drawcalls till you find something that is rendering with that vertex buffer. By the way if you extend the list of a frame it will show you which commands your are actually sending to the D3D runtime from your application. Hit F1 in pix and look for this subject in the help file "View Buffer Data" checking out subject "View Mesh Data" is also a good idea. You can find this in the DirectX Software Development Kit help file under:


-DirectX Software Development Kit
  -Tools
    -DirectX Performance Tools
      -PIX
        -Tutorials and Samples

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This is what I had in mind by a screenshot of PIX with actual information in it.

[attachment=13231:Part1.png]

[attachment=13232:Part2.png]

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

1st Draw Call (Pre VS):

jFjGQ.jpg?1

1st Draw Call (Post VS):

Wre2X.jpg?1

2nd (Last) Draw Call (Both PreVS and Post VS are the same):

hvOtN.jpg?1

Device info:

BxFjF.jpg?1

The first Draw indexed primitive seems to have correct Position (not sure why there are 4 though) and Text Co-ord values but no colour values. (Am I reading that right?)

Then the 2nd draw call look completely wrong.

And I'm not sure what to look at for the device.

One problem at a time.

Do you think there is anything you can glean from that second draw call?

Why would the input buffer have positions all-0’s and the index buffer be fubar…?

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Do you think there is anything you can glean from that second draw call?

Why would the input buffer have positions all-0’s and the index buffer be fubar…?

From what I can tell (since I've never used this before).

(Assumuming Prim = Primative ie. 1 triangle, VTX = Vertex and IDX = index)

Then the index buffer has the correct values, and the VB is using them the way I want. But the values of each Vertex are worng, also there is a 4th value for position and I'm not sure why. I'm using D3DXVECTOR3 so not sure if that has an extra value I am unaware of?

So I somehow have to find what is changing the values in the VB, right?

Thanks

You will always see 4 values in the position, internally setting a vector 4 is faster on most hardware then setting a vector 3, and thats why you see that fourth value.

It seems that you are overwriting your index buffer in between your draw calls, you might want to have a careful look at how you fill these. Also in the SetStreamSource call for the second draw is using an offset of 36 instead of 24 like the first one, why is this as that might be why you are skipping 2 verts at a time. Have a look at your vertex declarations in PIX as they will tell you what your stride size should be

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

It seems that you are overwriting your index buffer in between your draw calls, you might want to have a careful look at how you fill these. Also in the SetStreamSource call for the second draw is using an offset of 36 instead of 24 like the first one, why is this as that might be why you are skipping 2 verts at a time. Have a look at your vertex declarations in PIX as they will tell you what your stride size should be

My index buffer is only filled once, (During initialization)

Here is how I fill it


//Creation
if(FAILED( g_pd3dDevice->CreateIndexBuffer(s_nBatchSize * 6, 0, 
	D3DFMT_INDEX32, D3DPOOL_DEFAULT ,&m_pIB, NULL)))

//Filling only done once
// Lock the index buffer
VOID* pIndices;
m_pIB->Lock(0, s_nBatchSize * 6, (void**)&pIndices, 0);

uINT indices[s_nBatchSize * 6];//Because for a quad you need 4 verts and 6 indicies
uINT indexCounter = 0;//used to store a value that helps set the correct indicie value
for(uINT i = 0; i < s_nBatchSize * 6; i += 6)
{
	//Set 6 values that use 4 verticies
	//0, 1, 2  Triangle 1		
	indices[i + 0] = (indexCounter * 4 + 0);
	indices[i + 1] = (indexCounter * 4 + 1);
	indices[i + 2] = (indexCounter * 4 + 2);
	//2, 1, 3  Triangle 2		
        indices[i + 3] = (indexCounter * 4 + 2);
	indices[i + 4] = (indexCounter * 4 + 1);
	indices[i + 5] = (indexCounter * 4 + 3);

	//Increase the index counter to get the right values
	++indexCounter;
}

memcpy(pIndices, indices, sizeof(indices) / sizeof(indices[0]));//sizeof(indices) / sizeof(indices[0]) = number of elements in the array 


// Unlock it
m_pIB->Unlock();

Does that look right?

"second draw is using an offset of 36 instead of 24"

I can't figure this out, I don't know where the first one is coming from, it only gets called once per frame atm, so I have no idea what is calling it


g_pd3dDevice->SetStreamSource(0, m_pVB, nRenderOffset, sizeof( SpriteVertex ));

Interestingly though, sizeof (SpriteVetex) = 36 but when I put 24 in there instead I ACTUALLY SEE A SPRITE RENDERED I'm not sure what this means though.

One thing I just want check though as I am unfimiliar with them is my Vertex Declaration.

Do these two add up?:


//VERTEX
struct SpriteVertex
{
	D3DXVECTOR3		vPos;
	D3DXCOLOR		Colour;
	uINT			u1, v1;
};

//VERTEX DECLARATION 

D3DVERTEXELEMENT9 Sprite_Decl[] =
{
	{0, 0,  D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
	{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
	{0, 24, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
	D3DDECL_END() // this macro is needed as the last item!
};

Thanks

D3DXCOLOR looks like this: http://msdn.microsoft.com/en-us/library/windows/desktop/bb172730%28v=vs.85%29.aspx


struct D3DXCOLOR
{
    float r,g,b,a;
}

Which means it's 16 bytes big so you have D3DXVector3 = 12 bytes + D3DXCOLOR = 16 + uint = 4 bytes * 2 = 36 bytes, which happens to be the same thing sizeof(SpriteVertex) will return. Your vertex declaration however tells D3D that the color value is only a DWORD big which is 4 bytes.
If you define your SpriteVertex as:


struct SpriteVertex
{
   D3DXVector3 position;
   DWORD color;//This is the same as D3DCOLOR
   unsigned int u, v;
}

This will match your vertex declaration and will make your sprite buffer work again, there are helper functions in D3DX that allow you to transform a 4 float value into a dword(http://msdn.microsoft.com/en-us/library/windows/desktop/bb172518%28v=vs.85%29.aspx).

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This will match your vertex declaration and will make your sprite buffer work again, there are helper functions in D3DX that allow you to transform a 4 float value into a dword(http://msdn.microsoft.com/en-us/library/windows/desktop/bb172518%28v=vs.85%29.aspx).

I'm kind of confused by this.

Is it ok to write:


DWORD tColour = (*itCurr)->GetColour();//GetColour(): returns a D3DXCOLOR
//Then to change a vertex's color:
pVertex[VertexCounter].Colour = tColour;

This topic is closed to new replies.

Advertisement