DirectX 11 + MinGW-w64

Started by
8 comments, last by martymc 12 years, 2 months ago
So I'm having a hard time getting DirectX 11 and MinGW to cooperate. MinGW seems to come with some DX11 headers, but I wasn't able to get anything to compile since it couldn't even seem to find a class definition for ID3D11Device. sleep.png

With some help online I managed to come up with this:

d3d11-mingw.h
[source]
#define __in
#define __out
#define __inout
#define __in_bcount(x)
#define __out_bcount(x)
#define __in_ecount(x)
#define __out_ecount(x)
#define __in_ecount_opt(x)
#define __out_ecount_opt(x)
#define __in_bcount_opt(x)
#define __out_bcount_opt(x)
#define __in_opt
#define __inout_opt
#define __out_opt
#define __out_ecount_part_opt(x,y)
#define __deref_out
#define __deref_out_opt
#define __RPC__deref_out

#include <d3d11.h> //from D3D SDK

#ifdef __uuidof
#undef __uuidof
#endif
#define __uuidof(x) IID_##x

#ifdef DEFINE_GUID
#undef DEFINE_GUID
#endif
#define DEFINE_GUID(id, a, b, c, d, e, f, g, h, i, j, k) const GUID id = { a,b,c, { d,e,f,g,h,i,j,k } };

DEFINE_GUID(IID_ID3D11DeviceChild,0x1841e5c8,0x16b0,0x489b,0xbc,0xc8,0x44,0xcf,0xb0,0xd5,0xde,0xae);
DEFINE_GUID(IID_ID3D11DepthStencilState,0x03823efb,0x8d8f,0x4e1c,0x9a,0xa2,0xf6,0x4b,0xb2,0xcb,0xfd,0xf1);
DEFINE_GUID(IID_ID3D11BlendState,0x75b68faa,0x347d,0x4159,0x8f,0x45,0xa0,0x64,0x0f,0x01,0xcd,0x9a);
DEFINE_GUID(IID_ID3D11RasterizerState,0x9bb4ab81,0xab1a,0x4d8f,0xb5,0x06,0xfc,0x04,0x20,0x0b,0x6e,0xe7);
DEFINE_GUID(IID_ID3D11Resource,0xdc8e63f3,0xd12b,0x4952,0xb4,0x7b,0x5e,0x45,0x02,0x6a,0x86,0x2d);
DEFINE_GUID(IID_ID3D11Buffer,0x48570b85,0xd1ee,0x4fcd,0xa2,0x50,0xeb,0x35,0x07,0x22,0xb0,0x37);
DEFINE_GUID(IID_ID3D11Texture1D,0xf8fb5c27,0xc6b3,0x4f75,0xa4,0xc8,0x43,0x9a,0xf2,0xef,0x56,0x4c);
DEFINE_GUID(IID_ID3D11Texture2D,0x6f15aaf2,0xd208,0x4e89,0x9a,0xb4,0x48,0x95,0x35,0xd3,0x4f,0x9c);
DEFINE_GUID(IID_ID3D11Texture3D,0x037e866e,0xf56d,0x4357,0xa8,0xaf,0x9d,0xab,0xbe,0x6e,0x25,0x0e);
DEFINE_GUID(IID_ID3D11View,0x839d1216,0xbb2e,0x412b,0xb7,0xf4,0xa9,0xdb,0xeb,0xe0,0x8e,0xd1);
DEFINE_GUID(IID_ID3D11ShaderResourceView,0xb0e06fe0,0x8192,0x4e1a,0xb1,0xca,0x36,0xd7,0x41,0x47,0x10,0xb2);
DEFINE_GUID(IID_ID3D11RenderTargetView,0xdfdba067,0x0b8d,0x4865,0x87,0x5b,0xd7,0xb4,0x51,0x6c,0xc1,0x64);
DEFINE_GUID(IID_ID3D11DepthStencilView,0x9fdac92a,0x1876,0x48c3,0xaf,0xad,0x25,0xb9,0x4f,0x84,0xa9,0xb6);
DEFINE_GUID(IID_ID3D11UnorderedAccessView,0x28acf509,0x7f5c,0x48f6,0x86,0x11,0xf3,0x16,0x01,0x0a,0x63,0x80);
DEFINE_GUID(IID_ID3D11VertexShader,0x3b301d64,0xd678,0x4289,0x88,0x97,0x22,0xf8,0x92,0x8b,0x72,0xf3);
DEFINE_GUID(IID_ID3D11HullShader,0x8e5c6061,0x628a,0x4c8e,0x82,0x64,0xbb,0xe4,0x5c,0xb3,0xd5,0xdd);
DEFINE_GUID(IID_ID3D11DomainShader,0xf582c508,0x0f36,0x490c,0x99,0x77,0x31,0xee,0xce,0x26,0x8c,0xfa);
DEFINE_GUID(IID_ID3D11GeometryShader,0x38325b96,0xeffb,0x4022,0xba,0x02,0x2e,0x79,0x5b,0x70,0x27,0x5c);
DEFINE_GUID(IID_ID3D11PixelShader,0xea82e40d,0x51dc,0x4f33,0x93,0xd4,0xdb,0x7c,0x91,0x25,0xae,0x8c);
DEFINE_GUID(IID_ID3D11ComputeShader,0x4f5b196e,0xc2bd,0x495e,0xbd,0x01,0x1f,0xde,0xd3,0x8e,0x49,0x69);
DEFINE_GUID(IID_ID3D11InputLayout,0xe4819ddc,0x4cf0,0x4025,0xbd,0x26,0x5d,0xe8,0x2a,0x3e,0x07,0xb7);
DEFINE_GUID(IID_ID3D11SamplerState,0xda6fea51,0x564c,0x4487,0x98,0x10,0xf0,0xd0,0xf9,0xb4,0xe3,0xa5);
DEFINE_GUID(IID_ID3D11Asynchronous,0x4b35d0cd,0x1e15,0x4258,0x9c,0x98,0x1b,0x13,0x33,0xf6,0xdd,0x3b);
DEFINE_GUID(IID_ID3D11Query,0xd6c00747,0x87b7,0x425e,0xb8,0x4d,0x44,0xd1,0x08,0x56,0x0a,0xfd);
DEFINE_GUID(IID_ID3D11Predicate,0x9eb576dd,0x9f77,0x4d86,0x81,0xaa,0x8b,0xab,0x5f,0xe4,0x90,0xe2);
DEFINE_GUID(IID_ID3D11Counter,0x6e8c49fb,0xa371,0x4770,0xb4,0x40,0x29,0x08,0x60,0x22,0xb7,0x41);
DEFINE_GUID(IID_ID3D11ClassInstance,0xa6cd7faa,0xb0b7,0x4a2f,0x94,0x36,0x86,0x62,0xa6,0x57,0x97,0xcb);
DEFINE_GUID(IID_ID3D11ClassLinkage,0xddf57cba,0x9543,0x46e4,0xa1,0x2b,0xf2,0x07,0xa0,0xfe,0x7f,0xed);
DEFINE_GUID(IID_ID3D11CommandList,0xa24bc4d1,0x769e,0x43f7,0x80,0x13,0x98,0xff,0x56,0x6c,0x18,0xe2);
DEFINE_GUID(IID_ID3D11DeviceContext,0xc0bfa96c,0xe089,0x44fb,0x8e,0xaf,0x26,0xf8,0x79,0x61,0x90,0xda);
DEFINE_GUID(IID_ID3D11Device,0xdb6f6ddb,0xac77,0x4e88,0x82,0x53,0x81,0x9d,0xf9,0xbb,0xf1,0x40);
[/source]

Using this, I managed to compile a simple 32-bit hello world DirectX 11 program which sets up a device and swap chain and back buffer. However, if I compile it as 64-bits, it crashes when I call:


DXGI_SWAP_CHAIN_DESC scd;
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

scd.BufferCount = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = hWnd;
scd.SampleDesc.Count = 4;
scd.Windowed = true;

D3D11CreateDeviceAndSwapChain(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL, 0,
NULL, 0,
D3D11_SDK_VERSION,
&scd, &swapchain,
&dev, NULL,
&devcon); //crash


Any ideas on how I can get these two to work together better? I really[/d] don't want to have to deal with VC++. dry.png
Advertisement
I don't think that you can leave 11th argument NULL.
Also - have you checked that debug logging with DirectX Control Panel doesn't display some obvious error message?

But you really should try using VC++. It's nice IDE, especially when you need to debug code.

really[/d] don't want to have to deal with VC++. dry.png


smart move.. and very nice results. congrats.

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni


I don't think that you can leave 11th argument NULL.


That wasn't the issue.


But you really should try using VC++. It's nice IDE, especially when you need to debug code.
[/quote]

