Viewing vertices transformed by DrawPrimitive

Started by
5 comments, last by Nik02 14 years, 1 month ago
Is there a way to view the x,y,z values of a vertex in a vertex buffer after the vertex has been transformed by DrawPrimitive in DirectX9? My first thought is to Lock the vertex buffer after the DrawPrimitive call, and just look at the values in the vertex buffer, but unless I'm mistaken the values in the vertex buffer are not changed by the DrawPrimitive call. But that's the type of thing I'm trying to do. How do I look at the verts after the DrawPrimitive call? Or perhaps there is a method that simulates the transformations done by DrawPrimitive so I can see the resultant values of the the transformation pipeline?
Advertisement
You can use PIX to ispect geometry before and after the transformations.

In D3D9, you can use ProcessVertices method to transform vertex data without drawing it (but in the CPU, not GPU). In D3D10 and up you could redirect the vertex shader's output to a "stream out buffer" (on GPU) which you can then reuse or download to the main memory.

You can of course also do the transformations yourself on the data. The DX SDK explains the innards of the fixed function pipeline transforms very thoroughly. In simplified terms:

v' = v * model * view * projection * viewport

where v' is the transformed vertex; v is the original vertex; model, view and projection are the transform matrices; and viewport transforms geometry from perspective space to screen space. The viewport transformation can easily be expressed as a matrix, even though it isn't actually set to the device in matrix form.

Niko Suni

PIX looks like a great tool. But what action do I use to inspect the geometry after the DrawPrimitive call?
You're correct, the vertex buffer values themselves are not changed by the DrawPrimitive call. The DrawPrimitive call results in the values being converted to screen locations and pixels by a vertex/pixel shader or the fixed function pipeline using the method described by Nik02, and then stored in the screen buffer for display.

You can "process" the vertices yourself to get those screen locations using the formula Nik02 mentions and examine v'.

If you're not sure about the process described, perhaps you can ask a more specific question. Or, if that's not what you're asking about, maybe you can be a bit more descriptive about what you mean by "inspect."

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Nik02 mentioned:
You can use PIX to [inspect] geometry before and after the transformations.

I am new to using the PIX tool. I checked it out and was able to generate a log of DirectX calls very easily. Yet having gone over all the options, I see no way to inspect the geometry (a vertex buffer) after a DrawPrimitive call.

By inspect I just mean look at the x,y,z values in the vertex buffer.
Do a single frame capture, and click on the "render" tab on the right. That'd run all the rendering that's been done, and allow you to view device status, etc. The "mesh" tab IIRC (don't have it in front of me) will show you the vertices before and after transformation.
PIX won't change the fact that the pipeline runs in one direction. The T/L pipe or shaders do not change the original geometry inside the vertex buffers. This is true even on D3D10 and up, even though newer APIs offer more flexible options of eventually looping back the geometry.

As Eyal said, PIX enables you to intercept your D3D calls so you see visually what the system does internally. As far as I remember, you cannot dump the intermediate transformed geometry to a file; however, I could be wrong, PIX evolves over time.

If you need the results as a raw data inside your own application, you need to either use the ProcessVertices method of the device object (so the device applies the same transforms as in drawing) or implement the transformation pipeline yourself (by multiplying the original vertices with the various transforms I listed on my first reply). Check the ProcessVertices documentation to see that it requires a separate destination vertex buffer that gets filled with the processed data.

Niko Suni

This topic is closed to new replies.

Advertisement