Skip to content

Compute Only Sample

Bart House edited this page Jan 5, 2019 · 15 revisions

Introduction

The compute only sample attempts to demonstrate how to write a compute only driver using the WDDM 2.3+ driver model. Currently the sample is a software only driver that can be installed within a VM. By fall 2018, we expect to extend the sample to include support for running the driver on an iMX7 board available from Compulab.

Source

Building

  1. Install Visual Studio 2017
  2. Install Windows 10 WDK from https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk
  3. Install Windows 10 SDK from https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
  4. Launch Visual Studio 2017 and open solution at graphics-driver-samples\compute-only-sample\cos.sln
  5. Select Debug or Release
  6. Select X64, X32 or ARM targets
  7. Build solution

NOTE: Current Windows 10 release is 17763, when newer WDK/SDK is used, costestmc project's "Windows SDK Version" need to be adjusted accordingly.

NOTE2: If using a pre-released unsigned WDK, you must disable strong name verification on your machine in order for the Visual Studio driver extension to work. You can disable strong name verification by running the command "sn -Vr *" from a visual studio developer command prompted that has been elevated to administrator.

Installing in a VM

Before installing the Compute Only Sample driver you will need to modify the ACPI information of the VM to report the existence of a compute only device. Here are the steps you need to follow to modify the ACPI information (on Windows VM Generation 1):

  1. Launch an administrator command prompt within the VM
  2. Turn on test signing by running:
    bcdedit -set testsigning on
  3. Get a copy of the asl.exe tool from <WDKDIR>\Tools\x64\ACPIVerify
    NOTE:<WDKDIR> by default will be 'c:\Program Files (x86)\Windows Kits\10'
  4. Use asl.exe to get a copy of the DSDT.ASL source (this the ACPI file used to report devices) by running:
    asl.exe /tab=DSDT
  5. Modify the definition block in the DSDT.ASL bumping up version of the DSDT: DefinitionBlock("DSDT.AM", "DSDT", 0x01, "MSFTVM", "MSFTVM02", 0x00000002) to DefinitionBlock("DSDT.AM", "DSDT", 0x02, "MSFTVM", "MSFTVM02", 0x00000003)
  6. Modify DSDT.ASL to add the description of the COSD device within the SB scope
    Scope(\_SB_)
    {
      Device(COSD)
      {
        Name(_CID, "ComputeOnlySample")
        Name(_HID, "ComputeOnlySample")
        Name(_UID, 0x0)
        Name(_CRS, Buffer(0x5)
        {
          0x22,   // IRQ descriptor
          0x04,   // Low part of IRQ mask, IRQ 2
          0x00,   // High part of IRQ mask
          0x79,   // End tag
          0x00
        })
        Method(PMCD)   // Power Management Component Data *** THIS IS JUST A SAMPLE ***
        {
          Name(RBUF, Package()
          {
            1,         // Version
            1,         // Number of graphics power components
            Package()  // Power components package
            {
              Package()  // GPU component package
              {
                0,       // Component Index
                0,       // DXGK_POWER_COMPONENT_MAPPING.ComponentType (0 = DXGK_POWER_COMPONENT_ENGINE)
                0,       // DXGK_POWER_COMPONENT_MAPPING.NodeIndex
                Buffer() // DXGK_POWER_RUNTIME_COMPONENT.ComponentGuid
                {
                  0xb5, 0x54, 0x2d, 0xf0, 0xa9, 0x0f, 0x80, 0x4a, // f02d54b5-0fa9-4a80-854d-37613ab836ea
                  0x85, 0x4d, 0x37, 0x61, 0x3a, 0xb8, 0x36, 0xea
                },
                "3D_Engine_00", // DXGK_POWER_RUNTIME_COMPONENT.ComponentName
                3,              // DXGK_POWER_RUNTIME_COMPONENT.StateCount
                Package()       // DXGK_POWER_RUNTIME_COMPONENT.States[] package
                {
                  Package()     // F0
                  {
                     0,         // DXGK_POWER_RUNTIME_STATE.TransitionLatency
                     0,         // DXGK_POWER_RUNTIME_STATE.ResidencyRequirement
                     8,         // DXGK_POWER_RUNTIME_STATE.NominalPower
                  },
                  Package()     // F1
                  {
                     10000,     // DXGK_POWER_RUNTIME_STATE.TransitionLatency
                     0,         // DXGK_POWER_RUNTIME_STATE.ResidencyRequirement
                     4,         // DXGK_POWER_RUNTIME_STATE.NominalPower
                  },
                  Package()     // F2
                  {
                     20000,     // DXGK_POWER_RUNTIME_STATE.TransitionLatency
                     0,         // DXGK_POWER_RUNTIME_STATE.ResidencyRequirement
                     2,         // DXGK_POWER_RUNTIME_STATE.NominalPower
                  },
                }
              }
            }
          })
          Return(RBUF)
        }
      }
    }

  NOTES:  
  0x22, 0x04, 0x00 adds an interrupt resource. 1st byte (0x22) is type of resource.  
  0x79, 0x00 indicates end of "Current Resource" _CRS table.  

