Jump to content
  • Advertisement
Sign in to follow this  
sicsic6

Using a texture as both a render target and source

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

I am new to DirectX 10 so pardon if my question is trivial. I did my share of googling and reading the documentation but couldnt find the answer. I am trying to create a texture that is both a render target as well as a source to a subsequent pass. I have tried playing with the usage/cpu access flags used in the texture creation and nothing seems to help. Can someone post a piece of code showing how to do this? Thanks!

Share this post


Link to post
Share on other sites
Advertisement

D3D10_TEXTURE2D_DESC desc =
{
mSurfaceWidth, mSurfaceHeight, 1, 1, // Width, Height, MipLevels, ArraySize
mSurfaceFormat, { 1, 0 }, D3D10_USAGE_DEFAULT, // Format, SampleDesc, Usage
D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET, // BindFlags
0, 0 // CPUAccessFlags, MiscFlags
};

mDevice->CreateTexture2D(&desc, NULL, &mTexture);
mDevice->CreateShaderResourceView(mTexture, NULL, &mShaderResourceView);
mDevice->CreateRenderTargetView(mTexture, NULL, &mRenderTargetView);



That's the code I use.

Share this post


Link to post
Share on other sites
ET3D,

Thanks for the reply. I was doing the same. Let me explain my actual problem.

I am trying to do something like this in my C++ application.

bool isPing = true;
for (int i = 0; i < N; i++) // N some number
{
if (isPing)
{
pd3dDevice->OMSetRenderTargets(1, &m_PingRTTexture.m_RenderTargetView, NULL);
// render to m_PingRTTexture. Source is m_PongRTTexture
m_SrcImageResource->SetResource(m_PongRTTexture.GetResourceView());
}
else
{
pd3dDevice->OMSetRenderTargets(1, &m_PongRTTexture.m_RenderTargetView, NULL);
// render to m_PongRTTexture. Source is m_PingRTTexture
m_SrcImageResource->SetResource(m_PingRTTexture.GetResourceView());
}
isPing = !isPing;
}

Here m_PingRTTexture, and m_PongRTTexture are two render target textures (my own C++ class, encapsulating the DX10 2D texture). In every iteration of my loop I want to swap the source and destination so that I can use the output of the previous iteration to be the input in the current iteration. m_SrcImageResource is a pointer to ID3D10EffectShaderResourceVariable and initially points to my 2D image. What am I doing wrong here? Again I am a beginner and I am sure I missed something very basic.

Thanks in advance for the help.

Share this post


Link to post
Share on other sites
I can't really say what's wrong. My code is similar and it works (I'm also ping-ponging). There may be some error further downstream, such as not using the correct render target. All I can suggest is that you try to create the simplest scenario that fails (does it fail with N=1?), and that you use PIX to gain a better understanding of what's happening.

Share this post


Link to post
Share on other sites
Here's what I am doing in OnCreateDevice().


m_BflyValsResource->SetResource(m_ButterflyTexture.GetResourceView());
m_SrcImageResource->SetResource(m_PongRTTexture.GetResourceView());

for (int pass = 0; pass < NumButterfliesX; pass++)
{
//m_PingVar->SetBool(isPing);
m_BflyPassNumVar->SetInt(pass);

isPing = !isPing;
ID3D10ShaderResourceView *const pSRV[1] = {NULL};
pd3dDevice->PSSetShaderResources(0, 1, pSRV);

// Horizontal pass
if (isPing)
{
pd3dDevice->OMSetRenderTargets(1, &m_PingRTTexture.m_RenderTargetView, NULL);
m_SrcImageResource->SetResource(m_PongRTTexture.GetResourceView());
}
else
{
pd3dDevice->OMSetRenderTargets(1, &m_PongRTTexture.m_RenderTargetView, NULL);
m_SrcImageResource->SetResource(m_PingRTTexture.GetResourceView());
}
m_BflyValsResource->SetResource(m_ButterflyTexture.GetResourceView());
Render(pd3dDevice, m_HScrambleTechnique);

}
for (int pass = 0; pass < NumButterfliesX; pass++)
{
//m_PingVar->SetBool(isPing);
m_BflyPassNumVar->SetInt(pass);

isPing = !isPing;
ID3D10ShaderResourceView *const pSRV[1] = {NULL};
pd3dDevice->PSSetShaderResources(0, 1, pSRV);

// Vertical pass
if (isPing)
{
pd3dDevice->OMSetRenderTargets(1, &m_PingRTTexture.m_RenderTargetView, NULL);
m_SrcImageResource->SetResource(m_PongRTTexture.GetResourceView());
}
else
{
pd3dDevice->OMSetRenderTargets(1, &m_PongRTTexture.m_RenderTargetView, NULL);
m_SrcImageResource->SetResource(m_PingRTTexture.GetResourceView());
}
m_BflyValsResource->SetResource(m_ButterflyTexture.GetResourceView());
Render(pd3dDevice, m_VScrambleTechnique);
}




And in OnFrameRender() function I do


if (isPing)
{
m_SrcImageResource->SetResource(m_PingRTTexture.GetResourceView());
//pd3dDevice->OMSetRenderTargets(1, &m_PingRTTexture.m_RenderTargetView, NULL);
}
else
{
m_SrcImageResource->SetResource(m_PongRTTexture.GetResourceView());
//pd3dDevice->OMSetRenderTargets(1, &m_PongRTTexture.m_RenderTargetView, NULL);
}
m_BflyValsResource->SetResource(m_ButterflyTexture.GetResourceView());
Render(pd3dDevice, m_DisplayTechnique);




PIX, for some reason takes me to the wrong pixel shader when I am debugging. Maybe I am doing something wrong. But can you see anything obviously wrong in the above piece of code?

Thanks again!

[Edited by - sicsic6 on June 16, 2008 3:25:24 PM]

Share this post


Link to post
Share on other sites
Without some more explanation it'd be hard to get into this code, and I don't think I want to, anyway. It looks like you're creating texture content programmatically during OnCreateDevice then using it when rendering a frame.

Your Render function isn't included, and it may be that the problem is something silly like not applying the technique (so your resources aren't changed). As I said, I don't know, and I don't really want to spend a lot of time on this.

My suggestion of trying a simpler scenario still stands. Reducing the number of pingpongs and so on will help you find out where things go wrong.

Regarding PIX, I find that looking at the device state is usually helpful. You should be able to see what render targets are set and what values you have in the constant buffer for each call. That should tell you something about what's wrong.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!