Sign in to follow this  

Passing Computations from VS to PS

This topic is 822 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

Dear All

I have done some matrix calculations in the VS that I want to re utilize in the PS.

The problem I am having is that the slots of my PS buffer are already taken.

Any thoughts on how can I read those computations from the PS previous done in the VS?

Thanks!

Share this post


Link to post
Share on other sites
The only way to pass data from the VS to the PS is through interpolants. Is this what you mean when you say that "slots of my PS buffer"?

On certain GPU's having too many interpolants can be bad for performance, so I wouldn't recommend trying to use a lot of them just to save a few computations in the pixel shader. How much data are you trying to pass from the VS to the PS?

Share this post


Link to post
Share on other sites
Thanks MJP.

The VS_OUTPUT struct of the vertex shader already uses most of the available TEXCOORD variables and I am looking to pass two matrices over to the pixel shader (i.e. two float4x4 variables).

As I am doing this via shader injection at D3DCompile time, I don't have access to the C++ side which would enable me to possibly pass the variables to the pixel shader otherwise - it has to be done via a vertex-to-pixel shader technique. However, I cannot think of one, apart from using VS_OUTPUT TEXCOORD variables, but in this case they're not enough (two float4x4s require 8 TEXCOORDs and there are 10 used by the vertex shader already).

Any further ideas?

Share this post


Link to post
Share on other sites

The matrix computation code in the vertex shader (not my code) is quite complex and has many branches depending on material flags etc.

 

When you say "use shader constants" - I tried to do that:

 

1) I enabled D3DCOMPILE_ENABLE_BACKWARDS_COMPATIBILITY

2) I placed two global variables "matrix_1", "matrix_2" in the shader code, whereby inside the Vertex Shader, I populate them (right before the return statement) like so:

matrix matrix_1;

matrix matrix_2;

 

VS_OUTPUT VS( VS_INPUT In )
{
    VS_OUTPUT Out = (VS_OUTPUT) 0;
   

    ... (other code calculating various things) ...

    matrix_1 = calculatedMatrix1;

    matrix_2 = calculatedMatrix2;

    return Out;
}

float4 PS(VS_OUTPUT In) : SV_TARGET
{

    // check variable contents of matrix_1 and matrix_2 - doesn't work...
};


Is that what you had in mind with 'shader constants'?

I also tried to add them to constant buffers used (with the same compatibility flag), populate them in the vertex shader so that the pixel shader will receive values, that didn't work either.

As I said earlier in my posts, TEXCOORD0 to TEXCOORD11 are taken already, so I can't use the 8 TEXCOORDs required for storing 2 float4x4 variables...

Thanks for your help!

Edited by fs1

Share this post


Link to post
Share on other sites
Semantics-wise, since D3D10 (SM4) you don't have the restriction to use TEXCOORD for "custom" interpolators anymore. Also you can use almost arbitrary indices, e.g. you can use MYVERYOWNSEMANTIC1024 (Edit: As long as they don't collide with system value semantics).
 
There's a limit on the total count though. Can't find a doc entry, but I checked with the command line compiler:
 
For SM4 : 16 interpolators (4 channels)
For SM5 : 32 interpolators  (4 channels)
 
 
Check if you really need that a lot. E.g. for affine transformations you should only need float3x4. You could also reduce the number if you don't need interpolants (HLSL nointerpolation) and e.g. pack two 16 bit integers into a 32 bit integers and unpack in the PS.

Share this post


Link to post
Share on other sites

Thanks,

 

that worked just fine - I defined my own interpolators as you said - I was quite unaware that you can do that in D3D10 (and later).

 

your help was much appreciated!

Edited by fs1

Share this post


Link to post
Share on other sites

This topic is 822 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