0

I would like to find which Direct 3D Feature Levels (shown here) are supported in my C# UWP program.

Note: I am doing this in trying to research possible answers to my question How do I know, in code, if RadialGradientBrush is not being shown correctly?

In C++, there is a call to D3D11CreateDevice that might possibly be useful, but there does not appear to be a C# equivalent.

Or, even better, might be the ID3D11Device, which has a GetFeatureLevel() call. Again, these are C++ items.

Bob Krauth
  • 99
  • 2
  • 8

1 Answers1

0

I figured this out:

C++ DLL:

#include "pch.h"
#include <wrl.h>
#include <d3d11_2.h> 
#include "BKGraphicsDLL.h"

using Microsoft::WRL::ComPtr;

extern "C"
{
    __declspec(dllexport) D3D_FEATURE_LEVEL GetGraphicsFeatureLevel()
    {
        HRESULT hr = E_FAIL;
        D3D_FEATURE_LEVEL MaxSupportedFeatureLevel = D3D_FEATURE_LEVEL_9_1;
        D3D_FEATURE_LEVEL FeatureLevels[] = {
            D3D_FEATURE_LEVEL_11_1,
            D3D_FEATURE_LEVEL_11_0,
            D3D_FEATURE_LEVEL_10_1,
            D3D_FEATURE_LEVEL_10_0,
            D3D_FEATURE_LEVEL_9_3,
            D3D_FEATURE_LEVEL_9_2,
            D3D_FEATURE_LEVEL_9_1
        };

        hr = D3D11CreateDevice(
            NULL,
            D3D_DRIVER_TYPE_HARDWARE,
            NULL,
            0,
            FeatureLevels,
            ARRAYSIZE(FeatureLevels),
            D3D11_SDK_VERSION,
            NULL,
            &MaxSupportedFeatureLevel,
            NULL
        );

        return MaxSupportedFeatureLevel;
    }
}

An enum and a NativeMethods class to access the DLL in my MainPage C#:

    public enum D3DFeatureLevel
    {
        D3D_FEATURE_LEVEL_9_1 = 0x9100,
        D3D_FEATURE_LEVEL_9_2 = 0x9200,
        D3D_FEATURE_LEVEL_9_3 = 0x9300,
        D3D_FEATURE_LEVEL_10_0 = 0xa000,
        D3D_FEATURE_LEVEL_10_1 = 0xa100,
        D3D_FEATURE_LEVEL_11_0 = 0xb000,
        D3D_FEATURE_LEVEL_11_1 = 0xb100,
        D3D_FEATURE_LEVEL_12_0 = 0xc000,
        D3D_FEATURE_LEVEL_12_1 = 0xc100
    };


    // used to get Graphics capabilities
    internal static class NativeMethods
    {
        [DllImport("BKGraphicsDLL.dll", ExactSpelling = true)]
        public static extern D3DFeatureLevel GetGraphicsFeatureLevel();

    }

Wherever I need to Feature Level in my code, uses this line:

    D3DFeatureLevel maxFeatureLevel = NativeMethods.GetGraphicsFeatureLevel();
Bob Krauth
  • 99
  • 2
  • 8