0

Our custom DirectShow Video Renderer uses Direct3D9. When displayed in windowed mode (covering the whole display srface) on the primary display/monitor it performs well with CPU usage low, but when it's displayed on the secondary monitor the CPU (kernel) usage goes really high due to DirectX using the cpu to do the transfer between devices. This happens only on Windows XP. I create the Direct3DDevice9 using the appropriate adapter, at least I think I am. First I get the monitor handle for the specified window handle and then search for the D3D adapter that corresponds to this monitor using GetAdapterMonitor(). When moving the window and reinitializing the device I can see that the Adapter changes from 0 to 1, as expected. Is there something else I should do? here's the relevant code (Delphi).

Adapter := D3DADAPTER_DEFAULT;
if (FWnd <> 0) and (FWnd <> INVALID_HANDLE_VALUE) then
begin
  monitor := MonitorFromWindow(FWnd, MONITOR_DEFAULTTONEAREST);
  for idxAdapter := 0 to D3D.GetAdapterCount - 1 do
    if D3D.GetAdapterMonitor(idxAdapter) = monitor then
    begin
      Adapter := idxAdapter;
      Break;
    end;
end;
Result := D3D.GetDeviceCaps(Adapter, D3DDEVTYPE_HAL, Caps);

PP.BackBufferCount := 1;
PP.BackBufferFormat := FFormat; // xrgb
PP.BackBufferWidth := FWidth;
PP.BackBufferHeight := FHeight;
PP.Flags := D3DPRESENTFLAG_VIDEO;
PP.PresentationInterval := D3DPRESENT_INTERVAL_ONE;
PP.SwapEffect := D3DSWAPEFFECT_DISCARD;

PP.hDeviceWindow := FWnd;
PP.Windowed := not FFullScreen;

D3D.CreateDevice(Adapter, D3DDEVTYPE_HAL, FWnd, D3DCREATE_MULTITHREADED or D3DCREATE_MIXED_VERTEXPROCESSING, @PP, Device);

Other players and renderers don't have this problem. MPC-HC and madVR had this problem but fixed it. Looking at MPC-HC's code I can't find any significant differences to how I'm doing it.

Thanks!

Lee_Nover
  • 334
  • 3
  • 8
  • It's not Delphi specific, only the code example is, that's why I didn't add that tag – Lee_Nover May 11 '12 at 20:43
  • I'm almost sure that there is a "Direct3D on second monitor issue". But I couldn't find it right now. – EMBarbosa May 12 '12 at 01:37
  • Did you read that [documentation](http://msdn.microsoft.com/en-us/library/windows/desktop/bb206364(v=vs.85).aspx) ? – Diego Garcia May 12 '12 at 02:10
  • @DiegoGarcia yes, I did, many times, but it's about exclusive mode (full screen) only and this is not the case here. I have edited the question to explain that in more detail; previously it did say fullscreen but that's just the rendered surface not the execution mode. sorry about that! – Lee_Nover May 13 '12 at 09:44
  • Hi @Lee_Nover it seens that its a possible know xp limitation, take a look [here](http://www.tricerasoft.com/faq-vid.html) at the "Windows Tuning (notes below are for XP)" section. And [here](http://quark.sourceforge.net/infobase/intro.configuration.general.html) in this other site section "Multiple monitors" Introduction. – Diego Garcia May 13 '12 at 12:27
  • I've seen some of the MPC-HC code that uses the Direct3d9 and it seens that when it is in windowed mode they use the follow configurations on PP: pp.SwapEffect = D3DSWAPEFFECT_COPY; pp.Flags = D3DPRESENTFLAG_VIDEO; also you should look if in your case it would need the use of pp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; because as its comments sayed the Desktop composition takes care of the VSYNC. Another tag used in the create device is D3DCREATE_FPU_PRESERVE. I Hope that helps to inprove the performance on xp. – Diego Garcia May 13 '12 at 13:58
  • thanx, I've already tried that and it didn't help. the current workaround is to have the video displayed on the "primary" display. I'll investigate further when I have more time. – Lee_Nover May 14 '12 at 07:06

1 Answers1

0

Did you try to set BackBufferFormat to Caps.BackBufferFormat? As far as I know xrgb is not a universal format and can be not supported for some resolutions.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
Darthman
  • 457
  • 4
  • 21