Sign in to follow this  
veoon

render target problem

Recommended Posts

veoon    100
Hello,

I registered to post this problem I have with Direct3D 10 concerning Render Targets.

I am building a small Fluid Simulator to get me started with DirectX 10.
I've been looking for a solution on the web for quite some time now to find the answer to my problem without too much success.

My problem can be easily explained, I guess.
You see, I have this method that runs given shader technique and takes a number of fields
to pipe as inputs (HLSL 4, by the way). The result will be written to the render target specified. Easy enough.

However, the method should also ensure, that any input and output fields are removed from the technique
before returning. But that seems to be the issue as the Debug Device gives me the "slot x is bound as output - forcing to NULL" warning for all input fields.

Obviously, I need to somehow unbind the render target here. But how exactly do I do that?

OMSetRenderTarget(0, NULL, NULL) does not suffice, as you can see:

[code]typedef struct
{
ID3D10Texture2D *p_rt;
ID3D10RenderTargetView* p_rtv;
ID3D10ShaderResourceView *p_srv;
void BindField() { pD3DDevice->OMSetRenderTargets(1, &p_rtv, NULL); }
void UnbindField() { pD3DDevice->OMGetRenderTargets(0, NULL, NULL);}
void BindResource(ID3D10EffectShaderResourceVariable* p) { p->SetResource(p_srv); }
void Release() { SAFE_RELEASE(p_rt); SAFE_RELEASE(p_rtv); SAFE_RELEASE(p_srv); }
} Field;[/code]

[code]void RunShader(LPCSTR technique, Field *pInField0, Field *pInField1, Field *pInField2,
Field *pInField3, Field *pInField4, Field *pInField5, Field *pOutField)
{
D3D10_TECHNIQUE_DESC techniqueDescription;
gQuad.pTechnique = gQuad.pEffect->GetTechniqueByName(technique);
gQuad.pTechnique->GetDesc(&techniqueDescription);
gQuad.pTechnique->GetPassByIndex(0)->Apply(0);

//set the output-field to be the render target
if (pOutField != NULL) pOutField->BindField();

//and send input-fields down the pipe
if (pInField0 != NULL) pInField0->BindResource(pInput0);
if (pInField1 != NULL) pInField1->BindResource(pInput1);
if (pInField2 != NULL) pInField2->BindResource(pInput2);
if (pInField3 != NULL) pInField3->BindResource(pInput3);
if (pInField4 != NULL) pInField2->BindResource(pInput4);
if (pInField5 != NULL) pInField3->BindResource(pInput5);

for(UINT i = 0; i < techniqueDescription.Passes; i++)
{
gQuad.pTechnique->GetPassByIndex(i)->Apply(0);
pD3DDevice->Draw(gQuad.numVertices, 0);
}

//if (pOutField != NULL) pOutField->UnbindField();
pD3DDevice->OMSetRenderTargets(0, NULL, NULL);
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);

//the following works ok
pInput0->SetResource(NULL); //<- ID3D10EffectShaderResourceVariable*
pInput1->SetResource(NULL);
pInput2->SetResource(NULL);
pInput3->SetResource(NULL);
pInput4->SetResource(NULL);
pInput5->SetResource(NULL);
gQuad.pTechnique->GetPassByIndex(0)->Apply(0);
}[/code]

Any help on how to make this work would be appreciated.

Share this post


Link to post
Share on other sites
MJP    19787
Calling OMSetRenderTarget(0, NULL, NULL) doesn't do anything. You need to actually set slot 0 to NULL, like this:
[code]
ID3D11RenderTargetView* nullRT[1] = { NULL };
device->OMSetRenderTargets(1, nullRT, NULL);
[/code]

Share this post


Link to post
Share on other sites
veoon    100
Thanks for your reply.

While I understand the difference, I figured that it still does not solve the issue I'm afraid.
From here, it looks like OMSetRenderTargets() is not able to remove render targets in DirectX10 at all, as the first argument is not marked as "slot id" but as number of views to be added in dx10.

I really do not get how this simple problem can be that demanding to solve without sacrificing a lot of additional memory (e.g. duplicating the RT for further use in other shaders).

Share this post


Link to post
Share on other sites
veoon    100
Ok, sorry for my doubts... You were right. Thank you very much. It does work that way, I just didn't see it at first glance. Here's the revised struct for future reference:

[code]ID3D10RenderTargetView* p_nrt = NULL;

typedef struct
{
ID3D10Texture2D *p_rt;
ID3D10RenderTargetView* p_rtv;
ID3D10ShaderResourceView *p_srv;
void BindField() { pD3DDevice->OMSetRenderTargets(1, &p_rtv, NULL); }
void UnbindField() { pD3DDevice->OMSetRenderTargets(1, &p_nrt, NULL); }
void BindResource(ID3D10EffectShaderResourceVariable* p) { p->SetResource(p_srv); }
void Release() { SAFE_RELEASE(p_rt); SAFE_RELEASE(p_rtv); SAFE_RELEASE(p_srv); }
} Field;[/code]

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