summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/d3d1x/gd3dapi
diff options
context:
space:
mode:
authorLuca Barbieri <luca@luca-barbieri.com>2010-09-12 02:49:36 +0200
committerLuca Barbieri <luca@luca-barbieri.com>2010-09-21 10:58:17 +0200
commit92617aeac109481258f0c3863d09c1b8903d438b (patch)
treed85d6a04e87d227964386ad1d6b3d6ae6954e179 /src/gallium/state_trackers/d3d1x/gd3dapi
parent894a307a91d6437ec418800952da2ec174e092f5 (diff)
d3d1x: add new Direct3D 10/11 COM state tracker for Gallium
This is a new implementation of the Direct3D 11 COM API for Gallium. Direct3D 10 and 10.1 implementations are also provided, which are automatically generated with s/D3D11/D3D10/g plus a bunch of #ifs. While this is an initial version, most of the code is there (limited to what Gallium can express), and tri, gears and texturing demos are working. The primary goal is to realize Gallium's promise of multiple API support, and provide an API that can be easily implemented with just a very thin wrapper over Gallium, instead of the enormous amount of complex code needed for OpenGL. The secondary goal is to run Windows Direct3D 10/11 games on Linux using Wine. Wine dlls are currently not provided, but adding them should be quite easy. Fglrx and nvidia drivers can also be supported by writing a Gallium driver that talks to them using OpenGL, which is a relatively easy task. Thanks to the great design of Direct3D 10/11 and closeness to Gallium, this approach should not result in detectable overhead, and is the most maintainable way to do it, providing a path to switch to the open Gallium drivers once they are on par with the proprietary ones. Currently Wine has a very limited Direct3D 10 implementation, and completely lacks a Direct3D 11 implementation. Note that Direct3D 10/11 are completely different from Direct3D 9 and earlier, and thus warrant a fully separate implementation. The third goal is to provide a superior alternative to OpenGL for graphics programming on non-Windows systems, particularly Linux and other free and open systems. Thanks to a very clean and well-though design done from scratch, the Direct3D 10/11 APIs are vastly better than OpenGL and can be supported with orders of magnitude less code and development time, as you can see by comparing the lines of code of this commit and those in the existing Mesa OpenGL implementation. This would have been true for the Longs Peak proposal as well, but unfortunately it was abandoned by Khronos, leaving the OpenGL ecosystem without a graphics API with a modern design. A binding of Direct3D 10/11 to EGL would solve this issue in the most economical way possible, and this would be great to provide in Mesa, since DXGI, the API used to bind Direct3D 10/11 to Windows, is a bit suboptimal, especially on non-Windows platforms. Finally, a mature Direct3D 10/11 implementation is intrinsically going to be faster and more reliable than an OpenGL implementation, thanks to the dramatically smaller API and the segregation of all nontrivial work to object creation that the application must perform ahead of time. Currently, this commit contains: - Independently created headers for Direct3D 10, 10.1, 11 and DXGI 1.1, partially based on the existing Wine headers for D3D10 and DXGI 1.0 - A parser for Direct3D 10/11 DXBC and TokenizedProgramFormat (TPF) - A shader translator from TokenizedProgramFormat to TGSI - Implementation of the Direct3D 11 core interfaces - Automatically generated implementation of Direct3D 10 and 10.1 - Implementation of DXGI using the "native" framework of the EGL st - Demos, usable either on Windows or on this implementation - d3d11tri, a clone of tri - d3d11tex, a (multi)texturing demo - d3d11gears, an improved version of glxgears - d3d11spikysphere, a D3D11 tessellation demo (currently Windows-only) - A downloader for the Microsoft HLSL compiler, needed to recompile the shaders (compiled shader bytecode is also included) To compile this, configure at least with these options: --with-state-trackers=egl,d3d1x --with-egl-platforms=x11 plus some gallium drivers (such as softpipe with --enable-gallium-swrast) The Wine headers (usually from a wine-dev or wine-devel package) must be installed. Only x86-32 has been tested. You may need to run "make" in the subdirectories of src/gallium/winsys/sw and you may need to manually run "sudo make install" in src/gallium/targets/egl To test it, run the demos in the "progs" directory. Windows binaries are included to find out how demos should work, and to test Wine integration when it will be done. Enjoy, and let me know if you manage to compile and run this, or which issues you are facing if not. Using softpipe is recommended for now, and your mileage with hardware drivers may vary. However, getting this to work on hardware drivers is also obviously very important. Note that currently llvmpipe is buggy and causes all 3 gears to be drawn with the same color. Use export GALLIUM_DRIVER=softpipe to avoid this. Thanks to all the Gallium contributors and especially the VMware team, whose work made it possible to implement Direct3D 10/11 much more easily than it would have been otherwise.
Diffstat (limited to 'src/gallium/state_trackers/d3d1x/gd3dapi')
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3dapi/Makefile4
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3dapi/galliumcom.idl76
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d10_1.idl30
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d11.idl31
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3dapi/galliumdxgi.idl77
5 files changed, 218 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/d3d1x/gd3dapi/Makefile b/src/gallium/state_trackers/d3d1x/gd3dapi/Makefile
new file mode 100644
index 0000000000..8b16b1bcbc
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3dapi/Makefile
@@ -0,0 +1,4 @@
+all: idl
+
+include ../Makefile.inc
+
diff --git a/src/gallium/state_trackers/d3d1x/gd3dapi/galliumcom.idl b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumcom.idl
new file mode 100644
index 0000000000..c42e10cb66
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumcom.idl
@@ -0,0 +1,76 @@
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/* Header for all COM-based Gallium APIs and state trackers */
+
+import "oaidl.idl";
+import "ocidl.idl";
+
+[object, local, uuid("481c9372-795f-4630-bd5b-1f46d33cc28b")]
+interface IGalliumAdapter : IUnknown
+{
+ struct pipe_screen* GetGalliumScreen();
+ struct pipe_screen* GetGalliumReferenceSoftwareScreen();
+ struct pipe_screen* GetGalliumFastSoftwareScreen();
+}
+
+[object, local, uuid("2c0f7e72-d9fe-4e7b-9fee-d476695ad5d9")]
+interface IGalliumDevice : IUnknown
+{
+ // turn Gallium resource into API resource
+ HRESULT OpenGalliumResource(
+ [in] struct pipe_resource* resource,
+ [out] IUnknown** api_resource
+ );
+
+ /* returns the Gallium context used by the device
+ * can return NULL if the device uses multiple contexts or doesn't want to implement GetGalliumContext()
+ * we have this function because often using one context is faster than using more (or it's the only working option)
+ */
+ struct pipe_context* GetGalliumContext();
+
+ // restore the context state after using the Gallium context for something else
+ // does nothing if GetGalliumContext returns null
+ void RestoreGalliumState();
+
+ /* like RestoreGalliumState, but ignores:
+ * - constant buffers
+ * - non-PS samplers and shader resource views
+ * - blend color, sample mask
+ * - scissor
+ * - index buffer
+ *
+ * This is intended to restore state after a blit-like operation.
+ */
+ void RestoreGalliumStateBlitOnly();
+};
+
+[object, local, uuid("61934787-7aea-412c-8c72-8afe6a33d622")]
+interface IGalliumResource : IUnknown
+{
+ struct pipe_resource* GetGalliumResource();
+};
+
diff --git a/src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d10_1.idl b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d10_1.idl
new file mode 100644
index 0000000000..d2b72f56a1
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d10_1.idl
@@ -0,0 +1,30 @@
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+import "ocidl.idl";
+import "d3d10_1.idl";
+
+HRESULT GalliumD3D10DeviceCreate1(struct pipe_screen* screen, struct pipe_context* context, BOOL owns_context, unsigned creation_flags, IDXGIAdapter* adapter, ID3D10Device1** ppDevice);
diff --git a/src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d11.idl b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d11.idl
new file mode 100644
index 0000000000..640cbfa881
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumd3d11.idl
@@ -0,0 +1,31 @@
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+import "ocidl.idl";
+import "d3d11.idl";
+
+HRESULT GalliumD3D11DeviceCreate(struct pipe_screen* screen, struct pipe_context* context, BOOL owns_context, unsigned creation_flags, IDXGIAdapter* adapter, ID3D11Device** ppDevice);
+
diff --git a/src/gallium/state_trackers/d3d1x/gd3dapi/galliumdxgi.idl b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumdxgi.idl
new file mode 100644
index 0000000000..9fbe5d01a7
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3dapi/galliumdxgi.idl
@@ -0,0 +1,77 @@
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+/* Header for the Gallium extensions to DXGI */
+
+import "galliumcom.idl";
+import "../d3dapi/dxgi.idl";
+
+/* These calls set the display system that will be associated
+ * to new DXGI factories created with CreateDXGIFactory and
+ * CreateDXGIFactory1 by the current thread.
+ *
+ * Existing factories and DXGI objects created from them are
+ * not affected.
+ *
+ * Gallium DXGI has both per-thread and per-process settings.
+ * If the per-thread display system has been set (i.e. a function
+ * of these was called, and the last one called was not UseNothing),
+ * it will be used.
+ * Otherwise, the per-process display system will be used if set, or
+ * and other the factory creation call may either fail, or use an
+ * user-specified default..
+ *
+ * The per-process setting can be altered by calling
+ * GalliumDXGIMakeDefault, which will set the per-process setting
+ * according to the current per-thread setting.
+ *
+ * GalliumDXGIUseNothing() is the initial state, which means that
+ * the per-process default should be used, and if that is "use nothing"
+ * too, the call will either fail or use a user-specified default.
+ *
+ * NOTE that setting the per-process default is NOT atomic and must
+ * not be done concurrently with other calls to GalliumDXGIMakeDefault,
+ * CreateDXGIFactory or CreateDXGIFactory1.
+ *
+ * The PFNHWNDRESOLVER function is passed HWNDs coming from
+ * the API user and must return window-system-specific values:
+ * - X11: Window*
+ * - GDI: HWND
+ */
+
+typedef struct _XDisplay Display;
+typedef void* (*PFNHWNDRESOLVER)(void*, HWND);
+
+void GalliumDXGIUseNothing();
+
+/* only a subset of these may be available, depending on platform and compilation options */
+void GalliumDXGIUseX11Display(Display* dpy, PFNHWNDRESOLVER resolver, void* resolver_cookie);
+void GalliumDXGIUseDRMCard(int fd);
+void GalliumDXGIUseFBDev(int fd);
+void GalliumDXGIUseHDC(HDC hdc, PFNHWNDRESOLVER resolver, void* resolver_cookie);
+
+void GalliumDXGIMakeDefault();
+