# DX12 Problem rendering to multiple windows (SharpDX / DX12)

## Recommended Posts

I am having a problem rendering to multiple (two) windows, using SharpDX and DX12. I am setting up two swapchains etc, and it's almost working. The effect is that both windows shows sporadic flickering. It looks as though one window's transformation leaks into the other window every now and then (it goes both ways but not necessarily at the same time). The rendering is triggered by user input, not a render loop, and the flickering happens mostly when there is lots of input (like panning quickly). When I deliberately slow things down (for instance by printing debug info to Output) it looks fine.

At the moment I have this level of separation:

The application has: one device, bundles, all the resources like vertex, texture and constant buffers.

Each view has: a swap chain, render target, viewport, fence, command list, command allocator and command queue,

(I have also tried to use a single command list, allocator, queue and fence, but it doesn't make any difference regarding my flicker problem)

The rendering process is quite straight forward:

One of the windows requests to be re-rendered, and the other window's requests will be ignored until the first is done

1. Update the transformation matrix, based on the window's parameters (size, center position etc). The matrix is written to the constant buffer:
2. IntPtr pointer = constantBuffer.Map(0);
Utilities.Write<Transform>(pointer, ref transform);
constantBuffer.Unmap(0);

Reset, populate and close the window's command list (populating here means setting its render target & viewport, executing bundles etc).

3. Execute the window's command list on its command queue.

4. Present the window's swapchain

5. Wait for the window's command queue to finish rendering (using its fence)

6. Reset the window's command allocator

I really believe that since both windows use the same constant buffer to write and read the transformation, sometimes the first window's transformation is still there when the other window is rendering. But I don't understand why. The writing to the buffer really happens when the code in step 1 is executed... Right? And the reading of the buffer really happens when the command list is executed in step (3)... Right? At very least it must be read before reaching step (6). Am I right? Then how can it sometimes read the wrong transformation?

Has anyone tripped over a similar problem before? What was the cause and how did you fix it?

##### Share on other sites

I think I finally got it working. My mistake lies somewhere in step (5). I always mess up the waiting for the fence part. Now I went back to the simple one allocator (per window) instead of two, following the hello world examples... and it works. Goes to show that I still don't fully understand the routine for working with two allocators.

Anyway, I still wonder what makes most sense when rendering to multiple windows. Should each window have its own allocator, queue and command list, or should these things be central to the application? Porting a hello world example to multiple windows I guess it's easier to keep all those things per view.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 10
• 12
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
633348
• Total Posts
3011460
• ### Who's Online (See full list)

There are no registered users currently online

×