c++ - DirectX using multiple Render Targets as input to each other -


i have simple directx 11 framework setup want use various 2d simulations. trying implement 2d wave equation on gpu. requires keep grid state of simulation @ 2 previous timesteps in order compute new one.

how went - have class called framebuffer, has following public methods:

bool initialize(d3dgraphicsobject* graphicsobject, int width, int height);  void beginrender(float clearred, float cleargreen, float clearblue, float clearalpha) const; void endrender() const;  // return pointer underlying texture resource const id3d11shaderresourceview* gettextureresource() const; 

in main draw loop have array of 3 of these buffers. every loop use textures previous 2 buffers inputs next frame buffer , draw user input change simulation state. draw result.

    int nextstep = simstep+1;     if (nextstep > 2)         nextstep = 0;      mframearray[nextstep]->beginrender(0.0f,0.0f,0.0f,1.0f);     {         mgraphicsobj->setzbufferstate(false);         mquad->getrenderer()->renderbuffers(d3dgraphicsobj->getdevicecontext());         id3d11shaderresourceview* texarray[2] = { mframearray[simstep]->gettextureresource(),                                                   mframearray[prevstep]->gettextureresource() };         result = mwaveshader->render(d3dgraphicsobj, mquad->getrenderer()->getindexcount(), texarray);         if (!result)             return false;         // perform input         i_inputsystem *inputsystem = serviceprovider::instance().getinputsystem();         if (inputsystem->ismouseleftdown()) {             int x,y;             inputsystem->getmousepos(x,y);             int width,height;             mgraphicsobj->getscreendimensions(width,height);             float xpos = mapvalue((float)x,0.0f,(float)width,-1.0f,1.0f);             float ypos = mapvalue((float)y,0.0f,(float)height,-1.0f,1.0f);             mcolorquad->mtransform.position = vector3f(xpos,-ypos,0);             result = mcolorquad->render(&viewmatrix,&orthomatrix);             if (!result)                 return false;         }         mgraphicsobj->setzbufferstate(true);     }     mframearray[nextstep]->endrender();      prevstep = simstep;     simstep = nextstep;      id3d11shaderresourceview* currtexture = mframearray[nextstep]->gettextureresource();      // render texture screen     mgraphicsobj->setzbufferstate(false);     mquad->settexture(currtexture);     result = mquad->render(&viewmatrix,&orthomatrix);     if (!result)         return false;     mgraphicsobj->setzbufferstate(true); 

the problem nothing happening. whatever draw appears on screen(i draw using small quad) no part of simulation ran. can provide shader code if required, works since i've implemented before on cpu using same algorithm. i'm not how d3d render targets work , if i'm drawing wrong every frame.

edit 1: here code begin , end render functions of frame buffers:

void d3dframebuffer::beginrender(float clearred, float cleargreen, float clearblue, float clearalpha) const {    id3d11devicecontext *context = pd3dgraphicsobject->getdevicecontext();  context->omsetrendertargets(1, &(mrendertargetview._myptr), pd3dgraphicsobject->getdepthstencilview());  float color[4];  // setup color clear buffer to. color[0] = clearred; color[1] = cleargreen; color[2] = clearblue; color[3] = clearalpha;  // clear buffer. context->clearrendertargetview(mrendertargetview.get(), color);  // clear depth buffer. context->cleardepthstencilview(pd3dgraphicsobject->getdepthstencilview(), d3d11_clear_depth, 1.0f, 0);  void d3dframebuffer::endrender() const {     pd3dgraphicsobject->setbackbufferrendertarget(); } 

edit 2 ok, after set directx debug layer saw using srv render target while still bound pixel stage in out of shaders. fixed setting shader resources null after render wave shader, problem still persists - nothing gets ran or updated. took render target code here , modified it, if help: http://rastertek.com/dx11tut22.html

okay, understand correct need multipass-rendering texture.

basiacally i've described here: link

  • you creating srvs both d3d11_bind_shader_resource , d3d11_bind_render_target bind flags.
  • you ctreating render targets textures
  • you set first texture input (*setshaderresources()) , second texture output (omsetrendertargets())
  • you draw()*
  • then bind second texture input, , third output
  • draw()*
  • etc.

additional advices:

  1. if target gpu capable write uavs non-compute shaders, can use it. more simple , less error prone.
  2. if target gpu suitable, consider using compute shader. pleasure.
  3. don't forget enable directx debug layer. make obvious errors , debug output can point them.
  4. use graphics debugger review textures after each draw call.

edit 1:

as see, call beginrender , omsetrendertargets once, so, rendering goes mrendertargetview. need interleave:

setsrv(texture1); setrt(texture2); draw(); setsrv(texture2); setrt(texture3); draw(); setsrv(texture3); setrt(backbuffer); draw(); 

also, don't know mrendertargetview yet.

so, before

result = mcolorquad->render(&viewmatrix,&orthomatrix); 

somewhere must omsetrendertargets .

probably, s better review begin()/end() design, make resource binding more visible.

happy coding! =)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -