Trying to make D3DFMT_A2R10G10B10 work in DirectX renderer.

I’m trying to make this format working. First of all - why? As far as I know it can be used with 10 bits per channel monitors. Also it can be used with CRT monitors - as far as I know - modern videocards have 10 bits DAC - at least my Radeon 3850, it seems, have it. And this format can be used with even 8 bits per channel LCD monitors - for better dithering. I may be wrong - so if anybody precisely know technical aspects of this format and its appliances - you are welcome to correct me.

So what I’ve done - in file wdxGraphicsPipe9.cxx I’ve changed order of formats checking and placed it in the first place -

#define TOTAL_D3D_FORMATS 5
  static D3DFORMAT d3d_format_array [TOTAL_D3D_FORMATS] =
  {
    D3DFMT_A2R10G10B10,  // we may want this first in the list for XBOX 360 or HDR
    D3DFMT_A8R8G8B8,
    D3DFMT_X8R8G8B8,
    D3DFMT_R5G6B5,
    D3DFMT_X1R5G5B5,
  };

Than lower there is mistake - instead of A2R10G10B10_FLAG used A2B10G10R10_FLAG - as far as I know - all windows backbuffer formats must begin with R, not with B. So I changed this flag to right here -

// dx9 valid display modes for render targets.
      D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_X8R8G8B8, D3DFMT_A8R8G8B8, D3DFMT_A2R10G10B10
      */

      switch (dispmode.Format) {
      case D3DFMT_X1R5G5B5:
        *p_supported_screen_depths_mask |= X1R5G5B5_FLAG;
        break;
      case D3DFMT_X8R8G8B8:
        *p_supported_screen_depths_mask |= X8R8G8B8_FLAG;
        break;
      case D3DFMT_A8R8G8B8:
        *p_supported_screen_depths_mask |= A8R8G8B8_FLAG;
        break;
      case D3DFMT_R5G6B5:
        *p_supported_screen_depths_mask |= R5G6B5_FLAG;
        break;
      case D3DFMT_A2R10G10B10:
        *p_supported_screen_depths_mask |= A2R10G10B10_FLAG;
        break;
      default:
        wdxdisplay9_cat.error()
          << "unrecognized supported fmt " << D3DFormatStr(dispmode.Format)
          << " returned by EnumAdapter_display_modes!\n";
      }

and here -

// note: this chooses 32bpp, which may not be preferred over 16 for
    // memory & speed reasons on some older cards in particular
    if (*p_supported_screen_depths_mask & X8R8G8B8_FLAG) {
      *pSuggestedPixFmt = D3DFMT_X8R8G8B8;
    } else if (*p_supported_screen_depths_mask & A8R8G8B8_FLAG) {
      *pSuggestedPixFmt = D3DFMT_A8R8G8B8;
    } else if (*p_supported_screen_depths_mask & R5G6B5_FLAG) {
      *pSuggestedPixFmt = D3DFMT_R5G6B5;
    } else if (*p_supported_screen_depths_mask & X1R5G5B5_FLAG) {
      *pSuggestedPixFmt = D3DFMT_X1R5G5B5;
    } else if (*p_supported_screen_depths_mask & A2R10G10B10_FLAG) {
      *pSuggestedPixFmt = D3DFMT_A2R10G10B10;
    }

and also in file dxgsg9base.h .

Simply with these changes program stopped with errors in this place -

if (FAILED(_d3d9->CheckDeviceType(adapter, device_type, display._display_mode.Format, presentation_params->BackBufferFormat,
                                    is_fullscreen()))) {
    wdxdisplay9_cat.error() << "adapter #" << adapter << " CheckDeviceType failed for surface fmt " << D3DFormatStr(presentation_params->BackBufferFormat) << endl;
    goto Fallback_to_16bpp_buffers;
  }

in file wdxGraphicsWindow9.cxx . So I tried to comment out this piece of code - and everything - works fine. I even notice that on Sky Dome strips in blue gradient are gone - it now simply continuous juicy blue gradient. I know this format must work - because earlier I’ve done simple programs with DirectX 9 initialization and using of this format - everything worked fine. Also on Gamasutra there is HDR example and there is ability to choose backbuffer formats - D3DFMT_A2R10G10B10 works fine in it. More - in samples in DirectX SDK - there is also ability to choose backbuffer formats and it is present there. But there is ability to choose it only in window mode, in fullscreen it is not present.
So for now I made this workaround -

