having lots of g_pTechnique->GetPassByIndex( 0 )->Apply( 0 );

Started by
5 comments, last by satanir 10 years, 5 months ago

I have some parts in my code where I have something like this

g_p2DTa->SetResource( NULL );
g_p2DTb->SetResource( NULL );
g_p2DTc->SetResource( NULL );
g_p2DTe->SetResource( NULL );
g_p2DTf->SetResource( NULL );
g_p2DTg->SetResource( NULL );
g_p2DTk->SetResource( NULL );
g_pTechniqueFoP->GetPassByIndex( 0 )->Apply( 0 );
g_pTechnique3DSpace->GetPassByIndex( 0 )->Apply( 0 );
g_pTechniqueAirFric->GetPassByIndex( 0 )->Apply( 0 );
g_pTechniqueFoP->GetPassByIndex( 0 )->Apply( 0 );
g_pTechnique3DaddF->GetPassByIndex( 0 )->Apply( 0 );
g_pTechniqueJointsFo->GetPassByIndex( 0 )->Apply( 0 );
g_pTechniqueGYFo->GetPassByIndex( 0 )->Apply( 0 );
g_pTechniquePYFo->GetPassByIndex( 0 )->Apply( 0 );
g_pTechniqueCubeFo->GetPassByIndex( 0 )->Apply( 0 );
Is this normal? is there another performance faster way?
Advertisement

I'm curious what you are doing that uses that many different techniques.

Also, not sure whether this is a typo or not, but you have :


g_pTechniqueFoP->GetPassByIndex( 0 )->Apply( 0 );

executed twice.

Eric Richards

SlimDX tutorials - http://www.richardssoftware.net/

Twitter - @EricRichards22

Is this a single block of code? It's not clear what you are trying to do. Is this to get rid of the warning about bound SRV when calling OMSetRenderTargets()?

Anyway, when you call Apply(), it essentially sets the state for the requested pass. Your code basically sets the state for 10 different passes - but only the last one counts. Call Apply() only before executing the pass.

yes is because of the warnings about bound SRV when calling OMSetRenderTargets()

So what i think I am doing there is unbounding all those SRV that were used on those Techniques

a single Technique doens't uses all those SRV, just some of them.

I have something like this


g_p2DTa->SetResource( SRVa );
set other things....
g_pTechniqueFoP->GetPassByIndex( 0 )->Apply( 0 );
g_pd3dDevice->DrawIndexed( 240, 0, 0);

g_p2DTb->SetResource( SRVb );
g_p2DTc->SetResource( SRVc );
set other things....
g_pTechnique3DSpace->GetPassByIndex( 0 )->Apply( 0 ); //this thechnique uses too SRVa
g_pd3dDevice->DrawIndexed( 4235, 0, 0);


g_p2DTe->SetResource( SRVe );
set other things....
g_pTechniqueGYFo->GetPassByIndex( 0 )->Apply( 0 ); //this thechnique uses tooSRVa, SRVc

g_pd3dDevice->DrawIndexed( 2367, 0, 0);
.....
.....and more and more
.....

and at the end, I make lots of GetPassByIndex( 0 )->Apply( 0 ); to unbound all those SRV

the twice execution of g_pTechniqueFoP->GetPassByIndex( 0 )->Apply( 0 ); was my mistake

I usually ignore that warning. I don't understand why this is a warning and not an info message as this behavior is exactly as described in the API.

If you still want to get rid of it:

1. My techniques are wrapped inside classes. This abstracts the effect system from my renderer. It also makes state management a lot easier - each class manages its own state, and the technique draw routine looks like:


// Save non-shader related state objects(rasterizer state, output merger state, etc.) Doesn't save shaders, CBs, SRVs
// Set state
// Draw
// Restore saved state

If you have a similar design, than the you can clear the SRV slots used by the technique in the last phase.

2. A faster way to clear all SRVs that doesn't require a design change is:


NullSRV[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT] = {0};
pCtx->PSSetShaderResources(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, NullSRV);

I had stuck this idea from the start were I tough if I don't unbound then there will be a reading or rendering error.

So now I know it doens't need to be done, thanks

One thing to be really careful about is that it doesn't work the other way - If you have a resource bound as RTV, and you try to bound it as SRV, the SRV will not actually be bound, and the slot will be set to NULL.

You can think of that as RTV always takes precedence when bounding resources.

This topic is closed to new replies.

Advertisement