Sign in to follow this  
wforl

Shader Resource Views

Recommended Posts

Im wanting to create a few post process effects for my renderer, which involve using whats currently in the back buffer and depth buffer as shader textures in the following fashion.

void Renderer::SomePostEffect()
{
   // Get and store current targets
   ID3D10RenderTargetView *pBackBuffer = 0;
   ID3D10DepthStencilView *pDepthBuffer = 0;
   m_pD3dDevice->OMGetRenderTargets(1, &pBackBuffer, &pDepthBuffer);

   ID3D10ShaderResourceView *pBackBufferShaderView = ????
   HR(m_pFXBackBuffer->AsShaderResource()->SetResource(pBackBufferShaderView);

   ID3D10ShaderResourceView *pDepthBufferShaderView = ????
   HR(m_pFXDepthBuffer->AsShaderResource()->SetResource(pDepthBufferShaderView);

   // Set new targets (unbinds old ones)
   m_pRenderTarget->Bind();

      // do something with backbuffers as shader textures
      m_pFXTech->GetPassByIndex(0)->Apply(0);
	
   // restore old targets
   m_pD3dDevice->OMSetRenderTargets(1, pColour, pDepthStencil);

   //do something with result
}



But as you can see, Im wondering how i would debind the current back buffer and dpeth buffer to use as shader resources. Other than creating a shader resource views to them when they were created. Or to create the view every frame, which seems over the top. But if at all possible, i would like do it with only the data i have above. Is this possible? cheers

Share this post


Link to post
Share on other sites
The most common way that I have seen it is to have a centralized data structure that relates any created resource views to the resource. Something like a map of structures that take the resource pointer as the key and the structures hold pointers to all of the possible views.

This allows for quick lookup of the needed resource view without creating a new one every frame (which would be detrimental to performance). Is that a possibility?

Share this post


Link to post
Share on other sites
Hmm. Thanks for the reply. I will look into to it, to see how I could intergrate that functionality. I take it you mean some sort of global map?

The way i have designed my system so far is that the renderer knows nothing about the window or buffers that are currently bound. All it has is a D3dDevice pointer, which it can retrieve some information from. But as another idea to your suggestion, i guess i could bind some sort of "DirectXView" to the renderer before rendering. Where a DirectXView could encapsulate data such as the window handle, depth and back buffers, and all views to those buffers.

This would also work nicely with my proposed editor, which will have 4 rendering views (4 windows), similar to 3d applications like Max and Maya. Enabling me to do something like.


Render()
{
g_pEngine->GetRenderer()->BindView(TopRViewPort);
g_pEngine->GetRenderer()->RenderScene();

g_pEngine->GetRenderer()->BindView(BotLViewPort);
g_pEngine->GetRenderer()->RenderScene();

g_pEngine->GetRenderer()->BindView(TopLViewPort);
g_pEngine->GetRenderer()->RenderScene();

g_pEngine->GetRenderer()->BindView(TopRViewPort);
g_pEngine->GetRenderer()->RenderScene();
}




And for a single window application like a game, it would simply be


Render()
{
g_pEngine->GetRenderer()->BindView(GameView);
g_pEngine->GetRenderer()->RenderScene();
}




Any thoughts?

Share this post


Link to post
Share on other sites

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