Note that there are some explanatory texts on larger screens.

plurals
  1. PODirectX using multiple Render Targets as input to each other
    text
    copied!<p>I have a fairly simple DirectX 11 framework setup that I want to use for various 2D simulations. I am currently trying to implement the 2D Wave Equation on the GPU. It requires I keep the grid state of the simulation at 2 previous timesteps in order to compute the new one.</p> <p>How I went about it was this - I have a class called FrameBuffer, which has the following public methods:</p> <pre><code>bool Initialize(D3DGraphicsObject* graphicsObject, int width, int height); void BeginRender(float clearRed, float clearGreen, float clearBlue, float clearAlpha) const; void EndRender() const; // Return a pointer to the underlying texture resource const ID3D11ShaderResourceView* GetTextureResource() const; </code></pre> <p>In my main draw loop I have an array of 3 of these buffers. Every loop I use the textures from the previous 2 buffers as inputs to the next frame buffer and I also draw any user input to change the simulation state. I then draw the result. </p> <pre><code> int nextStep = simStep+1; if (nextStep &gt; 2) nextStep = 0; mFrameArray[nextStep]-&gt;BeginRender(0.0f,0.0f,0.0f,1.0f); { mGraphicsObj-&gt;SetZBufferState(false); mQuad-&gt;GetRenderer()-&gt;RenderBuffers(d3dGraphicsObj-&gt;GetDeviceContext()); ID3D11ShaderResourceView* texArray[2] = { mFrameArray[simStep]-&gt;GetTextureResource(), mFrameArray[prevStep]-&gt;GetTextureResource() }; result = mWaveShader-&gt;Render(d3dGraphicsObj, mQuad-&gt;GetRenderer()-&gt;GetIndexCount(), texArray); if (!result) return false; // perform any extra input I_InputSystem *inputSystem = ServiceProvider::Instance().GetInputSystem(); if (inputSystem-&gt;IsMouseLeftDown()) { int x,y; inputSystem-&gt;GetMousePos(x,y); int width,height; mGraphicsObj-&gt;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-&gt;mTransform.position = Vector3f(xPos,-yPos,0); result = mColorQuad-&gt;Render(&amp;viewMatrix,&amp;orthoMatrix); if (!result) return false; } mGraphicsObj-&gt;SetZBufferState(true); } mFrameArray[nextStep]-&gt;EndRender(); prevStep = simStep; simStep = nextStep; ID3D11ShaderResourceView* currTexture = mFrameArray[nextStep]-&gt;GetTextureResource(); // Render texture to screen mGraphicsObj-&gt;SetZBufferState(false); mQuad-&gt;SetTexture(currTexture); result = mQuad-&gt;Render(&amp;viewMatrix,&amp;orthoMatrix); if (!result) return false; mGraphicsObj-&gt;SetZBufferState(true); </code></pre> <p>The problem is nothing is happening. Whatever I draw appears on the screen(I draw using a small quad) but no part of the simulation is actually ran. I can provide the shader code if required, but I am certain it works since I've implemented this before on the CPU using the same algorithm. I'm just not certain how well D3D render targets work and if I'm just drawing wrong every frame.</p> <p>EDIT 1: Here is the code for the begin and end render functions of the frame buffers:</p> <pre><code>void D3DFrameBuffer::BeginRender(float clearRed, float clearGreen, float clearBlue, float clearAlpha) const { ID3D11DeviceContext *context = pD3dGraphicsObject-&gt;GetDeviceContext(); context-&gt;OMSetRenderTargets(1, &amp;(mRenderTargetView._Myptr), pD3dGraphicsObject-&gt;GetDepthStencilView()); float color[4]; // Setup the color to clear the buffer to. color[0] = clearRed; color[1] = clearGreen; color[2] = clearBlue; color[3] = clearAlpha; // Clear the back buffer. context-&gt;ClearRenderTargetView(mRenderTargetView.get(), color); // Clear the depth buffer. context-&gt;ClearDepthStencilView(pD3dGraphicsObject-&gt;GetDepthStencilView(), D3D11_CLEAR_DEPTH, 1.0f, 0); void D3DFrameBuffer::EndRender() const { pD3dGraphicsObject-&gt;SetBackBufferRenderTarget(); } </code></pre> <p><strong>Edit 2</strong> Ok, I after I set up the DirectX debug layer I saw that I was using an SRV as a render target while it was still bound to the Pixel stage in out of the shaders. I fixed that by setting shader resources to NULL after I render with the wave shader, but the problem still persists - nothing actually gets ran or updated. I took the render target code from here and slightly modified it, if its any help: <a href="http://rastertek.com/dx11tut22.html" rel="nofollow">http://rastertek.com/dx11tut22.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload