Problem getting value with HLSL (GetFloat)

Started by
5 comments, last by jollyjeffers 17 years, 4 months ago
Hi, I'm trying to get the number of vertex processed by an effect, so I thought it could be possible to maintain a shared variable and increment by 1 on each vertex shader call. So I set this variable as global in the shader, named: extern shared float gVertices; and on each shader call, I put: gVertices++; The problem is that, after the scene is done, I read the value with: g_pEffect->GetFloat( g_hVertices, &nVertices ); // g_hVertices is a handle to the vertex variable gVertices and nVertices always is 0. I've tried to put the GetFloat call before the EndPass call, before the EndScene, etc... and it always gives 0. Any suggestion? Is possible to get the number of vertex processed in a scene using HLSL? Thanks in advance
Advertisement
HLSL works different than C.

Global variables will be reset every time the shader is invoked (every vertex or pixel). Therefore you could not use them as counter.

The GetX methods only returns the values that were set with the SetX methods or defined in the FX file.
Thanks for the quick reply, Demirug

So, which is the use of the "shared" modifier for the variables? Is it only for sharing values between effects but not between same effect shader calls?

BTW, any other idea to get the number of vertex passed thought the pipeline? Maybe storing this value in texture data so it can be retrieved from the CPU?

Thanks again
Shared is used to share variables between different effects that are in the same effect pool.

May I ask you why you need to number of vertex passed through the shader? Normally you could calculate this value easily from the draw calls.
Hello Demirug, and thanks again.
I thought it could be the easiest way to calculate the real number of vertex processed.
When you say it's easy to get this number from the draw calls, you mean that I have to sum manually the vertex number of each vertex buffer or mesh every time an object is passed through the pipeline? If I'm wrong, could you post some lines of code to get the idea?
Hi, I'd like also ask this question, Because i want to calculate the sum of all the pixel values. If the global variable is reset through every pixel, it seems a little difficult...

I know I can calculate the sum in CPU easily, but I still want to calculate the SUM of all pixels using GPUs, could you give me any suggestions?
Quote:I thought it could be the easiest way to calculate the real number of vertex processed.
There isn't an easy way, yet. You can use Queries (look them up in the docs) to get information on what the GPU really does but retail drivers rarely expose any interesting statistics. You need access to instrumented drivers for this.

Quote:When you say it's easy to get this number from the draw calls, you mean that I have to sum manually the vertex number of each vertex buffer or mesh every time an object is passed through the pipeline?
Correct.

Quote:I know I can calculate the sum in CPU easily, but I still want to calculate the SUM of all pixels using GPUs, could you give me any suggestions?
You need to provide more information - are you summing all pixels rendered in order to create the final scene or are you summing the pixels for a single image (e.g. post-processing)?

I'd recommend using stencil buffers to count the number of pixels rendered to the screen, but you're limited to an overdraw of 28 for an 8bit stencil.

Even with that you'll still need to look into post-processing to down-sample the image to generate a single "pixels drawn" value. There's plenty of information on post-processing online so I won't go into it in anymore detail here...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement