🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

3D rendering flickering due to Direct2D/DirectWrite rendering

Started by
4 comments, last by Enzio599 4 years, 2 months ago

Hi,

I try to display text as HUD with my 3D engine.

The problem is that the screen is flickering and the 3D performances are low.

Can you help me ? ( I am also using Win32 for the window )

This is some code :

while (D3D11Rendering::exitThread == false)
{

		D3D11Rendering::getInstance()->GBuffer();

		D3D11Rendering::getInstance()->downsamplingPass();

		D3D11Rendering::getInstance()->glowEffect.extractingColorPass();

		D3D11Rendering::getInstance()->glowEffect.horizontalBlur();

		D3D11Rendering::getInstance()->glowEffect.verticalBlur();

		D3D11Rendering::getInstance()->LightingPass();

		D3D11Rendering::getInstance()->glowEffect.blendGlowAndScene();

		D3D11Rendering::getInstance()->text2D.renders2D();

		D3D11Rendering::getInstance()->updateRendering();
}
void Text2D::renders2D()
{
    renderTarget2D->BeginDraw();

    renderTarget2D->Clear(D2D1::ColorF(D2D1::ColorF::Black));

    drawText();

    renderTarget2D->EndDraw();

}
void Text2D::drawText()
{
    D2D1_RECT_F layoutRect = D2D1::RectF(D3D11Rendering::width-150.0f, D3D11Rendering::height-200.0f, D3D11Rendering::width, D3D11Rendering::height);

    renderTarget2D->DrawText(
        textToDisplay,        // The string to render.
        textLength,    // The string's length.
        textFormat.Get(),    // The text format.
        layoutRect,       // The region of the window where the text will be rendered.
        blackBrush.Get()     // The brush used to draw the text.
        );
}
Advertisement

are you trying to present another swap chain of directwrite with main swap chain of direct3d…

or … wait…

r u using two swap chains…

I have to call Present twice, with two different swap chain ? Once with direct3D and once with Direct2D or DirectWrite ?

Hi,

I used to* have a similar problem. In my case the text is rendered onto a background “textRenderTexture” (Direct2D/DirectWrite) then fields on this texture are sampled on quads in 3D. What solved the problem was forcing a Direct2D/Direct3D synchronization with a dummy copy operation from “textRenderTexture” to a dummy one.

Disclaimer: this is way over my skills and I found the method buried deep into some forum (lost the link sorry).

Dummy synchronization texture creation (SharpDX) - once:

 // creates a synchronization texture, as a staging resource to manage D2D / D3D sync
 textRenderSyncTextureCopyRegion = new ResourceRegion(0, 0, 0, 8, 8, 1);
 texture2DDescription textRenderSyncTextureDesc = new Texture2DDescription()
 {
 	ArraySize = 1, // only one texture
        BindFlags = BindFlags.None, // sync only, no use in pipeline
        CpuAccessFlags = CpuAccessFlags.Read, // no access from CPU
        Format = Format.B8G8R8A8_UNorm,
        Width = 8, // as per the textRenderSyncTextureCopyRegion
        Height = 8, // as per the textRenderSyncTextureCopyRegion
        MipLevels = 1, // only one MipLevel
        OptionFlags = ResourceOptionFlags.None,
        SampleDescription = new SampleDescription(1, 0), // check...
        Usage = ResourceUsage.Staging // GPU only                
  };
  RemoveAndAllocate(ref textRenderSyncTexture, new Texture2D(d3dDevice, textRenderSyncTextureDesc));

Synchronization (partial copy from “textRenderTexture” to dummy) - at each frame:

// requests a (partial) copy from the shared textRenderTexture to the dummy synchronization texture
d3dContext.CopySubresourceRegion(textRenderTexture, 0, textRenderSyncTextureCopyRegion, textRenderSyncTexture, 0, 0, 0, 0);
// map = lock for read => will wait until the copy is done
d3dContext.MapSubresource(textRenderSyncTexture, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
d3dContext.UnmapSubresource(textRenderSyncTexture, 0);
// from then on use of the shared textRenderTexture is safe

* “used to” because at some point as I was adding more elements to the scene the system stopped being necessary. As I said this is way over my skills sorry. Hope it may help though.

theScore said:

I have to call Present twice, with two different swap chain ? Once with direct3D and once with Direct2D or DirectWrite ?

how r u doin this interop…

This topic is closed to new replies.

Advertisement