Sign in to follow this  
ZeroWalker

How do i use PureDevice?

Recommended Posts

I am trying to enable PureDevice for testing purposes, but i can´t seem to get it to work.
Is there sometihng i need to set it to for it to work?
 



{
DeviceWindowHandle = form.Handle,
PresentFlags = SharpDX.Direct3D9.PresentFlags.None,
BackBufferCount = 1,
PresentationInterval = SharpDX.Direct3D9.PresentInterval.Immediate,
SwapEffect = SharpDX.Direct3D9.SwapEffect.FlipEx,
BackBufferFormat = SharpDX.Direct3D9.Format.X8R8G8B8,
MultiSampleType = MultisampleType.None,
Windowed = true,
};

device = new SharpDX.Direct3D9.DeviceEx(new SharpDX.Direct3D9.Direct3DEx(), 0, SharpDX.Direct3D9.DeviceType.Hardware, form.Handle, SharpDX.Direct3D9.CreateFlags.PureDevice, presentParams);

Share this post


Link to post
Share on other sites

What does "cannot seen to get it to work" mean? Please describe it better - are you getting an error? Is the app crashing? Is the code otherwise fine and working and problems come only when you include the PureDevice flag?

 

You also should check whether the device actually supports puredevice, in DirectX it's done by testing the DeviceCaps against D3DDEVCAPS_PUREDEVICE, but I have no idea how is this implemented in SharpDX.

Edited by Tom KQT

Share this post


Link to post
Share on other sites

Well it errors, when creating the device, it´s something either in the Device implementation, or in the Present.

And yeah i am trying to find that in SharpDX, and the only thing i can find is: http://sharpdx.org/documentation/api/f-sharpdx-direct3d9-capabilities-devicecaps

And well, i can use, SharpDX.Direct3D9.DeviceCaps.PureDevice , but that doesn´t return anything.

I thought it would be something like True, False. But then again, i don´t know how DirectX itself does in C++.

Share this post


Link to post
Share on other sites

On native side, the pure device is enabled simply by using the correct device creation flag.

 

What do you mean, "doesn't return anything"? The device caps are represented as bit flags (enum), and you should see whether the pure device value is set in the field (among other possible values). This can be done by using the & (AND operator), or using Enum.HasFlag, if you use modern enough version of .net.

 

Note that pure device can actually (and easily) decrease your performance, if you are not very careful about redundant state changes. The "non-pure" device caches device states, so if you set the same state multiple times in a row, you don't incur hardware calls every time - only when the state actually changes. Pure device, by contrast, removes this caching so you need to avoid device state calls even more vigorously than usual.

 

If you have the DirectX SDK installed, you can use the "DirectX Caps Viewer" to verify all your hardware capabilities from a single place. This tool essentially works by checking cap bits of your devices against all known possible bits.

Edited by Nik02

Share this post


Link to post
Share on other sites

Can you please show an example of how to check if  i support it.
I am brain dead when it comes to this. But it does hav, HasFlag, but don´t get how i am supposed to, let it tell me if it supports or not.

Yeah i know, or well, i know that it´s a very, Delicate state. Meaning, it turns blind eye to everything, and you have to be more vigilant.

But that being said, my "Rendering" if i even can call it that, only have 1 purpose.

Render an Image. No 3D, no effect etc.

So there shouldn´t be any problem


I don´t have DirecX SDK, never got it to work for me, and it said (It´s in Windows SDK now!) and i got that one, but no DirectX SDK anyway;P
 

Share this post


Link to post
Share on other sites

I'm more of a native D3D guy, but I would go about it as follows in SharpDX:

 

  • Create the Direct3D object.
  • Get the adapter collection from it.
  • For each adapter in the collection:
    • Get the AdapterInformation.
    • Use AdapterInformation.GetCaps to obtain a Capabilities structure for the given adapter.
    • Read the DeviceCaps field from the Capabilities structure.
    • bool SupportsPureDevice = DeviceCaps.HasFlag(SharpDX.Direct3D9.DeviceCaps.PureDevice)

