Jump to content
  • Advertisement

binder2

Member
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About binder2

  • Rank
    Newbie

Personal Information

  • Interests
    Programming
  1. binder2

    DX11 Render Target Picking

    Thanks for the replies. The reason I was doing picking this way is that it seemed like a much simpler approach, as it just works, no matter how complicated the geometry is. Testing the geometry on the CPU is a lot more work (programming wise), it also means I would need to have a copy of the geometry on the CPU as well as the GPU, which I currently don't have. The suggestion for doing the picking on the GPU sounds very clever. My only issue with that is that I also need to support marquee selection of objects in the viewport, which that wouldn't really work with. Although your suggestion of optimising how much I actually read back (single pixel, or small rectangles for marquee) makes a lot of sense and something I'll add. I probably don't even need to be reading back every frame either, only when a pick, mouse move (for hover indication) or marquee selection is requested.
  2. binder2

    DX11 Render Target Picking

    Ok - I have 3 rotating buffers in place and it does improve things. Although I am noticing a lot of spikes now. My frame looks something like this : void Frame() { Render(); D3DDevice.ImmediateContext.Flush(); D3DImage.Invalidate(); // (I am using D3DImage so I can render to a WPF control) } With picking disabled, my frame time is a steady 4ms. With picking enabled and no rotating buffers, it's a steady 11ms With picking enabled and 3 rotating buffers, it's varies between 4ms -> 8ms. Is that a sign something is wrong?
  3. binder2

    DX11 Render Target Picking

    Thanks, I will try that. One question though, I enabled MapFlags.DoNotWait, but do you know how I detect the DXGI_ERROR_WAS_STILL_DRAWING in SlimDx? as there is no HResult like with c++? I test for DataBox.Data.CanRead, but that is always true.
  4. I'm using Directx11 (SlimDx C#) to write an editor type thing (like Maya). As there will be a lot of complex objects on screen, I figured I would do the picking in the following manner. - Have all shaders write to two render targets, the first being the normal colour target, and the second being a R32_UInt texture to store pixel IDs (object ids) - Then have this second texture read by the CPU and copied to a map for easy picking via cursor coords The problem I am having is that it is rather slow. At the end of each frame, I use CopyResource to copy the picking texture (BindFlags.RenderTarget) to a 'ResourceUsage.Staging' texture Then I call MapSubresource, and copy it all to a simple array of uints (which are used for the actual picking detection). It takes about 10ms though :( .... is there a faster way? .... The Copy call appears to be ok, it is the mapping/Unmapping calls that take the time. My code looks something like this : void EndOfRenderFrame() { // copy the picking rendertarget to the staging texture (as we cant read from a rendertarget) D3DDevice.ImmediateContext.CopyResource(m_pickTexture, m_pickStagingTexture); // now copy the staging texture to our local copy of the picking buffer DataBox map = D3DDevice.ImmediateContext.MapSubresource(m_pickStagingTexture, 0, MapMode.Read, MapFlags.None); int destinationPitch = m_pickStagingTexture.Description.Width; for (int i = 0; i < m_pickStagingTexture.Description.Height; ++i) { Copy(map.Data.DataPointer, i * (map.RowPitch / 4), m_pickMap.Data, i * destinationPitch, destinationPitch); } D3DDevice.ImmediateContext.UnmapSubresource(m_pickStagingTexture, 0); } //-------------------------------------------------------------------------- public static void Copy(IntPtr source, int sourceOffset, uint[] destination, int destinationOffset, int length) { unsafe { uint* sourcePtr = ((uint*)source) + sourceOffset; for (int i = destinationOffset; i < destinationOffset + length; ++i) { destination[i] = *sourcePtr++; } } }
  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!