Skip to main content
gamedev.net
🔒 Locked

render target problem

Started by veoon Apr 15, 2011 at 9:44 PM 2 replies 1.5k views
Original Post
veoon
veoon
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:

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;


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);
}


Any help on how to make this work would be appreciated.
MJP
MJP
Calling OMSetRenderTarget(0, NULL, NULL) doesn't do anything. You need to actually set slot 0 to NULL, like this:

ID3D11RenderTargetView* nullRT[1] = { NULL };
device->OMSetRenderTargets(1, nullRT, NULL);
veoon
veoon
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).
veoon
veoon
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:

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;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.