if ( presentation_params->BackBufferFormat != D3DFMT_A2R10G10B10 ) {
  if (FAILED(_d3d9->CheckDeviceType(adapter, device_type, display._display_mode.Format, presentation_params->BackBufferFormat,
                                    is_fullscreen()))) {
    wdxdisplay9_cat.error() << "adapter #" << adapter << " CheckDeviceType failed for surface fmt " << D3DFormatStr(presentation_params->BackBufferFormat) << endl;
    goto Fallback_to_16bpp_buffers;
  } }

Here is log of program with this backbuffer format -

:display: loading display module: libpandadx9.dll
Known pipe types:
  wdxGraphicsPipe9
(1 aux display modules not yet loaded.)
:display:windisplay: OS version: 5.1.2.2600 
:display:windisplay:   Service Pack 2
:display:windisplay: max Mhz 2499000000, current Mhz 2499000000 
:display:wdxdisplay9: DX 9.0c GetAvailableVidMem (including AGP) returns Total: 1061945344, Free: 1058799616 for device #0
:display:wdxdisplay9: GetAvailableVidMem (no AGP) returns Total: 536870912, Free: 533725184 for device #0
:display:wdxdisplay9: SetLowVidMem flag to 0 based on adjusted VidMemTotal: 536870912
:display:wdxdisplay9: D3D9.0 Adapter[0]: ATI Radeon HD 3800 Series , Driver: ati2dvag.dll, DriverVersion: (6.14.10.7028)
VendorID: 0x00001002 DeviceID: 0x00009505 SubsysID: 0xE630174B Revision: 0x00000000
:display:wdxdisplay9: searching for valid display modes at res: (1024, 768), TotalModes: 6
:display:wdxdisplay9: DoMemBasedChecks = 0
:display:wdxdisplay9: Mode dimension 640x480; format D3DFMT_A2R10G10B10: onto next mode
:display:wdxdisplay9: Mode dimension 800x600; format D3DFMT_A2R10G10B10: onto next mode
:display:wdxdisplay9: Mode dimension 800x600; format D3DFMT_A2R10G10B10: onto next mode
:display:wdxdisplay9: Validated Mode (1024x768, D3DFMT_A2R10G10B10
:display:wdxdisplay9: Mode dimension 1280x1024; format D3DFMT_A2R10G10B10: onto next mode
:display:wdxdisplay9: Mode dimension 1600x1200; format D3DFMT_A2R10G10B10: onto next mode
:display:wdxdisplay9: search_for_valid_device returns fmt: D3DFMT_A2R10G10B10
:display:wdxdisplay9: Selected device 0 (of 1, zero-based)
:display:wdxdisplay9: walla: device00DFF744:2
:pnmtext: Loaded font Perspective Sans Regular
:display: Unable to set window properties: !undecorated 
:audio(error): OpenALAudioManager: alcOpenDevice(NULL): ALC couldn't open device
:audio(error): OpenALAudioManager: No open device or context
:audio(error):   OpenALAudioManager is not valid, will use NullAudioManager
:audio: NullAudioManager
:audio(error): OpenALAudioManager: alcOpenDevice(NULL): ALC couldn't open device
:audio(error): OpenALAudioManager: No open device or context
:audio(error):   OpenALAudioManager is not valid, will use NullAudioManager
:audio: NullAudioManager
:loader: loading file type module: p3ptloader
:gobj: Loading texture /j/Program Files/Panda3D-1.7.0/samples/Panda 3D/Resources\Models\SunQuad\Sun_blurred.png
:gobj: Loading texture /j/Program Files/Panda3D-1.7.0/samples/Panda 3D/Resources\Models\Terrain\layingrock_2.dds
:gobj: Loading texture /j/Program Files/Panda3D-1.7.0/models/maps/panda-model.jpg
:display: Closing wdxGraphicsWindow9

OpenAL do not work because on my computer Windows Audio Service is disabled by default.

So maybe anybody can help - why _d3d9->CheckDeviceType fails with D3DFMT_A2R10G10B10, but everything works fine without this check?