So, I should drop the compiler I'm used to, the one that is free with outstanding support for C++11 and virtually no bugs, and switch to VC++ Express, a non-optimizing compiler with few C++11 features and several bugs that I've personally encountered? I'm not exactly excited about the thought of that.

Edit: OK, I stand corrected, it's supposedly a "fully optimizing" compiler, but I believe GCC still wins by far when it comes to the performance of the code generated by it's auto vectorization.


smart move.. and very nice results. congrats.


Wow. You are incredibly ignorant and arrogant. Thanks for the help buddy.
I'd personally just use the one that is known to work.  In the case of D3D11 that's MSVC (as an added bonus you'll have the best debugger in the business available to you too).

I think your performance concerns are somewhat unfounded.  A huge chunk of your runtime performance is going to be going on stuff running on your GPU, and the compiler used for you C/C++ code is completely irrelevant where that's concerned.  Where stuff does run on the CPU, proper and sensible data and code structures will give you much better results than any amount of compiler-side micro-optimizations.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


But you really should try using VC++. It's nice IDE, especially when you need to debug code.
[/quote]

If the original poster wants to discuss DX11 + MinGW64, then by all means, let him have his topic. There's plenty of room for DX11 + VS2010 threads as well.


So, I should drop the compiler I'm used to, the one that is free with outstanding support for C++11 and virtually no bugs, and switch to VC++ Express, a non-optimizing compiler with few C++11 features and several bugs that I've personally encountered? I'm not exactly excited about the thought of that.

Edit: OK, I stand corrected, it's supposedly a "fully optimizing" compiler, but I believe GCC still wins by far when it comes to the performance of the code generated by it's auto vectorization.


Let's not throw in comments based on FUD. GCC is not virtually bug-free: there are 842 outstanding unfixed bugs in the GCC C++ compiler frontend alone. Visual Studio is not bug-free either.

Believing "GCC wins by far in performance" does not make it a correct statement either. It might. Or it might not. Instead of believing, it is better to profile, but unfortunately, there are not that many great sources available that would accurately profile these compilers. Two sources I found

  • http://www.g-truc.net/post-0372.html : VC2010 beats GCC by a large margin.
  • http://www.willus.com/ccomp_benchmark2.shtml?p1 : GCC beats VC2010 in 6 out of 10 tests.

I do not mean to derail, now please let's stick to the original topic.
virtually no bugs


You are being silly:
http://gcc.gnu.org/b...&resolution=---
http://gcc.gnu.org/b...&resolution=---
http://gcc.gnu.org/b...&resolution=---
http://gcc.gnu.org/b...&resolution=---

Every software has a bugs. And GCC is no exception from that. I develop with both - gcc and msvc compilers. And both have bugs. Different ones, of course, but they have bugs. Actually in my experience GCC has far more bugs (and worse ones) than MSVC.
Well, I have yet to encounter any serious bug myself in the latest GCC, and with the rate at which new versions and bug fixes are released, I wouldn't expect it to be much of a problem if I did. Visual Studio? Well, if you find a bug (which I have, several), you can wait a couple years and hope their next product comes with a fix. And that doesn't even address the overwhelming lack of support for C++11.

In any case I shouldn't have to defend my personal preference for what is a great compiler. Visual Studio isn't even available on the other platforms I use, and MinGW makes working in Windows easy and consistent. There is really no reason somebody shouldn't be able to compile D3D11 applications with it.

Visual Studio isn't even available on the other platforms I use


Nor is D3D11. Problem goes away.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Hi I have the solution to your problem.

I done the same thing a few months back.
What I had to do was download the official windows dx sdk and put the defines as you have done above.
I then had to get the directx dll files and use this
http://sourceforge.n...w64/wiki/gendef
And then from that I created library files to link with.

Lucky for you ruben seems to have added this to his latest personal build.

http://sourceforge.n...ubenvb/4.7.0-1/
Get the gcc build

Sample Program Follows

http://pastebin.com/QKwyL7Ph

Best of luck.. post back if you run into any problems smile.png

EDIT:



forgot to post compile and link parameters..

compile

-municode
-mwindows

-link

-ld3d11
-ld3dx11_43
-lgdi32

Also
http://orwellengine.blogspot.com/

Devcpp for mingw64 if you want a nice old style low memory consumption ide.
Although I use programmers notepad myself

This topic is closed to new replies.

Advertisement