Reference: http://www.baldwin.cx/~phoenix/reference/docs/acpi_impguide.pdf
7. Please see below about glitch in DSDT.ASL which is present in VM builds (as of build 17723) 8. Compile the modified DSDT.ASL to generate DSDT.AML by running:
asl.exe DSDT.ASL
9. Load the modified DSDT.AML into the registry for use in next boot by running:
asl /loadtable -v DSDT.AML
10. Reboot the VM


To install the driver:

  1. Use rs5_release 17763 or newer Windows Insider build
  2. Force the use of WARP by XAML by running:
    reg.exe add HKLM\SOFTWARE\Microsoft\XAML /v ForceWARP /t REG_DWORD /d 1
  3. Force Display Kernel Runtime to not use COS as POST device:
    reg.exe add HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers /v DisableAutoAcpiPostDeivce /t REG_DWORD /d 1
  4. Copy cos.inf, coskmd.sys, coskmd.cat and cosumd12.dll from compute-only-sample\x64\Debug\cosDriver into a folder
  5. In the folder with the driver files run:
    devcon.exe install cos.inf ACPI\COMPUTEONLYSAMPLE
    NOTE: You can find devcon.exe in WDK\Tools\x64
    NOTE: When connecting to VM do not use "Enhanced session"

Windows VM specific issue:

There is a glitch in DSDT.ASL that need to be patched for compiling into DSDT.AML
From:

                If(LEqual(WIN6, 0x0))
                {
                    Store(0x20, Local0)
                    Store(0x0, Local1)
                    While(Local0)
                    {
                        Store(0x84, Index(CRS_, Local1, ))
                        Add(Local1, 0x2e, Local1)
                        Decrement(Local0)
                    }
                    Return(Name(TBUF, Buffer(0x28)
                {
	0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22, 0xaa, 0xbb, 0xcc, 0xdd,
	0xee, 0xff, 0x33, 0x44, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x55, 0x66,
	0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x77, 0x88, 0xaa, 0xbb, 0xcc, 0xdd
                    }))
                }

To:

                If(LEqual(WIN6, 0x0))
                {
                    Store(0x20, Local0)
                    Store(0x0, Local1)
                    While(Local0)
                    {
                        Store(0x84, Index(CRS_, Local1, ))
                        Add(Local1, 0x2e, Local1)
                        Decrement(Local0)
                    }
                }
                Name(TBUF, Buffer(0x28)
                {
	0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x11, 0x22, 0xaa, 0xbb, 0xcc, 0xdd,
	0xee, 0xff, 0x33, 0x44, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x55, 0x66,
	0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x77, 0x88, 0xaa, 0xbb, 0xcc, 0xdd
                })

Testing

  1. Windows VM kernel debugging can be enabled by: (use debugger machine's IPv4 address for hostip)
bcdedit /debug on
bcdedit /dbgsettings NET hostip:192.168.1.2 PORT:50010 key:1.1.1.1
shutdown /r /t 0
  1. Updating the driver during development:
    For KMD coskmd.sys, set up a kdfiles association in windbg.exe for coskmd.sys:
    .kdfiles -m \Systemroot\System32\drivers\coskmd.sys d:\workspace\graphics-driver-samples\compute-only-sample\X64\Debug\coskmd.sys
    On the target machine, go back the directory used for driver installation and rerun devcon.exe update cos.inf ACPI\COMPUTEONLYSAMPLE
    The new version of coskmd.sys is copied over automatically.
    For UMD cosumd12.dll, simply copy over the new cosumd12.dll into target machine's c:\windows\system32 when no test is running or use VS remote debugging tool.

  2. With shader compiler yet to come, set ENABLE_FOR_COSTEST to 1 for coskmd.sys to simulate shader execution for costest.exe and costest2.exe

  3. Change g_doNotStop to false in cosumd12.cpp and update cosumd12.dll to observe DDI call sequence in the debugger.