DirectX Texture Behaviour Not As Expected

I’ve recently been playing with dynamic texture atlas handling and I’ve found that I receive a crash if I try to set the data for a texture that is larger than 4096, here’s a crude example of what I’m doing.

        int Size = 4096;
        Texture2D Test_Tex = new Texture2D(GraphicsDevice, Size, Size, false, SurfaceFormat.Color);
        Color[] Test_Data = new Color[Size * Size];
        Test_Tex.SetData<Color>(Test_Data);

This runs perfectly fine, however if I change the Size value to 4097 I receive the following crash:

An unhandled exception of type ‘SharpDX.SharpDXException’ occurred in SharpDX.dll

Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.

I have tested to make sure this isn’t due to using a non multiple of 2 size as I can use a size of 4095 without any issue.

Since DX11 can handle textures bigger than 4096 I would’ve thought this kind of error wouldn’t occur unless I tried a size larger than 16384. I also get the same error if I try to create a RenderTarget2D larger than 4096.

My guess is that I might be running in DX9, but I should be in DX11 as I’m using Windows 10 with a DX12 graphics card. Is there a way to tell if I’m running DX9 or DX11 and if so, is there a way to select DX11?

Or is there something stupidly obviously I’m missing here?

Are you targeting the HiDef graphics profile? MonoGame defaults to Reach.

In your Game1 constructor, add this line:

graphics.GraphicsProfile = GraphicsProfile.HiDef;

And for good measure, set the MGCB to target HiDef as well by opening the Pipeline tool, selecting the base “Content” file and setting it in the properties window.

2 Likes

I had set the target on my MGCB to be HiDef but I didn’t even know the program had a setting, makes sense though.

Tested that and it works good up to 16384, now I get that error if I try to use 16385 or larger. It also works on RenderTarget2D!

I had a feeling the solution would be simple.

Thanks.