or

  • bool SupportsPureDevice = (0 != (DeviceCaps & SharpDX.Direct3D9.DeviceCaps.PureDevice))
Edited by Nik02

Share this post


Link to post
Share on other sites

Also note that in such a simple scenario as you describe, you won't likely see any (or very small) performance implications on pure versus non-pure device. The difference would arise if API calls would be your bottleneck.

Share this post


Link to post
Share on other sites

I did:
 

using (device = new SharpDX.Direct3D9.DeviceEx(new SharpDX.Direct3D9.Direct3DEx(), 0, SharpDX.Direct3D9.DeviceType.Hardware, form.Handle, SharpDX.Direct3D9.CreateFlags.HardwareVertexProcessing, presentParams))
{
bool support = device.Capabilities.DeviceCaps.HasFlag(SharpDX.Direct3D9.DeviceCaps.PureDevice);

}

 

And, it give True.

 

 

Edit:

Probably true, but would atleast want to get it working just for the heck of it.

Edited by ZeroWalker

Share this post


Link to post
Share on other sites

Unless SharpDX has a bug in the device constructor, you should be able to use the pure device flag.

 

You will want to check the caps before creating the device, as per my approach. Device context creation is potentially expensive; you don't want to create a new device just to test a cap bit.

Edited by Nik02

Share this post


Link to post
Share on other sites

Hopefully it´s not.

And well i am trying to do that, but i don´t get how to check device capabilities before, setting the device.

 

Maybe like this:
 

