Sign in to follow this  

Problem getting value with HLSL (GetFloat)

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4030 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this