CreateFlags devFlags = CreateFlags.HardwareVertexProcessing;
if (cap.DeviceCaps.HasFlag(DeviceCaps.PureDevice))
{

devFlags |= CreateFlags.PureDevice;

 

Though, that returns false for some reason.

Edited by ZeroWalker

Share this post


Link to post
Share on other sites

Use the logic I outlined in my second reply to this thread. It doesn't involve creating a device.

 

The line you posted creates an empty Capabilities structure. The system won't make guesses as to which device you may refer with that :)

Edited by Nik02

Share this post


Link to post
Share on other sites

You need to get an instance of the DeviceCaps structure from the AdapterInformation structure instance. You get an array of AdapterInformation structure instances from the Direct3D object, for each adapter in your system.

Share this post


Link to post
Share on other sites

The device caps structure represents the information reported by your GPU driver about the capabilities of a given device instance. If you simply create an empty instance of such a structure, it won't contain any useful information.

Share this post


Link to post
Share on other sites

I got AdapterInformaiton ,but i can´t choose anything, they are just, well, empty.
 

DeviceType devType = DeviceType.Reference;
Capabilities cap = new Capabilities();
AdapterDetails u = new AdapterDetails();
MessageBox.Show(u.DeviceName);
AdapterCollection dd = new AdapterCollection;

how can i choose my own adapter, which probably is int 0?
 

Edited by ZeroWalker

Share this post


Link to post
Share on other sites

You keep creating empty structure instances; it is only logical that they don't contain any info.

 

You need to get the structures via the Direct3D interface.

 

...

 

Once you get the array of AdapterDetails from the Direct3D object, you can inspect the DeivceOrdinal field of that struct to determine which of those represents the device 0. It is generally regarded as the "primary adapter."

Share this post


Link to post
Share on other sites

Now i think i found  it:
 



                      CreateFlags devFlags = CreateFlags.HardwareVertexProcessing;
                      using (Direct3DEx D3DEx = new Direct3DEx())
                      {

                          cap = D3DEx.GetDeviceCaps(0, SharpDX.Direct3D9.DeviceType.Hardware);


                          
                          if (0 != (cap.DeviceCaps & SharpDX.Direct3D9.DeviceCaps.PureDevice))
                          {
                              devFlags = CreateFlags.PureDevice;
                              MessageBox.Show(devFlags.ToString());
                          }
                      }

Is this correct?

Edited by ZeroWalker

Share this post


Link to post
Share on other sites

i can post a half dozen lines of code to go pure device in dx code, but for slim dx, you're on your own.

 

 
 
 
 
void Zsetparams(int w,int h)
{
ZeroMemory(&Zparams,sizeof(D3DPRESENT_PARAMETERS));
Zparams.AutoDepthStencilFormat = D3DFMT_D24X8;
Zparams.BackBufferCount=1;
Zparams.BackBufferFormat = D3DFMT_A8R8G8B8;              // set the back buffer format to 32-bit      // turn these on for fullscreen
Zparams.BackBufferWidth = (unsigned)w;                          //width;    // set the width of the buffer
Zparams.BackBufferHeight = (unsigned)h;                          //height;    // set the height of the buffer
Zparams.EnableAutoDepthStencil = TRUE;                   // automatically run the z-buffer for us
Zparams.Flags=0;
Zparams.FullScreen_RefreshRateInHz=D3DPRESENT_INTERVAL_DEFAULT;
Zparams.hDeviceWindow=Zprogram_window_handle;
Zparams.MultiSampleQuality=0;
Zparams.MultiSampleType=D3DMULTISAMPLE_NONE;
Zparams.PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT;
Zparams.SwapEffect = D3DSWAPEFFECT_COPY;                 //D3DSWAPEFFECT_DISCARD;
Zparams.Windowed = FALSE;                                // TRUE for windowed, FALSE for fullscreen
}
 
 
 
 
// init d3d pure device....
 
d3d_obj_ptr=Direct3DCreate9(D3D_SDK_VERSION);
if (d3d_obj_ptr==NULL) { Zmsg("Error creating D3D object","Z game engine"); return(0); }
Zsetparams(width,height);
result=d3d_obj_ptr->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,Zprogram_window_handle,
                                 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,                          // D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                 &Zparams,&Zd3d_device_ptr);
if (result != D3D_OK) { Zmsg("Error creating D3D device","Z game Engine"); d3d_obj_ptr->Release(); return(0); }
 
 
 

Share this post


Link to post
Share on other sites

Norman's code has a good point embedded in it:

 

Since pure device is incompatible with software vertex processing, it may be that you need to specify the hw vertex processing flag as well in order to use the pure device flag successfully.

Share this post


Link to post
Share on other sites

Now i think i found  it:
 



                      CreateFlags devFlags = CreateFlags.HardwareVertexProcessing;
                      using (Direct3DEx D3DEx = new Direct3DEx())
                      {

                          cap = D3DEx.GetDeviceCaps(0, SharpDX.Direct3D9.DeviceType.Hardware);


                          
                          if (0 != (cap.DeviceCaps & SharpDX.Direct3D9.DeviceCaps.PureDevice))
                          {
                              devFlags = CreateFlags.PureDevice;
                              MessageBox.Show(devFlags.ToString());
                          }
                      }

Is this correct?

Looks like it is. I would change the line beginning with devFlags to following:

 

devFlags |= CreateFlags.PureDevice; // note the OR/assignment |=

Edited by Nik02

Share this post


Link to post
Share on other sites

Think i have pretty much copy pasted your present settings:
 

presentParams = new SharpDX.Direct3D9.PresentParameters
{
AutoDepthStencilFormat = Format.D24X8,
EnableAutoDepthStencil = true,
DeviceWindowHandle = form.Handle,
PresentFlags = SharpDX.Direct3D9.PresentFlags.None,
BackBufferCount = 1,
PresentationInterval = SharpDX.Direct3D9.PresentInterval.Default,
SwapEffect = SharpDX.Direct3D9.SwapEffect.Copy,
BackBufferFormat = SharpDX.Direct3D9.Format.A8R8G8B8,
MultiSampleQuality = 0,
MultiSampleType = MultisampleType.None,
Windowed = true,
};

But it won´t work.. hmm, i don´t get it.

Share this post


Link to post
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this