summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Barbieri <luca@luca-barbieri.com>2010-09-12 00:49:36 (GMT)
committerLuca Barbieri <luca@luca-barbieri.com>2010-09-21 08:58:17 (GMT)
commit92617aeac109481258f0c3863d09c1b8903d438b (patch)
treed85d6a04e87d227964386ad1d6b3d6ae6954e179
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.
-rw-r--r--src/gallium/state_trackers/d3d1x/Makefile11
-rw-r--r--src/gallium/state_trackers/d3d1x/Makefile.inc19
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/Makefile7
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h101
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/include/le32.h45
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/include/tpf.h808
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_dump.cpp43
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp93
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_analyze.cpp186
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_dump.cpp222
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_parse.cpp424
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_text.cpp385
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/src/utils.h45
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xshader/tools/fxdis.cpp75
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xstutil/Makefile5
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xstutil/include/d3d1xstutil.h1038
-rw-r--r--src/gallium/state_trackers/d3d1x/d3d1xstutil/src/dxgi_enums.cpp147
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/Makefile4
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/d3d10.idl1554
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/d3d10_1.idl191
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/d3d10misc.h47
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/d3d10shader.idl269
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/d3d11.idl2492
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/d3d11shader.idl287
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/d3dcommon.idl700
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/dxgi.idl470
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/dxgiformat.idl129
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/dxgitype.idl84
-rw-r--r--src/gallium/state_trackers/d3d1x/d3dapi/specstrings.h25
-rw-r--r--src/gallium/state_trackers/d3d1x/docs/Makefile4
-rw-r--r--src/gallium/state_trackers/d3d1x/docs/coding_style.txt85
-rw-r--r--src/gallium/state_trackers/d3d1x/docs/module_dependencies.dot25
-rw-r--r--src/gallium/state_trackers/d3d1x/docs/source_layout.txt17
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgi/Makefile17
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_loader.cpp206
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp1314
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_private.h50
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgid3d10/Makefile4
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgid3d10/dxgid3d10.cpp149
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgid3d11/Makefile4
-rw-r--r--src/gallium/state_trackers/d3d1x/dxgid3d11/dxgid3d11.cpp135
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d10/Makefile19
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/gd3d10/d3d10.pl12
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d11/Makefile6
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d11/d3d11.cpp236
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h2033
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d11/d3d11_objects.h715
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d11/d3d11_screen.h1447
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d1x/Makefile6
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d1x/d3d1x_private.h101
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d1x/d3d_enums.cpp147
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d1x/tools/dxbc2tgsi.cpp82
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.cpp832
-rw-r--r--src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.h34
-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
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/mstools/download-mstools73
-rw-r--r--src/gallium/state_trackers/d3d1x/progs/Makefile32
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/bin/d3d10tri.exebin0 -> 11776 bytes
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/bin/d3d11gears.exebin0 -> 27136 bytes
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/bin/d3d11spikysphere.exebin0 -> 17408 bytes
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/bin/d3d11tex.exebin0 -> 22016 bytes
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/bin/d3d11tri.exebin0 -> 11776 bytes
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10app.h51
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10winmain.cpp188
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10app/d3d10x11main.cpp164
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10tri/d3d10tri.cpp118
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10tri/d3d10tri.hlsl50
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10tri/d3d10tri.hlsl.ps.h112
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10tri/d3d10tri.hlsl.vs.h128
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d10tri/d3d10tri.vcxproj98
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11app/d3d11app.h51
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11app/d3d11blit.hlsl53
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11app/d3d11blit.hlsl.ps.h142
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11app/d3d11blit.hlsl.vs.h130
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11app/d3d11u.h424
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11app/d3d11winmain.cpp172
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11app/d3d11x11main.cpp124
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11gears/d3d11gears.cpp573
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11gears/d3d11gears.hlsl75
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11gears/d3d11gears.hlsl.ps.h309
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11gears/d3d11gears.hlsl.vs.h308
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11gears/d3d11gears.vcxproj100
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11spikysphere/d3d11spikysphere.cpp227
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11spikysphere/d3d11spikysphere.hlsl193
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11spikysphere/d3d11spikysphere.hlsl.ds.h623
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11spikysphere/d3d11spikysphere.hlsl.hs.h297
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11spikysphere/d3d11spikysphere.hlsl.ps.h211
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11spikysphere/d3d11spikysphere.hlsl.vs.h105
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11spikysphere/d3d11spikysphere.vcxproj102
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tex/d3d11tex.cpp116
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tex/d3d11tex.hlsl66
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tex/d3d11tex.hlsl.ps.h234
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tex/d3d11tex.hlsl.vs.h153
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tex/d3d11tex.vcxproj98
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tri/d3d11tri.cpp120
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tri/d3d11tri.hlsl50
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tri/d3d11tri.hlsl.ps.h112
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tri/d3d11tri.hlsl.vs.h128
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/d3d11tri/d3d11tri.vcxproj99
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/data/cornell_box_image.h1028
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/data/tux_image.h1028
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/progs/progs.sln49
-rwxr-xr-xsrc/gallium/state_trackers/d3d1x/tools/fxc16
l---------src/gallium/state_trackers/d3d1x/w32api1
108 files changed, 26335 insertions, 0 deletions
diff --git a/src/gallium/state_trackers/d3d1x/Makefile b/src/gallium/state_trackers/d3d1x/Makefile
new file mode 100644
index 0000000..6d55376
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/Makefile
@@ -0,0 +1,11 @@
+SUBDIRS=d3dapi gd3dapi docs d3d1xstutil d3d1xshader gd3d1x gd3d11 gd3d10 dxgi dxgid3d11 dxgid3d10 progs
+
+all:
+ @for dir in $(SUBDIRS) ; do $(MAKE) -C "$$dir" || exit $?; done
+
+clean:
+ rm -f `find . -name \*.[oa]`
+ rm -f `find . -name depend`
+
+install:
+
diff --git a/src/gallium/state_trackers/d3d1x/Makefile.inc b/src/gallium/state_trackers/d3d1x/Makefile.inc
new file mode 100644
index 0000000..1b9423b
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/Makefile.inc
@@ -0,0 +1,19 @@
+TOP=../../../../..
+include $(TOP)/configs/current
+
+IDL=$(wildcard *.idl include/*.idl)
+IDL_H=$(IDL:.idl=.h)
+LD=$(CXX)
+
+include ../../../Makefile.template
+
+idl: $(IDL_H)
+
+%.h: %.idl
+ widl -I../gd3dapi -I../d3dapi -I../w32api -U /dev/null -H $@ $^
+
+%.svg: %.dot
+ dot -Tsvg -o $@ $<
+
+%.pdf: %.dot
+ dot -Tpdf -o $@ $<
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/Makefile b/src/gallium/state_trackers/d3d1x/d3d1xshader/Makefile
new file mode 100644
index 0000000..6ac74d1
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/Makefile
@@ -0,0 +1,7 @@
+LIBNAME=d3d1xshader
+CPP_SOURCES=$(wildcard src/*.cpp)
+LIBRARY_INCLUDES=-Iinclude -I../w32api -I../d3dapi
+PROGS=tools/fxdis
+LIBS=libd3d1xshader.a
+
+include ../Makefile.inc
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h
new file mode 100644
index 0000000..44fce81
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/dxbc.h
@@ -0,0 +1,101 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef DXBC_H_
+#define DXBC_H_
+
+#include <stdint.h>
+#include <vector>
+#include <map>
+#include <iostream>
+#include "le32.h"
+
+#define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24 ))
+#define FOURCC_DXBC FOURCC('D', 'X', 'B', 'C')
+#define FOURCC_RDEF FOURCC('R', 'D', 'E', 'F')
+#define FOURCC_ISGN FOURCC('I', 'S', 'G', 'N')
+#define FOURCC_OSGN FOURCC('O', 'S', 'G', 'N')
+#define FOURCC_SHDR FOURCC('S', 'H', 'D', 'R')
+#define FOURCC_SHEX FOURCC('S', 'H', 'E', 'X')
+#define FOURCC_STAT FOURCC('S', 'T', 'A', 'T')
+
+/* this is always little-endian! */
+struct dxbc_chunk_header
+{
+ unsigned fourcc;
+ unsigned size;
+};
+
+/* this is always little-endian! */
+struct dxbc_chunk_signature : public dxbc_chunk_header
+{
+ uint32_t count;
+ uint32_t unk;
+ struct
+ {
+ uint32_t name_offset;
+ uint32_t semantic_index;
+ uint32_t system_value_type;
+ uint32_t component_type;
+ uint32_t register_num;
+ uint8_t mask;
+ uint8_t read_write_mask;
+ uint8_t stream; /* TODO: guess! */
+ uint8_t unused;
+ } elements[];
+};
+
+struct dxbc_container
+{
+ const void* data;
+ std::vector<dxbc_chunk_header*> chunks;
+ std::map<unsigned, unsigned> chunk_map;
+};
+
+dxbc_container* dxbc_parse(const void* data, int size);
+std::ostream& operator <<(std::ostream& out, const dxbc_container& container);
+
+dxbc_chunk_header* dxbc_find_chunk(const void* data, int size, unsigned fourcc);
+
+static inline dxbc_chunk_header* dxbc_find_shader_bytecode(const void* data, int size)
+{
+ dxbc_chunk_header* chunk;
+ chunk = dxbc_find_chunk(data, size, FOURCC_SHDR);
+ if(!chunk)
+ chunk = dxbc_find_chunk(data, size, FOURCC_SHEX);
+ return chunk;
+}
+
+static inline dxbc_chunk_signature* dxbc_find_signature(const void* data, int size, bool output)
+{
+ return (dxbc_chunk_signature*)dxbc_find_chunk(data, size, output ? FOURCC_OSGN : FOURCC_ISGN);
+}
+
+struct _D3D11_SIGNATURE_PARAMETER_DESC;
+typedef struct _D3D11_SIGNATURE_PARAMETER_DESC D3D11_SIGNATURE_PARAMETER_DESC;
+int dxbc_parse_signature(dxbc_chunk_signature* sig, D3D11_SIGNATURE_PARAMETER_DESC** params);
+
+#endif /* DXBC_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/include/le32.h b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/le32.h
new file mode 100644
index 0000000..923942a
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/le32.h
@@ -0,0 +1,45 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef LE32_H_
+#define LE32_H_
+
+#include <stdint.h>
+#include <assert.h>
+
+#ifdef WORDS_BIGENDIAN
+static inline uint32_t bswap_le32(uint32_t v)
+{
+ return ((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24);
+}
+#else
+static inline uint32_t bswap_le32(uint32_t v)
+{
+ return v;
+}
+#endif
+
+#endif /* LE32_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/include/tpf.h b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/tpf.h
new file mode 100644
index 0000000..2761b79
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/include/tpf.h
@@ -0,0 +1,808 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef TPF_H_
+#define TPF_H_
+
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <memory>
+#include <vector>
+#include <map>
+#include <iostream>
+#include "le32.h"
+
+/* This is an independent implementation of definitions and tools for the
+ * "tokenized program format" (TPF) bytecode documented in the
+ * d3d11TokenizedProgramFormat.hpp header in the Windows Driver Development kit
+ */
+
+enum tpf_opcode {
+ // Shader Model 4.0 (Direct3D 10.0)
+
+ TPF_OPCODE_ADD,
+ TPF_OPCODE_AND,
+ TPF_OPCODE_BREAK,
+ TPF_OPCODE_BREAKC,
+ TPF_OPCODE_CALL,
+ TPF_OPCODE_CALLC,
+ TPF_OPCODE_CASE,
+ TPF_OPCODE_CONTINUE,
+ TPF_OPCODE_CONTINUEC,
+ TPF_OPCODE_CUT,
+ TPF_OPCODE_DEFAULT,
+ TPF_OPCODE_DERIV_RTX,
+ TPF_OPCODE_DERIV_RTY,
+ TPF_OPCODE_DISCARD,
+ TPF_OPCODE_DIV,
+ TPF_OPCODE_DP2,
+ TPF_OPCODE_DP3,
+ TPF_OPCODE_DP4,
+ TPF_OPCODE_ELSE,
+ TPF_OPCODE_EMIT,
+ TPF_OPCODE_EMITTHENCUT,
+ TPF_OPCODE_ENDIF,
+ TPF_OPCODE_ENDLOOP,
+ TPF_OPCODE_ENDSWITCH,
+ TPF_OPCODE_EQ,
+ TPF_OPCODE_EXP,
+ TPF_OPCODE_FRC,
+ TPF_OPCODE_FTOI,
+ TPF_OPCODE_FTOU,
+ TPF_OPCODE_GE,
+ TPF_OPCODE_IADD,
+ TPF_OPCODE_IF,
+ TPF_OPCODE_IEQ,
+ TPF_OPCODE_IGE,
+ TPF_OPCODE_ILT,
+ TPF_OPCODE_IMAD,
+ TPF_OPCODE_IMAX,
+ TPF_OPCODE_IMIN,
+ TPF_OPCODE_IMUL,
+ TPF_OPCODE_INE,
+ TPF_OPCODE_INEG,
+ TPF_OPCODE_ISHL,
+ TPF_OPCODE_ISHR,
+ TPF_OPCODE_ITOF,
+ TPF_OPCODE_LABEL,
+ TPF_OPCODE_LD,
+ TPF_OPCODE_LD_MS,
+ TPF_OPCODE_LOG,
+ TPF_OPCODE_LOOP,
+ TPF_OPCODE_LT,
+ TPF_OPCODE_MAD,
+ TPF_OPCODE_MIN,
+ TPF_OPCODE_MAX,
+ TPF_OPCODE_CUSTOMDATA,
+ TPF_OPCODE_MOV,
+ TPF_OPCODE_MOVC,
+ TPF_OPCODE_MUL,
+ TPF_OPCODE_NE,
+ TPF_OPCODE_NOP,
+ TPF_OPCODE_NOT,
+ TPF_OPCODE_OR,
+ TPF_OPCODE_RESINFO,
+ TPF_OPCODE_RET,
+ TPF_OPCODE_RETC,
+ TPF_OPCODE_ROUND_NE,
+ TPF_OPCODE_ROUND_NI,
+ TPF_OPCODE_ROUND_PI,
+ TPF_OPCODE_ROUND_Z,
+ TPF_OPCODE_RSQ,
+ TPF_OPCODE_SAMPLE,
+ TPF_OPCODE_SAMPLE_C,
+ TPF_OPCODE_SAMPLE_C_LZ,
+ TPF_OPCODE_SAMPLE_L,
+ TPF_OPCODE_SAMPLE_D,
+ TPF_OPCODE_SAMPLE_B,
+ TPF_OPCODE_SQRT,
+ TPF_OPCODE_SWITCH,
+ TPF_OPCODE_SINCOS,
+ TPF_OPCODE_UDIV,
+ TPF_OPCODE_ULT,
+ TPF_OPCODE_UGE,
+ TPF_OPCODE_UMUL,
+ TPF_OPCODE_UMAD,
+ TPF_OPCODE_UMAX,
+ TPF_OPCODE_UMIN,
+ TPF_OPCODE_USHR,
+ TPF_OPCODE_UTOF,
+ TPF_OPCODE_XOR,
+
+ // these have custom formats
+ TPF_OPCODE_DCL_RESOURCE,
+ TPF_OPCODE_DCL_CONSTANT_BUFFER,
+ TPF_OPCODE_DCL_SAMPLER,
+ TPF_OPCODE_DCL_INDEX_RANGE,
+ TPF_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY,
+ TPF_OPCODE_DCL_GS_INPUT_PRIMITIVE,
+ TPF_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT,
+ TPF_OPCODE_DCL_INPUT,
+ TPF_OPCODE_DCL_INPUT_SGV,
+ TPF_OPCODE_DCL_INPUT_SIV,
+ TPF_OPCODE_DCL_INPUT_PS,
+ TPF_OPCODE_DCL_INPUT_PS_SGV,
+ TPF_OPCODE_DCL_INPUT_PS_SIV,
+ TPF_OPCODE_DCL_OUTPUT,
+ TPF_OPCODE_DCL_OUTPUT_SGV,
+ TPF_OPCODE_DCL_OUTPUT_SIV,
+ TPF_OPCODE_DCL_TEMPS,
+ TPF_OPCODE_DCL_INDEXABLE_TEMP,
+ TPF_OPCODE_DCL_GLOBAL_FLAGS,
+
+ TPF_OPCODE_D3D10_COUNT, // this is really a reserved opcode...
+
+ // Shader Model 4.1 (Direct3D 10.1)
+
+ TPF_OPCODE_LOD,
+ TPF_OPCODE_GATHER4,
+ TPF_OPCODE_SAMPLE_POS,
+ TPF_OPCODE_SAMPLE_INFO,
+
+ TPF_OPCODE_D3D10_1_COUNT, // this is really a reserved opcode...
+
+ // Shader Model 5.0 (Direct3D 11)
+
+ // HS subshader beginning markers
+ TPF_OPCODE_HS_DECLS,
+ TPF_OPCODE_HS_CONTROL_POINT_PHASE,
+ TPF_OPCODE_HS_FORK_PHASE,
+ TPF_OPCODE_HS_JOIN_PHASE,
+
+ TPF_OPCODE_EMIT_STREAM,
+ TPF_OPCODE_CUT_STREAM,
+ TPF_OPCODE_EMITTHENCUT_STREAM,
+ TPF_OPCODE_INTERFACE_CALL,
+
+ TPF_OPCODE_BUFINFO,
+ TPF_OPCODE_DERIV_RTX_COARSE,
+ TPF_OPCODE_DERIV_RTX_FINE,
+ TPF_OPCODE_DERIV_RTY_COARSE,
+ TPF_OPCODE_DERIV_RTY_FINE,
+ TPF_OPCODE_GATHER4_C,
+ TPF_OPCODE_GATHER4_PO,
+ TPF_OPCODE_GATHER4_PO_C,
+ TPF_OPCODE_RCP,
+ TPF_OPCODE_F32TOF16,
+ TPF_OPCODE_F16TOF32,
+ TPF_OPCODE_UADDC,
+ TPF_OPCODE_USUBB,
+ TPF_OPCODE_COUNTBITS,
+ TPF_OPCODE_FIRSTBIT_HI,
+ TPF_OPCODE_FIRSTBIT_LO,
+ TPF_OPCODE_FIRSTBIT_SHI,
+ TPF_OPCODE_UBFE,
+ TPF_OPCODE_IBFE,
+ TPF_OPCODE_BFI,
+ TPF_OPCODE_BFREV,
+ TPF_OPCODE_SWAPC,
+
+ // these have custom formats
+ TPF_OPCODE_DCL_STREAM,
+ TPF_OPCODE_DCL_FUNCTION_BODY,
+ TPF_OPCODE_DCL_FUNCTION_TABLE,
+ TPF_OPCODE_DCL_INTERFACE,
+
+ // these have custom formats
+ TPF_OPCODE_DCL_INPUT_CONTROL_POINT_COUNT,
+ TPF_OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT,
+ TPF_OPCODE_DCL_TESS_DOMAIN,
+ TPF_OPCODE_DCL_TESS_PARTITIONING,
+ TPF_OPCODE_DCL_TESS_OUTPUT_PRIMITIVE,
+ TPF_OPCODE_DCL_HS_MAX_TESSFACTOR,
+ TPF_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT,
+ TPF_OPCODE_DCL_HS_JOIN_PHASE_INSTANCE_COUNT,
+
+ // these have custom formats
+ TPF_OPCODE_DCL_THREAD_GROUP,
+ TPF_OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED,
+ TPF_OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW,
+ TPF_OPCODE_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED,
+ TPF_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW,
+ TPF_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED,
+ TPF_OPCODE_DCL_RESOURCE_RAW,
+ TPF_OPCODE_DCL_RESOURCE_STRUCTURED,
+
+ TPF_OPCODE_LD_UAV_TYPED,
+ TPF_OPCODE_STORE_UAV_TYPED,
+ TPF_OPCODE_LD_RAW,
+ TPF_OPCODE_STORE_RAW,
+ TPF_OPCODE_LD_STRUCTURED,
+ TPF_OPCODE_STORE_STRUCTURED,
+
+ TPF_OPCODE_ATOMIC_AND,
+ TPF_OPCODE_ATOMIC_OR,
+ TPF_OPCODE_ATOMIC_XOR,
+ TPF_OPCODE_ATOMIC_CMP_STORE,
+ TPF_OPCODE_ATOMIC_IADD,
+ TPF_OPCODE_ATOMIC_IMAX,
+ TPF_OPCODE_ATOMIC_IMIN,
+ TPF_OPCODE_ATOMIC_UMAX,
+ TPF_OPCODE_ATOMIC_UMIN,
+
+ TPF_OPCODE_IMM_ATOMIC_ALLOC,
+ TPF_OPCODE_IMM_ATOMIC_CONSUME,
+ TPF_OPCODE_IMM_ATOMIC_IADD,
+ TPF_OPCODE_IMM_ATOMIC_AND,
+ TPF_OPCODE_IMM_ATOMIC_OR,
+ TPF_OPCODE_IMM_ATOMIC_XOR,
+ TPF_OPCODE_IMM_ATOMIC_EXCH,
+ TPF_OPCODE_IMM_ATOMIC_CMP_EXCH,
+ TPF_OPCODE_IMM_ATOMIC_IMAX,
+ TPF_OPCODE_IMM_ATOMIC_IMIN,
+ TPF_OPCODE_IMM_ATOMIC_UMAX,
+ TPF_OPCODE_IMM_ATOMIC_UMIN,
+
+ TPF_OPCODE_SYNC,
+
+ TPF_OPCODE_DADD,
+ TPF_OPCODE_DMAX,
+ TPF_OPCODE_DMIN,
+ TPF_OPCODE_DMUL,
+ TPF_OPCODE_DEQ,
+ TPF_OPCODE_DGE,
+ TPF_OPCODE_DLT,
+ TPF_OPCODE_DNE,
+ TPF_OPCODE_DMOV,
+ TPF_OPCODE_DMOVC,
+
+ TPF_OPCODE_DTOF,
+ TPF_OPCODE_FTOD,
+
+ TPF_OPCODE_EVAL_SNAPPED,
+ TPF_OPCODE_EVAL_SAMPLE_INDEX,
+ TPF_OPCODE_EVAL_CENTROID,
+
+ TPF_OPCODE_DCL_GS_INSTANCE_COUNT,
+
+ TPF_OPCODE_D3D11_COUNT
+};
+
+extern const char* tpf_opcode_names[];
+
+enum tpf_file
+{
+ TPF_FILE_TEMP = 0,
+ TPF_FILE_INPUT = 1,
+ TPF_FILE_OUTPUT = 2,
+ TPF_FILE_INDEXABLE_TEMP = 3,
+ TPF_FILE_IMMEDIATE32 = 4, // one 32-bit value for each component follows
+ TPF_FILE_IMMEDIATE64 = 5, // one 64-bit value for each component follows
+ TPF_FILE_SAMPLER = 6,
+ TPF_FILE_RESOURCE = 7,
+ TPF_FILE_CONSTANT_BUFFER= 8,
+ TPF_FILE_IMMEDIATE_CONSTANT_BUFFER= 9,
+ TPF_FILE_LABEL = 10,
+ TPF_FILE_INPUT_PRIMITIVEID = 11,
+ TPF_FILE_OUTPUT_DEPTH = 12,
+ TPF_FILE_NULL = 13,
+
+ // Added in D3D10.1
+
+ TPF_FILE_RASTERIZER = 14,
+ TPF_FILE_OUTPUT_COVERAGE_MASK = 15,
+
+ // Added in D3D11
+
+ TPF_FILE_STREAM = 16,
+ TPF_FILE_FUNCTION_BODY = 17,
+ TPF_FILE_FUNCTION_TABLE = 18,
+ TPF_FILE_INTERFACE = 19,
+ TPF_FILE_FUNCTION_INPUT = 20,
+ TPF_FILE_FUNCTION_OUTPUT = 21,
+ TPF_FILE_OUTPUT_CONTROL_POINT_ID = 22,
+ TPF_FILE_INPUT_FORK_INSTANCE_ID = 23,
+ TPF_FILE_INPUT_JOIN_INSTANCE_ID = 24,
+ TPF_FILE_INPUT_CONTROL_POINT = 25,
+ TPF_FILE_OUTPUT_CONTROL_POINT = 26,
+ TPF_FILE_INPUT_PATCH_CONSTANT = 27,
+ TPF_FILE_INPUT_DOMAIN_POINT = 28,
+ TPF_FILE_THIS_POINTER = 29,
+ TPF_FILE_UNORDERED_ACCESS_VIEW = 30,
+ TPF_FILE_THREAD_GROUP_SHARED_MEMORY = 31,
+ TPF_FILE_INPUT_THREAD_ID = 32,
+ TPF_FILE_INPUT_THREAD_GROUP_ID = 33,
+ TPF_FILE_INPUT_THREAD_ID_IN_GROUP = 34,
+ TPF_FILE_INPUT_COVERAGE_MASK = 35,
+ TPF_FILE_INPUT_THREAD_ID_IN_GROUP_FLATTENED = 36,
+ TPF_FILE_INPUT_GS_INSTANCE_ID = 37,
+ TPF_FILE_OUTPUT_DEPTH_GREATER_EQUAL = 38,
+ TPF_FILE_OUTPUT_DEPTH_LESS_EQUAL = 39,
+ TPF_FILE_CYCLE_COUNTER = 40,
+
+ TPF_FILE_COUNT = 41,
+};
+
+extern const char* tpf_file_names[];
+extern const char* tpf_file_ms_names[];
+
+enum tpf_target
+{
+ TPF_TARGET_UNKNOWN = 0,
+ TPF_TARGET_BUFFER = 1,
+ TPF_TARGET_TEXTURE1D = 2,
+ TPF_TARGET_TEXTURE2D = 3,
+ TPF_TARGET_TEXTURE2DMS = 4,
+ TPF_TARGET_TEXTURE3D = 5,
+ TPF_TARGET_TEXTURECUBE = 6,
+ TPF_TARGET_TEXTURE1DARRAY = 7,
+ TPF_TARGET_TEXTURE2DARRAY = 8,
+ TPF_TARGET_TEXTURE2DMSARRAY = 9,
+ TPF_TARGET_TEXTURECUBEARRAY = 10,
+
+ // Added in D3D11
+ TPF_TARGET_RAW_BUFFER = 11,
+ TPF_TARGET_STRUCTURED_BUFFER = 12,
+};
+
+extern const char* tpf_target_names[];
+
+enum tpf_interpolation
+{
+ TPF_INTERPOLATION_UNDEFINED = 0,
+ TPF_INTERPOLATION_CONSTANT = 1,
+ TPF_INTERPOLATION_LINEAR = 2,
+ TPF_INTERPOLATION_LINEAR_CENTROID = 3,
+ TPF_INTERPOLATION_LINEAR_NOPERSPECTIVE = 4,
+ TPF_INTERPOLATION_LINEAR_NOPERSPECTIVE_CENTROID = 5,
+
+ // Added in D3D10.1
+ TPF_INTERPOLATION_LINEAR_SAMPLE = 6,
+ TPF_INTERPOLATION_LINEAR_NOPERSPECTIVE_SAMPLE = 7,
+};
+
+extern const char* tpf_interpolation_names[];
+
+enum tpf_sv
+{
+ TPF_SV_UNDEFINED,
+ TPF_SV_POSITION,
+ TPF_SV_CLIP_DISTANCE,
+ TPF_SV_CULL_DISTANCE,
+ TPF_SV_RENDER_TARGET_ARRAY_INDEX,
+ TPF_SV_VIEWPORT_ARRAY_INDEX,
+ TPF_SV_VERTEX_ID,
+ TPF_SV_PRIMITIVE_ID,
+ TPF_SV_INSTANCE_ID,
+ TPF_SV_IS_FRONT_FACE,
+ TPF_SV_SAMPLE_INDEX,
+
+ // Added in D3D11
+ TPF_SV_FINAL_QUAD_U_EQ_0_EDGE_TESSFACTOR,
+ TPF_SV_FINAL_QUAD_V_EQ_0_EDGE_TESSFACTOR,
+ TPF_SV_FINAL_QUAD_U_EQ_1_EDGE_TESSFACTOR,
+ TPF_SV_FINAL_QUAD_V_EQ_1_EDGE_TESSFACTOR,
+ TPF_SV_FINAL_QUAD_U_INSIDE_TESSFACTOR,
+ TPF_SV_FINAL_QUAD_V_INSIDE_TESSFACTOR,
+ TPF_SV_FINAL_TRI_U_EQ_0_EDGE_TESSFACTOR,
+ TPF_SV_FINAL_TRI_V_EQ_0_EDGE_TESSFACTOR,
+ TPF_SV_FINAL_TRI_W_EQ_0_EDGE_TESSFACTOR,
+ TPF_SV_FINAL_TRI_INSIDE_TESSFACTOR,
+ TPF_SV_FINAL_LINE_DETAIL_TESSFACTOR,
+ TPF_SV_FINAL_LINE_DENSITY_TESSFACTOR,
+};
+
+extern const char* tpf_sv_names[];
+
+struct tpf_token_version
+{
+ unsigned minor : 4;
+ unsigned major : 4;
+ unsigned format : 8;
+ unsigned type : 16;
+};
+
+struct tpf_token_instruction
+{
+ // we don't make it an union directly because unions can't be inherited from
+ union
+ {
+ // length and extended are always present, but they are only here to reduce duplication
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned _11_23 : 13;
+ unsigned length : 7;
+ unsigned extended : 1;
+ };
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned resinfo_return_type : 2;
+ unsigned sat : 1;
+ unsigned _14_17 : 4;
+ unsigned test_nz : 1; // bit 18
+ unsigned precise_mask : 4;
+ unsigned _23 : 1;
+ unsigned length : 7;
+ unsigned extended : 1;
+ } insn;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned threads_in_group : 1;
+ unsigned shared_memory : 1;
+ unsigned uav_group : 1;
+ unsigned uav_global : 1;
+ unsigned _15_17 : 3;
+ } sync;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned allow_refactoring : 1;
+ unsigned fp64 : 1;
+ unsigned early_depth_stencil : 1;
+ unsigned enable_raw_and_structured_in_non_cs : 1;
+ } dcl_global_flags;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned target : 5;
+ unsigned nr_samples : 7;
+ } dcl_resource;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned shadow : 1;
+ unsigned mono : 1;
+ } dcl_sampler;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned interpolation : 5;
+ } dcl_input_ps;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned dynamic : 1;
+ } dcl_constant_buffer;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned primitive : 6;
+ } dcl_gs_input_primitive;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned primitive_topology : 7;
+ } dcl_gs_output_primitive_topology;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned control_points : 6;
+ } dcl_input_control_point_count;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned control_points : 6;
+ } dcl_output_control_point_count;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned domain : 3; /* D3D_TESSELLATOR_DOMAIN */
+ } dcl_tess_domain;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned partitioning : 3; /* D3D_TESSELLATOR_PARTITIONING */
+ } dcl_tess_partitioning;
+ struct
+ {
+ unsigned opcode : 11;
+ unsigned primitive : 3; /* D3D_TESSELLATOR_OUTPUT_PRIMITIVE */
+ } dcl_tess_output_primitive;
+ };
+};
+
+enum tpf_token_instruction_extended_type
+{
+ TPF_TOKEN_INSTRUCTION_EXTENDED_TYPE_EMPTY = 0,
+ TPF_TOKEN_INSTRUCTION_EXTENDED_TYPE_SAMPLE_CONTROLS = 1,
+ TPF_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_DIM = 2,
+ TPF_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_RETURN_TYPE = 3,
+};
+
+union tpf_token_instruction_extended
+{
+ struct
+ {
+ unsigned type : 6;
+ unsigned _6_30 : 25;
+ unsigned extended :1;
+ };
+ struct
+ {
+ unsigned type : 6;
+ unsigned _6_8 : 3;
+ int offset_u : 4;
+ int offset_v : 4;
+ int offset_w : 4;
+ } sample_controls;
+ struct
+ {
+ unsigned type : 6;
+ unsigned target : 5;
+ } resource_target;
+ struct
+ {
+ unsigned type : 6;
+ unsigned x : 4;
+ unsigned y : 4;
+ unsigned z : 4;
+ unsigned w : 4;
+ } resource_return_type;
+};
+
+struct tpf_token_resource_return_type
+{
+ unsigned x : 4;
+ unsigned y : 4;
+ unsigned z : 4;
+ unsigned w : 4;
+};
+
+enum tpf_operand_comps
+{
+ TPF_OPERAND_COMPS_0 = 0,
+ TPF_OPERAND_COMPS_1 = 1,
+ TPF_OPERAND_COMPS_4 = 2,
+ TPF_OPERAND_COMPS_N = 3
+};
+
+enum tpf_operand_mode
+{
+ TPF_OPERAND_MODE_MASK = 0,
+ TPF_OPERAND_MODE_SWIZZLE = 1,
+ TPF_OPERAND_MODE_SCALAR = 2
+};
+
+enum tpf_operand_index_repr
+{
+ TPF_OPERAND_INDEX_REPR_IMM32 = 0,
+ TPF_OPERAND_INDEX_REPR_IMM64 = 1,
+ TPF_OPERAND_INDEX_REPR_REG = 2,
+ TPF_OPERAND_INDEX_REPR_REG_IMM32 = 3,
+ TPF_OPERAND_INDEX_REPR_REG_IMM64 = 4,
+};
+
+struct tpf_token_operand
+{
+ unsigned comps_enum : 2; /* tpf_operands_comps */
+ unsigned mode : 2; /* tpf_operand_mode */
+ unsigned sel : 8;
+ unsigned file : 8; /* tpf_file */
+ unsigned num_indices : 2;
+ unsigned index0_repr : 3; /* tpf_operand_index_repr */
+ unsigned index1_repr : 3; /* tpf_operand_index_repr */
+ unsigned index2_repr : 3; /* tpf_operand_index_repr */
+ unsigned extended : 1;
+};
+
+#define TPF_OPERAND_SEL_MASK(sel) ((sel) & 0xf)
+#define TPF_OPERAND_SEL_SWZ(sel, i) (((sel) >> ((i) * 2)) & 3)
+#define TPF_OPERAND_SEL_SCALAR(sel) ((sel) & 3)
+
+enum tpf_token_operand_extended_type
+{
+ TPF_TOKEN_OPERAND_EXTENDED_TYPE_EMPTY = 0,
+ TPF_TOKEN_OPERAND_EXTENDED_TYPE_MODIFIER = 1,
+};
+
+struct tpf_token_operand_extended
+{
+ unsigned type : 6;
+ unsigned neg : 1;
+ unsigned abs : 1;
+};
+
+union tpf_any
+{
+ double f64;
+ float f32;
+ int64_t i64;
+ int32_t i32;
+ uint64_t u64;
+ int64_t u32;
+};
+
+struct tpf_op;
+struct tpf_insn;
+struct tpf_dcl;
+struct tpf_program;
+std::ostream& operator <<(std::ostream& out, const tpf_op& op);
+std::ostream& operator <<(std::ostream& out, const tpf_insn& op);
+std::ostream& operator <<(std::ostream& out, const tpf_dcl& op);
+std::ostream& operator <<(std::ostream& out, const tpf_program& op);
+
+struct tpf_op
+{
+ uint8_t mode;
+ uint8_t comps;
+ uint8_t mask;
+ uint8_t num_indices;
+ uint8_t swizzle[4];
+ tpf_file file;
+ tpf_any imm_values[4];
+ bool neg;
+ bool abs;
+ struct
+ {
+ int64_t disp;
+ std::auto_ptr<tpf_op> reg;
+ } indices[3];
+
+ bool is_index_simple(unsigned i) const
+ {
+ return !indices[i].reg.get() && indices[i].disp >= 0 && (int64_t)(int32_t)indices[i].disp == indices[i].disp;
+ }
+
+ bool has_simple_index() const
+ {
+ return num_indices == 1 && is_index_simple(0);
+ }
+
+ tpf_op()
+ {
+ memset(this, 0, sizeof(*this));
+ }
+
+ void dump();
+
+private:
+ tpf_op(const tpf_op& op)
+ {}
+};
+
+/* for sample_d */
+#define TPF_MAX_OPS 6
+
+struct tpf_insn : public tpf_token_instruction
+{
+ int8_t sample_offset[3];
+ uint8_t resource_target;
+ uint8_t resource_return_type[4];
+
+ unsigned num;
+ unsigned num_ops;
+ std::auto_ptr<tpf_op> ops[TPF_MAX_OPS];
+
+ tpf_insn()
+ {
+ memset(this, 0, sizeof(*this));
+ }
+
+ void dump();
+
+private:
+ tpf_insn(const tpf_insn& op)
+ {}
+};
+
+struct tpf_dcl : public tpf_token_instruction
+{
+ std::auto_ptr<tpf_op> op;
+ union
+ {
+ unsigned num;
+ float f32;
+ tpf_sv sv;
+ struct
+ {
+ unsigned id;
+ unsigned expected_function_table_length;
+ unsigned table_length;
+ unsigned array_length;
+ } intf;
+ unsigned thread_group_size[3];
+ tpf_token_resource_return_type rrt;
+ struct
+ {
+ unsigned num;
+ unsigned comps;
+ } indexable_temp;
+ struct
+ {
+ unsigned stride;
+ unsigned count;
+ } structured;
+ };
+
+ void* data;
+
+ tpf_dcl()
+ {
+ memset(this, 0, sizeof(*this));
+ }
+
+ ~tpf_dcl()
+ {
+ free(data);
+ }
+
+ void dump();
+
+private:
+ tpf_dcl(const tpf_dcl& op)
+ {}
+};
+
+struct tpf_program
+{
+ tpf_token_version version;
+ std::vector<tpf_dcl*> dcls;
+ std::vector<tpf_insn*> insns;
+
+ /* for ifs, the insn number of the else or endif if there is no else
+ * for elses, the insn number of the endif
+ * for endifs, the insn number of the if
+ * for loops, the insn number of the endloop
+ * for endloops, the insn number of the loop
+ * for all others, -1
+ */
+ std::vector<int> cf_insn_linked;
+
+ /* NOTE: sampler 0 is the unnormalized nearest sampler for LD/LD_MS, while
+ * sampler 1 is user-specified sampler 0
+ */
+ bool resource_sampler_slots_assigned;
+ std::vector<int> slot_to_resource;
+ std::vector<int> slot_to_sampler;
+ std::map<std::pair<int, int>, int> resource_sampler_to_slot;
+ std::map<int, int> resource_to_slot;
+
+ bool labels_found;
+ std::vector<int> label_to_insn_num;
+
+ tpf_program()
+ {
+ memset(&version, 0, sizeof(version));
+ labels_found = false;
+ resource_sampler_slots_assigned = false;
+ }
+
+ ~tpf_program()
+ {
+ for(std::vector<tpf_dcl*>::iterator i = dcls.begin(), e = dcls.end(); i != e; ++i)
+ delete *i;
+ for(std::vector<tpf_insn*>::iterator i = insns.begin(), e = insns.end(); i != e; ++i)
+ delete *i;
+ }
+
+ void dump();
+
+private:
+ tpf_program(const tpf_dcl& op)
+ {}
+};
+
+tpf_program* tpf_parse(void* tokens, int size);
+
+bool tpf_link_cf_insns(tpf_program& program);
+bool tpf_find_labels(tpf_program& program);
+bool tpf_allocate_resource_sampler_pairs(tpf_program& program);
+
+#endif /* TPF_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_dump.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_dump.cpp
new file mode 100644
index 0000000..a3feec7
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_dump.cpp
@@ -0,0 +1,43 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include <memory>
+#include <string.h>
+#include <iomanip>
+#include "dxbc.h"
+
+std::ostream& operator <<(std::ostream& out, const dxbc_container& container)
+{
+ for(unsigned i = 0; i < container.chunks.size(); ++i)
+ {
+ struct dxbc_chunk_header* chunk = container.chunks[i];
+ char fourcc_str[5];
+ memcpy(fourcc_str, &chunk->fourcc, 4);
+ fourcc_str[4] = 0;
+ out << "# DXBC chunk " << std::setw(2) << i << ": " << fourcc_str << " offset " << ((char*)chunk - (char*)container.data) << " size " << bswap_le32(chunk->size) << "\n";
+ }
+ return out;
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp
new file mode 100644
index 0000000..6b696ae
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/dxbc_parse.cpp
@@ -0,0 +1,93 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include <memory>
+#include "dxbc.h"
+#include <d3d11shader.h>
+#include <d3dcommon.h>
+
+struct dxbc_container_header
+{
+ unsigned fourcc;
+ uint32_t unk[5];
+ uint32_t total_size;
+ uint32_t chunk_count;
+ uint32_t chunk_offsets[];
+};
+
+dxbc_container* dxbc_parse(const void* data, int size)
+{
+ std::auto_ptr<dxbc_container> container(new dxbc_container());
+ container->data = data;
+ dxbc_container_header* header = (dxbc_container_header*)data;
+ if(bswap_le32(header->fourcc) != FOURCC_DXBC)
+ return 0;
+ unsigned num_chunks = bswap_le32(header->chunk_count);
+ for(unsigned i = 0; i < num_chunks; ++i)
+ {
+ unsigned offset = bswap_le32(header->chunk_offsets[i]);
+ dxbc_chunk_header* chunk = (dxbc_chunk_header*)((char*)data + offset);
+ unsigned fourcc = bswap_le32(chunk->fourcc);
+ container->chunk_map[fourcc] = i;
+ container->chunks.push_back(chunk);
+ }
+ return container.release();
+}
+
+dxbc_chunk_header* dxbc_find_chunk(const void* data, int size, unsigned fourcc)
+{
+ dxbc_container_header* header = (dxbc_container_header*)data;
+ if(bswap_le32(header->fourcc) != FOURCC_DXBC)
+ return 0;
+ unsigned num_chunks = bswap_le32(header->chunk_count);
+ for(unsigned i = 0; i < num_chunks; ++i)
+ {
+ unsigned offset = bswap_le32(header->chunk_offsets[i]);
+ dxbc_chunk_header* chunk = (dxbc_chunk_header*)((char*)data + offset);
+ if(bswap_le32(chunk->fourcc) == fourcc)
+ return chunk;
+ }
+ return 0;
+}
+
+int dxbc_parse_signature(dxbc_chunk_signature* sig, D3D11_SIGNATURE_PARAMETER_DESC** params)
+{
+ unsigned count = bswap_le32(sig->count);
+ *params = (D3D11_SIGNATURE_PARAMETER_DESC*)malloc(sizeof(D3D11_SIGNATURE_PARAMETER_DESC) * count);
+
+ for (unsigned i = 0; i < count; ++i)
+ {
+ D3D11_SIGNATURE_PARAMETER_DESC& param = (*params)[i];
+ param.SemanticName = (char*)&sig->count + bswap_le32(sig->elements[i].name_offset);
+ param.SemanticIndex = bswap_le32(sig->elements[i].semantic_index);
+ param.SystemValueType = (D3D_NAME)bswap_le32(sig->elements[i].system_value_type);
+ param.ComponentType = (D3D_REGISTER_COMPONENT_TYPE)bswap_le32(sig->elements[i].component_type);
+ param.Mask = sig->elements[i].mask;
+ param.ReadWriteMask = sig->elements[i].read_write_mask;
+ param.Stream = sig->elements[i].stream;
+ }
+ return count;
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_analyze.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_analyze.cpp
new file mode 100644
index 0000000..a100ee5
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_analyze.cpp
@@ -0,0 +1,186 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include <vector>
+#include <set>
+#include "tpf.h"
+
+#define check(x) do {if(!(x)) return false;} while(0)
+
+bool tpf_link_cf_insns(tpf_program& program)
+{
+ if(program.cf_insn_linked.size())
+ return true;
+
+ program.cf_insn_linked.resize(program.insns.size());
+ std::vector<int> cf_insn_linked;
+ memset(&cf_insn_linked[0], 0xff, cf_insn_linked.size() * sizeof(int));
+ std::vector<unsigned> cf_stack;
+ for(unsigned insn_num = 0; insn_num < program.insns.size(); ++insn_num)
+ {
+ unsigned v;
+ switch(program.insns[insn_num]->opcode)
+ {
+ case TPF_OPCODE_LOOP:
+ cf_stack.push_back(insn_num);
+ break;
+ case TPF_OPCODE_ENDLOOP:
+ check(!cf_stack.empty());
+ v = cf_stack.back();
+ check(program.insns[v]->opcode == TPF_OPCODE_LOOP);
+ cf_insn_linked[v] = insn_num;
+ cf_insn_linked[insn_num] = v;
+ cf_stack.pop_back();
+ break;
+ case TPF_OPCODE_IF:
+ case TPF_OPCODE_SWITCH:
+ cf_insn_linked[insn_num] = insn_num; // later changed
+ cf_stack.push_back(insn_num);
+ break;
+ case TPF_OPCODE_ELSE:
+ case TPF_OPCODE_CASE:
+ check(!cf_stack.empty());
+ v = cf_stack.back();
+ if(program.insns[insn_num]->opcode == TPF_OPCODE_ELSE)
+ check(program.insns[v]->opcode == TPF_OPCODE_IF);
+ else
+ check(program.insns[v]->opcode == TPF_OPCODE_SWITCH || program.insns[v]->opcode == TPF_OPCODE_CASE);
+ cf_insn_linked[insn_num] = cf_insn_linked[v]; // later changed
+ cf_insn_linked[v] = insn_num;
+ cf_stack.back() = insn_num;
+ break;
+ case TPF_OPCODE_ENDSWITCH:
+ case TPF_OPCODE_ENDIF:
+ check(!cf_stack.empty());
+ v = cf_stack.back();
+ if(program.insns[insn_num]->opcode == TPF_OPCODE_ENDIF)
+ check(program.insns[v]->opcode == TPF_OPCODE_IF || program.insns[v]->opcode == TPF_OPCODE_ELSE);
+ else
+ check(program.insns[v]->opcode == TPF_OPCODE_SWITCH || program.insns[v]->opcode == TPF_OPCODE_CASE);
+ cf_insn_linked[insn_num] = cf_insn_linked[v];
+ cf_insn_linked[v] = insn_num;
+ cf_stack.pop_back();
+ break;
+ }
+ }
+ check(cf_stack.empty());
+ program.cf_insn_linked.swap(cf_insn_linked);
+ return true;
+}
+
+bool tpf_find_labels(tpf_program& program)
+{
+ if(program.labels_found)
+ return true;
+
+ std::vector<int> labels;
+ for(unsigned insn_num = 0; insn_num < program.insns.size(); ++insn_num)
+ {
+ switch(program.insns[insn_num]->opcode)
+ {
+ case TPF_OPCODE_LABEL:
+ if(program.insns[insn_num]->num_ops > 0)
+ {
+ tpf_op& op = *program.insns[insn_num]->ops[0];
+ if(op.file == TPF_FILE_LABEL && op.has_simple_index())
+ {
+ unsigned idx = (unsigned)op.indices[0].disp;
+ if(idx >= labels.size())
+ labels.resize(idx + 1);
+ labels[idx] = insn_num;
+ }
+ }
+ break;
+ }
+ }
+ program.label_to_insn_num.swap(labels);
+ program.labels_found = true;
+ return true;
+}
+
+bool tpf_allocate_resource_sampler_pairs(tpf_program& program)
+{
+ if(program.resource_sampler_slots_assigned)
+ return true;
+
+ std::set<std::pair<int, int> > pairs;
+ std::set<int> resinfos;
+
+ for(unsigned insn_num = 0; insn_num < program.insns.size(); ++insn_num)
+ {
+ int resource = -1;
+ int sampler = -2;
+ for(unsigned i = 0; i < program.insns[insn_num]->num_ops; ++i)
+ {
+ tpf_op* op = program.insns[insn_num]->ops[i].get();
+ if(op)
+ {
+ if(op->file == TPF_FILE_RESOURCE)
+ {
+ if(!op->has_simple_index() || resource >= 0)
+ return false;
+ resource = (int)op->indices[0].disp;
+ }
+ if(op->file == TPF_FILE_SAMPLER)
+ {
+ if(!op->has_simple_index() || sampler >= 0)
+ return false;
+ sampler = (int)op->indices[0].disp;
+ }
+ }
+ }
+
+ unsigned opcode = program.insns[insn_num]->opcode;
+ if(opcode == TPF_OPCODE_LD || opcode == TPF_OPCODE_LD_MS)
+ sampler = -1;
+ if(sampler >= -1 && resource >= 0)
+ pairs.insert(std::make_pair(resource, sampler));
+ if(opcode == TPF_OPCODE_RESINFO)
+ resinfos.insert(resource);
+ }
+
+ for(std::set<std::pair<int, int> >::iterator i = pairs.begin(); i != pairs.end(); ++i)
+ {
+ program.resource_sampler_to_slot[*i] = program.slot_to_resource.size();
+ if(!program.resource_to_slot.count(i->first))
+ {
+ program.resource_to_slot[i->first] = program.slot_to_resource.size();
+ resinfos.erase(i->first);
+ }
+ program.slot_to_resource.push_back(i->first);
+ program.slot_to_sampler.push_back(i->second);
+ }
+
+ for(std::set<int>::iterator i = resinfos.begin(); i != resinfos.end(); ++i)
+ {
+ program.resource_sampler_to_slot[std::make_pair(*i, -1)] = program.slot_to_resource.size();
+ program.resource_to_slot[*i] = program.slot_to_resource.size();
+ program.slot_to_resource.push_back(*i);
+ program.slot_to_sampler.push_back(-1);
+ }
+ program.resource_sampler_slots_assigned = true;
+ return true;
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_dump.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_dump.cpp
new file mode 100644
index 0000000..2e6e094
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_dump.cpp
@@ -0,0 +1,222 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "tpf.h"
+
+// TODO: we should fix this to output the same syntax as fxc, if tpf_dump_ms_syntax is set
+
+bool tpf_dump_ms_syntax = true;
+
+std::ostream& operator <<(std::ostream& out, const tpf_op& op)
+{
+ if(op.neg)
+ out << '-';
+ if(op.abs)
+ out << '|';
+ if(op.file == TPF_FILE_IMMEDIATE32)
+ {
+ out << "l(";
+ for(unsigned i = 0; i < op.comps; ++i)
+ {
+ if(i)
+ out << ", ";
+ out << op.imm_values[i].f32;
+ }
+ out << ")";
+ }
+ else if(op.file == TPF_FILE_IMMEDIATE64)
+ {
+ out << "d(";
+ for(unsigned i = 0; i < op.comps; ++i)
+ {
+ if(i)
+ out << ", ";
+ out << op.imm_values[i].f64;
+ }
+ out << ")";
+ return out;
+ }
+ else
+ {
+ bool naked = false;
+ if(tpf_dump_ms_syntax)
+ {
+ switch(op.file)
+ {
+ case TPF_FILE_TEMP:
+ case TPF_FILE_INPUT:
+ case TPF_FILE_OUTPUT:
+ case TPF_FILE_CONSTANT_BUFFER:
+ case TPF_FILE_INDEXABLE_TEMP:
+ case TPF_FILE_UNORDERED_ACCESS_VIEW:
+ case TPF_FILE_THREAD_GROUP_SHARED_MEMORY:
+ naked = true;
+ break;
+ default:
+ naked = false;
+ break;
+ }
+ }
+
+ out << (tpf_dump_ms_syntax ? tpf_file_ms_names : tpf_file_names)[op.file];
+
+ if(op.indices[0].reg.get())
+ naked = false;
+
+ for(unsigned i = 0; i < op.num_indices; ++i)
+ {
+ if(!naked || i)
+ out << '[';
+ if(op.indices[i].reg.get())
+ {
+ out << *op.indices[i].reg;
+ if(op.indices[i].disp)
+ out << '+' << op.indices[i].disp;
+ }
+ else
+ out << op.indices[i].disp;
+ if(!naked || i)
+ out << ']';
+ }
+ if(op.comps)
+ {
+ switch(op.mode)
+ {
+ case TPF_OPERAND_MODE_MASK:
+ out << (tpf_dump_ms_syntax ? '.' : '!');
+ for(unsigned i = 0; i < op.comps; ++i)
+ {
+ if(op.mask & (1 << i))
+ out << "xyzw"[i];
+ }
+ break;
+ case TPF_OPERAND_MODE_SWIZZLE:
+ out << '.';
+ for(unsigned i = 0; i < op.comps; ++i)
+ out << "xyzw"[op.swizzle[i]];
+ break;
+ case TPF_OPERAND_MODE_SCALAR:
+ out << (tpf_dump_ms_syntax ? '.' : ':');
+ out << "xyzw"[op.swizzle[0]];
+ break;
+ }
+ }
+ }
+ if(op.abs)
+ out << '|';
+ return out;
+}
+
+std::ostream& operator <<(std::ostream& out, const tpf_dcl& dcl)
+{
+ out << tpf_opcode_names[dcl.opcode];
+ switch(dcl.opcode)
+ {
+ case TPF_OPCODE_DCL_GLOBAL_FLAGS:
+ if(dcl.dcl_global_flags.allow_refactoring)
+ out << " refactoringAllowed";
+ if(dcl.dcl_global_flags.early_depth_stencil)
+ out << " forceEarlyDepthStencil";
+ if(dcl.dcl_global_flags.fp64)
+ out << " enableDoublePrecisionFloatOps";
+ if(dcl.dcl_global_flags.enable_raw_and_structured_in_non_cs)
+ out << " enableRawAndStructuredBuffers";
+ break;
+ case TPF_OPCODE_DCL_INPUT_PS:
+ case TPF_OPCODE_DCL_INPUT_PS_SIV:
+ case TPF_OPCODE_DCL_INPUT_PS_SGV:
+ out << ' ' << tpf_interpolation_names[dcl.dcl_input_ps.interpolation];
+ break;
+ case TPF_OPCODE_DCL_TEMPS:
+ out << ' ' << dcl.num;
+ break;
+ default:
+ break;
+ }
+ if(dcl.op.get())
+ out << ' ' << *dcl.op;
+ switch(dcl.opcode)
+ {
+ case TPF_OPCODE_DCL_CONSTANT_BUFFER:
+ out << ", " << (dcl.dcl_constant_buffer.dynamic ? "dynamicIndexed" : "immediateIndexed");
+ break;
+ case TPF_OPCODE_DCL_INPUT_SIV:
+ case TPF_OPCODE_DCL_INPUT_SGV:
+ case TPF_OPCODE_DCL_OUTPUT_SIV:
+ case TPF_OPCODE_DCL_OUTPUT_SGV:
+ case TPF_OPCODE_DCL_INPUT_PS_SIV:
+ case TPF_OPCODE_DCL_INPUT_PS_SGV:
+ out << ", " << tpf_sv_names[dcl.num];
+ break;
+ }
+
+ return out;
+}
+
+std::ostream& operator <<(std::ostream& out, const tpf_insn& insn)
+{
+ out << tpf_opcode_names[insn.opcode];
+ if(insn.insn.sat)
+ out << "_sat";
+ for(unsigned i = 0; i < insn.num_ops; ++i)
+ {
+ if(i)
+ out << ',';
+ out << ' ' << *insn.ops[i];
+ }
+ return out;
+}
+
+std::ostream& operator <<(std::ostream& out, const tpf_program& program)
+{
+ out << "pvghdc"[program.version.type] << "s_" << program.version.major << "_" << program.version.minor << "\n";
+ for(unsigned i = 0; i < program.dcls.size(); ++i)
+ out << *program.dcls[i] << "\n";
+
+ for(unsigned i = 0; i < program.insns.size(); ++i)
+ out << *program.insns[i] << "\n";
+ return out;
+}
+
+void tpf_op::dump()
+{
+ std::cout << *this;
+}
+
+void tpf_insn::dump()
+{
+ std::cout << *this;
+}
+
+void tpf_dcl::dump()
+{
+ std::cout << *this;
+}
+
+void tpf_program::dump()
+{
+ std::cout << *this;
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_parse.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_parse.cpp
new file mode 100644
index 0000000..a4f6cc6
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_parse.cpp
@@ -0,0 +1,424 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "tpf.h"
+#include "utils.h"
+
+#if 1
+#define check(x) assert(x)
+#define fail(x) assert(0 && (x))
+#else
+#define check(x) do {if(!(x)) throw(#x);} while(0)
+#define fail(x) throw(x)
+#endif
+
+struct tpf_parser
+{
+ unsigned* tokens;
+ unsigned* tokens_end;
+ tpf_program& program;
+
+ tpf_parser(tpf_program& program, void* p_tokens, unsigned size)
+ : program(program)
+ {
+ tokens = (unsigned*)p_tokens;
+ tokens_end = (unsigned*)((char*)p_tokens + size);
+ }
+
+ /* TODO: byteswap if machine is big endian */
+ uint32_t read32()
+ {
+ check(tokens < tokens_end);
+ return bswap_le32(*tokens++);
+ }
+
+ template<typename T>
+ void read_token(T* tok)
+ {
+ *(unsigned*)tok = read32();
+ }
+
+ uint64_t read64()
+ {
+ unsigned a = read32();
+ unsigned b = read32();
+ return (uint64_t)a | ((uint64_t)b << 32);
+ }
+
+ void skip(unsigned toskip)
+ {
+ tokens += toskip;
+ }
+
+ void read_op(tpf_op* pop)
+ {
+ tpf_op& op = *pop;
+ tpf_token_operand optok;
+ read_token(&optok);
+ assert(optok.file < TPF_FILE_COUNT);
+ op.swizzle[0] = 0;
+ op.swizzle[1] = 1;
+ op.swizzle[2] = 2;
+ op.swizzle[3] = 3;
+ op.mask = 0xf;
+ switch(optok.comps_enum)
+ {
+ case TPF_OPERAND_COMPS_0:
+ op.comps = 0;
+ break;
+ case TPF_OPERAND_COMPS_1:
+ op.comps = 1;
+ break;
+ case TPF_OPERAND_COMPS_4:
+ op.comps = 4;
+ op.mode = optok.mode;
+ switch(optok.mode)
+ {
+ case TPF_OPERAND_MODE_MASK:
+ op.mask = TPF_OPERAND_SEL_MASK(optok.sel);
+ break;
+ case TPF_OPERAND_MODE_SWIZZLE:
+ op.swizzle[0] = TPF_OPERAND_SEL_SWZ(optok.sel, 0);
+ op.swizzle[1] = TPF_OPERAND_SEL_SWZ(optok.sel, 1);
+ op.swizzle[2] = TPF_OPERAND_SEL_SWZ(optok.sel, 2);
+ op.swizzle[3] = TPF_OPERAND_SEL_SWZ(optok.sel, 3);
+ break;
+ case TPF_OPERAND_MODE_SCALAR:
+ op.swizzle[0] = op.swizzle[1] = op.swizzle[2] = op.swizzle[3] = TPF_OPERAND_SEL_SCALAR(optok.sel);
+ break;
+ }
+ break;
+ case TPF_OPERAND_COMPS_N:
+ fail("Unhandled operand component type");
+ }
+ op.file = (tpf_file)optok.file;
+ op.num_indices = optok.num_indices;
+
+ if(optok.extended)
+ {
+ tpf_token_operand_extended optokext;
+ read_token(&optokext);
+ if(optokext.type == 0)
+ {}
+ else if(optokext.type == 1)
+ {
+ op.neg = optokext.neg;
+ op.abs= optokext.abs;
+ }
+ else
+ fail("Unhandled extended operand token type");
+ }
+
+ for(unsigned i = 0; i < op.num_indices; ++i)
+ {
+ unsigned repr;
+ if(i == 0)
+ repr = optok.index0_repr;
+ else if(i == 1)
+ repr = optok.index1_repr;
+ else if(i == 2)
+ repr = optok.index2_repr;
+ else
+ fail("Unhandled operand index representation");
+ op.indices[0].disp = 0;
+ // TODO: is disp supposed to be signed here??
+ switch(repr)
+ {
+ case TPF_OPERAND_INDEX_REPR_IMM32:
+ op.indices[i].disp = (int32_t)read32();
+ break;
+ case TPF_OPERAND_INDEX_REPR_IMM64:
+ op.indices[i].disp = read64();
+ break;
+ case TPF_OPERAND_INDEX_REPR_REG:
+relative:
+ op.indices[i].reg.reset(new tpf_op());
+ read_op(&*op.indices[0].reg);
+ break;
+ case TPF_OPERAND_INDEX_REPR_REG_IMM32:
+ op.indices[i].disp = (int32_t)read32();
+ goto relative;
+ case TPF_OPERAND_INDEX_REPR_REG_IMM64:
+ op.indices[i].disp = read64();
+ goto relative;
+ }
+ }
+
+ if(op.file == TPF_FILE_IMMEDIATE32)
+ {
+ for(unsigned i = 0; i < op.comps; ++i)
+ op.imm_values[i].i32 = read32();
+ }
+ else if(op.file == TPF_FILE_IMMEDIATE64)
+ {
+ for(unsigned i = 0; i < op.comps; ++i)
+ op.imm_values[i].i64 = read64();
+ }
+ }
+
+ void do_parse()
+ {
+ read_token(&program.version);
+
+ unsigned lentok = read32();
+ tokens_end = tokens - 2 + lentok;
+
+ while(tokens != tokens_end)
+ {
+ tpf_token_instruction insntok;
+ read_token(&insntok);
+ unsigned* insn_end = tokens - 1 + insntok.length;
+ tpf_opcode opcode = (tpf_opcode)insntok.opcode;
+ check(opcode < TPF_OPCODE_D3D11_COUNT);
+
+ if(opcode == TPF_OPCODE_CUSTOMDATA)
+ {
+ unsigned customlen = read32() - 2;
+ skip(customlen);
+ continue;
+ }
+
+ if((opcode >= TPF_OPCODE_DCL_RESOURCE && opcode <= TPF_OPCODE_DCL_GLOBAL_FLAGS)
+ || (opcode >= TPF_OPCODE_DCL_STREAM && opcode <= TPF_OPCODE_DCL_RESOURCE_STRUCTURED))
+ {
+ tpf_dcl& dcl = *new tpf_dcl;
+ program.dcls.push_back(&dcl);
+ (tpf_token_instruction&)dcl = insntok;
+
+ tpf_token_instruction_extended exttok;
+ memcpy(&exttok, &insntok, sizeof(exttok));
+ while(exttok.extended)
+ {
+ read_token(&exttok);
+ }
+
+#define READ_OP_ANY dcl.op.reset(new tpf_op()); read_op(&*dcl.op);
+#define READ_OP(FILE) READ_OP_ANY
+ //check(dcl.op->file == TPF_FILE_##FILE);
+
+ switch(opcode)
+ {
+ case TPF_OPCODE_DCL_GLOBAL_FLAGS:
+ break;
+ case TPF_OPCODE_DCL_RESOURCE:
+ READ_OP(RESOURCE);
+ read_token(&dcl.rrt);
+ break;
+ case TPF_OPCODE_DCL_SAMPLER:
+ READ_OP(SAMPLER);
+ break;
+ case TPF_OPCODE_DCL_INPUT:
+ case TPF_OPCODE_DCL_INPUT_PS:
+ READ_OP(INPUT);
+ break;
+ case TPF_OPCODE_DCL_INPUT_SIV:
+ case TPF_OPCODE_DCL_INPUT_SGV:
+ case TPF_OPCODE_DCL_INPUT_PS_SIV:
+ case TPF_OPCODE_DCL_INPUT_PS_SGV:
+ READ_OP(INPUT);
+ dcl.sv = (tpf_sv)(uint16_t)read32();
+ break;
+ case TPF_OPCODE_DCL_OUTPUT:
+ READ_OP(OUTPUT);
+ break;
+ case TPF_OPCODE_DCL_OUTPUT_SIV:
+ case TPF_OPCODE_DCL_OUTPUT_SGV:
+ READ_OP(OUTPUT);
+ dcl.sv = (tpf_sv)(uint16_t)read32();
+ break;
+ case TPF_OPCODE_DCL_INDEX_RANGE:
+ READ_OP_ANY;
+ check(dcl.op->file == TPF_FILE_INPUT || dcl.op->file == TPF_FILE_OUTPUT);
+ dcl.num = read32();
+ break;
+ case TPF_OPCODE_DCL_TEMPS:
+ dcl.num = read32();
+ break;
+ case TPF_OPCODE_DCL_INDEXABLE_TEMP:
+ READ_OP(INDEXABLE_TEMP);
+ dcl.indexable_temp.num = read32();
+ dcl.indexable_temp.comps = read32();
+ break;
+ case TPF_OPCODE_DCL_CONSTANT_BUFFER:
+ READ_OP(CONSTANT_BUFFER);
+ break;
+ case TPF_OPCODE_DCL_GS_INPUT_PRIMITIVE:
+ case TPF_OPCODE_DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY:
+ break;
+ case TPF_OPCODE_DCL_MAX_OUTPUT_VERTEX_COUNT:
+ dcl.num = read32();
+ break;
+ case TPF_OPCODE_DCL_GS_INSTANCE_COUNT:
+ dcl.num = read32();
+ break;
+ case TPF_OPCODE_DCL_INPUT_CONTROL_POINT_COUNT:
+ case TPF_OPCODE_DCL_OUTPUT_CONTROL_POINT_COUNT:
+ case TPF_OPCODE_DCL_TESS_DOMAIN:
+ case TPF_OPCODE_DCL_TESS_PARTITIONING:
+ case TPF_OPCODE_DCL_TESS_OUTPUT_PRIMITIVE:
+ break;
+ case TPF_OPCODE_DCL_HS_MAX_TESSFACTOR:
+ dcl.f32 = read32();
+ break;
+ case TPF_OPCODE_DCL_HS_FORK_PHASE_INSTANCE_COUNT:
+ dcl.num = read32();
+ break;
+ case TPF_OPCODE_DCL_FUNCTION_BODY:
+ dcl.num = read32();
+ break;
+ case TPF_OPCODE_DCL_FUNCTION_TABLE:
+ dcl.num = read32();
+ dcl.data = malloc(dcl.num * sizeof(uint32_t));
+ for(unsigned i = 0; i < dcl.num; ++i)
+ ((uint32_t*)dcl.data)[i] = read32();
+ break;
+ case TPF_OPCODE_DCL_INTERFACE:
+ dcl.intf.id = read32();
+ dcl.intf.expected_function_table_length = read32();
+ {
+ uint32_t v = read32();
+ dcl.intf.table_length = v & 0xffff;
+ dcl.intf.array_length = v >> 16;
+ }
+ dcl.data = malloc(dcl.intf.table_length * sizeof(uint32_t));
+ for(unsigned i = 0; i < dcl.intf.table_length; ++i)
+ ((uint32_t*)dcl.data)[i] = read32();
+ break;
+ case TPF_OPCODE_DCL_THREAD_GROUP:
+ dcl.thread_group_size[0] = read32();
+ dcl.thread_group_size[1] = read32();
+ dcl.thread_group_size[2] = read32();
+ break;
+ case TPF_OPCODE_DCL_UNORDERED_ACCESS_VIEW_TYPED:
+ READ_OP(UNORDERED_ACCESS_VIEW);
+ read_token(&dcl.rrt);
+ break;
+ case TPF_OPCODE_DCL_UNORDERED_ACCESS_VIEW_RAW:
+ READ_OP(UNORDERED_ACCESS_VIEW);
+ break;
+ case TPF_OPCODE_DCL_UNORDERED_ACCESS_VIEW_STRUCTURED:
+ READ_OP(UNORDERED_ACCESS_VIEW);
+ dcl.structured.stride = read32();
+ break;
+ case TPF_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW:
+ READ_OP(THREAD_GROUP_SHARED_MEMORY);
+ dcl.num = read32();
+ break;
+ case TPF_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
+ READ_OP(THREAD_GROUP_SHARED_MEMORY);
+ dcl.structured.stride = read32();
+ dcl.structured.count = read32();
+ break;
+ case TPF_OPCODE_DCL_RESOURCE_RAW:
+ READ_OP(RESOURCE);
+ break;
+ case TPF_OPCODE_DCL_RESOURCE_STRUCTURED:
+ READ_OP(RESOURCE);
+ dcl.structured.stride = read32();
+ break;
+ case TPF_OPCODE_DCL_STREAM:
+ /* TODO: dcl_stream is undocumented: what is it? */
+ fail("Unhandled dcl_stream since it's undocumented");
+ default:
+ fail("Unhandled declaration");
+ }
+
+ check(tokens == insn_end);
+ }
+ else
+ {
+ tpf_insn& insn = *new tpf_insn;
+ program.insns.push_back(&insn);
+ (tpf_token_instruction&)insn = insntok;
+
+ tpf_token_instruction_extended exttok;
+ memcpy(&exttok, &insntok, sizeof(exttok));
+ while(exttok.extended)
+ {
+ read_token(&exttok);
+ if(exttok.type == TPF_TOKEN_INSTRUCTION_EXTENDED_TYPE_SAMPLE_CONTROLS)
+ {
+ insn.sample_offset[0] = exttok.sample_controls.offset_u;
+ insn.sample_offset[1] = exttok.sample_controls.offset_v;
+ insn.sample_offset[2] = exttok.sample_controls.offset_w;
+ }
+ else if(exttok.type == TPF_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_DIM)
+ insn.resource_target = exttok.resource_target.target;
+ else if(exttok.type == TPF_TOKEN_INSTRUCTION_EXTENDED_TYPE_RESOURCE_RETURN_TYPE)
+ {
+ insn.resource_return_type[0] = exttok.resource_return_type.x;
+ insn.resource_return_type[1] = exttok.resource_return_type.y;
+ insn.resource_return_type[2] = exttok.resource_return_type.z;
+ insn.resource_return_type[3] = exttok.resource_return_type.w;
+ }
+ }
+
+ switch(opcode)
+ {
+ case TPF_OPCODE_INTERFACE_CALL:
+ insn.num = read32();
+ break;
+ default:
+ break;
+ }
+
+ unsigned op_num = 0;
+ while(tokens != insn_end)
+ {
+ check(tokens < insn_end);
+ check(op_num < TPF_MAX_OPS);
+ insn.ops[op_num].reset(new tpf_op);
+ read_op(&*insn.ops[op_num]);
+ ++op_num;
+ }
+ insn.num_ops = op_num;
+ }
+ }
+ }
+
+ const char* parse()
+ {
+ try
+ {
+ do_parse();
+ return 0;
+ }
+ catch(const char* error)
+ {
+ return error;
+ }
+ }
+};
+
+tpf_program* tpf_parse(void* tokens, int size)
+{
+ tpf_program* program = new tpf_program;
+ tpf_parser parser(*program, tokens, size);
+ if(!parser.parse())
+ return program;
+ delete program;
+ return 0;
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_text.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_text.cpp
new file mode 100644
index 0000000..94192c9
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/tpf_text.cpp
@@ -0,0 +1,385 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+// generated with sed -re 's/TPF_WHATEVER_//; s/=.*//; s,//.*,,; s/,//; s/\s*//g;'|tr '[A-Z]' '[a-z]'|tr -s '\n'|sed -re 's/(.*)/\t"\1",/g'
+
+const char* tpf_opcode_names[] =
+{
+ "add",
+ "and",
+ "break",
+ "breakc",
+ "call",
+ "callc",
+ "case",
+ "continue",
+ "continuec",
+ "cut",
+ "default",
+ "deriv_rtx",
+ "deriv_rty",
+ "discard",
+ "div",
+ "dp2",
+ "dp3",
+ "dp4",
+ "else",
+ "emit",
+ "emitthencut",
+ "endif",
+ "endloop",
+ "endswitch",
+ "eq",
+ "exp",
+ "frc",
+ "ftoi",
+ "ftou",
+ "ge",
+ "iadd",
+ "if",
+ "ieq",
+ "ige",
+ "ilt",
+ "imad",
+ "imax",
+ "imin",
+ "imul",
+ "ine",
+ "ineg",
+ "ishl",
+ "ishr",
+ "itof",
+ "label",
+ "ld",
+ "ld_ms",
+ "log",
+ "loop",
+ "lt",
+ "mad",
+ "min",
+ "max",
+ "customdata",
+ "mov",
+ "movc",
+ "mul",
+ "ne",
+ "nop",
+ "not",
+ "or",
+ "resinfo",
+ "ret",
+ "retc",
+ "round_ne",
+ "round_ni",
+ "round_pi",
+ "round_z",
+ "rsq",
+ "sample",
+ "sample_c",
+ "sample_c_lz",
+ "sample_l",
+ "sample_d",
+ "sample_b",
+ "sqrt",
+ "switch",
+ "sincos",
+ "udiv",
+ "ult",
+ "uge",
+ "umul",
+ "umad",
+ "umax",
+ "umin",
+ "ushr",
+ "utof",
+ "xor",
+ "dcl_resource",
+ "dcl_constant_buffer",
+ "dcl_sampler",
+ "dcl_index_range",
+ "dcl_gs_output_primitive_topology",
+ "dcl_gs_input_primitive",
+ "dcl_max_output_vertex_count",
+ "dcl_input",
+ "dcl_input_sgv",
+ "dcl_input_siv",
+ "dcl_input_ps",
+ "dcl_input_ps_sgv",
+ "dcl_input_ps_siv",
+ "dcl_output",
+ "dcl_output_sgv",
+ "dcl_output_siv",
+ "dcl_temps",
+ "dcl_indexable_temp",
+ "dcl_global_flags",
+ "d3d10_count",
+ "lod",
+ "gather4",
+ "sample_pos",
+ "sample_info",
+ "d3d10_1_count",
+ "hs_decls",
+ "hs_control_point_phase",
+ "hs_fork_phase",
+ "hs_join_phase",
+ "emit_stream",
+ "cut_stream",
+ "emitthencut_stream",
+ "interface_call",
+ "bufinfo",
+ "deriv_rtx_coarse",
+ "deriv_rtx_fine",
+ "deriv_rty_coarse",
+ "deriv_rty_fine",
+ "gather4_c",
+ "gather4_po",
+ "gather4_po_c",
+ "rcp",
+ "f32tof16",
+ "f16tof32",
+ "uaddc",
+ "usubb",
+ "countbits",
+ "firstbit_hi",
+ "firstbit_lo",
+ "firstbit_shi",
+ "ubfe",
+ "ibfe",
+ "bfi",
+ "bfrev",
+ "swapc",
+ "dcl_stream",
+ "dcl_function_body",
+ "dcl_function_table",
+ "dcl_interface",
+ "dcl_input_control_point_count",
+ "dcl_output_control_point_count",
+ "dcl_tess_domain",
+ "dcl_tess_partitioning",
+ "dcl_tess_output_primitive",
+ "dcl_hs_max_tessfactor",
+ "dcl_hs_fork_phase_instance_count",
+ "dcl_hs_join_phase_instance_count",
+ "dcl_thread_group",
+ "dcl_unordered_access_view_typed",
+ "dcl_unordered_access_view_raw",
+ "dcl_unordered_access_view_structured",
+ "dcl_thread_group_shared_memory_raw",
+ "dcl_thread_group_shared_memory_structured",
+ "dcl_resource_raw",
+ "dcl_resource_structured",
+ "ld_uav_typed",
+ "store_uav_typed",
+ "ld_raw",
+ "store_raw",
+ "ld_structured",
+ "store_structured",
+ "atomic_and",
+ "atomic_or",
+ "atomic_xor",
+ "atomic_cmp_store",
+ "atomic_iadd",
+ "atomic_imax",
+ "atomic_imin",
+ "atomic_umax",
+ "atomic_umin",
+ "imm_atomic_alloc",
+ "imm_atomic_consume",
+ "imm_atomic_iadd",
+ "imm_atomic_and",
+ "imm_atomic_or",
+ "imm_atomic_xor",
+ "imm_atomic_exch",
+ "imm_atomic_cmp_exch",
+ "imm_atomic_imax",
+ "imm_atomic_imin",
+ "imm_atomic_umax",
+ "imm_atomic_umin",
+ "sync",
+ "dadd",
+ "dmax",
+ "dmin",
+ "dmul",
+ "deq",
+ "dge",
+ "dlt",
+ "dne",
+ "dmov",
+ "dmovc",
+ "dtof",
+ "ftod",
+ "eval_snapped",
+ "eval_sample_index",
+ "eval_centroid",
+ "dcl_gs_instance_count",
+ "d3d11_count",
+};
+
+const char* tpf_file_names[] =
+{
+ "temp",
+ "input",
+ "output",
+ "indexable_temp",
+ "immediate32",
+ "immediate64",
+ "sampler",
+ "resource",
+ "constant_buffer",
+ "immediate_constant_buffer",
+ "label",
+ "input_primitiveid",
+ "output_depth",
+ "null",
+ "rasterizer",
+ "output_coverage_mask",
+ "stream",
+ "function_body",
+ "function_table",
+ "interface",
+ "function_input",
+ "function_output",
+ "output_control_point_id",
+ "input_fork_instance_id",
+ "input_join_instance_id",
+ "input_control_point",
+ "output_control_point",
+ "input_patch_constant",
+ "input_domain_point",
+ "this_pointer",
+ "unordered_access_view",
+ "thread_group_shared_memory",
+ "input_thread_id",
+ "input_thread_group_id",
+ "input_thread_id_in_group",
+ "input_coverage_mask",
+ "input_thread_id_in_group_flattened",
+ "input_gs_instance_id",
+ "output_depth_greater_equal",
+ "output_depth_less_equal",
+ "cycle_counter",
+};
+
+const char* tpf_file_ms_names[] =
+{
+ "r",
+ "v",
+ "o",
+ "x",
+ "l",
+ "d",
+ "sampler",
+ "resource",
+ "cb",
+ "icb",
+ "label",
+ "vPrim",
+ "oDepth",
+ "null",
+ "rasterizer",
+ "oMask",
+ "stream",
+ "function_body",
+ "function_table",
+ "interface",
+ "function_input",
+ "function_output",
+ "vOutputControlPointID",
+ "vForkInstanceID",
+ "vJoinInstanceID",
+ "vicp",
+ "vocp",
+ "input_patch_constant",
+ "vDomain",
+ "this",
+ "u",
+ "g",
+ "vThreadID",
+ "vThreadGrouID",
+ "vThreadIDInGroup",
+ "vCoverage",
+ "vThreadIDInGroupFlattened",
+ "vGSInstanceID",
+ "oDepthGE",
+ "oDepthLE",
+ "vCycleCounter",
+};
+
+const char* tpf_target_names[] =
+{
+ "unknown",
+ "buffer",
+ "texture1d",
+ "texture2d",
+ "texture2dms",
+ "texture3d",
+ "texturecube",
+ "texture1darray",
+ "texture2darray",
+ "texture2dmsarray",
+ "texturecubearray",
+ "raw_buffer",
+ "structured_buffer",
+};
+
+const char* tpf_interpolation_names[] =
+{
+ "undefined",
+ "constant",
+ "linear",
+ "linear centroid",
+ "linear noperspective",
+ "linear noperspective centroid",
+ "linear sample",
+ "linear noperspective sample",
+};
+
+const char* tpf_sv_names[] =
+{
+ "undefined",
+ "position",
+ "clip_distance",
+ "cull_distance",
+ "render_target_array_index",
+ "viewport_array_index",
+ "vertex_id",
+ "primitive_id",
+ "instance_id",
+ "is_front_face",
+ "sample_index",
+ "final_quad_u_eq_0_edge_tessfactor",
+ "final_quad_v_eq_0_edge_tessfactor",
+ "final_quad_u_eq_1_edge_tessfactor",
+ "final_quad_v_eq_1_edge_tessfactor",
+ "final_quad_u_inside_tessfactor",
+ "final_quad_v_inside_tessfactor",
+ "final_tri_u_eq_0_edge_tessfactor",
+ "final_tri_v_eq_0_edge_tessfactor",
+ "final_tri_w_eq_0_edge_tessfactor",
+ "final_tri_inside_tessfactor",
+ "final_line_detail_tessfactor",
+ "final_line_density_tessfactor",
+};
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/src/utils.h b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/utils.h
new file mode 100644
index 0000000..6e77b51
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/src/utils.h
@@ -0,0 +1,45 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef BYTESWAP_H_
+#define BYTESWAP_H_
+
+#include <stdint.h>
+#include <assert.h>
+
+#ifdef WORDS_BIGENDIAN
+static inline uint32_t le32_to_cpu(uint32_t v)
+{
+ return ((v & 0xff) << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24);
+}
+#else
+static inline uint32_t le32_to_cpu(uint32_t v)
+{
+ return v;
+}
+#endif
+
+#endif /* BYTESWAP_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xshader/tools/fxdis.cpp b/src/gallium/state_trackers/d3d1x/d3d1xshader/tools/fxdis.cpp
new file mode 100644
index 0000000..721f95f
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xshader/tools/fxdis.cpp
@@ -0,0 +1,75 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "dxbc.h"
+#include "tpf.h"
+#include <iostream>
+#include <fstream>
+
+void usage()
+{
+ std::cerr << "Gallium Direct3D10/11 Shader Disassembler\n";
+ std::cerr << "This program is free software, released under a MIT-like license\n";
+ std::cerr << "Not affiliated with or endorsed by Microsoft in any way\n";
+ std::cerr << "Latest version available from http://cgit.freedesktop.org/mesa/mesa/\n";
+ std::cerr << "\n";
+ std::cerr << "Usage: fxdis FILE\n";
+ std::cerr << std::endl;
+}
+
+int main(int argc, char** argv)
+{
+ if(argc < 2)
+ {
+ usage();
+ return 1;
+ }
+
+ std::vector<char> data;
+ std::ifstream in(argv[1]);
+ char c;
+ in >> std::noskipws;
+ while(in >> c)
+ data.push_back(c);
+ in.close();
+
+ dxbc_container* dxbc = dxbc_parse(&data[0], data.size());
+ if(dxbc)
+ {
+ std::cout << *dxbc;
+ dxbc_chunk_header* tpf_chunk = dxbc_find_shader_bytecode(&data[0], data.size());
+ if(tpf_chunk)
+ {
+ tpf_program* tpf = tpf_parse(tpf_chunk + 1, bswap_le32(tpf_chunk->size));
+ if(tpf)
+ {
+ std::cout << *tpf;
+ delete tpf;
+ }
+ }
+ delete dxbc;
+ }
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xstutil/Makefile b/src/gallium/state_trackers/d3d1x/d3d1xstutil/Makefile
new file mode 100644
index 0000000..f986f8e
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xstutil/Makefile
@@ -0,0 +1,5 @@
+LIBNAME=d3d1xstutil
+CPP_SOURCES=$(wildcard src/*.cpp)
+LIBRARY_INCLUDES=-Iinclude -I../gd3dapi -I../d3dapi -I../w32api -I../../../include -I../../../auxiliary
+
+include ../Makefile.inc
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xstutil/include/d3d1xstutil.h b/src/gallium/state_trackers/d3d1x/d3d1xstutil/include/d3d1xstutil.h
new file mode 100644
index 0000000..a9260ac
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xstutil/include/d3d1xstutil.h
@@ -0,0 +1,1038 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef D3D1XSTUTIL_H_
+#define D3D1XSTUTIL_H_
+
+#ifdef _MSC_VER
+#include <unordered_map>
+#include <unordered_set>
+#else
+#include <tr1/unordered_map>
+#include <tr1/unordered_set>
+namespace std
+{
+ using namespace tr1;
+}
+#endif
+#include <map>
+#include <utility>
+
+#define WIN32_LEAN_AND_MEAN
+#include <objbase.h>
+#include <guiddef.h>
+#include <specstrings.h>
+
+#ifdef __GNUC__
+#define ATTRIBUTE_UNUSED __attribute__((unused))
+#else
+#define ATTRIBUTE_UNUSED
+#endif
+
+// just replicate GUIDs in every object file to avoid the hassle of having to pull in a library for them
+#undef DEFINE_GUID
+#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+ static const GUID name ATTRIBUTE_UNUSED = \
+ { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
+
+#include "galliumdxgi.h"
+
+extern "C"
+{
+#include <util/u_atomic.h>
+#include <pipe/p_format.h>
+#include <os/os_thread.h>
+}
+
+#include <assert.h>
+#ifdef min
+#undef min
+#endif
+#ifdef max
+#undef max
+#endif
+
+/* NOTE: this _depends_ on the vtable layout of the C++ compiler to be
+ * binary compatible with Windows.
+ * Furthermore some absurd vtable layout likely won't work at all, since
+ * we perform some casts which are probably not safe by the C++ standard.
+ *
+ * In particular, the GNU/Linux/Itanium/clang ABI and Microsoft ABIs will work,
+ * but others may not.
+ * If in doubt, just switch to the latest version of a widely used C++ compiler.
+ *
+ * DESIGN of the Gallium COM implementation
+ *
+ * This state tracker uses somewhat unusual C++ coding patterns,
+ * to implement the COM interfaces required by Direct3D.
+ *
+ * While it may seem complicated, the effect is that the result
+ * generally behaves as intuitively as possible: in particular pointer
+ * casts very rarely change the pointer value (only for secondary
+ * DXGI/Gallium interfaces)
+ *
+ * Implementing COM is on first sight very easy: after all, it just
+ * consists of a reference count, and a dynamic_cast<> equivalent.
+ *
+ * However, implementing objects with multiple interfaces is actually
+ * quite tricky.
+ * The issue is that the interface pointers can't be equal, since this
+ * would place incompatible constraints on the vtable layout and thus
+ * multiple inheritance (and the subobjects the C++ compiler creates
+ * with it) must be correctly used.
+ *
+ * Furthermore, we must have a single reference count, which means
+ * that a naive implementation won't work, and it's necessary to either
+ * use virtual inheritance, or the "mixin inheritance" model we use.
+ *
+ * This solution aims to achieve the following object layout:
+ * 0: pointer to vtable for primary interface
+ * 1: reference count
+ * ... main class
+ * ... vtable pointers for secondary interfaces
+ * ... implementation of subclasses assuming secondary interfaces
+ *
+ * This allows us to cast pointers by just reinterpreting the value in
+ * almost all cases.
+ *
+ * To achieve this, *all* non-leaf classes must have their parent
+ * or the base COM interface as a template parameter, since derived
+ * classes may need to change that to support an interface derived
+ * from the one implemented by the superclass.
+ *
+ * Note however, that you can cast without regard to the template
+ * parameter, because only the vtable layout depends on it, since
+ * interfaces have no data members.
+ *
+ * For this to work, DON'T USE VIRTUAL FUNCTIONS except to implement
+ * interfaces, since the vtable layouts would otherwise be mismatched.
+ * An exception are virtual functions called only from other virtual functions,
+ * which is currently only used for the virtual destructor.
+ *
+ * The base class is GalliumComObject<IFoo>, which implements the
+ * IUnknown interface, and inherits IFoo.
+ *
+ * To support multiple inheritance, we insert GalliumMultiComObject,
+ * which redirects the secondary interfaces to the GalliumComObject
+ * superclass.
+ *
+ * Gallium(Multi)PrivateDataComObject is like ComObject but also
+ * implements the Get/SetPrivateData functions present on several
+ * D3D/DXGI interfaces.
+ *
+ * Example class hierarchy:
+ *
+ * IUnknown
+ * (pure interface)
+ * |
+ * V
+ * IAnimal
+ * (pure interface)
+ * |
+ * V
+ * IDuck
+ * (pure interface)
+ * |
+ * V
+ * GalliumComObject<IDuck>
+ * (non-instantiable, only implements IUnknown)
+ * |
+ * V
+ * GalliumAnimal<IDuck>
+ * (non-instantiable, only implements IAnimal)
+ * |
+ * V
+ * GalliumDuck
+ * (concrete)
+ * |
+ * V
+ * GalliumMultiComObject<GalliumDuck, IWheeledVehicle> <- IWheeledVehicle <- IVehicle <- IUnknown (second version)
+ * (non-instantiable, only implements IDuck and the IUnknown of IWheeledVehicle)
+ * |
+ * V
+ * GalliumDuckOnWheels
+ * (concrete)
+ *
+ * This will produce the desired layout.
+ * Note that GalliumAnimal<IFoo>* is safely castable to GalliumAnimal<IBar>*
+ * by reinterpreting, as long as non-interface virtual functions are not used,
+ * and that you only call interface functions for the superinterface of IBar
+ * that the object actually implements.
+ *
+ * Instead, if GalliumDuck where to inherit both from GalliumAnimal
+ * and IDuck, then (IDuck*)gallium_duck and (IAnimal*)gallium_duck would
+ * have different pointer values, which the "base class as template parameter"
+ * trick avoids.
+ *
+ * The price we pay is that you MUST NOT have virtual functions other than those
+ * implementing interfaces (except for leaf classes) since the position of these
+ * would depend on the base interface.
+ * As mentioned above, virtual functions only called from interface functions
+ * are an exception, currently used only for the virtual destructor.
+ * If you want virtual functions anyway , put them in a separate interface class,
+ * multiply inherit from that and cast the pointer to that interface.
+ *
+ * You CAN however have virtual functions on any class which does not specify
+ * his base as a template parameter, or where you don't need to change the
+ * template base interface parameter by casting.
+ *
+ * --- The magic QueryInterface "delete this" trick ---
+ *
+ * When the reference count drops to 0, we must delete the class.
+ * The problem is, that we must call the right virtual destructor (i.e. on the right class).
+ * However, we would like to be able to call release() and nonatomic_release()
+ * non-virtually for performance (also, the latter cannot be called virtually at all, since
+ * IUnknown does not offer it).
+ *
+ * The naive solution would be to just add a virtual destructor and rely on it.
+ * However, this doesn't work due to the fact that as described above we perform casets
+ * with are unsafe regarding vtable layout.
+ * In particular, consider the case where we try to delete GalliumComObject<ID3D11Texture2D>
+ * with a pointer to GalliumComObject<ID3D11Resource>.
+ * Since we think that this is a GalliumComObject<ID3D11Resource>, we'll look for the
+ * destructor in the vtable slot immediately after the ID3D11Resource vtable, but this is
+ * actually an ID3D11Texture2D function implemented by the object!
+ *
+ * So, we must put the destructor somewhere else.
+ * We could add it as a data member, but it would be awkward and it would bloat the
+ * class.
+ * Thus, we use this trick: we reuse the vtable slot for QueryInterface, which is always at the
+ * same position.
+ * To do so, we define a special value for the first pointer argument, that triggers a
+ * "delete this".
+ * In addition to that, we add a virtual destructor to GalliumComObject.
+ * That virtual destructor will be called by QueryInterface, and since that is a virtual
+ * function, it will know the correct place for the virtual destructor.
+ *
+ * QueryInterface is already slow due to the need to compare several GUIDs, so the
+ * additional pointer test should not be significant.
+ *
+ * Of course the ideal solution would be telling the C++ compiler to put the
+ * destructor it in a negative vtable slot, but unfortunately GCC doesn't support that
+ * yet, and this method is almost as good as that.
+ */
+
+template<typename T>
+struct com_traits;
+
+#define COM_INTERFACE(intf, base) \
+template<> \
+struct com_traits<intf> \
+{ \
+ static REFIID iid() {return IID_##intf;} \
+ static inline bool is_self_or_ancestor(REFIID riid) {return riid == iid() || com_traits<base>::is_self_or_ancestor(riid);} \
+};
+
+template<>
+struct com_traits<IUnknown>
+{
+ static REFIID iid() {return IID_IUnknown;}
+ static inline bool is_self_or_ancestor(REFIID riid) {return riid == iid();}
+};
+
+#ifndef _MSC_VER
+#define __uuidof(T) (com_traits<T>::iid())
+#endif
+
+struct refcnt_t
+{
+ uint32_t refcnt;
+
+ refcnt_t(unsigned v = 1)
+ : refcnt(v)
+ {}
+
+ unsigned add_ref()
+ {
+ p_atomic_inc((int32_t*)&refcnt);
+ return refcnt;
+ }
+
+ unsigned release()
+ {
+ if(p_atomic_dec_zero((int32_t*)&refcnt))
+ return 0;
+ return refcnt;
+ }
+
+ void nonatomic_add_ref()
+ {
+ p_atomic_inc((int32_t*)&refcnt);
+ }
+
+ unsigned nonatomic_release()
+ {
+ if(p_atomic_dec_zero((int32_t*)&refcnt))
+ return 0;
+ else
+ return 1;
+ }
+};
+
+#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
+/* this should be safe because atomic ops are full memory barriers, and thus a sequence that does:
+ * ++one_refcnt;
+ * --other_refcnt;
+ * should never be reorderable (as seen from another CPU) to:
+ * --other_refcnt
+ * ++one_refcnt
+ *
+ * since one of the ops is atomic.
+ * If this weren't the case, a CPU could incorrectly destroy an object manipulated in that way by another one.
+ */
+struct dual_refcnt_t
+{
+ union
+ {
+ uint64_t refcnt;
+ struct
+ {
+ uint32_t atomic_refcnt;
+ uint32_t nonatomic_refcnt;
+ };
+ };
+
+ dual_refcnt_t(unsigned v = 1)
+ {
+ atomic_refcnt = v;
+ nonatomic_refcnt = 0;
+ }
+
+ bool is_zero()
+ {
+ if(sizeof(void*) == 8)
+ return *(volatile uint64_t*)&refcnt == 0ULL;
+ else
+ {
+ uint64_t v;
+ do
+ {
+ v = refcnt;
+ }
+ while(!__sync_bool_compare_and_swap(&refcnt, v, v));
+ return v == 0ULL;
+ }
+ }
+
+ unsigned add_ref()
+ {
+ //printf("%p add_ref at %u %u\n", this, atomic_refcnt, nonatomic_refcnt);
+ p_atomic_inc((int32_t*)&atomic_refcnt);
+ return atomic_refcnt + nonatomic_refcnt;
+ }
+
+ unsigned release()
+ {
+ //printf("%p release at %u %u\n", this, atomic_refcnt, nonatomic_refcnt);
+ if(p_atomic_dec_zero((int32_t*)&atomic_refcnt) && !nonatomic_refcnt && is_zero())
+ return 0;
+ unsigned v = atomic_refcnt + nonatomic_refcnt;
+ return v ? v : 1;
+ }
+
+ void nonatomic_add_ref()
+ {
+ //printf("%p nonatomic_add_ref at %u %u\n", this, atomic_refcnt, nonatomic_refcnt);
+ ++nonatomic_refcnt;
+ }
+
+ unsigned nonatomic_release()
+ {
+ //printf("%p nonatomic_release at %u %u\n", this, atomic_refcnt, nonatomic_refcnt);
+ if(!--nonatomic_refcnt && !atomic_refcnt && is_zero())
+ return 0;
+ return 1;
+ }
+};
+#else
+// this will result in atomic operations being used while they could have been avoided
+#ifdef __i386__
+#warning Compile for 586+ using GCC to improve the performance of the Direct3D 10/11 state tracker
+#endif
+typedef refcnt_t dual_refcnt_t;
+#endif
+
+#define IID_MAGIC_DELETE_THIS (*(const IID*)((intptr_t)-(int)(sizeof(IID) - 1)))
+
+template<typename Base = IUnknown, typename RefCnt = refcnt_t>
+struct GalliumComObject : public Base
+{
+ RefCnt refcnt;
+
+ GalliumComObject()
+ {}
+
+ /* DO NOT CALL this from externally called non-virtual functions in derived classes, since
+ * the vtable position depends on the COM interface being implemented
+ */
+ virtual ~GalliumComObject()
+ {}
+
+ inline ULONG add_ref()
+ {
+ return refcnt.add_ref();
+ }
+
+ inline ULONG release()
+ {
+ ULONG v = refcnt.release();
+ if(!v)
+ {
+ /* this will call execute "delete this", using the correct vtable slot for the destructor */
+ /* see the initial comment for an explaination of this magic trick */
+ this->QueryInterface(IID_MAGIC_DELETE_THIS, 0);
+ return 0;
+ }
+ return v;
+ }
+
+ inline void nonatomic_add_ref()
+ {
+ refcnt.nonatomic_add_ref();
+ }
+
+ inline void nonatomic_release()
+ {
+ if(!refcnt.nonatomic_release())
+ {
+ /* this will execute "delete this", using the correct vtable slot for the destructor */
+ /* see the initial comment for an explaination of this magic trick */
+ this->QueryInterface(IID_MAGIC_DELETE_THIS, 0);
+ }
+ }
+
+ inline HRESULT query_interface(REFIID riid, void **ppvObject)
+ {
+ if(com_traits<Base>::is_self_or_ancestor(riid))
+ {
+ // must be the virtual AddRef, since it is overridden by some classes
+ this->AddRef();
+ *ppvObject = this;
+ return S_OK;
+ }
+ else
+ return E_NOINTERFACE;
+ }
+
+ virtual ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return add_ref();
+ }
+
+ virtual ULONG STDMETHODCALLTYPE Release()
+ {
+ return release();
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE QueryInterface(
+ REFIID riid,
+ void **ppvObject)
+ {
+ /* see the initial comment for an explaination of this magic trick */
+ if(&riid == &IID_MAGIC_DELETE_THIS)
+ {
+ delete this;
+ return 0;
+ }
+ if(!this)
+ return E_INVALIDARG;
+ if(!ppvObject)
+ return E_POINTER;
+ return query_interface(riid, ppvObject);
+ }
+};
+
+template<typename BaseClass, typename SecondaryInterface>
+struct GalliumMultiComObject : public BaseClass, SecondaryInterface
+{
+ // we could avoid this duplication, but the increased complexity to do so isn't worth it
+ virtual ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return BaseClass::add_ref();
+ }
+
+ virtual ULONG STDMETHODCALLTYPE Release()
+ {
+ return BaseClass::release();
+ }
+
+ inline HRESULT query_interface(REFIID riid, void **ppvObject)
+ {
+ HRESULT hr = BaseClass::query_interface(riid, ppvObject);
+ if(SUCCEEDED(hr))
+ return hr;
+ if(com_traits<SecondaryInterface>::is_self_or_ancestor(riid))
+ {
+ // must be the virtual AddRef, since it is overridden by some classes
+ this->AddRef();
+ *ppvObject = (SecondaryInterface*)this;
+ return S_OK;
+ }
+ else
+ return E_NOINTERFACE;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE QueryInterface(
+ REFIID riid,
+ void **ppvObject)
+ {
+ /* see the initial comment for an explaination of this magic trick */
+ if(&riid == &IID_MAGIC_DELETE_THIS)
+ {
+ delete this;
+ return 0;
+ }
+ if(!this)
+ return E_INVALIDARG;
+ if(!ppvObject)
+ return E_POINTER;
+ return query_interface(riid, ppvObject);
+ }
+};
+
+template<typename T, typename Traits>
+struct refcnt_ptr
+{
+ T* p;
+
+ refcnt_ptr()
+ : p(0)
+ {}
+
+ void add_ref() {Traits::add_ref(p);}
+ void release() {Traits::release(p);}
+
+ template<typename U, typename UTraits>
+ refcnt_ptr(const refcnt_ptr<U, UTraits>& c)
+ {
+ *this = static_cast<U*>(c.ref());
+ }
+
+ ~refcnt_ptr()
+ {
+ release();
+ }
+
+ void reset(T* q)
+ {
+ release();
+ p = q;
+ }
+
+ template<typename U, typename UTraits>
+ refcnt_ptr& operator =(const refcnt_ptr<U, UTraits>& q)
+ {
+ return *this = q.p;
+ }
+
+ template<typename U>
+ refcnt_ptr& operator =(U* q)
+ {
+ release();
+ p = static_cast<T*>(q);
+ add_ref();
+ return *this;
+ }
+
+ T* ref()
+ {
+ add_ref();
+ return p;
+ }
+
+ T* steal()
+ {
+ T* ret = p;
+ p = 0;
+ return ret;
+ }
+
+ T* operator ->()
+ {
+ return p;
+ }
+
+ const T* operator ->() const
+ {
+ return p;
+ }
+
+ T** operator &()
+ {
+ assert(!p);
+ return &p;
+ }
+
+ bool operator !() const
+ {
+ return !p;
+ }
+
+ typedef T* refcnt_ptr::*unspecified_bool_type;
+
+ operator unspecified_bool_type() const
+ {
+ return p ? &refcnt_ptr::p : 0;
+ }
+};
+
+struct simple_ptr_traits
+{
+ static void add_ref(void* p) {}
+ static void release(void* p) {}
+};
+
+struct com_ptr_traits
+{
+ static void add_ref(void* p)
+ {
+ if(p)
+ ((IUnknown*)p)->AddRef();
+ }
+
+ static void release(void* p)
+ {
+ if(p)
+ ((IUnknown*)p)->Release();
+ }
+};
+
+template<typename T>
+struct ComPtr : public refcnt_ptr<T, com_ptr_traits>
+{
+ template<typename U, typename UTraits>
+ ComPtr& operator =(const refcnt_ptr<U, UTraits>& q)
+ {
+ return *this = q.p;
+ }
+
+ template<typename U>
+ ComPtr& operator =(U* q)
+ {
+ this->release();
+ this->p = static_cast<T*>(q);
+ this->add_ref();
+ return *this;
+ }
+};
+
+template<typename T, typename TTraits, typename U, typename UTraits>
+bool operator ==(const refcnt_ptr<T, TTraits>& a, const refcnt_ptr<U, UTraits>& b)
+{
+ return a.p == b.p;
+}
+
+template<typename T, typename TTraits, typename U>
+bool operator ==(const refcnt_ptr<T, TTraits>& a, U* b)
+{
+ return a.p == b;
+}
+
+template<typename T, typename TTraits, typename U>
+bool operator ==(U* b, const refcnt_ptr<T, TTraits>& a)
+{
+ return a.p == b;
+}
+
+template<typename T, typename TTraits, typename U, typename UTraits>
+bool operator !=(const refcnt_ptr<T, TTraits>& a, const refcnt_ptr<U, UTraits>& b)
+{
+ return a.p != b.p;
+}
+
+template<typename T, typename TTraits, typename U>
+bool operator !=(const refcnt_ptr<T, TTraits>& a, U* b)
+{
+ return a.p != b;
+}
+
+template<typename T, typename TTraits, typename U>
+bool operator !=(U* b, const refcnt_ptr<T, TTraits>& a)
+{
+ return a.p != b;
+}
+
+template<bool threadsafe>
+struct maybe_mutex_t;
+
+template<>
+struct maybe_mutex_t<true>
+{
+ pipe_mutex mutex;
+
+ void lock()
+ {
+ pipe_mutex_lock(mutex);
+ }
+
+ void unlock()
+ {
+ pipe_mutex_unlock(mutex);
+ }
+};
+
+template<>
+struct maybe_mutex_t<false>
+{
+ void lock()
+ {
+ }
+
+ void unlock()
+ {
+ }
+};
+
+typedef maybe_mutex_t<true> mutex_t;
+
+template<typename T>
+struct lock_t
+{
+ T& mutex;
+ lock_t(T& mutex)
+ : mutex(mutex)
+ {
+ mutex.lock();
+ }
+
+ ~lock_t()
+ {
+ mutex.unlock();
+ }
+};
+
+struct c_string
+{
+ const char* p;
+ c_string(const char* p)
+ : p(p)
+ {}
+
+ operator const char*() const
+ {
+ return p;
+ }
+};
+
+static inline bool operator ==(const c_string& a, const c_string& b)
+{
+ return !strcmp(a.p, b.p);
+}
+
+static inline bool operator !=(const c_string& a, const c_string& b)
+{
+ return strcmp(a.p, b.p);
+}
+
+#ifdef __GLIBCXX__
+namespace std
+{
+ namespace tr1
+ {
+ template<>
+ inline size_t hash<GUID>::operator()(GUID __val) const
+ {
+ return _Fnv_hash::hash(__val);
+ }
+
+ template<>
+ inline size_t hash<c_string>::operator()(c_string __val) const
+ {
+ return _Fnv_hash::hash(__val.p, strlen(__val.p));
+ }
+
+ template<typename T, typename U>
+ struct hash<std::pair<T, U> > : public std::unary_function<std::pair<T, U>, size_t>
+ {
+ size_t operator()(std::pair<T, U> __val) const;
+ };
+
+ template<typename T, typename U>
+ inline size_t hash<std::pair<T, U> >::operator()(std::pair<T, U> __val) const
+ {
+ std::pair<size_t, size_t> p;
+ p.first = hash<T>()(__val.first);
+ p.second = hash<U>()(__val.second);
+ return _Fnv_hash::hash(p);
+ }
+ }
+}
+#else
+#warning "You probably need to add a pair, C string and GUID hash implementation for your C++ library"
+#endif
+
+template<typename Base, typename RefCnt = refcnt_t>
+struct GalliumPrivateDataComObject : public GalliumComObject<Base, RefCnt>
+{
+ typedef std::unordered_map<GUID, std::pair<void*, unsigned> > private_data_map_t;
+ private_data_map_t private_data_map;
+ mutex_t private_data_mutex;
+
+ ~GalliumPrivateDataComObject()
+ {
+ for(private_data_map_t::iterator i = private_data_map.begin(), e = private_data_map.end(); i != e; ++i)
+ {
+ if(i->second.second == ~0u)
+ ((IUnknown*)i->second.first)->Release();
+ else
+ free(i->second.first);
+ }
+ }
+
+ HRESULT get_private_data(
+ __in REFGUID guid,
+ __inout UINT *pDataSize,
+ __out_bcount_opt(*pDataSize) void *pData)
+ {
+ lock_t<mutex_t> lock(private_data_mutex);
+ private_data_map_t::iterator i = private_data_map.find(guid);
+ *pDataSize = 0;
+ if(i == private_data_map.end())
+ return DXGI_ERROR_NOT_FOUND;
+ if(i->second.second == ~0u)
+ {
+ /* TODO: is GetPrivateData on interface data supposed to do this? */
+ if(*pDataSize < sizeof(void*))
+ return E_INVALIDARG;
+ if(pData)
+ {
+ memcpy(pData, &i->second.first, sizeof(void*));
+ ((IUnknown*)i->second.first)->AddRef();
+ }
+ *pDataSize = sizeof(void*);
+ }
+ else
+ {
+ unsigned size = std::min(*pDataSize, i->second.second);
+ if(pData)
+ memcpy(pData, i->second.first, size);
+ *pDataSize = size;
+ }
+ return S_OK;
+ }
+
+ HRESULT set_private_data(
+ __in REFGUID guid,
+ __in UINT DataSize,
+ __in_bcount_opt( DataSize ) const void *pData)
+ {
+ void* p = 0;
+
+ if(DataSize && pData)
+ {
+ p = malloc(DataSize);
+ if(!p)
+ return E_OUTOFMEMORY;
+ }
+
+ lock_t<mutex_t> lock(private_data_mutex);
+ std::pair<void*, unsigned>& v = private_data_map[guid];
+ if(v.first)
+ {
+ if(v.second == ~0u)
+ ((IUnknown*)v.first)->Release();
+ else
+ free(v.first);
+ }
+ if(DataSize && pData)
+ {
+ memcpy(p, pData, DataSize);
+ v.first = p;
+ v.second = DataSize;
+ }
+ else
+ private_data_map.erase(guid);
+ return S_OK;
+ }
+
+ HRESULT set_private_data_interface(
+ __in REFGUID guid,
+ __in_opt const IUnknown *pData)
+ {
+ lock_t<mutex_t> lock(private_data_mutex);
+ std::pair<void*, unsigned>& v = private_data_map[guid];
+ if(v.first)
+ {
+ if(v.second == ~0u)
+ ((IUnknown*)v.first)->Release();
+ else
+ free(v.first);
+ }
+ if(pData)
+ {
+ ((IUnknown*)pData)->AddRef();
+ v.first = (void*)pData;
+ v.second = ~0;
+ }
+ else
+ private_data_map.erase(guid);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetPrivateData(
+ __in REFGUID guid,
+ __inout UINT *pDataSize,
+ __out_bcount_opt(*pDataSize) void *pData)
+ {
+ return get_private_data(guid, pDataSize, pData);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetPrivateData(
+ __in REFGUID guid,
+ __in UINT DataSize,
+ __in_bcount_opt( DataSize ) const void *pData)
+ {
+ return set_private_data(guid, DataSize, pData);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
+ __in REFGUID guid,
+ __in_opt const IUnknown *pData)
+ {
+ return set_private_data_interface(guid, pData);
+ }
+};
+
+template<typename BaseClass, typename SecondaryInterface>
+struct GalliumMultiPrivateDataComObject : public GalliumMultiComObject<BaseClass, SecondaryInterface>
+{
+ // we could avoid this duplication, but the increased complexity to do so isn't worth it
+ virtual HRESULT STDMETHODCALLTYPE GetPrivateData(
+ __in REFGUID guid,
+ __inout UINT *pDataSize,
+ __out_bcount_opt(*pDataSize) void *pData)
+ {
+ return BaseClass::get_private_data(guid, pDataSize, pData);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetPrivateData(
+ __in REFGUID guid,
+ __in UINT DataSize,
+ __in_bcount_opt( DataSize ) const void *pData)
+ {
+ return BaseClass::set_private_data(guid, DataSize, pData);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
+ __in REFGUID guid,
+ __in_opt const IUnknown *pData)
+ {
+ return BaseClass::set_private_data_interface(guid, pData);
+ }
+};
+
+#define DXGI_FORMAT_COUNT 100
+extern pipe_format dxgi_to_pipe_format[DXGI_FORMAT_COUNT];
+extern DXGI_FORMAT pipe_to_dxgi_format[PIPE_FORMAT_COUNT];
+
+void init_pipe_to_dxgi_format();
+
+COM_INTERFACE(IGalliumDevice, IUnknown);
+COM_INTERFACE(IGalliumAdapter, IUnknown);
+COM_INTERFACE(IGalliumResource, IUnknown);
+
+// used to make QueryInterface know the IIDs of the interface and its ancestors
+COM_INTERFACE(IDXGIObject, IUnknown)
+COM_INTERFACE(IDXGIDeviceSubObject, IDXGIObject)
+COM_INTERFACE(IDXGISurface, IDXGIDeviceSubObject)
+COM_INTERFACE(IDXGIOutput, IDXGIObject)
+COM_INTERFACE(IDXGIAdapter, IDXGIObject)
+COM_INTERFACE(IDXGISwapChain, IDXGIDeviceSubObject)
+COM_INTERFACE(IDXGIFactory, IDXGIObject)
+COM_INTERFACE(IDXGIDevice, IDXGIObject)
+COM_INTERFACE(IDXGIResource, IDXGIDeviceSubObject)
+COM_INTERFACE(IDXGISurface1, IDXGISurface)
+COM_INTERFACE(IDXGIDevice1, IDXGIDevice)
+COM_INTERFACE(IDXGIAdapter1, IDXGIAdapter)
+COM_INTERFACE(IDXGIFactory1, IDXGIFactory)
+
+template<typename Base>
+struct GalliumDXGIDevice : public GalliumMultiPrivateDataComObject<Base, IDXGIDevice>
+{
+ ComPtr<IDXGIAdapter> adapter;
+ int priority;
+ unsigned max_latency;
+
+ GalliumDXGIDevice(IDXGIAdapter* p_adapter)
+ {
+ adapter = p_adapter;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetParent(
+ __in REFIID riid,
+ __out void **ppParent)
+ {
+ return adapter.p->QueryInterface(riid, ppParent);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetAdapter(
+ __out IDXGIAdapter **pAdapter)
+ {
+ *pAdapter = adapter.ref();
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE QueryResourceResidency(
+ __in_ecount(NumResources) IUnknown *const *ppResources,
+ __out_ecount(NumResources) DXGI_RESIDENCY *pResidencyStatus,
+ UINT NumResources)
+ {
+ for(unsigned i = 0; i < NumResources; ++i)
+ pResidencyStatus[i] = DXGI_RESIDENCY_FULLY_RESIDENT;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetGPUThreadPriority(
+ INT Priority)
+ {
+ priority = Priority;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetGPUThreadPriority(
+ __out INT *pPriority)
+ {
+ *pPriority = priority;
+ return S_OK;
+ }
+
+ HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency(
+ UINT *pMaxLatency
+ )
+ {
+ *pMaxLatency = max_latency;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency(
+ UINT MaxLatency)
+ {
+ max_latency = MaxLatency;
+ return S_OK;
+ }
+};
+
+#endif /* D3D1XSTUTIL_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/d3d1xstutil/src/dxgi_enums.cpp b/src/gallium/state_trackers/d3d1x/d3d1xstutil/src/dxgi_enums.cpp
new file mode 100644
index 0000000..da28e64
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3d1xstutil/src/dxgi_enums.cpp
@@ -0,0 +1,147 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include <d3d1xstutil.h>
+
+/* D3D has to keep binary compatibility, so these tables will always work
+ * However, Gallium -> D3D conversion must use .[PIPE_xxx] = D3D11_xxx syntax */
+
+pipe_format dxgi_to_pipe_format[DXGI_FORMAT_COUNT] =
+{
+ PIPE_FORMAT_NONE,
+ PIPE_FORMAT_R32G32B32A32_FLOAT, /* TYPELESS */
+ PIPE_FORMAT_R32G32B32A32_FLOAT,
+ PIPE_FORMAT_R32G32B32A32_USCALED,
+ PIPE_FORMAT_R32G32B32A32_SSCALED,
+ PIPE_FORMAT_R32G32B32_FLOAT, /* TYPELESS */
+ PIPE_FORMAT_R32G32B32_FLOAT,
+ PIPE_FORMAT_R32G32B32_USCALED,
+ PIPE_FORMAT_R32G32B32_SSCALED,
+ PIPE_FORMAT_R16G16B16A16_FLOAT, /* TYPELESS */
+ PIPE_FORMAT_R16G16B16A16_FLOAT,
+ PIPE_FORMAT_R16G16B16A16_UNORM,
+ PIPE_FORMAT_R16G16B16A16_USCALED,
+ PIPE_FORMAT_R16G16B16A16_SNORM,
+ PIPE_FORMAT_R16G16B16A16_SSCALED,
+ PIPE_FORMAT_R32G32_FLOAT, /* TYPELESS */
+ PIPE_FORMAT_R32G32_FLOAT,
+ PIPE_FORMAT_R32G32_USCALED,
+ PIPE_FORMAT_R32G32_SSCALED,
+ PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED, /* PIPE_FORMAT_R32G8X24_FLOAT_TYPELESS */
+ PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED,
+ PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED, /* PIPE_FORMAT_R32_FLOAT_X8X24_TYPELESS */
+ PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED, /* PIPE_FORMAT_X32_TYPELESS_G8X24_USCALED */
+ PIPE_FORMAT_R10G10B10A2_UNORM, /* TYPELESS */
+ PIPE_FORMAT_R10G10B10A2_UNORM,
+ PIPE_FORMAT_R10G10B10A2_USCALED,
+ PIPE_FORMAT_R11G11B10_FLOAT,
+ PIPE_FORMAT_R8G8B8A8_UNORM, /* TYPELESS */
+ PIPE_FORMAT_R8G8B8A8_UNORM,
+ PIPE_FORMAT_R8G8B8A8_SRGB,
+ PIPE_FORMAT_R8G8B8A8_USCALED,
+ PIPE_FORMAT_R8G8B8A8_SNORM,
+ PIPE_FORMAT_R8G8B8A8_SSCALED,
+ PIPE_FORMAT_R16G16_FLOAT, /* TYPELESS */
+ PIPE_FORMAT_R16G16_FLOAT,
+ PIPE_FORMAT_R16G16_UNORM,
+ PIPE_FORMAT_R16G16_USCALED,
+ PIPE_FORMAT_R16G16_SNORM,
+ PIPE_FORMAT_R16G16_SSCALED,
+ PIPE_FORMAT_R32_FLOAT, /* TYPELESS */
+ PIPE_FORMAT_Z32_FLOAT,
+ PIPE_FORMAT_R32_FLOAT,
+ PIPE_FORMAT_R32_USCALED,
+ PIPE_FORMAT_R32_SSCALED,
+ PIPE_FORMAT_Z24_UNORM_S8_USCALED, /* PIPE_FORMAT_R24G8_TYPELESS */
+ PIPE_FORMAT_Z24_UNORM_S8_USCALED,
+ PIPE_FORMAT_Z24X8_UNORM, /* PIPE_FORMAT_R24_UNORM_X8_TYPELESS */
+ PIPE_FORMAT_Z24_UNORM_S8_USCALED, /* PIPE_FORMAT_X24_TYPELESS_G8_USCALED */
+ PIPE_FORMAT_R8G8_UNORM, /* TYPELESS */
+ PIPE_FORMAT_R8G8_UNORM,
+ PIPE_FORMAT_R8G8_USCALED,
+ PIPE_FORMAT_R8G8_SNORM,
+ PIPE_FORMAT_R8G8_SSCALED,
+ PIPE_FORMAT_R16_FLOAT, /* TYPELESS */
+ PIPE_FORMAT_R16_FLOAT,
+ PIPE_FORMAT_Z16_UNORM,
+ PIPE_FORMAT_R16_UNORM,
+ PIPE_FORMAT_R16_USCALED,
+ PIPE_FORMAT_R16_SNORM,
+ PIPE_FORMAT_R16_SSCALED,
+ PIPE_FORMAT_R8_UNORM, /* TYPELESS */
+ PIPE_FORMAT_R8_UNORM,
+ PIPE_FORMAT_R8_USCALED,
+ PIPE_FORMAT_R8_SNORM,
+ PIPE_FORMAT_R8_SSCALED,
+ PIPE_FORMAT_A8_UNORM,
+ PIPE_FORMAT_R1_UNORM,
+ PIPE_FORMAT_R9G9B9E5_FLOAT,
+ PIPE_FORMAT_R8G8_B8G8_UNORM,
+ PIPE_FORMAT_G8R8_G8B8_UNORM,
+ PIPE_FORMAT_DXT1_RGBA, /* TYPELESS */
+ PIPE_FORMAT_DXT1_RGBA,
+ PIPE_FORMAT_DXT1_SRGBA,
+ PIPE_FORMAT_DXT3_RGBA, /* TYPELESS */
+ PIPE_FORMAT_DXT3_RGBA,
+ PIPE_FORMAT_DXT3_SRGBA,
+ PIPE_FORMAT_DXT5_RGBA, /* TYPELESS */
+ PIPE_FORMAT_DXT5_RGBA,
+ PIPE_FORMAT_DXT5_SRGBA,
+ PIPE_FORMAT_RGTC1_UNORM, /* TYPELESS */
+ PIPE_FORMAT_RGTC1_UNORM,
+ PIPE_FORMAT_RGTC1_SNORM,
+ PIPE_FORMAT_RGTC2_UNORM, /* TYPELESS */
+ PIPE_FORMAT_RGTC2_UNORM,
+ PIPE_FORMAT_RGTC2_SNORM,
+ PIPE_FORMAT_B5G6R5_UNORM,
+ PIPE_FORMAT_B5G5R5A1_UNORM,
+ PIPE_FORMAT_B8G8R8A8_UNORM,
+ PIPE_FORMAT_B8G8R8X8_UNORM,
+ PIPE_FORMAT_R10SG10SB10SA2U_NORM,
+ PIPE_FORMAT_B8G8R8A8_UNORM, /* TYPELESS */
+ PIPE_FORMAT_B8G8R8A8_SRGB,
+ PIPE_FORMAT_B8G8R8X8_UNORM, /* TYPELESS */
+ PIPE_FORMAT_B8G8R8X8_SRGB,
+ PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC6H_TYPELESS */
+ PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC6H_UF16 */
+ PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC6H_SF16 */
+ PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC7_TYPELESS */
+ PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC7_UNORM */
+ PIPE_FORMAT_NONE, /* PIPE_FORMAT_BC7_UNORM_SRGB */
+};
+
+DXGI_FORMAT pipe_to_dxgi_format[PIPE_FORMAT_COUNT];
+static int pipe_to_dxgi_format_initialized;
+void init_pipe_to_dxgi_format()
+{
+ if(!pipe_to_dxgi_format_initialized)
+ {
+ for(unsigned i = 0; i < DXGI_FORMAT_COUNT; ++i)
+ pipe_to_dxgi_format[dxgi_to_pipe_format[i]] = (DXGI_FORMAT)i;
+ pipe_to_dxgi_format[PIPE_FORMAT_NONE] = DXGI_FORMAT_UNKNOWN;
+ pipe_to_dxgi_format_initialized = 1;
+ }
+}
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/Makefile b/src/gallium/state_trackers/d3d1x/d3dapi/Makefile
new file mode 100644
index 0000000..8b16b1b
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/Makefile
@@ -0,0 +1,4 @@
+all: idl
+
+include ../Makefile.inc
+
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3d10.idl b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10.idl
new file mode 100644
index 0000000..c371bbe
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10.idl
@@ -0,0 +1,1554 @@
+/*
+ * Copyright 2007 Andras Kovacs
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/* modified by Luca Barbieri on Sep 2010 to:
+ * - converted to using d3dcommon.idl
+ * - add missing D3D10_FORMAT_SUPPORT
+ * - add DXGI 1.1 D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX, D3D10_RESOURCE_MISC_GDI_COMPATIBLE
+*/
+import "oaidl.idl";
+import "ocidl.idl";
+import "dxgi.idl";
+import "d3dcommon.idl";
+
+cpp_quote("#ifndef _D3D10_CONSTANTS")
+cpp_quote("#define _D3D10_CONSTANTS")
+const float D3D10_DEFAULT_BLEND_FACTOR_ALPHA = 1.0;
+const float D3D10_DEFAULT_BLEND_FACTOR_BLUE = 1.0;
+const float D3D10_DEFAULT_BLEND_FACTOR_GREEN = 1.0;
+const float D3D10_DEFAULT_BLEND_FACTOR_RED = 1.0;
+const float D3D10_DEFAULT_BORDER_COLOR_COMPONENT = 0.0;
+const float D3D10_DEFAULT_SLOPE_SCALED_DEPTH_BIAS = 0.0;
+const float D3D10_DEFAULT_DEPTH_BIAS_CLAMP = 0.0;
+const float D3D10_DEFAULT_MAX_ANISOTROPY = 16.0;
+const float D3D10_DEFAULT_MIP_LOD_BIAS = 0.0;
+const float D3D10_DEFAULT_VIEWPORT_MAX_DEPTH = 0.0;
+const float D3D10_DEFAULT_VIEWPORT_MIN_DEPTH = 0.0;
+const float D3D10_FLOAT16_FUSED_TOLERANCE_IN_ULP = 0.6;
+const float D3D10_FLOAT32_MAX = 3.402823466e+38;
+const float D3D10_FLOAT32_TO_INTEGER_TOLERANCE_IN_ULP = 0.6;
+const float D3D10_FLOAT_TO_SRGB_EXPONENT_DENOMINATOR = 2.4;
+const float D3D10_FLOAT_TO_SRGB_EXPONENT_NUMERATOR = 1.0;
+const float D3D10_FLOAT_TO_SRGB_OFFSET = 0.055;
+const float D3D10_FLOAT_TO_SRGB_SCALE_1 = 12.92;
+const float D3D10_FLOAT_TO_SRGB_SCALE_2 = 1.055;
+const float D3D10_FLOAT_TO_SRGB_THRESHOLD = 0.0031308;
+const float D3D10_FTOI_INSTRUCTION_MAX_INPUT = 2147483647.999;
+const float D3D10_FTOI_INSTRUCTION_MIN_INPUT = -2147483648.999;
+const float D3D10_FTOU_INSTRUCTION_MAX_INPUT = 4294967295.999;
+const float D3D10_FTOU_INSTRUCTION_MIN_INPUT = 0.0;
+const float D3D10_LINEAR_GAMMA = 1.0;
+const float D3D10_MAX_BORDER_COLOR_COMPONENT = 1.0;
+const float D3D10_MAX_DEPTH = 1.0;
+const float D3D10_MAX_POSITION_VALUE = 3.402823466e+34;
+const float D3D10_MIN_BORDER_COLOR_COMPONENT = 0.0;
+const float D3D10_MIN_DEPTH = 0.0;
+const float D3D10_MIP_LOD_BIAS_MAX = 15.99;
+const float D3D10_MIP_LOD_BIAS_MIN = -16.0;
+const float D3D10_PS_PIXEL_CENTER_FRACTIONAL_COMPONENT = 0.5;
+const float D3D10_MULTISAMPLE_ANTIALIAS_LINE_WIDTH = 1.4;
+const float D3D10_SRGB_GAMMA = 2.2;
+const float D3D10_SRGB_TO_FLOAT_DENOMINATOR_1 = 12.92;
+const float D3D10_SRGB_TO_FLOAT_DENOMINATOR_2 = 1.055;
+const float D3D10_SRGB_TO_FLOAT_EXPONENT = 2.4;
+const float D3D10_SRGB_TO_FLOAT_OFFSET = 0.055;
+const float D3D10_SRGB_TO_FLOAT_THRESHOLD = 0.04045;
+const float D3D10_SRGB_TO_FLOAT_TOLERANCE_IN_ULP = 0.5;
+const float D3D10_PS_LEGACY_PIXEL_CENTER_FRACTIONAL_COMPONENT = 0.0;
+const float D3D_SPEC_VERSION = 1.050005;
+const unsigned int D3D10_16BIT_INDEX_STRIP_CUT_VALUE = 0xffff;
+const unsigned int D3D10_32BIT_INDEX_STRIP_CUT_VALUE = 0xffffffff;
+const unsigned int D3D10_8BIT_INDEX_STRIP_CUT_VALUE = 0xff;
+const unsigned int D3D10_ARRAY_AXIS_ADDRESS_RANGE_BIT_COUNT = 9;
+const unsigned int D3D10_CLIP_OR_CULL_DISTANCE_COUNT = 8;
+const unsigned int D3D10_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT = 2;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT = 14;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_COMPONENTS = 4;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_HW_SLOT_COUNT = 15;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_REGISTER_COUNT = 15;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D10_COMMONSHADER_CONSTANT_BUFFER_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_COMMONSHADER_FLOWCONTROL_NESTING_LIMIT = 64;
+const unsigned int D3D10_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_COUNT = 1;
+const unsigned int D3D10_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D10_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_COMMONSHADER_IMMEDIATE_VALUE_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COMPONENTS = 1;
+const unsigned int D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT = 128;
+const unsigned int D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D10_COMMONSHADER_INPUT_RESOURCE_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT = 128;
+const unsigned int D3D10_COMMONSHADER_SAMPLER_REGISTER_COMPONENTS = 1;
+const unsigned int D3D10_COMMONSHADER_SAMPLER_REGISTER_COUNT = 16;
+const unsigned int D3D10_COMMONSHADER_SAMPLER_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D10_COMMONSHADER_SAMPLER_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT = 16;
+const unsigned int D3D10_COMMONSHADER_SUBROUTINE_NESTING_LIMIT = 32;
+const unsigned int D3D10_COMMONSHADER_TEMP_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_COMMONSHADER_TEMP_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_COMMONSHADER_TEMP_REGISTER_COUNT = 4096;
+const unsigned int D3D10_COMMONSHADER_TEMP_REGISTER_READS_PER_INST = 3;
+const unsigned int D3D10_COMMONSHADER_TEMP_REGISTER_READ_PORTS = 3;
+const unsigned int D3D10_COMMONSHADER_TEXCOORD_RANGE_REDUCTION_MAX = 10;
+const int D3D10_COMMONSHADER_TEXCOORD_RANGE_REDUCTION_MIN = -10;
+const int D3D10_COMMONSHADER_TEXEL_OFFSET_MAX_NEGATIVE = -8;
+const unsigned int D3D10_COMMONSHADER_TEXEL_OFFSET_MAX_POSITIVE = 7;
+const unsigned int D3D10_DEFAULT_DEPTH_BIAS = 0;
+const unsigned int D3D10_DEFAULT_RENDER_TARGET_ARRAY_INDEX = 0;
+const unsigned int D3D10_DEFAULT_SAMPLE_MASK = 0xffffffff;
+const unsigned int D3D10_DEFAULT_SCISSOR_ENDX = 0;
+const unsigned int D3D10_DEFAULT_SCISSOR_ENDY = 0;
+const unsigned int D3D10_DEFAULT_SCISSOR_STARTX = 0;
+const unsigned int D3D10_DEFAULT_SCISSOR_STARTY = 0;
+const unsigned int D3D10_DEFAULT_STENCIL_READ_MASK = 0xff;
+const unsigned int D3D10_DEFAULT_STENCIL_REFERENCE = 0;
+const unsigned int D3D10_DEFAULT_STENCIL_WRITE_MASK = 0xff;
+const unsigned int D3D10_DEFAULT_VIEWPORT_AND_SCISSORRECT_INDEX = 0;
+const unsigned int D3D10_DEFAULT_VIEWPORT_HEIGHT = 0;
+const unsigned int D3D10_DEFAULT_VIEWPORT_TOPLEFTX = 0;
+const unsigned int D3D10_DEFAULT_VIEWPORT_TOPLEFTY = 0;
+const unsigned int D3D10_DEFAULT_VIEWPORT_WIDTH = 0;
+const unsigned int D3D10_GS_INPUT_PRIM_CONST_REGISTER_COMPONENTS = 1;
+const unsigned int D3D10_GS_INPUT_PRIM_CONST_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_GS_INPUT_PRIM_CONST_REGISTER_COUNT = 1;
+const unsigned int D3D10_GS_INPUT_PRIM_CONST_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D10_GS_INPUT_PRIM_CONST_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_GS_INPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_GS_INPUT_REGISTER_COMPONENT_BIT_COUNT =32;
+const unsigned int D3D10_GS_INPUT_REGISTER_COUNT = 16;
+const unsigned int D3D10_GS_INPUT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D10_GS_INPUT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_GS_INPUT_REGISTER_VERTICES = 6;
+const unsigned int D3D10_GS_OUTPUT_ELEMENTS = 32;
+const unsigned int D3D10_GS_OUTPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_GS_OUTPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_GS_OUTPUT_REGISTER_COUNT = 32;
+const unsigned int D3D10_IA_DEFAULT_INDEX_BUFFER_OFFSET_IN_BYTES = 0;
+const unsigned int D3D10_IA_DEFAULT_PRIMITIVE_TOPOLOGY = 0;
+const unsigned int D3D10_IA_DEFAULT_VERTEX_BUFFER_OFFSET_IN_BYTES = 0;
+const unsigned int D3D10_IA_INDEX_INPUT_RESOURCE_SLOT_COUNT = 1;
+const unsigned int D3D10_IA_INSTANCE_ID_BIT_COUNT = 32;
+const unsigned int D3D10_IA_INTEGER_ARITHMETIC_BIT_COUNT = 32;
+const unsigned int D3D10_IA_PRIMITIVE_ID_BIT_COUNT = 32;
+const unsigned int D3D10_IA_VERTEX_ID_BIT_COUNT = 32;
+const unsigned int D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT = 16;
+const unsigned int D3D10_IA_VERTEX_INPUT_STRUCTURE_ELEMENTS_COMPONENTS = 64;
+const unsigned int D3D10_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT = 16;
+const unsigned int D3D10_INTEGER_DIVIDE_BY_ZERO_QUOTIENT = 0xffffffff;
+const unsigned int D3D10_INTEGER_DIVIDE_BY_ZERO_REMAINDER = 0xffffffff;
+const unsigned int D3D10_MAX_MAXANISOTROPY = 16;
+const unsigned int D3D10_MAX_MULTISAMPLE_SAMPLE_COUNT = 32;
+const unsigned int D3D10_MAX_TEXTURE_DIMENSION_2_TO_EXP = 17;
+const unsigned int D3D10_MIN_MAXANISOTROPY = 0;
+const unsigned int D3D10_MIP_LOD_FRACTIONAL_BIT_COUNT = 6;
+const unsigned int D3D10_MIP_LOD_RANGE_BIT_COUNT = 8;
+const unsigned int D3D10_NONSAMPLE_FETCH_OUT_OF_RANGE_ACCESS_RESULT = 0;
+const unsigned int D3D10_PIXEL_ADDRESS_RANGE_BIT_COUNT = 13;
+const unsigned int D3D10_PRE_SCISSOR_PIXEL_ADDRESS_RANGE_BIT_COUNT = 15;
+const unsigned int D3D10_PS_FRONTFACING_DEFAULT_VALUE = 0xffffffff;
+const unsigned int D3D10_PS_FRONTFACING_FALSE_VALUE = 0;
+const unsigned int D3D10_PS_FRONTFACING_TRUE_VALUE = 0xffffffff;
+const unsigned int D3D10_PS_INPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_PS_INPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_PS_INPUT_REGISTER_COUNT = 32;
+const unsigned int D3D10_PS_INPUT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D10_PS_INPUT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_PS_OUTPUT_DEPTH_REGISTER_COMPONENTS = 1;
+const unsigned int D3D10_PS_OUTPUT_DEPTH_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_PS_OUTPUT_DEPTH_REGISTER_COUNT = 1;
+const unsigned int D3D10_PS_OUTPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_PS_OUTPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_PS_OUTPUT_REGISTER_COUNT = 8;
+const unsigned int D3D10_REQ_BLEND_OBJECT_COUNT_PER_CONTEXT = 4096;
+const unsigned int D3D10_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP = 27;
+const unsigned int D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT = 4096;
+const unsigned int D3D10_REQ_DEPTH_STENCIL_OBJECT_COUNT_PER_CONTEXT = 4096;
+const unsigned int D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP = 32;
+const unsigned int D3D10_REQ_DRAW_VERTEX_COUNT_2_TO_EXP = 32;
+const unsigned int D3D10_REQ_FILTERING_HW_ADDRESSABLE_RESOURCE_DIMENSION = 8192;
+const unsigned int D3D10_REQ_GS_INVOCATION_32BIT_OUTPUT_COMPONENT_LIMIT = 1024;
+const unsigned int D3D10_REQ_IMMEDIATE_CONSTANT_BUFFER_ELEMENT_COUNT = 4096;
+const unsigned int D3D10_REQ_MAXANISOTROPY = 16;
+const unsigned int D3D10_REQ_MIP_LEVELS = 14;
+const unsigned int D3D10_REQ_MULTI_ELEMENT_STRUCTURE_SIZE_IN_BYTES = 2048;
+const unsigned int D3D10_REQ_RASTERIZER_OBJECT_COUNT_PER_CONTEXT = 4096;
+const unsigned int D3D10_REQ_RENDER_TO_BUFFER_WINDOW_WIDTH = 8192;
+const unsigned int D3D10_REQ_RESOURCE_SIZE_IN_MEGABYTES = 128;
+const unsigned int D3D10_REQ_RESOURCE_VIEW_COUNT_PER_CONTEXT_2_TO_EXP = 20;
+const unsigned int D3D10_REQ_SAMPLER_OBJECT_COUNT_PER_CONTEXT = 4096;
+const unsigned int D3D10_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION = 512;
+const unsigned int D3D10_REQ_TEXTURE1D_U_DIMENSION = 8192;
+const unsigned int D3D10_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION = 512;
+const unsigned int D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION = 8192;
+const unsigned int D3D10_REQ_TEXTURE3D_U_V_OR_W_DIMENSION = 2048;
+const unsigned int D3D10_REQ_TEXTURECUBE_DIMENSION = 8192;
+const unsigned int D3D10_RESINFO_INSTRUCTION_MISSING_COMPONENT_RETVAL = 0;
+const unsigned int D3D10_SHADER_MAJOR_VERSION = 4;
+const unsigned int D3D10_SHADER_MINOR_VERSION = 0;
+const unsigned int D3D10_SHIFT_INSTRUCTION_PAD_VALUE = 0;
+const unsigned int D3D10_SHIFT_INSTRUCTION_SHIFT_VALUE_BIT_COUNT = 5;
+const unsigned int D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT = 8;
+const unsigned int D3D10_SO_BUFFER_MAX_STRIDE_IN_BYTES = 2048;
+const unsigned int D3D10_SO_BUFFER_MAX_WRITE_WINDOW_IN_BYTES = 256;
+const unsigned int D3D10_SO_BUFFER_SLOT_COUNT = 4;
+const unsigned int D3D10_SO_DDI_REGISTER_INDEX_DENOTING_GAP = 0xffffffff;
+const unsigned int D3D10_SO_MULTIPLE_BUFFER_ELEMENTS_PER_BUFFER = 1;
+const unsigned int D3D10_SO_SINGLE_BUFFER_COMPONENT_LIMIT = 64;
+const unsigned int D3D10_STANDARD_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_STANDARD_COMPONENT_BIT_COUNT_DOUBLED = 64;
+const unsigned int D3D10_STANDARD_MAXIMUM_ELEMENT_ALIGNMENT_BYTE_MULTIPLE = 4;
+const unsigned int D3D10_STANDARD_PIXEL_COMPONENT_COUNT = 128;
+const unsigned int D3D10_STANDARD_PIXEL_ELEMENT_COUNT = 32;
+const unsigned int D3D10_STANDARD_VECTOR_SIZE = 4;
+const unsigned int D3D10_STANDARD_VERTEX_ELEMENT_COUNT = 16;
+const unsigned int D3D10_STANDARD_VERTEX_TOTAL_COMPONENT_COUNT = 64;
+const unsigned int D3D10_SUBPIXEL_FRACTIONAL_BIT_COUNT = 8;
+const unsigned int D3D10_SUBTEXEL_FRACTIONAL_BIT_COUNT = 6;
+const unsigned int D3D10_TEXEL_ADDRESS_RANGE_BIT_COUNT = 18;
+const unsigned int D3D10_UNBOUND_MEMORY_ACCESS_RESULT = 0;
+const unsigned int D3D10_VIEWPORT_AND_SCISSORRECT_MAX_INDEX = 15;
+const unsigned int D3D10_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE = 16;
+const unsigned int D3D10_VIEWPORT_BOUNDS_MAX = 16383;
+const int D3D10_VIEWPORT_BOUNDS_MIN = -16384;
+const unsigned int D3D10_VS_INPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_VS_INPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_VS_INPUT_REGISTER_COUNT = 16;
+const unsigned int D3D10_VS_INPUT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D10_VS_INPUT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D10_VS_OUTPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D10_VS_OUTPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_VS_OUTPUT_REGISTER_COUNT = 16;
+const unsigned int D3D10_WHQL_CONTEXT_COUNT_FOR_RESOURCE_LIMIT = 10;
+const unsigned int D3D10_WHQL_DRAWINDEXED_INDEX_COUNT_2_TO_EXP = 25;
+const unsigned int D3D10_WHQL_DRAW_VERTEX_COUNT_2_TO_EXP = 25;
+const unsigned int D3D_MAJOR_VERSION = 10;
+const unsigned int D3D_MINOR_VERSION = 0;
+const unsigned int D3D_SPEC_DATE_DAY = 8;
+const unsigned int D3D_SPEC_DATE_MONTH = 8;
+const unsigned int D3D_SPEC_DATE_YEAR = 2006;
+cpp_quote("#endif")
+
+const unsigned int D3D10_APPEND_ALIGNED_ELEMENT = 0xffffffff;
+const unsigned int _FACD3D10 = 0x87;
+const unsigned int _FACD3D10DEBUG = _FACD3D10 + 1;
+const unsigned int D3D10_FILTER_TYPE_MASK = 0x3;
+const unsigned int D3D10_SDK_VERSION = 29;
+
+cpp_quote("#define MAKE_D3D10_HRESULT(code) MAKE_HRESULT( 1, _FACD3D10, code)")
+cpp_quote("#define MAKE_D3D10_STATUS(code) MAKE_HRESULT( 0, _FACD3D10, code)")
+cpp_quote("#define D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS MAKE_D3D10_HRESULT(1)")
+cpp_quote("#define D3D10_ERROR_FILE_NOT_FOUND MAKE_D3D10_HRESULT(2)")
+
+typedef enum D3D10_FORMAT_SUPPORT
+{
+ D3D10_FORMAT_SUPPORT_BUFFER = 0x1,
+ D3D10_FORMAT_SUPPORT_IA_VERTEX_BUFFER = 0x2,
+ D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER = 0x4,
+ D3D10_FORMAT_SUPPORT_SO_BUFFER = 0x8,
+ D3D10_FORMAT_SUPPORT_TEXTURE1D = 0x10,
+ D3D10_FORMAT_SUPPORT_TEXTURE2D = 0x20,
+ D3D10_FORMAT_SUPPORT_TEXTURE3D = 0x40,
+ D3D10_FORMAT_SUPPORT_TEXTURECUBE = 0x80,
+ D3D10_FORMAT_SUPPORT_SHADER_LOAD = 0x100,
+ D3D10_FORMAT_SUPPORT_SHADER_SAMPLE = 0x200,
+ D3D10_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON = 0x400,
+ D3D10_FORMAT_SUPPORT_SHADER_SAMPLE_MONO_TEXT = 0x800,
+ D3D10_FORMAT_SUPPORT_MIP = 0x1000,
+ D3D10_FORMAT_SUPPORT_MIP_AUTOGEN = 0x2000,
+ D3D10_FORMAT_SUPPORT_RENDER_TARGET = 0x4000,
+ D3D10_FORMAT_SUPPORT_BLENDABLE = 0x8000,
+ D3D10_FORMAT_SUPPORT_DEPTH_STENCIL = 0x10000,
+ D3D10_FORMAT_SUPPORT_CPU_LOCKABLE = 0x20000,
+ D3D10_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE = 0x40000,
+ D3D10_FORMAT_SUPPORT_DISPLAY = 0x80000,
+ D3D10_FORMAT_SUPPORT_CAST_WITHIN_BIT_LAYOUT = 0x100000,
+ D3D10_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET = 0x200000,
+ D3D10_FORMAT_SUPPORT_MULTISAMPLE_LOAD = 0x400000,
+ D3D10_FORMAT_SUPPORT_SHADER_GATHER = 0x800000,
+} D3D10_FORMAT_SUPPORT;
+
+
+typedef enum D3D10_BLEND {
+ D3D10_BLEND_ZERO = 1,
+ D3D10_BLEND_ONE = 2,
+ D3D10_BLEND_SRC_COLOR = 3,
+ D3D10_BLEND_INV_SRC_COLOR = 4,
+ D3D10_BLEND_SRC_ALPHA = 5,
+ D3D10_BLEND_INV_SRC_ALPHA = 6,
+ D3D10_BLEND_DEST_ALPHA = 7,
+ D3D10_BLEND_INV_DEST_ALPHA = 8,
+ D3D10_BLEND_DEST_COLOR = 9,
+ D3D10_BLEND_INV_DEST_COLOR = 10,
+ D3D10_BLEND_SRC_ALPHA_SAT = 11,
+ D3D10_BLEND_BLEND_FACTOR = 14,
+ D3D10_BLEND_INV_BLEND_FACTOR = 15,
+ D3D10_BLEND_SRC1_COLOR = 16,
+ D3D10_BLEND_INV_SRC1_COLOR = 17,
+ D3D10_BLEND_SRC1_ALPHA = 18,
+ D3D10_BLEND_INV_SRC1_ALPHA = 19
+} D3D10_BLEND;
+
+typedef enum D3D10_BLEND_OP {
+ D3D10_BLEND_OP_ADD = 1,
+ D3D10_BLEND_OP_SUBTRACT,
+ D3D10_BLEND_OP_REV_SUBTRACT,
+ D3D10_BLEND_OP_MIN,
+ D3D10_BLEND_OP_MAX,
+} D3D10_BLEND_OP;
+
+typedef struct D3D10_BLEND_DESC {
+ BOOL AlphaToCoverageEnable;
+ BOOL BlendEnable[8];
+ D3D10_BLEND SrcBlend;
+ D3D10_BLEND DestBlend;
+ D3D10_BLEND_OP BlendOp;
+ D3D10_BLEND SrcBlendAlpha;
+ D3D10_BLEND DestBlendAlpha;
+ D3D10_BLEND_OP BlendOpAlpha;
+ UINT8 RenderTargetWriteMask[8];
+} D3D10_BLEND_DESC;
+
+typedef enum D3D10_DEPTH_WRITE_MASK {
+ D3D10_DEPTH_WRITE_MASK_ZERO,
+ D3D10_DEPTH_WRITE_MASK_ALL,
+} D3D10_DEPTH_WRITE_MASK;
+
+typedef enum D3D10_COMPARISON_FUNC {
+ D3D10_COMPARISON_NEVER = 1,
+ D3D10_COMPARISON_LESS,
+ D3D10_COMPARISON_EQUAL,
+ D3D10_COMPARISON_LESS_EQUAL,
+ D3D10_COMPARISON_GREATER,
+ D3D10_COMPARISON_NOT_EQUAL,
+ D3D10_COMPARISON_GREATER_EQUAL,
+ D3D10_COMPARISON_ALWAYS,
+} D3D10_COMPARISON_FUNC;
+
+typedef enum D3D10_STENCIL_OP {
+ D3D10_STENCIL_OP_KEEP = 1,
+ D3D10_STENCIL_OP_ZERO,
+ D3D10_STENCIL_OP_REPLACE,
+ D3D10_STENCIL_OP_INCR_SAT,
+ D3D10_STENCIL_OP_DECR_SAT,
+ D3D10_STENCIL_OP_INVERT,
+ D3D10_STENCIL_OP_INCR,
+ D3D10_STENCIL_OP_DECR,
+} D3D10_STENCIL_OP;
+
+typedef struct D3D10_DEPTH_STENCILOP_DESC {
+ D3D10_STENCIL_OP StencilFailOp;
+ D3D10_STENCIL_OP StencilDepthFailOp;
+ D3D10_STENCIL_OP StencilPassOp;
+ D3D10_COMPARISON_FUNC StencilFunc;
+} D3D10_DEPTH_STENCILOP_DESC;
+
+typedef struct D3D10_DEPTH_STENCIL_DESC {
+ BOOL DepthEnable;
+ D3D10_DEPTH_WRITE_MASK DepthWriteMask;
+ D3D10_COMPARISON_FUNC DepthFunc;
+ BOOL StencilEnable;
+ UINT8 StencilReadMask;
+ UINT8 StencilWriteMask;
+ D3D10_DEPTH_STENCILOP_DESC FrontFace;
+ D3D10_DEPTH_STENCILOP_DESC BackFace;
+} D3D10_DEPTH_STENCIL_DESC;
+
+typedef enum D3D10_FILL_MODE {
+ D3D10_FILL_WIREFRAME = 2,
+ D3D10_FILL_SOLID,
+} D3D10_FILL_MODE;
+
+typedef enum D3D10_CULL_MODE {
+ D3D10_CULL_NONE = 1,
+ D3D10_CULL_FRONT,
+ D3D10_CULL_BACK,
+} D3D10_CULL_MODE;
+
+typedef struct D3D10_RASTERIZER_DESC {
+ D3D10_FILL_MODE FillMode;
+ D3D10_CULL_MODE CullMode;
+ BOOL FrontCounterClockwise;
+ INT DepthBias;
+ FLOAT DepthBiasClamp;
+ FLOAT SlopeScaledDepthBias;
+ BOOL DepthClipEnable;
+ BOOL ScissorEnable;
+ BOOL MultisampleEnable;
+ BOOL AntialiasedLineEnable;
+} D3D10_RASTERIZER_DESC;
+
+typedef enum D3D10_FILTER {
+ D3D10_FILTER_MIN_MAG_MIP_POINT = 0,
+ D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR = 0x1,
+ D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x4,
+ D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR = 0x5,
+ D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10,
+ D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11,
+ D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14,
+ D3D10_FILTER_MIN_MAG_MIP_LINEAR = 0x15,
+ D3D10_FILTER_ANISOTROPIC = 0x55,
+ D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT = 0x80,
+ D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR = 0x81,
+ D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x84,
+ D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR = 0x85,
+ D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT = 0x90,
+ D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x91,
+ D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT = 0x94,
+ D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR = 0x95,
+ D3D10_FILTER_COMPARISON_ANISOTROPIC = 0xd5,
+ D3D10_FILTER_TEXT_1BIT = 0x80000000
+} D3D10_FILTER;
+
+typedef enum D3D10_TEXTURE_ADDRESS_MODE {
+ D3D10_TEXTURE_ADDRESS_WRAP = 1,
+ D3D10_TEXTURE_ADDRESS_MIRROR,
+ D3D10_TEXTURE_ADDRESS_CLAMP,
+ D3D10_TEXTURE_ADDRESS_BORDER,
+ D3D10_TEXTURE_ADDRESS_MIRROR_ONCE,
+} D3D10_TEXTURE_ADDRESS_MODE;
+
+typedef struct D3D10_SAMPLER_DESC {
+ D3D10_FILTER Filter;
+ D3D10_TEXTURE_ADDRESS_MODE AddressU;
+ D3D10_TEXTURE_ADDRESS_MODE AddressV;
+ D3D10_TEXTURE_ADDRESS_MODE AddressW;
+ FLOAT MipLODBias;
+ UINT MaxAnisotropy;
+ D3D10_COMPARISON_FUNC ComparisonFunc;
+ FLOAT BorderColor[4];
+ FLOAT MinLOD;
+ FLOAT MaxLOD;
+} D3D10_SAMPLER_DESC;
+
+typedef enum D3D10_COUNTER {
+ D3D10_COUNTER_GPU_IDLE,
+ D3D10_COUNTER_VERTEX_PROCESSING,
+ D3D10_COUNTER_GEOMETRY_PROCESSING,
+ D3D10_COUNTER_PIXEL_PROCESSING,
+ D3D10_COUNTER_OTHER_GPU_PROCESSING,
+ D3D10_COUNTER_HOST_ADAPTER_BANDWIDTH_UTILIZATION,
+ D3D10_COUNTER_LOCAL_VIDMEM_BANDWIDTH_UTILIZATION,
+ D3D10_COUNTER_VERTEX_THROUGHPUT_UTILIZATION,
+ D3D10_COUNTER_TRIANGLE_SETUP_THROUGHPUT_UTILIZATION,
+ D3D10_COUNTER_FILLRATE_THROUGHPUT_UTILIZATION,
+ D3D10_COUNTER_VS_MEMORY_LIMITED,
+ D3D10_COUNTER_VS_COMPUTATION_LIMITED,
+ D3D10_COUNTER_GS_MEMORY_LIMITED,
+ D3D10_COUNTER_GS_COMPUTATION_LIMITED,
+ D3D10_COUNTER_PS_MEMORY_LIMITED,
+ D3D10_COUNTER_PS_COMPUTATION_LIMITED,
+ D3D10_COUNTER_POST_TRANSFORM_CACHE_HIT_RATE,
+ D3D10_COUNTER_TEXTURE_CACHE_HIT_RATE,
+ D3D10_COUNTER_DEVICE_DEPENDENT_0 = 0x40000000
+} D3D10_COUNTER;
+
+typedef struct D3D10_COUNTER_DESC {
+ D3D10_COUNTER Counter;
+ UINT MiscFlags;
+} D3D10_COUNTER_DESC;
+
+typedef enum D3D10_COUNTER_TYPE {
+ D3D10_COUNTER_TYPE_FLOAT32,
+ D3D10_COUNTER_TYPE_UINT16,
+ D3D10_COUNTER_TYPE_UINT32,
+ D3D10_COUNTER_TYPE_UINT64,
+} D3D10_COUNTER_TYPE;
+
+typedef struct D3D10_COUNTER_INFO {
+ D3D10_COUNTER LastDeviceDependentCounter;
+ UINT NumSimultaneousCounters;
+ UINT8 NumDetectableParallelUnits;
+} D3D10_COUNTER_INFO;
+
+typedef enum D3D10_RESOURCE_DIMENSION {
+ D3D10_RESOURCE_DIMENSION_UNKNOWN,
+ D3D10_RESOURCE_DIMENSION_BUFFER,
+ D3D10_RESOURCE_DIMENSION_TEXTURE1D,
+ D3D10_RESOURCE_DIMENSION_TEXTURE2D,
+ D3D10_RESOURCE_DIMENSION_TEXTURE3D,
+} D3D10_RESOURCE_DIMENSION;
+
+typedef enum D3D10_USAGE {
+ D3D10_USAGE_DEFAULT,
+ D3D10_USAGE_IMMUTABLE,
+ D3D10_USAGE_DYNAMIC,
+ D3D10_USAGE_STAGING,
+} D3D10_USAGE;
+
+typedef struct D3D10_BUFFER_DESC {
+ UINT ByteWidth;
+ D3D10_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+} D3D10_BUFFER_DESC;
+
+typedef enum D3D10_MAP {
+ D3D10_MAP_READ = 1,
+ D3D10_MAP_WRITE,
+ D3D10_MAP_READ_WRITE,
+ D3D10_MAP_WRITE_DISCARD,
+ D3D10_MAP_WRITE_NO_OVERWRITE,
+} D3D10_MAP;
+
+typedef struct D3D10_TEXTURE1D_DESC {
+ UINT Width;
+ UINT MipLevels;
+ UINT ArraySize;
+ DXGI_FORMAT Format;
+ D3D10_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+} D3D10_TEXTURE1D_DESC;
+
+typedef struct D3D10_TEXTURE2D_DESC {
+ UINT Width;
+ UINT Height;
+ UINT MipLevels;
+ UINT ArraySize;
+ DXGI_FORMAT Format;
+ DXGI_SAMPLE_DESC SampleDesc;
+ D3D10_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+} D3D10_TEXTURE2D_DESC;
+
+typedef struct D3D10_TEXTURE3D_DESC {
+ UINT Width;
+ UINT Height;
+ UINT Depth;
+ UINT MipLevels;
+ DXGI_FORMAT Format;
+ D3D10_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+} D3D10_TEXTURE3D_DESC;
+
+typedef enum D3D10_DSV_DIMENSION
+{
+ D3D10_DSV_DIMENSION_UNKNOWN,
+ D3D10_DSV_DIMENSION_TEXTURE1D,
+ D3D10_DSV_DIMENSION_TEXTURE1DARRAY,
+ D3D10_DSV_DIMENSION_TEXTURE2D,
+ D3D10_DSV_DIMENSION_TEXTURE2DARRAY,
+ D3D10_DSV_DIMENSION_TEXTURE2DMS,
+ D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY,
+} D3D10_DSV_DIMENSION;
+
+typedef struct D3D10_TEX1D_DSV {
+ UINT MipSlice;
+} D3D10_TEX1D_DSV;
+
+typedef struct D3D10_TEX1D_ARRAY_DSV {
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX1D_ARRAY_DSV;
+
+typedef struct D3D10_TEX2D_DSV {
+ UINT MipSlice;
+} D3D10_TEX2D_DSV;
+
+typedef struct D3D10_TEX2D_ARRAY_DSV {
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX2D_ARRAY_DSV;
+
+typedef struct D3D10_TEX2DMS_DSV {
+ UINT UnusedField_NothingToDefine;
+} D3D10_TEX2DMS_DSV;
+
+typedef struct D3D10_TEX2DMS_ARRAY_DSV {
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX2DMS_ARRAY_DSV;
+
+typedef struct D3D10_DEPTH_STENCIL_VIEW_DESC {
+ DXGI_FORMAT Format;
+ D3D10_DSV_DIMENSION ViewDimension;
+ union {
+ D3D10_TEX1D_DSV Texture1D;
+ D3D10_TEX1D_ARRAY_DSV Texture1DArray;
+ D3D10_TEX2D_DSV Texture2D;
+ D3D10_TEX2D_ARRAY_DSV Texture2DArray;
+ D3D10_TEX2DMS_DSV Texture2DMS;
+ D3D10_TEX2DMS_ARRAY_DSV Texture2DMSArray;
+ } DUMMYUNIONNAME;
+} D3D10_DEPTH_STENCIL_VIEW_DESC;
+
+typedef enum D3D10_RTV_DIMENSION {
+ D3D10_RTV_DIMENSION_UNKNOWN,
+ D3D10_RTV_DIMENSION_BUFFER,
+ D3D10_RTV_DIMENSION_TEXTURE1D,
+ D3D10_RTV_DIMENSION_TEXTURE1DARRAY,
+ D3D10_RTV_DIMENSION_TEXTURE2D,
+ D3D10_RTV_DIMENSION_TEXTURE2DARRAY,
+ D3D10_RTV_DIMENSION_TEXTURE2DMS,
+ D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY,
+ D3D10_RTV_DIMENSION_TEXTURE3D,
+} D3D10_RTV_DIMENSION;
+
+typedef struct D3D10_BUFFER_RTV {
+ UINT ElementOffset;
+ UINT ElementWidth;
+} D3D10_BUFFER_RTV;
+
+typedef struct D3D10_TEX1D_RTV {
+ UINT MipSlice;
+} D3D10_TEX1D_RTV;
+
+typedef struct D3D10_TEX1D_ARRAY_RTV {
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX1D_ARRAY_RTV;
+
+typedef struct D3D10_TEX2D_RTV {
+ UINT MipSlice;
+} D3D10_TEX2D_RTV;
+
+typedef struct D3D10_TEX2D_ARRAY_RTV {
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX2D_ARRAY_RTV;
+
+typedef struct D3D10_TEX2DMS_RTV {
+ UINT UnusedField_NothingToDefine;
+} D3D10_TEX2DMS_RTV;
+
+typedef struct D3D10_TEX2DMS_ARRAY_RTV {
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX2DMS_ARRAY_RTV;
+
+typedef struct D3D10_TEX3D_RTV {
+ UINT MipSlice;
+ UINT FirstWSlice;
+ UINT WSize;
+} D3D10_TEX3D_RTV;
+
+typedef struct D3D10_RENDER_TARGET_VIEW_DESC {
+ DXGI_FORMAT Format;
+ D3D10_RTV_DIMENSION ViewDimension;
+ union {
+ D3D10_BUFFER_RTV Buffer;
+ D3D10_TEX1D_RTV Texture1D;
+ D3D10_TEX1D_ARRAY_RTV Texture1DArray;
+ D3D10_TEX2D_RTV Texture2D;
+ D3D10_TEX2D_ARRAY_RTV Texture2DArray;
+ D3D10_TEX2DMS_RTV Texture2DMS;
+ D3D10_TEX2DMS_ARRAY_RTV Texture2DMSArray;
+ D3D10_TEX3D_RTV Texture3D;
+ } DUMMYUNIONNAME;
+} D3D10_RENDER_TARGET_VIEW_DESC;
+
+typedef D3D_SRV_DIMENSION D3D10_SRV_DIMENSION;
+
+typedef struct D3D10_BUFFER_SRV {
+ UINT ElementOffset;
+ UINT ElementWidth;
+} D3D10_BUFFER_SRV;
+
+typedef struct D3D10_TEX1D_SRV {
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D10_TEX1D_SRV;
+
+typedef struct D3D10_TEX1D_ARRAY_SRV {
+ UINT MostDetailedMip;
+ UINT MipLevels;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX1D_ARRAY_SRV;
+
+typedef struct D3D10_TEX2D_SRV {
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D10_TEX2D_SRV;
+
+typedef struct D3D10_TEX2D_ARRAY_SRV {
+ UINT MostDetailedMip;
+ UINT MipLevels;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX2D_ARRAY_SRV;
+
+typedef struct D3D10_TEX2DMS_SRV {
+ UINT UnusedField_NothingToDefine;
+} D3D10_TEX2DMS_SRV;
+
+typedef struct D3D10_TEX2DMS_ARRAY_SRV {
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D10_TEX2DMS_ARRAY_SRV;
+
+typedef struct D3D10_TEX3D_SRV {
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D10_TEX3D_SRV;
+
+typedef struct D3D10_TEXCUBE_SRV {
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D10_TEXCUBE_SRV;
+
+typedef struct D3D10_SHADER_RESOURCE_VIEW_DESC {
+ DXGI_FORMAT Format;
+ D3D10_SRV_DIMENSION ViewDimension;
+ union {
+ D3D10_BUFFER_SRV Buffer;
+ D3D10_TEX1D_SRV Texture1D;
+ D3D10_TEX1D_ARRAY_SRV Texture1DArray;
+ D3D10_TEX2D_SRV Texture2D;
+ D3D10_TEX2D_ARRAY_SRV Texture2DArray;
+ D3D10_TEX2DMS_SRV Texture2DMS;
+ D3D10_TEX2DMS_ARRAY_SRV Texture2DMSArray;
+ D3D10_TEX3D_SRV Texture3D;
+ D3D10_TEXCUBE_SRV TextureCube;
+ } DUMMYUNIONNAME;
+} D3D10_SHADER_RESOURCE_VIEW_DESC;
+
+typedef struct D3D10_BOX {
+ UINT left;
+ UINT top;
+ UINT front;
+ UINT right;
+ UINT bottom;
+ UINT back;
+} D3D10_BOX;
+
+typedef struct D3D10_SUBRESOURCE_DATA {
+ const void *pSysMem;
+ UINT SysMemPitch;
+ UINT SysMemSlicePitch;
+} D3D10_SUBRESOURCE_DATA;
+
+typedef struct D3D10_SO_DECLARATION_ENTRY {
+ LPCSTR SemanticName;
+ UINT SemanticIndex;
+ BYTE StartComponent;
+ BYTE ComponentCount;
+ BYTE OutputSlot;
+} D3D10_SO_DECLARATION_ENTRY;
+
+typedef enum D3D10_INPUT_CLASSIFICATION {
+ D3D10_INPUT_PER_VERTEX_DATA,
+ D3D10_INPUT_PER_INSTANCE_DATA,
+} D3D10_INPUT_CLASSIFICATION;
+
+typedef struct D3D10_INPUT_ELEMENT_DESC {
+ LPCSTR SemanticName;
+ UINT SemanticIndex;
+ DXGI_FORMAT Format;
+ UINT InputSlot;
+ UINT AlignedByteOffset;
+ D3D10_INPUT_CLASSIFICATION InputSlotClass;
+ UINT InstanceDataStepRate;
+} D3D10_INPUT_ELEMENT_DESC;
+
+typedef enum D3D10_QUERY {
+ D3D10_QUERY_EVENT,
+ D3D10_QUERY_OCCLUSION,
+ D3D10_QUERY_TIMESTAMP,
+ D3D10_QUERY_TIMESTAMP_DISJOINT,
+ D3D10_QUERY_PIPELINE_STATISTICS,
+ D3D10_QUERY_OCCLUSION_PREDICATE,
+ D3D10_QUERY_SO_STATISTICS,
+ D3D10_QUERY_SO_OVERFLOW_PREDICATE,
+} D3D10_QUERY;
+
+typedef struct D3D10_QUERY_DESC {
+ D3D10_QUERY Query;
+ UINT MiscFlags;
+} D3D10_QUERY_DESC;
+
+typedef D3D_PRIMITIVE_TOPOLOGY D3D10_PRIMITIVE_TOPOLOGY;
+
+typedef RECT D3D10_RECT;
+
+typedef struct D3D10_VIEWPORT {
+ INT TopLeftX;
+ INT TopLeftY;
+ UINT Width;
+ UINT Height;
+ FLOAT MinDepth;
+ FLOAT MaxDepth;
+} D3D10_VIEWPORT;
+
+typedef struct D3D10_MAPPED_TEXTURE2D {
+ void *pData;
+ UINT RowPitch;
+} D3D10_MAPPED_TEXTURE2D;
+
+typedef struct D3D10_MAPPED_TEXTURE3D {
+ void *pData;
+ UINT RowPitch;
+ UINT DepthPitch;
+} D3D10_MAPPED_TEXTURE3D;
+
+typedef enum D3D10_BIND_FLAG {
+ D3D10_BIND_VERTEX_BUFFER = 0x1,
+ D3D10_BIND_INDEX_BUFFER = 0x2,
+ D3D10_BIND_CONSTANT_BUFFER = 0x4,
+ D3D10_BIND_SHADER_RESOURCE = 0x8,
+ D3D10_BIND_STREAM_OUTPUT = 0x10,
+ D3D10_BIND_RENDER_TARGET = 0x20,
+ D3D10_BIND_DEPTH_STENCIL = 0x40
+} D3D10_BIND_FLAG;
+
+typedef enum D3D10_CPU_ACCESS_FLAG {
+ D3D10_CPU_ACCESS_WRITE = 0x10000,
+ D3D10_CPU_ACCESS_READ = 0x20000
+} D3D10_CPU_ACCESS_FLAG;
+
+typedef enum D3D10_RESOURCE_MISC_FLAG {
+ D3D10_RESOURCE_MISC_GENERATE_MIPS = 0x1,
+ D3D10_RESOURCE_MISC_SHARED = 0x2,
+ D3D10_RESOURCE_MISC_TEXTURECUBE = 0x4,
+ D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX = 0x10L,
+ D3D10_RESOURCE_MISC_GDI_COMPATIBLE = 0x20L
+} D3D10_RESOURCE_MISC_FLAG;
+
+typedef enum D3D10_MAP_FLAG {
+ D3D10_MAP_FLAG_DO_NOT_WAIT = 0x100000,
+} D3D10_MAP_FLAG;
+
+typedef enum D3D10_CLEAR_FLAG {
+ D3D10_CLEAR_DEPTH = 0x1,
+ D3D10_CLEAR_STENCIL = 0x2
+} D3D10_CLEAR_FLAG;
+
+typedef enum D3D10_COLOR_WRITE_ENABLE {
+ D3D10_COLOR_WRITE_ENABLE_RED = 0x1,
+ D3D10_COLOR_WRITE_ENABLE_GREEN = 0x2,
+ D3D10_COLOR_WRITE_ENABLE_BLUE = 0x4,
+ D3D10_COLOR_WRITE_ENABLE_ALPHA = 0x8,
+ D3D10_COLOR_WRITE_ENABLE_ALL = (D3D10_COLOR_WRITE_ENABLE_RED | D3D10_COLOR_WRITE_ENABLE_GREEN |
+ D3D10_COLOR_WRITE_ENABLE_BLUE | D3D10_COLOR_WRITE_ENABLE_ALPHA)
+} D3D10_COLOR_WRITE_ENABLE;
+
+typedef enum D3D10_TEXTURECUBE_FACE {
+ D3D10_TEXTURECUBE_FACE_POSITIVE_X,
+ D3D10_TEXTURECUBE_FACE_NEGATIVE_X,
+ D3D10_TEXTURECUBE_FACE_POSITIVE_Y,
+ D3D10_TEXTURECUBE_FACE_NEGATIVE_Y,
+ D3D10_TEXTURECUBE_FACE_POSITIVE_Z,
+ D3D10_TEXTURECUBE_FACE_NEGATIVE_Z,
+} D3D10_TEXTURECUBE_FACE;
+
+typedef enum D3D10_ASYNC_GETDATA_FLAG {
+ D3D10_ASYNC_GETDATA_DONOTFLUSH = 0x1,
+} D3D10_ASYNC_GETDATA_FLAG;
+
+typedef enum D3D10_FILTER_TYPE {
+ D3D10_FILTER_TYPE_POINT,
+ D3D10_FILTER_TYPE_LINEAR
+} D3D10_FILTER_TYPE;
+
+typedef enum D3D10_QUERY_MISC_FLAG {
+ D3D10_QUERY_MISC_PREDICATEHINT = 0x1
+} D3D10_QUERY_MISC_FLAG;
+
+typedef struct D3D10_QUERY_DATA_TIMESTAMP_DISJOINT {
+ UINT64 Frequency;
+ BOOL Disjoint;
+} D3D10_QUERY_DATA_TIMESTAMP_DISJOINT;
+
+typedef struct D3D10_QUERY_DATA_PIPELINE_STATISTICS {
+ UINT64 IAVertices;
+ UINT64 IAPrimitives;
+ UINT64 VSInvocations;
+ UINT64 GSInvocations;
+ UINT64 GSPrimitives;
+ UINT64 CInvocations;
+ UINT64 CPrimitives;
+ UINT64 PSInvocations;
+} D3D10_QUERY_DATA_PIPELINE_STATISTICS;
+
+typedef struct D3D10_QUERY_DATA_SO_STATISTICS {
+ UINT64 NumPrimitivesWritten;
+ UINT64 PrimitivesStorageNeeded;
+} D3D10_QUERY_DATA_SO_STATISTICS;
+
+typedef enum D3D10_CREATE_DEVICE_FLAG {
+ D3D10_CREATE_DEVICE_SINGLETHREADED = 0x1,
+ D3D10_CREATE_DEVICE_DEBUG = 0x2,
+ D3D10_CREATE_DEVICE_SWITCH_TO_REF = 0x4,
+ D3D10_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS = 0x8
+} D3D10_CREATE_DEVICE_FLAG;
+
+/* Core */
+
+interface ID3D10Device;
+
+[
+ object,
+ local,
+ uuid(9b7e4c00-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10DeviceChild : IUnknown
+{
+ void GetDevice(
+ [out] ID3D10Device **ppDevice);
+ HRESULT GetPrivateData(
+ [in] REFGUID guid,
+ [in, out] UINT *pDataSize,
+ [out] void *pData);
+ HRESULT SetPrivateData(
+ [in] REFGUID guid,
+ [in] UINT DataSize,
+ [in] const void *pData);
+ HRESULT SetPrivateDataInterface(
+ [in] REFGUID guid,
+ [in] const IUnknown *pData);
+}
+
+/* Resource */
+
+[
+ object,
+ local,
+ uuid(9b7e4c01-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Resource : ID3D10DeviceChild
+{
+ void GetType(
+ [out] D3D10_RESOURCE_DIMENSION *rType);
+ void SetEvictionPriority(
+ [in] UINT EvictionPriority);
+ UINT GetEvictionPriority();
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c02-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Buffer : ID3D10Resource
+{
+ HRESULT Map(
+ [in] D3D10_MAP MapType,
+ [in] UINT MapFlags,
+ [out] void **ppData);
+ void Unmap();
+ void GetDesc(
+ [out] D3D10_BUFFER_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c03-342c-4106-a19f-4f2704f689F0)
+]
+interface ID3D10Texture1D : ID3D10Resource
+{
+ HRESULT Map(
+ [in] UINT Subresource,
+ [in] D3D10_MAP MapType,
+ [in] UINT MapFlags,
+ [out] void **ppData);
+ void Unmap(
+ [in] UINT Subresource);
+ void GetDesc(
+ [out] D3D10_TEXTURE1D_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c04-342c-4106-a19f-4f2704f689F0)
+]
+interface ID3D10Texture2D : ID3D10Resource
+{
+ HRESULT Map(
+ [in] UINT Subresource,
+ [in] D3D10_MAP MapType,
+ [in] UINT MapFlags,
+ [out] D3D10_MAPPED_TEXTURE2D *pMappedTex2D);
+ void Unmap(
+ [in] UINT Subresource);
+ void GetDesc(
+ [out] D3D10_TEXTURE2D_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c05-342c-4106-a19f-4f2704f689F0)
+]
+interface ID3D10Texture3D : ID3D10Resource
+{
+ HRESULT Map(
+ [in] UINT Subresource,
+ [in] D3D10_MAP MapType,
+ [in] UINT MapFlags,
+ [out] D3D10_MAPPED_TEXTURE3D *pMappedTex3D);
+ void Unmap(
+ [in] UINT Subresource);
+ void GetDesc(
+ [out] D3D10_TEXTURE3D_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(c902b03f-60a7-49ba-9936-2a3ab37a7e33)
+]
+interface ID3D10View : ID3D10DeviceChild
+{
+ void GetResource(
+ [out] ID3D10Resource **ppResource);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c09-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10DepthStencilView : ID3D10View
+{
+ void GetDesc(
+ [out] D3D10_DEPTH_STENCIL_VIEW_DESC *pDesc);
+}
+
+
+[
+ object,
+ local,
+ uuid(9b7e4c08-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10RenderTargetView : ID3D10View
+{
+ void GetDesc(
+ [out] D3D10_RENDER_TARGET_VIEW_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c07-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10ShaderResourceView : ID3D10View
+{
+ void GetDesc(
+ [out] D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc);
+}
+
+/* Resource End */
+
+[
+ object,
+ local,
+ uuid(edad8d19-8a35-4d6d-8566-2ea276cde161)
+]
+interface ID3D10BlendState : ID3D10DeviceChild
+{
+ void GetDesc(
+ [out] D3D10_BLEND_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(2b4b1cc8-a4ad-41f8-8322-ca86fc3ec675)
+]
+interface ID3D10DepthStencilState : ID3D10DeviceChild
+{
+ void GetDesc(
+ [out] D3D10_DEPTH_STENCIL_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(6316be88-54cd-4040-ab44-20461bc81f68)
+]
+interface ID3D10GeometryShader : ID3D10DeviceChild
+{
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c0b-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10InputLayout : ID3D10DeviceChild
+{
+}
+
+[
+ object,
+ local,
+ uuid(4968b601-9d00-4cde-8346-8e7f675819b6)
+]
+interface ID3D10PixelShader : ID3D10DeviceChild
+{
+}
+
+[
+ object,
+ local,
+ uuid(a2a07292-89af-4345-be2e-c53d9fbb6e9f)
+]
+interface ID3D10RasterizerState : ID3D10DeviceChild
+{
+ void GetDesc(
+ [out] D3D10_RASTERIZER_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c0c-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10SamplerState : ID3D10DeviceChild
+{
+ void GetDesc(
+ [out] D3D10_SAMPLER_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c0a-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10VertexShader : ID3D10DeviceChild
+{
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c0d-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Asynchronous : ID3D10DeviceChild
+{
+ void Begin();
+ void End();
+ HRESULT GetData(
+ [out] void *pData,
+ [in] UINT DataSize,
+ [in] UINT GetDataFlags);
+ UINT GetDataSize();
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c11-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Counter : ID3D10Asynchronous
+{
+ void GetDesc(
+ [out] D3D10_COUNTER_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4C0e-342C-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Query : ID3D10Asynchronous
+{
+ void GetDesc(
+ [out] D3D10_QUERY_DESC *pDesc);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c10-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Predicate : ID3D10Query
+{
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4c0f-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Device : IUnknown
+{
+ void VSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D10Buffer *const *ppConstantBuffers);
+ void PSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D10ShaderResourceView *const *ppShaderResourceViews);
+ void PSSetShader(
+ [in] ID3D10PixelShader *pPixelShader);
+ void PSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in]ID3D10SamplerState *const *ppSamplers);
+ void VSSetShader(
+ [in] ID3D10VertexShader *pVertexShader);
+ void DrawIndexed(
+ [in] UINT IndexCount,
+ [in] UINT StartIndexLocation,
+ [in] INT BaseVertexLocation);
+ void Draw(
+ [in] UINT VertexCount,
+ [in] UINT StartVertexLocation);
+ void PSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D10Buffer *const *ppConstantBuffers);
+ void IASetInputLayout(
+ [in] ID3D10InputLayout *pInputLayout);
+ void IASetVertexBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D10Buffer *const *ppVertexBuffers,
+ [in] const UINT *pStrides,
+ [in] const UINT *pOffsets);
+ void IASetIndexBuffer(
+ [in] ID3D10Buffer *pIndexBuffer,
+ [in] DXGI_FORMAT Format,
+ [in] UINT Offset);
+ void DrawIndexedInstanced(
+ [in] UINT IndexCountPerInstance,
+ [in] UINT InstanceCount,
+ [in] UINT StartIndexLocation,
+ [in] INT BaseVertexLocation,
+ [in] UINT StartInstanceLocation);
+ void DrawInstanced(
+ [in] UINT VertexCountPerInstance,
+ [in] UINT InstanceCount,
+ [in] UINT StartVertexLocation,
+ [in] UINT StartInstanceLocation);
+ void GSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D10Buffer *const *ppConstantBuffers);
+ void GSSetShader(
+ [in] ID3D10GeometryShader *pShader);
+ void IASetPrimitiveTopology(
+ [in] D3D10_PRIMITIVE_TOPOLOGY Topology);
+ void VSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D10ShaderResourceView *const *ppShaderResourceViews);
+ void VSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D10SamplerState *const *ppSamplers);
+ void SetPredication(
+ [in] ID3D10Predicate *pPredicate,
+ [in] BOOL PredicateValue);
+ void GSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D10ShaderResourceView * const *ppShaderResourceViews);
+ void GSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D10SamplerState *const *ppSamplers);
+ void OMSetRenderTargets(
+ [in] UINT NumViews,
+ [in] ID3D10RenderTargetView *const *ppRenderTargetViews,
+ [in] ID3D10DepthStencilView *pDepthStencilView);
+ void OMSetBlendState(
+ [in] ID3D10BlendState *pBlendState,
+ [in] const FLOAT BlendFactor[4],
+ [in] UINT SampleMask);
+ void OMSetDepthStencilState(
+ [in] ID3D10DepthStencilState *pDepthStencilState,
+ [in] UINT StencilRef);
+ void SOSetTargets(
+ [in] UINT NumBuffers,
+ [in] ID3D10Buffer *const *ppSOTargets,
+ [in] const UINT *pOffsets);
+ void DrawAuto();
+ void RSSetState(
+ [in] ID3D10RasterizerState *pRasterizerState);
+ void RSSetViewports(
+ [in] UINT NumViewports,
+ [in] const D3D10_VIEWPORT *pViewports);
+ void RSSetScissorRects(
+ [in] UINT NumRects,
+ [in] const D3D10_RECT *pRects);
+ void CopySubresourceRegion(
+ [in] ID3D10Resource *pDstResource,
+ [in] UINT DstSubresource,
+ [in] UINT DstX,
+ [in] UINT DstY,
+ [in] UINT DstZ,
+ [in] ID3D10Resource *pSrcResource,
+ [in] UINT SrcSubresource,
+ [in] const D3D10_BOX *pSrcBox);
+ void CopyResource(
+ [in] ID3D10Resource *pDstResource,
+ [in] ID3D10Resource *pSrcResource);
+ void UpdateSubresource(
+ [in] ID3D10Resource *pDstResource,
+ [in] UINT DstSubresource,
+ [in] const D3D10_BOX *pDstBox,
+ [in] const void *pSrcData,
+ [in] UINT SrcRowPitch,
+ [in] UINT SrcDepthPitch);
+ void ClearRenderTargetView(
+ [in] ID3D10RenderTargetView *pRenderTargetView,
+ [in] const FLOAT ColorRGBA[4]);
+ void ClearDepthStencilView(
+ [in] ID3D10DepthStencilView *pDepthStencilView,
+ [in] UINT ClearFlags,
+ [in] FLOAT Depth,
+ [in] UINT8 Stencil);
+ void GenerateMips(
+ [in] ID3D10ShaderResourceView *pShaderResourceView);
+ void ResolveSubresource(
+ [in] ID3D10Resource *pDstResource,
+ [in] UINT DstSubresource,
+ [in] ID3D10Resource *pSrcResource,
+ [in] UINT SrcSubresource,
+ [in] DXGI_FORMAT Format);
+ void VSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D10Buffer **ppConstantBuffers);
+ void PSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D10ShaderResourceView **ppShaderResourceViews);
+ void PSGetShader(
+ [out] ID3D10PixelShader **ppPixelShader);
+ void PSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D10SamplerState **ppSamplers);
+ void VSGetShader(
+ [out] ID3D10VertexShader **ppVertexShader);
+ void PSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D10Buffer **ppConstantBuffers);
+ void IAGetInputLayout(
+ [out] ID3D10InputLayout **ppInputLayout);
+ void IAGetVertexBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D10Buffer **ppVertexBuffers,
+ [out] UINT *pStrides,
+ [out] UINT *pOffsets);
+ void IAGetIndexBuffer(
+ [out] ID3D10Buffer **pIndexBuffer,
+ [out] DXGI_FORMAT *Format,
+ [out] UINT *Offset);
+ void GSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D10Buffer **ppConstantBuffers);
+ void GSGetShader(
+ [out] ID3D10GeometryShader **ppGeometryShader);
+ void IAGetPrimitiveTopology(
+ [out] D3D10_PRIMITIVE_TOPOLOGY *pTopology);
+ void VSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D10ShaderResourceView **ppShaderResourceViews);
+ void VSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D10SamplerState **ppSamplers);
+ void GetPredication(
+ [out] ID3D10Predicate **ppPredicate,
+ [out] BOOL *pPredicateValue);
+ void GSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D10ShaderResourceView **ppShaderResourceViews);
+ void GSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D10SamplerState **ppSamplers);
+ void OMGetRenderTargets(
+ [in] UINT NumViews,
+ [out] ID3D10RenderTargetView **ppRenderTargetViews,
+ [out] ID3D10DepthStencilView **ppDepthStencilView);
+ void OMGetBlendState(
+ [out] ID3D10BlendState **ppBlendState,
+ [out] FLOAT BlendFactor[4],
+ [out] UINT *pSampleMask);
+ void OMGetDepthStencilState(
+ [out] ID3D10DepthStencilState **ppDepthStencilState,
+ [out] UINT *pStencilRef);
+ void SOGetTargets(
+ [in] UINT NumBuffers,
+ [out] ID3D10Buffer **ppSOTargets,
+ [out] UINT *pOffsets);
+ void RSGetState(
+ [out] ID3D10RasterizerState **ppRasterizerState);
+ void RSGetViewports(
+ [in, out] UINT *NumViewports,
+ [out] D3D10_VIEWPORT *pViewports);
+ void RSGetScissorRects(
+ [in, out] UINT *NumRects,
+ [out] D3D10_RECT *pRects);
+ HRESULT GetDeviceRemovedReason();
+ HRESULT SetExceptionMode(
+ [in] UINT RaiseFlags);
+ UINT GetExceptionMode();
+ HRESULT GetPrivateData(
+ [in] REFGUID guid,
+ [in, out] UINT *pDataSize,
+ [out] void *pData);
+ HRESULT SetPrivateData(
+ [in] REFGUID guid,
+ [in] UINT DataSize,
+ [in] const void *pData);
+ HRESULT SetPrivateDataInterface(
+ [in] REFGUID guid,
+ [in] const IUnknown *pData);
+ void ClearState();
+ void Flush();
+ HRESULT CreateBuffer(
+ [in] const D3D10_BUFFER_DESC *pDesc,
+ [in] const D3D10_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D10Buffer **ppBuffer);
+ HRESULT CreateTexture1D(
+ [in] const D3D10_TEXTURE1D_DESC *pDesc,
+ [in] const D3D10_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D10Texture1D **ppTexture1D);
+ HRESULT CreateTexture2D(
+ [in] const D3D10_TEXTURE2D_DESC *pDesc,
+ [in] const D3D10_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D10Texture2D **ppTexture2D);
+ HRESULT CreateTexture3D(
+ [in] const D3D10_TEXTURE3D_DESC *pDesc,
+ [in] const D3D10_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D10Texture3D **ppTexture3D);
+ HRESULT CreateShaderResourceView(
+ [in] ID3D10Resource *pResource,
+ [in] const D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc,
+ [out] ID3D10ShaderResourceView **ppSRView);
+ HRESULT CreateRenderTargetView(
+ [in] ID3D10Resource *pResource,
+ [in] const D3D10_RENDER_TARGET_VIEW_DESC *pDesc,
+ [out] ID3D10RenderTargetView **ppRTView);
+ HRESULT CreateDepthStencilView(
+ [in] ID3D10Resource *pResource,
+ [in] const D3D10_DEPTH_STENCIL_VIEW_DESC *pDesc,
+ [out] ID3D10DepthStencilView **ppDepthStencilView);
+ HRESULT CreateInputLayout(
+ [in] const D3D10_INPUT_ELEMENT_DESC *pInputElementDescs,
+ [in] UINT NumElements,
+ [in] const void *pShaderBytecodeWithInputSignature,
+ [in] SIZE_T BytecodeLength,
+ [out] ID3D10InputLayout **ppInputLayout);
+ HRESULT CreateVertexShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [out] ID3D10VertexShader **ppVertexShader);
+ HRESULT CreateGeometryShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [out] ID3D10GeometryShader **ppGeometryShader);
+ HRESULT CreateGeometryShaderWithStreamOutput(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] const D3D10_SO_DECLARATION_ENTRY *pSODeclaration,
+ [in] UINT NumEntries,
+ [in] UINT OutputStreamStride,
+ [out] ID3D10GeometryShader **ppGeometryShader);
+ HRESULT CreatePixelShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [out] ID3D10PixelShader **ppPixelShader);
+ HRESULT CreateBlendState(
+ [in] const D3D10_BLEND_DESC *pBlendStateDesc,
+ [out] ID3D10BlendState **ppBlendState);
+ HRESULT CreateDepthStencilState(
+ [in] const D3D10_DEPTH_STENCIL_DESC *pDepthStencilDesc,
+ [out] ID3D10DepthStencilState **ppDepthStencilState);
+ HRESULT CreateRasterizerState(
+ [in] const D3D10_RASTERIZER_DESC *pRasterizerDesc,
+ [out] ID3D10RasterizerState **ppRasterizerState);
+ HRESULT CreateSamplerState(
+ [in] const D3D10_SAMPLER_DESC *pSamplerDesc,
+ [out] ID3D10SamplerState **ppSamplerState);
+ HRESULT CreateQuery(
+ [in] const D3D10_QUERY_DESC *pQueryDesc,
+ [out] ID3D10Query **ppQuery);
+ HRESULT CreatePredicate(
+ [in] const D3D10_QUERY_DESC *pPredicateDesc,
+ [out] ID3D10Predicate **ppPredicate);
+ HRESULT CreateCounter(
+ [in] const D3D10_COUNTER_DESC *pCounterDesc,
+ [out] ID3D10Counter **ppCounter);
+ HRESULT CheckFormatSupport(
+ [in] DXGI_FORMAT Format,
+ [out] UINT *pFormatSupport);
+ HRESULT CheckMultisampleQualityLevels(
+ [in] DXGI_FORMAT Format,
+ [in] UINT SampleCount,
+ [out] UINT *pNumQualityLevels);
+ void CheckCounterInfo(
+ [out] D3D10_COUNTER_INFO *pCounterInfo);
+ HRESULT CheckCounter(
+ [in] const D3D10_COUNTER_DESC *pDesc,
+ [out] D3D10_COUNTER_TYPE *pType,
+ [out] UINT *pActiveCounters,
+ [out] LPSTR szName,
+ [in, out] UINT *pNameLength,
+ [out] LPSTR szUnits,
+ [in, out] UINT *pUnitsLength,
+ [out] LPSTR szDescription,
+ [in, out] UINT *pDescriptionLength);
+ UINT GetCreationFlags();
+ HRESULT OpenSharedResource(
+ [in] HANDLE hResource,
+ [in] REFIID ReturnedInterface,
+ [out] void **ppResource);
+ void SetTextFilterSize(
+ [in] UINT Width,
+ [in] UINT Height);
+ void GetTextFilterSize(
+ [out] UINT *pWidth,
+ [out] UINT *pHeight);
+}
+
+[
+ object,
+ local,
+ uuid(9b7e4e00-342c-4106-a19f-4f2704f689f0)
+]
+interface ID3D10Multithread : IUnknown
+{
+ void Enter();
+ void Leave();
+ BOOL SetMultithreadProtected(
+ [in] BOOL bMTProtect);
+ BOOL GetMultithreadProtected();
+}
+
+cpp_quote("#include \"d3d10misc.h\"")
+cpp_quote("#include \"d3d10shader.h\"")
+cpp_quote("#include \"d3d10effect.h\"")
+/* TODO: Include "d310sdklayers.h" as soon as it exists */
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3d10_1.idl b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10_1.idl
new file mode 100644
index 0000000..b507e09
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10_1.idl
@@ -0,0 +1,191 @@
+/**************************************************************************
+ *
+ * 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 "oaidl.idl";
+import "ocidl.idl";
+import "d3d10.idl";
+import "d3dcommon.idl";
+
+const unsigned int D3D10_1_SDK_VERSION = 0x20;
+
+cpp_quote("#ifndef _D3D10_1_CONSTANTS")
+cpp_quote("#define _D3D10_1_CONSTANTS")
+const unsigned int D3D10_1_DEFAULT_SAMPLE_MASK = 0xffffffff;
+const float D3D10_1_FLOAT16_FUSED_TOLERANCE_IN_ULP = 0.6;
+const float D3D10_1_FLOAT32_TO_INTEGER_TOLERANCE_IN_ULP = 0.6;
+const unsigned int D3D10_1_GS_INPUT_REGISTER_COUNT = 32;
+const unsigned int D3D10_1_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT = 32;
+const unsigned int D3D10_1_IA_VERTEX_INPUT_STRUCTURE_ELEMENTS_COMPONENTS = 128;
+const unsigned int D3D10_1_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT = 32;
+const unsigned int D3D10_1_PS_OUTPUT_MASK_REGISTER_COMPONENTS = 1;
+const unsigned int D3D10_1_PS_OUTPUT_MASK_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D10_1_PS_OUTPUT_MASK_REGISTER_COUNT = 1;
+const unsigned int D3D10_1_SHADER_MAJOR_VERSION = 4;
+const unsigned int D3D10_1_SHADER_MINOR_VERSION = 1;
+const unsigned int D3D10_1_SO_BUFFER_MAX_STRIDE_IN_BYTES = 2048;
+const unsigned int D3D10_1_SO_BUFFER_MAX_WRITE_WINDOW_IN_BYTES = 256;
+const unsigned int D3D10_1_SO_BUFFER_SLOT_COUNT = 4;
+const unsigned int D3D10_1_SO_MULTIPLE_BUFFER_ELEMENTS_PER_BUFFER = 1;
+const unsigned int D3D10_1_SO_SINGLE_BUFFER_COMPONENT_LIMIT = 64;
+const unsigned int D3D10_1_STANDARD_VERTEX_ELEMENT_COUNT = 32;
+const unsigned int D3D10_1_SUBPIXEL_FRACTIONAL_BIT_COUNT = 8;
+const unsigned int D3D10_1_VS_INPUT_REGISTER_COUNT = 32;
+const unsigned int D3D10_1_VS_OUTPUT_REGISTER_COUNT = 32;
+cpp_quote("#endif")
+
+typedef enum D3D10_FEATURE_LEVEL1
+{
+ D3D10_FEATURE_LEVEL_10_0 = 0xa000,
+ D3D10_FEATURE_LEVEL_10_1 = 0xa100,
+ D3D10_FEATURE_LEVEL_9_1 = 0x9100,
+ D3D10_FEATURE_LEVEL_9_2 = 0x9200,
+ D3D10_FEATURE_LEVEL_9_3 = 0x9300
+} D3D10_FEATURE_LEVEL1;
+
+typedef struct D3D10_RENDER_TARGET_BLEND_DESC1
+{
+ BOOL BlendEnable;
+ D3D10_BLEND SrcBlend;
+ D3D10_BLEND DestBlend;
+ D3D10_BLEND_OP BlendOp;
+ D3D10_BLEND SrcBlendAlpha;
+ D3D10_BLEND DestBlendAlpha;
+ D3D10_BLEND_OP BlendOpAlpha;
+ UINT8 RenderTargetWriteMask;
+} D3D10_RENDER_TARGET_BLEND_DESC1;
+
+typedef struct D3D10_BLEND_DESC1
+{
+ BOOL AlphaToCoverageEnable;
+ BOOL IndependentBlendEnable;
+ D3D10_RENDER_TARGET_BLEND_DESC1 RenderTarget[8];
+} D3D10_BLEND_DESC1;
+
+typedef struct D3D10_TEXCUBE_ARRAY_SRV1
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+ UINT First2DArrayFace;
+ UINT NumCubes;
+} D3D10_TEXCUBE_ARRAY_SRV1;
+
+typedef D3D_SRV_DIMENSION D3D10_SRV_DIMENSION1;
+
+typedef struct D3D10_SHADER_RESOURCE_VIEW_DESC1
+{
+ DXGI_FORMAT Format;
+ D3D10_SRV_DIMENSION1 ViewDimension;
+ union
+ {
+ D3D10_BUFFER_SRV Buffer;
+ D3D10_TEX1D_SRV Texture1D;
+ D3D10_TEX1D_ARRAY_SRV Texture1DArray;
+ D3D10_TEX2D_SRV Texture2D;
+ D3D10_TEX2D_ARRAY_SRV Texture2DArray;
+ D3D10_TEX2DMS_SRV Texture2DMS;
+ D3D10_TEX2DMS_ARRAY_SRV Texture2DMSArray;
+ D3D10_TEX3D_SRV Texture3D;
+ D3D10_TEXCUBE_SRV TextureCube;
+ D3D10_TEXCUBE_ARRAY_SRV1 TextureCubeArray;
+ } ;
+} D3D10_SHADER_RESOURCE_VIEW_DESC1;
+
+typedef enum D3D10_STANDARD_MULTISAMPLE_QUALITY_LEVELS
+{
+ D3D10_STANDARD_MULTISAMPLE_PATTERN = 0xffffffff,
+ D3D10_CENTER_MULTISAMPLE_PATTERN = 0xfffffffe
+} D3D10_STANDARD_MULTISAMPLE_QUALITY_LEVELS;
+
+[object, local, uuid("EDAD8D99-8A35-4d6d-8566-2EA276CDE161")]
+interface ID3D10BlendState1 : ID3D10BlendState
+{
+ void GetDesc1(
+ [out] D3D10_BLEND_DESC1 *pDesc
+ );
+};
+
+[object, local, uuid("9B7E4C87-342C-4106-A19F-4F2704F689F0")]
+interface ID3D10ShaderResourceView1 : ID3D10ShaderResourceView
+{
+ void GetDesc1(
+ [out] D3D10_SHADER_RESOURCE_VIEW_DESC1 *pDesc
+ );
+};
+
+[object, local, uuid("9B7E4C8F-342C-4106-A19F-4F2704F689F0")]
+interface ID3D10Device1 : ID3D10Device
+{
+ HRESULT CreateShaderResourceView1(
+ [in] ID3D10Resource *pResource,
+ [in] const D3D10_SHADER_RESOURCE_VIEW_DESC1 *pDesc,
+ [out,optional] ID3D10ShaderResourceView1 **ppSRView
+ );
+
+ HRESULT CreateBlendState1(
+ [in] const D3D10_BLEND_DESC1 *pBlendStateDesc,
+ [out, optional] ID3D10BlendState1 **ppBlendState
+ );
+
+ D3D10_FEATURE_LEVEL1 GetFeatureLevel();
+};
+
+//cpp_quote("#include \"d3d10_1shader.h\"")
+
+typedef enum D3D10_DRIVER_TYPE D3D10_DRIVER_TYPE;
+
+HRESULT D3D10CreateDevice1(
+ [in,optional] IDXGIAdapter* pAdapter,
+ [in] D3D10_DRIVER_TYPE DriverType,
+ [in] HMODULE Software,
+ [in] UINT Flags,
+ [in] D3D10_FEATURE_LEVEL1 HardwareLevel,
+ [in] UINT SDKVersion,
+ [out,optional] ID3D10Device1** ppDevice
+);
+
+typedef HRESULT (* PFN_D3D10_CREATE_DEVICE_AND_SWAP_CHAIN1)(
+ [in,optional] IDXGIAdapter*,
+ D3D10_DRIVER_TYPE,
+ HMODULE,
+ UINT,
+ D3D10_FEATURE_LEVEL1 HardwareLevels,
+ UINT,
+ [in, optional] DXGI_SWAP_CHAIN_DESC*,
+ [out,optional] IDXGISwapChain**,
+ [out,optional] ID3D10Device1**
+);
+
+HRESULT D3D10CreateDeviceAndSwapChain1(
+ [in,optional] IDXGIAdapter* pAdapter,
+ [in] D3D10_DRIVER_TYPE DriverType,
+ [in] HMODULE Software,
+ [in] UINT Flags,
+ [in] D3D10_FEATURE_LEVEL1 HardwareLevel,
+ [in] UINT SDKVersion,
+ [in,optional] DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
+ [out,optional] IDXGISwapChain** ppSwapChain,
+ [out,optional] ID3D10Device1** ppDevice
+);
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3d10misc.h b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10misc.h
new file mode 100644
index 0000000..d2241e6
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10misc.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2008 Henri Verbeet for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef __D3D10MISC_H__
+#define __D3D10MISC_H__
+
+#include "d3d10.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum D3D10_DRIVER_TYPE {
+ D3D10_DRIVER_TYPE_HARDWARE = 0,
+ D3D10_DRIVER_TYPE_REFERENCE = 1,
+ D3D10_DRIVER_TYPE_NULL = 2,
+ D3D10_DRIVER_TYPE_SOFTWARE = 3,
+ D3D10_DRIVER_TYPE_WARP = 5, // added by Luca Barbieri in Sep 2010
+} D3D10_DRIVER_TYPE;
+
+HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
+ HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device);
+
+HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
+ HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc,
+ IDXGISwapChain **swapchain, ID3D10Device **device);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __D3D10MISC_H__ */
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3d10shader.idl b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10shader.idl
new file mode 100644
index 0000000..c4668a8
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3d10shader.idl
@@ -0,0 +1,269 @@
+/**************************************************************************
+ *
+ * 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 "d3d10.idl";
+
+cpp_quote("#define D3D10_TX_VERSION(a, b) (('T' << 24) | ('X' << 16) | ((a) << 8) | (b)))")
+
+const unsigned int D3D10_SHADER_DEBUG = (1 << 0);
+const unsigned int D3D10_SHADER_SKIP_VALIDATION = (1 << 1);
+const unsigned int D3D10_SHADER_SKIP_OPTIMIZATION = (1 << 2);
+const unsigned int D3D10_SHADER_PACK_MATRIX_ROW_MAJOR = (1 << 3);
+const unsigned int D3D10_SHADER_PACK_MATRIX_COLUMN_MAJOR = (1 << 4);
+const unsigned int D3D10_SHADER_PARTIAL_PRECISION = (1 << 5);
+const unsigned int D3D10_SHADER_FORCE_VS_SOFTWARE_NO_OPT = (1 << 6);
+const unsigned int D3D10_SHADER_FORCE_PS_SOFTWARE_NO_OPT = (1 << 7);
+const unsigned int D3D10_SHADER_NO_PRESHADER = (1 << 8);
+const unsigned int D3D10_SHADER_AVOID_FLOW_CONTROL = (1 << 9);
+const unsigned int D3D10_SHADER_PREFER_FLOW_CONTROL = (1 << 10);
+const unsigned int D3D10_SHADER_ENABLE_STRICTNESS = (1 << 11);
+const unsigned int D3D10_SHADER_ENABLE_BACKWARDS_COMPATIBILITY = (1 << 12);
+const unsigned int D3D10_SHADER_IEEE_STRICTNESS = (1 << 13);
+const unsigned int D3D10_SHADER_WARNINGS_ARE_ERRORS = (1 << 18);
+
+
+const unsigned int D3D10_SHADER_OPTIMIZATION_LEVEL0 = (1 << 14);
+const unsigned int D3D10_SHADER_OPTIMIZATION_LEVEL1 = 0;
+const unsigned int D3D10_SHADER_OPTIMIZATION_LEVEL2 = ((1 << 14) | (1 << 15));
+const unsigned int D3D10_SHADER_OPTIMIZATION_LEVEL3 = (1 << 15);
+
+typedef D3D_SHADER_MACRO D3D10_SHADER_MACRO;
+typedef D3D10_SHADER_MACRO* LPD3D10_SHADER_MACRO;
+
+
+typedef D3D_SHADER_VARIABLE_CLASS D3D10_SHADER_VARIABLE_CLASS;
+typedef D3D10_SHADER_VARIABLE_CLASS* LPD3D10_SHADER_VARIABLE_CLASS;
+typedef D3D_SHADER_VARIABLE_FLAGS D3D10_SHADER_VARIABLE_FLAGS;
+typedef D3D10_SHADER_VARIABLE_FLAGS* LPD3D10_SHADER_VARIABLE_FLAGS;
+typedef D3D_SHADER_VARIABLE_TYPE D3D10_SHADER_VARIABLE_TYPE;
+typedef D3D10_SHADER_VARIABLE_TYPE* LPD3D10_SHADER_VARIABLE_TYPE;
+typedef D3D_SHADER_INPUT_FLAGS D3D10_SHADER_INPUT_FLAGS;
+typedef D3D10_SHADER_INPUT_FLAGS* LPD3D10_SHADER_INPUT_FLAGS;
+typedef D3D_SHADER_INPUT_TYPE D3D10_SHADER_INPUT_TYPE;
+typedef D3D10_SHADER_INPUT_TYPE* LPD3D10_SHADER_INPUT_TYPE;
+typedef D3D_SHADER_CBUFFER_FLAGS D3D10_SHADER_CBUFFER_FLAGS;
+typedef D3D10_SHADER_CBUFFER_FLAGS* LPD3D10_SHADER_CBUFFER_FLAGS;
+typedef D3D_CBUFFER_TYPE D3D10_CBUFFER_TYPE;
+typedef D3D10_CBUFFER_TYPE* LPD3D10_CBUFFER_TYPE;
+typedef D3D_NAME D3D10_NAME;
+typedef D3D_RESOURCE_RETURN_TYPE D3D10_RESOURCE_RETURN_TYPE;
+typedef D3D_REGISTER_COMPONENT_TYPE D3D10_REGISTER_COMPONENT_TYPE;
+typedef D3D_INCLUDE_TYPE D3D10_INCLUDE_TYPE;
+typedef ID3DInclude* LPD3D10INCLUDE;
+
+cpp_quote("#define D3D10_SHVER_GET_TYPE(v) (((v) >> 16) & 0xffff)")
+cpp_quote("#define D3D10_SHVER_GET_MAJOR(v) (((v) >> 4) & 0xf)")
+cpp_quote("#define D3D10_SHVER_GET_MINOR(v) (((v) >> 0) & 0xf)")
+
+typedef struct _D3D10_SIGNATURE_PARAMETER_DESC
+{
+ LPCSTR SemanticName;
+ UINT SemanticIndex;
+ UINT Register;
+ D3D_NAME SystemValueType;
+ D3D_REGISTER_COMPONENT_TYPE ComponentType;
+ BYTE Mask;
+ BYTE ReadWriteMask;
+} D3D10_SIGNATURE_PARAMETER_DESC;
+
+typedef struct _D3D10_SHADER_BUFFER_DESC
+{
+ LPCSTR Name;
+ D3D_CBUFFER_TYPE Type;
+ UINT Variables;
+ UINT Size;
+ UINT uFlags;
+} D3D10_SHADER_BUFFER_DESC;
+
+typedef struct _D3D10_SHADER_VARIABLE_DESC
+{
+ LPCSTR Name;
+ UINT StartOffset;
+ UINT Size;
+ UINT uFlags;
+ LPVOID DefaultValue;
+ UINT StartTexture;
+ UINT TextureSize;
+ UINT StartSampler;
+ UINT SamplerSize;
+} D3D10_SHADER_VARIABLE_DESC;
+
+typedef struct _D3D10_SHADER_TYPE_DESC
+{
+ D3D_SHADER_VARIABLE_CLASS Class;
+ D3D_SHADER_VARIABLE_TYPE Type;
+ UINT Rows;
+ UINT Columns;
+ UINT Elements;
+ UINT Members;
+ UINT Offset;
+ LPCSTR Name;
+} D3D10_SHADER_TYPE_DESC;
+
+typedef D3D_TESSELLATOR_DOMAIN D3D10_TESSELLATOR_DOMAIN;
+typedef D3D_TESSELLATOR_PARTITIONING D3D10_TESSELLATOR_PARTITIONING;
+typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D10_TESSELLATOR_OUTPUT_PRIMITIVE;
+
+typedef struct _D3D10_SHADER_DESC
+{
+ UINT Version;
+ LPCSTR Creator;
+ UINT Flags;
+
+ UINT ConstantBuffers;
+ UINT BoundResources;
+ UINT InputParameters;
+ UINT OutputParameters;
+
+ UINT InstructionCount;
+ UINT TempRegisterCount;
+ UINT TempArrayCount;
+ UINT DefCount;
+ UINT DclCount;
+ UINT TextureNormalInstructions;
+ UINT TextureLoadInstructions;
+ UINT TextureCompInstructions;
+ UINT TextureBiasInstructions;
+ UINT TextureGradientInstructions;
+ UINT FloatInstructionCount;
+ UINT IntInstructionCount;
+ UINT UintInstructionCount;
+ UINT StaticFlowControlCount;
+ UINT DynamicFlowControlCount;
+ UINT MacroInstructionCount;
+ UINT ArrayInstructionCount;
+ UINT CutInstructionCount;
+ UINT EmitInstructionCount;
+ D3D_PRIMITIVE_TOPOLOGY GSOutputTopology;
+ UINT GSMaxOutputVertexCount;
+} D3D10_SHADER_DESC;
+
+typedef struct _D3D10_SHADER_INPUT_BIND_DESC
+{
+ LPCSTR Name;
+ D3D_SHADER_INPUT_TYPE Type;
+ UINT BindPoint;
+ UINT BindCount;
+
+ UINT uFlags;
+ D3D_RESOURCE_RETURN_TYPE ReturnType;
+ D3D_SRV_DIMENSION Dimension;
+ UINT NumSamples;
+} D3D10_SHADER_INPUT_BIND_DESC;
+
+[local, object, uuid("C530AD7D-9B16-4395-A979-BA2ECFF83ADD")]
+interface ID3D10ShaderReflectionType
+{
+ HRESULT GetDesc(
+ [out] D3D10_SHADER_TYPE_DESC *pDesc
+ );
+
+ ID3D10ShaderReflectionType* GetMemberTypeByIndex(
+ [in] UINT Index
+ );
+
+ ID3D10ShaderReflectionType* GetMemberTypeByName(
+ [in] LPCSTR Name
+ );
+
+ LPCSTR GetMemberTypeName(
+ [in] UINT Index
+ );
+};
+
+interface ID3D10ShaderReflectionConstantBuffer;
+
+[object, local, uuid("1BF63C95-2650-405d-99C1-3636BD1DA0A1")]
+interface ID3D10ShaderReflectionVariable
+{
+ HRESULT GetDesc(
+ [out] D3D10_SHADER_VARIABLE_DESC *pDesc
+ );
+
+ ID3D10ShaderReflectionType* GetType();
+};
+
+[object, local, uuid("66C66A94-DDDD-4b62-A66A-F0DA33C2B4D0")]
+interface ID3D10ShaderReflectionConstantBuffer
+{
+ HRESULT GetDesc(
+ [out] D3D10_SHADER_BUFFER_DESC *pDesc
+ );
+
+ ID3D10ShaderReflectionVariable* GetVariableByIndex(
+ [in] UINT Index
+ );
+
+ ID3D10ShaderReflectionVariable* GetVariableByName(
+ [in] LPCSTR Name
+ );
+};
+
+[object,local,uuid("D40E20B6-F8F7-42ad-AB20-4BAF8F15DFAA")]
+interface ID3D10ShaderReflection : IUnknown
+{
+ HRESULT GetDesc(
+ [out] D3D10_SHADER_DESC *pDesc
+ );
+
+ ID3D10ShaderReflectionConstantBuffer* GetConstantBufferByIndex(
+ [in] UINT Index
+ );
+
+ ID3D10ShaderReflectionConstantBuffer* GetConstantBufferByName(
+ [in] LPCSTR Name
+ );
+
+ HRESULT GetResourceBindingDesc(
+ [in] UINT ResourceIndex,
+ [out] D3D10_SHADER_INPUT_BIND_DESC *pDesc
+ );
+
+ HRESULT GetInputParameterDesc(
+ [in] UINT ParameterIndex,
+ [out] D3D10_SIGNATURE_PARAMETER_DESC *pDesc
+ );
+
+ HRESULT GetOutputParameterDesc
+ (
+ [in] UINT ParameterIndex,
+ [out] D3D10_SIGNATURE_PARAMETER_DESC *pDesc
+ );
+};
+
+HRESULT D3D10CompileShader(LPCSTR pSrcData, SIZE_T SrcDataLen, LPCSTR pFileName, const D3D10_SHADER_MACRO* pDefines, LPD3D10INCLUDE pInclude,
+ LPCSTR pFunctionName, LPCSTR pProfile, UINT Flags, ID3D10Blob** ppShader, ID3D10Blob** ppErrorMsgs);
+HRESULT D3D10DisassembleShader(const void *pShader, SIZE_T BytecodeLength, BOOL EnableColorCode, LPCSTR pComments, ID3D10Blob** ppDisassembly);
+LPCSTR D3D10GetPixelShaderProfile(ID3D10Device *pDevice);
+LPCSTR D3D10GetVertexShaderProfile(ID3D10Device *pDevice);
+LPCSTR D3D10GetGeometryShaderProfile(ID3D10Device *pDevice);
+HRESULT D3D10ReflectShader(const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10ShaderReflection **ppReflector);
+HRESULT D3D10PreprocessShader(LPCSTR pSrcData, SIZE_T SrcDataSize, LPCSTR pFileName, const D3D10_SHADER_MACRO* pDefines,
+ LPD3D10INCLUDE pInclude, ID3D10Blob** ppShaderText, ID3D10Blob** ppErrorMsgs);
+HRESULT D3D10GetInputSignatureBlob(const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10Blob **ppSignatureBlob);
+HRESULT D3D10GetOutputSignatureBlob(const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10Blob **ppSignatureBlob);
+HRESULT D3D10GetInputAndOutputSignatureBlob(const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10Blob **ppSignatureBlob);
+HRESULT D3D10GetShaderDebugInfo(const void *pShaderBytecode, SIZE_T BytecodeLength, ID3D10Blob** ppDebugInfo);
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3d11.idl b/src/gallium/state_trackers/d3d1x/d3dapi/d3d11.idl
new file mode 100644
index 0000000..5a57da3
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3d11.idl
@@ -0,0 +1,2492 @@
+/**************************************************************************
+ *
+ * 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 "oaidl.idl";
+import "ocidl.idl";
+import "dxgi.idl";
+import "d3dcommon.idl";
+
+const unsigned int D3D11_SDK_VERSION = 7;
+
+cpp_quote("#ifndef _D3D11_CONSTANTS")
+cpp_quote("#define _D3D11_CONSTANTS")
+const unsigned int D3D11_16BIT_INDEX_STRIP_CUT_VALUE = 0xffff;
+const unsigned int D3D11_32BIT_INDEX_STRIP_CUT_VALUE = 0xffffffff;
+const unsigned int D3D11_8BIT_INDEX_STRIP_CUT_VALUE = 0xff;
+const unsigned int D3D11_ARRAY_AXIS_ADDRESS_RANGE_BIT_COUNT = 9;
+const unsigned int D3D11_CLIP_OR_CULL_DISTANCE_COUNT = 8;
+const unsigned int D3D11_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT = 2;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT = 14;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_COMPONENTS = 4;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_HW_SLOT_COUNT = 15;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_REGISTER_COUNT = 15;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_COMMONSHADER_CONSTANT_BUFFER_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D11_COMMONSHADER_FLOWCONTROL_NESTING_LIMIT = 64;
+const unsigned int D3D11_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_COUNT = 1;
+const unsigned int D3D11_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_COMMONSHADER_IMMEDIATE_CONSTANT_BUFFER_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D11_COMMONSHADER_IMMEDIATE_VALUE_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT = 128;
+const unsigned int D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT = 128;
+const unsigned int D3D11_COMMONSHADER_SAMPLER_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT = 16;
+const unsigned int D3D11_COMMONSHADER_SAMPLER_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_COMMONSHADER_SAMPLER_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT = 16;
+const unsigned int D3D11_COMMONSHADER_SUBROUTINE_NESTING_LIMIT = 32;
+const unsigned int D3D11_COMMONSHADER_TEMP_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_COMMONSHADER_TEMP_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_COMMONSHADER_TEMP_REGISTER_COUNT = 4096;
+const unsigned int D3D11_COMMONSHADER_TEMP_REGISTER_READ_PORTS = 3;
+const unsigned int D3D11_COMMONSHADER_TEMP_REGISTER_READS_PER_INST = 3;
+const unsigned int D3D11_COMMONSHADER_TEXCOORD_RANGE_REDUCTION_MAX = 10;
+const int D3D11_COMMONSHADER_TEXCOORD_RANGE_REDUCTION_MIN = -10;
+const int D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_NEGATIVE = -8;
+const unsigned int D3D11_COMMONSHADER_TEXEL_OFFSET_MAX_POSITIVE = 7;
+const unsigned int D3D11_CS_4_X_BUCKET00_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 256;
+const unsigned int D3D11_CS_4_X_BUCKET00_MAX_NUM_THREADS_PER_GROUP = 64;
+const unsigned int D3D11_CS_4_X_BUCKET01_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 240;
+const unsigned int D3D11_CS_4_X_BUCKET01_MAX_NUM_THREADS_PER_GROUP = 68;
+const unsigned int D3D11_CS_4_X_BUCKET02_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 224;
+const unsigned int D3D11_CS_4_X_BUCKET02_MAX_NUM_THREADS_PER_GROUP = 72;
+const unsigned int D3D11_CS_4_X_BUCKET03_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 208;
+const unsigned int D3D11_CS_4_X_BUCKET03_MAX_NUM_THREADS_PER_GROUP = 76;
+const unsigned int D3D11_CS_4_X_BUCKET04_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 192;
+const unsigned int D3D11_CS_4_X_BUCKET04_MAX_NUM_THREADS_PER_GROUP = 84;
+const unsigned int D3D11_CS_4_X_BUCKET05_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 176;
+const unsigned int D3D11_CS_4_X_BUCKET05_MAX_NUM_THREADS_PER_GROUP = 92;
+const unsigned int D3D11_CS_4_X_BUCKET06_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 160;
+const unsigned int D3D11_CS_4_X_BUCKET06_MAX_NUM_THREADS_PER_GROUP = 100;
+const unsigned int D3D11_CS_4_X_BUCKET07_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 144;
+const unsigned int D3D11_CS_4_X_BUCKET07_MAX_NUM_THREADS_PER_GROUP = 112;
+const unsigned int D3D11_CS_4_X_BUCKET08_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 128;
+const unsigned int D3D11_CS_4_X_BUCKET08_MAX_NUM_THREADS_PER_GROUP = 128;
+const unsigned int D3D11_CS_4_X_BUCKET09_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 112;
+const unsigned int D3D11_CS_4_X_BUCKET09_MAX_NUM_THREADS_PER_GROUP = 144;
+const unsigned int D3D11_CS_4_X_BUCKET10_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 96;
+const unsigned int D3D11_CS_4_X_BUCKET10_MAX_NUM_THREADS_PER_GROUP = 168;
+const unsigned int D3D11_CS_4_X_BUCKET11_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 80;
+const unsigned int D3D11_CS_4_X_BUCKET11_MAX_NUM_THREADS_PER_GROUP = 204;
+const unsigned int D3D11_CS_4_X_BUCKET12_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 64;
+const unsigned int D3D11_CS_4_X_BUCKET12_MAX_NUM_THREADS_PER_GROUP = 256;
+const unsigned int D3D11_CS_4_X_BUCKET13_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 48;
+const unsigned int D3D11_CS_4_X_BUCKET13_MAX_NUM_THREADS_PER_GROUP = 340;
+const unsigned int D3D11_CS_4_X_BUCKET14_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 32;
+const unsigned int D3D11_CS_4_X_BUCKET14_MAX_NUM_THREADS_PER_GROUP = 512;
+const unsigned int D3D11_CS_4_X_BUCKET15_MAX_BYTES_TGSM_WRITABLE_PER_THREAD = 16;
+const unsigned int D3D11_CS_4_X_BUCKET15_MAX_NUM_THREADS_PER_GROUP = 768;
+const unsigned int D3D11_CS_4_X_DISPATCH_MAX_THREAD_GROUPS_IN_Z_DIMENSION = 1;
+const unsigned int D3D11_CS_4_X_RAW_UAV_BYTE_ALIGNMENT = 256;
+const unsigned int D3D11_CS_4_X_THREAD_GROUP_MAX_THREADS_PER_GROUP = 768;
+const unsigned int D3D11_CS_4_X_THREAD_GROUP_MAX_X = 768;
+const unsigned int D3D11_CS_4_X_THREAD_GROUP_MAX_Y = 768;
+const unsigned int D3D11_CS_4_X_UAV_REGISTER_COUNT = 1;
+const unsigned int D3D11_CS_DISPATCH_MAX_THREAD_GROUPS_PER_DIMENSION = 65535;
+const unsigned int D3D11_CS_TGSM_REGISTER_COUNT = 8192;
+const unsigned int D3D11_CS_TGSM_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D11_CS_TGSM_RESOURCE_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_CS_TGSM_RESOURCE_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_CS_THREAD_GROUP_MAX_THREADS_PER_GROUP = 1024;
+const unsigned int D3D11_CS_THREAD_GROUP_MAX_X = 1024;
+const unsigned int D3D11_CS_THREAD_GROUP_MAX_Y = 1024;
+const unsigned int D3D11_CS_THREAD_GROUP_MAX_Z = 64;
+const unsigned int D3D11_CS_THREAD_GROUP_MIN_X = 1;
+const unsigned int D3D11_CS_THREAD_GROUP_MIN_Y = 1;
+const unsigned int D3D11_CS_THREAD_GROUP_MIN_Z = 1;
+const unsigned int D3D11_CS_THREAD_LOCAL_TEMP_REGISTER_POOL = 16384;
+const float D3D11_DEFAULT_BLEND_FACTOR_ALPHA = 1.0;
+const float D3D11_DEFAULT_BLEND_FACTOR_BLUE = 1.0;
+const float D3D11_DEFAULT_BLEND_FACTOR_GREEN = 1.0;
+const float D3D11_DEFAULT_BLEND_FACTOR_RED = 1.0;
+const float D3D11_DEFAULT_BORDER_COLOR_COMPONENT = 0.0;
+const unsigned int D3D11_DEFAULT_DEPTH_BIAS = 0;
+const float D3D11_DEFAULT_DEPTH_BIAS_CLAMP = 0.0;
+const unsigned int D3D11_DEFAULT_MAX_ANISOTROPY = 16;
+const float D3D11_DEFAULT_MIP_LOD_BIAS = 0.0;
+const unsigned int D3D11_DEFAULT_RENDER_TARGET_ARRAY_INDEX = 0;
+const unsigned int D3D11_DEFAULT_SAMPLE_MASK = 0xffffffff;
+const unsigned int D3D11_DEFAULT_SCISSOR_ENDX = 0;
+const unsigned int D3D11_DEFAULT_SCISSOR_ENDY = 0;
+const unsigned int D3D11_DEFAULT_SCISSOR_STARTX = 0;
+const unsigned int D3D11_DEFAULT_SCISSOR_STARTY = 0;
+const float D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS = 0.0;
+const unsigned int D3D11_DEFAULT_STENCIL_READ_MASK = 0xff;
+const unsigned int D3D11_DEFAULT_STENCIL_REFERENCE = 0;
+const unsigned int D3D11_DEFAULT_STENCIL_WRITE_MASK = 0xff;
+const unsigned int D3D11_DEFAULT_VIEWPORT_AND_SCISSORRECT_INDEX = 0;
+const unsigned int D3D11_DEFAULT_VIEWPORT_HEIGHT = 0;
+const float D3D11_DEFAULT_VIEWPORT_MAX_DEPTH = 0.0;
+const float D3D11_DEFAULT_VIEWPORT_MIN_DEPTH = 0.0;
+const unsigned int D3D11_DEFAULT_VIEWPORT_TOPLEFTX = 0;
+const unsigned int D3D11_DEFAULT_VIEWPORT_TOPLEFTY = 0;
+const unsigned int D3D11_DEFAULT_VIEWPORT_WIDTH = 0;
+const unsigned int D3D11_DS_INPUT_CONTROL_POINT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_DS_INPUT_CONTROL_POINT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_DS_INPUT_CONTROL_POINT_REGISTER_COUNT = 32;
+const unsigned int D3D11_DS_INPUT_CONTROL_POINT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_DS_INPUT_CONTROL_POINT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_DS_INPUT_CONTROL_POINTS_MAX_TOTAL_SCALARS = 3968;
+const unsigned int D3D11_DS_INPUT_DOMAIN_POINT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_DS_INPUT_DOMAIN_POINT_REGISTER_COMPONENTS = 3;
+const unsigned int D3D11_DS_INPUT_DOMAIN_POINT_REGISTER_COUNT = 1;
+const unsigned int D3D11_DS_INPUT_DOMAIN_POINT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_DS_INPUT_DOMAIN_POINT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_DS_INPUT_PATCH_CONSTANT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_DS_INPUT_PATCH_CONSTANT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_DS_INPUT_PATCH_CONSTANT_REGISTER_COUNT = 32;
+const unsigned int D3D11_DS_INPUT_PATCH_CONSTANT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_DS_INPUT_PATCH_CONSTANT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_DS_OUTPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_DS_OUTPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_DS_OUTPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_FLOAT16_FUSED_TOLERANCE_IN_ULP = 0.6;
+const float D3D11_FLOAT32_MAX = 3.402823466e+38;
+const float D3D11_FLOAT32_TO_INTEGER_TOLERANCE_IN_ULP = 0.6;
+const float D3D11_FLOAT_TO_SRGB_EXPONENT_DENOMINATOR = 2.4;
+const float D3D11_FLOAT_TO_SRGB_EXPONENT_NUMERATOR = 1.0;
+const float D3D11_FLOAT_TO_SRGB_OFFSET = 0.055;
+const float D3D11_FLOAT_TO_SRGB_SCALE_1 = 12.92;
+const float D3D11_FLOAT_TO_SRGB_SCALE_2 = 1.055;
+const float D3D11_FLOAT_TO_SRGB_THRESHOLD = 0.0031308;
+const float D3D11_FTOI_INSTRUCTION_MAX_INPUT = 2147483647.999;
+const float D3D11_FTOI_INSTRUCTION_MIN_INPUT = -2147483648.999;
+const float D3D11_FTOU_INSTRUCTION_MAX_INPUT = 4294967295.999;
+const float D3D11_FTOU_INSTRUCTION_MIN_INPUT = 0.0;
+const unsigned int D3D11_GS_INPUT_INSTANCE_ID_READ_PORTS = 1;
+const unsigned int D3D11_GS_INPUT_INSTANCE_ID_READS_PER_INST = 2;
+const unsigned int D3D11_GS_INPUT_INSTANCE_ID_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_GS_INPUT_INSTANCE_ID_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_GS_INPUT_INSTANCE_ID_REGISTER_COUNT = 1;
+const unsigned int D3D11_GS_INPUT_PRIM_CONST_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_GS_INPUT_PRIM_CONST_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_GS_INPUT_PRIM_CONST_REGISTER_COUNT = 1;
+const unsigned int D3D11_GS_INPUT_PRIM_CONST_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_GS_INPUT_PRIM_CONST_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_GS_INPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_GS_INPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_GS_INPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_GS_INPUT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_GS_INPUT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_GS_INPUT_REGISTER_VERTICES = 32;
+const unsigned int D3D11_GS_MAX_INSTANCE_COUNT = 32;
+const unsigned int D3D11_GS_MAX_OUTPUT_VERTEX_COUNT_ACROSS_INSTANCES = 1024;
+const unsigned int D3D11_GS_OUTPUT_ELEMENTS = 32;
+const unsigned int D3D11_GS_OUTPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_GS_OUTPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_GS_OUTPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_HS_CONTROL_POINT_PHASE_INPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_HS_CONTROL_POINT_PHASE_OUTPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_HS_CONTROL_POINT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_HS_CONTROL_POINT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_HS_CONTROL_POINT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_HS_CONTROL_POINT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_HS_FORK_PHASE_INSTANCE_COUNT_UPPER_BOUND = 0xffffffff;
+const unsigned int D3D11_HS_INPUT_FORK_INSTANCE_ID_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_HS_INPUT_FORK_INSTANCE_ID_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_HS_INPUT_FORK_INSTANCE_ID_REGISTER_COUNT = 1;
+const unsigned int D3D11_HS_INPUT_FORK_INSTANCE_ID_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_HS_INPUT_FORK_INSTANCE_ID_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_HS_INPUT_JOIN_INSTANCE_ID_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_HS_INPUT_JOIN_INSTANCE_ID_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_HS_INPUT_JOIN_INSTANCE_ID_REGISTER_COUNT = 1;
+const unsigned int D3D11_HS_INPUT_JOIN_INSTANCE_ID_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_HS_INPUT_JOIN_INSTANCE_ID_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_HS_INPUT_PRIMITIVE_ID_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_HS_INPUT_PRIMITIVE_ID_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_HS_INPUT_PRIMITIVE_ID_REGISTER_COUNT = 1;
+const unsigned int D3D11_HS_INPUT_PRIMITIVE_ID_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_HS_INPUT_PRIMITIVE_ID_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_HS_JOIN_PHASE_INSTANCE_COUNT_UPPER_BOUND = 0xffffffff;
+const float D3D11_HS_MAXTESSFACTOR_LOWER_BOUND = 1.0;
+const float D3D11_HS_MAXTESSFACTOR_UPPER_BOUND = 64.0;
+const unsigned int D3D11_HS_OUTPUT_CONTROL_POINT_ID_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_HS_OUTPUT_CONTROL_POINT_ID_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_HS_OUTPUT_CONTROL_POINT_ID_REGISTER_COUNT = 1;
+const unsigned int D3D11_HS_OUTPUT_CONTROL_POINT_ID_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_HS_OUTPUT_CONTROL_POINT_ID_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_HS_OUTPUT_CONTROL_POINTS_MAX_TOTAL_SCALARS = 3968;
+const unsigned int D3D11_HS_OUTPUT_PATCH_CONSTANT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_HS_OUTPUT_PATCH_CONSTANT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_HS_OUTPUT_PATCH_CONSTANT_REGISTER_COUNT = 32;
+const unsigned int D3D11_HS_OUTPUT_PATCH_CONSTANT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_HS_OUTPUT_PATCH_CONSTANT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_IA_DEFAULT_INDEX_BUFFER_OFFSET_IN_BYTES = 0;
+const unsigned int D3D11_IA_DEFAULT_PRIMITIVE_TOPOLOGY = 0;
+const unsigned int D3D11_IA_DEFAULT_VERTEX_BUFFER_OFFSET_IN_BYTES = 0;
+const unsigned int D3D11_IA_INDEX_INPUT_RESOURCE_SLOT_COUNT = 1;
+const unsigned int D3D11_IA_INSTANCE_ID_BIT_COUNT = 32;
+const unsigned int D3D11_IA_INTEGER_ARITHMETIC_BIT_COUNT = 32;
+const unsigned int D3D11_IA_PATCH_MAX_CONTROL_POINT_COUNT = 32;
+const unsigned int D3D11_IA_PRIMITIVE_ID_BIT_COUNT = 32;
+const unsigned int D3D11_IA_VERTEX_ID_BIT_COUNT = 32;
+const unsigned int D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT = 32;
+const unsigned int D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT = 32;
+const unsigned int D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENTS_COMPONENTS = 128;
+const unsigned int D3D11_INTEGER_DIVIDE_BY_ZERO_QUOTIENT = 0xffffffff;
+const unsigned int D3D11_INTEGER_DIVIDE_BY_ZERO_REMAINDER = 0xffffffff;
+const unsigned int D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL = 0xffffffff;
+const unsigned int D3D11_KEEP_UNORDERED_ACCESS_VIEWS = 0xffffffff;
+const float D3D11_LINEAR_GAMMA = 1.0;
+const unsigned int D3D11_MAJOR_VERSION = 11;
+const float D3D11_MAX_BORDER_COLOR_COMPONENT = 1.0;
+const float D3D11_MAX_DEPTH = 1.0;
+const unsigned int D3D11_MAX_MAXANISOTROPY = 16;
+const unsigned int D3D11_MAX_MULTISAMPLE_SAMPLE_COUNT = 32;
+const float D3D11_MAX_POSITION_VALUE = 3.402823466e+34;
+const unsigned int D3D11_MAX_TEXTURE_DIMENSION_2_TO_EXP = 17;
+const float D3D11_MIN_BORDER_COLOR_COMPONENT = 0.0;
+const float D3D11_MIN_DEPTH = 0.0;
+const unsigned int D3D11_MIN_MAXANISOTROPY = 0;
+const unsigned int D3D11_MINOR_VERSION = 0;
+const float D3D11_MIP_LOD_BIAS_MAX = 15.99;
+const float D3D11_MIP_LOD_BIAS_MIN = -16.0;
+const unsigned int D3D11_MIP_LOD_FRACTIONAL_BIT_COUNT = 8;
+const unsigned int D3D11_MIP_LOD_RANGE_BIT_COUNT = 8;
+const float D3D11_MULTISAMPLE_ANTIALIAS_LINE_WIDTH = 1.4;
+const unsigned int D3D11_NONSAMPLE_FETCH_OUT_OF_RANGE_ACCESS_RESULT = 0;
+const unsigned int D3D11_PIXEL_ADDRESS_RANGE_BIT_COUNT = 15;
+const unsigned int D3D11_PRE_SCISSOR_PIXEL_ADDRESS_RANGE_BIT_COUNT = 16;
+const unsigned int D3D11_PS_CS_UAV_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_PS_CS_UAV_REGISTER_COUNT = 8;
+const unsigned int D3D11_PS_CS_UAV_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_PS_CS_UAV_REGISTER_READS_PER_INST = 1;
+const unsigned int D3D11_PS_FRONTFACING_DEFAULT_VALUE = 0xffffffff;
+const unsigned int D3D11_PS_FRONTFACING_FALSE_VALUE = 0;
+const unsigned int D3D11_PS_FRONTFACING_TRUE_VALUE = 0xffffffff;
+const unsigned int D3D11_PS_INPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_PS_INPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_PS_INPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_PS_INPUT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_PS_INPUT_REGISTER_READS_PER_INST = 2;
+const float D3D11_PS_LEGACY_PIXEL_CENTER_FRACTIONAL_COMPONENT = 0.0;
+const unsigned int D3D11_PS_OUTPUT_DEPTH_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_PS_OUTPUT_DEPTH_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_PS_OUTPUT_DEPTH_REGISTER_COUNT = 1;
+const unsigned int D3D11_PS_OUTPUT_MASK_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_PS_OUTPUT_MASK_REGISTER_COMPONENTS = 1;
+const unsigned int D3D11_PS_OUTPUT_MASK_REGISTER_COUNT = 1;
+const unsigned int D3D11_PS_OUTPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_PS_OUTPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_PS_OUTPUT_REGISTER_COUNT = 8;
+const float D3D11_PS_PIXEL_CENTER_FRACTIONAL_COMPONENT = 0.5;
+const unsigned int D3D11_RAW_UAV_SRV_BYTE_ALIGNMENT = 16;
+const unsigned int D3D11_REQ_BLEND_OBJECT_COUNT_PER_DEVICE = 4096;
+const unsigned int D3D11_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP = 27;
+const unsigned int D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT = 4096;
+const unsigned int D3D11_REQ_DEPTH_STENCIL_OBJECT_COUNT_PER_DEVICE = 4096;
+const unsigned int D3D11_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP = 32;
+const unsigned int D3D11_REQ_DRAW_VERTEX_COUNT_2_TO_EXP = 32;
+const unsigned int D3D11_REQ_FILTERING_HW_ADDRESSABLE_RESOURCE_DIMENSION = 16384;
+const unsigned int D3D11_REQ_GS_INVOCATION_32BIT_OUTPUT_COMPONENT_LIMIT = 1024;
+const unsigned int D3D11_REQ_IMMEDIATE_CONSTANT_BUFFER_ELEMENT_COUNT = 4096;
+const unsigned int D3D11_REQ_MAXANISOTROPY = 16;
+const unsigned int D3D11_REQ_MIP_LEVELS = 15;
+const unsigned int D3D11_REQ_MULTI_ELEMENT_STRUCTURE_SIZE_IN_BYTES = 2048;
+const unsigned int D3D11_REQ_RASTERIZER_OBJECT_COUNT_PER_DEVICE = 4096;
+const unsigned int D3D11_REQ_RENDER_TO_BUFFER_WINDOW_WIDTH = 16384;
+const unsigned int D3D11_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_A_TERM = 128;
+const float D3D11_REQ_RESOURCE_SIZE_IN_MEGABYTES_EXPRESSION_B_TERM = 0.25;
+const unsigned int D3D11_REQ_RESOURCE_VIEW_COUNT_PER_DEVICE_2_TO_EXP = 20;
+const unsigned int D3D11_REQ_SAMPLER_OBJECT_COUNT_PER_DEVICE = 4096;
+const unsigned int D3D11_REQ_TEXTURE1D_ARRAY_AXIS_DIMENSION = 2048;
+const unsigned int D3D11_REQ_TEXTURE1D_U_DIMENSION = 16384;
+const unsigned int D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION = 2048;
+const unsigned int D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION = 16384;
+const unsigned int D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION = 2048;
+const unsigned int D3D11_REQ_TEXTURECUBE_DIMENSION = 16384;
+const unsigned int D3D11_RESINFO_INSTRUCTION_MISSING_COMPONENT_RETVAL = 0;
+const unsigned int D3D11_SHADER_MAJOR_VERSION = 5;
+const unsigned int D3D11_SHADER_MAX_INSTANCES = 65535;
+const unsigned int D3D11_SHADER_MAX_INTERFACE_CALL_SITES = 4096;
+const unsigned int D3D11_SHADER_MAX_INTERFACES = 253;
+const unsigned int D3D11_SHADER_MAX_TYPES = 65535;
+const unsigned int D3D11_SHADER_MINOR_VERSION = 0;
+const unsigned int D3D11_SHIFT_INSTRUCTION_PAD_VALUE = 0;
+const unsigned int D3D11_SHIFT_INSTRUCTION_SHIFT_VALUE_BIT_COUNT = 5;
+const unsigned int D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT = 8;
+const unsigned int D3D11_SO_BUFFER_MAX_STRIDE_IN_BYTES = 2048;
+const unsigned int D3D11_SO_BUFFER_MAX_WRITE_WINDOW_IN_BYTES = 512;
+const unsigned int D3D11_SO_BUFFER_SLOT_COUNT = 4;
+const unsigned int D3D11_SO_DDI_REGISTER_INDEX_DENOTING_GAP = 0xffffffff;
+const unsigned int D3D11_SO_NO_RASTERIZED_STREAM = 0xffffffff;
+const unsigned int D3D11_SO_OUTPUT_COMPONENT_COUNT = 128;
+const unsigned int D3D11_SO_STREAM_COUNT = 4;
+const unsigned int D3D11_SPEC_DATE_DAY = 04;
+const unsigned int D3D11_SPEC_DATE_MONTH = 06;
+const unsigned int D3D11_SPEC_DATE_YEAR = 2009;
+const unsigned int D3D11_SPEC_VERSION = 1.0;
+const float D3D11_SRGB_GAMMA = 2.2;
+const float D3D11_SRGB_TO_FLOAT_DENOMINATOR_1 = 12.92;
+const float D3D11_SRGB_TO_FLOAT_DENOMINATOR_2 = 1.055;
+const float D3D11_SRGB_TO_FLOAT_EXPONENT = 2.4;
+const float D3D11_SRGB_TO_FLOAT_OFFSET = 0.055;
+const float D3D11_SRGB_TO_FLOAT_THRESHOLD = 0.04045;
+const float D3D11_SRGB_TO_FLOAT_TOLERANCE_IN_ULP = 0.5;
+const unsigned int D3D11_STANDARD_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_STANDARD_COMPONENT_BIT_COUNT_DOUBLED = 64;
+const unsigned int D3D11_STANDARD_MAXIMUM_ELEMENT_ALIGNMENT_BYTE_MULTIPLE = 4;
+const unsigned int D3D11_STANDARD_PIXEL_COMPONENT_COUNT = 128;
+const unsigned int D3D11_STANDARD_PIXEL_ELEMENT_COUNT = 32;
+const unsigned int D3D11_STANDARD_VECTOR_SIZE = 4;
+const unsigned int D3D11_STANDARD_VERTEX_ELEMENT_COUNT = 32;
+const unsigned int D3D11_STANDARD_VERTEX_TOTAL_COMPONENT_COUNT = 64;
+const unsigned int D3D11_SUBPIXEL_FRACTIONAL_BIT_COUNT = 8;
+const unsigned int D3D11_SUBTEXEL_FRACTIONAL_BIT_COUNT = 8;
+const unsigned int D3D11_TESSELLATOR_MAX_EVEN_TESSELLATION_FACTOR = 64;
+const unsigned int D3D11_TESSELLATOR_MAX_ISOLINE_DENSITY_TESSELLATION_FACTOR = 64;
+const unsigned int D3D11_TESSELLATOR_MAX_ODD_TESSELLATION_FACTOR = 63;
+const unsigned int D3D11_TESSELLATOR_MAX_TESSELLATION_FACTOR = 64;
+const unsigned int D3D11_TESSELLATOR_MIN_EVEN_TESSELLATION_FACTOR = 2;
+const unsigned int D3D11_TESSELLATOR_MIN_ISOLINE_DENSITY_TESSELLATION_FACTOR = 1;
+const unsigned int D3D11_TESSELLATOR_MIN_ODD_TESSELLATION_FACTOR = 1;
+const unsigned int D3D11_TEXEL_ADDRESS_RANGE_BIT_COUNT = 16;
+const unsigned int D3D11_UNBOUND_MEMORY_ACCESS_RESULT = 0;
+const unsigned int D3D11_VIEWPORT_AND_SCISSORRECT_MAX_INDEX = 15;
+const unsigned int D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE = 16;
+const unsigned int D3D11_VIEWPORT_BOUNDS_MAX = 32767;
+const int D3D11_VIEWPORT_BOUNDS_MIN = -32768;
+const unsigned int D3D11_VS_INPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_VS_INPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_VS_INPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_VS_INPUT_REGISTER_READ_PORTS = 1;
+const unsigned int D3D11_VS_INPUT_REGISTER_READS_PER_INST = 2;
+const unsigned int D3D11_VS_OUTPUT_REGISTER_COMPONENT_BIT_COUNT = 32;
+const unsigned int D3D11_VS_OUTPUT_REGISTER_COMPONENTS = 4;
+const unsigned int D3D11_VS_OUTPUT_REGISTER_COUNT = 32;
+const unsigned int D3D11_WHQL_CONTEXT_COUNT_FOR_RESOURCE_LIMIT = 10;
+const unsigned int D3D11_WHQL_DRAWINDEXED_INDEX_COUNT_2_TO_EXP = 25;
+const unsigned int D3D11_WHQL_DRAW_VERTEX_COUNT_2_TO_EXP = 25;
+cpp_quote("#endif")
+
+const unsigned int _FACD3D11 = 0x87C;
+const unsigned int _FACD3D11DEBUG = _FACD3D11 + 1;
+
+cpp_quote("#define MAKE_D3D11_HRESULT(c) MAKE_HRESULT(1, _FACD3D11, (c))")
+cpp_quote("#define MAKE_D3D11_STATUS(c) MAKE_HRESULT(0, _FACD3D11, (c))")
+cpp_quote("#define D3D11_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS MAKE_D3D11_HRESULT(1)")
+cpp_quote("#define D3D11_ERROR_FILE_NOT_FOUND MAKE_D3D11_HRESULT(2)")
+cpp_quote("#define D3D11_ERROR_TOO_MANY_UNIQUE_VIEW_OBJECTS MAKE_D3D11_HRESULT(3)")
+cpp_quote("#define D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD MAKE_D3D11_HRESULT(4)")
+
+typedef enum D3D11_INPUT_CLASSIFICATION
+{
+ D3D11_INPUT_PER_VERTEX_DATA,
+ D3D11_INPUT_PER_INSTANCE_DATA
+} D3D11_INPUT_CLASSIFICATION;
+
+const unsigned int D3D11_APPEND_ALIGNED_ELEMENT = 0xffffffff;
+
+typedef struct D3D11_INPUT_ELEMENT_DESC
+{
+ LPCSTR SemanticName;
+ UINT SemanticIndex;
+ DXGI_FORMAT Format;
+ UINT InputSlot;
+ UINT AlignedByteOffset;
+ D3D11_INPUT_CLASSIFICATION InputSlotClass;
+ UINT InstanceDataStepRate;
+} D3D11_INPUT_ELEMENT_DESC;
+
+typedef enum D3D11_FILL_MODE
+{
+ D3D11_FILL_WIREFRAME = 2,
+ D3D11_FILL_SOLID = 3
+} D3D11_FILL_MODE;
+
+typedef D3D_PRIMITIVE_TOPOLOGY D3D11_PRIMITIVE_TOPOLOGY;
+
+typedef D3D_PRIMITIVE D3D11_PRIMITIVE;
+
+typedef enum D3D11_CULL_MODE
+{
+ D3D11_CULL_NONE = 1,
+ D3D11_CULL_FRONT = 2,
+ D3D11_CULL_BACK = 3
+} D3D11_CULL_MODE;
+
+typedef struct D3D11_SO_DECLARATION_ENTRY
+{
+ UINT Stream;
+ LPCSTR SemanticName;
+ UINT SemanticIndex;
+ BYTE StartComponent;
+ BYTE ComponentCount;
+ BYTE OutputSlot;
+} D3D11_SO_DECLARATION_ENTRY;
+
+typedef struct D3D11_VIEWPORT
+{
+ FLOAT TopLeftX;
+ FLOAT TopLeftY;
+ FLOAT Width;
+ FLOAT Height;
+ FLOAT MinDepth;
+ FLOAT MaxDepth;
+} D3D11_VIEWPORT;
+
+typedef enum D3D11_RESOURCE_DIMENSION
+{
+ D3D11_RESOURCE_DIMENSION_UNKNOWN,
+ D3D11_RESOURCE_DIMENSION_BUFFER,
+ D3D11_RESOURCE_DIMENSION_TEXTURE1D,
+ D3D11_RESOURCE_DIMENSION_TEXTURE2D,
+ D3D11_RESOURCE_DIMENSION_TEXTURE3D,
+} D3D11_RESOURCE_DIMENSION;
+
+typedef D3D_SRV_DIMENSION D3D11_SRV_DIMENSION;
+
+typedef enum D3D11_DSV_DIMENSION
+{
+ D3D11_DSV_DIMENSION_UNKNOWN,
+ D3D11_DSV_DIMENSION_TEXTURE1D,
+ D3D11_DSV_DIMENSION_TEXTURE1DARRAY,
+ D3D11_DSV_DIMENSION_TEXTURE2D,
+ D3D11_DSV_DIMENSION_TEXTURE2DARRAY,
+ D3D11_DSV_DIMENSION_TEXTURE2DMS,
+ D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY,
+} D3D11_DSV_DIMENSION;
+
+
+typedef enum D3D11_RTV_DIMENSION
+{
+ D3D11_RTV_DIMENSION_UNKNOWN,
+ D3D11_RTV_DIMENSION_BUFFER,
+ D3D11_RTV_DIMENSION_TEXTURE1D,
+ D3D11_RTV_DIMENSION_TEXTURE1DARRAY,
+ D3D11_RTV_DIMENSION_TEXTURE2D,
+ D3D11_RTV_DIMENSION_TEXTURE2DARRAY,
+ D3D11_RTV_DIMENSION_TEXTURE2DMS,
+ D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY,
+ D3D11_RTV_DIMENSION_TEXTURE3D
+} D3D11_RTV_DIMENSION;
+
+typedef enum D3D11_UAV_DIMENSION
+{
+ D3D11_UAV_DIMENSION_UNKNOWN,
+ D3D11_UAV_DIMENSION_BUFFER,
+ D3D11_UAV_DIMENSION_TEXTURE1D,
+ D3D11_UAV_DIMENSION_TEXTURE1DARRAY,
+ D3D11_UAV_DIMENSION_TEXTURE2D,
+ D3D11_UAV_DIMENSION_TEXTURE2DARRAY,
+ D3D11_UAV_DIMENSION_TEXTURE3D = 8
+} D3D11_UAV_DIMENSION;
+
+typedef enum D3D11_USAGE
+{
+ D3D11_USAGE_DEFAULT,
+ D3D11_USAGE_IMMUTABLE,
+ D3D11_USAGE_DYNAMIC,
+ D3D11_USAGE_STAGING
+} D3D11_USAGE;
+
+typedef enum D3D11_BIND_FLAG
+{
+ D3D11_BIND_VERTEX_BUFFER = 1,
+ D3D11_BIND_INDEX_BUFFER = 2,
+ D3D11_BIND_CONSTANT_BUFFER = 4,
+ D3D11_BIND_SHADER_RESOURCE = 8,
+ D3D11_BIND_STREAM_OUTPUT = 0x10,
+ D3D11_BIND_RENDER_TARGET = 0x20,
+ D3D11_BIND_DEPTH_STENCIL = 0x40,
+ D3D11_BIND_UNORDERED_ACCESS = 0x80
+} D3D11_BIND_FLAG;
+
+typedef enum D3D11_CPU_ACCESS_FLAG
+{
+ D3D11_CPU_ACCESS_WRITE = 0x10000,
+ D3D11_CPU_ACCESS_READ = 0x20000
+} D3D11_CPU_ACCESS_FLAG;
+
+typedef enum D3D11_RESOURCE_MISC_FLAG
+{
+ D3D11_RESOURCE_MISC_GENERATE_MIPS = 1,
+ D3D11_RESOURCE_MISC_SHARED = 2,
+ D3D11_RESOURCE_MISC_TEXTURECUBE = 4,
+ D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS = 0x10,
+ D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS = 0x20,
+ D3D11_RESOURCE_MISC_BUFFER_STRUCTURED = 0x40,
+ D3D11_RESOURCE_MISC_RESOURCE_CLAMP = 0x80,
+ D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX = 0x100,
+ D3D11_RESOURCE_MISC_GDI_COMPATIBLE = 0x200
+} D3D11_RESOURCE_MISC_FLAG;
+
+typedef enum D3D11_MAP
+{
+ D3D11_MAP_READ = 1,
+ D3D11_MAP_WRITE,
+ D3D11_MAP_READ_WRITE,
+ D3D11_MAP_WRITE_DISCARD,
+ D3D11_MAP_WRITE_NO_OVERWRITE
+} D3D11_MAP;
+
+typedef enum D3D11_MAP_FLAG
+{
+ D3D11_MAP_FLAG_DO_NOT_WAIT = 0x100000
+} D3D11_MAP_FLAG;
+
+typedef enum D3D11_RAISE_FLAG
+{
+ D3D11_RAISE_FLAG_DRIVER_INTERNAL_ERROR = 1
+} D3D11_RAISE_FLAG;
+
+typedef
+enum D3D11_CLEAR_FLAG
+{
+ D3D11_CLEAR_DEPTH = 1,
+ D3D11_CLEAR_STENCIL = 2
+} D3D11_CLEAR_FLAG;
+
+typedef RECT D3D11_RECT;
+
+typedef struct D3D11_BOX
+{
+ UINT left;
+ UINT top;
+ UINT front;
+ UINT right;
+ UINT bottom;
+ UINT back;
+} D3D11_BOX;
+
+typedef enum D3D11_COMPARISON_FUNC
+{
+ D3D11_COMPARISON_NEVER = 1,
+ D3D11_COMPARISON_LESS,
+ D3D11_COMPARISON_EQUAL,
+ D3D11_COMPARISON_LESS_EQUAL,
+ D3D11_COMPARISON_GREATER,
+ D3D11_COMPARISON_NOT_EQUAL,
+ D3D11_COMPARISON_GREATER_EQUAL,
+ D3D11_COMPARISON_ALWAYS
+} D3D11_COMPARISON_FUNC;
+
+typedef enum D3D11_DEPTH_WRITE_MASK
+{
+ D3D11_DEPTH_WRITE_MASK_ZERO,
+ D3D11_DEPTH_WRITE_MASK_ALL
+} D3D11_DEPTH_WRITE_MASK;
+
+typedef enum D3D11_STENCIL_OP
+{
+ D3D11_STENCIL_OP_KEEP = 1,
+ D3D11_STENCIL_OP_ZERO,
+ D3D11_STENCIL_OP_REPLACE,
+ D3D11_STENCIL_OP_INCR_SAT,
+ D3D11_STENCIL_OP_DECR_SAT,
+ D3D11_STENCIL_OP_INVERT,
+ D3D11_STENCIL_OP_INCR,
+ D3D11_STENCIL_OP_DECR
+} D3D11_STENCIL_OP;
+
+typedef struct D3D11_DEPTH_STENCILOP_DESC
+{
+ D3D11_STENCIL_OP StencilFailOp;
+ D3D11_STENCIL_OP StencilDepthFailOp;
+ D3D11_STENCIL_OP StencilPassOp;
+ D3D11_COMPARISON_FUNC StencilFunc;
+} D3D11_DEPTH_STENCILOP_DESC;
+
+typedef struct D3D11_DEPTH_STENCIL_DESC
+{
+ BOOL DepthEnable;
+ D3D11_DEPTH_WRITE_MASK DepthWriteMask;
+ D3D11_COMPARISON_FUNC DepthFunc;
+ BOOL StencilEnable;
+ UINT8 StencilReadMask;
+ UINT8 StencilWriteMask;
+ D3D11_DEPTH_STENCILOP_DESC FrontFace;
+ D3D11_DEPTH_STENCILOP_DESC BackFace;
+} D3D11_DEPTH_STENCIL_DESC;
+
+
+typedef enum D3D11_BLEND
+{
+ D3D11_BLEND_ZERO = 1,
+ D3D11_BLEND_ONE,
+ D3D11_BLEND_SRC_COLOR,
+ D3D11_BLEND_INV_SRC_COLOR,
+ D3D11_BLEND_SRC_ALPHA,
+ D3D11_BLEND_INV_SRC_ALPHA,
+ D3D11_BLEND_DEST_ALPHA,
+ D3D11_BLEND_INV_DEST_ALPHA,
+ D3D11_BLEND_DEST_COLOR,
+ D3D11_BLEND_INV_DEST_COLOR ,
+ D3D11_BLEND_SRC_ALPHA_SAT,
+
+ D3D11_BLEND_BLEND_FACTOR = 14,
+ D3D11_BLEND_INV_BLEND_FACTOR,
+ D3D11_BLEND_SRC1_COLOR,
+ D3D11_BLEND_INV_SRC1_COLOR ,
+ D3D11_BLEND_SRC1_ALPHA,
+ D3D11_BLEND_INV_SRC1_ALPHA
+} D3D11_BLEND;
+
+typedef enum D3D11_BLEND_OP
+{
+ D3D11_BLEND_OP_ADD = 1,
+ D3D11_BLEND_OP_SUBTRACT,
+ D3D11_BLEND_OP_REV_SUBTRACT,
+ D3D11_BLEND_OP_MIN,
+ D3D11_BLEND_OP_MAX
+} D3D11_BLEND_OP;
+
+typedef enum D3D11_COLOR_WRITE_ENABLE
+{
+ D3D11_COLOR_WRITE_ENABLE_RED = 1,
+ D3D11_COLOR_WRITE_ENABLE_GREEN = 2,
+ D3D11_COLOR_WRITE_ENABLE_BLUE = 4,
+ D3D11_COLOR_WRITE_ENABLE_ALPHA = 8,
+ D3D11_COLOR_WRITE_ENABLE_ALL = 0xf
+} D3D11_COLOR_WRITE_ENABLE;
+
+typedef struct D3D11_RENDER_TARGET_BLEND_DESC
+{
+ BOOL BlendEnable;
+ D3D11_BLEND SrcBlend;
+ D3D11_BLEND DestBlend;
+ D3D11_BLEND_OP BlendOp;
+ D3D11_BLEND SrcBlendAlpha;
+ D3D11_BLEND DestBlendAlpha;
+ D3D11_BLEND_OP BlendOpAlpha;
+ UINT8 RenderTargetWriteMask;
+} D3D11_RENDER_TARGET_BLEND_DESC;
+
+typedef struct D3D11_BLEND_DESC
+{
+ BOOL AlphaToCoverageEnable;
+ BOOL IndependentBlendEnable;
+ D3D11_RENDER_TARGET_BLEND_DESC RenderTarget[8];
+} D3D11_BLEND_DESC;
+
+typedef struct D3D11_RASTERIZER_DESC
+{
+ D3D11_FILL_MODE FillMode;
+ D3D11_CULL_MODE CullMode;
+ BOOL FrontCounterClockwise;
+ INT DepthBias;
+ FLOAT DepthBiasClamp;
+ FLOAT SlopeScaledDepthBias;
+ BOOL DepthClipEnable;
+ BOOL ScissorEnable;
+ BOOL MultisampleEnable;
+ BOOL AntialiasedLineEnable;
+} D3D11_RASTERIZER_DESC;
+
+typedef struct D3D11_SUBRESOURCE_DATA
+{
+ const void *pSysMem;
+ UINT SysMemPitch;
+ UINT SysMemSlicePitch;
+} D3D11_SUBRESOURCE_DATA;
+
+typedef struct D3D11_MAPPED_SUBRESOURCE
+{
+ void *pData;
+ UINT RowPitch;
+ UINT DepthPitch;
+} D3D11_MAPPED_SUBRESOURCE;
+
+typedef struct D3D11_BUFFER_DESC
+{
+ UINT ByteWidth;
+ D3D11_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+ UINT StructureByteStride;
+} D3D11_BUFFER_DESC;
+
+typedef struct D3D11_TEXTURE1D_DESC
+{
+ UINT Width;
+ UINT MipLevels;
+ UINT ArraySize;
+ DXGI_FORMAT Format;
+ D3D11_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+} D3D11_TEXTURE1D_DESC;
+
+typedef struct D3D11_TEXTURE2D_DESC
+{
+ UINT Width;
+ UINT Height;
+ UINT MipLevels;
+ UINT ArraySize;
+ DXGI_FORMAT Format;
+ DXGI_SAMPLE_DESC SampleDesc;
+ D3D11_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+} D3D11_TEXTURE2D_DESC;
+
+typedef struct D3D11_TEXTURE3D_DESC
+{
+ UINT Width;
+ UINT Height;
+ UINT Depth;
+ UINT MipLevels;
+ DXGI_FORMAT Format;
+ D3D11_USAGE Usage;
+ UINT BindFlags;
+ UINT CPUAccessFlags;
+ UINT MiscFlags;
+} D3D11_TEXTURE3D_DESC;
+
+typedef enum D3D11_TEXTURECUBE_FACE
+{
+ D3D11_TEXTURECUBE_FACE_POSITIVE_X,
+ D3D11_TEXTURECUBE_FACE_NEGATIVE_X,
+ D3D11_TEXTURECUBE_FACE_POSITIVE_Y,
+ D3D11_TEXTURECUBE_FACE_NEGATIVE_Y,
+ D3D11_TEXTURECUBE_FACE_POSITIVE_Z,
+ D3D11_TEXTURECUBE_FACE_NEGATIVE_Z
+} D3D11_TEXTURECUBE_FACE;
+
+typedef struct D3D11_BUFFER_SRV
+{
+ union
+ {
+ UINT FirstElement;
+ UINT ElementOffset;
+ };
+ union
+ {
+ UINT NumElements;
+ UINT ElementWidth;
+ };
+} D3D11_BUFFER_SRV;
+
+typedef enum D3D11_BUFFEREX_SRV_FLAG
+{
+ D3D11_BUFFEREX_SRV_FLAG_RAW = 1
+} D3D11_BUFFEREX_SRV_FLAG;
+
+typedef struct D3D11_BUFFEREX_SRV
+{
+ UINT FirstElement;
+ UINT NumElements;
+ UINT Flags;
+} D3D11_BUFFEREX_SRV;
+
+typedef struct D3D11_TEX1D_SRV
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D11_TEX1D_SRV;
+
+typedef struct D3D11_TEX1D_ARRAY_SRV
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX1D_ARRAY_SRV;
+
+typedef struct D3D11_TEX2D_SRV
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D11_TEX2D_SRV;
+
+typedef struct D3D11_TEX2D_ARRAY_SRV
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX2D_ARRAY_SRV;
+
+typedef struct D3D11_TEX3D_SRV
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D11_TEX3D_SRV;
+
+typedef struct D3D11_TEXCUBE_SRV
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+} D3D11_TEXCUBE_SRV;
+
+typedef struct D3D11_TEXCUBE_ARRAY_SRV
+{
+ UINT MostDetailedMip;
+ UINT MipLevels;
+ UINT First2DArrayFace;
+ UINT NumCubes;
+} D3D11_TEXCUBE_ARRAY_SRV;
+
+typedef struct D3D11_TEX2DMS_SRV
+{
+ UINT UnusedField_NothingToDefine;
+} D3D11_TEX2DMS_SRV;
+
+typedef struct D3D11_TEX2DMS_ARRAY_SRV
+{
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX2DMS_ARRAY_SRV;
+
+typedef struct D3D11_SHADER_RESOURCE_VIEW_DESC
+{
+ DXGI_FORMAT Format;
+ D3D11_SRV_DIMENSION ViewDimension;
+ union
+ {
+ D3D11_BUFFER_SRV Buffer;
+ D3D11_TEX1D_SRV Texture1D;
+ D3D11_TEX1D_ARRAY_SRV Texture1DArray;
+ D3D11_TEX2D_SRV Texture2D;
+ D3D11_TEX2D_ARRAY_SRV Texture2DArray;
+ D3D11_TEX2DMS_SRV Texture2DMS;
+ D3D11_TEX2DMS_ARRAY_SRV Texture2DMSArray;
+ D3D11_TEX3D_SRV Texture3D;
+ D3D11_TEXCUBE_SRV TextureCube;
+ D3D11_TEXCUBE_ARRAY_SRV TextureCubeArray;
+ D3D11_BUFFEREX_SRV BufferEx;
+ };
+} D3D11_SHADER_RESOURCE_VIEW_DESC;
+
+
+typedef struct D3D11_BUFFER_RTV
+{
+ union
+ {
+ UINT FirstElement;
+ UINT ElementOffset;
+ };
+ union
+ {
+ UINT NumElements;
+ UINT ElementWidth;
+ };
+} D3D11_BUFFER_RTV;
+
+typedef struct D3D11_TEX1D_RTV
+{
+ UINT MipSlice;
+} D3D11_TEX1D_RTV;
+
+typedef struct D3D11_TEX1D_ARRAY_RTV
+{
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX1D_ARRAY_RTV;
+
+typedef struct D3D11_TEX2D_RTV
+{
+ UINT MipSlice;
+} D3D11_TEX2D_RTV;
+
+typedef struct D3D11_TEX2DMS_RTV
+{
+ UINT UnusedField_NothingToDefine;
+} D3D11_TEX2DMS_RTV;
+
+typedef struct D3D11_TEX2D_ARRAY_RTV
+{
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX2D_ARRAY_RTV;
+
+typedef struct D3D11_TEX2DMS_ARRAY_RTV
+{
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX2DMS_ARRAY_RTV;
+
+typedef struct D3D11_TEX3D_RTV
+{
+ UINT MipSlice;
+ UINT FirstWSlice;
+ UINT WSize;
+} D3D11_TEX3D_RTV;
+
+typedef struct D3D11_RENDER_TARGET_VIEW_DESC
+{
+ DXGI_FORMAT Format;
+ D3D11_RTV_DIMENSION ViewDimension;
+ union
+ {
+ D3D11_BUFFER_RTV Buffer;
+ D3D11_TEX1D_RTV Texture1D;
+ D3D11_TEX1D_ARRAY_RTV Texture1DArray;
+ D3D11_TEX2D_RTV Texture2D;
+ D3D11_TEX2D_ARRAY_RTV Texture2DArray;
+ D3D11_TEX2DMS_RTV Texture2DMS;
+ D3D11_TEX2DMS_ARRAY_RTV Texture2DMSArray;
+ D3D11_TEX3D_RTV Texture3D;
+ };
+} D3D11_RENDER_TARGET_VIEW_DESC;
+
+typedef struct D3D11_TEX1D_DSV
+{
+ UINT MipSlice;
+} D3D11_TEX1D_DSV;
+
+typedef struct D3D11_TEX1D_ARRAY_DSV
+{
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX1D_ARRAY_DSV;
+
+typedef struct D3D11_TEX2D_DSV
+{
+ UINT MipSlice;
+} D3D11_TEX2D_DSV;
+
+typedef struct D3D11_TEX2D_ARRAY_DSV
+{
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX2D_ARRAY_DSV;
+
+typedef struct D3D11_TEX2DMS_DSV
+{
+ UINT UnusedField_NothingToDefine;
+} D3D11_TEX2DMS_DSV;
+
+typedef struct D3D11_TEX2DMS_ARRAY_DSV
+{
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX2DMS_ARRAY_DSV;
+
+typedef enum D3D11_DSV_FLAG
+{
+ D3D11_DSV_READ_ONLY_DEPTH = 1L,
+ D3D11_DSV_READ_ONLY_STENCIL = 2L
+} D3D11_DSV_FLAG;
+
+typedef struct D3D11_DEPTH_STENCIL_VIEW_DESC
+{
+ DXGI_FORMAT Format;
+ D3D11_DSV_DIMENSION ViewDimension;
+ UINT Flags;
+ union
+ {
+ D3D11_TEX1D_DSV Texture1D;
+ D3D11_TEX1D_ARRAY_DSV Texture1DArray;
+ D3D11_TEX2D_DSV Texture2D;
+ D3D11_TEX2D_ARRAY_DSV Texture2DArray;
+ D3D11_TEX2DMS_DSV Texture2DMS;
+ D3D11_TEX2DMS_ARRAY_DSV Texture2DMSArray;
+ };
+} D3D11_DEPTH_STENCIL_VIEW_DESC;
+
+typedef enum D3D11_BUFFER_UAV_FLAG
+{
+ D3D11_BUFFER_UAV_FLAG_RAW = 1,
+ D3D11_BUFFER_UAV_FLAG_APPEND = 2,
+ D3D11_BUFFER_UAV_FLAG_COUNTER = 4
+} D3D11_BUFFER_UAV_FLAG;
+
+typedef struct D3D11_BUFFER_UAV
+{
+ UINT FirstElement;
+ UINT NumElements;
+ UINT Flags;
+} D3D11_BUFFER_UAV;
+
+typedef struct D3D11_TEX1D_UAV
+{
+ UINT MipSlice;
+} D3D11_TEX1D_UAV;
+
+typedef struct D3D11_TEX1D_ARRAY_UAV
+{
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX1D_ARRAY_UAV;
+
+typedef struct D3D11_TEX2D_UAV
+{
+ UINT MipSlice;
+} D3D11_TEX2D_UAV;
+
+typedef struct D3D11_TEX2D_ARRAY_UAV
+{
+ UINT MipSlice;
+ UINT FirstArraySlice;
+ UINT ArraySize;
+} D3D11_TEX2D_ARRAY_UAV;
+
+typedef struct D3D11_TEX3D_UAV
+{
+ UINT MipSlice;
+ UINT FirstWSlice;
+ UINT WSize;
+} D3D11_TEX3D_UAV;
+
+typedef struct D3D11_UNORDERED_ACCESS_VIEW_DESC
+{
+ DXGI_FORMAT Format;
+ D3D11_UAV_DIMENSION ViewDimension;
+ union
+ {
+ D3D11_BUFFER_UAV Buffer;
+ D3D11_TEX1D_UAV Texture1D;
+ D3D11_TEX1D_ARRAY_UAV Texture1DArray;
+ D3D11_TEX2D_UAV Texture2D;
+ D3D11_TEX2D_ARRAY_UAV Texture2DArray;
+ D3D11_TEX3D_UAV Texture3D;
+ };
+} D3D11_UNORDERED_ACCESS_VIEW_DESC;
+
+typedef enum D3D11_FILTER
+{
+ D3D11_FILTER_MIN_MAG_MIP_POINT = 0,
+ D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR = 1,
+ D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT = 4,
+ D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR = 5,
+ D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT = 0x10,
+ D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x11,
+ D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT = 0x14,
+ D3D11_FILTER_MIN_MAG_MIP_LINEAR = 0x15,
+ D3D11_FILTER_ANISOTROPIC = 0x55,
+ D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT = 0x80,
+ D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR = 0x81,
+ D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT = 0x84,
+ D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR = 0x85,
+ D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT = 0x90,
+ D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR = 0x91,
+ D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT = 0x94,
+ D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR = 0x95,
+ D3D11_FILTER_COMPARISON_ANISOTROPIC = 0xd5
+} D3D11_FILTER;
+
+typedef enum D3D11_FILTER_TYPE
+{
+ D3D11_FILTER_TYPE_POINT,
+ D3D11_FILTER_TYPE_LINEAR
+} D3D11_FILTER_TYPE;
+
+const unsigned int D3D11_FILTER_TYPE_MASK = 3;
+const unsigned int D3D11_MIN_FILTER_SHIFT = 4;
+const unsigned int D3D11_MAG_FILTER_SHIFT = 2;
+const unsigned int D3D11_MIP_FILTER_SHIFT = 0;
+const unsigned int D3D11_COMPARISON_FILTERING_BIT = 0x80;
+const unsigned int D3D11_ANISOTROPIC_FILTERING_BIT = 0x40;
+
+cpp_quote("#define D3D11_ENCODE_BASIC_FILTER(min, mag, mip, comp) ((D3D11_FILTER) (((comp) ? D3D11_COMPARISON_FILTERING_BIT : 0 ) | (((min) & D3D11_FILTER_TYPE_MASK ) << D3D11_MIN_FILTER_SHIFT ) | (((mag) & D3D11_FILTER_TYPE_MASK ) << D3D11_MAG_FILTER_SHIFT ) | (((mip) & D3D11_FILTER_TYPE_MASK) << D3D11_MIP_FILTER_SHIFT)))")
+cpp_quote("#define D3D11_ENCODE_ANISOTROPIC_FILTER(comp) ((D3D11_FILTER)(D3D11_ANISOTROPIC_FILTERING_BIT | D3D11_ENCODE_BASIC_FILTER(D3D11_FILTER_TYPE_LINEAR, D3D11_FILTER_TYPE_LINEAR, D3D11_FILTER_TYPE_LINEAR, comp)))")
+cpp_quote("#define D3D11_DECODE_MIN_FILTER(f) ((D3D11_FILTER_TYPE)(((f) >> D3D11_MIN_FILTER_SHIFT) & D3D11_FILTER_TYPE_MASK))")
+cpp_quote("#define D3D11_DECODE_MAG_FILTER(f) ((D3D11_FILTER_TYPE)(((f) >> D3D11_MAG_FILTER_SHIFT) & D3D11_FILTER_TYPE_MASK))")
+cpp_quote("#define D3D11_DECODE_MIP_FILTER(f) ((D3D11_FILTER_TYPE)(((f) >> D3D11_MIP_FILTER_SHIFT) & D3D11_FILTER_TYPE_MASK))")
+cpp_quote("#define D3D11_DECODE_IS_COMPARISON_FILTER(f) ((f) & D3D11_COMPARISON_FILTERING_BIT)")
+cpp_quote("#define D3D11_DECODE_IS_ANISOTROPIC_FILTER(f) (((f) & D3D11_ANISOTROPIC_FILTERING_BIT) && (D3D11_DECODE_MIN_FILTER(f) == D3D11_FILTER_TYPE_LINEAR) && (D3D11_DECODE_MAG_FILTER(f) == D3D11_FILTER_TYPE_LINEAR) && (D3D11_DECODE_MIP_FILTER( f ) == D3D11_FILTER_TYPE_LINEAR))")
+
+typedef enum D3D11_TEXTURE_ADDRESS_MODE
+{
+ D3D11_TEXTURE_ADDRESS_WRAP = 1,
+ D3D11_TEXTURE_ADDRESS_MIRROR = 2,
+ D3D11_TEXTURE_ADDRESS_CLAMP = 3,
+ D3D11_TEXTURE_ADDRESS_BORDER = 4,
+ D3D11_TEXTURE_ADDRESS_MIRROR_ONCE = 5
+} D3D11_TEXTURE_ADDRESS_MODE;
+
+typedef struct D3D11_SAMPLER_DESC
+{
+ D3D11_FILTER Filter;
+ D3D11_TEXTURE_ADDRESS_MODE AddressU;
+ D3D11_TEXTURE_ADDRESS_MODE AddressV;
+ D3D11_TEXTURE_ADDRESS_MODE AddressW;
+ FLOAT MipLODBias;
+ UINT MaxAnisotropy;
+ D3D11_COMPARISON_FUNC ComparisonFunc;
+ FLOAT BorderColor[ 4 ];
+ FLOAT MinLOD;
+ FLOAT MaxLOD;
+} D3D11_SAMPLER_DESC;
+
+typedef enum D3D11_FORMAT_SUPPORT
+{
+ D3D11_FORMAT_SUPPORT_BUFFER = 0x1,
+ D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER = 0x2,
+ D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER = 0x4,
+ D3D11_FORMAT_SUPPORT_SO_BUFFER = 0x8,
+ D3D11_FORMAT_SUPPORT_TEXTURE1D = 0x10,
+ D3D11_FORMAT_SUPPORT_TEXTURE2D = 0x20,
+ D3D11_FORMAT_SUPPORT_TEXTURE3D = 0x40,
+ D3D11_FORMAT_SUPPORT_TEXTURECUBE = 0x80,
+ D3D11_FORMAT_SUPPORT_SHADER_LOAD = 0x100,
+ D3D11_FORMAT_SUPPORT_SHADER_SAMPLE = 0x200,
+ D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON = 0x400,
+ D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_MONO_TEXT = 0x800,
+ D3D11_FORMAT_SUPPORT_MIP = 0x1000,
+ D3D11_FORMAT_SUPPORT_MIP_AUTOGEN = 0x2000,
+ D3D11_FORMAT_SUPPORT_RENDER_TARGET = 0x4000,
+ D3D11_FORMAT_SUPPORT_BLENDABLE = 0x8000,
+ D3D11_FORMAT_SUPPORT_DEPTH_STENCIL = 0x10000,
+ D3D11_FORMAT_SUPPORT_CPU_LOCKABLE = 0x20000,
+ D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE = 0x40000,
+ D3D11_FORMAT_SUPPORT_DISPLAY = 0x80000,
+ D3D11_FORMAT_SUPPORT_CAST_WITHIN_BIT_LAYOUT = 0x100000,
+ D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET = 0x200000,
+ D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD = 0x400000,
+ D3D11_FORMAT_SUPPORT_SHADER_GATHER = 0x800000,
+ D3D11_FORMAT_SUPPORT_BACK_BUFFER_CAST = 0x1000000,
+ D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW = 0x2000000,
+ D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON = 0x4000000
+} D3D11_FORMAT_SUPPORT;
+
+typedef enum D3D11_FORMAT_SUPPORT2
+{
+ D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_ADD = 1,
+ D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_BITWISE_OPS = 2,
+ D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_COMPARE_STORE_OR_COMPARE_EXCHANGE = 4,
+ D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_EXCHANGE = 8,
+ D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_SIGNED_MIN_OR_MAX = 0x10,
+ D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_UNSIGNED_MIN_OR_MAX = 0x20,
+ D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD = 0x40,
+ D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE = 0x80
+} D3D11_FORMAT_SUPPORT2;
+
+typedef enum D3D11_ASYNC_GETDATA_FLAG
+{
+ D3D11_ASYNC_GETDATA_DONOTFLUSH = 1
+} D3D11_ASYNC_GETDATA_FLAG;
+
+typedef enum D3D11_QUERY
+{
+ D3D11_QUERY_EVENT,
+ D3D11_QUERY_OCCLUSION,
+ D3D11_QUERY_TIMESTAMP,
+ D3D11_QUERY_TIMESTAMP_DISJOINT,
+ D3D11_QUERY_PIPELINE_STATISTICS,
+ D3D11_QUERY_OCCLUSION_PREDICATE,
+ D3D11_QUERY_SO_STATISTICS,
+ D3D11_QUERY_SO_OVERFLOW_PREDICATE,
+ D3D11_QUERY_SO_STATISTICS_STREAM0,
+ D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0,
+ D3D11_QUERY_SO_STATISTICS_STREAM1,
+ D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1,
+ D3D11_QUERY_SO_STATISTICS_STREAM2,
+ D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2,
+ D3D11_QUERY_SO_STATISTICS_STREAM3,
+ D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3,
+} D3D11_QUERY;
+
+typedef enum D3D11_QUERY_MISC_FLAG
+{
+ D3D11_QUERY_MISC_PREDICATEHINT = 1
+} D3D11_QUERY_MISC_FLAG;
+
+typedef struct D3D11_QUERY_DESC
+{
+ D3D11_QUERY Query;
+ UINT MiscFlags;
+} D3D11_QUERY_DESC;
+
+typedef struct D3D11_QUERY_DATA_TIMESTAMP_DISJOINT
+{
+ UINT64 Frequency;
+ BOOL Disjoint;
+} D3D11_QUERY_DATA_TIMESTAMP_DISJOINT;
+
+typedef struct D3D11_QUERY_DATA_PIPELINE_STATISTICS
+{
+ UINT64 IAVertices;
+ UINT64 IAPrimitives;
+ UINT64 VSInvocations;
+ UINT64 GSInvocations;
+ UINT64 GSPrimitives;
+ UINT64 CInvocations;
+ UINT64 CPrimitives;
+ UINT64 PSInvocations;
+ UINT64 HSInvocations;
+ UINT64 DSInvocations;
+ UINT64 CSInvocations;
+} D3D11_QUERY_DATA_PIPELINE_STATISTICS;
+
+typedef struct D3D11_QUERY_DATA_SO_STATISTICS
+{
+ UINT64 NumPrimitivesWritten;
+ UINT64 PrimitivesStorageNeeded;
+} D3D11_QUERY_DATA_SO_STATISTICS;
+
+typedef enum D3D11_COUNTER
+{
+ D3D11_COUNTER_DEVICE_DEPENDENT_0 = 0x40000000
+} D3D11_COUNTER;
+
+typedef enum D3D11_COUNTER_TYPE
+{
+ D3D11_COUNTER_TYPE_FLOAT32,
+ D3D11_COUNTER_TYPE_UINT16,
+ D3D11_COUNTER_TYPE_UINT32,
+ D3D11_COUNTER_TYPE_UINT64,
+} D3D11_COUNTER_TYPE;
+
+typedef struct D3D11_COUNTER_DESC
+{
+ D3D11_COUNTER Counter;
+ UINT MiscFlags;
+} D3D11_COUNTER_DESC;
+
+typedef struct D3D11_COUNTER_INFO
+{
+ D3D11_COUNTER LastDeviceDependentCounter;
+ UINT NumSimultaneousCounters;
+ UINT8 NumDetectableParallelUnits;
+} D3D11_COUNTER_INFO;
+
+typedef enum D3D11_STANDARD_MULTISAMPLE_QUALITY_LEVELS
+{
+ D3D11_STANDARD_MULTISAMPLE_PATTERN = 0xffffffff,
+ D3D11_CENTER_MULTISAMPLE_PATTERN = 0xfffffffe
+} D3D11_STANDARD_MULTISAMPLE_QUALITY_LEVELS;
+
+typedef enum D3D11_DEVICE_CONTEXT_TYPE
+{
+ D3D11_DEVICE_CONTEXT_IMMEDIATE,
+ D3D11_DEVICE_CONTEXT_DEFERRED,
+} D3D11_DEVICE_CONTEXT_TYPE;
+
+typedef struct D3D11_CLASS_INSTANCE_DESC
+{
+ UINT InstanceId;
+ UINT InstanceIndex;
+ UINT TypeId;
+ UINT ConstantBuffer;
+ UINT BaseConstantBufferOffset;
+ UINT BaseTexture;
+ UINT BaseSampler;
+ BOOL Created;
+} D3D11_CLASS_INSTANCE_DESC;
+
+typedef enum D3D11_FEATURE
+{
+ D3D11_FEATURE_THREADING,
+ D3D11_FEATURE_DOUBLES,
+ D3D11_FEATURE_FORMAT_SUPPORT,
+ D3D11_FEATURE_FORMAT_SUPPORT2,
+ D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS,
+} D3D11_FEATURE;
+
+typedef struct D3D11_FEATURE_DATA_THREADING
+{
+ BOOL DriverConcurrentCreates;
+ BOOL DriverCommandLists;
+} D3D11_FEATURE_DATA_THREADING;
+
+typedef struct D3D11_FEATURE_DATA_DOUBLES
+{
+ BOOL DoublePrecisionFloatShaderOps;
+} D3D11_FEATURE_DATA_DOUBLES;
+
+typedef struct D3D11_FEATURE_DATA_FORMAT_SUPPORT
+{
+ DXGI_FORMAT InFormat;
+ UINT OutFormatSupport;
+} D3D11_FEATURE_DATA_FORMAT_SUPPORT;
+
+typedef struct D3D11_FEATURE_DATA_FORMAT_SUPPORT2
+{
+ DXGI_FORMAT InFormat;
+ UINT OutFormatSupport2;
+} D3D11_FEATURE_DATA_FORMAT_SUPPORT2;
+
+typedef struct D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS
+{
+ BOOL ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
+} D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS;
+
+interface ID3D11Device;
+
+[object, local, uuid("1841e5c8-16b0-489b-bcc8-44cfb0d5deae")]
+interface ID3D11DeviceChild : IUnknown {
+ void GetDevice(
+ [out] ID3D11Device **ppDevice
+ );
+
+ HRESULT GetPrivateData(
+ [in] REFGUID guid,
+ [in, out] UINT *pDataSize,
+ [out] void *pData
+ );
+
+ HRESULT SetPrivateData(
+ [in] REFGUID guid,
+ [in] UINT DataSize,
+ [in] const void *pData
+ );
+
+ HRESULT SetPrivateDataInterface(
+ [in] REFGUID guid,
+ [in] const IUnknown *pData
+ );
+};
+
+[object, local, uuid("e4819ddc-4cf0-4025-bd26-5de82a3e07b7")]
+interface ID3D11InputLayout : ID3D11DeviceChild
+{
+};
+
+[object, local, uuid("03823efb-8d8f-4e1c-9aa2-f64bb2cbfdf1")]
+interface ID3D11DepthStencilState : ID3D11DeviceChild {
+ void GetDesc(
+ [out] D3D11_DEPTH_STENCIL_DESC *pDesc
+ );
+};
+
+[object, local, uuid("75b68faa-347d-4159-8f45-a0640f01cd9a")]
+interface ID3D11BlendState : ID3D11DeviceChild {
+ void GetDesc(
+ [out] D3D11_BLEND_DESC *pDesc
+ );
+};
+
+[object, local, uuid("9bb4ab81-ab1a-4d8f-b506-fc04200b6ee7")]
+interface ID3D11RasterizerState : ID3D11DeviceChild {
+ void GetDesc(
+ [out] D3D11_RASTERIZER_DESC *pDesc
+ );
+};
+
+[object, local, uuid("da6fea51-564c-4487-9810-f0d0f9b4e3a5")]
+interface ID3D11SamplerState : ID3D11DeviceChild
+{
+ void GetDesc(
+ [out] D3D11_SAMPLER_DESC *pDesc
+ );
+
+};
+
+[object, local, uuid("dc8e63f3-d12b-4952-b47b-5e45026a862d")]
+interface ID3D11Resource : ID3D11DeviceChild {
+ void GetType(
+ [out] D3D11_RESOURCE_DIMENSION *pResourceDimension
+ );
+
+ void SetEvictionPriority(
+ [in] UINT EvictionPriority
+ );
+
+ UINT GetEvictionPriority(
+ );
+};
+
+[object, local, uuid("48570b85-d1ee-4fcd-a250-eb350722b037")]
+interface ID3D11Buffer : ID3D11Resource {
+ void GetDesc(
+ [out] D3D11_BUFFER_DESC *pDesc
+ );
+
+};
+
+[object, local, uuid("f8fb5c27-c6b3-4f75-a4c8-439af2ef564c")]
+interface ID3D11Texture1D : ID3D11Resource {
+ void GetDesc(
+ [out] D3D11_TEXTURE1D_DESC *pDesc
+ );
+};
+
+[object, local, uuid("6f15aaf2-d208-4e89-9ab4-489535d34f9c")]
+interface ID3D11Texture2D : ID3D11Resource {
+ void GetDesc(
+ [out] D3D11_TEXTURE2D_DESC *pDesc
+ );
+};
+
+[object, local, uuid("037e866e-f56d-4357-a8af-9dabbe6e250e")]
+interface ID3D11Texture3D : ID3D11Resource {
+ void GetDesc(
+ [out] D3D11_TEXTURE3D_DESC *pDesc
+ );
+};
+
+[object, local, uuid("839d1216-bb2e-412b-b7f4-a9dbebe08ed1")]
+interface ID3D11View : ID3D11DeviceChild {
+ void GetResource(
+ [out] ID3D11Resource **ppResource
+ );
+
+};
+
+[object, local, uuid("b0e06fe0-8192-4e1a-b1ca-36d7414710b2")]
+interface ID3D11ShaderResourceView : ID3D11View {
+ void GetDesc(
+ [out] D3D11_SHADER_RESOURCE_VIEW_DESC *pDesc
+ );
+};
+
+[object, local, uuid("dfdba067-0b8d-4865-875b-d7b4516cc164")]
+interface ID3D11RenderTargetView : ID3D11View
+{
+ void GetDesc(
+ [out] D3D11_RENDER_TARGET_VIEW_DESC *pDesc
+ );
+};
+
+[object, local, uuid("9fdac92a-1876-48c3-afad-25b94f84a9b6")]
+interface ID3D11DepthStencilView : ID3D11View
+{
+ void GetDesc(
+ [out] D3D11_DEPTH_STENCIL_VIEW_DESC *pDesc
+ );
+};
+
+[object, local, uuid("28acf509-7f5c-48f6-8611-f316010a6380")]
+interface ID3D11UnorderedAccessView : ID3D11View
+{
+ void GetDesc(
+ [out] D3D11_UNORDERED_ACCESS_VIEW_DESC *pDesc
+ );
+};
+
+[object, local, uuid("3b301d64-d678-4289-8897-22f8928b72f3")]
+interface ID3D11VertexShader : ID3D11DeviceChild
+{
+};
+
+[object, local, uuid("8e5c6061-628a-4c8e-8264-bbe45cb3d5dd")]
+interface ID3D11HullShader : ID3D11DeviceChild
+{
+};
+
+[object, local, uuid("f582c508-0f36-490c-9977-31eece268cfa")]
+interface ID3D11DomainShader : ID3D11DeviceChild
+{
+};
+
+
+[object, local, uuid("38325b96-effb-4022-ba02-2e795b70275c")]
+interface ID3D11GeometryShader : ID3D11DeviceChild
+{
+};
+
+[object, local, uuid("ea82e40d-51dc-4f33-93d4-db7c9125ae8c")]
+interface ID3D11PixelShader : ID3D11DeviceChild
+{
+};
+
+[object, local, uuid("4f5b196e-c2bd-495e-bd01-1fded38e4969")]
+interface ID3D11ComputeShader : ID3D11DeviceChild
+{
+};
+
+[object, local, uuid("4b35d0cd-1e15-4258-9c98-1b1333f6dd3b")]
+interface ID3D11Asynchronous : ID3D11DeviceChild
+{
+ UINT GetDataSize();
+};
+
+[object, local, uuid("d6c00747-87b7-425e-b84d-44d108560afd")]
+interface ID3D11Query : ID3D11Asynchronous
+{
+ void GetDesc(
+ [out] D3D11_QUERY_DESC *pDesc
+ );
+};
+
+[object, local, uuid("9eb576dd-9f77-4d86-81aa-8bab5fe490e2")]
+interface ID3D11Predicate : ID3D11Query
+{
+};
+
+[object, local, uuid("6e8c49fb-a371-4770-b440-29086022b741")]
+interface ID3D11Counter : ID3D11Asynchronous
+{
+ void GetDesc(
+ [out] D3D11_COUNTER_DESC *pDesc
+ );
+};
+
+interface ID3D11ClassLinkage;
+
+[object, local, uuid("a6cd7faa-b0b7-4a2f-9436-8662a65797cb")]
+interface ID3D11ClassInstance : ID3D11DeviceChild
+{
+ void GetClassLinkage(
+ [out] ID3D11ClassLinkage **ppLinkage
+ );
+
+ void GetDesc(
+ [out] D3D11_CLASS_INSTANCE_DESC *pDesc
+ );
+
+ void GetInstanceName(
+ [out] LPSTR pInstanceName,
+ [in, out] SIZE_T *pBufferLength
+ );
+
+ void GetTypeName(
+ [out] LPSTR pTypeName,
+ [in, out] SIZE_T *pBufferLength
+ );
+};
+
+[object, local, uuid("ddf57cba-9543-46e4-a12b-f207a0fe7fed")]
+interface ID3D11ClassLinkage : ID3D11DeviceChild
+{
+ HRESULT GetClassInstance(
+ [in] LPCSTR pClassInstanceName,
+ [in] UINT InstanceIndex,
+ [out] ID3D11ClassInstance **ppInstance
+ );
+
+ HRESULT CreateClassInstance(
+ [in] LPCSTR pClassTypeName,
+ [in] UINT ConstantBufferOffset,
+ [in] UINT ConstantVectorOffset,
+ [in] UINT TextureOffset,
+ [in] UINT SamplerOffset,
+ [out] ID3D11ClassInstance **ppInstance
+ );
+};
+
+[object, local, uuid("a24bc4d1-769e-43f7-8013-98ff566c18e2")]
+interface ID3D11CommandList : ID3D11DeviceChild
+{
+ UINT GetContextFlags();
+};
+
+interface ID3D11DeviceContext;
+
+[object, local, uuid("db6f6ddb-ac77-4e88-8253-819df9bbf140")]
+interface ID3D11Device : IUnknown
+{
+ HRESULT CreateBuffer(
+ [in] const D3D11_BUFFER_DESC *pDesc,
+ [in] const D3D11_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D11Buffer **ppBuffer
+ );
+
+ HRESULT CreateTexture1D(
+ [in] const D3D11_TEXTURE1D_DESC *pDesc,
+ [in] const D3D11_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D11Texture1D **ppTexture1D
+ );
+
+ HRESULT CreateTexture2D(
+ [in] const D3D11_TEXTURE2D_DESC *pDesc,
+ [in] const D3D11_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D11Texture2D **ppTexture2D
+ );
+
+ HRESULT CreateTexture3D(
+ [in] const D3D11_TEXTURE3D_DESC *pDesc,
+ [in] const D3D11_SUBRESOURCE_DATA *pInitialData,
+ [out] ID3D11Texture3D **ppTexture3D
+ );
+
+ HRESULT CreateShaderResourceView(
+ [in] ID3D11Resource *pResource,
+ [in] const D3D11_SHADER_RESOURCE_VIEW_DESC *pDesc,
+ [out] ID3D11ShaderResourceView **ppSRView
+ );
+
+ HRESULT CreateUnorderedAccessView(
+ [in] ID3D11Resource *pResource,
+ [in] const D3D11_UNORDERED_ACCESS_VIEW_DESC *pDesc,
+ [out] ID3D11UnorderedAccessView **ppUAView
+ );
+
+ HRESULT CreateRenderTargetView(
+ [in] ID3D11Resource *pResource,
+ [in] const D3D11_RENDER_TARGET_VIEW_DESC *pDesc,
+ [out] ID3D11RenderTargetView **ppRTView
+ );
+
+ HRESULT CreateDepthStencilView(
+ [in] ID3D11Resource *pResource,
+ [in] const D3D11_DEPTH_STENCIL_VIEW_DESC *pDesc,
+ [out] ID3D11DepthStencilView **ppDepthStencilView
+ );
+
+ HRESULT CreateInputLayout(
+ [in] const D3D11_INPUT_ELEMENT_DESC *pInputElementDescs,
+ [in] UINT NumElements,
+ [in] const void *pShaderBytecodeWithInputSignature,
+ [in] SIZE_T BytecodeLength,
+ [out] ID3D11InputLayout **ppInputLayout
+ );
+
+ HRESULT CreateVertexShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] ID3D11ClassLinkage *pClassLinkage,
+ [out] ID3D11VertexShader **ppVertexShader
+ );
+
+ HRESULT CreateGeometryShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] ID3D11ClassLinkage *pClassLinkage,
+ [out] ID3D11GeometryShader **ppGeometryShader
+ );
+
+ HRESULT CreateGeometryShaderWithStreamOutput(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] const D3D11_SO_DECLARATION_ENTRY *pSODeclaration,
+ [in] UINT NumEntries,
+ [in] const UINT *pBufferStrides,
+ [in] UINT NumStrides,
+ [in] UINT RasterizedStream,
+ [in] ID3D11ClassLinkage *pClassLinkage,
+ [out] ID3D11GeometryShader **ppGeometryShader
+ );
+
+ HRESULT CreatePixelShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] ID3D11ClassLinkage *pClassLinkage,
+ [out] ID3D11PixelShader **ppPixelShader
+ );
+
+ HRESULT CreateHullShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] ID3D11ClassLinkage *pClassLinkage,
+ [out] ID3D11HullShader **ppHullShader
+ );
+
+ HRESULT CreateDomainShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] ID3D11ClassLinkage *pClassLinkage,
+ [out] ID3D11DomainShader **ppDomainShader
+ );
+
+ HRESULT CreateComputeShader(
+ [in] const void *pShaderBytecode,
+ [in] SIZE_T BytecodeLength,
+ [in] ID3D11ClassLinkage *pClassLinkage,
+ [out] ID3D11ComputeShader **ppComputeShader
+ );
+
+ HRESULT CreateClassLinkage(
+ [out] ID3D11ClassLinkage **ppLinkage
+ );
+
+ HRESULT CreateBlendState(
+ [in] const D3D11_BLEND_DESC *pBlendStateDesc,
+ [out] ID3D11BlendState **ppBlendState
+ );
+
+ HRESULT CreateDepthStencilState(
+ [in] const D3D11_DEPTH_STENCIL_DESC *pDepthStencilDesc,
+ [out] ID3D11DepthStencilState **ppDepthStencilState
+ );
+
+ HRESULT CreateRasterizerState(
+ [in] const D3D11_RASTERIZER_DESC *pRasterizerDesc,
+ [out] ID3D11RasterizerState **ppRasterizerState
+ );
+
+ HRESULT CreateSamplerState(
+ [in] const D3D11_SAMPLER_DESC *pSamplerDesc,
+ [out] ID3D11SamplerState **ppSamplerState
+ );
+
+ HRESULT CreateQuery(
+ [in] const D3D11_QUERY_DESC *pQueryDesc,
+ [out] ID3D11Query **ppQuery
+ );
+
+ HRESULT CreatePredicate(
+ [in] const D3D11_QUERY_DESC *pPredicateDesc,
+ [out] ID3D11Predicate **ppPredicate
+ );
+
+ HRESULT CreateCounter(
+ [in] const D3D11_COUNTER_DESC *pCounterDesc,
+ [out] ID3D11Counter **ppCounter
+ );
+
+ HRESULT CreateDeferredContext(
+ [in] UINT ContextFlags,
+ [out] ID3D11DeviceContext **ppDeferredContext
+ );
+
+ HRESULT OpenSharedResource(
+ [in] HANDLE hResource,
+ [in] REFIID ReturnedInterface,
+ [out] void **ppResource
+ );
+
+ HRESULT CheckFormatSupport(
+ [in] DXGI_FORMAT Format,
+ [out] UINT *pFormatSupport
+ );
+
+ HRESULT CheckMultisampleQualityLevels(
+ [in] DXGI_FORMAT Format,
+ [in] UINT SampleCount,
+ [out] UINT *pNumQualityLevels
+ );
+
+ void CheckCounterInfo(
+ [out] D3D11_COUNTER_INFO *pCounterInfo
+ );
+
+ HRESULT CheckCounter(
+ [in] const D3D11_COUNTER_DESC *pDesc,
+ [out] D3D11_COUNTER_TYPE *pType,
+ [out] UINT *pActiveCounters,
+ [out] LPSTR szName,
+ [in, out, optional] UINT *pNameLength,
+ [out] LPSTR szUnits,
+ [in, out, optional] UINT *pUnitsLength,
+ [out] LPSTR szDescription,
+ [in, out, optional] UINT *pDescriptionLength
+ );
+
+ HRESULT CheckFeatureSupport(
+ [in] D3D11_FEATURE Feature,
+ [out] void *pFeatureSupportData,
+ [in] UINT FeatureSupportDataSize
+ );
+
+ HRESULT GetPrivateData(
+ [in] REFGUID guid,
+ [in, out] UINT *pDataSize,
+ [out] void *pData
+ );
+
+ HRESULT SetPrivateData(
+ [in] REFGUID guid,
+ [in] UINT DataSize,
+ [in] const void *pData
+ );
+
+ HRESULT SetPrivateDataInterface(
+ [in] REFGUID guid,
+ [in] const IUnknown *pData
+ );
+
+ D3D_FEATURE_LEVEL GetFeatureLevel();
+
+ UINT GetCreationFlags();
+
+ HRESULT GetDeviceRemovedReason();
+
+ void GetImmediateContext(
+ [out] ID3D11DeviceContext **ppImmediateContext
+ );
+
+ HRESULT SetExceptionMode(
+ [in] UINT RaiseFlags
+ );
+
+ UINT GetExceptionMode();
+};
+
+[object, local, uuid("c0bfa96c-e089-44fb-8eaf-26f8796190da")]
+interface ID3D11DeviceContext : ID3D11DeviceChild
+{
+ void VSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppConstantBuffers
+ );
+
+ void PSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D11ShaderResourceView *const *ppShaderResourceViews
+ );
+
+ void PSSetShader(
+ [in] ID3D11PixelShader *pPixelShader,
+ [in] ID3D11ClassInstance *const *ppClassInstances,
+ [in] UINT NumClassInstances
+ );
+
+ void PSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D11SamplerState *const *ppSamplers
+ );
+
+ void VSSetShader(
+ [in] ID3D11VertexShader *pVertexShader,
+ [in] ID3D11ClassInstance *const *ppClassInstances,
+ [in] UINT NumClassInstances
+ );
+
+ void DrawIndexed(
+ [in] UINT IndexCount,
+ [in] UINT StartIndexLocation,
+ [in] INT BaseVertexLocation
+ );
+
+ void Draw(
+ [in] UINT VertexCount,
+ [in] UINT StartVertexLocation
+ );
+
+ HRESULT Map(
+ [in] ID3D11Resource *pResource,
+ [in] UINT Subresource,
+ [in] D3D11_MAP MapType,
+ [in] UINT MapFlags,
+ [out] D3D11_MAPPED_SUBRESOURCE *pMappedResource
+ );
+
+ void Unmap(
+ [in] ID3D11Resource *pResource,
+ [in] UINT Subresource
+ );
+
+ void PSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppConstantBuffers
+ );
+
+ void IASetInputLayout(
+ [in] ID3D11InputLayout *pInputLayout
+ );
+
+ void IASetVertexBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppVertexBuffers,
+ [in] const UINT *pStrides,
+ [in] const UINT *pOffsets
+ );
+
+ void IASetIndexBuffer(
+ [in] ID3D11Buffer *pIndexBuffer,
+ [in] DXGI_FORMAT Format,
+ [in] UINT Offset
+ );
+
+ void DrawIndexedInstanced(
+ [in] UINT IndexCountPerInstance,
+ [in] UINT InstanceCount,
+ [in] UINT StartIndexLocation,
+ [in] INT BaseVertexLocation,
+ [in] UINT StartInstanceLocation
+ );
+
+ void DrawInstanced(
+ [in] UINT VertexCountPerInstance,
+ [in] UINT InstanceCount,
+ [in] UINT StartVertexLocation,
+ [in] UINT StartInstanceLocation
+ );
+
+ void GSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppConstantBuffers
+ );
+
+ void GSSetShader(
+ [in] ID3D11GeometryShader *pShader,
+ [in] ID3D11ClassInstance *const *ppClassInstances,
+ [in] UINT NumClassInstances
+ );
+
+ void IASetPrimitiveTopology(
+ [in] D3D11_PRIMITIVE_TOPOLOGY Topology
+ );
+
+ void VSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D11ShaderResourceView *const *ppShaderResourceViews
+ );
+
+ void VSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D11SamplerState *const *ppSamplers
+ );
+
+ void Begin(
+ [in] ID3D11Asynchronous *pAsync
+ );
+
+ void End(
+ [in] ID3D11Asynchronous *pAsync
+ );
+
+ HRESULT GetData(
+ [in] ID3D11Asynchronous *pAsync,
+ [out] void *pData,
+ [in] UINT DataSize,
+ [in] UINT GetDataFlags
+ );
+
+ void SetPredication(
+ [in] ID3D11Predicate *pPredicate,
+ [in] BOOL PredicateValue
+ );
+
+ void GSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D11ShaderResourceView *const *ppShaderResourceViews
+ );
+
+ void GSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D11SamplerState *const *ppSamplers
+ );
+
+ void OMSetRenderTargets(
+ [in] UINT NumViews,
+ [in] ID3D11RenderTargetView *const *ppRenderTargetViews,
+ [in] ID3D11DepthStencilView *pDepthStencilView
+ );
+
+ void OMSetRenderTargetsAndUnorderedAccessViews(
+ [in] UINT NumRTVs,
+ [in] ID3D11RenderTargetView *const *ppRenderTargetViews,
+ [in] ID3D11DepthStencilView *pDepthStencilView,
+ [in] UINT UAVStartSlot,
+ [in] UINT NumUAVs,
+ [in] ID3D11UnorderedAccessView *const *ppUnorderedAccessViews,
+ [in] const UINT *pUAVInitialCounts
+ );
+
+ void OMSetBlendState(
+ [in] ID3D11BlendState *pBlendState,
+ [in] const FLOAT BlendFactor[ 4 ],
+ [in] UINT SampleMask
+ );
+
+ void OMSetDepthStencilState(
+ [in] ID3D11DepthStencilState *pDepthStencilState,
+ [in] UINT StencilRef
+ );
+
+ void SOSetTargets(
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppSOTargets,
+ [in] const UINT *pOffsets
+ );
+
+ void DrawAuto(
+ );
+
+ void DrawIndexedInstancedIndirect(
+ [in] ID3D11Buffer *pBufferForArgs,
+ [in] UINT AlignedByteOffsetForArgs
+ );
+
+ void DrawInstancedIndirect(
+ [in] ID3D11Buffer *pBufferForArgs,
+ [in] UINT AlignedByteOffsetForArgs
+ );
+
+ void Dispatch(
+ [in] UINT ThreadGroupCountX,
+ [in] UINT ThreadGroupCountY,
+ [in] UINT ThreadGroupCountZ
+ );
+
+ void DispatchIndirect(
+ [in] ID3D11Buffer *pBufferForArgs,
+ [in] UINT AlignedByteOffsetForArgs
+ );
+
+ void RSSetState(
+ [in] ID3D11RasterizerState *pRasterizerState
+ );
+
+ void RSSetViewports(
+ [in] UINT NumViewports,
+ [in] const D3D11_VIEWPORT *pViewports
+ );
+
+ void RSSetScissorRects(
+ [in] UINT NumRects,
+ [in] const D3D11_RECT *pRects
+ );
+
+ void CopySubresourceRegion(
+ [in] ID3D11Resource *pDstResource,
+ [in] UINT DstSubresource,
+ [in] UINT DstX,
+ [in] UINT DstY,
+ [in] UINT DstZ,
+ [in] ID3D11Resource *pSrcResource,
+ [in] UINT SrcSubresource,
+ [in] const D3D11_BOX *pSrcBox
+ );
+
+ void CopyResource(
+ [in] ID3D11Resource *pDstResource,
+ [in] ID3D11Resource *pSrcResource
+ );
+
+ void UpdateSubresource(
+ [in] ID3D11Resource *pDstResource,
+ [in] UINT DstSubresource,
+ [in] const D3D11_BOX *pDstBox,
+ [in] const void *pSrcData,
+ [in] UINT SrcRowPitch,
+ [in] UINT SrcDepthPitch
+ );
+
+ void CopyStructureCount(
+ [in] ID3D11Buffer *pDstBuffer,
+ [in] UINT DstAlignedByteOffset,
+ [in] ID3D11UnorderedAccessView *pSrcView
+ );
+
+ void ClearRenderTargetView(
+ [in] ID3D11RenderTargetView *pRenderTargetView,
+ [in] const FLOAT ColorRGBA[ 4 ]
+ );
+
+ void ClearUnorderedAccessViewUint(
+ [in] ID3D11UnorderedAccessView *pUnorderedAccessView,
+ [in] const UINT Values[ 4 ]
+ );
+
+ void ClearUnorderedAccessViewFloat(
+ [in] ID3D11UnorderedAccessView *pUnorderedAccessView,
+ [in] const FLOAT Values[ 4 ]
+ );
+
+ void ClearDepthStencilView(
+ [in] ID3D11DepthStencilView *pDepthStencilView,
+ [in] UINT ClearFlags,
+ [in] FLOAT Depth,
+ [in] UINT8 Stencil
+ );
+
+ void GenerateMips(
+ [in] ID3D11ShaderResourceView *pShaderResourceView
+ );
+
+ void SetResourceMinLOD(
+ [in] ID3D11Resource *pResource,
+ [in] FLOAT MinLOD
+ );
+
+ FLOAT GetResourceMinLOD(
+ [in] ID3D11Resource *pResource
+ );
+
+ void ResolveSubresource(
+ [in] ID3D11Resource *pDstResource,
+ [in] UINT DstSubresource,
+ [in] ID3D11Resource *pSrcResource,
+ [in] UINT SrcSubresource,
+ [in] DXGI_FORMAT Format
+ );
+
+ void ExecuteCommandList(
+ [in] ID3D11CommandList *pCommandList,
+ [in] BOOL RestoreContextState
+ );
+
+ void HSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D11ShaderResourceView *const *ppShaderResourceViews
+ );
+
+ void HSSetShader(
+ [in] ID3D11HullShader *pHullShader,
+ [in] ID3D11ClassInstance *const *ppClassInstances,
+ [in] UINT NumClassInstances
+ );
+
+ void HSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D11SamplerState *const *ppSamplers
+ );
+
+ void HSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppConstantBuffers
+ );
+
+ void DSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D11ShaderResourceView *const *ppShaderResourceViews
+ );
+
+ void DSSetShader(
+ [in] ID3D11DomainShader *pDomainShader,
+ [in] ID3D11ClassInstance *const *ppClassInstances,
+ [in] UINT NumClassInstances
+ );
+
+ void DSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D11SamplerState *const *ppSamplers
+ );
+
+ void DSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppConstantBuffers
+ );
+
+ void CSSetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [in] ID3D11ShaderResourceView *const *ppShaderResourceViews
+ );
+
+ void CSSetUnorderedAccessViews(
+ [in] UINT StartSlot,
+ [in] UINT NumUAVs,
+ [in] ID3D11UnorderedAccessView *const *ppUnorderedAccessViews,
+ [in] const UINT *pUAVInitialCounts
+ );
+
+ void CSSetShader(
+ [in] ID3D11ComputeShader *pComputeShader,
+ [in] ID3D11ClassInstance *const *ppClassInstances,
+ [in] UINT NumClassInstances
+ );
+
+ void CSSetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [in] ID3D11SamplerState *const *ppSamplers
+ );
+
+ void CSSetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [in] ID3D11Buffer *const *ppConstantBuffers
+ );
+
+ void VSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppConstantBuffers
+ );
+
+ void PSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D11ShaderResourceView **ppShaderResourceViews
+ );
+
+ void PSGetShader(
+ [out] ID3D11PixelShader **ppPixelShader,
+ [out] ID3D11ClassInstance **ppClassInstances,
+ [in, out, optional] UINT *pNumClassInstances
+ );
+
+ void PSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D11SamplerState **ppSamplers
+ );
+
+ void VSGetShader(
+ [out] ID3D11VertexShader **ppVertexShader,
+ [out] ID3D11ClassInstance **ppClassInstances,
+ [in, out, optional] UINT *pNumClassInstances
+ );
+
+ void PSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppConstantBuffers
+ );
+
+ void IAGetInputLayout(
+ [out] ID3D11InputLayout **ppInputLayout
+ );
+
+ void IAGetVertexBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppVertexBuffers,
+ [out] UINT *pStrides,
+ [out] UINT *pOffsets
+ );
+
+ void IAGetIndexBuffer(
+ [out] ID3D11Buffer **pIndexBuffer,
+ [out] DXGI_FORMAT *Format,
+ [out] UINT *Offset
+ );
+
+ void GSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppConstantBuffers
+ );
+
+ void GSGetShader(
+ [out] ID3D11GeometryShader **ppGeometryShader,
+ [out] ID3D11ClassInstance **ppClassInstances,
+ [in, out, optional] UINT *pNumClassInstances
+ );
+
+ void IAGetPrimitiveTopology(
+ [out] D3D11_PRIMITIVE_TOPOLOGY *pTopology
+ );
+
+ void VSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D11ShaderResourceView **ppShaderResourceViews
+ );
+
+ void VSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D11SamplerState **ppSamplers
+ );
+
+ void GetPredication(
+ [out] ID3D11Predicate **ppPredicate,
+ [out] BOOL *pPredicateValue
+ );
+
+ void GSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D11ShaderResourceView **ppShaderResourceViews
+ );
+
+ void GSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D11SamplerState **ppSamplers
+ );
+
+ void OMGetRenderTargets(
+ [in] UINT NumViews,
+ [out] ID3D11RenderTargetView **ppRenderTargetViews,
+ [out] ID3D11DepthStencilView **ppDepthStencilView
+ );
+
+ void OMGetRenderTargetsAndUnorderedAccessViews(
+ [in] UINT NumRTVs,
+ [out] ID3D11RenderTargetView **ppRenderTargetViews,
+ [out] ID3D11DepthStencilView **ppDepthStencilView,
+ [in] UINT UAVStartSlot,
+ [in] UINT NumUAVs,
+ [out] ID3D11UnorderedAccessView **ppUnorderedAccessViews
+ );
+
+ void OMGetBlendState(
+ [out] ID3D11BlendState **ppBlendState,
+ [out] FLOAT BlendFactor[ 4 ],
+ [out] UINT *pSampleMask
+ );
+
+ void OMGetDepthStencilState(
+ [out] ID3D11DepthStencilState **ppDepthStencilState,
+ [out] UINT *pStencilRef
+ );
+
+ void SOGetTargets(
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppSOTargets
+ );
+
+ void RSGetState(
+ [out] ID3D11RasterizerState **ppRasterizerState
+ );
+
+ void RSGetViewports(
+ [in, out] /*_range*/ UINT *pNumViewports,
+ [out] D3D11_VIEWPORT *pViewports
+ );
+
+ void RSGetScissorRects(
+ [in, out] /*_range*/ UINT *pNumRects,
+ [out] D3D11_RECT *pRects
+ );
+
+ void HSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D11ShaderResourceView **ppShaderResourceViews
+ );
+
+ void HSGetShader(
+ [out] ID3D11HullShader **ppHullShader,
+ [out] ID3D11ClassInstance **ppClassInstances,
+ [in, out, optional] UINT *pNumClassInstances
+ );
+
+ void HSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D11SamplerState **ppSamplers
+ );
+
+ void HSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppConstantBuffers
+ );
+
+ void DSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D11ShaderResourceView **ppShaderResourceViews
+ );
+
+ void DSGetShader(
+ [out] ID3D11DomainShader **ppDomainShader,
+ [out] ID3D11ClassInstance **ppClassInstances,
+ [in, out, optional] UINT *pNumClassInstances
+ );
+
+ void DSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D11SamplerState **ppSamplers
+ );
+
+ void DSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppConstantBuffers
+ );
+
+ void CSGetShaderResources(
+ [in] UINT StartSlot,
+ [in] UINT NumViews,
+ [out] ID3D11ShaderResourceView **ppShaderResourceViews
+ );
+
+ void CSGetUnorderedAccessViews(
+ [in] UINT StartSlot,
+ [in] UINT NumUAVs,
+ [out] ID3D11UnorderedAccessView **ppUnorderedAccessViews
+ );
+
+ void CSGetShader(
+ [out] ID3D11ComputeShader **ppComputeShader,
+ [out] ID3D11ClassInstance **ppClassInstances,
+ [in, out, optional] UINT *pNumClassInstances
+ );
+
+ void CSGetSamplers(
+ [in] UINT StartSlot,
+ [in] UINT NumSamplers,
+ [out] ID3D11SamplerState **ppSamplers
+ );
+
+ void CSGetConstantBuffers(
+ [in] UINT StartSlot,
+ [in] UINT NumBuffers,
+ [out] ID3D11Buffer **ppConstantBuffers
+ );
+
+ void ClearState();
+
+ void Flush();
+
+ D3D11_DEVICE_CONTEXT_TYPE GetType();
+
+ UINT GetContextFlags();
+
+ HRESULT FinishCommandList(
+ [in] BOOL RestoreDeferredContextState,
+ [out] ID3D11CommandList **ppCommandList
+ );
+};
+
+cpp_quote("#include \"d3d10_1.h\"")
+cpp_quote("#include \"d3d10shader.h\"")
+cpp_quote("#include \"d3d10effect.h\"")
+/*cpp_quote("#include \"d3d10_1shader.h\"") */
+
+typedef enum D3D11_CREATE_DEVICE_FLAG
+{
+ D3D11_CREATE_DEVICE_SINGLETHREADED = 1,
+ D3D11_CREATE_DEVICE_DEBUG = 2,
+ D3D11_CREATE_DEVICE_SWITCH_TO_REF = 4,
+ D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS = 8,
+ D3D11_CREATE_DEVICE_BGRA_SUPPORT = 0x20
+} D3D11_CREATE_DEVICE_FLAG;
+
+
+HRESULT D3D11CreateDevice(
+ [in,optional] IDXGIAdapter* pAdapter,
+ [in] D3D_DRIVER_TYPE DriverType,
+ [in] HMODULE Software,
+ [in] UINT Flags,
+ [in,optional] const D3D_FEATURE_LEVEL* pFeatureLevels,
+ [in] UINT FeatureLevels,
+ [in] UINT SDKVersion,
+ [out,optional] ID3D11Device** ppDevice,
+ [out,optional] D3D_FEATURE_LEVEL* pFeatureLevel,
+ [out,optional] ID3D11DeviceContext** ppImmediateContext
+);
+
+typedef HRESULT (* PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN)(
+ [in,optional] IDXGIAdapter*,
+ D3D_DRIVER_TYPE,
+ HMODULE,
+ UINT,
+ [in,optional] const D3D_FEATURE_LEVEL*,
+ UINT FeatureLevels,
+ UINT,
+ [in, optional] const DXGI_SWAP_CHAIN_DESC*,
+ [out,optional] IDXGISwapChain**,
+ [out,optional] ID3D11Device**,
+ [out,optional] D3D_FEATURE_LEVEL*,
+ [out,optional] ID3D11DeviceContext**
+);
+
+HRESULT D3D11CreateDeviceAndSwapChain(
+ [in,optional] IDXGIAdapter* pAdapter,
+ [in] D3D_DRIVER_TYPE DriverType,
+ [in] HMODULE Software,
+ [in] UINT Flags,
+ [in,optional] const D3D_FEATURE_LEVEL* pFeatureLevels,
+ [in] UINT FeatureLevels,
+ [in] UINT SDKVersion,
+ [in,optional] const DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
+ [out,optional] IDXGISwapChain** ppSwapChain,
+ [out,optional] ID3D11Device** ppDevice,
+ [out,optional] D3D_FEATURE_LEVEL* pFeatureLevel,
+ [out,optional] ID3D11DeviceContext** ppImmediateContext
+);
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3d11shader.idl b/src/gallium/state_trackers/d3d1x/d3dapi/d3d11shader.idl
new file mode 100644
index 0000000..09588a0
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3d11shader.idl
@@ -0,0 +1,287 @@
+/**************************************************************************
+ *
+ * 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 "d3dcommon.idl";
+
+typedef enum D3D11_SHADER_VERSION_TYPE
+{
+ D3D11_SHVER_PIXEL_SHADER,
+ D3D11_SHVER_VERTEX_SHADER,
+ D3D11_SHVER_GEOMETRY_SHADER,
+
+ D3D11_SHVER_HULL_SHADER,
+ D3D11_SHVER_DOMAIN_SHADER,
+ D3D11_SHVER_COMPUTE_SHADER,
+} D3D11_SHADER_VERSION_TYPE;
+
+cpp_quote("#define D3D11_SHVER_GET_TYPE(v) (((v) >> 16) & 0xffff)")
+cpp_quote("#define D3D11_SHVER_GET_MAJOR(v) (((v) >> 4) & 0xf)")
+cpp_quote("#define D3D11_SHVER_GET_MINOR(v) (((v) >> 0) & 0xf)")
+
+typedef D3D_RESOURCE_RETURN_TYPE D3D11_RESOURCE_RETURN_TYPE;
+typedef D3D_CBUFFER_TYPE D3D11_CBUFFER_TYPE;
+
+typedef struct _D3D11_SIGNATURE_PARAMETER_DESC
+{
+ LPCSTR SemanticName;
+ UINT SemanticIndex;
+ UINT Register;
+ D3D_NAME SystemValueType;
+ D3D_REGISTER_COMPONENT_TYPE ComponentType;
+ BYTE Mask;
+ BYTE ReadWriteMask;
+ UINT Stream;
+} D3D11_SIGNATURE_PARAMETER_DESC;
+
+typedef struct _D3D11_SHADER_BUFFER_DESC
+{
+ LPCSTR Name;
+ D3D_CBUFFER_TYPE Type;
+ UINT Variables;
+ UINT Size;
+ UINT uFlags;
+} D3D11_SHADER_BUFFER_DESC;
+
+typedef struct _D3D11_SHADER_VARIABLE_DESC
+{
+ LPCSTR Name;
+ UINT StartOffset;
+ UINT Size;
+ UINT uFlags;
+ LPVOID DefaultValue;
+ UINT StartTexture;
+ UINT TextureSize;
+ UINT StartSampler;
+ UINT SamplerSize;
+} D3D11_SHADER_VARIABLE_DESC;
+
+typedef struct _D3D11_SHADER_TYPE_DESC
+{
+ D3D_SHADER_VARIABLE_CLASS Class;
+ D3D_SHADER_VARIABLE_TYPE Type;
+ UINT Rows;
+ UINT Columns;
+ UINT Elements;
+ UINT Members;
+ UINT Offset;
+ LPCSTR Name;
+} D3D11_SHADER_TYPE_DESC;
+
+typedef D3D_TESSELLATOR_DOMAIN D3D11_TESSELLATOR_DOMAIN;
+typedef D3D_TESSELLATOR_PARTITIONING D3D11_TESSELLATOR_PARTITIONING;
+typedef D3D_TESSELLATOR_OUTPUT_PRIMITIVE D3D11_TESSELLATOR_OUTPUT_PRIMITIVE;
+
+typedef struct _D3D11_SHADER_DESC
+{
+ UINT Version;
+ LPCSTR Creator;
+ UINT Flags;
+
+ UINT ConstantBuffers;
+ UINT BoundResources;
+ UINT InputParameters;
+ UINT OutputParameters;
+
+ UINT InstructionCount;
+ UINT TempRegisterCount;
+ UINT TempArrayCount;
+ UINT DefCount;
+ UINT DclCount;
+ UINT TextureNormalInstructions;
+ UINT TextureLoadInstructions;
+ UINT TextureCompInstructions;
+ UINT TextureBiasInstructions;
+ UINT TextureGradientInstructions;
+ UINT FloatInstructionCount;
+ UINT IntInstructionCount;
+ UINT UintInstructionCount;
+ UINT StaticFlowControlCount;
+ UINT DynamicFlowControlCount;
+ UINT MacroInstructionCount;
+ UINT ArrayInstructionCount;
+ UINT CutInstructionCount;
+ UINT EmitInstructionCount;
+ D3D_PRIMITIVE_TOPOLOGY GSOutputTopology;
+ UINT GSMaxOutputVertexCount;
+ D3D_PRIMITIVE InputPrimitive;
+ UINT PatchConstantParameters;
+ UINT cGSInstanceCount;
+ UINT cControlPoints;
+ D3D_TESSELLATOR_OUTPUT_PRIMITIVE HSOutputPrimitive;
+ D3D_TESSELLATOR_PARTITIONING HSPartitioning;
+ D3D_TESSELLATOR_DOMAIN TessellatorDomain;
+
+ UINT cBarrierInstructions;
+ UINT cInterlockedInstructions;
+ UINT cTextureStoreInstructions;
+} D3D11_SHADER_DESC;
+
+typedef struct _D3D11_SHADER_INPUT_BIND_DESC
+{
+ LPCSTR Name;
+ D3D_SHADER_INPUT_TYPE Type;
+ UINT BindPoint;
+ UINT BindCount;
+
+ UINT uFlags;
+ D3D_RESOURCE_RETURN_TYPE ReturnType;
+ D3D_SRV_DIMENSION Dimension;
+ UINT NumSamples;
+} D3D11_SHADER_INPUT_BIND_DESC;
+
+[local, object, uuid("6e6ffa6a-9bae-4613-a51e-91652d508c21")]
+interface ID3D11ShaderReflectionType
+{
+ HRESULT GetDesc(
+ [out] D3D11_SHADER_TYPE_DESC *pDesc
+ );
+
+ ID3D11ShaderReflectionType* GetMemberTypeByIndex(
+ [in] UINT Index
+ );
+
+ ID3D11ShaderReflectionType* GetMemberTypeByName(
+ [in] LPCSTR Name
+ );
+
+ LPCSTR GetMemberTypeName(
+ [in] UINT Index
+ );
+
+ HRESULT IsEqual(
+ [in] ID3D11ShaderReflectionType* pType
+ );
+ ID3D11ShaderReflectionType* GetSubType();
+ ID3D11ShaderReflectionType* GetBaseClass();
+ UINT GetNumInterfaces();
+ ID3D11ShaderReflectionType* GetInterfaceByIndex(
+ [in] UINT uIndex
+ );
+ HRESULT IsOfType(
+ [in] ID3D11ShaderReflectionType* pType
+ );
+ HRESULT ImplementsInterface(
+ [in] ID3D11ShaderReflectionType* pBase
+ );
+};
+
+interface ID3D11ShaderReflectionConstantBuffer;
+
+[object, local, uuid("51f23923-f3e5-4bd1-91cb-606177d8db4c")]
+interface ID3D11ShaderReflectionVariable
+{
+ HRESULT GetDesc(
+ [out] D3D11_SHADER_VARIABLE_DESC *pDesc
+ );
+
+ ID3D11ShaderReflectionType* GetType();
+ ID3D11ShaderReflectionConstantBuffer* GetBuffer();
+
+ UINT GetInterfaceSlot(
+ [in] UINT uArrayIndex
+ );
+};
+
+[object, local, uuid("eb62d63d-93dd-4318-8ae8-c6f83ad371b8")]
+interface ID3D11ShaderReflectionConstantBuffer
+{
+ HRESULT GetDesc(
+ [out] D3D11_SHADER_BUFFER_DESC *pDesc
+ );
+
+ ID3D11ShaderReflectionVariable* GetVariableByIndex(
+ [in] UINT Index
+ );
+
+ ID3D11ShaderReflectionVariable* GetVariableByName(
+ [in] LPCSTR Name
+ );
+};
+
+[object,local,uuid("0a233719-3960-4578-9d7c-203b8b1d9cc1")]
+interface ID3D11ShaderReflection
+{
+ HRESULT GetDesc(
+ [out] D3D11_SHADER_DESC *pDesc
+ );
+
+ ID3D11ShaderReflectionConstantBuffer* GetConstantBufferByIndex(
+ [in] UINT Index
+ );
+
+ ID3D11ShaderReflectionConstantBuffer* GetConstantBufferByName(
+ [in] LPCSTR Name
+ );
+
+ HRESULT GetResourceBindingDesc(
+ [in] UINT ResourceIndex,
+ [out] D3D11_SHADER_INPUT_BIND_DESC *pDesc
+ );
+
+ HRESULT GetInputParameterDesc(
+ [in] UINT ParameterIndex,
+ [out] D3D11_SIGNATURE_PARAMETER_DESC *pDesc
+ );
+
+ HRESULT GetOutputParameterDesc
+ (
+ [in] UINT ParameterIndex,
+ [out] D3D11_SIGNATURE_PARAMETER_DESC *pDesc
+ );
+
+ HRESULT GetPatchConstantParameterDesc(
+ [in] UINT ParameterIndex,
+ [out] D3D11_SIGNATURE_PARAMETER_DESC *pDesc
+ );
+
+ ID3D11ShaderReflectionVariable* GetVariableByName(
+ [in] LPCSTR Name
+ );
+
+ HRESULT GetResourceBindingDescByName(
+ [in] LPCSTR Name,
+ [out] D3D11_SHADER_INPUT_BIND_DESC *pDesc
+ );
+
+ UINT GetMovInstructionCount();
+ UINT GetMovcInstructionCount();
+ UINT GetConversionInstructionCount();
+ UINT GetBitwiseInstructionCount();
+ D3D_PRIMITIVE GetGSInputPrimitive();
+ BOOL IsSampleFrequencyShader();
+ UINT GetNumInterfaceSlots();
+
+ HRESULT GetMinFeatureLevel(
+ [out] D3D_FEATURE_LEVEL* pLevel
+ );
+
+ UINT GetThreadGroupSize(
+ [out,optional] UINT* pSizeX,
+ [out,optional] UINT* pSizeY,
+ [out,optional] UINT* pSizeZ
+ );
+};
+
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/d3dcommon.idl b/src/gallium/state_trackers/d3d1x/d3dapi/d3dcommon.idl
new file mode 100644
index 0000000..3594bf5
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/d3dcommon.idl
@@ -0,0 +1,700 @@
+/**************************************************************************
+ *
+ * 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 "oaidl.idl";
+import "ocidl.idl";
+
+typedef const void* LPCVOID;
+
+typedef enum D3D_DRIVER_TYPE
+{
+ D3D_DRIVER_TYPE_UNKNOWN,
+ D3D_DRIVER_TYPE_HARDWARE,
+ D3D_DRIVER_TYPE_REFERENCE,
+ D3D_DRIVER_TYPE_NULL,
+ D3D_DRIVER_TYPE_SOFTWARE,
+ D3D_DRIVER_TYPE_WARP,
+} D3D_DRIVER_TYPE;
+
+typedef enum D3D_FEATURE_LEVEL
+{
+ 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;
+
+typedef enum D3D_PRIMITIVE_TOPOLOGY
+{
+ D3D_PRIMITIVE_TOPOLOGY_UNDEFINED = 0,
+ D3D_PRIMITIVE_TOPOLOGY_POINTLIST,
+ D3D_PRIMITIVE_TOPOLOGY_LINELIST,
+ D3D_PRIMITIVE_TOPOLOGY_LINESTRIP,
+ D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
+ D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
+
+ D3D_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10,
+ D3D_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ,
+ D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ,
+ D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ,
+
+ D3D_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = 33,
+ D3D_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST,
+ D3D_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST,
+
+ D3D10_PRIMITIVE_TOPOLOGY_UNDEFINED = 0,
+ D3D10_PRIMITIVE_TOPOLOGY_POINTLIST,
+ D3D10_PRIMITIVE_TOPOLOGY_LINELIST,
+ D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP,
+ D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
+ D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
+
+ D3D10_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10,
+ D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ,
+ D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ,
+ D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ,
+
+ D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED = 0,
+ D3D11_PRIMITIVE_TOPOLOGY_POINTLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_LINELIST,
+ D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP,
+ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
+ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
+
+ D3D11_PRIMITIVE_TOPOLOGY_LINELIST_ADJ = 10,
+ D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP_ADJ,
+ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ,
+ D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP_ADJ,
+
+ D3D11_PRIMITIVE_TOPOLOGY_1_CONTROL_POINT_PATCHLIST = 33,
+ D3D11_PRIMITIVE_TOPOLOGY_2_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_5_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_6_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_7_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_8_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_9_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_10_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_11_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_12_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_13_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_14_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_15_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_16_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_17_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_18_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_19_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_20_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_21_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_22_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_23_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_24_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_25_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_26_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_27_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_28_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_29_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_30_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_31_CONTROL_POINT_PATCHLIST,
+ D3D11_PRIMITIVE_TOPOLOGY_32_CONTROL_POINT_PATCHLIST,
+} D3D_PRIMITIVE_TOPOLOGY;
+
+typedef enum D3D_PRIMITIVE
+{
+ D3D_PRIMITIVE_UNDEFINED = 0,
+ D3D_PRIMITIVE_POINT,
+ D3D_PRIMITIVE_LINE,
+ D3D_PRIMITIVE_TRIANGLE,
+
+ D3D_PRIMITIVE_LINE_ADJ = 6,
+ D3D_PRIMITIVE_TRIANGLE_ADJ,
+
+ D3D_PRIMITIVE_1_CONTROL_POINT_PATCH = 8,
+ D3D_PRIMITIVE_2_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_3_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_4_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_5_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_6_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_7_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_8_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_9_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_10_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_11_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_12_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_13_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_14_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_15_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_16_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_17_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_18_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_19_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_20_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_21_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_22_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_23_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_24_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_25_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_26_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_27_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_28_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_29_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_30_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_31_CONTROL_POINT_PATCH,
+ D3D_PRIMITIVE_32_CONTROL_POINT_PATCH,
+
+ D3D10_PRIMITIVE_UNDEFINED = 0,
+ D3D10_PRIMITIVE_POINT,
+ D3D10_PRIMITIVE_LINE,
+ D3D10_PRIMITIVE_TRIANGLE,
+
+ D3D10_PRIMITIVE_LINE_ADJ = 6,
+ D3D10_PRIMITIVE_TRIANGLE_ADJ,
+
+ D3D11_PRIMITIVE_UNDEFINED = 0,
+ D3D11_PRIMITIVE_POINT,
+ D3D11_PRIMITIVE_LINE,
+ D3D11_PRIMITIVE_TRIANGLE,
+
+ D3D11_PRIMITIVE_LINE_ADJ = 6,
+ D3D11_PRIMITIVE_TRIANGLE_ADJ,
+
+ D3D11_PRIMITIVE_1_CONTROL_POINT_PATCH = 8,
+ D3D11_PRIMITIVE_2_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_3_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_4_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_5_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_6_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_7_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_8_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_9_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_10_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_11_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_12_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_13_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_14_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_15_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_16_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_17_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_18_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_19_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_20_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_21_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_22_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_23_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_24_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_25_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_26_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_27_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_28_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_29_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_30_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_31_CONTROL_POINT_PATCH,
+ D3D11_PRIMITIVE_32_CONTROL_POINT_PATCH,
+} D3D_PRIMITIVE;
+
+typedef enum D3D_SRV_DIMENSION
+{
+ D3D_SRV_DIMENSION_UNKNOWN = 0,
+ D3D_SRV_DIMENSION_BUFFER,
+ D3D_SRV_DIMENSION_TEXTURE1D,
+ D3D_SRV_DIMENSION_TEXTURE1DARRAY,
+ D3D_SRV_DIMENSION_TEXTURE2D,
+ D3D_SRV_DIMENSION_TEXTURE2DARRAY,
+ D3D_SRV_DIMENSION_TEXTURE2DMS,
+ D3D_SRV_DIMENSION_TEXTURE2DMSARRAY,
+ D3D_SRV_DIMENSION_TEXTURE3D,
+ D3D_SRV_DIMENSION_TEXTURECUBE,
+ D3D_SRV_DIMENSION_TEXTURECUBEARRAY,
+ D3D_SRV_DIMENSION_BUFFEREX,
+
+ D3D10_SRV_DIMENSION_UNKNOWN = 0,
+ D3D10_SRV_DIMENSION_BUFFER,
+ D3D10_SRV_DIMENSION_TEXTURE1D,
+ D3D10_SRV_DIMENSION_TEXTURE1DARRAY,
+ D3D10_SRV_DIMENSION_TEXTURE2D,
+ D3D10_SRV_DIMENSION_TEXTURE2DARRAY,
+ D3D10_SRV_DIMENSION_TEXTURE2DMS,
+ D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY,
+ D3D10_SRV_DIMENSION_TEXTURE3D,
+ D3D10_SRV_DIMENSION_TEXTURECUBE,
+
+ D3D10_1_SRV_DIMENSION_UNKNOWN = 0,
+ D3D10_1_SRV_DIMENSION_BUFFER,
+ D3D10_1_SRV_DIMENSION_TEXTURE1D,
+ D3D10_1_SRV_DIMENSION_TEXTURE1DARRAY,
+ D3D10_1_SRV_DIMENSION_TEXTURE2D,
+ D3D10_1_SRV_DIMENSION_TEXTURE2DARRAY,
+ D3D10_1_SRV_DIMENSION_TEXTURE2DMS,
+ D3D10_1_SRV_DIMENSION_TEXTURE2DMSARRAY,
+ D3D10_1_SRV_DIMENSION_TEXTURE3D,
+ D3D10_1_SRV_DIMENSION_TEXTURECUBE,
+ D3D10_1_SRV_DIMENSION_TEXTURECUBEARRAY,
+
+ D3D11_SRV_DIMENSION_UNKNOWN = 0,
+ D3D11_SRV_DIMENSION_BUFFER,
+ D3D11_SRV_DIMENSION_TEXTURE1D,
+ D3D11_SRV_DIMENSION_TEXTURE1DARRAY,
+ D3D11_SRV_DIMENSION_TEXTURE2D,
+ D3D11_SRV_DIMENSION_TEXTURE2DARRAY,
+ D3D11_SRV_DIMENSION_TEXTURE2DMS,
+ D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY,
+ D3D11_SRV_DIMENSION_TEXTURE3D,
+ D3D11_SRV_DIMENSION_TEXTURECUBE,
+ D3D11_SRV_DIMENSION_TEXTURECUBEARRAY,
+ D3D11_SRV_DIMENSION_BUFFEREX,
+} D3D_SRV_DIMENSION;
+
+typedef struct _D3D_SHADER_MACRO
+{
+ LPCSTR Name;
+ LPCSTR Definition;
+} D3D_SHADER_MACRO;
+
+typedef struct _D3D_SHADER_MACRO *LPD3D_SHADER_MACRO;
+
+[object, local, uuid(8ba5fb08-5195-40e2-ac58-0d989c3a0102)]
+interface ID3D10Blob : IUnknown
+{
+ LPVOID GetBufferPointer();
+ SIZE_T GetBufferSize();
+};
+
+typedef enum _D3D_INCLUDE_TYPE
+{
+ D3D_INCLUDE_LOCAL = 0,
+ D3D_INCLUDE_SYSTEM,
+
+ D3D10_INCLUDE_LOCAL = 0,
+ D3D10_INCLUDE_SYSTEM,
+
+ D3D_INCLUDE_FORCE_DWORD = 0x7fffffff,
+} D3D_INCLUDE_TYPE;
+
+[object, local]
+interface ID3DInclude : IUnknown
+{
+ HRESULT Open(
+ [in] D3D_INCLUDE_TYPE IncludeType,
+ [in] LPCSTR pFileName,
+ [in] LPCVOID pParentData,
+ [out] LPCVOID *ppData,
+ [in] UINT *pBytes
+ );
+ HRESULT Close(
+ [in] LPCVOID pData
+ );
+};
+
+typedef enum _D3D_SHADER_VARIABLE_CLASS
+{
+ D3D_SVC_SCALAR = 0,
+ D3D_SVC_VECTOR,
+ D3D_SVC_MATRIX_ROWS,
+ D3D_SVC_MATRIX_COLUMNS,
+ D3D_SVC_OBJECT,
+ D3D_SVC_STRUCT,
+ D3D_SVC_INTERFACE_CLASS,
+ D3D_SVC_INTERFACE_POINTER,
+
+ D3D10_SVC_SCALAR = 0,
+ D3D10_SVC_VECTOR,
+ D3D10_SVC_MATRIX_ROWS,
+ D3D10_SVC_MATRIX_COLUMNS,
+ D3D10_SVC_OBJECT,
+ D3D10_SVC_STRUCT,
+ D3D11_SVC_INTERFACE_CLASS,
+ D3D11_SVC_INTERFACE_POINTER,
+ D3D_SVC_FORCE_DWORD = 0x7fffffff
+} D3D_SHADER_VARIABLE_CLASS;
+
+typedef enum _D3D_SHADER_VARIABLE_FLAGS
+{
+ D3D_SVF_USERPACKED = 1,
+ D3D_SVF_USED = 2,
+ D3D_SVF_INTERFACE_POINTER = 4,
+ D3D_SVF_INTERFACE_PARAMETER = 8,
+
+ D3D10_SVF_USERPACKED = 1,
+ D3D10_SVF_USED = 2,
+ D3D10_SVF_INTERFACE_POINTER = 4,
+ D3D10_SVF_INTERFACE_PARAMETER = 8,
+
+ D3D_SVF_FORCE_DWORD = 0x7fffffff
+} D3D_SHADER_VARIABLE_FLAGS;
+
+typedef enum _D3D_SHADER_VARIABLE_TYPE
+{
+ D3D_SVT_VOID = 0,
+ D3D_SVT_BOOL,
+ D3D_SVT_INT,
+ D3D_SVT_FLOAT,
+ D3D_SVT_STRING,
+ D3D_SVT_TEXTURE,
+ D3D_SVT_TEXTURE1D,
+ D3D_SVT_TEXTURE2D,
+ D3D_SVT_TEXTURE3D,
+ D3D_SVT_TEXTURECUBE,
+ D3D_SVT_SAMPLER,
+ D3D_SVT_SAMPLER1D,
+ D3D_SVT_SAMPLER2D,
+ D3D_SVT_SAMPLER3D,
+ D3D_SVT_SAMPLERCUBE,
+ D3D_SVT_PIXELSHADER,
+ D3D_SVT_VERTEXSHADER,
+ D3D_SVT_PIXELFRAGMENT,
+ D3D_SVT_VERTEXFRAGMENT,
+ D3D_SVT_UINT,
+ D3D_SVT_UINT8,
+ D3D_SVT_GEOMETRYSHADER,
+ D3D_SVT_RASTERIZER,
+ D3D_SVT_DEPTHSTENCIL,
+ D3D_SVT_BLEND,
+ D3D_SVT_BUFFER,
+ D3D_SVT_CBUFFER,
+ D3D_SVT_TBUFFER,
+ D3D_SVT_TEXTURE1DARRAY,
+ D3D_SVT_TEXTURE2DARRAY,
+ D3D_SVT_RENDERTARGETVIEW,
+ D3D_SVT_DEPTHSTENCILVIEW,
+ D3D_SVT_TEXTURE2DMS,
+ D3D_SVT_TEXTURE2DMSARRAY,
+ D3D_SVT_TEXTURECUBEARRAY,
+ D3D_SVT_HULLSHADER,
+ D3D_SVT_DOMAINSHADER,
+ D3D_SVT_INTERFACE_POINTER,
+ D3D_SVT_COMPUTESHADER,
+ D3D_SVT_DOUBLE,
+ D3D_SVT_RWTEXTURE1D,
+ D3D_SVT_RWTEXTURE1DARRAY,
+ D3D_SVT_RWTEXTURE2D,
+ D3D_SVT_RWTEXTURE2DARRAY,
+ D3D_SVT_RWTEXTURE3D,
+ D3D_SVT_RWBUFFER,
+ D3D_SVT_BYTEADDRESS_BUFFER,
+ D3D_SVT_RWBYTEADDRESS_BUFFER,
+ D3D_SVT_STRUCTURED_BUFFER,
+ D3D_SVT_RWSTRUCTURED_BUFFER,
+ D3D_SVT_APPEND_STRUCTURED_BUFFER,
+ D3D_SVT_CONSUME_STRUCTURED_BUFFER,
+
+ D3D10_SVT_VOID = 0,
+ D3D10_SVT_BOOL,
+ D3D10_SVT_INT,
+ D3D10_SVT_FLOAT,
+ D3D10_SVT_STRING,
+ D3D10_SVT_TEXTURE,
+ D3D10_SVT_TEXTURE1D,
+ D3D10_SVT_TEXTURE2D,
+ D3D10_SVT_TEXTURE3D,
+ D3D10_SVT_TEXTURECUBE,
+ D3D10_SVT_SAMPLER,
+ D3D10_SVT_SAMPLER1D,
+ D3D10_SVT_SAMPLER2D,
+ D3D10_SVT_SAMPLER3D,
+ D3D10_SVT_SAMPLERCUBE,
+ D3D10_SVT_PIXELSHADER,
+ D3D10_SVT_VERTEXSHADER,
+ D3D10_SVT_PIXELFRAGMENT,
+ D3D10_SVT_VERTEXFRAGMENT,
+ D3D10_SVT_UINT,
+ D3D10_SVT_UINT8,
+ D3D10_SVT_GEOMETRYSHADER,
+ D3D10_SVT_RASTERIZER,
+ D3D10_SVT_DEPTHSTENCIL,
+ D3D10_SVT_BLEND,
+ D3D10_SVT_BUFFER,
+ D3D10_SVT_CBUFFER,
+ D3D10_SVT_TBUFFER,
+ D3D10_SVT_TEXTURE1DARRAY,
+ D3D10_SVT_TEXTURE2DARRAY,
+ D3D10_SVT_RENDERTARGETVIEW,
+ D3D10_SVT_DEPTHSTENCILVIEW,
+ D3D10_SVT_TEXTURE2DMS,
+ D3D10_SVT_TEXTURE2DMSARRAY,
+ D3D10_SVT_TEXTURECUBEARRAY,
+
+ D3D11_SVT_HULLSHADER,
+ D3D11_SVT_DOMAINSHADER,
+ D3D11_SVT_INTERFACE_POINTER,
+ D3D11_SVT_COMPUTESHADER,
+ D3D11_SVT_DOUBLE,
+ D3D11_SVT_RWTEXTURE1D,
+ D3D11_SVT_RWTEXTURE1DARRAY,
+ D3D11_SVT_RWTEXTURE2D,
+ D3D11_SVT_RWTEXTURE2DARRAY,
+ D3D11_SVT_RWTEXTURE3D,
+ D3D11_SVT_RWBUFFER,
+ D3D11_SVT_BYTEADDRESS_BUFFER,
+ D3D11_SVT_RWBYTEADDRESS_BUFFER,
+ D3D11_SVT_STRUCTURED_BUFFER,
+ D3D11_SVT_RWSTRUCTURED_BUFFER,
+ D3D11_SVT_APPEND_STRUCTURED_BUFFER,
+ D3D11_SVT_CONSUME_STRUCTURED_BUFFER,
+
+ D3D_SVT_FORCE_DWORD = 0x7fffffff
+} D3D_SHADER_VARIABLE_TYPE;
+
+typedef enum _D3D_SHADER_INPUT_FLAGS
+{
+ D3D_SIF_USERPACKED = 1,
+ D3D_SIF_COMPARISON_SAMPLER = 2,
+ D3D_SIF_TEXTURE_COMPONENT_0 = 4,
+ D3D_SIF_TEXTURE_COMPONENT_1 = 8,
+ D3D_SIF_TEXTURE_COMPONENTS = 12,
+
+ D3D10_SIF_USERPACKED = 1,
+ D3D10_SIF_COMPARISON_SAMPLER = 2,
+ D3D10_SIF_TEXTURE_COMPONENT_0 = 4,
+ D3D10_SIF_TEXTURE_COMPONENT_1 = 8,
+ D3D10_SIF_TEXTURE_COMPONENTS = 12,
+
+ D3D_SIF_FORCE_DWORD = 0x7fffffff
+ } D3D_SHADER_INPUT_FLAGS;
+
+typedef enum _D3D_SHADER_INPUT_TYPE
+{
+ D3D_SIT_CBUFFER = 0,
+ D3D_SIT_TBUFFER,
+ D3D_SIT_TEXTURE,
+ D3D_SIT_SAMPLER,
+ D3D_SIT_UAV_RWTYPED,
+ D3D_SIT_STRUCTURED,
+ D3D_SIT_UAV_RWSTRUCTURED,
+ D3D_SIT_BYTEADDRESS,
+ D3D_SIT_UAV_RWBYTEADDRESS,
+ D3D_SIT_UAV_APPEND_STRUCTURED,
+ D3D_SIT_UAV_CONSUME_STRUCTURED,
+ D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER,
+
+ D3D10_SIT_CBUFFER = 0,
+ D3D10_SIT_TBUFFER,
+ D3D10_SIT_TEXTURE,
+ D3D10_SIT_SAMPLER,
+
+ D3D11_SIT_UAV_RWTYPED,
+ D3D11_SIT_STRUCTURED,
+ D3D11_SIT_UAV_RWSTRUCTURED,
+ D3D11_SIT_BYTEADDRESS,
+ D3D11_SIT_UAV_RWBYTEADDRESS,
+ D3D11_SIT_UAV_APPEND_STRUCTURED,
+ D3D11_SIT_UAV_CONSUME_STRUCTURED,
+ D3D11_SIT_UAV_RWSTRUCTURED_WITH_COUNTER,
+ } D3D_SHADER_INPUT_TYPE;
+
+typedef enum _D3D_SHADER_CBUFFER_FLAGS
+{
+ D3D_CBF_USERPACKED = 1,
+
+ D3D10_CBF_USERPACKED = 1,
+
+ D3D_CBF_FORCE_DWORD = 0x7fffffff
+} D3D_SHADER_CBUFFER_FLAGS;
+
+typedef enum _D3D_CBUFFER_TYPE
+{
+ D3D_CT_CBUFFER = 0,
+ D3D_CT_TBUFFER,
+ D3D_CT_INTERFACE_POINTERS,
+ D3D_CT_RESOURCE_BIND_INFO,
+
+ D3D10_CT_CBUFFER = 0,
+ D3D10_CT_TBUFFER,
+
+ D3D11_CT_CBUFFER = 0,
+ D3D11_CT_TBUFFER,
+ D3D11_CT_INTERFACE_POINTERS,
+ D3D11_CT_RESOURCE_BIND_INFO,
+} D3D_CBUFFER_TYPE;
+
+typedef enum D3D_NAME
+{
+ D3D_NAME_UNDEFINED = 0,
+ D3D_NAME_POSITION,
+ D3D_NAME_CLIP_DISTANCE,
+ D3D_NAME_CULL_DISTANCE,
+ D3D_NAME_RENDER_TARGET_ARRAY_INDEX,
+ D3D_NAME_VIEWPORT_ARRAY_INDEX,
+ D3D_NAME_VERTEX_ID,
+ D3D_NAME_PRIMITIVE_ID,
+ D3D_NAME_INSTANCE_ID,
+ D3D_NAME_IS_FRONT_FACE,
+ D3D_NAME_SAMPLE_INDEX,
+ D3D_NAME_FINAL_QUAD_EDGE_TESSFACTOR,
+ D3D_NAME_FINAL_QUAD_INSIDE_TESSFACTOR,
+ D3D_NAME_FINAL_TRI_EDGE_TESSFACTOR,
+ D3D_NAME_FINAL_TRI_INSIDE_TESSFACTOR,
+ D3D_NAME_FINAL_LINE_DETAIL_TESSFACTOR,
+ D3D_NAME_FINAL_LINE_DENSITY_TESSFACTOR,
+
+ D3D_NAME_TARGET = 64,
+ D3D_NAME_DEPTH,
+ D3D_NAME_COVERAGE,
+ D3D_NAME_DEPTH_GREATER_EQUAL,
+ D3D_NAME_DEPTH_LESS_EQUAL,
+
+ D3D10_NAME_UNDEFINED = 0,
+ D3D10_NAME_POSITION,
+ D3D10_NAME_CLIP_DISTANCE,
+ D3D10_NAME_CULL_DISTANCE,
+ D3D10_NAME_RENDER_TARGET_ARRAY_INDEX,
+ D3D10_NAME_VIEWPORT_ARRAY_INDEX,
+ D3D10_NAME_VERTEX_ID,
+ D3D10_NAME_PRIMITIVE_ID,
+ D3D10_NAME_INSTANCE_ID,
+ D3D10_NAME_IS_FRONT_FACE,
+ D3D10_NAME_SAMPLE_INDEX,
+
+ D3D11_NAME_FINAL_QUAD_EDGE_TESSFACTOR,
+ D3D11_NAME_FINAL_QUAD_INSIDE_TESSFACTOR,
+ D3D11_NAME_FINAL_TRI_EDGE_TESSFACTOR,
+ D3D11_NAME_FINAL_TRI_INSIDE_TESSFACTOR,
+ D3D11_NAME_FINAL_LINE_DETAIL_TESSFACTOR,
+ D3D11_NAME_FINAL_LINE_DENSITY_TESSFACTOR,
+
+ D3D10_NAME_TARGET = 64,
+ D3D10_NAME_DEPTH ,
+ D3D10_NAME_COVERAGE,
+
+ D3D11_NAME_DEPTH_GREATER_EQUAL,
+ D3D11_NAME_DEPTH_LESS_EQUAL,
+} D3D_NAME;
+
+typedef enum D3D_RESOURCE_RETURN_TYPE
+{
+ D3D_RETURN_TYPE_UNORM = 1,
+ D3D_RETURN_TYPE_SNORM,
+ D3D_RETURN_TYPE_SINT,
+ D3D_RETURN_TYPE_UINT,
+ D3D_RETURN_TYPE_FLOAT,
+ D3D_RETURN_TYPE_MIXED,
+ D3D_RETURN_TYPE_DOUBLE,
+ D3D_RETURN_TYPE_CONTINUED,
+
+ D3D10_RETURN_TYPE_UNORM = 1,
+ D3D10_RETURN_TYPE_SNORM,
+ D3D10_RETURN_TYPE_SINT,
+ D3D10_RETURN_TYPE_UINT,
+ D3D10_RETURN_TYPE_FLOAT,
+ D3D10_RETURN_TYPE_MIXED,
+
+ D3D11_RETURN_TYPE_UNORM = 1,
+ D3D11_RETURN_TYPE_SNORM,
+ D3D11_RETURN_TYPE_SINT,
+ D3D11_RETURN_TYPE_UINT,
+ D3D11_RETURN_TYPE_FLOAT,
+ D3D11_RETURN_TYPE_MIXED,
+ D3D11_RETURN_TYPE_DOUBLE,
+ D3D11_RETURN_TYPE_CONTINUED,
+} D3D_RESOURCE_RETURN_TYPE;
+
+typedef enum D3D_REGISTER_COMPONENT_TYPE
+{
+ D3D_REGISTER_COMPONENT_UNKNOWN = 0,
+ D3D_REGISTER_COMPONENT_UINT32,
+ D3D_REGISTER_COMPONENT_SINT32,
+ D3D_REGISTER_COMPONENT_FLOAT32,
+
+ D3D10_REGISTER_COMPONENT_UNKNOWN = 0,
+ D3D10_REGISTER_COMPONENT_UINT32,
+ D3D10_REGISTER_COMPONENT_SINT32,
+ D3D10_REGISTER_COMPONENT_FLOAT32,
+} D3D_REGISTER_COMPONENT_TYPE;
+
+typedef enum D3D_TESSELLATOR_DOMAIN
+{
+ D3D_TESSELLATOR_DOMAIN_UNDEFINED = 0,
+ D3D_TESSELLATOR_DOMAIN_ISOLINE,
+ D3D_TESSELLATOR_DOMAIN_TRI,
+ D3D_TESSELLATOR_DOMAIN_QUAD,
+
+ D3D11_TESSELLATOR_DOMAIN_UNDEFINED = 0,
+ D3D11_TESSELLATOR_DOMAIN_ISOLINE,
+ D3D11_TESSELLATOR_DOMAIN_TRI,
+ D3D11_TESSELLATOR_DOMAIN_QUAD,
+} D3D_TESSELLATOR_DOMAIN;
+
+typedef enum D3D_TESSELLATOR_PARTITIONING
+{
+ D3D_TESSELLATOR_PARTITIONING_UNDEFINED = 0,
+ D3D_TESSELLATOR_PARTITIONING_INTEGER,
+ D3D_TESSELLATOR_PARTITIONING_POW2,
+ D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD,
+ D3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN,
+
+ D3D11_TESSELLATOR_PARTITIONING_UNDEFINED = 0,
+ D3D11_TESSELLATOR_PARTITIONING_INTEGER,
+ D3D11_TESSELLATOR_PARTITIONING_POW2,
+ D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD,
+ D3D11_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN,
+} D3D_TESSELLATOR_PARTITIONING;
+
+typedef enum D3D_TESSELLATOR_OUTPUT_PRIMITIVE
+{
+ D3D_TESSELLATOR_OUTPUT_UNDEFINED = 0,
+ D3D_TESSELLATOR_OUTPUT_POINT,
+ D3D_TESSELLATOR_OUTPUT_LINE,
+ D3D_TESSELLATOR_OUTPUT_TRIANGLE_CW,
+ D3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW,
+
+ D3D11_TESSELLATOR_OUTPUT_UNDEFINED = 0,
+ D3D11_TESSELLATOR_OUTPUT_POINT,
+ D3D11_TESSELLATOR_OUTPUT_LINE,
+ D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CW,
+ D3D11_TESSELLATOR_OUTPUT_TRIANGLE_CCW,
+} D3D_TESSELLATOR_OUTPUT_PRIMITIVE;
+
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/dxgi.idl b/src/gallium/state_trackers/d3d1x/d3dapi/dxgi.idl
new file mode 100644
index 0000000..d268e43
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/dxgi.idl
@@ -0,0 +1,470 @@
+/*
+ * Copyright 2007 Andras Kovacs
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*DXGI 1.1 IDL, and missing DXGI 1.0 parts added by Luca Barbieri on Sep 2010 */
+
+import "dxgitype.idl";
+
+const UINT _FACDXGI = 0x87a;
+
+cpp_quote("#define MAKE_DXGI_STATUS(x) MAKE_HRESULT(0, _FACDXGI, x)")
+cpp_quote("#define DXGI_STATUS_OCCLUDED MAKE_DXGI_STATUS(1)")
+cpp_quote("#define DXGI_STATUS_CLIPPED MAKE_DXGI_STATUS(2)")
+cpp_quote("#define DXGI_STATUS_NO_REDIRECTION MAKE_DXGI_STATUS(4)")
+cpp_quote("#define DXGI_STATUS_NO_DESKTOP_ACCESS MAKE_DXGI_STATUS(5)")
+cpp_quote("#define DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE MAKE_DXGI_STATUS(6)")
+cpp_quote("#define DXGI_STATUS_MODE_CHANGED MAKE_DXGI_STATUS(7)")
+cpp_quote("#define DXGI_STATUS_MODE_CHANGE_IN_PROGRESS MAKE_DXGI_STATUS(8)")
+
+cpp_quote("#define MAKE_DXGI_HRESULT(x) MAKE_HRESULT(1, _FACDXGI, x)")
+cpp_quote("#define DXGI_ERROR_INVALID_CALL MAKE_DXGI_HRESULT(1)")
+cpp_quote("#define DXGI_ERROR_NOT_FOUND MAKE_DXGI_HRESULT(2)")
+cpp_quote("#define DXGI_ERROR_MORE_DATA MAKE_DXGI_HRESULT(3)")
+cpp_quote("#define DXGI_ERROR_UNSUPPORTED MAKE_DXGI_HRESULT(4)")
+cpp_quote("#define DXGI_ERROR_DEVICE_REMOVED MAKE_DXGI_HRESULT(5)")
+cpp_quote("#define DXGI_ERROR_DEVICE_HUNG MAKE_DXGI_HRESULT(6)")
+cpp_quote("#define DXGI_ERROR_DEVICE_RESET MAKE_DXGI_HRESULT(7)")
+cpp_quote("#define DXGI_ERROR_WAS_STILL_DRAWING MAKE_DXGI_HRESULT(10)")
+cpp_quote("#define DXGI_ERROR_FRAME_STATISTICS_DISJOINT MAKE_DXGI_HRESULT(11)")
+cpp_quote("#define DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE MAKE_DXGI_HRESULT(12)")
+cpp_quote("#define DXGI_ERROR_DRIVER_INTERNAL_ERROR MAKE_DXGI_HRESULT(32)")
+cpp_quote("#define DXGI_ERROR_NONEXCLUSIVE MAKE_DXGI_HRESULT(33)")
+cpp_quote("#define DXGI_ERROR_NOT_CURRENTLY_AVAILABLE MAKE_DXGI_HRESULT(34)")
+
+cpp_quote("#if 0")
+typedef HANDLE HMONITOR;
+typedef struct _LUID {
+ DWORD LowPart;
+ LONG HighPart;
+} LUID, *PLUID;
+cpp_quote("#endif")
+
+typedef UINT DXGI_USAGE;
+const DXGI_USAGE DXGI_USAGE_SHADER_INPUT = 0x10L;
+const DXGI_USAGE DXGI_USAGE_RENDER_TARGET_OUTPUT = 0x20L;
+const DXGI_USAGE DXGI_USAGE_BACK_BUFFER = 0x40L;
+const DXGI_USAGE DXGI_USAGE_SHARED = 0x80L;
+const DXGI_USAGE DXGI_USAGE_READ_ONLY = 0x100L;
+
+typedef enum DXGI_SWAP_EFFECT {
+ DXGI_SWAP_EFFECT_DISCARD = 0,
+ DXGI_SWAP_EFFECT_SEQUENTIAL = 1,
+} DXGI_SWAP_EFFECT;
+
+typedef enum DXGI_RESIDENCY {
+ DXGI_RESIDENCY_FULLY_RESIDENT = 1,
+ DXGI_RESIDENCY_RESIDENT_IN_SHARED_MEMORY = 2,
+ DXGI_RESIDENCY_EVICTED_TO_DISK = 3,
+} DXGI_RESIDENCY;
+
+typedef struct DXGI_SURFACE_DESC {
+ UINT Width;
+ UINT Height;
+ DXGI_FORMAT Format;
+ DXGI_SAMPLE_DESC SampleDesc;
+} DXGI_SURFACE_DESC;
+
+typedef struct DXGI_MAPPED_RECT {
+ INT Pitch;
+ BYTE *pBits;
+} DXGI_MAPPED_RECT;
+
+typedef struct DXGI_OUTPUT_DESC {
+ WCHAR DeviceName[32];
+ RECT DesktopCoordinates;
+ BOOL AttachedToDesktop;
+ DXGI_MODE_ROTATION Rotation;
+ HMONITOR Monitor;
+} DXGI_OUTPUT_DESC;
+
+typedef struct DXGI_FRAME_STATISTICS {
+ UINT PresentCount;
+ UINT PresentRefreshCount;
+ UINT SyncRefreshCount;
+ LARGE_INTEGER SyncQPCTime;
+ LARGE_INTEGER SyncGPUTime;
+} DXGI_FRAME_STATISTICS;
+
+typedef struct DXGI_ADAPTER_DESC {
+ WCHAR Description[128];
+ UINT VendorId;
+ UINT DeviceId;
+ UINT SubSysId;
+ UINT Revision;
+ SIZE_T DedicatedVideoMemory;
+ SIZE_T DedicatedSystemMemory;
+ SIZE_T SharedSystemMemory;
+ LUID AdapterLuid;
+} DXGI_ADAPTER_DESC;
+
+typedef struct DXGI_SWAP_CHAIN_DESC {
+ DXGI_MODE_DESC BufferDesc;
+ DXGI_SAMPLE_DESC SampleDesc;
+ DXGI_USAGE BufferUsage;
+ UINT BufferCount;
+ HWND OutputWindow;
+ BOOL Windowed;
+ DXGI_SWAP_EFFECT SwapEffect;
+ UINT Flags;
+} DXGI_SWAP_CHAIN_DESC;
+
+typedef struct DXGI_SHARED_RESOURCE {
+ HANDLE Handle;
+} DXGI_SHARED_RESOURCE;
+
+[
+ object,
+ local,
+ uuid(aec22fb8-76f3-4639-9be0-28eb43a67a2e)
+]
+interface IDXGIObject : IUnknown
+{
+ HRESULT SetPrivateData(
+ [in] REFGUID guid,
+ [in] UINT data_size,
+ [in] const void *data
+ );
+ HRESULT SetPrivateDataInterface(
+ [in] REFGUID guid,
+ [in] const IUnknown *object
+ );
+ HRESULT GetPrivateData(
+ [in] REFGUID guid,
+ [in, out] UINT *data_size,
+ [out] void *data
+ );
+ HRESULT GetParent(
+ [in] REFIID riid,
+ [out] void **parent
+ );
+}
+
+[
+ object,
+ local,
+ uuid(3d3e0379-f9de-4d58-bb6c-18d62992f1a6)
+]
+interface IDXGIDeviceSubObject : IDXGIObject
+{
+ HRESULT GetDevice(
+ [in] REFIID riid,
+ [out] void **device
+ );
+}
+
+[
+ object,
+ local,
+ uuid(cafcb56c-6ac3-4889-bf47-9e23bbd260ec)
+]
+interface IDXGISurface : IDXGIDeviceSubObject
+{
+ HRESULT GetDesc(
+ [out] DXGI_SURFACE_DESC *desc
+ );
+ HRESULT Map(
+ [out] DXGI_MAPPED_RECT *mapped_rect,
+ [in] UINT flags
+ );
+ HRESULT Unmap(
+ );
+}
+
+[
+ object,
+ local,
+ uuid(ae02eedb-c735-4690-8d52-5a8dc20213aa)
+]
+interface IDXGIOutput : IDXGIObject
+{
+ HRESULT GetDesc(
+ [out] DXGI_OUTPUT_DESC *desc
+ );
+ HRESULT GetDisplayModeList(
+ [in] DXGI_FORMAT format,
+ [in] UINT flags,
+ [in, out] UINT *mode_count,
+ [out] DXGI_MODE_DESC *desc
+ );
+ HRESULT FindClosestMatchingMode(
+ [in] const DXGI_MODE_DESC *mode,
+ [out] DXGI_MODE_DESC *closest_match,
+ [in] IUnknown *device
+ );
+ HRESULT WaitForVBlank(
+ );
+ HRESULT TakeOwnership(
+ [in] IUnknown *device,
+ [in] BOOL exclusive
+ );
+ void ReleaseOwnership(
+ );
+ HRESULT GetGammaControlCapabilities(
+ [out] DXGI_GAMMA_CONTROL_CAPABILITIES *gamma_caps
+ );
+ HRESULT SetGammaControl(
+ [in] const DXGI_GAMMA_CONTROL *gamma_control
+ );
+ HRESULT GetGammaControl(
+ [out] DXGI_GAMMA_CONTROL *gamma_control
+ );
+ HRESULT SetDisplaySurface(
+ [in] IDXGISurface *surface
+ );
+ HRESULT GetDisplaySurfaceData(
+ [in] IDXGISurface *surface
+ );
+ HRESULT GetFrameStatistics(
+ [out] DXGI_FRAME_STATISTICS *stats
+ );
+}
+
+[
+ object,
+ local,
+ uuid(2411e7e1-12ac-4ccf-bd14-9798e8534dc0)
+]
+interface IDXGIAdapter : IDXGIObject
+{
+ HRESULT EnumOutputs(
+ [in] UINT output_idx,
+ [in, out] IDXGIOutput **output
+ );
+ HRESULT GetDesc(
+ [out] DXGI_ADAPTER_DESC *desc
+ );
+ HRESULT CheckInterfaceSupport(
+ [in] REFGUID guid,
+ [out] LARGE_INTEGER *umd_version
+ );
+}
+
+[
+ object,
+ local,
+ uuid(310d36a0-d2e7-4c0a-aa04-6a9d23b8886a)
+]
+interface IDXGISwapChain : IDXGIDeviceSubObject
+{
+ HRESULT Present(
+ [in] UINT sync_interval,
+ [in] UINT flags
+ );
+ HRESULT GetBuffer(
+ [in] UINT buffer_idx,
+ [in] REFIID riid,
+ [in, out] void **surface
+ );
+ HRESULT SetFullscreenState(
+ [in] BOOL fullscreen,
+ [in] IDXGIOutput *target
+ );
+ HRESULT GetFullscreenState(
+ [out] BOOL *fullscreen,
+ [out] IDXGIOutput **target
+ );
+ HRESULT GetDesc(
+ [out] DXGI_SWAP_CHAIN_DESC *desc
+ );
+ HRESULT ResizeBuffers(
+ [in] UINT buffer_count,
+ [in] UINT width,
+ [in] UINT height,
+ [in] DXGI_FORMAT format,
+ [in] UINT flags
+ );
+ HRESULT ResizeTarget(
+ [in] const DXGI_MODE_DESC *target_mode_desc
+ );
+ HRESULT GetContainingOutput(
+ [out] IDXGIOutput **output
+ );
+ HRESULT GetFrameStatistics(
+ [out] DXGI_FRAME_STATISTICS *stats
+ );
+ HRESULT GetLastPresentCount(
+ [out] UINT *last_present_count
+ );
+}
+
+[
+ object,
+ local,
+ uuid(7b7166ec-21c7-44ae-b21a-c9ae321ae369)
+]
+interface IDXGIFactory : IDXGIObject
+{
+ HRESULT EnumAdapters(
+ [in] UINT adapter_idx,
+ [out] IDXGIAdapter **adapter
+ );
+ HRESULT MakeWindowAssociation(
+ [in] HWND window,
+ [in] UINT flags
+ );
+ HRESULT GetWindowAssociation(
+ [in] HWND *window
+ );
+ HRESULT CreateSwapChain(
+ [in] IUnknown *device,
+ [in] DXGI_SWAP_CHAIN_DESC *desc,
+ [out] IDXGISwapChain **swapchain
+ );
+ HRESULT CreateSoftwareAdapter(
+ [in] HMODULE swrast,
+ [out] IDXGIAdapter **adapter
+ );
+}
+
+[local] HRESULT CreateDXGIFactory(REFIID riid, void **factory);
+
+[
+ object,
+ local,
+ uuid(54ec77fa-1377-44e6-8c32-88fd5f44c84c)
+]
+interface IDXGIDevice : IDXGIObject
+{
+ HRESULT GetAdapter(
+ [out] IDXGIAdapter **adapter
+ );
+ HRESULT CreateSurface(
+ [in] const DXGI_SURFACE_DESC *desc,
+ [in] UINT surface_count,
+ [in] DXGI_USAGE usage,
+ [in] const DXGI_SHARED_RESOURCE *shared_resource,
+ [out] IDXGISurface **surface
+ );
+ HRESULT QueryResourceResidency(
+ [in] IUnknown *const *resources,
+ [out] DXGI_RESIDENCY *residency,
+ [in] UINT resource_count
+ );
+ HRESULT SetGPUThreadPriority(
+ [in] INT priority
+ );
+ HRESULT GetGPUThreadPriority(
+ [out] INT *priority
+ );
+}
+
+
+// BEGIN parts added for Gallium
+
+const unsigned int DXGI_MAP_READ = 1;
+const unsigned int DXGI_MAP_WRITE = 2;
+const unsigned int DXGI_MAP_DISCARD = 4;
+
+const unsigned int DXGI_CPU_ACCESS_NONE = 0;
+const unsigned int DXGI_CPU_ACCESS_DYNAMIC = 1;
+const unsigned int DXGI_CPU_ACCESS_READ_WRITE = 2;
+const unsigned int DXGI_CPU_ACCESS_SCRATCH = 3;
+const unsigned int DXGI_CPU_ACCESS_FIELD = 15;
+const unsigned int DXGI_USAGE_DISCARD_ON_PRESENT = 0x200;
+const unsigned int DXGI_USAGE_UNORDERED_ACCESS = 0x400;
+
+const unsigned int DXGI_PRESENT_TEST = 1;
+const unsigned int DXGI_PRESENT_DO_NOT_SEQUENCE = 2;
+const unsigned int DXGI_PRESENT_RESTART = 4;
+
+typedef enum DXGI_SWAP_CHAIN_FLAG
+{
+ DXGI_SWAP_CHAIN_FLAG_NONPREROTATED = 1,
+ DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH = 2,
+ DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE = 4
+} DXGI_SWAP_CHAIN_FLAG;
+
+typedef struct DXGI_ADAPTER_DESC1
+{
+ WCHAR Description[128];
+ UINT VendorId;
+ UINT DeviceId;
+ UINT SubSysId;
+ UINT Revision;
+ SIZE_T DedicatedVideoMemory;
+ SIZE_T DedicatedSystemMemory;
+ SIZE_T SharedSystemMemory;
+ LUID AdapterLuid;
+ UINT Flags;
+} DXGI_ADAPTER_DESC1;
+
+[object, local, uuid("035f3ab4-482e-4e50-b41f-8a7f8bd8960b")]
+interface IDXGIResource : IDXGIDeviceSubObject
+{
+ HRESULT GetSharedHandle(
+ [out] HANDLE *pSharedHandle
+ );
+
+ HRESULT GetUsage(
+ [out] DXGI_USAGE *pUsage
+ );
+
+ HRESULT SetEvictionPriority(
+ [in] UINT EvictionPriority
+ );
+
+ HRESULT GetEvictionPriority(
+ [out] UINT *pEvictionPriority
+ );
+};
+
+[object, local, uuid("4AE63092-6327-4c1b-80AE-BFE12EA32B86")]
+interface IDXGISurface1 : IDXGISurface
+{
+ HRESULT GetDC(
+ [in] BOOL Discard,
+ [out] HDC *phdc
+ );
+
+ HRESULT ReleaseDC(
+ [in, optional] RECT *pDirtyRect
+ );
+ };
+
+[object, local, uuid("77db970f-6276-48ba-ba28-070143b4392c")]
+interface IDXGIDevice1 : IDXGIDevice
+{
+ HRESULT SetMaximumFrameLatency(
+ [in] UINT MaxLatency
+ );
+
+ HRESULT GetMaximumFrameLatency(
+ [out] UINT *pMaxLatency
+ );
+};
+
+[object, local, uuid("29038f61-3839-4626-91fd-086879011a05")]
+interface IDXGIAdapter1 : IDXGIAdapter
+{
+ HRESULT GetDesc1(
+ [out] DXGI_ADAPTER_DESC1 *pDesc
+ );
+};
+
+[object, local, uuid("770aae78-f26f-4dba-a829-253c83d1b387")]
+interface IDXGIFactory1 : IDXGIFactory
+{
+ HRESULT EnumAdapters1(
+ [in] UINT Adapter,
+ [out] IDXGIAdapter1 **ppAdapter
+ );
+
+ BOOL IsCurrent();
+};
+
+[local] HRESULT CreateDXGIFactory1(REFIID riid, void **factory);
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/dxgiformat.idl b/src/gallium/state_trackers/d3d1x/d3dapi/dxgiformat.idl
new file mode 100644
index 0000000..28846e9
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/dxgiformat.idl
@@ -0,0 +1,129 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+typedef enum DXGI_FORMAT {
+ DXGI_FORMAT_UNKNOWN,
+ DXGI_FORMAT_R32G32B32A32_TYPELESS,
+ DXGI_FORMAT_R32G32B32A32_FLOAT,
+ DXGI_FORMAT_R32G32B32A32_UINT,
+ DXGI_FORMAT_R32G32B32A32_SINT,
+ DXGI_FORMAT_R32G32B32_TYPELESS,
+ DXGI_FORMAT_R32G32B32_FLOAT,
+ DXGI_FORMAT_R32G32B32_UINT,
+ DXGI_FORMAT_R32G32B32_SINT,
+ DXGI_FORMAT_R16G16B16A16_TYPELESS,
+ DXGI_FORMAT_R16G16B16A16_FLOAT,
+ DXGI_FORMAT_R16G16B16A16_UNORM,
+ DXGI_FORMAT_R16G16B16A16_UINT,
+ DXGI_FORMAT_R16G16B16A16_SNORM,
+ DXGI_FORMAT_R16G16B16A16_SINT,
+ DXGI_FORMAT_R32G32_TYPELESS,
+ DXGI_FORMAT_R32G32_FLOAT,
+ DXGI_FORMAT_R32G32_UINT,
+ DXGI_FORMAT_R32G32_SINT,
+ DXGI_FORMAT_R32G8X24_TYPELESS,
+ DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
+ DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS,
+ DXGI_FORMAT_X32_TYPELESS_G8X24_UINT,
+ DXGI_FORMAT_R10G10B10A2_TYPELESS,
+ DXGI_FORMAT_R10G10B10A2_UNORM,
+ DXGI_FORMAT_R10G10B10A2_UINT,
+ DXGI_FORMAT_R11G11B10_FLOAT,
+ DXGI_FORMAT_R8G8B8A8_TYPELESS,
+ DXGI_FORMAT_R8G8B8A8_UNORM,
+ DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
+ DXGI_FORMAT_R8G8B8A8_UINT,
+ DXGI_FORMAT_R8G8B8A8_SNORM,
+ DXGI_FORMAT_R8G8B8A8_SINT,
+ DXGI_FORMAT_R16G16_TYPELESS,
+ DXGI_FORMAT_R16G16_FLOAT,
+ DXGI_FORMAT_R16G16_UNORM,
+ DXGI_FORMAT_R16G16_UINT,
+ DXGI_FORMAT_R16G16_SNORM,
+ DXGI_FORMAT_R16G16_SINT,
+ DXGI_FORMAT_R32_TYPELESS,
+ DXGI_FORMAT_D32_FLOAT,
+ DXGI_FORMAT_R32_FLOAT,
+ DXGI_FORMAT_R32_UINT,
+ DXGI_FORMAT_R32_SINT,
+ DXGI_FORMAT_R24G8_TYPELESS,
+ DXGI_FORMAT_D24_UNORM_S8_UINT,
+ DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
+ DXGI_FORMAT_X24_TYPELESS_G8_UINT,
+ DXGI_FORMAT_R8G8_TYPELESS,
+ DXGI_FORMAT_R8G8_UNORM,
+ DXGI_FORMAT_R8G8_UINT,
+ DXGI_FORMAT_R8G8_SNORM,
+ DXGI_FORMAT_R8G8_SINT,
+ DXGI_FORMAT_R16_TYPELESS,
+ DXGI_FORMAT_R16_FLOAT,
+ DXGI_FORMAT_D16_UNORM,
+ DXGI_FORMAT_R16_UNORM,
+ DXGI_FORMAT_R16_UINT,
+ DXGI_FORMAT_R16_SNORM,
+ DXGI_FORMAT_R16_SINT,
+ DXGI_FORMAT_R8_TYPELESS,
+ DXGI_FORMAT_R8_UNORM,
+ DXGI_FORMAT_R8_UINT,
+ DXGI_FORMAT_R8_SNORM,
+ DXGI_FORMAT_R8_SINT,
+ DXGI_FORMAT_A8_UNORM,
+ DXGI_FORMAT_R1_UNORM,
+ DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
+ DXGI_FORMAT_R8G8_B8G8_UNORM,
+ DXGI_FORMAT_G8R8_G8B8_UNORM,
+ DXGI_FORMAT_BC1_TYPELESS,
+ DXGI_FORMAT_BC1_UNORM,
+ DXGI_FORMAT_BC1_UNORM_SRGB,
+ DXGI_FORMAT_BC2_TYPELESS,
+ DXGI_FORMAT_BC2_UNORM,
+ DXGI_FORMAT_BC2_UNORM_SRGB,
+ DXGI_FORMAT_BC3_TYPELESS,
+ DXGI_FORMAT_BC3_UNORM,
+ DXGI_FORMAT_BC3_UNORM_SRGB,
+ DXGI_FORMAT_BC4_TYPELESS,
+ DXGI_FORMAT_BC4_UNORM,
+ DXGI_FORMAT_BC4_SNORM,
+ DXGI_FORMAT_BC5_TYPELESS,
+ DXGI_FORMAT_BC5_UNORM,
+ DXGI_FORMAT_BC5_SNORM,
+ DXGI_FORMAT_B5G6R5_UNORM,
+ DXGI_FORMAT_B5G5R5A1_UNORM,
+ DXGI_FORMAT_B8G8R8A8_UNORM,
+ DXGI_FORMAT_B8G8R8X8_UNORM,
+ DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM,
+ DXGI_FORMAT_B8G8R8A8_TYPELESS,
+ DXGI_FORMAT_B8G8R8A8_UNORM_SRGB,
+ DXGI_FORMAT_B8G8R8X8_TYPELESS,
+ DXGI_FORMAT_B8G8R8X8_UNORM_SRGB,
+ DXGI_FORMAT_BC6H_TYPELESS,
+ DXGI_FORMAT_BC6H_UF16,
+ DXGI_FORMAT_BC6H_SF16,
+ DXGI_FORMAT_BC7_TYPELESS,
+ DXGI_FORMAT_BC7_UNORM,
+ DXGI_FORMAT_BC7_UNORM_SRGB,
+ DXGI_FORMAT_FORCE_UINT = 0xffffffff
+} DXGI_FORMAT;
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/dxgitype.idl b/src/gallium/state_trackers/d3d1x/d3dapi/dxgitype.idl
new file mode 100644
index 0000000..9584407
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/dxgitype.idl
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2007 Andras Kovacs
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/* DXGI 1.1 IDL, and missing DXGI 1.0 parts added by Luca Barbieri on Sep 2010 */
+
+import "oaidl.idl";
+import "ocidl.idl";
+
+import "dxgiformat.idl";
+
+typedef struct DXGI_SAMPLE_DESC {
+ UINT Count;
+ UINT Quality;
+} DXGI_SAMPLE_DESC;
+
+typedef enum DXGI_MODE_ROTATION {
+ DXGI_MODE_ROTATION_UNSPECIFIED = 0,
+ DXGI_MODE_ROTATION_IDENTITY = 1,
+ DXGI_MODE_ROTATION_ROTATE90 = 2,
+ DXGI_MODE_ROTATION_ROTATE180 = 3,
+ DXGI_MODE_ROTATION_ROTATE270 = 4,
+} DXGI_MODE_ROTATION;
+
+typedef enum DXGI_MODE_SCANLINE_ORDER {
+ DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED = 0,
+ DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE = 1,
+ DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST = 2,
+ DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST = 3,
+} DXGI_MODE_SCANLINE_ORDER;
+
+typedef enum DXGI_MODE_SCALING {
+ DXGI_MODE_SCALING_UNSPECIFIED = 0,
+ DXGI_MODE_SCALING_CENTERED = 1,
+ DXGI_MODE_SCALING_STRETCHED = 2,
+} DXGI_MODE_SCALING;
+
+typedef struct DXGI_RATIONAL {
+ UINT Numerator;
+ UINT Denominator;
+} DXGI_RATIONAL;
+
+typedef struct DXGI_MODE_DESC {
+ UINT Width;
+ UINT Height;
+ DXGI_RATIONAL RefreshRate;
+ DXGI_FORMAT Format;
+ DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
+ DXGI_MODE_SCALING Scaling;
+} DXGI_MODE_DESC;
+
+typedef struct DXGI_GAMMA_CONTROL_CAPABILITIES {
+ BOOL ScaleAndOffsetSupported;
+ float MaxConvertedValue;
+ float MinConvertedValue;
+ UINT NumGammaControlPoints;
+ float ControlPointPositions[1025];
+} DXGI_GAMMA_CONTROL_CAPABILITIES;
+
+typedef struct DXGI_RGB {
+ float Red;
+ float Green;
+ float Blue;
+} DXGI_RGB;
+
+typedef struct DXGI_GAMMA_CONTROL {
+ DXGI_RGB Scale;
+ DXGI_RGB Offset;
+ DXGI_RGB GammaCurve[1025];
+} DXGI_GAMMA_CONTROL;
diff --git a/src/gallium/state_trackers/d3d1x/d3dapi/specstrings.h b/src/gallium/state_trackers/d3d1x/d3dapi/specstrings.h
new file mode 100644
index 0000000..fbd390f
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/d3dapi/specstrings.h
@@ -0,0 +1,25 @@
+#ifndef SPECSTRINGS_H
+#define SPECSTRINGS_H
+
+#define __in
+#define __in_opt
+#define __out
+#define __out_opt
+#define __inout
+#define __inout_opt
+#define __in_bcount(...)
+#define __in_bcount_opt(...)
+#define __in_ecount(...)
+#define __in_ecount_opt(...)
+#define __in_xcount(...)
+#define __in_xcount_opt(...)
+#define __out_bcount(...)
+#define __out_bcount_opt(...)
+#define __out_ecount(...)
+#define __out_ecount_opt(...)
+#define __out_ecount_part_opt(...)
+#define __in_range(...)
+#define __inout_range(...)
+#define __out_range(...)
+
+#endif
diff --git a/src/gallium/state_trackers/d3d1x/docs/Makefile b/src/gallium/state_trackers/d3d1x/docs/Makefile
new file mode 100644
index 0000000..ca1e3ce
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/docs/Makefile
@@ -0,0 +1,4 @@
+all: module_dependencies.svg module_dependencies.pdf
+
+include ../Makefile.inc
+
diff --git a/src/gallium/state_trackers/d3d1x/docs/coding_style.txt b/src/gallium/state_trackers/d3d1x/docs/coding_style.txt
new file mode 100644
index 0000000..a644a13
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/docs/coding_style.txt
@@ -0,0 +1,85 @@
+The goal of these guidelines is to allow as much freedom as possible, while keeping the code buildable and pleasant to read.
+
+* Formatting
+
+- Indent with a single tab character. This is the best choice, since anyone can use the visual indentation he prefers by adjust the tab width setting in his editor.
+- Align multiline statements with an additional extra tab before each continuation line
+- Keep in mind that people can program with proportional fonts: hence, don't attempt to align anything not at the start of the line, since it's impossible
+- In general, there should never be two consecutive spaces in the source code
+- As a special exception, [in] and __in annotations are followed by two spaces to align them with [out] and __out if displayed with a fixed size font. This may be revisited.
+- There is no strict limit on line length, but try to not make lines too long, and insert a line break where it looks good
+
+* Language/platform features
+
+All language features of C++03 with TR1 and all the STL library may be used.
+Obviously, try to keep the code simple, readable and intuitive, code size small, and compilation time short where possible.
+Platform/compiler-specific extensions can be used if beneficial, protected by #ifs.
+
+C++0x is currently not used since it's unreleased and currently not well supported by clang.
+Once GCC, clang and Visual C++ all have very good or complete support, and ideally the standard is finalized, we can start taking advantage of it.
+Change this document once that happens.
+
+Boost is currently not used because it hasn't been necessary and it's best to keep things simple.
+If really necessary, add a dependency on it, but use it judiciously.
+
+C should be used only for old code, and preferably completely avoided.
+
+You can freely assume that char is 8-bit, short 16-bit and int 32-bit, that long and pointers are 32-bit or 64-bit, that long long is at least 64-bit, that float is 32-bit and that double is 64-bit.
+However, when you intend a specific size, int8_t, etc. are preferred.
+
+* Naming style
+
+ Code implementing public parts of Windows interfaces (and derived ones) should follow Windows naming conventions:
+ - Classes are like GalliumD3D11VertexShader
+ - Functions are like CreateVertexShader
+ - Variables are like ppVertexShader
+
+ Other code should follow Gallium/Linux/POSIX/STL/Boost naming conventions:
+ - Classes are like maybe_mutex_t
+ - Functions are like xs_create_shader
+ - Variables are like sampler_view
+
+ Template parameters are named accordingly to what looks best for the specific case.
+ Typically it will be FooBar for typename parameters and foo_bar for non-typename ones.
+
+ * Implementation style
+
+See the comments in d3d1xstutil.h for the COM implementation method.
+In particular, avoid multiple/virtual inheritance in favor of mixins where possible.
+
+Try to limit or avoid preprocessor magic and multiline macros and use templates instead where possible.
+Often, you can lessen the preprocessor magic by putting some of it in a template instantiated by the remaining magic.
+
+Forward declarations should not be used unless necessary.
+In particular C++ classes should be implemented "inline" and should you should almost never have a forward declaration of a class.
+To achieve this, you can opt to create an "interface class", which goes into an header or earlier in the C++ file, and an "implementation class" with goes in the C++ file.
+Alternatively, use global helpers with forward declaration.
+
+Order definitions so that forward declarations are not necessary (e.g. put main at the end of the file).
+
+Choose between "struct" or "class" depending on whether the first declared member is public or private, to save the explicit specifier.
+
+Try to use const appropriately, esp. as a qualifier for member functions.
+
+Try to avoid Microsoft-style TYPES like FLOAT, UINT, etc. in favor of the usual C types like float, unsigned.
+
+Where feasible, if a platform is missing a function/keyword, add a definition of it with the standard name, rather than inventing an "abstraction layer".
+
+Try to use typedefs for STL maps on which you need to declare iterations, as well as function pointers or other "weird" C types.
+
+ To iterate, use the following idiom from LLVM, which is optimal, unless end() is trivial:
+ for(iterator_type i = begin(), e = end(); i != e; ++i)
+ {}
+
+ Otherwise, you risk the compiler evaluating end() for each loop iteration.
+ If end() is trivial, use this:
+ for(iterator_type i = begin(); i != end(); ++i)
+ {}
+
+ Note the "++i" instead of the "i++" to avoid creating an unnecessary copy (esp. with overloaded operators).
+
+ Declare variables just before they are needed, and inside the for() header.
+ Usually, you should initialize variable in the declaration if that's the only assignment or if it is a default value, and as a separate assignment if not.
+
+Try to use C++ references (with const if appropriate) when the pointer must be non-null, and that type is not already customarily passed with a pointer.
+
diff --git a/src/gallium/state_trackers/d3d1x/docs/module_dependencies.dot b/src/gallium/state_trackers/d3d1x/docs/module_dependencies.dot
new file mode 100644
index 0000000..3db6fb2
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/docs/module_dependencies.dot
@@ -0,0 +1,25 @@
+digraph module_dependencies
+{
+ d3dapi -> w32api;
+ gd3dapi -> d3dapi;
+ progs -> d3dapi [style="dotted"];
+ progs -> gd3dapi [style="dotted"];
+ progs -> microsoft_directx_sdk [style="dotted"];
+ d3d1xstutil -> gd3dapi
+ d3d1xshader -> d3dapi
+ gd3d1x -> d3d1xshader;
+ gd3d1x -> d3d1xstutil;
+ gd3d10 -> gd3d1x;
+ gd3d11 -> gd3d1x;
+ dxgi -> d3d1xstutil;
+ dxgi -> gd3dapi;
+ dxgid3d10 -> gd3dapi;
+ dxgid3d11 -> gd3dapi;
+ "d3d11.dll" -> gd3d11;
+ "d3d11.dll" -> dxgid3d11;
+ "d3d10.dll" -> gd3d10;
+ "d3d10.dll" -> dxgid3d10;
+ "dxgi.dll" -> dxgi;
+ tools -> mstools
+ mstools -> microsoft_directx_sdk
+};
diff --git a/src/gallium/state_trackers/d3d1x/docs/source_layout.txt b/src/gallium/state_trackers/d3d1x/docs/source_layout.txt
new file mode 100644
index 0000000..46e9f2d
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/docs/source_layout.txt
@@ -0,0 +1,17 @@
+Source layout and architecture of the Gallium D3D state tracker
+
+w32api is a link to Wine's include files for the Windows API
+d3dapi contains the headers for Direct3D 10.0, 10.1 and 11.0 (independently created, except d3d10 which is based on Wine)
+gd3dapi contains the Gallium COM state tracker API and extensions to the DXGI and Direct3D APIs, both for internal and external usage
+d3d1xshader is a standalone module with a parser, disassembler and utility routines for Direct3D 10/11 shaders using Shader Model 4/5 instructions encoded using Tokenized Program Format embedded in a DXBC chunked container (the data format produced by the HLSL compiler).
+mstools contains a downloader for the Microsoft HLSL compiler
+tools contains the shader compiler, currently wrapping the Microsoft HLSL compiler
+gd3d10 contains the implementation of Direct3D 10 and 10.1 with Gallium-specific entry points
+gd3d11 contains the implementation of Direct3D 11 with Gallium-specific entry points
+gd3d1x contains the shader translator and code not directly implementing Direct3D interfaces, but needed by those implementations
+dxgid3d10 contains the DXGI-based "official" entry points to Direct3D 10.0 and 10.1
+dxgid3d11 contains the DXGI-based "official" entry points to Direct3D 11
+dxgi contains the implementation of DXGI (currently over the EGL native interface)
+d3d1xstutil contains helper code shared among all the modules in the state tracker
+programs contains the Gallium Direct3D 11 demos, runnable either on the Microsoft or Gallium implementations
+docs contains documentation
diff --git a/src/gallium/state_trackers/d3d1x/dxgi/Makefile b/src/gallium/state_trackers/d3d1x/dxgi/Makefile
new file mode 100644
index 0000000..323f6f7
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgi/Makefile
@@ -0,0 +1,17 @@
+LIBNAME=dxgi
+LIBRARY_INCLUDES=-Iinclude -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common
+LIBRARY_DEFINES=-DDXGI_DRIVER_SEARCH_DIR=\"$(EGL_DRIVER_INSTALL_DIR)\"
+CPP_SOURCES=$(wildcard src/*.cpp)
+
+include ../Makefile.inc
+
+ifneq ($(findstring x11, $(EGL_PLATFORMS)),)
+LIBRARY_DEFINES += -DGALLIUM_DXGI_USE_X11
+endif
+ifneq ($(findstring drm, $(EGL_PLATFORMS)),)
+LIBRARY_DEFINES += -DGALLIUM_DXGI_USE_DRM
+endif
+ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),)
+LIBRARY_DEFINES += -DGALLIUM_DXGI_USE_FBDEV
+endif
+
diff --git a/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_loader.cpp b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_loader.cpp
new file mode 100644
index 0000000..e5ba309
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_loader.cpp
@@ -0,0 +1,206 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * 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 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#include "dxgi_private.h"
+#include <stdio.h>
+extern "C"
+{
+#include "state_tracker/drm_driver.h"
+#include "util/u_dl.h"
+}
+#define PIPE_PREFIX "pipe_"
+
+static const char *
+get_search_path(void)
+{
+ static const char *search_path;
+
+ if (!search_path) {
+ static char buffer[1024];
+ const char *p;
+ int ret;
+
+ p = getenv("DXGI_DRIVERS_PATH");
+ if(!p)
+ p = getenv("EGL_DRIVERS_PATH");
+#ifdef __unix__
+ if (p && (geteuid() != getuid() || getegid() != getgid())) {
+ p = NULL;
+ }
+#endif
+
+ if (p) {
+ ret = snprintf(buffer, sizeof(buffer),
+ "%s:%s", p, DXGI_DRIVER_SEARCH_DIR);
+ if (ret > 0 && ret < (int)sizeof(buffer))
+ search_path = buffer;
+ }
+ }
+ if (!search_path)
+ search_path = DXGI_DRIVER_SEARCH_DIR;
+
+ return search_path;
+}
+
+static void
+for_each_colon_separated(const char *search_path,
+ bool (*loader)(const char *, size_t, void *),
+ void *loader_data)
+{
+ const char *cur, *next;
+ size_t len;
+
+ cur = search_path;
+ while (cur) {
+ next = strchr(cur, ':');
+ len = (next) ? next - cur : strlen(cur);
+
+ if (!loader(cur, len, loader_data))
+ break;
+
+ cur = (next) ? next + 1 : NULL;
+ }
+}
+
+void
+for_each_in_search_path(bool (*callback)(const char *, size_t, void *),
+ void *callback_data)
+{
+ const char *search_path = get_search_path();
+ for_each_colon_separated(search_path, callback, callback_data);
+}
+
+static struct pipe_module {
+ boolean initialized;
+ char *name;
+ struct util_dl_library *lib;
+ const struct drm_driver_descriptor *drmdd;
+ struct pipe_screen *(*swrast_create_screen)(struct sw_winsys *);
+} pipe_modules[16];
+
+static bool
+dlopen_pipe_module_cb(const char *dir, size_t len, void *callback_data)
+{
+ struct pipe_module *pmod = (struct pipe_module *) callback_data;
+ char path[1024];
+ int ret;
+
+ if (len) {
+ ret = snprintf(path, sizeof(path),
+ "%.*s/" PIPE_PREFIX "%s" UTIL_DL_EXT, len, dir, pmod->name);
+ }
+ else {
+ ret = snprintf(path, sizeof(path),
+ PIPE_PREFIX "%s" UTIL_DL_EXT, pmod->name);
+ }
+ if (ret > 0 && ret < (int)sizeof(path)) {
+ pmod->lib = util_dl_open(path);
+ }
+
+ return !(pmod->lib);
+}
+
+static bool
+load_pipe_module(struct pipe_module *pmod, const char *name)
+{
+ pmod->name = strdup(name);
+ if (!pmod->name)
+ return FALSE;
+
+ for_each_in_search_path(dlopen_pipe_module_cb, (void *) pmod);
+ if (pmod->lib) {
+ pmod->drmdd = (const struct drm_driver_descriptor *)
+ util_dl_get_proc_address(pmod->lib, "driver_descriptor");
+
+ /* sanity check on the name */
+ if (pmod->drmdd && strcmp(pmod->drmdd->name, pmod->name) != 0)
+ pmod->drmdd = NULL;
+
+ /* swrast */
+ if (pmod->drmdd && !pmod->drmdd->driver_name) {
+ pmod->swrast_create_screen =
+ (struct pipe_screen *(*)(struct sw_winsys *))
+ util_dl_get_proc_address(pmod->lib, "swrast_create_screen");
+ if (!pmod->swrast_create_screen)
+ pmod->drmdd = NULL;
+ }
+
+ if (!pmod->drmdd) {
+ util_dl_close(pmod->lib);
+ pmod->lib = NULL;
+ }
+ }
+
+ return (pmod->drmdd != NULL);
+}
+
+
+static struct pipe_module *
+get_pipe_module(const char *name)
+{
+ struct pipe_module *pmod = NULL;
+ unsigned i;
+
+ if (!name)
+ return NULL;
+
+ for (i = 0; i < sizeof(pipe_modules) / sizeof(pipe_modules[0]); i++) {
+ if (!pipe_modules[i].initialized ||
+ strcmp(pipe_modules[i].name, name) == 0) {
+ pmod = &pipe_modules[i];
+ break;
+ }
+ }
+ if (!pmod)
+ return NULL;
+
+ if (!pmod->initialized) {
+ load_pipe_module(pmod, name);
+ pmod->initialized = TRUE;
+ }
+
+ return pmod;
+}
+
+struct native_display;
+
+struct pipe_screen *
+dxgi_loader_create_drm_screen(struct native_display* dpy, const char *name, int fd)
+{
+ struct pipe_module *pmod = get_pipe_module(name);
+ return (pmod && pmod->drmdd && pmod->drmdd->create_screen) ?
+ pmod->drmdd->create_screen(fd) : NULL;
+}
+
+struct pipe_screen *
+dxgi_loader_create_sw_screen(struct native_display* dpy, struct sw_winsys *ws)
+{
+ struct pipe_module *pmod = get_pipe_module("swrast");
+ return (pmod && pmod->swrast_create_screen) ?
+ pmod->swrast_create_screen(ws) : NULL;
+}
diff --git a/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp
new file mode 100644
index 0000000..69ddbc5
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp
@@ -0,0 +1,1314 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "dxgi_private.h"
+extern "C" {
+#include "native.h"
+#include <util/u_format.h>
+#include <util/u_inlines.h>
+#include <util/u_simple_shaders.h>
+#include <pipe/p_shader_tokens.h>
+}
+#include <iostream>
+#include <memory>
+
+struct GalliumDXGIOutput;
+struct GalliumDXGIAdapter;
+struct GalliumDXGISwapChain;
+struct GalliumDXGIFactory;
+
+static HRESULT GalliumDXGISwapChainCreate(GalliumDXGIFactory* factory, IUnknown* device, const DXGI_SWAP_CHAIN_DESC& desc, IDXGISwapChain** ppSwapChain);
+static HRESULT GalliumDXGIAdapterCreate(GalliumDXGIFactory* adapter, const struct native_platform* platform, void* dpy, IDXGIAdapter1** ppAdapter);
+static HRESULT GalliumDXGIOutputCreate(GalliumDXGIAdapter* adapter, const std::string& name, const struct native_connector* connector, IDXGIOutput** ppOutput);
+static void GalliumDXGISwapChainRevalidate(IDXGISwapChain* swap_chain);
+
+template<typename Base = IDXGIObject, typename Parent = IDXGIObject>
+struct GalliumDXGIObject : public GalliumPrivateDataComObject<Base>
+{
+ ComPtr<Parent> parent;
+
+ GalliumDXGIObject(Parent* p_parent = 0)
+ {
+ this->parent = p_parent;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetParent(
+ __in REFIID riid,
+ __out void **ppParent)
+ {
+ return parent->QueryInterface(riid, ppParent);
+ }
+};
+
+static void* STDMETHODCALLTYPE identity_resolver(void* cookie, HWND hwnd)
+{
+ return (void*)hwnd;
+}
+
+struct GalliumDXGIFactory : public GalliumDXGIObject<IDXGIFactory1, IUnknown>
+{
+ HWND associated_window;
+ const struct native_platform* platform;
+ void* display;
+ PFNHWNDRESOLVER resolver;
+ void* resolver_cookie;
+
+ GalliumDXGIFactory(const struct native_platform* platform, void* display, PFNHWNDRESOLVER resolver, void* resolver_cookie)
+ : GalliumDXGIObject((IUnknown*)NULL), platform(platform), display(display), resolver(resolver ? resolver : identity_resolver), resolver_cookie(resolver_cookie)
+ {}
+
+ virtual HRESULT STDMETHODCALLTYPE EnumAdapters(
+ UINT Adapter,
+ __out IDXGIAdapter **ppAdapter)
+ {
+ return EnumAdapters1(Adapter, (IDXGIAdapter1**)ppAdapter);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE EnumAdapters1(
+ UINT Adapter,
+ __out IDXGIAdapter1 **ppAdapter)
+ {
+ *ppAdapter = 0;
+ if(Adapter == 0)
+ {
+ return GalliumDXGIAdapterCreate(this, platform, display, ppAdapter);
+ }
+#if 0
+ // TODO: enable this
+ if(platform == native_get_x11_platform())
+ {
+ unsigned nscreens = ScreenCount((Display*)display);
+ if(Adapter < nscreens)
+ {
+ unsigned def_screen = DefaultScreen(display);
+ if(Adapter <= def_screen)
+ --Adapter;
+ *ppAdapter = GalliumDXGIAdapterCreate(this, platform, display, Adapter);
+ return S_OK;
+ }
+ }
+#endif
+ return DXGI_ERROR_NOT_FOUND;
+ }
+
+ /* TODO: this is a mysterious underdocumented magic API
+ * Can we have multiple windows associated?
+ * Can we have multiple windows associated if we use multiple factories?
+ * If so, what should GetWindowAssociation return?
+ * If not, does a new swapchain steal the association?
+ * Does this act for existing swapchains? For new swapchains?
+ */
+ virtual HRESULT STDMETHODCALLTYPE MakeWindowAssociation(
+ HWND WindowHandle,
+ UINT Flags)
+ {
+ /* TODO: actually implement, for Wine, X11 and KMS*/
+ associated_window = WindowHandle;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetWindowAssociation(
+ __out HWND *pWindowHandle)
+ {
+ *pWindowHandle = associated_window;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateSwapChain(
+ __in IUnknown *pDevice,
+ __in DXGI_SWAP_CHAIN_DESC *pDesc,
+ __out IDXGISwapChain **ppSwapChain)
+ {
+ return GalliumDXGISwapChainCreate(this, pDevice, *pDesc, ppSwapChain);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter(
+ HMODULE Module,
+ __out IDXGIAdapter **ppAdapter)
+ {
+ /* TODO: ignore the module, and just create a Gallium software screen */
+ *ppAdapter = 0;
+ return E_NOTIMPL;
+ }
+
+ /* TODO: support hotplug */
+ virtual BOOL STDMETHODCALLTYPE IsCurrent( void)
+ {
+ return TRUE;
+ }
+};
+
+struct GalliumDXGIAdapter
+ : public GalliumMultiComObject<
+ GalliumDXGIObject<IDXGIAdapter1, GalliumDXGIFactory>,
+ IGalliumAdapter>
+{
+ struct native_display* display;
+ const struct native_config** configs;
+ std::unordered_multimap<unsigned, unsigned> configs_by_pipe_format;
+ std::unordered_map<unsigned, unsigned> configs_by_native_visual_id;
+ const struct native_connector** connectors;
+ unsigned num_configs;
+ DXGI_ADAPTER_DESC1 desc;
+ std::vector<ComPtr<IDXGIOutput> > outputs;
+ int num_outputs;
+ struct native_event_handler handler;
+
+ GalliumDXGIAdapter(GalliumDXGIFactory* factory, const struct native_platform* platform, void* dpy)
+ {
+ this->parent = factory;
+
+ handler.invalid_surface = handle_invalid_surface;
+ handler.new_drm_screen = dxgi_loader_create_drm_screen;
+ handler.new_sw_screen = dxgi_loader_create_sw_screen;
+ display = platform->create_display(dpy, &handler, this);
+ if(!display)
+ throw E_FAIL;
+ memset(&desc, 0, sizeof(desc));
+ std::string s = std::string("GalliumD3D on ") + display->screen->get_name(display->screen) + " by " + display->screen->get_vendor(display->screen);
+
+ /* hopefully no one will decide to use UTF-8 in Gallium name/vendor strings */
+ for(int i = 0; i < std::min((int)s.size(), 127); ++i)
+ desc.Description[i] = (WCHAR)s[i];
+
+ // TODO: add an interface to get these; for now, return mid/low values
+ desc.DedicatedVideoMemory = 256 << 20;
+ desc.DedicatedSystemMemory = 256 << 20;
+ desc.SharedSystemMemory = 1024 << 20;
+
+ // TODO: we should actually use an unique ID instead
+ *(void**)&desc.AdapterLuid = dpy;
+
+ configs = display->get_configs(display, (int*)&num_configs);
+ for(unsigned i = 0; i < num_configs; ++i)
+ {
+ if(configs[i]->window_bit)
+ {
+ configs_by_pipe_format.insert(std::make_pair(configs[i]->color_format, i));
+ configs_by_native_visual_id[configs[i]->native_visual_id] = i;
+ }
+ }
+
+ connectors = 0;
+ num_outputs = 0;
+
+ if(display->modeset)
+ {
+ int num_crtcs;
+
+ connectors = display->modeset->get_connectors(display, &num_outputs, &num_crtcs);
+ if(!connectors)
+ num_outputs = 0;
+ else if(!num_outputs)
+ {
+ free(connectors);
+ connectors = 0;
+ }
+ }
+ if(!num_outputs)
+ num_outputs = 1;
+ }
+
+ static void handle_invalid_surface(struct native_display *ndpy, struct native_surface *nsurf, unsigned int seq_num)
+ {
+ GalliumDXGISwapChainRevalidate((IDXGISwapChain*)nsurf->user_data);
+ }
+
+ ~GalliumDXGIAdapter()
+ {
+ free(configs);
+ free(connectors);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE EnumOutputs(
+ UINT Output,
+ __out IDXGIOutput **ppOutput)
+ {
+ if(Output >= (unsigned)num_outputs)
+ return DXGI_ERROR_NOT_FOUND;
+
+ if(connectors)
+ {
+ std::ostringstream ss;
+ ss << "Output #" << Output;
+ return GalliumDXGIOutputCreate(this, ss.str(), connectors[Output], ppOutput);
+ }
+ else
+ return GalliumDXGIOutputCreate(this, "Unique output", NULL, ppOutput);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDesc(
+ __out DXGI_ADAPTER_DESC *pDesc)
+ {
+ memcpy(pDesc, &desc, sizeof(*pDesc));
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDesc1(
+ __out DXGI_ADAPTER_DESC1 *pDesc)
+ {
+ memcpy(pDesc, &desc, sizeof(*pDesc));
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CheckInterfaceSupport(
+ __in REFGUID InterfaceName,
+ __out LARGE_INTEGER *pUMDVersion)
+ {
+ // these number was taken from Windows 7 with Catalyst 10.8: its meaning is unclear
+ if(InterfaceName == IID_ID3D11Device || InterfaceName == IID_ID3D10Device1 || InterfaceName == IID_ID3D10Device)
+ {
+ pUMDVersion->QuadPart = 0x00080011000a0411ULL;
+ return S_OK;
+ }
+ return DXGI_ERROR_UNSUPPORTED;
+ }
+
+ pipe_screen* STDMETHODCALLTYPE GetGalliumScreen()
+ {
+ return display->screen;
+ }
+
+ pipe_screen* STDMETHODCALLTYPE GetGalliumReferenceSoftwareScreen()
+ {
+ // TODO: give a softpipe screen
+ return display->screen;
+ }
+
+ pipe_screen* STDMETHODCALLTYPE GetGalliumFastSoftwareScreen()
+ {
+ // TODO: give an llvmpipe screen
+ return display->screen;
+ }
+};
+
+
+struct GalliumDXGIOutput : public GalliumDXGIObject<IDXGIOutput, GalliumDXGIAdapter>
+{
+ DXGI_OUTPUT_DESC desc;
+ const struct native_mode** modes;
+ DXGI_MODE_DESC* dxgi_modes;
+ unsigned num_modes;
+ const struct native_connector* connector;
+ DXGI_GAMMA_CONTROL* gamma;
+
+ GalliumDXGIOutput(GalliumDXGIAdapter* adapter, std::string name, const struct native_connector* connector = 0)
+ : GalliumDXGIObject(adapter), connector(connector)
+ {
+ memset(&desc, 0, sizeof(desc));
+ for(unsigned i = 0; i < std::min(name.size(), sizeof(desc.DeviceName) - 1); ++i)
+ desc.DeviceName[i] = name[i];
+ desc.AttachedToDesktop = TRUE;
+ /* TODO: should put an HMONITOR in desc.Monitor */
+
+ gamma = 0;
+ num_modes = 0;
+ modes = 0;
+ if(connector)
+ {
+ modes = parent->display->modeset->get_modes(parent->display, connector, (int*)&num_modes);
+ if(modes && num_modes)
+ {
+ dxgi_modes = new DXGI_MODE_DESC[num_modes];
+ for(unsigned i = 0; i < num_modes; ++i)
+ {
+ dxgi_modes[i].Width = modes[i]->width;
+ dxgi_modes[i].Height = modes[i]->height;
+ dxgi_modes[i].RefreshRate.Numerator = modes[i]->refresh_rate;
+ dxgi_modes[i].RefreshRate.Denominator = 1;
+ dxgi_modes[i].Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
+ dxgi_modes[i].ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
+ }
+ }
+ else
+ {
+ if(modes)
+ {
+ free(modes);
+ modes = 0;
+ }
+ goto use_fake_mode;
+ }
+ }
+ else
+ {
+use_fake_mode:
+ dxgi_modes = new DXGI_MODE_DESC[1];
+ dxgi_modes[0].Width = 1920;
+ dxgi_modes[0].Height = 1200;
+ dxgi_modes[0].RefreshRate.Numerator = 60;
+ dxgi_modes[0].RefreshRate.Denominator = 1;
+ dxgi_modes[0].Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
+ dxgi_modes[0].ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
+ }
+ }
+
+ ~GalliumDXGIOutput()
+ {
+ delete [] dxgi_modes;
+ free(modes);
+ if(gamma)
+ delete gamma;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDesc(
+ __out DXGI_OUTPUT_DESC *pDesc)
+ {
+ *pDesc = desc;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDisplayModeList(
+ DXGI_FORMAT EnumFormat,
+ UINT Flags,
+ __inout UINT *pNumModes,
+ __out_ecount_part_opt(*pNumModes,*pNumModes) DXGI_MODE_DESC *pDesc)
+ {
+ /* TODO: should we return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE when we don't
+ * support modesetting instead of fake modes?
+ */
+ pipe_format format = dxgi_to_pipe_format[EnumFormat];
+ if(parent->configs_by_pipe_format.count(format))
+ {
+ if(!pDesc)
+ {
+ *pNumModes = num_modes;
+ return S_OK;
+ }
+
+ unsigned copy_modes = std::min(num_modes, *pNumModes);
+ for(unsigned i = 0; i < copy_modes; ++i)
+ {
+ pDesc[i] = dxgi_modes[i];
+ pDesc[i].Format = EnumFormat;
+ }
+ *pNumModes = num_modes;
+
+ if(copy_modes < num_modes)
+ return DXGI_ERROR_MORE_DATA;
+ else
+ return S_OK;
+ }
+ else
+ {
+ *pNumModes = 0;
+ return S_OK;
+ }
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE FindClosestMatchingMode(
+ __in const DXGI_MODE_DESC *pModeToMatch,
+ __out DXGI_MODE_DESC *pClosestMatch,
+ __in_opt IUnknown *pConcernedDevice)
+ {
+ /* TODO: actually implement this */
+ DXGI_FORMAT dxgi_format = pModeToMatch->Format;
+ enum pipe_format format = dxgi_to_pipe_format[dxgi_format];
+ init_pipe_to_dxgi_format();
+ if(!parent->configs_by_pipe_format.count(format))
+ {
+ if(!pConcernedDevice)
+ return E_FAIL;
+ else
+ {
+ format = parent->configs[0]->color_format;
+ dxgi_format = pipe_to_dxgi_format[format];
+ }
+ }
+
+ *pClosestMatch = dxgi_modes[0];
+ pClosestMatch->Format = dxgi_format;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE WaitForVBlank( void)
+ {
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE TakeOwnership(
+ __in IUnknown *pDevice,
+ BOOL Exclusive)
+ {
+ return S_OK;
+ }
+
+ virtual void STDMETHODCALLTYPE ReleaseOwnership( void)
+ {
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetGammaControlCapabilities(
+ __out DXGI_GAMMA_CONTROL_CAPABILITIES *pGammaCaps)
+ {
+ memset(pGammaCaps, 0, sizeof(*pGammaCaps));
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetGammaControl(
+ __in const DXGI_GAMMA_CONTROL *pArray)
+ {
+ if(!gamma)
+ gamma = new DXGI_GAMMA_CONTROL;
+ *gamma = *pArray;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetGammaControl(
+ __out DXGI_GAMMA_CONTROL *pArray)
+ {
+ if(gamma)
+ *pArray = *gamma;
+ else
+ {
+ pArray->Scale.Red = 1;
+ pArray->Scale.Green = 1;
+ pArray->Scale.Blue = 1;
+ pArray->Offset.Red = 0;
+ pArray->Offset.Green = 0;
+ pArray->Offset.Blue = 0;
+ for(unsigned i = 0; i <= 1024; ++i)
+ pArray->GammaCurve[i].Red = pArray->GammaCurve[i].Green = pArray->GammaCurve[i].Blue = (float)i / 1024.0;
+ }
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE SetDisplaySurface(
+ __in IDXGISurface *pScanoutSurface)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDisplaySurfaceData(
+ __in IDXGISurface *pDestination)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetFrameStatistics(
+ __out DXGI_FRAME_STATISTICS *pStats)
+ {
+ memset(pStats, 0, sizeof(*pStats));
+#ifdef _WIN32
+ QueryPerformanceCounter(&pStats->SyncQPCTime);
+#endif
+ return E_NOTIMPL;
+ }
+};
+
+/* Swap chain are rather complex, and Microsoft's documentation is rather
+ * lacking. As far as I know, this is the most thorough publicly available
+ * description of how swap chains work, based on multiple sources and
+ * experimentation.
+ *
+ * There are two modes (called "swap effects") that a swap chain can operate in:
+ * discard and sequential.
+ *
+ * In discard mode, things always look as if there is a single buffer, which
+ * you can get with GetBuffers(0).
+ * The 2D texture returned by GetBuffers(0) and can only be
+ * used as a render target view and for resource copies, since no CPU access
+ * flags are set and only the D3D11_BIND_RENDER_TARGET bind flag is set.
+ * On Present, it is copied to the actual display
+ * surface and the contents become undefined.
+ * D3D may internally use multiple buffers, but you can't observe this, except
+ * by looking at the buffer contents after Present (but those are undefined).
+ * If it uses multiple buffers internally, then it will normally use BufferCount buffers
+ * (this has latency implications).
+ * Discard mode seems to internally use a single buffer in windowed mode,
+ * even if DWM is enabled, and BufferCount buffers in fullscreen mode.
+ *
+ * In sequential mode, the runtime alllocates BufferCount buffers.
+ * You can get each with GetBuffers(n).
+ * GetBuffers(0) ALWAYS points to the backbuffer to be presented and has the
+ * same usage constraints as the discard mode.
+ * GetBuffer(n) with n > 0 points to resources that are identical to buffer 0, but
+ * are classified as "read-only resources" (due to DXGI_USAGE_READ_ONLY),
+ * meaning that you can't create render target views on them, or use them as
+ * a CopyResource/CopySubresourceRegion destination.
+ * It appears the only valid operation is to use them as a source for CopyResource
+ * and CopySubresourceRegion as well as just waiting for them to become
+ * buffer 0 again.
+ * Buffer n - 1 is always displayed on screen.
+ * When you call Present(), the contents of the buffers are rotated, so that buffer 0
+ * goes to buffer n - 1, and is thus displayed, and buffer 1 goes to buffer 0, becomes
+ * the accessible back buffer.
+ * The resources themselves are NOT rotated, so that you can still render on the
+ * same ID3D11Texture2D*, and views based on it, that you got before Present().
+ *
+ * Present seems to happen by either copying the relevant buffer into the window,
+ * or alternatively making it the current one, either by programming the CRTC or
+ * by sending the resource name to the DWM compositor.
+ *
+ * Hence, you can call GetBuffer(0) once and keep using the same ID3D11Texture2D*
+ * and ID3D11RenderTargetView* (and other views if needed) you got from it.
+ *
+ * If the window gets resized, DXGI will then "emulate" all successive presentations,
+ * by using a stretched blit automatically.
+ * Thus, you should handle WM_SIZE and call ResizeBuffers to update the DXGI
+ * swapchain buffers size to the new window size.
+ * Doing so requires you to release all GetBuffers() results and anything referencing
+ * them, including views and Direct3D11 deferred context command lists (this is
+ * documented).
+ *
+ * How does Microsoft implement the rotation behavior?
+ * It turns out that it does it by calling RotateResourceIdentitiesDXGI in the user-mode
+ * DDI driver.
+ * This will rotate the kernel buffer handle, or possibly rotate the GPU virtual memory
+ * mappings.
+ *
+ * The reason this is done by driver instead of by the runtime appears to be that
+ * this is necessary to support driver-provided command list support, since otherwise
+ * the command list would not always target the current backbuffer, since it would
+ * be done at the driver level, while only the runtime knows about the rotation.
+ *
+ * OK, so how do we implement this in Gallium?
+ *
+ * There are three strategies:
+ * 1. Use a single buffer, and always copy it to a window system provided buffer, or
+ * just give the buffer to the window system if it supports that
+ * 2. Rotate the buffers in the D3D1x implementation, and recreate and rebind the views.
+ * Don't support driver-provided command lists
+ * 3. Add this rotation functionality to the Gallium driver, with the idea that it would rotate
+ * remap GPU virtual memory, so that virtual address are unchanged, but the physical
+ * ones are rotated (so that pushbuffers remain valid).
+ * If the driver does not support this, either fall back to (1), or have a layer doing this,
+ * putting a deferred context layer over this intermediate layer.
+ *
+ * (2) is not acceptable since it prevents an optimal implementation.
+ * (3) is the ideal solution, but it is complicated.
+ *
+ * Hence, we implement (1) for now, and will switch to (3) later.
+ *
+ * Note that (1) doesn't really work for DXGI_SWAP_EFFECT_SEQUENTIAL with more
+ * than one buffer, so we just pretend we got asked for a single buffer in that case
+ * Fortunately, no one seems to rely on that, so we'll just not implement it at first, and
+ * later perform the rotation with blits.
+ * Once we switch to (3), we'll just use real rotation to do it..
+ *
+ * DXGI_SWAP_EFFECT_SEQUENTIAL with more than one buffer is of dubious use
+ * anyway, since you can only render or write to buffer 0, and other buffers can apparently
+ * be used only as sources for copies.
+ * I was unable to find any code using it either in DirectX SDK examples, or on the web.
+ *
+ * It seems the only reason you would use it is to not have to redraw from scratch, while
+ * also possibly avoid a copy compared to BufferCount == 1, assuming that your
+ * application is OK with having to redraw starting not from the last frame, but from
+ * one/two/more frames behind it.
+ *
+ * A better design would forbid the user specifying BufferCount explicitly, and
+ * would instead let the application give an upper bound on how old the buffer can
+ * become after presentation, with "infinite" being equivalent to discard.
+ * The runtime would then tell the application with frame number the buffer switched to
+ * after present.
+ * In addition, in a better design, the application would be allowed to specify the
+ * number of buffers available, having all them usable for rendering, so that things
+ * like video players could efficiently decode frames in parallel.
+ * Present would in such a better design gain a way to specify the number of buffers
+ * to present.
+ *
+ * Other miscellaneous info:
+ * DXGI_PRESENT_DO_NOT_SEQUENCE causes DXGI to hold the frame for another
+ * vblank interval without rotating the resource data.
+ *
+ * References:
+ * "DXGI Overview" in MSDN
+ * IDXGISwapChain documentation on MSDN
+ * "RotateResourceIdentitiesDXGI" on MSDN
+ * http://forums.xna.com/forums/p/42362/266016.aspx
+ */
+
+static float quad_data[] = {
+ -1, -1, 0, 0,
+ -1, 1, 0, 1,
+ 1, 1, 1, 1,
+ 1, -1, 1, 0,
+};
+
+struct dxgi_blitter
+{
+ pipe_context* pipe;
+ bool normalized;
+ void* fs;
+ void* vs;
+ void* sampler[2];
+ void* elements;
+ void* blend;
+ void* rasterizer;
+ void* zsa;
+ struct pipe_clip_state clip;
+ struct pipe_vertex_buffer vbuf;
+ struct pipe_draw_info draw;
+
+ dxgi_blitter(pipe_context* pipe)
+ : pipe(pipe)
+ {
+ //normalized = !!pipe->screen->get_param(pipe, PIPE_CAP_NPOT_TEXTURES);
+ // TODO: need to update buffer in unnormalized case
+ normalized = true;
+
+ struct pipe_rasterizer_state rs_state;
+ memset(&rs_state, 0, sizeof(rs_state));
+ rs_state.cull_face = PIPE_FACE_NONE;
+ rs_state.gl_rasterization_rules = 1;
+ rs_state.flatshade = 1;
+ rasterizer = pipe->create_rasterizer_state(pipe, &rs_state);
+
+ struct pipe_blend_state blendd;
+ blendd.rt[0].colormask = PIPE_MASK_RGBA;
+ blend = pipe->create_blend_state(pipe, &blendd);
+
+ struct pipe_depth_stencil_alpha_state zsad;
+ memset(&zsad, 0, sizeof(zsad));
+ zsa = pipe->create_depth_stencil_alpha_state(pipe, &zsad);
+
+ struct pipe_vertex_element velem[2];
+ memset(&velem[0], 0, sizeof(velem[0]) * 2);
+ velem[0].src_offset = 0;
+ velem[0].src_format = PIPE_FORMAT_R32G32_FLOAT;
+ velem[1].src_offset = 8;
+ velem[1].src_format = PIPE_FORMAT_R32G32_FLOAT;
+ elements = pipe->create_vertex_elements_state(pipe, 2, &velem[0]);
+
+ for(unsigned stretch = 0; stretch < 2; ++stretch)
+ {
+ struct pipe_sampler_state sampler_state;
+ memset(&sampler_state, 0, sizeof(sampler_state));
+ sampler_state.min_img_filter = stretch ? PIPE_TEX_FILTER_LINEAR : PIPE_TEX_FILTER_NEAREST;
+ sampler_state.mag_img_filter = stretch ? PIPE_TEX_FILTER_LINEAR : PIPE_TEX_FILTER_NEAREST;
+ sampler_state.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ sampler_state.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ sampler_state.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ sampler_state.normalized_coords = normalized;
+
+ sampler[stretch] = pipe->create_sampler_state(pipe, &sampler_state);
+ }
+
+ fs = util_make_fragment_tex_shader(pipe, normalized ? TGSI_TEXTURE_2D : TGSI_TEXTURE_RECT, TGSI_INTERPOLATE_LINEAR);
+
+ const unsigned semantic_names[] = { TGSI_SEMANTIC_POSITION, TGSI_SEMANTIC_GENERIC };
+ const unsigned semantic_indices[] = { 0, 0 };
+ vs = util_make_vertex_passthrough_shader(pipe, 2, semantic_names, semantic_indices);
+
+ vbuf.buffer = pipe_buffer_create(pipe->screen, PIPE_BIND_VERTEX_BUFFER, sizeof(quad_data));
+ vbuf.buffer_offset = 0;
+ vbuf.max_index = ~0;
+ vbuf.stride = 4 * sizeof(float);
+ pipe_buffer_write(pipe, vbuf.buffer, 0, sizeof(quad_data), quad_data);
+
+ memset(&clip, 0, sizeof(clip));
+
+ memset(&draw, 0, sizeof(draw));
+ draw.mode = PIPE_PRIM_QUADS;
+ draw.count = 4;
+ draw.instance_count = 1;
+ draw.max_index = ~0;
+ }
+
+ void blit(struct pipe_surface* surf, struct pipe_sampler_view* view, unsigned x, unsigned y, unsigned w, unsigned h)
+ {
+ struct pipe_framebuffer_state fb;
+ memset(&fb, 0, sizeof(fb));
+ fb.nr_cbufs = 1;
+ fb.cbufs[0] = surf;
+ fb.width = surf->width;
+ fb.height = surf->height;
+
+ struct pipe_viewport_state viewport;
+ float half_width = w * 0.5f;
+ float half_height = h * 0.5f;
+ viewport.scale[0] = half_width;
+ viewport.scale[1] = half_height;
+ viewport.scale[2] = 1.0f;
+ viewport.scale[3] = 1.0f;
+ viewport.translate[0] = x + half_width;
+ viewport.translate[1] = y + half_height;
+ viewport.translate[2] = 0.0f;
+ viewport.translate[3] = 1.0f;
+
+ bool stretch = view->texture->width0 != w || view->texture->height0 != h;
+ if(pipe->render_condition)
+ pipe->render_condition(pipe, 0, 0);
+ pipe->set_framebuffer_state(pipe, &fb);
+ pipe->bind_fragment_sampler_states(pipe, 1, &sampler[stretch]);
+ pipe->set_viewport_state(pipe, &viewport);
+ pipe->set_clip_state(pipe, &clip);
+ pipe->bind_rasterizer_state(pipe, rasterizer);
+ pipe->bind_depth_stencil_alpha_state(pipe, zsa);
+ pipe->bind_blend_state(pipe, blend);
+ pipe->bind_vertex_elements_state(pipe, elements);
+ pipe->set_vertex_buffers(pipe, 1, &vbuf);
+ pipe->bind_fs_state(pipe, fs);
+ pipe->bind_vs_state(pipe, vs);
+ if(pipe->bind_gs_state)
+ pipe->bind_gs_state(pipe, 0);
+ if(pipe->bind_stream_output_state)
+ pipe->bind_stream_output_state(pipe, 0);
+ pipe->set_fragment_sampler_views(pipe, 1, &view);
+
+ pipe->draw_vbo(pipe, &draw);
+ }
+
+ ~dxgi_blitter()
+ {
+ pipe->delete_blend_state(pipe, blend);
+ pipe->delete_rasterizer_state(pipe, rasterizer);
+ pipe->delete_depth_stencil_alpha_state(pipe, zsa);
+ pipe->delete_sampler_state(pipe, sampler[0]);
+ pipe->delete_sampler_state(pipe, sampler[1]);
+ pipe->delete_vertex_elements_state(pipe, elements);
+ pipe->delete_vs_state(pipe, vs);
+ pipe->delete_fs_state(pipe, fs);
+ pipe->screen->resource_destroy(pipe->screen, vbuf.buffer);
+ }
+};
+
+struct GalliumDXGISwapChain : public GalliumDXGIObject<IDXGISwapChain, GalliumDXGIFactory>
+{
+ ComPtr<IDXGIDevice>dxgi_device;
+ ComPtr<IGalliumDevice>gallium_device;
+ ComPtr<GalliumDXGIAdapter> adapter;
+ ComPtr<IDXGIOutput> target;
+
+ struct native_surface* surface;
+ const struct native_config* config;
+
+ struct pipe_resource* resources[NUM_NATIVE_ATTACHMENTS];
+ int width;
+ int height;
+ unsigned seq_num;
+ bool ever_validated;
+ bool needs_validation;
+ unsigned present_count;
+
+ ComPtr<IDXGISurface> buffer0;
+ struct pipe_resource* gallium_buffer0;
+ struct pipe_sampler_view* gallium_buffer0_view;
+
+ DXGI_SWAP_CHAIN_DESC desc;
+
+ struct pipe_context* pipe;
+ bool owns_pipe;
+
+ BOOL fullscreen;
+
+ std::auto_ptr<dxgi_blitter> blitter;
+ bool formats_compatible;
+
+ GalliumDXGISwapChain(GalliumDXGIFactory* factory, IUnknown* p_device, const DXGI_SWAP_CHAIN_DESC& p_desc)
+ : GalliumDXGIObject(factory), desc(p_desc)
+ {
+ HRESULT hr;
+
+ hr = p_device->QueryInterface(IID_IGalliumDevice, (void**)&gallium_device);
+ if(!SUCCEEDED(hr))
+ throw hr;
+
+ hr = p_device->QueryInterface(IID_IDXGIDevice, (void**)&dxgi_device);
+ if(!SUCCEEDED(hr))
+ throw hr;
+
+ hr = dxgi_device->GetAdapter((IDXGIAdapter**)&adapter);
+ if(!SUCCEEDED(hr))
+ throw hr;
+
+ void* win = factory->resolver(factory->resolver_cookie, desc.OutputWindow);
+
+ unsigned config_num;
+ if(!strcmp(factory->platform->name, "X11"))
+ {
+ XWindowAttributes xwa;
+ XGetWindowAttributes((Display*)factory->display, (Window)win, &xwa);
+ config_num = adapter->configs_by_native_visual_id[xwa.visual->visualid];
+ }
+ else
+ {
+ enum pipe_format format = dxgi_to_pipe_format[desc.BufferDesc.Format];
+ if(!adapter->configs_by_pipe_format.count(format))
+ {
+ if(adapter->configs_by_pipe_format.empty())
+ throw E_FAIL;
+ // TODO: choose the best match
+ format = (pipe_format)adapter->configs_by_pipe_format.begin()->first;
+ }
+ // TODO: choose the best config
+ config_num = adapter->configs_by_pipe_format.find(format)->second;
+ }
+
+ config = adapter->configs[config_num];
+ surface = adapter->display->create_window_surface(adapter->display, (EGLNativeWindowType)win, config);
+ surface->user_data = this;
+
+ width = 0;
+ height = 0;
+ seq_num = 0;
+ present_count = 0;
+ needs_validation = true;
+ ever_validated = false;
+
+ if(desc.SwapEffect == DXGI_SWAP_EFFECT_SEQUENTIAL && desc.BufferCount != 1)
+ {
+ std::cerr << "Gallium DXGI: if DXGI_SWAP_EFFECT_SEQUENTIAL is specified, only BufferCount == 1 is implemented, but " << desc.BufferCount << " was specified: ignoring this" << std::endl;
+ // change the returned desc, so that the application might perhaps notice what we did and react well
+ desc.BufferCount = 1;
+ }
+
+ pipe = gallium_device->GetGalliumContext();
+ owns_pipe = false;
+ if(!pipe)
+ {
+ pipe = adapter->display->screen->context_create(adapter->display->screen, 0);
+ owns_pipe = true;
+ }
+
+ blitter.reset(new dxgi_blitter(pipe));
+
+ formats_compatible = util_is_format_compatible(
+ util_format_description(dxgi_to_pipe_format[desc.BufferDesc.Format]),
+ util_format_description(config->color_format));
+ }
+
+ ~GalliumDXGISwapChain()
+ {
+ if(owns_pipe)
+ pipe->destroy(pipe);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDevice(
+ __in REFIID riid,
+ __out void **ppDevice)
+ {
+ return dxgi_device->QueryInterface(riid, ppDevice);
+ }
+
+ HRESULT create_buffer0()
+ {
+ HRESULT hr;
+ ComPtr<IDXGISurface> new_buffer0;
+ DXGI_USAGE usage = DXGI_USAGE_BACK_BUFFER | DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ if(desc.SwapEffect == DXGI_SWAP_EFFECT_DISCARD)
+ usage |= DXGI_USAGE_DISCARD_ON_PRESENT;
+ // for our blitter
+ usage |= DXGI_USAGE_SHADER_INPUT;
+
+ DXGI_SURFACE_DESC surface_desc;
+ surface_desc.Format = desc.BufferDesc.Format;
+ surface_desc.Width = desc.BufferDesc.Width;
+ surface_desc.Height = desc.BufferDesc.Height;
+ surface_desc.SampleDesc = desc.SampleDesc;
+ hr = dxgi_device->CreateSurface(&surface_desc, 1, usage, 0, &new_buffer0);
+ if(!SUCCEEDED(hr))
+ return hr;
+
+ ComPtr<IGalliumResource> gallium_resource;
+ hr = new_buffer0->QueryInterface(IID_IGalliumResource, (void**)&gallium_resource);
+ if(!SUCCEEDED(hr))
+ return hr;
+
+ struct pipe_resource* new_gallium_buffer0 = gallium_resource->GetGalliumResource();
+ if(!new_gallium_buffer0)
+ return E_FAIL;
+
+ buffer0.reset(new_buffer0.steal());
+ gallium_buffer0 = new_gallium_buffer0;
+ struct pipe_sampler_view templat;
+ memset(&templat, 0, sizeof(templat));
+ templat.texture = gallium_buffer0;
+ templat.swizzle_r = 0;
+ templat.swizzle_g = 1;
+ templat.swizzle_b = 2;
+ templat.swizzle_a = 3;
+ templat.format = gallium_buffer0->format;
+ gallium_buffer0_view = pipe->create_sampler_view(pipe, gallium_buffer0, &templat);
+ return S_OK;
+ }
+
+ bool validate()
+ {
+ unsigned new_seq_num;
+ needs_validation = false;
+
+ if(!surface->validate(surface, 1 << NATIVE_ATTACHMENT_BACK_LEFT, &new_seq_num, resources, &width, &height))
+ return false;
+
+ if(!ever_validated || seq_num != new_seq_num)
+ {
+ seq_num = new_seq_num;
+ ever_validated = true;
+ }
+ return true;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Present(
+ UINT SyncInterval,
+ UINT Flags)
+ {
+ if(Flags & DXGI_PRESENT_TEST)
+ return S_OK;
+
+ if(!buffer0)
+ {
+ HRESULT hr = create_buffer0();
+ if(!SUCCEEDED(hr))
+ return hr;
+ }
+
+ if(needs_validation)
+ {
+ if(!validate())
+ return DXGI_ERROR_DEVICE_REMOVED;
+ }
+
+ bool db = !!(config->buffer_mask & NATIVE_ATTACHMENT_BACK_LEFT);
+ struct pipe_resource* dst = resources[db ? NATIVE_ATTACHMENT_BACK_LEFT : NATIVE_ATTACHMENT_FRONT_LEFT];
+ struct pipe_resource* src = gallium_buffer0;
+ struct pipe_surface* dst_surface = 0;
+
+ /* TODO: sharing the context for blitting won't work correctly if queries are active
+ * Hopefully no one is crazy enough to keep queries active while presenting, expecting
+ * sensible results.
+ * We could alternatively force using another context, but that might cause inefficiency issues
+ */
+
+ /* Windows DXGI does not scale in an aspect-preserving way, but we do this
+ * by default, since we can and it's usually what you want
+ */
+ unsigned blit_x, blit_y, blit_w, blit_h;
+ float black[4] = {0, 0, 0, 0};
+
+ if(!formats_compatible || src->width0 != dst->width0 || dst->width0 != src->width0)
+ dst_surface = pipe->screen->get_tex_surface(pipe->screen, dst, 0, 0, 0, PIPE_BIND_RENDER_TARGET);
+
+ int delta = src->width0 * dst->height0 - dst->width0 * src->height0;
+ if(delta > 0)
+ {
+ blit_w = dst->width0;
+ blit_h = dst->width0 * src->height0 / src->width0;
+ }
+ else if(delta < 0)
+ {
+ blit_w = dst->height0 * src->width0 / src->height0;
+ blit_h = dst->height0;
+ }
+ else
+ {
+ blit_w = dst->width0;
+ blit_h = dst->height0;
+ }
+
+ blit_x = (dst->width0 - blit_w) >> 1;
+ blit_y = (dst->height0 - blit_h) >> 1;
+
+ if(blit_x)
+ pipe->clear_render_target(pipe, dst_surface, black, 0, 0, blit_x, dst->height0);
+ if(blit_y)
+ pipe->clear_render_target(pipe, dst_surface, black, 0, 0, dst->width0, blit_y);
+
+ if(formats_compatible && blit_w == src->width0 && blit_h == src->height0)
+ {
+ pipe_subresource sr;
+ sr.face = 0;
+ sr.level = 0;
+ pipe->resource_copy_region(pipe, dst, sr, 0, 0, 0, src, sr, 0, 0, 0, blit_w, blit_h);
+ }
+ else
+ {
+ blitter->blit(dst_surface, gallium_buffer0_view, blit_x, blit_y, blit_w, blit_h);
+ if(!owns_pipe)
+ gallium_device->RestoreGalliumState();
+ }
+
+ if(blit_w != dst->width0)
+ pipe->clear_render_target(pipe, dst_surface, black, blit_x + blit_w, 0, dst->width0 - blit_x - blit_w, dst->height0);
+ if(blit_h != dst->height0)
+ pipe->clear_render_target(pipe, dst_surface, black, 0, blit_y + blit_h, dst->width0, dst->height0 - blit_y - blit_h);
+
+ if(dst_surface)
+ pipe->screen->tex_surface_destroy(dst_surface);
+
+ if(db)
+ {
+ if(!surface->swap_buffers(surface))
+ return DXGI_ERROR_DEVICE_REMOVED;
+ }
+ else
+ {
+ if(!surface->flush_frontbuffer(surface))
+ return DXGI_ERROR_DEVICE_REMOVED;
+ }
+
+ ++present_count;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetBuffer(
+ UINT Buffer,
+ __in REFIID riid,
+ __out void **ppSurface)
+ {
+ if(Buffer > 0)
+ {
+ if(desc.SwapEffect == DXGI_SWAP_EFFECT_SEQUENTIAL)
+ std::cerr << "DXGI unimplemented: GetBuffer(n) with n > 0 not supported, returning buffer 0 instead!" << std::endl;
+ else
+ std::cerr << "DXGI error: in GetBuffer(n), n must be 0 for DXGI_SWAP_EFFECT_DISCARD\n" << std::endl;
+ }
+
+ if(!buffer0)
+ {
+ HRESULT hr = create_buffer0();
+ if(!SUCCEEDED(hr))
+ return hr;
+ }
+ return buffer0->QueryInterface(riid, ppSurface);
+ }
+
+ /* TODO: implement somehow */
+ virtual HRESULT STDMETHODCALLTYPE SetFullscreenState(
+ BOOL Fullscreen,
+ __in_opt IDXGIOutput *pTarget)
+ {
+ fullscreen = Fullscreen;
+ target = pTarget;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetFullscreenState(
+ __out BOOL *pFullscreen,
+ __out IDXGIOutput **ppTarget)
+ {
+ if(pFullscreen)
+ *pFullscreen = fullscreen;
+ if(ppTarget)
+ *ppTarget = target.ref();
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDesc(
+ __out DXGI_SWAP_CHAIN_DESC *pDesc)
+ {
+ *pDesc = desc;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE ResizeBuffers(
+ UINT BufferCount,
+ UINT Width,
+ UINT Height,
+ DXGI_FORMAT NewFormat,
+ UINT SwapChainFlags)
+ {
+ if(buffer0)
+ {
+ buffer0.p->AddRef();
+ ULONG v = buffer0.p->Release();
+ // we must fail if there are any references to buffer0 other than ours
+ if(v > 1)
+ return E_FAIL;
+ pipe_sampler_view_reference(&gallium_buffer0_view, 0);
+ buffer0 = (IUnknown*)NULL;
+ gallium_buffer0 = 0;
+ }
+
+ if(desc.SwapEffect != DXGI_SWAP_EFFECT_SEQUENTIAL)
+ desc.BufferCount = BufferCount;
+ desc.BufferDesc.Format = NewFormat;
+ desc.BufferDesc.Width = Width;
+ desc.BufferDesc.Height = Height;
+ desc.Flags = SwapChainFlags;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE ResizeTarget(
+ const DXGI_MODE_DESC *pNewTargetParameters)
+ {
+ /* TODO: implement */
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetContainingOutput(
+ __out IDXGIOutput **ppOutput)
+ {
+ *ppOutput = adapter->outputs[0].ref();
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetFrameStatistics(
+ __out DXGI_FRAME_STATISTICS *pStats)
+ {
+ memset(pStats, 0, sizeof(*pStats));
+#ifdef _WIN32
+ QueryPerformanceCounter(&pStats->SyncQPCTime);
+#endif
+ pStats->PresentCount = present_count;
+ pStats->PresentRefreshCount = present_count;
+ pStats->SyncRefreshCount = present_count;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetLastPresentCount(
+ __out UINT *pLastPresentCount)
+ {
+ *pLastPresentCount = present_count;
+ return S_OK;
+ }
+};
+
+static void GalliumDXGISwapChainRevalidate(IDXGISwapChain* swap_chain)
+{
+ ((GalliumDXGISwapChain*)swap_chain)->needs_validation = true;
+}
+
+static HRESULT GalliumDXGIAdapterCreate(GalliumDXGIFactory* factory, const struct native_platform* platform, void* dpy, IDXGIAdapter1** pAdapter)
+{
+ try
+ {
+ *pAdapter = new GalliumDXGIAdapter(factory, platform, dpy);
+ return S_OK;
+ }
+ catch(HRESULT hr)
+ {
+ return hr;
+ }
+}
+
+static HRESULT GalliumDXGIOutputCreate(GalliumDXGIAdapter* adapter, const std::string& name, const struct native_connector* connector, IDXGIOutput** pOutput)
+{
+ try
+ {
+ *pOutput = new GalliumDXGIOutput(adapter, name, connector);
+ return S_OK;
+ }
+ catch(HRESULT hr)
+ {
+ return hr;
+ }
+}
+
+static HRESULT GalliumDXGISwapChainCreate(GalliumDXGIFactory* factory, IUnknown* device, const DXGI_SWAP_CHAIN_DESC& desc, IDXGISwapChain** pSwapChain)
+{
+ try
+ {
+ *pSwapChain = new GalliumDXGISwapChain(factory, device, desc);
+ return S_OK;
+ }
+ catch(HRESULT hr)
+ {
+ return hr;
+ }
+}
+
+struct dxgi_binding
+{
+ const struct native_platform* platform;
+ void* display;
+ PFNHWNDRESOLVER resolver;
+ void* resolver_cookie;
+};
+
+static dxgi_binding dxgi_default_binding;
+static __thread dxgi_binding dxgi_thread_binding;
+
+void STDMETHODCALLTYPE GalliumDXGIUseNothing()
+{
+ dxgi_thread_binding.platform = 0;
+ dxgi_thread_binding.display = 0;
+ dxgi_thread_binding.resolver = 0;
+ dxgi_thread_binding.resolver_cookie = 0;
+}
+
+#ifdef GALLIUM_DXGI_USE_X11
+void STDMETHODCALLTYPE GalliumDXGIUseX11Display(Display* dpy, PFNHWNDRESOLVER resolver, void* resolver_cookie)
+{
+ dxgi_thread_binding.platform = native_get_x11_platform();
+ dxgi_thread_binding.display = dpy;
+ dxgi_thread_binding.resolver = resolver;
+ dxgi_thread_binding.resolver_cookie = resolver_cookie;
+}
+#endif
+
+#ifdef GALLIUM_DXGI_USE_DRM
+void STDMETHODCALLTYPE GalliumDXGIUseDRMCard(int fd)
+{
+ dxgi_thread_binding.platform = native_get_drm_platform();
+ dxgi_thread_binding.display = (void*)fd;
+ dxgi_thread_binding.resolver = 0;
+ dxgi_thread_binding.resolver_cookie = 0;
+}
+#endif
+
+#ifdef GALLIUM_DXGI_USE_FBDEV
+void STDMETHODCALLTYPE GalliumDXGIUseFBDev(int fd)
+{
+ dxgi_thread_binding.platform = native_get_fbdev_platform();
+ dxgi_thread_binding.display = (void*)fd;
+ dxgi_thread_binding.resolver = 0;
+ dxgi_thread_binding.resolver_cookie = 0;
+}
+#endif
+
+#ifdef GALLIUM_DXGI_USE_GDI
+void STDMETHODCALLTYPE GalliumDXGIUseHDC(HDC hdc, PFNHWNDRESOLVER resolver, void* resolver_cookie)
+{
+ dxgi_thread_binding.platform = native_get_gdi_platform();
+ dxgi_thread_binding.display = (void*)hdc;
+ dxgi_thread_binding.resolver = resolver;
+ dxgi_thread_binding.resolver_cookie = resolver_cookie;
+}
+#endif
+
+void STDMETHODCALLTYPE GalliumDXGIMakeDefault()
+{
+ dxgi_default_binding = dxgi_thread_binding;
+}
+
+ /* TODO: why did Microsoft add this? should we do something different for DXGI 1.0 and 1.1?
+ * Or perhaps what they actually mean is "only create a single factory in your application"?
+ * TODO: should we use a singleton here, so we never have multiple DXGI objects for the same thing? */
+ HRESULT STDMETHODCALLTYPE CreateDXGIFactory1(
+ __in REFIID riid,
+ __out void **ppFactory
+)
+ {
+ GalliumDXGIFactory* factory;
+ *ppFactory = 0;
+ if(dxgi_thread_binding.platform)
+ factory = new GalliumDXGIFactory(dxgi_thread_binding.platform, dxgi_thread_binding.display, dxgi_thread_binding.resolver, dxgi_thread_binding.resolver_cookie);
+ else if(dxgi_default_binding.platform)
+ factory = new GalliumDXGIFactory(dxgi_default_binding.platform, dxgi_default_binding.display, dxgi_default_binding.resolver, dxgi_default_binding.resolver_cookie);
+ else
+ factory = new GalliumDXGIFactory(native_get_x11_platform(), NULL, NULL, NULL);
+ HRESULT hres = factory->QueryInterface(riid, ppFactory);
+ factory->Release();
+ return hres;
+ }
+
+ HRESULT STDMETHODCALLTYPE CreateDXGIFactory(
+ __in REFIID riid,
+ __out void **ppFactory
+)
+ {
+ return CreateDXGIFactory1(riid, ppFactory);
+ }
diff --git a/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_private.h b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_private.h
new file mode 100644
index 0000000..30a6932
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_private.h
@@ -0,0 +1,50 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef DXGI_PRIVATE_H_
+#define DXGI_PRIVATE_H_
+
+#include <vector>
+#include <string>
+#include <sstream>
+
+#include "d3d1xstutil.h"
+
+#include <dxgi.h>
+#include <d3d11.h>
+#include <galliumcom.h>
+#include <galliumdxgi.h>
+#include <specstrings.h>
+
+struct native_display;
+
+struct pipe_screen *
+dxgi_loader_create_drm_screen(struct native_display* dpy, const char *name, int fd);
+
+struct pipe_screen *
+dxgi_loader_create_sw_screen(struct native_display* dpy, struct sw_winsys *ws);
+
+#endif /* DXGI_PRIVATE_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/dxgid3d10/Makefile b/src/gallium/state_trackers/d3d1x/dxgid3d10/Makefile
new file mode 100644
index 0000000..85f41e8
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgid3d10/Makefile
@@ -0,0 +1,4 @@
+LIBNAME=dxgid3d10
+CPP_SOURCES=$(wildcard *.cpp)
+LIBRARY_INCLUDES=-I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../include -I../../../include -I../../../auxiliary
+include ../Makefile.inc
diff --git a/src/gallium/state_trackers/d3d1x/dxgid3d10/dxgid3d10.cpp b/src/gallium/state_trackers/d3d1x/dxgid3d10/dxgid3d10.cpp
new file mode 100644
index 0000000..dd00226
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgid3d10/dxgid3d10.cpp
@@ -0,0 +1,149 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "d3d1xstutil.h"
+#include "galliumd3d10_1.h"
+#include <dxgi.h>
+#include <pipe/p_screen.h>
+#include <pipe/p_context.h>
+
+HRESULT D3D10CreateDevice1(
+ __in_opt IDXGIAdapter *pAdapter,
+ __in D3D10_DRIVER_TYPE DriverType,
+ __in HMODULE Software,
+ __in unsigned Flags,
+ __in D3D10_FEATURE_LEVEL1 HardwareLevel,
+ __in unsigned SDKVersion,
+ __out_opt ID3D10Device1 **ppDevice
+)
+{
+ HRESULT hr;
+ ComPtr<IDXGIAdapter1> adapter_to_release;
+ if(!pAdapter)
+ {
+ ComPtr<IDXGIFactory1> factory;
+ hr = CreateDXGIFactory1(IID_IDXGIFactory1, (void**)&factory);
+ if(!SUCCEEDED(hr))
+ return hr;
+ hr = factory->EnumAdapters1(0, &adapter_to_release);
+ if(!SUCCEEDED(hr))
+ return hr;
+ pAdapter = adapter_to_release.p;
+ }
+ ComPtr<IGalliumAdapter> gallium_adapter;
+ hr = pAdapter->QueryInterface(IID_IGalliumAdapter, (void**)&gallium_adapter);
+ if(!SUCCEEDED(hr))
+ return hr;
+ struct pipe_screen* screen;
+ // TODO: what should D3D_DRIVER_TYPE_SOFTWARE return? fast or reference?
+ if(DriverType == D3D10_DRIVER_TYPE_REFERENCE)
+ screen = gallium_adapter->GetGalliumReferenceSoftwareScreen();
+ else if(DriverType == D3D10_DRIVER_TYPE_SOFTWARE || DriverType == D3D10_DRIVER_TYPE_WARP)
+ screen = gallium_adapter->GetGalliumFastSoftwareScreen();
+ else
+ screen = gallium_adapter->GetGalliumScreen();
+ if(!screen)
+ return E_FAIL;
+ struct pipe_context* context = screen->context_create(screen, 0);
+ if(!context)
+ return E_FAIL;
+ ComPtr<ID3D10Device1> device;
+ hr = GalliumD3D10DeviceCreate1(screen, context, TRUE, Flags, pAdapter, &device);
+ if(!SUCCEEDED(hr))
+ {
+ context->destroy(context);
+ return hr;
+ }
+ if(ppDevice)
+ *ppDevice = device.steal();
+ return S_OK;
+}
+
+HRESULT WINAPI D3D10CreateDeviceAndSwapChain1(
+ __in_opt IDXGIAdapter* pAdapter,
+ D3D10_DRIVER_TYPE DriverType,
+ HMODULE Software,
+ unsigned Flags,
+ __in D3D10_FEATURE_LEVEL1 HardwareLevel,
+ unsigned SDKVersion,
+ __in_opt DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
+ __out_opt IDXGISwapChain** ppSwapChain,
+ __out_opt ID3D10Device1** ppDevice
+)
+{
+ ComPtr<ID3D10Device1> dev;
+ HRESULT hr;
+ hr = D3D10CreateDevice1(pAdapter, DriverType, Software, Flags, HardwareLevel, SDKVersion, &dev);
+ if(!SUCCEEDED(hr))
+ return hr;
+ if(ppSwapChain)
+ {
+ ComPtr<IDXGIFactory> factory;
+ ComPtr<IDXGIDevice> dxgi_device;
+ ComPtr<IDXGIAdapter> adapter;
+ hr = dev->QueryInterface(IID_IDXGIDevice, (void**)&dxgi_device);
+ if(!SUCCEEDED(hr))
+ return hr;
+
+ hr = dxgi_device->GetAdapter(&adapter);
+ if(!SUCCEEDED(hr))
+ return hr;
+
+ adapter->GetParent(IID_IDXGIFactory, (void**)&factory);
+ hr = factory->CreateSwapChain(dev.p, (DXGI_SWAP_CHAIN_DESC*)pSwapChainDesc, ppSwapChain);
+ if(!SUCCEEDED(hr))
+ return hr;
+ }
+ if(ppDevice)
+ *ppDevice = dev.steal();
+ return hr;
+}
+
+HRESULT D3D10CreateDevice(
+ __in_opt IDXGIAdapter *pAdapter,
+ __in D3D10_DRIVER_TYPE DriverType,
+ __in HMODULE Software,
+ __in unsigned Flags,
+ __in unsigned SDKVersion,
+ __out_opt ID3D10Device **ppDevice
+)
+{
+ return D3D10CreateDevice1(pAdapter, DriverType, Software, Flags, D3D10_FEATURE_LEVEL_10_0, SDKVersion, (ID3D10Device1**)ppDevice);
+}
+
+HRESULT WINAPI D3D10CreateDeviceAndSwapChain(
+ __in_opt IDXGIAdapter* pAdapter,
+ D3D10_DRIVER_TYPE DriverType,
+ HMODULE Software,
+ unsigned Flags,
+ unsigned SDKVersion,
+ __in_opt DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
+ __out_opt IDXGISwapChain** ppSwapChain,
+ __out_opt ID3D10Device** ppDevice
+)
+{
+ return D3D10CreateDeviceAndSwapChain1(pAdapter, DriverType, Software, Flags, D3D10_FEATURE_LEVEL_10_0, SDKVersion, pSwapChainDesc, ppSwapChain, (ID3D10Device1**)ppDevice);
+}
diff --git a/src/gallium/state_trackers/d3d1x/dxgid3d11/Makefile b/src/gallium/state_trackers/d3d1x/dxgid3d11/Makefile
new file mode 100644
index 0000000..591d1be
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgid3d11/Makefile
@@ -0,0 +1,4 @@
+LIBNAME=dxgid3d11
+CPP_SOURCES=$(wildcard *.cpp)
+LIBRARY_INCLUDES=-I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../include -I../../../include -I../../../auxiliary
+include ../Makefile.inc
diff --git a/src/gallium/state_trackers/d3d1x/dxgid3d11/dxgid3d11.cpp b/src/gallium/state_trackers/d3d1x/dxgid3d11/dxgid3d11.cpp
new file mode 100644
index 0000000..86bb24b
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/dxgid3d11/dxgid3d11.cpp
@@ -0,0 +1,135 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "d3d1xstutil.h"
+#include "galliumd3d11.h"
+#include <dxgi.h>
+#include <pipe/p_screen.h>
+#include <pipe/p_context.h>
+
+HRESULT D3D11CreateDevice(
+ __in_opt IDXGIAdapter *pAdapter,
+ __in D3D_DRIVER_TYPE DriverType,
+ __in HMODULE Software,
+ __in unsigned Flags,
+ __in_ecount_opt( FeatureLevels ) const D3D_FEATURE_LEVEL *pFeatureLevels,
+ __in unsigned FeatureLevels,
+ __in unsigned SDKVersion,
+ __out_opt ID3D11Device **ppDevice,
+ __out_opt D3D_FEATURE_LEVEL *pFeatureLevel,
+ __out_opt ID3D11DeviceContext **ppImmediateContext
+)
+{
+ HRESULT hr;
+ ComPtr<IDXGIAdapter1> adapter_to_release;
+ if(!pAdapter)
+ {
+ ComPtr<IDXGIFactory1> factory;
+ hr = CreateDXGIFactory1(IID_IDXGIFactory1, (void**)&factory);
+ if(!SUCCEEDED(hr))
+ return hr;
+ hr = factory->EnumAdapters1(0, &adapter_to_release);
+ if(!SUCCEEDED(hr))
+ return hr;
+ pAdapter = adapter_to_release.p;
+ }
+ ComPtr<IGalliumAdapter> gallium_adapter;
+ hr = pAdapter->QueryInterface(IID_IGalliumAdapter, (void**)&gallium_adapter);
+ if(!SUCCEEDED(hr))
+ return hr;
+ struct pipe_screen* screen;
+ // TODO: what should D3D_DRIVER_TYPE_SOFTWARE return? fast or reference?
+ if(DriverType == D3D_DRIVER_TYPE_REFERENCE)
+ screen = gallium_adapter->GetGalliumReferenceSoftwareScreen();
+ else if(DriverType == D3D_DRIVER_TYPE_SOFTWARE || DriverType == D3D_DRIVER_TYPE_WARP)
+ screen = gallium_adapter->GetGalliumFastSoftwareScreen();
+ else
+ screen = gallium_adapter->GetGalliumScreen();
+ if(!screen)
+ return E_FAIL;
+ struct pipe_context* context = screen->context_create(screen, 0);
+ if(!context)
+ return E_FAIL;
+ ComPtr<ID3D11Device> device;
+ hr = GalliumD3D11DeviceCreate(screen, context, TRUE, Flags, pAdapter, &device);
+ if(!SUCCEEDED(hr))
+ {
+ context->destroy(context);
+ return hr;
+ }
+ if(ppImmediateContext)
+ device->GetImmediateContext(ppImmediateContext);
+ if(pFeatureLevel)
+ *pFeatureLevel = device->GetFeatureLevel();
+ if(ppDevice)
+ *ppDevice = device.steal();
+ return S_OK;
+}
+
+HRESULT WINAPI D3D11CreateDeviceAndSwapChain(
+ __in_opt IDXGIAdapter* pAdapter,
+ D3D_DRIVER_TYPE DriverType,
+ HMODULE Software,
+ unsigned Flags,
+ __in_ecount_opt( FeatureLevels ) CONST D3D_FEATURE_LEVEL* pFeatureLevels,
+ unsigned FeatureLevels,
+ unsigned SDKVersion,
+ __in_opt CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc,
+ __out_opt IDXGISwapChain** ppSwapChain,
+ __out_opt ID3D11Device** ppDevice,
+ __out_opt D3D_FEATURE_LEVEL* pFeatureLevel,
+ __out_opt ID3D11DeviceContext** ppImmediateContext )
+{
+ ComPtr<ID3D11Device> dev;
+ ComPtr<ID3D11DeviceContext> ctx;
+ HRESULT hr;
+ hr = D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, (ID3D11Device**)&dev, pFeatureLevel, (ID3D11DeviceContext**)&ctx);
+ if(!SUCCEEDED(hr))
+ return hr;
+ if(ppSwapChain)
+ {
+ ComPtr<IDXGIFactory> factory;
+ ComPtr<IDXGIDevice> dxgi_device;
+ ComPtr<IDXGIAdapter> adapter;
+ hr = dev->QueryInterface(IID_IDXGIDevice, (void**)&dxgi_device);
+ if(!SUCCEEDED(hr))
+ return hr;
+
+ hr = dxgi_device->GetAdapter(&adapter);
+ if(!SUCCEEDED(hr))
+ return hr;
+
+ adapter->GetParent(IID_IDXGIFactory, (void**)&factory);
+ hr = factory->CreateSwapChain(dev.p, (DXGI_SWAP_CHAIN_DESC*)pSwapChainDesc, ppSwapChain);
+ if(!SUCCEEDED(hr))
+ return hr;
+ }
+ if(ppDevice)
+ *ppDevice = dev.steal();
+ if(ppImmediateContext)
+ *ppImmediateContext = ctx.steal();
+ return hr;
+}
diff --git a/src/gallium/state_trackers/d3d1x/gd3d10/Makefile b/src/gallium/state_trackers/d3d1x/gd3d10/Makefile
new file mode 100644
index 0000000..c6cfea2
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d10/Makefile
@@ -0,0 +1,19 @@
+LIBNAME=gd3d10
+CPP_SOURCES=d3d10.generated.cpp
+LIBRARY_INCLUDES=-I../gd3d1x -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../d3d1xshader/include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common
+
+GEN_D3D10=perl d3d10.pl
+
+include ../Makefile.inc
+
+d3d10.generated.o: d3d10_objects.generated.h d3d10_screen.generated.h d3d10_context.generated.h
+
+d3d10.generated.cpp: ../gd3d11/d3d11.cpp d3d10.pl
+ $(GEN_D3D10) $< > $@
+d3d10_objects.generated.h: ../gd3d11/d3d11_objects.h d3d10.pl
+ $(GEN_D3D10) $< > $@
+d3d10_screen.generated.h: ../gd3d11/d3d11_screen.h d3d10.pl
+ $(GEN_D3D10) $< > $@
+d3d10_context.generated.h: ../gd3d11/d3d11_context.h d3d10.pl
+ $(GEN_D3D10) $< > $@
+
diff --git a/src/gallium/state_trackers/d3d1x/gd3d10/d3d10.pl b/src/gallium/state_trackers/d3d1x/gd3d10/d3d10.pl
new file mode 100755
index 0000000..4687b83
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d10/d3d10.pl
@@ -0,0 +1,12 @@
+#!/usr/bin/perl
+while(<>)
+{
+ s/D3D11_SRV_DIMENSION_/D3D10_1_SRV_DIMENSION_/g;
+ s/D3D11/D3D10/g;
+ s/D3D10_SIGNATURE_PARAMETER_DESC/D3D11_SIGNATURE_PARAMETER_DESC/g;
+ s/D3D_FEATURE_LEVEL_/D3D10_FEATURE_LEVEL_/g;
+ s/D3D_FEATURE_LEVEL/D3D10_FEATURE_LEVEL1/g;
+ s/^#define API 11/#define API 10/;
+ s/^(#include "d3d1)1(_[^.]*)(.h")/${1}0$2.generated$3/;
+ print $_;
+}
diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/Makefile b/src/gallium/state_trackers/d3d1x/gd3d11/Makefile
new file mode 100644
index 0000000..650c11d
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d11/Makefile
@@ -0,0 +1,6 @@
+LIBNAME=gd3d11
+CPP_SOURCES=d3d11.cpp
+LIBRARY_INCLUDES=-I../gd3d1x -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../d3d1xshader/include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common
+
+include ../Makefile.inc
+
diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11.cpp b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11.cpp
new file mode 100644
index 0000000..22cbf15
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11.cpp
@@ -0,0 +1,236 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "d3d1x_private.h"
+
+extern "C"
+{
+#include "util/u_gen_mipmap.h"
+#include "tgsi/tgsi_ureg.h"
+#include "cso_cache/cso_context.h"
+}
+
+
+// the perl script will change this to 10 for d3d10, and also do s/D3D11/D3D10 in the whole file
+#define API 11
+
+#if API >= 11
+#define DX10_ONLY(x)
+#else
+#define DX10_ONLY(x) x
+#endif
+
+typedef D3D10_MAPPED_TEXTURE3D D3D10_MAPPED_SUBRESOURCE;
+
+// used to make QueryInterface know the IIDs of the interface and its ancestors
+COM_INTERFACE(ID3D11DeviceChild, IUnknown)
+COM_INTERFACE(ID3D11InputLayout, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11DepthStencilState, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11BlendState, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11RasterizerState, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11SamplerState, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11Resource, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11Buffer, ID3D11Resource)
+COM_INTERFACE(ID3D11Texture1D, ID3D11Resource)
+COM_INTERFACE(ID3D11Texture2D, ID3D11Resource)
+COM_INTERFACE(ID3D11Texture3D, ID3D11Resource)
+COM_INTERFACE(ID3D11View, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11ShaderResourceView, ID3D11View)
+COM_INTERFACE(ID3D11RenderTargetView, ID3D11View)
+COM_INTERFACE(ID3D11DepthStencilView, ID3D11View)
+COM_INTERFACE(ID3D11VertexShader, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11GeometryShader, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11PixelShader, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11Asynchronous, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11Query, ID3D11Asynchronous)
+COM_INTERFACE(ID3D11Predicate, ID3D11Query)
+COM_INTERFACE(ID3D11Counter, ID3D11Asynchronous)
+COM_INTERFACE(ID3D11Device, IUnknown)
+
+#if API >= 11
+COM_INTERFACE(ID3D11UnorderedAccessView, ID3D11View)
+COM_INTERFACE(ID3D11HullShader, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11DomainShader, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11ComputeShader, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11ClassInstance, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11ClassLinkage, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11CommandList, ID3D11DeviceChild)
+COM_INTERFACE(ID3D11DeviceContext, ID3D11DeviceChild)
+#else
+COM_INTERFACE(ID3D10BlendState1, ID3D10BlendState)
+COM_INTERFACE(ID3D10ShaderResourceView1, ID3D10ShaderResourceView)
+COM_INTERFACE(ID3D10Device1, ID3D10Device)
+#endif
+
+struct GalliumD3D11Screen;
+
+#if API >= 11
+static ID3D11DeviceContext* GalliumD3D11ImmediateDeviceContext_Create(GalliumD3D11Screen* device, struct pipe_context* pipe, bool owns_pipe);
+static void GalliumD3D11ImmediateDeviceContext_RestoreGalliumState(ID3D11DeviceContext* context);
+static void GalliumD3D11ImmediateDeviceContext_RestoreGalliumStateBlitOnly(ID3D11DeviceContext* context);
+static void GalliumD3D11ImmediateDeviceContext_Destroy(ID3D11DeviceContext* device);
+#endif
+
+static inline pipe_box d3d11_to_pipe_box(struct pipe_resource* resource, unsigned level, const D3D11_BOX* pBox)
+{
+ pipe_box box;
+ if(pBox)
+ {
+ box.x = pBox->left;
+ box.y = pBox->top;
+ box.z = pBox->front;
+ box.width = pBox->right - pBox->left;
+ box.height = pBox->bottom - pBox->top;
+ box.depth = pBox->back - pBox->front;
+ }
+ else
+ {
+ box.x = box.y = box.z = 0;
+ box.width = u_minify(resource->width0, level);
+ box.height = u_minify(resource->height0, level);
+ box.depth = u_minify(resource->depth0, level);
+ }
+ return box;
+}
+
+struct GalliumD3D11Caps
+{
+ bool so;
+ bool gs;
+ bool queries;
+ bool render_condition;
+ unsigned constant_buffers[D3D11_STAGES];
+ unsigned stages;
+};
+
+// used to avoid needing to have forward declarations of functions
+// this is called "screen" because in the D3D10 case it's only part of the device
+struct GalliumD3D11Screen
+ : public GalliumDXGIDevice<
+ GalliumMultiComObject<
+#if API >= 11
+ GalliumPrivateDataComObject<ID3D11Device>,
+#else
+ GalliumPrivateDataComObject<ID3D10Device1>,
+#endif
+ IGalliumDevice
+ >
+ >
+{
+ pipe_screen* screen;
+ pipe_context* immediate_pipe;
+ GalliumD3D11Caps screen_caps;
+
+#if API >= 11
+ ID3D11DeviceContext* immediate_context;
+ ID3D11DeviceContext* get_immediate_context()
+ {
+ return immediate_context;
+ }
+#else
+ GalliumD3D11Screen* get_immediate_context()
+ {
+ return this;
+ }
+#endif
+
+
+ GalliumD3D11Screen(pipe_screen* screen, struct pipe_context* immediate_pipe, IDXGIAdapter* adapter)
+ : GalliumDXGIDevice(adapter), screen(screen), immediate_pipe(immediate_pipe)
+ {
+ }
+
+#if API < 11
+ // we use a D3D11-like API internally
+ virtual HRESULT STDMETHODCALLTYPE Map(
+ __in ID3D11Resource *pResource,
+ __in unsigned Subresource,
+ __in D3D11_MAP MapType,
+ __in unsigned MapFlags,
+ __out D3D11_MAPPED_SUBRESOURCE *pMappedResource) = 0;
+ virtual void STDMETHODCALLTYPE Unmap(
+ __in ID3D11Resource *pResource,
+ __in unsigned Subresource) = 0;
+ virtual void STDMETHODCALLTYPE Begin(
+ __in ID3D11Asynchronous *pAsync) = 0;
+ virtual void STDMETHODCALLTYPE End(
+ __in ID3D11Asynchronous *pAsync) = 0;
+ virtual HRESULT STDMETHODCALLTYPE GetData(
+ __in ID3D11Asynchronous *pAsync,
+ __out_bcount_opt(DataSize) void *pData,
+ __in unsigned DataSize,
+ __in unsigned GetDataFlags) = 0;
+
+ // TODO: maybe we should use function overloading, but that might risk silent errors,
+ // and cannot be exported to a C interface
+ virtual void UnbindBlendState(ID3D11BlendState* state) = 0;
+ virtual void UnbindRasterizerState(ID3D11RasterizerState* state) = 0;
+ virtual void UnbindDepthStencilState(ID3D11DepthStencilState* state) = 0;
+ virtual void UnbindInputLayout(ID3D11InputLayout* state) = 0;
+ virtual void UnbindPixelShader(ID3D11PixelShader* state) = 0;
+ virtual void UnbindVertexShader(ID3D11VertexShader* state) = 0;
+ virtual void UnbindGeometryShader(ID3D11GeometryShader* state) = 0;
+ virtual void UnbindPredicate(ID3D11Predicate* predicate) = 0;
+ virtual void UnbindSamplerState(ID3D11SamplerState* state) = 0;
+ virtual void UnbindBuffer(ID3D11Buffer* buffer) = 0;
+ virtual void UnbindDepthStencilView(ID3D11DepthStencilView* view) = 0;
+ virtual void UnbindRenderTargetView(ID3D11RenderTargetView* view) = 0;
+ virtual void UnbindShaderResourceView(ID3D11ShaderResourceView* view) = 0;
+
+ void UnbindBlendState1(ID3D11BlendState1* state)
+ {
+ UnbindBlendState(state);
+ }
+ void UnbindShaderResourceView1(ID3D11ShaderResourceView1* view)
+ {
+ UnbindShaderResourceView(view);
+ }
+#endif
+};
+
+#include "d3d11_objects.h"
+#include "d3d11_screen.h"
+#include "d3d11_context.h"
+
+#if API >= 11
+HRESULT STDMETHODCALLTYPE GalliumD3D11DeviceCreate(struct pipe_screen* screen, struct pipe_context* context, BOOL owns_context, unsigned creation_flags, IDXGIAdapter* adapter, ID3D11Device** ppDevice)
+{
+ if(creation_flags & D3D11_CREATE_DEVICE_SINGLETHREADED)
+ *ppDevice = new GalliumD3D11ScreenImpl<false>(screen, context, owns_context, creation_flags, adapter);
+ else
+ *ppDevice = new GalliumD3D11ScreenImpl<true>(screen, context, owns_context, creation_flags, adapter);
+ return S_OK;
+}
+#else
+HRESULT STDMETHODCALLTYPE GalliumD3D10DeviceCreate1(struct pipe_screen* screen, struct pipe_context* context, BOOL owns_context, unsigned creation_flags, IDXGIAdapter* adapter, ID3D10Device1** ppDevice)
+{
+ if(creation_flags & D3D10_CREATE_DEVICE_SINGLETHREADED)
+ *ppDevice = new GalliumD3D10Device<false>(screen, context, owns_context, creation_flags, adapter);
+ else
+ *ppDevice = new GalliumD3D10Device<true>(screen, context, owns_context, creation_flags, adapter);
+ return S_OK;
+}
+#endif
diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h
new file mode 100644
index 0000000..a8573cd
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_context.h
@@ -0,0 +1,2033 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+/* used to unbind things, we need 128 due to resources */
+static const void* zero_data[128];
+
+#define UPDATE_VIEWS_SHIFT (D3D11_STAGES * 0)
+#define UPDATE_SAMPLERS_SHIFT (D3D11_STAGES * 1)
+#define UPDATE_VERTEX_BUFFERS (1 << (D3D11_STAGES * 2))
+
+#if API >= 11
+template<typename PtrTraits>
+struct GalliumD3D11DeviceContext :
+ public GalliumD3D11DeviceChild<ID3D11DeviceContext>
+{
+#else
+template<bool threadsafe>
+struct GalliumD3D10Device : public GalliumD3D10ScreenImpl<threadsafe>
+{
+ typedef simple_ptr_traits PtrTraits;
+ typedef GalliumD3D10Device GalliumD3D10DeviceContext;
+#endif
+
+ refcnt_ptr<GalliumD3D11Shader<>, PtrTraits> shaders[D3D11_STAGES];
+ refcnt_ptr<GalliumD3D11InputLayout, PtrTraits> input_layout;
+ refcnt_ptr<GalliumD3D11Buffer, PtrTraits> index_buffer;
+ refcnt_ptr<GalliumD3D11RasterizerState, PtrTraits> rasterizer_state;
+ refcnt_ptr<GalliumD3D11DepthStencilState, PtrTraits> depth_stencil_state;
+ refcnt_ptr<GalliumD3D11BlendState, PtrTraits> blend_state;
+ refcnt_ptr<GalliumD3D11DepthStencilView, PtrTraits> depth_stencil_view;
+ refcnt_ptr<GalliumD3D11Predicate, PtrTraits> render_predicate;
+
+ refcnt_ptr<GalliumD3D11Buffer, PtrTraits> constant_buffers[D3D11_STAGES][D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
+ refcnt_ptr<GalliumD3D11ShaderResourceView, PtrTraits> shader_resource_views[D3D11_STAGES][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
+ refcnt_ptr<GalliumD3D11SamplerState, PtrTraits> samplers[D3D11_STAGES][D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
+ refcnt_ptr<GalliumD3D11Buffer, PtrTraits> input_buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
+ refcnt_ptr<GalliumD3D11RenderTargetView, PtrTraits> render_target_views[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
+ refcnt_ptr<GalliumD3D11Buffer, PtrTraits> so_targets[D3D11_SO_BUFFER_SLOT_COUNT];
+
+#if API >= 11
+ refcnt_ptr<ID3D11UnorderedAccessView, PtrTraits> cs_unordered_access_views[D3D11_PS_CS_UAV_REGISTER_COUNT];
+ refcnt_ptr<ID3D11UnorderedAccessView, PtrTraits> om_unordered_access_views[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
+#endif
+
+ D3D11_VIEWPORT viewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
+ D3D11_RECT scissor_rects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
+ unsigned so_offsets[D3D11_SO_BUFFER_SLOT_COUNT];
+ D3D11_PRIMITIVE_TOPOLOGY primitive_topology;
+ DXGI_FORMAT index_format;
+ unsigned index_offset;
+ BOOL render_predicate_value;
+ float blend_color[4];
+ unsigned sample_mask;
+ unsigned stencil_ref;
+ bool depth_clamp;
+
+ void* default_input_layout;
+ void* default_rasterizer;
+ void* default_depth_stencil;
+ void* default_blend;
+ void* default_sampler;
+ void* ld_sampler;
+ void * default_shaders[D3D11_STAGES];
+
+ // derived state
+ int primitive_mode;
+ struct pipe_vertex_buffer vertex_buffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
+ struct pipe_resource* so_buffers[D3D11_SO_BUFFER_SLOT_COUNT];
+ struct pipe_sampler_view* sampler_views[D3D11_STAGES][D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
+ struct
+ {
+ void* ld; // accessed with a -1 index from v
+ void* v[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
+ } sampler_csos[D3D11_STAGES];
+ struct pipe_resource * buffers[D3D11_SO_BUFFER_SLOT_COUNT];
+ unsigned num_shader_resource_views[D3D11_STAGES];
+ unsigned num_samplers[D3D11_STAGES];
+ unsigned num_vertex_buffers;
+ unsigned num_render_target_views;
+ unsigned num_viewports;
+ unsigned num_scissor_rects;
+ unsigned num_so_targets;
+
+ struct pipe_context* pipe;
+ unsigned update_flags;
+
+ bool owns_pipe;
+ unsigned context_flags;
+
+ GalliumD3D11Caps caps;
+
+ cso_context* cso_ctx;
+ gen_mipmap_state* gen_mipmap;
+
+#if API >= 11
+#define SYNCHRONIZED do {} while(0)
+
+ GalliumD3D11DeviceContext(GalliumD3D11Screen* device, pipe_context* pipe, bool owns_pipe, unsigned context_flags = 0)
+ : GalliumD3D11DeviceChild(device), pipe(pipe), owns_pipe(owns_pipe), context_flags(context_flags)
+ {
+ caps = device->screen_caps;
+ init_context();
+ }
+
+ ~GalliumD3D11DeviceContext()
+ {
+ destroy_context();
+ }
+#else
+#define SYNCHRONIZED lock_t<maybe_mutex_t<threadsafe> > lock_(this->mutex)
+
+ GalliumD3D10Device(pipe_screen* screen, pipe_context* pipe, bool owns_pipe, unsigned creation_flags, IDXGIAdapter* adapter)
+ : GalliumD3D10ScreenImpl<threadsafe>(screen, pipe, owns_pipe, creation_flags, adapter), pipe(pipe), owns_pipe(owns_pipe), context_flags(0)
+ {
+ caps = this->screen_caps;
+ init_context();
+ }
+
+ ~GalliumD3D10Device()
+ {
+ destroy_context();
+ }
+#endif
+
+ void init_context()
+ {
+ if(!pipe->begin_query)
+ caps.queries = false;
+ if(!pipe->render_condition)
+ caps.render_condition = false;
+ if(!pipe->bind_gs_state)
+ {
+ caps.gs = false;
+ caps.stages = 2;
+ }
+ if(!pipe->set_stream_output_buffers)
+ caps.so = false;
+
+ update_flags = 0;
+
+ // pipeline state
+ memset(viewports, 0, sizeof(viewports));
+ memset(scissor_rects, 0, sizeof(scissor_rects));
+ memset(so_offsets, 0, sizeof(so_offsets));
+ primitive_topology = D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED;
+ index_format = DXGI_FORMAT_UNKNOWN;
+ index_offset = 0;
+ render_predicate_value = 0;
+ memset(blend_color, 0, sizeof(blend_color));
+ sample_mask = ~0;
+ stencil_ref = 0;
+ depth_clamp = 0;
+
+ // derived state
+ primitive_mode = 0;
+ memset(vertex_buffers, 0, sizeof(vertex_buffers));
+ memset(so_buffers, 0, sizeof(so_buffers));
+ memset(sampler_views, 0, sizeof(sampler_views));
+ memset(sampler_csos, 0, sizeof(sampler_csos));
+ memset(num_shader_resource_views, 0, sizeof(num_shader_resource_views));
+ memset(num_samplers, 0, sizeof(num_samplers));
+ num_vertex_buffers = 0;
+ num_render_target_views = 0;
+ num_viewports = 0;
+ num_scissor_rects = 0;
+ num_so_targets = 0;
+
+ default_input_layout = pipe->create_vertex_elements_state(pipe, 0, 0);
+
+ struct pipe_rasterizer_state rasterizerd;
+ memset(&rasterizerd, 0, sizeof(rasterizerd));
+ rasterizerd.gl_rasterization_rules = 1;
+ rasterizerd.cull_face = PIPE_FACE_BACK;
+ default_rasterizer = pipe->create_rasterizer_state(pipe, &rasterizerd);
+
+ struct pipe_depth_stencil_alpha_state depth_stencild;
+ memset(&depth_stencild, 0, sizeof(depth_stencild));
+ depth_stencild.depth.enabled = TRUE;
+ depth_stencild.depth.writemask = 1;
+ depth_stencild.depth.func = PIPE_FUNC_LESS;
+ default_depth_stencil = pipe->create_depth_stencil_alpha_state(pipe, &depth_stencild);
+
+ struct pipe_blend_state blendd;
+ memset(&blendd, 0, sizeof(blendd));
+ blendd.rt[0].colormask = 0xf;
+ default_blend = pipe->create_blend_state(pipe, &blendd);
+
+ struct pipe_sampler_state samplerd;
+ memset(&samplerd, 0, sizeof(samplerd));
+ samplerd.normalized_coords = 1;
+ samplerd.min_img_filter = PIPE_TEX_FILTER_LINEAR;
+ samplerd.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
+ samplerd.min_mip_filter = PIPE_TEX_MIPFILTER_LINEAR;
+ samplerd.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ samplerd.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ samplerd.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+ samplerd.border_color[0] = 1.0f;
+ samplerd.border_color[1] = 1.0f;
+ samplerd.border_color[2] = 1.0f;
+ samplerd.border_color[3] = 1.0f;
+ samplerd.min_lod = -FLT_MAX;
+ samplerd.max_lod = FLT_MAX;
+ samplerd.max_anisotropy = 1;
+ default_sampler = pipe->create_sampler_state(pipe, &samplerd);
+
+ memset(&samplerd, 0, sizeof(samplerd));
+ samplerd.normalized_coords = 0;
+ samplerd.min_img_filter = PIPE_TEX_FILTER_NEAREST;
+ samplerd.mag_img_filter = PIPE_TEX_FILTER_NEAREST;
+ samplerd.min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
+ samplerd.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_BORDER;
+ samplerd.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_BORDER;
+ samplerd.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_BORDER;
+ samplerd.min_lod = -FLT_MAX;
+ samplerd.max_lod = FLT_MAX;
+ samplerd.max_anisotropy = 1;
+ ld_sampler = pipe->create_sampler_state(pipe, &samplerd);
+
+ for(unsigned s = 0; s < D3D11_STAGES; ++s)
+ {
+ sampler_csos[s].ld = ld_sampler;
+ for(unsigned i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
+ sampler_csos[s].v[i] = default_sampler;
+ }
+
+ // TODO: should this really be empty shaders, or should they be all-passthrough?
+ memset(default_shaders, 0, sizeof(default_shaders));
+ struct ureg_program *ureg;
+ ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
+ ureg_END(ureg);
+ default_shaders[PIPE_SHADER_FRAGMENT] = ureg_create_shader_and_destroy(ureg, pipe);
+
+ ureg = ureg_create(TGSI_PROCESSOR_VERTEX);
+ ureg_END(ureg);
+ default_shaders[PIPE_SHADER_VERTEX] = ureg_create_shader_and_destroy(ureg, pipe);
+
+ cso_ctx = cso_create_context(pipe);
+ gen_mipmap = util_create_gen_mipmap(pipe, cso_ctx);
+
+ RestoreGalliumState();
+ }
+
+ void destroy_context()
+ {
+ util_destroy_gen_mipmap(gen_mipmap);
+ cso_destroy_context(cso_ctx);
+ pipe->delete_vertex_elements_state(pipe, default_input_layout);
+ pipe->delete_rasterizer_state(pipe, default_rasterizer);
+ pipe->delete_depth_stencil_alpha_state(pipe, default_depth_stencil);
+ pipe->delete_blend_state(pipe, default_blend);
+ pipe->delete_sampler_state(pipe, default_sampler);
+ pipe->delete_sampler_state(pipe, ld_sampler);
+ pipe->delete_fs_state(pipe, default_shaders[PIPE_SHADER_FRAGMENT]);
+ pipe->delete_vs_state(pipe, default_shaders[PIPE_SHADER_VERTEX]);
+ if(owns_pipe)
+ pipe->destroy(pipe);
+ }
+
+ virtual unsigned STDMETHODCALLTYPE GetContextFlags(void)
+ {
+ return context_flags;
+ }
+#if API >= 11
+#define SET_SHADER_EXTRA_ARGS , \
+ __in_ecount_opt(NumClassInstances) ID3D11ClassInstance *const *ppClassInstances, \
+ unsigned NumClassInstances
+#define GET_SHADER_EXTRA_ARGS , \
+ __out_ecount_opt(*pNumClassInstances) ID3D11ClassInstance **ppClassInstances, \
+ __inout_opt unsigned *pNumClassInstances
+#else
+#define SET_SHADER_EXTRA_ARGS
+#define GET_SHADER_EXTRA_ARGS
+#endif
+
+/* On Windows D3D11, SetConstantBuffers and SetShaderResources crash if passed a null pointer.
+ * Instead, you have to pass a pointer to nulls to unbind things.
+ * We do the same.
+ * TODO: is D3D10 the same?
+ */
+ template<unsigned s>
+ void xs_set_shader(GalliumD3D11Shader<>* shader)
+ {
+ if(shader != shaders[s].p)
+ {
+ shaders[s] = shader;
+ void* shader_cso = shader ? shader->object : default_shaders[s];
+ switch(s)
+ {
+ case PIPE_SHADER_VERTEX:
+ pipe->bind_vs_state(pipe, shader_cso);
+ break;
+ case PIPE_SHADER_FRAGMENT:
+ pipe->bind_fs_state(pipe, shader_cso);
+ break;
+ case PIPE_SHADER_GEOMETRY:
+ pipe->bind_gs_state(pipe, shader_cso);
+ break;
+ }
+ update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + s)) | (1 << (UPDATE_VIEWS_SHIFT + s));
+ }
+ }
+
+ template<unsigned s>
+ void xs_set_constant_buffers(unsigned start, unsigned count, GalliumD3D11Buffer *const *constbufs)
+ {
+ for(unsigned i = 0; i < count; ++i)
+ {
+ if(constbufs[i] != constant_buffers[s][i].p)
+ {
+ constant_buffers[s][i] = constbufs[i];
+ if(s < caps.stages && start + i < caps.constant_buffers[s])
+ pipe->set_constant_buffer(pipe, s, start + i, constbufs[i] ? constbufs[i]->resource : NULL);
+ }
+ }
+ }
+
+ template<unsigned s>
+ void xs_set_shader_resources(unsigned start, unsigned count, GalliumD3D11ShaderResourceView *const *srvs)
+ {
+ int last_different = -1;
+ for(unsigned i = 0; i < count; ++i)
+ {
+ if(shader_resource_views[s][start + i].p != srvs[i])
+ {
+ shader_resource_views[s][start + i] = srvs[i];
+ sampler_views[s][start + i] = srvs[i] ? srvs[i]->object : 0;
+ last_different = i;
+ }
+ }
+ if(last_different >= 0)
+ {
+ num_shader_resource_views[s] = std::max(num_shader_resource_views[s], start + last_different + 1);
+ update_flags |= 1 << (UPDATE_VIEWS_SHIFT + s);
+ }
+ }
+
+ template<unsigned s>
+ void xs_set_samplers(unsigned start, unsigned count, GalliumD3D11SamplerState *const *samps)
+ {
+ int last_different = -1;
+ for(unsigned i = 0; i < count; ++i)
+ {
+ if(samplers[s][start + i].p != samps[i])
+ {
+ samplers[s][start + i] = samps[i];
+ sampler_csos[s].v[start + i] = samps[i] ? samps[i]->object : default_sampler;
+ }
+ if(last_different >= 0)
+ {
+ num_samplers[s] = std::max(num_samplers[s], start + last_different + 1);
+ update_flags |= (UPDATE_SAMPLERS_SHIFT + s);
+ }
+ }
+ }
+
+#define IMPLEMENT_SHADER_STAGE(XS, Stage) \
+ virtual void STDMETHODCALLTYPE XS##SetShader( \
+ __in_opt ID3D11##Stage##Shader *pShader \
+ SET_SHADER_EXTRA_ARGS) \
+ { \
+ SYNCHRONIZED; \
+ xs_set_shader<D3D11_STAGE_##XS>((GalliumD3D11Shader<>*)pShader); \
+ } \
+ virtual void STDMETHODCALLTYPE XS##GetShader(\
+ __out ID3D11##Stage##Shader **ppShader \
+ GET_SHADER_EXTRA_ARGS) \
+ { \
+ SYNCHRONIZED; \
+ *ppShader = (ID3D11##Stage##Shader*)shaders[D3D11_STAGE_##XS].ref(); \
+ } \
+ virtual void STDMETHODCALLTYPE XS##SetConstantBuffers(\
+ __in_range(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1) unsigned StartSlot, \
+ __in_range(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot) unsigned NumBuffers, \
+ __in_ecount(NumBuffers) ID3D11Buffer *const *ppConstantBuffers) \
+ { \
+ SYNCHRONIZED; \
+ xs_set_constant_buffers<D3D11_STAGE_##XS>(StartSlot, NumBuffers, (GalliumD3D11Buffer *const *)ppConstantBuffers); \
+ } \
+ virtual void STDMETHODCALLTYPE XS##GetConstantBuffers(\
+ __in_range(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - 1) unsigned StartSlot, \
+ __in_range(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT - StartSlot) unsigned NumBuffers, \
+ __out_ecount(NumBuffers) ID3D11Buffer **ppConstantBuffers) \
+ { \
+ SYNCHRONIZED; \
+ for(unsigned i = 0; i < NumBuffers; ++i) \
+ ppConstantBuffers[i] = constant_buffers[D3D11_STAGE_##XS][StartSlot + i].ref(); \
+ } \
+ virtual void STDMETHODCALLTYPE XS##SetShaderResources(\
+ __in_range(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1) unsigned StartSlot, \
+ __in_range(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot) unsigned NumViews, \
+ __in_ecount(NumViews) ID3D11ShaderResourceView *const *ppShaderResourceViews) \
+ { \
+ SYNCHRONIZED; \
+ xs_set_shader_resources<D3D11_STAGE_##XS>(StartSlot, NumViews, (GalliumD3D11ShaderResourceView *const *)ppShaderResourceViews); \
+ } \
+ virtual void STDMETHODCALLTYPE XS##GetShaderResources(\
+ __in_range(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1) unsigned StartSlot, \
+ __in_range(0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - StartSlot) unsigned NumViews, \
+ __out_ecount(NumViews) ID3D11ShaderResourceView **ppShaderResourceViews) \
+ { \
+ SYNCHRONIZED; \
+ for(unsigned i = 0; i < NumViews; ++i) \
+ ppShaderResourceViews[i] = shader_resource_views[D3D11_STAGE_##XS][StartSlot + i].ref(); \
+ } \
+ virtual void STDMETHODCALLTYPE XS##SetSamplers(\
+ __in_range(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1) unsigned StartSlot, \
+ __in_range(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot) unsigned NumSamplers, \
+ __in_ecount(NumSamplers) ID3D11SamplerState *const *ppSamplers) \
+ { \
+ SYNCHRONIZED; \
+ xs_set_samplers<D3D11_STAGE_##XS>(StartSlot, NumSamplers, (GalliumD3D11SamplerState *const *)ppSamplers); \
+ } \
+ virtual void STDMETHODCALLTYPE XS##GetSamplers( \
+ __in_range(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - 1) unsigned StartSlot, \
+ __in_range(0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT - StartSlot) unsigned NumSamplers, \
+ __out_ecount(NumSamplers) ID3D11SamplerState **ppSamplers) \
+ { \
+ SYNCHRONIZED; \
+ for(unsigned i = 0; i < NumSamplers; ++i) \
+ ppSamplers[i] = samplers[D3D11_STAGE_##XS][StartSlot + i].ref(); \
+ }
+
+#define DO_VS(x) x
+#define DO_GS(x) do {if(caps.gs) {x;}} while(0)
+#define DO_PS(x) x
+#define DO_HS(x)
+#define DO_DS(x)
+#define DO_CS(x)
+ IMPLEMENT_SHADER_STAGE(VS, Vertex)
+ IMPLEMENT_SHADER_STAGE(GS, Geometry)
+ IMPLEMENT_SHADER_STAGE(PS, Pixel)
+
+#if API >= 11
+ IMPLEMENT_SHADER_STAGE(HS, Hull)
+ IMPLEMENT_SHADER_STAGE(DS, Domain)
+ IMPLEMENT_SHADER_STAGE(CS, Compute)
+
+ virtual void STDMETHODCALLTYPE CSSetUnorderedAccessViews(
+ __in_range(0, D3D11_PS_CS_UAV_REGISTER_COUNT - 1) unsigned StartSlot,
+ __in_range(0, D3D11_PS_CS_UAV_REGISTER_COUNT - StartSlot) unsigned NumUAVs,
+ __in_ecount(NumUAVs) ID3D11UnorderedAccessView *const *ppUnorderedAccessViews,
+ __in_ecount(NumUAVs) const unsigned *pUAVInitialCounts)
+ {
+ SYNCHRONIZED;
+ for(unsigned i = 0; i < NumUAVs; ++i)
+ cs_unordered_access_views[StartSlot + i] = ppUnorderedAccessViews[i];
+ }
+
+ virtual void STDMETHODCALLTYPE CSGetUnorderedAccessViews(
+ __in_range(0, D3D11_PS_CS_UAV_REGISTER_COUNT - 1) unsigned StartSlot,
+ __in_range(0, D3D11_PS_CS_UAV_REGISTER_COUNT - StartSlot) unsigned NumUAVs,
+ __out_ecount(NumUAVs) ID3D11UnorderedAccessView **ppUnorderedAccessViews)
+ {
+ SYNCHRONIZED;
+ for(unsigned i = 0; i < NumUAVs; ++i)
+ ppUnorderedAccessViews[i] = cs_unordered_access_views[StartSlot + i].ref();
+ }
+#endif
+
+ template<unsigned s>
+ void update_stage()
+ {
+ if(update_flags & (1 << (UPDATE_VIEWS_SHIFT + s)))
+ {
+ while(num_shader_resource_views[s] && !sampler_views[s][num_shader_resource_views[s] - 1]) \
+ --num_shader_resource_views[s];
+ if(s < caps.stages)
+ {
+ struct pipe_sampler_view* views_to_bind[PIPE_MAX_SAMPLERS];
+ unsigned num_views_to_bind = shaders[s] ? shaders[s]->slot_to_resource.size() : 0;
+ for(unsigned i = 0; i < num_views_to_bind; ++i)
+ {
+ views_to_bind[i] = sampler_views[s][shaders[s]->slot_to_resource[i]];
+ }
+ switch(s)
+ {
+ case PIPE_SHADER_VERTEX:
+ pipe->set_vertex_sampler_views(pipe, num_views_to_bind, views_to_bind);
+ break;
+ case PIPE_SHADER_FRAGMENT:
+ pipe->set_fragment_sampler_views(pipe, num_views_to_bind, views_to_bind);
+ break;
+ case PIPE_SHADER_GEOMETRY:
+ pipe->set_geometry_sampler_views(pipe, num_views_to_bind, views_to_bind);
+ break;
+ }
+ }
+ }
+
+ if(update_flags & (1 << (UPDATE_SAMPLERS_SHIFT + s)))
+ {
+ while(num_samplers[s] && !sampler_csos[s].v[num_samplers[s] - 1])
+ --num_samplers[s];
+ if(s < caps.stages)
+ {
+ void* samplers_to_bind[PIPE_MAX_SAMPLERS];
+ unsigned num_samplers_to_bind = shaders[s] ? shaders[s]->slot_to_sampler.size() : 0;
+ for(unsigned i = 0; i < num_samplers_to_bind; ++i)
+ {
+ // index can be -1 to access sampler_csos[s].ld
+ samplers_to_bind[i] = *(sampler_csos[s].v + shaders[s]->slot_to_sampler[i]);
+ }
+ switch(s)
+ {
+ case PIPE_SHADER_VERTEX:
+ pipe->bind_vertex_sampler_states(pipe, num_samplers_to_bind, samplers_to_bind);
+ break;
+ case PIPE_SHADER_FRAGMENT:
+ pipe->bind_fragment_sampler_states(pipe, num_samplers_to_bind, samplers_to_bind);
+ break;
+ case PIPE_SHADER_GEOMETRY:
+ pipe->bind_geometry_sampler_states(pipe, num_samplers_to_bind, samplers_to_bind);
+ break;
+ }
+ }
+ }
+ }
+
+ void update_state()
+ {
+ update_stage<D3D11_STAGE_PS>();
+ update_stage<D3D11_STAGE_VS>();
+ update_stage<D3D11_STAGE_GS>();
+#if API >= 11
+ update_stage<D3D11_STAGE_HS>();
+ update_stage<D3D11_STAGE_DS>();
+ update_stage<D3D11_STAGE_CS>();
+#endif
+
+ if(update_flags & UPDATE_VERTEX_BUFFERS)
+ {
+ while(num_vertex_buffers && !vertex_buffers[num_vertex_buffers - 1].buffer)
+ --num_vertex_buffers;
+ pipe->set_vertex_buffers(pipe, num_vertex_buffers, vertex_buffers);
+ }
+
+ update_flags = 0;
+ }
+
+ virtual void STDMETHODCALLTYPE IASetInputLayout(
+ __in_opt ID3D11InputLayout *pInputLayout)
+ {
+ SYNCHRONIZED;
+ if(pInputLayout != input_layout.p)
+ {
+ input_layout = pInputLayout;
+ pipe->bind_vertex_elements_state(pipe, pInputLayout ? ((GalliumD3D11InputLayout*)pInputLayout)->object : default_input_layout);
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE IAGetInputLayout(
+ __out ID3D11InputLayout **ppInputLayout)
+ {
+ SYNCHRONIZED;
+ *ppInputLayout = input_layout.ref();
+ }
+
+ virtual void STDMETHODCALLTYPE IASetVertexBuffers(
+ __in_range(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - 1) unsigned StartSlot,
+ __in_range(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - StartSlot) unsigned NumBuffers,
+ __in_ecount(NumBuffers) ID3D11Buffer *const *ppVertexBuffers,
+ __in_ecount(NumBuffers) const unsigned *pStrides,
+ __in_ecount(NumBuffers) const unsigned *pOffsets)
+ {
+ SYNCHRONIZED;
+ int last_different = -1;
+ for(unsigned i = 0; i < NumBuffers; ++i)
+ {
+ ID3D11Buffer* buffer = ppVertexBuffers[i];
+ if(buffer != input_buffers[StartSlot + i].p
+ || vertex_buffers[StartSlot + i].buffer_offset != pOffsets[i]
+ || vertex_buffers[StartSlot + i].stride != pOffsets[i]
+ )
+ {
+ input_buffers[StartSlot + i] = buffer;
+ vertex_buffers[StartSlot + i].buffer = buffer ? ((GalliumD3D11Buffer*)buffer)->resource : 0;
+ vertex_buffers[StartSlot + i].buffer_offset = pOffsets[i];
+ vertex_buffers[StartSlot + i].stride = pStrides[i];
+ vertex_buffers[StartSlot + i].max_index = ~0;
+ last_different = i;
+ }
+ }
+ if(last_different >= 0)
+ {
+ num_vertex_buffers = std::max(num_vertex_buffers, StartSlot + NumBuffers);
+ update_flags |= UPDATE_VERTEX_BUFFERS;
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE IAGetVertexBuffers(
+ __in_range(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - 1) unsigned StartSlot,
+ __in_range(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT - StartSlot) unsigned NumBuffers,
+ __out_ecount_opt(NumBuffers) ID3D11Buffer **ppVertexBuffers,
+ __out_ecount_opt(NumBuffers) unsigned *pStrides,
+ __out_ecount_opt(NumBuffers) unsigned *pOffsets)
+ {
+ SYNCHRONIZED;
+ if(ppVertexBuffers)
+ {
+ for(unsigned i = 0; i < NumBuffers; ++i)
+ ppVertexBuffers[i] = input_buffers[StartSlot + i].ref();
+ }
+
+ if(pOffsets)
+ {
+ for(unsigned i = 0; i < NumBuffers; ++i)
+ pOffsets[i] = vertex_buffers[StartSlot + i].buffer_offset;
+ }
+
+ if(pStrides)
+ {
+ for(unsigned i = 0; i < NumBuffers; ++i)
+ pStrides[i] = vertex_buffers[StartSlot + i].stride;
+ }
+ }
+
+ void set_index_buffer()
+ {
+ pipe_index_buffer ib;
+ if(!index_buffer)
+ {
+ memset(&ib, 0, sizeof(ib));
+ }
+ else
+ {
+ if(index_format == DXGI_FORMAT_R32_UINT)
+ ib.index_size = 4;
+ else if(index_format == DXGI_FORMAT_R16_UINT)
+ ib.index_size = 2;
+ else
+ ib.index_size = 1;
+ ib.offset = index_offset;
+ ib.buffer = index_buffer ? ((GalliumD3D11Buffer*)index_buffer.p)->resource : 0;
+ }
+ pipe->set_index_buffer(pipe, &ib);
+ }
+
+ virtual void STDMETHODCALLTYPE IASetIndexBuffer(
+ __in_opt ID3D11Buffer *pIndexBuffer,
+ __in DXGI_FORMAT Format,
+ __in unsigned Offset)
+ {
+ SYNCHRONIZED;
+ if(index_buffer.p != pIndexBuffer || index_format != Format || index_offset != Offset)
+ {
+ index_buffer = pIndexBuffer;
+ index_format = Format;
+ index_offset = Offset;
+
+ set_index_buffer();
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE IAGetIndexBuffer(
+ __out_opt ID3D11Buffer **pIndexBuffer,
+ __out_opt DXGI_FORMAT *Format,
+ __out_opt unsigned *Offset)
+ {
+ SYNCHRONIZED;
+ if(pIndexBuffer)
+ *pIndexBuffer = index_buffer.ref();
+ if(Format)
+ *Format = index_format;
+ if(Offset)
+ *Offset = index_offset;
+ }
+
+ virtual void STDMETHODCALLTYPE IASetPrimitiveTopology(
+ __in D3D11_PRIMITIVE_TOPOLOGY Topology)
+ {
+ SYNCHRONIZED;
+ if(primitive_topology != Topology)
+ {
+ if(Topology < D3D_PRIMITIVE_TOPOLOGY_COUNT)
+ primitive_mode = d3d_to_pipe_prim[Topology];
+ else
+ primitive_mode = 0;
+ primitive_topology = Topology;
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE IAGetPrimitiveTopology(
+ __out D3D11_PRIMITIVE_TOPOLOGY *pTopology)
+ {
+ SYNCHRONIZED;
+ *pTopology = primitive_topology;
+ }
+
+ virtual void STDMETHODCALLTYPE DrawIndexed(
+ __in unsigned IndexCount,
+ __in unsigned StartIndexLocation,
+ __in int BaseVertexLocation)
+ {
+ SYNCHRONIZED;
+ if(update_flags)
+ update_state();
+
+ pipe_draw_info info;
+ info.mode = primitive_mode;
+ info.indexed = TRUE;
+ info.count = IndexCount;
+ info.start = StartIndexLocation;
+ info.index_bias = BaseVertexLocation;
+ info.min_index = 0;
+ info.max_index = ~0;
+ info.start_instance = 0;
+ info.instance_count = 1;
+
+ pipe->draw_vbo(pipe, &info);
+ }
+
+ virtual void STDMETHODCALLTYPE Draw(
+ __in unsigned VertexCount,
+ __in unsigned StartVertexLocation)
+ {
+ SYNCHRONIZED;
+ if(update_flags)
+ update_state();
+
+ pipe_draw_info info;
+ info.mode = primitive_mode;
+ info.indexed = FALSE;
+ info.count = VertexCount;
+ info.start = StartVertexLocation;
+ info.index_bias = 0;
+ info.min_index = 0;
+ info.max_index = ~0;
+ info.start_instance = 0;
+ info.instance_count = 1;
+
+ pipe->draw_vbo(pipe, &info);
+ }
+
+ virtual void STDMETHODCALLTYPE DrawIndexedInstanced(
+ __in unsigned IndexCountPerInstance,
+ __in unsigned InstanceCount,
+ __in unsigned StartIndexLocation,
+ __in int BaseVertexLocation,
+ __in unsigned StartInstanceLocation)
+ {
+ SYNCHRONIZED;
+ if(update_flags)
+ update_state();
+
+ pipe_draw_info info;
+ info.mode = primitive_mode;
+ info.indexed = TRUE;
+ info.count = IndexCountPerInstance;
+ info.start = StartIndexLocation;
+ info.index_bias = BaseVertexLocation;
+ info.min_index = 0;
+ info.max_index = ~0;
+ info.start_instance = StartInstanceLocation;
+ info.instance_count = InstanceCount;
+
+ pipe->draw_vbo(pipe, &info);
+ }
+
+ virtual void STDMETHODCALLTYPE DrawInstanced(
+ __in unsigned VertexCountPerInstance,
+ __in unsigned InstanceCount,
+ __in unsigned StartVertexLocation,
+ __in unsigned StartInstanceLocation)
+ {
+ SYNCHRONIZED;
+ if(update_flags)
+ update_state();
+
+ pipe_draw_info info;
+ info.mode = primitive_mode;
+ info.indexed = FALSE;
+ info.count = VertexCountPerInstance;
+ info.start = StartVertexLocation;
+ info.index_bias = 0;
+ info.min_index = 0;
+ info.max_index = ~0;
+ info.start_instance = StartInstanceLocation;
+ info.instance_count = InstanceCount;
+
+ pipe->draw_vbo(pipe, &info);
+ }
+
+ virtual void STDMETHODCALLTYPE DrawAuto(void)
+ {
+ if(!caps.so)
+ return;
+
+ SYNCHRONIZED;
+ if(update_flags)
+ update_state();
+
+ pipe->draw_stream_output(pipe, primitive_mode);
+ }
+
+ virtual void STDMETHODCALLTYPE DrawIndexedInstancedIndirect(
+ __in ID3D11Buffer *pBufferForArgs,
+ __in unsigned AlignedByteOffsetForArgs)
+ {
+ SYNCHRONIZED;
+ if(update_flags)
+ update_state();
+
+ struct {
+ unsigned count;
+ unsigned instance_count;
+ unsigned start;
+ unsigned index_bias;
+ } data;
+
+ pipe_buffer_read(pipe, ((GalliumD3D11Buffer*)pBufferForArgs)->resource, AlignedByteOffsetForArgs, sizeof(data), &data);
+
+ pipe_draw_info info;
+ info.mode = primitive_mode;
+ info.indexed = TRUE;
+ info.start = data.start;
+ info.count = data.count;
+ info.index_bias = data.index_bias;
+ info.min_index = 0;
+ info.max_index = ~0;
+ info.start_instance = 0;
+ info.instance_count = data.instance_count;
+
+ pipe->draw_vbo(pipe, &info);
+ }
+
+ virtual void STDMETHODCALLTYPE DrawInstancedIndirect(
+ __in ID3D11Buffer *pBufferForArgs,
+ __in unsigned AlignedByteOffsetForArgs)
+ {
+ SYNCHRONIZED;
+ if(update_flags)
+ update_state();
+
+ struct {
+ unsigned count;
+ unsigned instance_count;
+ unsigned start;
+ } data;
+
+ pipe_buffer_read(pipe, ((GalliumD3D11Buffer*)pBufferForArgs)->resource, AlignedByteOffsetForArgs, sizeof(data), &data);
+
+ pipe_draw_info info;
+ info.mode = primitive_mode;
+ info.indexed = FALSE;
+ info.start = data.start;
+ info.count = data.count;
+ info.index_bias = 0;
+ info.min_index = 0;
+ info.max_index = ~0;
+ info.start_instance = 0;
+ info.instance_count = data.instance_count;
+
+ pipe->draw_vbo(pipe, &info);
+ }
+
+#if API >= 11
+ virtual void STDMETHODCALLTYPE Dispatch(
+ __in unsigned ThreadGroupCountX,
+ __in unsigned ThreadGroupCountY,
+ __in unsigned ThreadGroupCountZ)
+ {
+// uncomment this when this is implemented
+// SYNCHRONIZED;
+// if(update_flags)
+// update_state();
+ }
+
+ virtual void STDMETHODCALLTYPE DispatchIndirect(
+ __in ID3D11Buffer *pBufferForArgs,
+ __in unsigned AlignedByteOffsetForArgs)
+ {
+// uncomment this when this is implemented
+// SYNCHRONIZED;
+// if(update_flags)
+// update_state();
+ }
+#endif
+
+ void set_clip()
+ {
+ SYNCHRONIZED;
+ pipe_clip_state clip;
+ clip.nr = 0;
+ clip.depth_clamp = depth_clamp;
+ pipe->set_clip_state(pipe, &clip);
+ }
+
+ virtual void STDMETHODCALLTYPE RSSetState(
+ __in_opt ID3D11RasterizerState *pRasterizerState)
+ {
+ SYNCHRONIZED;
+ if(pRasterizerState != rasterizer_state.p)
+ {
+ rasterizer_state = pRasterizerState;
+ pipe->bind_rasterizer_state(pipe, pRasterizerState ? ((GalliumD3D11RasterizerState*)pRasterizerState)->object : default_rasterizer);
+ bool new_depth_clamp = pRasterizerState ? ((GalliumD3D11RasterizerState*)pRasterizerState)->depth_clamp : false;
+ if(depth_clamp != new_depth_clamp)
+ {
+ depth_clamp = new_depth_clamp;
+ set_clip();
+ }
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE RSGetState(
+ __out ID3D11RasterizerState **ppRasterizerState)
+ {
+ SYNCHRONIZED;
+ *ppRasterizerState = rasterizer_state.ref();
+ }
+
+ void set_viewport()
+ {
+ // TODO: is depth correct? it seems D3D10/11 uses a [-1,1]x[-1,1]x[0,1] cube
+ pipe_viewport_state viewport;
+ float half_width = viewports[0].Width * 0.5f;
+ float half_height = viewports[0].Height * 0.5f;
+
+ viewport.scale[0] = half_width;
+ viewport.scale[1] = -half_height;
+ viewport.scale[2] = (viewports[0].MaxDepth - viewports[0].MinDepth);
+ viewport.scale[3] = 1.0f;
+ viewport.translate[0] = half_width + viewports[0].TopLeftX;
+ viewport.translate[1] = half_height + viewports[0].TopLeftY;
+ viewport.translate[2] = viewports[0].MinDepth;
+ viewport.translate[3] = 1.0f;
+ pipe->set_viewport_state(pipe, &viewport);
+ }
+
+ virtual void STDMETHODCALLTYPE RSSetViewports(
+ __in_range(0, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE) unsigned NumViewports,
+ __in_ecount_opt(NumViewports) const D3D11_VIEWPORT *pViewports)
+ {
+ SYNCHRONIZED;
+ if(NumViewports)
+ {
+ if(memcmp(&viewports[0], &pViewports[0], sizeof(viewports[0])))
+ {
+ viewports[0] = pViewports[0];
+ set_viewport();
+ }
+ for(unsigned i = 1; i < NumViewports; ++i)
+ viewports[i] = pViewports[i];
+ }
+ else if(num_viewports)
+ {
+ // TODO: what should we do here?
+ memset(&viewports[0], 0, sizeof(viewports[0]));
+ set_viewport();
+ }
+ num_viewports = NumViewports;
+ }
+
+ virtual void STDMETHODCALLTYPE RSGetViewports(
+ __inout_range(0, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE) unsigned *pNumViewports,
+ __out_ecount_opt(*pNumViewports) D3D11_VIEWPORT *pViewports)
+ {
+ SYNCHRONIZED;
+ if(pViewports)
+ {
+ unsigned i;
+ for(i = 0; i < std::min(*pNumViewports, num_viewports); ++i)
+ pViewports[i] = viewports[i];
+
+ memset(pViewports + i, 0, (*pNumViewports - i) * sizeof(D3D11_VIEWPORT));
+ }
+
+ *pNumViewports = num_viewports;
+ }
+
+ void set_scissor()
+ {
+ pipe_scissor_state scissor;
+ scissor.minx = scissor_rects[0].left;
+ scissor.miny = scissor_rects[0].top;
+ scissor.maxx = scissor_rects[0].right;
+ scissor.maxy = scissor_rects[0].bottom;
+ pipe->set_scissor_state(pipe, &scissor);
+ }
+
+ virtual void STDMETHODCALLTYPE RSSetScissorRects(
+ __in_range(0, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE) unsigned NumRects,
+ __in_ecount_opt(NumRects) const D3D11_RECT *pRects)
+ {
+ SYNCHRONIZED;
+ if(NumRects)
+ {
+ if(memcmp(&scissor_rects[0], &pRects[0], sizeof(scissor_rects[0])))
+ {
+ scissor_rects[0] = pRects[0];
+ set_scissor();
+ }
+ for(unsigned i = 1; i < NumRects; ++i)
+ scissor_rects[i] = pRects[i];
+ }
+ else if(num_scissor_rects)
+ {
+ // TODO: what should we do here?
+ memset(&scissor_rects[0], 0, sizeof(scissor_rects[0]));
+ set_scissor();
+ }
+
+ num_scissor_rects = NumRects;
+ }
+
+ virtual void STDMETHODCALLTYPE RSGetScissorRects(
+ __inout_range(0, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE) unsigned *pNumRects,
+ __out_ecount_opt(*pNumRects) D3D11_RECT *pRects)
+ {
+ SYNCHRONIZED;
+ if(pRects)
+ {
+ unsigned i;
+ for(i = 0; i < std::min(*pNumRects, num_scissor_rects); ++i)
+ pRects[i] = scissor_rects[i];
+
+ memset(pRects + i, 0, (*pNumRects - i) * sizeof(D3D11_RECT));
+ }
+
+ *pNumRects = num_scissor_rects;
+ }
+
+ virtual void STDMETHODCALLTYPE OMSetBlendState(
+ __in_opt ID3D11BlendState *pBlendState,
+ __in_opt const float BlendFactor[ 4 ],
+ __in unsigned SampleMask)
+ {
+ SYNCHRONIZED;
+ float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+
+ if(blend_state.p != pBlendState)
+ {
+ pipe->bind_blend_state(pipe, pBlendState ? ((GalliumD3D11BlendState*)pBlendState)->object : default_blend);
+ blend_state = pBlendState;
+ }
+
+ // Windows D3D11 does this, even though it's apparently undocumented
+ if(!BlendFactor)
+ BlendFactor = white;
+
+ if(memcmp(blend_color, BlendFactor, sizeof(blend_color)))
+ {
+ pipe->set_blend_color(pipe, (struct pipe_blend_color*)BlendFactor);
+ memcpy(blend_color, BlendFactor, sizeof(blend_color));
+ }
+
+ if(sample_mask != SampleMask)
+ {
+ pipe->set_sample_mask(pipe, sample_mask);
+ sample_mask = SampleMask;
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE OMGetBlendState(
+ __out_opt ID3D11BlendState **ppBlendState,
+ __out_opt float BlendFactor[ 4 ],
+ __out_opt unsigned *pSampleMask)
+ {
+ SYNCHRONIZED;
+ if(ppBlendState)
+ *ppBlendState = blend_state.ref();
+ if(BlendFactor)
+ memcpy(BlendFactor, blend_color, sizeof(blend_color));
+ if(pSampleMask)
+ *pSampleMask = sample_mask;
+ }
+
+ void set_stencil_ref()
+ {
+ struct pipe_stencil_ref sref;
+ sref.ref_value[0] = stencil_ref;
+ sref.ref_value[1] = stencil_ref;
+ pipe->set_stencil_ref(pipe, &sref);
+ }
+
+ virtual void STDMETHODCALLTYPE OMSetDepthStencilState(
+ __in_opt ID3D11DepthStencilState *pDepthStencilState,
+ __in unsigned StencilRef)
+ {
+ SYNCHRONIZED;
+ if(pDepthStencilState != depth_stencil_state.p)
+ {
+ pipe->bind_depth_stencil_alpha_state(pipe, pDepthStencilState ? ((GalliumD3D11DepthStencilState*)pDepthStencilState)->object : default_depth_stencil);
+ depth_stencil_state = pDepthStencilState;
+ }
+
+ if(StencilRef != stencil_ref)
+ {
+ stencil_ref = StencilRef;
+ set_stencil_ref();
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE OMGetDepthStencilState(
+ __out_opt ID3D11DepthStencilState **ppDepthStencilState,
+ __out_opt unsigned *pStencilRef)
+ {
+ SYNCHRONIZED;
+ if(*ppDepthStencilState)
+ *ppDepthStencilState = depth_stencil_state.ref();
+ if(pStencilRef)
+ *pStencilRef = stencil_ref;
+ }
+
+ void set_framebuffer()
+ {
+ struct pipe_framebuffer_state fb;
+ memset(&fb, 0, sizeof(fb));
+ if(depth_stencil_view)
+ {
+ struct pipe_surface* surf = ((GalliumD3D11DepthStencilView*)depth_stencil_view.p)->object;
+ fb.zsbuf = surf;
+ if(surf->width > fb.width)
+ fb.width = surf->width;
+ if(surf->height > fb.height)
+ fb.height = surf->height;
+ }
+ fb.nr_cbufs = num_render_target_views;
+ unsigned i;
+ for(i = 0; i < num_render_target_views; ++i)
+ {
+ if(render_target_views[i])
+ {
+ struct pipe_surface* surf = ((GalliumD3D11RenderTargetView*)render_target_views[i].p)->object;
+ fb.cbufs[i] = surf;
+ if(surf->width > fb.width)
+ fb.width = surf->width;
+ if(surf->height > fb.height)
+ fb.height = surf->height;
+ }
+ }
+
+ pipe->set_framebuffer_state(pipe, &fb);
+ }
+
+ /* TODO: the docs say that we should unbind conflicting resources (e.g. those bound for read while we are binding them for write too), but we aren't.
+ * Hopefully nobody relies on this happening
+ */
+
+ virtual void STDMETHODCALLTYPE OMSetRenderTargets(
+ __in_range(0, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT) unsigned NumViews,
+ __in_ecount_opt(NumViews) ID3D11RenderTargetView *const *ppRenderTargetViews,
+ __in_opt ID3D11DepthStencilView *pDepthStencilView)
+ {
+ SYNCHRONIZED;
+ if(!ppRenderTargetViews)
+ NumViews = 0;
+ if(NumViews == num_render_target_views)
+ {
+ for(unsigned i = 0; i < NumViews; ++i)
+ {
+ if(ppRenderTargetViews[i] != render_target_views[i].p)
+ goto changed;
+ }
+ return;
+ }
+changed:
+ depth_stencil_view = pDepthStencilView;
+ unsigned i;
+ for(i = 0; i < NumViews; ++i)
+ {
+ render_target_views[i] = ppRenderTargetViews[i];
+#if API >= 11
+ om_unordered_access_views[i] = (ID3D11UnorderedAccessView*)NULL;
+#endif
+ }
+ for(; i < num_render_target_views; ++i)
+ render_target_views[i] = (ID3D11RenderTargetView*)NULL;
+ num_render_target_views = NumViews;
+ set_framebuffer();
+ }
+
+ virtual void STDMETHODCALLTYPE OMGetRenderTargets(
+ __in_range(0, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT) unsigned NumViews,
+ __out_ecount_opt(NumViews) ID3D11RenderTargetView **ppRenderTargetViews,
+ __out_opt ID3D11DepthStencilView **ppDepthStencilView)
+ {
+ SYNCHRONIZED;
+ if(ppRenderTargetViews)
+ {
+ unsigned i;
+ for(i = 0; i < std::min(num_render_target_views, NumViews); ++i)
+ ppRenderTargetViews[i] = render_target_views[i].ref();
+
+ for(; i < NumViews; ++i)
+ ppRenderTargetViews[i] = 0;
+ }
+
+ if(ppDepthStencilView)
+ *ppDepthStencilView = depth_stencil_view.ref();
+ }
+
+#if API >= 11
+ /* TODO: what is this supposed to do _exactly_? are we doing the right thing? */
+ virtual void STDMETHODCALLTYPE OMSetRenderTargetsAndUnorderedAccessViews(
+ __in unsigned NumRTVs,
+ __in_ecount_opt(NumRTVs) ID3D11RenderTargetView *const *ppRenderTargetViews,
+ __in_opt ID3D11DepthStencilView *pDepthStencilView,
+ __in_range(0, D3D11_PS_CS_UAV_REGISTER_COUNT - 1) unsigned UAVStartSlot,
+ __in unsigned NumUAVs,
+ __in_ecount_opt(NumUAVs) ID3D11UnorderedAccessView *const *ppUnorderedAccessViews,
+ __in_ecount_opt(NumUAVs) const unsigned *pUAVInitialCounts)
+ {
+ SYNCHRONIZED;
+ if(NumRTVs != D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL)
+ OMSetRenderTargets(NumRTVs, ppRenderTargetViews, pDepthStencilView);
+
+ if(NumUAVs != D3D11_KEEP_UNORDERED_ACCESS_VIEWS)
+ {
+ for(unsigned i = 0; i < NumUAVs; ++i)
+ {
+ om_unordered_access_views[UAVStartSlot + i] = ppUnorderedAccessViews[i];
+ render_target_views[UAVStartSlot + i] = (ID3D11RenderTargetView*)0;
+ }
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE OMGetRenderTargetsAndUnorderedAccessViews(
+ __in_range(0, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT) unsigned NumRTVs,
+ __out_ecount_opt(NumRTVs) ID3D11RenderTargetView **ppRenderTargetViews,
+ __out_opt ID3D11DepthStencilView **ppDepthStencilView,
+ __in_range(0, D3D11_PS_CS_UAV_REGISTER_COUNT - 1) unsigned UAVStartSlot,
+ __in_range(0, D3D11_PS_CS_UAV_REGISTER_COUNT - UAVStartSlot) unsigned NumUAVs,
+ __out_ecount_opt(NumUAVs) ID3D11UnorderedAccessView **ppUnorderedAccessViews)
+ {
+ SYNCHRONIZED;
+ if(ppRenderTargetViews)
+ OMGetRenderTargets(NumRTVs, ppRenderTargetViews, ppDepthStencilView);
+
+ if(ppUnorderedAccessViews)
+ {
+ for(unsigned i = 0; i < NumUAVs; ++i)
+ ppUnorderedAccessViews[i] = om_unordered_access_views[UAVStartSlot + i].ref();
+ }
+ }
+#endif
+
+ virtual void STDMETHODCALLTYPE SOSetTargets(
+ __in_range(0, D3D11_SO_BUFFER_SLOT_COUNT) unsigned NumBuffers,
+ __in_ecount_opt(NumBuffers) ID3D11Buffer *const *ppSOTargets,
+ __in_ecount_opt(NumBuffers) const unsigned *pOffsets)
+ {
+ SYNCHRONIZED;
+ unsigned i;
+ if(!ppSOTargets)
+ NumBuffers = 0;
+ bool changed = false;
+ for(i = 0; i < NumBuffers; ++i)
+ {
+ ID3D11Buffer* buffer = ppSOTargets[i];
+ if(buffer != so_targets[i].p || pOffsets[i] != so_offsets[i])
+ {
+ so_buffers[i] = buffer ? ((GalliumD3D11Buffer*)buffer)->resource : 0;
+ so_targets[i] = buffer;
+ so_offsets[i] = pOffsets[i];
+ changed = true;
+ }
+ }
+ for(; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
+ {
+ if(so_targets[i].p || so_offsets[i])
+ {
+ changed = true;
+ so_targets[i] = (ID3D11Buffer*)0;
+ so_offsets[i] = 0;
+ }
+ }
+ num_so_targets = NumBuffers;
+
+ if(changed && caps.so)
+ pipe->set_stream_output_buffers(pipe, so_buffers, (int*)so_offsets, num_so_targets);
+ }
+
+ virtual void STDMETHODCALLTYPE SOGetTargets(
+ __in_range(0, D3D11_SO_BUFFER_SLOT_COUNT) unsigned NumBuffers,
+ __out_ecount(NumBuffers) ID3D11Buffer **ppSOTargets
+#if API < 11
+ , __out_ecount(NumBuffers) UINT *pOffsets
+#endif
+ )
+ {
+ SYNCHRONIZED;
+ for(unsigned i = 0; i < NumBuffers; ++i)
+ {
+ ppSOTargets[i] = so_targets[i].ref();
+#if API < 11
+ pOffsets[i] = so_offsets[i];
+#endif
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE Begin(
+ __in ID3D11Asynchronous *pAsync)
+ {
+ SYNCHRONIZED;
+ if(caps.queries)
+ pipe->begin_query(pipe, ((GalliumD3D11Asynchronous<>*)pAsync)->query);
+ }
+
+ virtual void STDMETHODCALLTYPE End(
+ __in ID3D11Asynchronous *pAsync)
+ {
+ SYNCHRONIZED;
+ if(caps.queries)
+ pipe->end_query(pipe, ((GalliumD3D11Asynchronous<>*)pAsync)->query);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetData(
+ __in ID3D11Asynchronous *pAsync,
+ __out_bcount_opt(DataSize) void *pData,
+ __in unsigned DataSize,
+ __in unsigned GetDataFlags)
+ {
+ SYNCHRONIZED;
+ if(!caps.queries)
+ return E_NOTIMPL;
+
+ GalliumD3D11Asynchronous<>* async = (GalliumD3D11Asynchronous<>*)pAsync;
+ void* data = alloca(async->data_size);
+ boolean ret = pipe->get_query_result(pipe, ((GalliumD3D11Asynchronous<>*)pAsync)->query, !(GetDataFlags & D3D11_ASYNC_GETDATA_DONOTFLUSH), data);
+ if(pData)
+ memcpy(pData, data, std::min(async->data_size, DataSize));
+ return ret ? S_OK : S_FALSE;
+ }
+
+ void set_render_condition()
+ {
+ if(caps.render_condition)
+ {
+ if(!render_predicate)
+ pipe->render_condition(pipe, 0, 0);
+ else
+ {
+ GalliumD3D11Predicate* predicate = (GalliumD3D11Predicate*)render_predicate.p;
+ if(!render_predicate_value && predicate->desc.Query == D3D11_QUERY_OCCLUSION_PREDICATE)
+ {
+ unsigned mode = (predicate->desc.MiscFlags & D3D11_QUERY_MISC_PREDICATEHINT) ? PIPE_RENDER_COND_NO_WAIT : PIPE_RENDER_COND_WAIT;
+ pipe->render_condition(pipe, predicate->query, mode);
+ }
+ else
+ {
+ /* TODO: add inverted predication to Gallium*/
+ pipe->render_condition(pipe, 0, 0);
+ }
+ }
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE SetPredication(
+ __in_opt ID3D11Predicate *pPredicate,
+ __in BOOL PredicateValue)
+ {
+ SYNCHRONIZED;
+ if(render_predicate.p != pPredicate || render_predicate_value != PredicateValue)
+ {
+ render_predicate = pPredicate;
+ render_predicate_value = PredicateValue;
+ set_render_condition();
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE GetPredication(
+ __out_opt ID3D11Predicate **ppPredicate,
+ __out_opt BOOL *pPredicateValue)
+ {
+ SYNCHRONIZED;
+ if(ppPredicate)
+ *ppPredicate = render_predicate.ref();
+ if(pPredicateValue)
+ *pPredicateValue = render_predicate_value;
+ }
+
+ static pipe_subresource d3d11_to_pipe_subresource(struct pipe_resource* resource, unsigned subresource)
+ {
+ pipe_subresource sr;
+ if(subresource <= resource->last_level)
+ {
+ sr.level = subresource;
+ sr.face = 0;
+ }
+ else
+ {
+ unsigned levels = resource->last_level + 1;
+ sr.level = subresource % levels;
+ sr.face = subresource / levels;
+ }
+ return sr;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Map(
+ __in ID3D11Resource *pResource,
+ __in unsigned Subresource,
+ __in D3D11_MAP MapType,
+ __in unsigned MapFlags,
+ __out D3D11_MAPPED_SUBRESOURCE *pMappedResource)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)pResource;
+ if(resource->transfers.count(Subresource))
+ return E_FAIL;
+ pipe_subresource sr = d3d11_to_pipe_subresource(resource->resource, Subresource);
+ pipe_box box;
+ d3d11_to_pipe_box(resource->resource, sr.level, 0);
+ unsigned usage = 0;
+ if(MapType == D3D11_MAP_READ)
+ usage = PIPE_TRANSFER_READ;
+ else if(MapType == D3D11_MAP_WRITE)
+ usage = PIPE_TRANSFER_WRITE;
+ else if(MapType == D3D11_MAP_READ_WRITE)
+ usage = PIPE_TRANSFER_READ_WRITE;
+ else if(MapType == D3D11_MAP_WRITE_DISCARD)
+ usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD;
+ else if(MapType == D3D11_MAP_WRITE_NO_OVERWRITE)
+ usage = PIPE_TRANSFER_WRITE | PIPE_TRANSFER_NOOVERWRITE;
+ else
+ return E_INVALIDARG;
+ if(MapType & D3D10_MAP_FLAG_DO_NOT_WAIT)
+ usage |= PIPE_TRANSFER_DONTBLOCK;
+ struct pipe_transfer* transfer = pipe->get_transfer(pipe, resource->resource, sr, usage, &box);
+ if(!transfer) {
+ if(MapType & D3D10_MAP_FLAG_DO_NOT_WAIT)
+ return DXGI_ERROR_WAS_STILL_DRAWING;
+ else
+ return E_FAIL;
+ }
+ resource->transfers[Subresource] = transfer;
+ pipe->transfer_map(pipe, transfer);
+ pMappedResource->pData = transfer->data;
+ pMappedResource->RowPitch = transfer->stride;
+ pMappedResource->DepthPitch = transfer->slice_stride;
+ return S_OK;
+ }
+
+ virtual void STDMETHODCALLTYPE Unmap(
+ __in ID3D11Resource *pResource,
+ __in unsigned Subresource)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)pResource;
+ std::unordered_map<unsigned, pipe_transfer*>::iterator i = resource->transfers.find(Subresource);
+ if(i != resource->transfers.end())
+ {
+ pipe->transfer_unmap(pipe, i->second);
+ pipe->transfer_destroy(pipe, i->second);
+ resource->transfers.erase(i);
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE CopySubresourceRegion(
+ __in ID3D11Resource *pDstResource,
+ __in unsigned DstSubresource,
+ __in unsigned DstX,
+ __in unsigned DstY,
+ __in unsigned DstZ,
+ __in ID3D11Resource *pSrcResource,
+ __in unsigned SrcSubresource,
+ __in_opt const D3D11_BOX *pSrcBox)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)pDstResource;
+ GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)pSrcResource;
+ pipe_subresource subdst = d3d11_to_pipe_subresource(dst->resource, DstSubresource);
+ pipe_subresource subsrc = d3d11_to_pipe_subresource(src->resource, SrcSubresource);
+ pipe_box box = d3d11_to_pipe_box(src->resource, subsrc.level, pSrcBox);
+ for(unsigned i = 0; i < box.depth; ++i)
+ {
+ pipe->resource_copy_region(pipe,
+ dst->resource, subdst, DstX, DstY, DstZ + i,
+ src->resource, subsrc, box.x, box.y, box.z + i,
+ box.width, box.height);
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE CopyResource(
+ __in ID3D11Resource *pDstResource,
+ __in ID3D11Resource *pSrcResource)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)pDstResource;
+ GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)pSrcResource;
+ pipe_subresource sr;
+ unsigned faces = dst->resource->target == PIPE_TEXTURE_CUBE ? 6 : 1;
+
+ for(sr.face = 0; sr.face < faces; ++sr.face)
+ {
+ for(sr.level = 0; sr.level <= dst->resource->last_level; ++sr.level)
+ {
+ unsigned w = u_minify(dst->resource->width0, sr.level);
+ unsigned h = u_minify(dst->resource->height0, sr.level);
+ unsigned d = u_minify(dst->resource->depth0, sr.level);
+ for(unsigned i = 0; i < d; ++i)
+ {
+ pipe->resource_copy_region(pipe,
+ dst->resource, sr, 0, 0, i,
+ src->resource, sr, 0, 0, i,
+ w, h);
+ }
+ }
+ }
+ }
+
+ virtual void STDMETHODCALLTYPE UpdateSubresource(
+ __in ID3D11Resource *pDstResource,
+ __in unsigned DstSubresource,
+ __in_opt const D3D11_BOX *pDstBox,
+ __in const void *pSrcData,
+ __in unsigned SrcRowPitch,
+ __in unsigned SrcDepthPitch)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)pDstResource;
+ pipe_subresource subdst = d3d11_to_pipe_subresource(dst->resource, DstSubresource);
+ pipe_box box = d3d11_to_pipe_box(dst->resource, subdst.level, pDstBox);
+ pipe->transfer_inline_write(pipe, dst->resource, subdst, PIPE_TRANSFER_WRITE, &box, pSrcData, SrcRowPitch, SrcDepthPitch);
+ }
+
+#if API >= 11
+ virtual void STDMETHODCALLTYPE CopyStructureCount(
+ __in ID3D11Buffer *pDstBuffer,
+ __in unsigned DstAlignedByteOffset,
+ __in ID3D11UnorderedAccessView *pSrcView)
+ {
+ SYNCHRONIZED;
+ }
+#endif
+
+ virtual void STDMETHODCALLTYPE ClearRenderTargetView(
+ __in ID3D11RenderTargetView *pRenderTargetView,
+ __in const float ColorRGBA[4])
+ {
+ SYNCHRONIZED;
+ GalliumD3D11RenderTargetView* view = ((GalliumD3D11RenderTargetView*)pRenderTargetView);
+ pipe->clear_render_target(pipe, view->object, ColorRGBA, 0, 0, view->object->width, view->object->height);
+ }
+
+ virtual void STDMETHODCALLTYPE ClearDepthStencilView(
+ __in ID3D11DepthStencilView *pDepthStencilView,
+ __in unsigned ClearFlags,
+ __in float Depth,
+ __in UINT8 Stencil)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11DepthStencilView* view = ((GalliumD3D11DepthStencilView*)pDepthStencilView);
+ unsigned flags = 0;
+ if(ClearFlags & D3D11_CLEAR_DEPTH)
+ flags |= PIPE_CLEAR_DEPTH;
+ if(ClearFlags & D3D11_CLEAR_STENCIL)
+ flags |= PIPE_CLEAR_STENCIL;
+ pipe->clear_depth_stencil(pipe, view->object, flags, Depth, Stencil, 0, 0, view->object->width, view->object->height);
+ }
+
+#if API >= 11
+ virtual void STDMETHODCALLTYPE ClearUnorderedAccessViewUint(
+ __in ID3D11UnorderedAccessView *pUnorderedAccessView,
+ __in const unsigned Values[ 4 ])
+ {
+ SYNCHRONIZED;
+ }
+
+ virtual void STDMETHODCALLTYPE ClearUnorderedAccessViewFloat(
+ __in ID3D11UnorderedAccessView *pUnorderedAccessView,
+ __in const float Values[ 4 ])
+ {
+ SYNCHRONIZED;
+ }
+#endif
+
+ virtual void STDMETHODCALLTYPE RestoreGalliumStateBlitOnly()
+ {
+ pipe->bind_blend_state(pipe, blend_state.p ? blend_state.p->object : default_blend);
+ pipe->bind_depth_stencil_alpha_state(pipe, depth_stencil_state.p ? depth_stencil_state.p->object : default_depth_stencil);
+ pipe->bind_rasterizer_state(pipe, rasterizer_state.p ? rasterizer_state.p->object : default_rasterizer);
+ pipe->bind_vertex_elements_state(pipe, input_layout.p ? input_layout.p->object : default_input_layout);
+ pipe->bind_fs_state(pipe, shaders[D3D11_STAGE_PS].p ? shaders[D3D11_STAGE_PS].p->object : default_shaders[PIPE_SHADER_FRAGMENT]);
+ pipe->bind_vs_state(pipe, shaders[D3D11_STAGE_VS].p ? shaders[D3D11_STAGE_VS].p->object : default_shaders[PIPE_SHADER_VERTEX]);
+ if(caps.gs)
+ pipe->bind_gs_state(pipe, shaders[D3D11_STAGE_GS].p ? shaders[D3D11_STAGE_GS].p->object : default_shaders[PIPE_SHADER_GEOMETRY]);
+ set_framebuffer();
+ set_viewport();
+ set_clip();
+ set_render_condition();
+ // TODO: restore stream output
+
+ update_flags |= UPDATE_VERTEX_BUFFERS | (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_PS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_PS));
+ }
+
+ virtual void STDMETHODCALLTYPE GenerateMips(
+ __in ID3D11ShaderResourceView *pShaderResourceView)
+ {
+ SYNCHRONIZED;
+
+ GalliumD3D11ShaderResourceView* view = (GalliumD3D11ShaderResourceView*)pShaderResourceView;
+ if(caps.gs)
+ pipe->bind_gs_state(pipe, 0);
+ if(caps.so)
+ pipe->bind_stream_output_state(pipe, 0);
+ if(pipe->render_condition)
+ pipe->render_condition(pipe, 0, 0);
+ util_gen_mipmap(gen_mipmap, view->object, 0, 0, view->object->texture->last_level, PIPE_TEX_FILTER_LINEAR);
+ RestoreGalliumStateBlitOnly();
+ }
+
+ virtual void STDMETHODCALLTYPE RestoreGalliumState()
+ {
+ SYNCHRONIZED;
+ RestoreGalliumStateBlitOnly();
+
+ set_index_buffer();
+ set_stencil_ref();
+ pipe->set_blend_color(pipe, (struct pipe_blend_color*)blend_color);
+ pipe->set_sample_mask(pipe, sample_mask);
+
+ for(unsigned s = 0; s < 3; ++s)
+ {
+ unsigned num = std::min(caps.constant_buffers[s], (unsigned)D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
+ for(unsigned i = 0; i < num; ++i)
+ pipe->set_constant_buffer(pipe, s, i, constant_buffers[s][i].p ? constant_buffers[s][i].p->resource : 0);
+ }
+
+ if(caps.so)
+ pipe->set_stream_output_buffers(pipe, so_buffers, (int*)so_offsets, num_so_targets);
+
+ update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_VS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_VS));
+ update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + D3D11_STAGE_GS)) | (1 << (UPDATE_VIEWS_SHIFT + D3D11_STAGE_GS));
+
+ set_scissor();
+ }
+
+#if API >= 11
+ /* TODO: hack SRVs or sampler states to handle this, or add to Gallium */
+ virtual void STDMETHODCALLTYPE SetResourceMinLOD(
+ __in ID3D11Resource *pResource,
+ float MinLOD)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)pResource;
+ if(resource->min_lod != MinLOD)
+ {
+ // TODO: actually do anything?
+ resource->min_lod = MinLOD;
+ }
+ }
+
+ virtual float STDMETHODCALLTYPE GetResourceMinLOD(
+ __in ID3D11Resource *pResource)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* resource = (GalliumD3D11Resource<>*)pResource;
+ return resource->min_lod;
+ }
+#endif
+
+ virtual void STDMETHODCALLTYPE ResolveSubresource(
+ __in ID3D11Resource *pDstResource,
+ __in unsigned DstSubresource,
+ __in ID3D11Resource *pSrcResource,
+ __in unsigned SrcSubresource,
+ __in DXGI_FORMAT Format)
+ {
+ SYNCHRONIZED;
+ GalliumD3D11Resource<>* dst = (GalliumD3D11Resource<>*)pDstResource;
+ GalliumD3D11Resource<>* src = (GalliumD3D11Resource<>*)pSrcResource;
+ pipe_subresource subdst = d3d11_to_pipe_subresource(dst->resource, DstSubresource);
+ pipe_subresource subsrc = d3d11_to_pipe_subresource(src->resource, SrcSubresource);
+ pipe->resource_resolve(pipe, dst->resource, subdst, src->resource, subsrc);
+ }
+
+#if API >= 11
+ virtual void STDMETHODCALLTYPE ExecuteCommandList(
+ __in ID3D11CommandList *pCommandList,
+ BOOL RestoreContextState)
+ {
+ SYNCHRONIZED;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE FinishCommandList(
+ BOOL RestoreDeferredContextState,
+ __out_opt ID3D11CommandList **ppCommandList)
+ {
+ SYNCHRONIZED;
+ return E_NOTIMPL;
+ }
+#endif
+
+ virtual void STDMETHODCALLTYPE ClearState(void)
+ {
+ SYNCHRONIZED;
+
+ // we qualify all calls so that we avoid virtual dispatch and might get them inlined
+ // TODO: make sure all this gets inlined, which might require more compiler flags
+ // TODO: optimize this
+#if API >= 11
+ GalliumD3D11DeviceContext::PSSetShader(0, 0, 0);
+ GalliumD3D11DeviceContext::GSSetShader(0, 0, 0);
+ GalliumD3D11DeviceContext::VSSetShader(0, 0, 0);
+ GalliumD3D11DeviceContext::HSSetShader(0, 0, 0);
+ GalliumD3D11DeviceContext::DSSetShader(0, 0, 0);
+ GalliumD3D11DeviceContext::CSSetShader(0, 0, 0);
+#else
+ GalliumD3D11DeviceContext::PSSetShader(0);
+ GalliumD3D11DeviceContext::GSSetShader(0);
+ GalliumD3D11DeviceContext::VSSetShader(0);
+#endif
+
+ GalliumD3D11DeviceContext::IASetInputLayout(0);
+ GalliumD3D11DeviceContext::IASetIndexBuffer(0, DXGI_FORMAT_UNKNOWN, 0);
+ GalliumD3D11DeviceContext::RSSetState(0);
+ GalliumD3D11DeviceContext::OMSetDepthStencilState(0, 0);
+ GalliumD3D11DeviceContext::OMSetBlendState(0, (float*)zero_data, ~0);
+ GalliumD3D11DeviceContext::SetPredication(0, 0);
+ GalliumD3D11DeviceContext::IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_UNDEFINED);
+
+ GalliumD3D11DeviceContext::PSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data);
+ GalliumD3D11DeviceContext::GSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data);
+ GalliumD3D11DeviceContext::VSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data);
+#if API >= 11
+ GalliumD3D11DeviceContext::HSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data);
+ GalliumD3D11DeviceContext::DSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data);
+ GalliumD3D11DeviceContext::CSSetConstantBuffers(0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, (ID3D11Buffer**)zero_data);
+#endif
+
+ GalliumD3D11DeviceContext::IASetVertexBuffers(0, num_vertex_buffers, (ID3D11Buffer**)zero_data, (unsigned*)zero_data, (unsigned*)zero_data);
+#if API >= 11
+ GalliumD3D11DeviceContext::OMSetRenderTargetsAndUnorderedAccessViews(0, 0, 0 , 0, 0, 0, 0);
+#else
+ GalliumD3D11DeviceContext::OMSetRenderTargets(0, 0, 0 );
+#endif
+ GalliumD3D11DeviceContext::SOSetTargets(0, 0, 0);
+
+ GalliumD3D11DeviceContext::PSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_PS], (ID3D11ShaderResourceView**)zero_data);
+ GalliumD3D11DeviceContext::GSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_GS], (ID3D11ShaderResourceView**)zero_data);
+ GalliumD3D11DeviceContext::VSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_VS], (ID3D11ShaderResourceView**)zero_data);
+#if API >= 11
+ GalliumD3D11DeviceContext::HSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_HS], (ID3D11ShaderResourceView**)zero_data);
+ GalliumD3D11DeviceContext::DSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_DS], (ID3D11ShaderResourceView**)zero_data);
+ GalliumD3D11DeviceContext::CSSetShaderResources(0, num_shader_resource_views[D3D11_STAGE_CS], (ID3D11ShaderResourceView**)zero_data);
+#endif
+
+ GalliumD3D11DeviceContext::PSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_PS], (ID3D11SamplerState**)zero_data);
+ GalliumD3D11DeviceContext::GSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_GS], (ID3D11SamplerState**)zero_data);
+ GalliumD3D11DeviceContext::VSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_VS], (ID3D11SamplerState**)zero_data);
+#if API >= 11
+ GalliumD3D11DeviceContext::HSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_HS], (ID3D11SamplerState**)zero_data);
+ GalliumD3D11DeviceContext::DSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_DS], (ID3D11SamplerState**)zero_data);
+ GalliumD3D11DeviceContext::CSSetSamplers(0, num_shader_resource_views[D3D11_STAGE_CS], (ID3D11SamplerState**)zero_data);
+#endif
+
+ GalliumD3D11DeviceContext::RSSetViewports(0, 0);
+ GalliumD3D11DeviceContext::RSSetScissorRects(0, 0);
+ }
+
+ virtual void STDMETHODCALLTYPE Flush(void)
+ {
+ SYNCHRONIZED;
+ pipe->flush(pipe, PIPE_FLUSH_FRAME, 0);
+ }
+
+ /* In Direct3D 10, if the reference count of an object drops to 0, it is automatically
+ * cleanly unbound from the pipeline.
+ * In Direct3D 11, the pipeline holds a reference.
+ *
+ * Note that instead of always scanning the pipeline on destruction, we could
+ * maintain the internal reference count on DirectX 10 and use it to check if an
+ * object is still bound.
+ * Presumably, on average, scanning is faster if the application is well written.
+ */
+#if API < 11
+#define IMPLEMENT_SIMPLE_UNBIND(name, member, gallium, def) \
+ void Unbind##name(ID3D11##name* state) \
+ { \
+ SYNCHRONIZED; \
+ if((void*)state == (void*)member.p) \
+ { \
+ member.p = 0; \
+ pipe->bind_##gallium##_state(pipe, default_##def); \
+ } \
+ }
+ IMPLEMENT_SIMPLE_UNBIND(BlendState, blend_state, blend, blend)
+ IMPLEMENT_SIMPLE_UNBIND(RasterizerState, rasterizer_state, rasterizer, rasterizer)
+ IMPLEMENT_SIMPLE_UNBIND(DepthStencilState, depth_stencil_state, depth_stencil_alpha, depth_stencil)
+ IMPLEMENT_SIMPLE_UNBIND(InputLayout, input_layout, vertex_elements, input_layout)
+ IMPLEMENT_SIMPLE_UNBIND(PixelShader, shaders[D3D11_STAGE_PS], fs, shaders[D3D11_STAGE_PS])
+ IMPLEMENT_SIMPLE_UNBIND(VertexShader, shaders[D3D11_STAGE_VS], vs, shaders[D3D11_STAGE_VS])
+ IMPLEMENT_SIMPLE_UNBIND(GeometryShader, shaders[D3D11_STAGE_GS], gs, shaders[D3D11_STAGE_GS])
+
+ void UnbindPredicate(ID3D11Predicate* predicate)
+ {
+ SYNCHRONIZED;
+ if(predicate == render_predicate)
+ {
+ render_predicate.p = NULL;
+ render_predicate_value = 0;
+ pipe->render_condition(pipe, 0, 0);
+ }
+ }
+
+ void UnbindSamplerState(ID3D11SamplerState* state)
+ {
+ SYNCHRONIZED;
+ for(unsigned s = 0; s < D3D11_STAGES; ++s)
+ {
+ for(unsigned i = 0; i < num_samplers[s]; ++i)
+ {
+ if(samplers[s][i] == state)
+ {
+ samplers[s][i].p = NULL;
+ sampler_csos[s].v[i] = NULL;
+ update_flags |= (1 << (UPDATE_SAMPLERS_SHIFT + s));
+ }
+ }
+ }
+ }
+
+ void UnbindBuffer(ID3D11Buffer* buffer)
+ {
+ SYNCHRONIZED;
+ if(buffer == index_buffer)
+ {
+ index_buffer.p = 0;
+ index_format = DXGI_FORMAT_UNKNOWN;
+ index_offset = 0;
+ struct pipe_index_buffer ib;
+ memset(&ib, 0, sizeof(ib));
+ pipe->set_index_buffer(pipe, &ib);
+ }
+
+ for(unsigned i = 0; i < num_vertex_buffers; ++i)
+ {
+ if(buffer == input_buffers[i])
+ {
+ input_buffers[i].p = 0;
+ memset(&vertex_buffers[num_vertex_buffers], 0, sizeof(vertex_buffers[num_vertex_buffers]));
+ update_flags |= UPDATE_VERTEX_BUFFERS;
+ }
+ }
+
+ for(unsigned s = 0; s < D3D11_STAGES; ++s)
+ {
+ for(unsigned i = 0; i < sizeof(constant_buffers) / sizeof(constant_buffers[0]); ++i)
+ {
+ if(constant_buffers[s][i] == buffer)
+ {
+ constant_buffers[s][i] = (ID3D10Buffer*)NULL;
+ pipe->set_constant_buffer(pipe, s, i, NULL);
+ }
+ }
+ }
+ }
+
+ void UnbindDepthStencilView(ID3D11DepthStencilView* view)
+ {
+ SYNCHRONIZED;
+ if(view == depth_stencil_view)
+ {
+ depth_stencil_view.p = NULL;
+ set_framebuffer();
+ }
+ }
+
+ void UnbindRenderTargetView(ID3D11RenderTargetView* view)
+ {
+ SYNCHRONIZED;
+ bool any_bound = false;
+ for(unsigned i = 0; i < num_render_target_views; ++i)
+ {
+ if(render_target_views[i] == view)
+ {
+ render_target_views[i].p = NULL;
+ any_bound = true;
+ }
+ }
+ if(any_bound)
+ set_framebuffer();
+ }
+
+ void UnbindShaderResourceView(ID3D11ShaderResourceView* view)
+ {
+ SYNCHRONIZED;
+ for(unsigned s = 0; s < D3D11_STAGES; ++s)
+ {
+ for(unsigned i = 0; i < num_shader_resource_views[s]; ++i)
+ {
+ if(shader_resource_views[s][i] == view)
+ {
+ shader_resource_views[s][i].p = NULL;
+ sampler_views[s][i] = NULL;
+ update_flags |= (1 << (UPDATE_VIEWS_SHIFT + s));
+ }
+ }
+ }
+ }
+#endif
+
+#undef SYNCHRONIZED
+};
+
+#if API >= 11
+/* This approach serves two purposes.
+ * First, we don't want to do an atomic operation to manipulate the reference
+ * count every time something is bound/unbound to the pipeline, since they are
+ * expensive.
+ * Fortunately, the immediate context can only be used by a single thread, so
+ * we don't have to use them, as long as a separate reference count is used
+ * (see dual_refcnt_t).
+ *
+ * Second, we want to avoid the Device -> DeviceContext -> bound DeviceChild -> Device
+ * garbage cycle.
+ * To avoid it, DeviceChild doesn't hold a reference to Device as usual, but adds
+ * one for each external reference count, while internal nonatomic_add_ref doesn't
+ * add any.
+ *
+ * Note that ideally we would to eliminate the non-atomic op too, but this is more
+ * complicated, since we would either need to use garbage collection and give up
+ * deterministic destruction (especially bad for large textures), or scan the whole
+ * pipeline state every time the reference count of object drops to 0, which risks
+ * pathological slowdowns.
+ *
+ * Since this microoptimization should matter relatively little, let's avoid it for now.
+ *
+ * Note that deferred contexts don't use this, since as a whole, they must thread-safe.
+ * Eliminating the atomic ops for deferred contexts seems substantially harder.
+ * This might be a problem if they are used in a one-shot multithreaded rendering
+ * fashion, where SMP cacheline bouncing on the reference count may be visible.
+ *
+ * The idea would be to attach a structure of reference counts indexed by deferred
+ * context id to each object. Ideally, this should be organized like ext2 block pointers.
+ *
+ * Every deferred context would get a reference count in its own cacheline.
+ * The external count is protected by a lock bit, and there is also a "lock bit" in each
+ * internal count.
+ *
+ * When the external count has to be dropped to 0, the lock bit is taken and all internal
+ * reference counts are scanned, taking a count of them. A flag would also be set on them.
+ * Deferred context manipulation would notice the flag, and update the count.
+ * Once the count goes to zero, the object is freed.
+ *
+ * The problem of this is that if the external reference count ping-pongs between
+ * zero and non-zero, the scans will take a lot of time.
+ *
+ * The idea to solve this is to compute the scans in a binary-tree like fashion, where
+ * each binary tree node would have a "determined bit", which would be invalidated
+ * by manipulations.
+ *
+ * However, all this complexity might actually be a loss in most cases, so let's just
+ * stick to a single atomic refcnt for now.
+ *
+ * Also, we don't even support deferred contexts yet, so this can wait.
+ */
+struct nonatomic_device_child_ptr_traits
+{
+ static void add_ref(void* p)
+ {
+ if(p)
+ ((GalliumD3D11DeviceChild<>*)p)->nonatomic_add_ref();
+ }
+
+ static void release(void* p)
+ {
+ if(p)
+ ((GalliumD3D11DeviceChild<>*)p)->nonatomic_release();
+ }
+};
+
+struct GalliumD3D11ImmediateDeviceContext
+ : public GalliumD3D11DeviceContext<nonatomic_device_child_ptr_traits>
+{
+ GalliumD3D11ImmediateDeviceContext(GalliumD3D11Screen* device, pipe_context* pipe, unsigned context_flags = 0)
+ : GalliumD3D11DeviceContext(device, pipe, context_flags)
+ {
+ // not necessary, but tests that the API at least basically works
+ ClearState();
+ }
+
+ /* we do this since otherwise we would have a garbage cycle between this and the device */
+ virtual ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return this->device->AddRef();
+ }
+
+ virtual ULONG STDMETHODCALLTYPE Release()
+ {
+ return this->device->Release();
+ }
+
+ virtual D3D11_DEVICE_CONTEXT_TYPE STDMETHODCALLTYPE GetType()
+ {
+ return D3D11_DEVICE_CONTEXT_IMMEDIATE;
+ }
+};
+
+static ID3D11DeviceContext* GalliumD3D11ImmediateDeviceContext_Create(GalliumD3D11Screen* device, struct pipe_context* pipe, bool owns_pipe)
+{
+ return new GalliumD3D11ImmediateDeviceContext(device, pipe, owns_pipe);
+}
+
+static void GalliumD3D11ImmediateDeviceContext_RestoreGalliumState(ID3D11DeviceContext* context)
+{
+ ((GalliumD3D11ImmediateDeviceContext*)context)->RestoreGalliumState();
+}
+
+static void GalliumD3D11ImmediateDeviceContext_RestoreGalliumStateBlitOnly(ID3D11DeviceContext* context)
+{
+ ((GalliumD3D11ImmediateDeviceContext*)context)->RestoreGalliumStateBlitOnly();
+}
+
+static void GalliumD3D11ImmediateDeviceContext_Destroy(ID3D11DeviceContext* context)
+{
+ delete (GalliumD3D11ImmediateDeviceContext*)context;
+}
+#endif
diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_objects.h b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_objects.h
new file mode 100644
index 0000000..ad6b28f
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_objects.h
@@ -0,0 +1,715 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+template<typename Base = ID3D11DeviceChild>
+struct GalliumD3D11DeviceChild : public GalliumPrivateDataComObject<Base, dual_refcnt_t>
+{
+ GalliumD3D11Screen* device; // must not be null
+
+
+ // if this is called, the subclass constructor must set device itself
+ GalliumD3D11DeviceChild()
+ : device(0)
+ {}
+
+ GalliumD3D11DeviceChild(GalliumD3D11Screen* p_device)
+ {
+ // we store the reference count minus one in refcnt
+ device = p_device;
+ device->AddRef();
+ }
+
+ /* The purpose of this is to avoid cyclic garbage, since this won't hold
+ * a pointer to the device if it is only held by a pipeline binding in the immediate context
+ *
+ * TODO: we could only manipulate the device refcnt when atomic_refcnt == 0 changes,
+ * but this requires more complex atomic ops
+ */
+ inline ULONG add_ref()
+ {
+ device->AddRef();
+ return GalliumPrivateDataComObject<Base, dual_refcnt_t>::add_ref();
+ }
+
+ inline ULONG release()
+ {
+ device->Release();
+ return GalliumPrivateDataComObject<Base, dual_refcnt_t>::release();
+ }
+
+ virtual ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return add_ref();
+ }
+
+ virtual ULONG STDMETHODCALLTYPE Release()
+ {
+ return release();
+ }
+
+ virtual void STDMETHODCALLTYPE GetDevice(
+ __out ID3D11Device **ppDevice
+ )
+ {
+ device->AddRef();
+ *ppDevice = device;
+ }
+};
+
+template<typename Base = ID3D11DeviceChild, typename Object = void>
+struct GalliumD3D11Object : public GalliumD3D11DeviceChild<Base>
+{
+ Object* object;
+ GalliumD3D11Object(GalliumD3D11Screen* device, Object* object)
+ : GalliumD3D11DeviceChild<Base>(device), object(object)
+ {}
+
+ virtual ~GalliumD3D11Object();
+};
+
+#define IMPLEMENT_OBJECT_DTOR(name, gallium) \
+template<> \
+GalliumD3D11Object<ID3D11##name, void>::~GalliumD3D11Object() \
+{ \
+ DX10_ONLY(device->Unbind##name(this)); \
+ device->immediate_pipe->delete_##gallium##_state(device->immediate_pipe, object); \
+}
+
+#define IMPLEMENT_VIEW_DTOR(name, gallium) \
+template<> \
+GalliumD3D11Object<ID3D11##name, struct pipe_##gallium>::~GalliumD3D11Object() \
+{ \
+ DX10_ONLY(device->Unbind##name(this)); \
+ pipe_##gallium##_reference(&object, 0); \
+}
+
+IMPLEMENT_OBJECT_DTOR(InputLayout, vertex_elements)
+IMPLEMENT_OBJECT_DTOR(DepthStencilState, depth_stencil_alpha)
+IMPLEMENT_OBJECT_DTOR(RasterizerState, rasterizer)
+IMPLEMENT_OBJECT_DTOR(SamplerState, sampler)
+IMPLEMENT_OBJECT_DTOR(BlendState, blend)
+IMPLEMENT_OBJECT_DTOR(VertexShader, vs)
+IMPLEMENT_OBJECT_DTOR(PixelShader, fs)
+IMPLEMENT_OBJECT_DTOR(GeometryShader, gs)
+
+IMPLEMENT_VIEW_DTOR(ShaderResourceView, sampler_view)
+IMPLEMENT_VIEW_DTOR(RenderTargetView, surface)
+IMPLEMENT_VIEW_DTOR(DepthStencilView, surface)
+
+#if API >= 11
+// IMPLEMENT_VIEW_DTOR(UnorderedAccessView, surface);
+// IMPLEMENT_OBJECT_DTOR(HullShader, tcs);
+// IMPLEMENT_OBJECT_DTOR(DomainShader, tes);
+// IMPLEMENT_OBJECT_DTOR(ComputeShader, cs);
+#else
+IMPLEMENT_OBJECT_DTOR(BlendState1, blend)
+IMPLEMENT_VIEW_DTOR(ShaderResourceView1, sampler_view)
+#endif
+
+template<typename Base, typename Desc, typename Object = void>
+struct GalliumD3D11DescribedObject : public GalliumD3D11Object<Base, Object>
+{
+ Desc desc;
+ GalliumD3D11DescribedObject(GalliumD3D11Screen* device, Object* object, const Desc& desc)
+ : GalliumD3D11Object<Base, Object>(device, object), desc(desc)
+ {}
+
+ virtual void STDMETHODCALLTYPE GetDesc(Desc *pDesc)
+ {
+ memcpy(pDesc, &desc, sizeof(desc));
+ }
+};
+
+typedef GalliumD3D11Object<ID3D11InputLayout> GalliumD3D11InputLayout;
+typedef GalliumD3D11DescribedObject<ID3D11DepthStencilState, D3D11_DEPTH_STENCIL_DESC> GalliumD3D11DepthStencilState;
+typedef GalliumD3D11DescribedObject<ID3D11RasterizerState, D3D11_RASTERIZER_DESC> GalliumD3D11RasterizerStateBase;
+typedef GalliumD3D11DescribedObject<ID3D11SamplerState, D3D11_SAMPLER_DESC> GalliumD3D11SamplerState;
+
+#if API >= 11
+typedef GalliumD3D11DescribedObject<ID3D11BlendState, D3D11_BLEND_DESC> GalliumD3D11BlendState;
+#else
+typedef GalliumD3D10DescribedObject<ID3D10BlendState1, D3D10_BLEND_DESC> GalliumD3D10BlendStateBase;
+
+struct GalliumD3D10BlendState : public GalliumD3D10BlendStateBase
+{
+ static D3D10_BLEND_DESC convert_to_d3d10(const D3D10_BLEND_DESC1& desc1)
+ {
+ D3D10_BLEND_DESC desc;
+ desc.AlphaToCoverageEnable = desc1.AlphaToCoverageEnable;
+ desc.SrcBlend = desc1.RenderTarget[0].SrcBlend;
+ desc.DestBlend = desc1.RenderTarget[0].DestBlend;
+ desc.BlendOp = desc1.RenderTarget[0].BlendOp;
+ desc.SrcBlendAlpha = desc1.RenderTarget[0].SrcBlendAlpha;
+ desc.DestBlendAlpha = desc1.RenderTarget[0].DestBlendAlpha;
+ desc.BlendOpAlpha = desc1.RenderTarget[0].BlendOpAlpha;
+ for(unsigned i = 0; i < 8; ++i)
+ {
+ desc.BlendEnable[i] = desc1.RenderTarget[i].BlendEnable;
+ desc.RenderTargetWriteMask[i] = desc1.RenderTarget[i].RenderTargetWriteMask;
+ }
+ return desc;
+ }
+
+ D3D10_BLEND_DESC1 desc1;
+
+ GalliumD3D10BlendState(GalliumD3D10Screen* device, void* object, const D3D10_BLEND_DESC& desc)
+ : GalliumD3D10BlendStateBase(device, object, desc)
+ {
+ memset(&desc1, 0, sizeof(desc1));
+ desc1.AlphaToCoverageEnable = desc.AlphaToCoverageEnable;
+ desc1.RenderTarget[0].SrcBlend = desc.SrcBlend;
+ desc1.RenderTarget[0].DestBlend = desc.DestBlend;
+ desc1.RenderTarget[0].BlendOp = desc.BlendOp;
+ desc1.RenderTarget[0].SrcBlendAlpha = desc.SrcBlendAlpha;
+ desc1.RenderTarget[0].DestBlendAlpha = desc.DestBlendAlpha;
+ desc1.RenderTarget[0].BlendOpAlpha = desc.BlendOpAlpha;
+ for(unsigned i = 0; i < 8; ++i)
+ {
+ desc1.RenderTarget[i].BlendEnable = desc.BlendEnable[i];
+ desc1.RenderTarget[i].RenderTargetWriteMask = desc.RenderTargetWriteMask[i];
+ }
+ }
+
+ GalliumD3D10BlendState(GalliumD3D10Screen* device, void* object, const D3D10_BLEND_DESC1& desc)
+ : GalliumD3D10BlendStateBase(device, object, convert_to_d3d10(desc)), desc1(desc1)
+ {}
+
+ virtual void STDMETHODCALLTYPE GetDesc1(D3D10_BLEND_DESC1 *pDesc)
+ {
+ memcpy(pDesc, &desc1, sizeof(desc1));
+ }
+};
+#endif
+
+struct GalliumD3D11RasterizerState : public GalliumD3D11RasterizerStateBase
+{
+ bool depth_clamp;
+
+ GalliumD3D11RasterizerState(GalliumD3D11Screen* device, void* object, const D3D11_RASTERIZER_DESC& desc, bool depth_clamp)
+ : GalliumD3D11RasterizerStateBase(device, object, desc), depth_clamp(depth_clamp)
+ {}
+};
+
+template<typename Base = ID3D11DeviceChild>
+struct GalliumD3D11Shader : public GalliumD3D11Object<Base>
+{
+ std::vector<int> slot_to_resource;
+ std::vector<int> slot_to_sampler;
+
+ GalliumD3D11Shader(GalliumD3D11Screen* device, void* object)
+ : GalliumD3D11Object<Base>(device, object)
+ {}
+};
+
+typedef GalliumD3D11Shader<ID3D11VertexShader> GalliumD3D11VertexShader;
+typedef GalliumD3D11Shader<ID3D11GeometryShader> GalliumD3D11GeometryShader;
+typedef GalliumD3D11Shader<ID3D11PixelShader> GalliumD3D11PixelShader;
+
+#if API >= 11
+/*
+typedef GalliumD3D11Shader<ID3D11HullShader> GalliumD3D11HullShader;
+typedef GalliumD3D11Shader<ID3D11DomainShader> GalliumD3D11DomainShader;
+typedef GalliumD3D11Shader<ID3D11ComputeShader> GalliumD3D11ComputeShader;
+*/
+#endif
+
+template<typename Base = ID3D11Resource>
+struct GalliumD3D11ResourceBase : public GalliumD3D11DeviceChild<Base>
+{
+ unsigned eviction_priority;
+
+ virtual void STDMETHODCALLTYPE SetEvictionPriority(
+ __in unsigned EvictionPriority)
+ {
+ eviction_priority = EvictionPriority;
+ }
+
+ virtual unsigned STDMETHODCALLTYPE GetEvictionPriority()
+ {
+ return eviction_priority;
+ }
+};
+
+template<typename Real>
+struct GalliumDXGIResource : public IDXGIResource
+{
+ virtual HRESULT STDMETHODCALLTYPE SetEvictionPriority(
+ __in unsigned EvictionPriority)
+ {
+ static_cast<Real*>(this)->eviction_priority = EvictionPriority;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetEvictionPriority(unsigned* pEvictionPriority)
+ {
+ *pEvictionPriority = static_cast<Real*>(this)->eviction_priority;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDevice(
+ __in REFIID riid,
+ __out void **ppParent)
+ {
+ if(!static_cast<Real*>(this)->device)
+ return E_NOINTERFACE;
+ return static_cast<Real*>(this)->device->QueryInterface(riid, ppParent);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetParent(
+ __in REFIID riid,
+ __out void **ppParent)
+ {
+ if(!static_cast<Real*>(this)->device)
+ return E_NOINTERFACE;
+ return static_cast<Real*>(this)->device->QueryInterface(riid, ppParent);
+ }
+};
+
+template<typename T>
+struct com_traits<GalliumDXGIResource<T> > : public com_traits<IDXGIResource>
+{};
+
+template<typename Base = ID3D11Resource>
+struct GalliumD3D11Resource
+ : public GalliumMultiComObject<
+ GalliumMultiPrivateDataComObject<
+ GalliumD3D11ResourceBase<Base>,
+ GalliumDXGIResource<GalliumD3D11Resource<Base> >
+ >,
+ IGalliumResource
+ >
+{
+ struct pipe_resource* resource;
+ std::unordered_map<unsigned, pipe_transfer*> transfers;
+ float min_lod;
+ DXGI_USAGE dxgi_usage;
+
+ GalliumD3D11Resource(GalliumD3D11Screen* device = 0, struct pipe_resource* resource = 0, unsigned dxgi_usage = 0)
+ : resource(resource), min_lod(0), dxgi_usage(dxgi_usage)
+ {
+ this->device = device;
+ if(device)
+ device->AddRef();
+ this->eviction_priority = 0;
+ }
+
+ ~GalliumD3D11Resource()
+ {
+ pipe_resource_reference(&resource, 0);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetUsage(
+ __out DXGI_USAGE *pUsage
+ )
+ {
+ *pUsage = this->dxgi_usage;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetSharedHandle(HANDLE *pSharedHandle)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual struct pipe_resource* STDMETHODCALLTYPE GetGalliumResource()
+ {
+ return resource;
+ }
+};
+
+template<typename Base, typename Desc, D3D11_RESOURCE_DIMENSION Dim>
+struct GalliumD3D11TypedResource : public GalliumD3D11Resource<Base>
+{
+ Desc desc;
+ GalliumD3D11TypedResource() {}
+ GalliumD3D11TypedResource(GalliumD3D11Screen* device, struct pipe_resource* resource, const Desc& desc, unsigned dxgi_usage)
+ : GalliumD3D11Resource<Base>(device, resource, dxgi_usage), desc(desc)
+ {}
+ virtual void STDMETHODCALLTYPE GetType(
+ __out D3D11_RESOURCE_DIMENSION *pResourceDimension)
+ {
+ *pResourceDimension = Dim;
+ }
+ virtual void STDMETHODCALLTYPE GetDesc(Desc *pDesc)
+ {
+ memcpy(pDesc, &desc, sizeof(desc));
+ }
+};
+
+typedef GalliumD3D11TypedResource<ID3D11Texture1D, D3D11_TEXTURE1D_DESC, D3D11_RESOURCE_DIMENSION_TEXTURE1D> GalliumD3D11Texture1DBase;
+typedef GalliumD3D11TypedResource<ID3D11Texture2D, D3D11_TEXTURE2D_DESC, D3D11_RESOURCE_DIMENSION_TEXTURE2D> GalliumD3D11Texture2DBase;
+typedef GalliumD3D11TypedResource<ID3D11Texture3D, D3D11_TEXTURE3D_DESC, D3D11_RESOURCE_DIMENSION_TEXTURE3D> GalliumD3D11Texture3DBase;
+typedef GalliumD3D11TypedResource<ID3D11Buffer, D3D11_BUFFER_DESC, D3D11_RESOURCE_DIMENSION_BUFFER> GalliumD3D11BufferBase;
+
+#if API >= 11
+typedef GalliumD3D11BufferBase GalliumD3D11Buffer;
+typedef GalliumD3D11Texture1DBase GalliumD3D11Texture1D;
+typedef GalliumD3D11Texture2DBase GalliumD3D11Texture2D;
+typedef GalliumD3D11Texture3DBase GalliumD3D11Texture3D;
+#else
+struct GalliumD3D10Buffer : public GalliumD3D10BufferBase
+{
+ GalliumD3D10Buffer(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_BUFFER_DESC& desc, unsigned dxgi_usage)
+ : GalliumD3D10BufferBase(device, resource, desc, dxgi_usage)
+ {}
+
+ ~GalliumD3D10Buffer()
+ {
+ device->UnbindBuffer(this);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Map(
+ __in D3D10_MAP MapType,
+ __in unsigned MapFlags,
+ __out void **ppData)
+ {
+ D3D10_MAPPED_SUBRESOURCE msr;
+ HRESULT hr = device->Map(this, 0, MapType, MapFlags, &msr);
+ if(!SUCCEEDED(hr))
+ return hr;
+ *ppData = msr.pData;
+ return S_OK;
+ }
+
+ virtual void STDMETHODCALLTYPE Unmap()
+ {
+ device->Unmap(this, 0);
+ }
+};
+
+struct GalliumD3D10Texture1D : public GalliumD3D10Texture1DBase
+{
+ GalliumD3D10Texture1D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE1D_DESC& desc, unsigned dxgi_usage)
+ : GalliumD3D10Texture1DBase(device, resource, desc, dxgi_usage)
+ {}
+
+ virtual HRESULT STDMETHODCALLTYPE Map(
+ __in unsigned Subresource,
+ __in D3D10_MAP MapType,
+ __in unsigned MapFlags,
+ __out void **ppData)
+ {
+ D3D10_MAPPED_SUBRESOURCE msr;
+ HRESULT hr = device->Map(this, Subresource, MapType, MapFlags, &msr);
+ if(!SUCCEEDED(hr))
+ return hr;
+ *ppData = msr.pData;
+ return S_OK;
+ }
+
+ virtual void STDMETHODCALLTYPE Unmap(
+ __in unsigned Subresource
+ )
+ {
+ device->Unmap(this, Subresource);
+ }
+};
+
+struct GalliumD3D10Texture2D : public GalliumD3D10Texture2DBase
+{
+ GalliumD3D10Texture2D() {}
+ GalliumD3D10Texture2D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE2D_DESC& desc, unsigned dxgi_usage)
+ : GalliumD3D10Texture2DBase(device, resource, desc, dxgi_usage)
+ {}
+
+ virtual HRESULT STDMETHODCALLTYPE Map(
+ __in unsigned Subresource,
+ __in D3D10_MAP MapType,
+ __in unsigned MapFlags,
+ __out D3D10_MAPPED_TEXTURE2D *pMappedTex2D)
+ {
+ D3D10_MAPPED_SUBRESOURCE msr;
+ HRESULT hr = device->Map(this, Subresource, MapType, MapFlags, &msr);
+ if(!SUCCEEDED(hr))
+ return hr;
+ pMappedTex2D->pData = msr.pData;
+ pMappedTex2D->RowPitch = msr.RowPitch;
+ return S_OK;
+ }
+
+ virtual void STDMETHODCALLTYPE Unmap(
+ __in unsigned Subresource
+ )
+ {
+ device->Unmap(this, Subresource);
+ }
+};
+
+
+struct GalliumD3D10Texture3D : public GalliumD3D10Texture3DBase
+{
+ GalliumD3D10Texture3D(GalliumD3D10Screen* device, struct pipe_resource* resource, const D3D10_TEXTURE3D_DESC& desc, unsigned dxgi_usage)
+ : GalliumD3D10Texture3DBase(device, resource, desc, dxgi_usage)
+ {}
+
+ virtual HRESULT STDMETHODCALLTYPE Map(
+ __in unsigned Subresource,
+ __in D3D10_MAP MapType,
+ __in unsigned MapFlags,
+ __out D3D10_MAPPED_TEXTURE3D *pMappedTex3D)
+ {
+ D3D10_MAPPED_SUBRESOURCE msr;
+ HRESULT hr = device->Map(this, Subresource, MapType, MapFlags, &msr);
+ if(!SUCCEEDED(hr))
+ return hr;
+ pMappedTex3D->pData = msr.pData;
+ pMappedTex3D->RowPitch = msr.RowPitch;
+ pMappedTex3D->DepthPitch = msr.DepthPitch;
+ return S_OK;
+ }
+
+ virtual void STDMETHODCALLTYPE Unmap(
+ __in unsigned Subresource
+ )
+ {
+ device->Unmap(this, Subresource);
+ }
+};
+#endif
+
+struct GalliumD3D11Surface : public GalliumMultiPrivateDataComObject<GalliumD3D11Texture2D, IDXGISurface1>
+{
+ GalliumD3D11Surface(GalliumD3D11Screen* device, struct pipe_resource* resource, const D3D11_TEXTURE2D_DESC& desc, unsigned dxgi_usage)
+ {
+ this->device = device;
+ this->device->AddRef();
+ this->resource = resource;
+ this->desc = desc;
+ this->dxgi_usage = dxgi_usage;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDesc(
+ __out DXGI_SURFACE_DESC *pDesc)
+ {
+ pDesc->Format = this->desc.Format;
+ pDesc->Width = this->desc.Width;
+ pDesc->Height = this->desc.Height;
+ pDesc->SampleDesc = this->desc.SampleDesc;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetParent(
+ __in REFIID riid,
+ __out void **ppParent)
+ {
+ if(!device)
+ return E_NOINTERFACE;
+ return device->QueryInterface(riid, ppParent);
+ }
+
+ /* TODO: somehow implement these */
+ virtual HRESULT STDMETHODCALLTYPE GetDC(
+ BOOL Discard,
+ __out HDC *phdc)
+ {
+ *phdc = 0;
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE ReleaseDC(
+ __in_opt RECT *pDirtyRect)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Map(
+ __out DXGI_MAPPED_RECT *pLockedRect,
+ unsigned MapFlags)
+ {
+ D3D11_MAP d3d_map;
+ if(MapFlags & DXGI_MAP_DISCARD)
+ d3d_map = D3D11_MAP_WRITE_DISCARD;
+ else
+ {
+ if(MapFlags & DXGI_MAP_READ)
+ {
+ if(MapFlags & DXGI_MAP_WRITE)
+ d3d_map = D3D11_MAP_READ_WRITE;
+ else
+ d3d_map = D3D11_MAP_READ;
+ }
+ else
+ d3d_map = D3D11_MAP_WRITE;
+ }
+ D3D11_MAPPED_SUBRESOURCE d3d_mapped;
+ HRESULT hres = this->device->get_immediate_context()->Map(this, 0, d3d_map, 0, &d3d_mapped);
+ pLockedRect->pBits = (uint8_t*)d3d_mapped.pData;
+ pLockedRect->Pitch = d3d_mapped.RowPitch;
+ return hres;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE Unmap(void)
+ {
+ this->device->get_immediate_context()->Unmap(this, 0);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDevice(
+ __in REFIID riid,
+ __out void **ppParent)
+ {
+ if(!device)
+ return E_NOINTERFACE;
+ return device->QueryInterface(riid, ppParent);
+ }
+};
+
+template<typename Base, typename Desc, typename Object>
+struct GalliumD3D11View : public GalliumD3D11DescribedObject<Base, Desc, Object>
+{
+ GalliumD3D11Resource<>* resource;
+ GalliumD3D11View(GalliumD3D11Screen* device, GalliumD3D11Resource<>* resource, Object* object, const Desc& desc)
+ : GalliumD3D11DescribedObject<Base, Desc, Object>(device, object, desc), resource(resource)
+ {
+ resource->AddRef();
+ }
+
+ ~GalliumD3D11View()
+ {
+ resource->Release();
+ }
+
+ virtual void STDMETHODCALLTYPE GetResource(ID3D11Resource** ppResource)
+ {
+ resource->AddRef();
+ *ppResource = resource;
+ }
+};
+
+typedef GalliumD3D11View<ID3D11DepthStencilView, D3D11_DEPTH_STENCIL_VIEW_DESC, struct pipe_surface> GalliumD3D11DepthStencilView;
+typedef GalliumD3D11View<ID3D11RenderTargetView, D3D11_RENDER_TARGET_VIEW_DESC, struct pipe_surface> GalliumD3D11RenderTargetView;
+
+#if API >= 11
+typedef GalliumD3D11View<ID3D11ShaderResourceView, D3D11_SHADER_RESOURCE_VIEW_DESC, struct pipe_sampler_view> GalliumD3D11ShaderResourceView;
+#else
+typedef GalliumD3D10View<ID3D10ShaderResourceView1, D3D10_SHADER_RESOURCE_VIEW_DESC1, struct pipe_sampler_view> GalliumD3D10ShaderResourceViewBase;
+
+struct GalliumD3D10ShaderResourceView : public GalliumD3D10ShaderResourceViewBase
+{
+ GalliumD3D10ShaderResourceView(GalliumD3D10Screen* device, GalliumD3D10Resource<>* resource, struct pipe_sampler_view* view, const D3D10_SHADER_RESOURCE_VIEW_DESC1& desc)
+ : GalliumD3D10ShaderResourceViewBase(device, resource, view, desc)
+ {}
+
+ virtual void STDMETHODCALLTYPE GetDesc1(D3D10_SHADER_RESOURCE_VIEW_DESC1 *pDesc)
+ {
+ memcpy(pDesc, &desc, sizeof(*pDesc));
+ }
+
+ virtual void STDMETHODCALLTYPE GetDesc(D3D10_SHADER_RESOURCE_VIEW_DESC *pDesc)
+ {
+ memcpy(pDesc, &desc, sizeof(*pDesc));
+ }
+};
+#endif
+
+template<typename Base = ID3D11Asynchronous>
+struct GalliumD3D11Asynchronous : public GalliumD3D11DeviceChild<Base>
+{
+ struct pipe_query* query;
+ unsigned data_size;
+
+ GalliumD3D11Asynchronous(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size)
+ : GalliumD3D11DeviceChild<Base>(device), query(query), data_size(data_size)
+ {}
+
+ ~GalliumD3D11Asynchronous()
+ {
+ this->device->immediate_pipe->destroy_query(this->device->immediate_pipe, query);
+ }
+
+ virtual unsigned STDMETHODCALLTYPE GetDataSize()
+ {
+ return data_size;
+ }
+
+#if API < 11
+ virtual void STDMETHODCALLTYPE Begin()
+ {
+ this->device->Begin(this);
+ }
+
+ virtual void STDMETHODCALLTYPE End()
+ {
+ this->device->End(this);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetData(
+ __out_bcount(DataSize) void *pData,
+ __in unsigned DataSize,
+ __in unsigned GetDataFlags)
+ {
+ return this->device->GetData(this, pData, DataSize, GetDataFlags);
+ }
+#endif
+};
+
+template<typename Base = ID3D11Asynchronous>
+struct GalliumD3D11QueryOrPredicate : public GalliumD3D11Asynchronous<Base>
+{
+ D3D11_QUERY_DESC desc;
+ GalliumD3D11QueryOrPredicate(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc)
+ : GalliumD3D11Asynchronous<Base>(device, query, data_size), desc(desc)
+ {}
+
+ virtual void STDMETHODCALLTYPE GetDesc(
+ __out D3D11_QUERY_DESC *pDesc)
+ {
+ *pDesc = desc;
+ }
+};
+
+struct GalliumD3D11Query : public GalliumD3D11QueryOrPredicate<ID3D11Query>
+{
+ GalliumD3D11Query(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc)
+ : GalliumD3D11QueryOrPredicate(device, query, data_size, desc)
+ {}
+};
+
+struct GalliumD3D11Predicate : public GalliumD3D11QueryOrPredicate<ID3D11Predicate>
+{
+ GalliumD3D11Predicate(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_QUERY_DESC& desc)
+ : GalliumD3D11QueryOrPredicate(device, query, data_size, desc)
+ {}
+
+ ~GalliumD3D11Predicate()
+ {
+ DX10_ONLY(device->UnbindPredicate(this));
+ }
+};
+
+struct GalliumD3D11Counter : public GalliumD3D11Asynchronous<ID3D11Counter>
+{
+ D3D11_COUNTER_DESC desc;
+ GalliumD3D11Counter(GalliumD3D11Screen* device, struct pipe_query* query, unsigned data_size, const D3D11_COUNTER_DESC& desc)
+ : GalliumD3D11Asynchronous(device, query, data_size), desc(desc)
+ {}
+
+ virtual void STDMETHODCALLTYPE GetDesc(
+ __out D3D11_COUNTER_DESC *pDesc)
+ {
+ *pDesc = desc;
+ }
+};
diff --git a/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_screen.h b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_screen.h
new file mode 100644
index 0000000..50039e3
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d11/d3d11_screen.h
@@ -0,0 +1,1447 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+/* These cap sets are much more correct than the ones in u_caps.c */
+/* TODO: it seems cube levels should be the same as 2D levels */
+
+/* DX 9_1 */
+static unsigned caps_dx_9_1[] = {
+ UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
+ UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
+ UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 8), /* 256 */
+ UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
+ UTIL_CHECK_TERMINATE
+};
+
+/* DX 9_2 */
+static unsigned caps_dx_9_2[] = {
+ UTIL_CHECK_CAP(OCCLUSION_QUERY),
+ UTIL_CHECK_CAP(TWO_SIDED_STENCIL),
+ UTIL_CHECK_CAP(TEXTURE_MIRROR_CLAMP),
+ UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
+ UTIL_CHECK_INT(MAX_RENDER_TARGETS, 1),
+ UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 12), /* 2048 */
+ UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
+ UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
+ UTIL_CHECK_TERMINATE
+};
+
+/* DX 9_3 */
+static unsigned caps_dx_9_3[] = {
+ UTIL_CHECK_CAP(OCCLUSION_QUERY),
+ UTIL_CHECK_CAP(TWO_SIDED_STENCIL),
+ UTIL_CHECK_CAP(TEXTURE_MIRROR_CLAMP),
+ UTIL_CHECK_CAP(BLEND_EQUATION_SEPARATE),
+ UTIL_CHECK_CAP(SM3),
+ //UTIL_CHECK_CAP(INSTANCING),
+ UTIL_CHECK_CAP(OCCLUSION_QUERY),
+ UTIL_CHECK_INT(MAX_RENDER_TARGETS, 4),
+ UTIL_CHECK_INT(MAX_TEXTURE_2D_LEVELS, 13), /* 4096 */
+ UTIL_CHECK_INT(MAX_TEXTURE_3D_LEVELS, 9), /* 256 */
+ UTIL_CHECK_INT(MAX_TEXTURE_CUBE_LEVELS, 10), /* 512 */
+ UTIL_CHECK_TERMINATE
+};
+
+
+// this is called "screen" because in the D3D10 case it's only part of the device
+template<bool threadsafe>
+struct GalliumD3D11ScreenImpl : public GalliumD3D11Screen
+{
+ D3D_FEATURE_LEVEL feature_level;
+ int format_support[PIPE_FORMAT_COUNT];
+ unsigned creation_flags;
+ unsigned exception_mode;
+ maybe_mutex_t<threadsafe> mutex;
+
+/* TODO: Direct3D 11 specifies that fine-grained locking should be used if the driver supports it.
+ * Right now, I don't trust Gallium drivers to get this right.
+ */
+#define SYNCHRONIZED lock_t<maybe_mutex_t<threadsafe> > lock_(mutex)
+
+ GalliumD3D11ScreenImpl(struct pipe_screen* screen, struct pipe_context* immediate_pipe, BOOL owns_immediate_pipe,unsigned creation_flags, IDXGIAdapter* adapter)
+ : GalliumD3D11Screen(screen, immediate_pipe, adapter), creation_flags(creation_flags)
+ {
+ memset(&screen_caps, 0, sizeof(screen_caps));
+ screen_caps.gs = screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0;
+ screen_caps.so = !!screen->get_param(screen, PIPE_CAP_STREAM_OUTPUT);
+ screen_caps.queries = screen->get_param(screen, PIPE_CAP_OCCLUSION_QUERY);
+ screen_caps.render_condition = screen_caps.queries;
+ for(unsigned i = 0; i < PIPE_SHADER_TYPES; ++i)
+ screen_caps.constant_buffers[i] = screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_CONST_BUFFERS);
+ screen_caps.stages = 0;
+ for(unsigned i = 0; i < PIPE_SHADER_TYPES; ++i)
+ {
+ if(!screen->get_shader_param(screen, i, PIPE_SHADER_CAP_MAX_INSTRUCTIONS))
+ break;
+ screen_caps.stages = i + 1;
+ }
+
+ memset(format_support, 0xff, sizeof(format_support));
+
+ float default_level;
+ /* don't even attempt to autodetect D3D10 level support, since it's just not fully implemented yet */
+ if(util_check_caps(screen, caps_dx_9_3))
+ default_level = 9.3;
+ else if(util_check_caps(screen, caps_dx_9_2))
+ default_level = 9.2;
+ else if(util_check_caps(screen, caps_dx_9_1))
+ default_level = 9.1;
+ else
+ {
+ _debug_printf("Warning: driver does not even meet D3D_FEATURE_LEVEL_9_1 features, advertising it anyway!\n");
+ default_level = 9.1;
+ }
+
+ char default_level_name[64];
+ sprintf(default_level_name, "%.1f", default_level);
+ float feature_level_number = atof(debug_get_option("D3D11_FEATURE_LEVEL", default_level_name));
+ if(!feature_level_number)
+ feature_level_number = default_level;
+
+#if API >= 11
+ if(feature_level_number >= 11.0f)
+ feature_level = D3D_FEATURE_LEVEL_11_0;
+ else
+#endif
+ if(feature_level_number >= 10.1f)
+ feature_level = D3D_FEATURE_LEVEL_10_1;
+ else if(feature_level_number >= 10.0f)
+ feature_level = D3D_FEATURE_LEVEL_10_0;
+ else if(feature_level_number >= 9.3f)
+ feature_level = D3D_FEATURE_LEVEL_9_3;
+ else if(feature_level_number >= 9.2f)
+ feature_level = D3D_FEATURE_LEVEL_9_2;
+ else
+ feature_level = D3D_FEATURE_LEVEL_9_1;
+
+#if API >= 11
+ immediate_context = GalliumD3D11ImmediateDeviceContext_Create(this, immediate_pipe, owns_immediate_pipe);
+#endif
+ }
+
+ ~GalliumD3D11ScreenImpl()
+ {
+#if API >= 11
+ GalliumD3D11ImmediateDeviceContext_Destroy(immediate_context);
+#endif
+ }
+
+ virtual D3D_FEATURE_LEVEL STDMETHODCALLTYPE GetFeatureLevel(void)
+ {
+ return feature_level;
+ }
+
+ virtual unsigned STDMETHODCALLTYPE GetCreationFlags(void)
+ {
+ return creation_flags;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE GetDeviceRemovedReason(void)
+ {
+ return S_OK;
+ }
+
+#if API >= 11
+ virtual void STDMETHODCALLTYPE GetImmediateContext(
+ __out ID3D11DeviceContext **ppImmediateContext)
+ {
+ immediate_context->AddRef();
+ *ppImmediateContext = immediate_context;
+ }
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE SetExceptionMode(unsigned RaiseFlags)
+ {
+ exception_mode = RaiseFlags;
+ return S_OK;
+ }
+
+ virtual unsigned STDMETHODCALLTYPE GetExceptionMode(void)
+ {
+ return exception_mode;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CheckCounter(
+ __in const D3D11_COUNTER_DESC *pDesc,
+ __out D3D11_COUNTER_TYPE *pType,
+ __out unsigned *pActiveCounters,
+ __out_ecount_opt(*pNameLength) LPSTR szName,
+ __inout_opt unsigned *pNameLength,
+ __out_ecount_opt(*pUnitsLength) LPSTR szUnits,
+ __inout_opt unsigned *pUnitsLength,
+ __out_ecount_opt(*pDescriptionLength) LPSTR szDescription,
+ __inout_opt unsigned *pDescriptionLength)
+ {
+ return E_NOTIMPL;
+ }
+
+ virtual void STDMETHODCALLTYPE CheckCounterInfo(
+ __out D3D11_COUNTER_INFO *pCounterInfo)
+ {
+ /* none supported at the moment */
+ pCounterInfo->LastDeviceDependentCounter = (D3D11_COUNTER)0;
+ pCounterInfo->NumSimultaneousCounters = 0;
+ pCounterInfo->NumDetectableParallelUnits = 1;
+ }
+
+#if API >= 11
+ virtual HRESULT STDMETHODCALLTYPE CheckFeatureSupport(
+ D3D11_FEATURE Feature,
+ __out_bcount(FeatureSupportDataSize) void *pFeatureSupportData,
+ unsigned FeatureSupportDataSize)
+ {
+ SYNCHRONIZED;
+
+ switch(Feature)
+ {
+ case D3D11_FEATURE_THREADING:
+ {
+ D3D11_FEATURE_DATA_THREADING* data = (D3D11_FEATURE_DATA_THREADING*)pFeatureSupportData;
+ if(FeatureSupportDataSize != sizeof(*data))
+ return E_INVALIDARG;
+
+ data->DriverCommandLists = FALSE;
+ data->DriverConcurrentCreates = FALSE;
+ return S_OK;
+ }
+ case D3D11_FEATURE_DOUBLES:
+ {
+ D3D11_FEATURE_DATA_DOUBLES* data = (D3D11_FEATURE_DATA_DOUBLES*)pFeatureSupportData;
+ if(FeatureSupportDataSize != sizeof(*data))
+ return E_INVALIDARG;
+
+ data->DoublePrecisionFloatShaderOps = FALSE;
+ return S_OK;
+ }
+ case D3D11_FEATURE_FORMAT_SUPPORT:
+ {
+ D3D11_FEATURE_DATA_FORMAT_SUPPORT* data = (D3D11_FEATURE_DATA_FORMAT_SUPPORT*)pFeatureSupportData;
+ if(FeatureSupportDataSize != sizeof(*data))
+ return E_INVALIDARG;
+
+ return this->CheckFormatSupport(data->InFormat, &data->OutFormatSupport);
+ }
+ case D3D11_FEATURE_FORMAT_SUPPORT2:
+ {
+ D3D11_FEATURE_DATA_FORMAT_SUPPORT* data = (D3D11_FEATURE_DATA_FORMAT_SUPPORT*)pFeatureSupportData;
+ if(FeatureSupportDataSize != sizeof(*data))
+ return E_INVALIDARG;
+
+ data->OutFormatSupport = 0;
+ /* TODO: should this be S_OK? */
+ return E_INVALIDARG;
+ }
+ case D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS:
+ {
+ D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS* data = (D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS*)pFeatureSupportData;
+ if(FeatureSupportDataSize != sizeof(*data))
+ return E_INVALIDARG;
+
+ data->ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x = FALSE;
+ return S_OK;
+ }
+ default:
+ return E_INVALIDARG;
+ }
+ }
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE CheckFormatSupport(
+ DXGI_FORMAT Format,
+ unsigned *pFormatSupport
+ )
+ {
+ SYNCHRONIZED;
+
+ /* TODO: MSAA, advanced features */
+ pipe_format format = dxgi_to_pipe_format[Format];
+ if(!format)
+ return E_INVALIDARG;
+
+ int support = format_support[format];
+ if(support < 0)
+ {
+ support = 0;
+ unsigned buffer = D3D11_FORMAT_SUPPORT_BUFFER | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER | D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER;
+ unsigned sampler_view = D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP | D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
+ if(util_format_is_depth_or_stencil(format))
+ sampler_view |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
+
+ /* TODO: do this properly when Gallium drivers actually support index/vertex format queries */
+ if(screen->is_format_supported(screen, format, PIPE_BUFFER, 0, PIPE_BIND_VERTEX_BUFFER, 0)
+ || (screen->is_format_supported(screen, format, PIPE_BUFFER, 0, PIPE_BIND_INDEX_BUFFER, 0)
+ || format == PIPE_FORMAT_R8_UNORM))
+ support |= buffer;
+ if(screen->is_format_supported(screen, format, PIPE_BUFFER, 0, PIPE_BIND_STREAM_OUTPUT, 0))
+ support |= buffer | D3D11_FORMAT_SUPPORT_SO_BUFFER;
+ if(screen->is_format_supported(screen, format, PIPE_TEXTURE_1D, 0, PIPE_BIND_SAMPLER_VIEW, 0))
+ support |= D3D11_FORMAT_SUPPORT_TEXTURE1D | sampler_view;
+ if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW, 0))
+ support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | sampler_view;
+ if(screen->is_format_supported(screen, format, PIPE_TEXTURE_CUBE, 0, PIPE_BIND_SAMPLER_VIEW, 0))
+ support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | sampler_view;
+ if(screen->is_format_supported(screen, format, PIPE_TEXTURE_3D, 0, PIPE_BIND_SAMPLER_VIEW, 0))
+ support |= D3D11_FORMAT_SUPPORT_TEXTURE3D | sampler_view;
+ if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_RENDER_TARGET, 0))
+ support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_BLENDABLE;
+ if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_DEPTH_STENCIL, 0))
+ support |= D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_DEPTH_STENCIL;
+ if(screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, PIPE_BIND_DISPLAY_TARGET, 0))
+ support |= D3D11_FORMAT_SUPPORT_DISPLAY;
+ format_support[format] = support;
+ }
+ *pFormatSupport = support;
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CheckMultisampleQualityLevels(
+ DXGI_FORMAT Format,
+ unsigned SampleCount,
+ unsigned *pNumQualityLevels
+ )
+ {
+ SYNCHRONIZED;
+
+ *pNumQualityLevels = 0;
+ return S_OK;
+ }
+
+ template<typename T, typename U>
+ bool convert_blend_state(T& to, const U& from, unsigned BlendEnable, unsigned RenderTargetWriteMask)
+ {
+ if(invalid(0
+ || from.SrcBlend >= D3D11_BLEND_COUNT
+ || from.SrcBlendAlpha >= D3D11_BLEND_COUNT
+ || from.DestBlend >= D3D11_BLEND_COUNT
+ || from.DestBlendAlpha >= D3D11_BLEND_COUNT
+ || from.BlendOp >= 6
+ || from.BlendOpAlpha >= 6
+ || !from.BlendOp
+ || !from.BlendOpAlpha
+ ))
+ return false;
+
+ to.blend_enable = BlendEnable;
+
+ to.rgb_func = from.BlendOp - 1;
+ to.alpha_func = from.BlendOpAlpha - 1;
+
+ to.rgb_src_factor = d3d11_to_pipe_blend[from.SrcBlend];
+ to.alpha_src_factor = d3d11_to_pipe_blend[from.SrcBlendAlpha];
+ to.rgb_dst_factor = d3d11_to_pipe_blend[from.DestBlend];
+ to.alpha_dst_factor = d3d11_to_pipe_blend[from.DestBlendAlpha];
+
+ to.colormask = RenderTargetWriteMask & 0xf;
+ return true;
+ }
+
+#if API >= 11
+ virtual HRESULT STDMETHODCALLTYPE CreateBlendState(
+ __in const D3D11_BLEND_DESC *pBlendStateDesc,
+ __out_opt ID3D11BlendState **ppBlendState
+ )
+#else
+ virtual HRESULT STDMETHODCALLTYPE CreateBlendState1(
+ __in const D3D10_BLEND_DESC1 *pBlendStateDesc,
+ __out_opt ID3D10BlendState1 **ppBlendState
+ )
+#endif
+ {
+ SYNCHRONIZED;
+
+ pipe_blend_state state;
+ memset(&state, 0, sizeof(state));
+ state.alpha_to_coverage = !!pBlendStateDesc->AlphaToCoverageEnable;
+ state.independent_blend_enable = !!pBlendStateDesc->IndependentBlendEnable;
+ assert(PIPE_MAX_COLOR_BUFS >= 8);
+ for(unsigned i = 0; i < 8; ++i)
+ {
+ if(!convert_blend_state(
+ state.rt[i],
+ pBlendStateDesc->RenderTarget[i],
+ pBlendStateDesc->RenderTarget[i].BlendEnable,
+ pBlendStateDesc->RenderTarget[i].RenderTargetWriteMask))
+ return E_INVALIDARG;
+ }
+
+ if(!ppBlendState)
+ return S_FALSE;
+
+ void* object = immediate_pipe->create_blend_state(immediate_pipe, &state);
+ if(!object)
+ return E_FAIL;
+
+ *ppBlendState = new GalliumD3D11BlendState(this, object, *pBlendStateDesc);
+ return S_OK;
+ }
+
+#if API < 11
+ virtual HRESULT STDMETHODCALLTYPE CreateBlendState(
+ __in const D3D10_BLEND_DESC *pBlendStateDesc,
+ __out_opt ID3D10BlendState **ppBlendState
+ )
+ {
+ SYNCHRONIZED;
+
+ pipe_blend_state state;
+ memset(&state, 0, sizeof(state));
+ state.alpha_to_coverage = !!pBlendStateDesc->AlphaToCoverageEnable;
+ assert(PIPE_MAX_COLOR_BUFS >= 8);
+ for(unsigned i = 0; i < 8; ++i)
+ {
+ if(!convert_blend_state(
+ state.rt[i],
+ *pBlendStateDesc,
+ pBlendStateDesc->BlendEnable[i],
+ pBlendStateDesc->RenderTargetWriteMask[i]))
+ return E_INVALIDARG;
+ }
+
+ for(unsigned i = 1; i < 8; ++i)
+ {
+ if(memcmp(&state.rt[0], &state.rt[i], sizeof(state.rt[0])))
+ {
+ state.independent_blend_enable = TRUE;
+ break;
+ }
+ }
+
+ void* object = immediate_pipe->create_blend_state(immediate_pipe, &state);
+ if(!object)
+ return E_FAIL;
+
+ *ppBlendState = new GalliumD3D11BlendState(this, object, *pBlendStateDesc);
+ return S_OK;
+ }
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE CreateDepthStencilState(
+ __in const D3D11_DEPTH_STENCIL_DESC *pDepthStencilStateDesc,
+ __out_opt ID3D11DepthStencilState **ppDepthStencilState
+ )
+ {
+ SYNCHRONIZED;
+
+ pipe_depth_stencil_alpha_state state;
+ memset(&state, 0, sizeof(state));
+ state.depth.enabled = !!pDepthStencilStateDesc->DepthEnable;
+ state.depth.writemask = pDepthStencilStateDesc->DepthWriteMask;
+ state.depth.func = pDepthStencilStateDesc->DepthFunc - 1;
+ state.stencil[0].enabled = !!pDepthStencilStateDesc->StencilEnable;
+ state.stencil[0].writemask = pDepthStencilStateDesc->StencilWriteMask;
+ state.stencil[0].valuemask = pDepthStencilStateDesc->StencilReadMask;
+ state.stencil[0].zpass_op = d3d11_to_pipe_stencil_op[pDepthStencilStateDesc->FrontFace.StencilPassOp];
+ state.stencil[0].fail_op = d3d11_to_pipe_stencil_op[pDepthStencilStateDesc->FrontFace.StencilFailOp];
+ state.stencil[0].zfail_op = d3d11_to_pipe_stencil_op[pDepthStencilStateDesc->FrontFace.StencilDepthFailOp];
+ state.stencil[0].func = pDepthStencilStateDesc->FrontFace.StencilFunc - 1;
+ state.stencil[1].enabled = !!pDepthStencilStateDesc->StencilEnable;
+ state.stencil[1].writemask = pDepthStencilStateDesc->StencilWriteMask;
+ state.stencil[1].valuemask = pDepthStencilStateDesc->StencilReadMask;
+ state.stencil[1].zpass_op = d3d11_to_pipe_stencil_op[pDepthStencilStateDesc->BackFace.StencilPassOp];
+ state.stencil[1].fail_op = d3d11_to_pipe_stencil_op[pDepthStencilStateDesc->BackFace.StencilFailOp];
+ state.stencil[1].zfail_op = d3d11_to_pipe_stencil_op[pDepthStencilStateDesc->BackFace.StencilDepthFailOp];
+ state.stencil[1].func = pDepthStencilStateDesc->BackFace.StencilFunc - 1;
+
+ if(!ppDepthStencilState)
+ return S_FALSE;
+
+ void* object = immediate_pipe->create_depth_stencil_alpha_state(immediate_pipe, &state);
+ if(!object)
+ return E_FAIL;
+
+ *ppDepthStencilState = new GalliumD3D11DepthStencilState(this, object, *pDepthStencilStateDesc);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateRasterizerState(
+ __in const D3D11_RASTERIZER_DESC *pRasterizerDesc,
+ __out_opt ID3D11RasterizerState **ppRasterizerState)
+ {
+ SYNCHRONIZED;
+
+ pipe_rasterizer_state state;
+ memset(&state, 0, sizeof(state));
+ state.gl_rasterization_rules = 1; /* D3D10/11 use GL rules */
+ state.fill_front = state.fill_back = (pRasterizerDesc->FillMode == D3D11_FILL_WIREFRAME) ? PIPE_POLYGON_MODE_LINE : PIPE_POLYGON_MODE_FILL;
+ if(pRasterizerDesc->CullMode == D3D11_CULL_FRONT)
+ state.cull_face = PIPE_FACE_FRONT;
+ else if(pRasterizerDesc->CullMode == D3D11_CULL_BACK)
+ state.cull_face = PIPE_FACE_BACK;
+ else
+ state.cull_face = PIPE_FACE_NONE;
+ state.front_ccw = !!pRasterizerDesc->FrontCounterClockwise;
+ /* TODO: is this correct? */
+ /* TODO: we are ignoring DepthBiasClamp! */
+ state.offset_tri = state.offset_line = state.offset_point = pRasterizerDesc->SlopeScaledDepthBias || pRasterizerDesc->DepthBias;
+ state.offset_scale = pRasterizerDesc->SlopeScaledDepthBias;
+ state.offset_units = pRasterizerDesc->DepthBias;
+ state.scissor = !!pRasterizerDesc->ScissorEnable;
+ state.multisample = !!pRasterizerDesc->MultisampleEnable;
+ state.line_smooth = !!pRasterizerDesc->AntialiasedLineEnable;
+
+ /* TODO: is this correct? */
+ state.point_quad_rasterization = 1;
+
+ if(!ppRasterizerState)
+ return S_FALSE;
+
+ void* object = immediate_pipe->create_rasterizer_state(immediate_pipe, &state);
+ if(!object)
+ return E_FAIL;
+
+ *ppRasterizerState = new GalliumD3D11RasterizerState(this, object, *pRasterizerDesc, !pRasterizerDesc->DepthClipEnable);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateSamplerState(
+ __in const D3D11_SAMPLER_DESC *pSamplerDesc,
+ __out_opt ID3D11SamplerState **ppSamplerState)
+ {
+ SYNCHRONIZED;
+
+ pipe_sampler_state state;
+ memset(&state, 0, sizeof(state));
+ state.normalized_coords = 1;
+ state.min_mip_filter = (pSamplerDesc->Filter & 1);
+ state.mag_img_filter = ((pSamplerDesc->Filter >> 2) & 1);
+ state.min_img_filter = ((pSamplerDesc->Filter >> 4) & 1);
+ if(pSamplerDesc->Filter & 0x40)
+ state.max_anisotropy = pSamplerDesc->MaxAnisotropy;
+ if(pSamplerDesc->Filter & 0x80)
+ {
+ state.compare_mode = PIPE_TEX_COMPARE_R_TO_TEXTURE;
+ state.compare_func = pSamplerDesc->ComparisonFunc;
+ }
+ state.wrap_s = d3d11_to_pipe_wrap[pSamplerDesc->AddressU];
+ state.wrap_t = d3d11_to_pipe_wrap[pSamplerDesc->AddressV];
+ state.wrap_r = d3d11_to_pipe_wrap[pSamplerDesc->AddressW];
+ state.lod_bias = pSamplerDesc->MipLODBias;
+ memcpy(state.border_color, pSamplerDesc->BorderColor, sizeof(state.border_color));
+ state.min_lod = pSamplerDesc->MinLOD;
+ state.max_lod = pSamplerDesc->MaxLOD;
+
+ if(!ppSamplerState)
+ return S_FALSE;
+
+ void* object = immediate_pipe->create_sampler_state(immediate_pipe, &state);
+ if(!object)
+ return E_FAIL;
+
+ *ppSamplerState = new GalliumD3D11SamplerState(this, object, *pSamplerDesc);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateInputLayout(
+ __in_ecount(NumElements) const D3D11_INPUT_ELEMENT_DESC *pInputElementDescs,
+ __in_range(0, D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT) unsigned NumElements,
+ __in const void *pShaderBytecodeWithInputSignature,
+ __in SIZE_T BytecodeLength,
+ __out_opt ID3D11InputLayout **ppInputLayout)
+ {
+ SYNCHRONIZED;
+
+ if(NumElements > D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT)
+ return E_INVALIDARG;
+ assert(D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT <= PIPE_MAX_ATTRIBS);
+
+ // putting semantics matching in the core API seems to be a (minor) design mistake
+
+ struct dxbc_chunk_signature* sig = dxbc_find_signature(pShaderBytecodeWithInputSignature, BytecodeLength, false);
+ D3D11_SIGNATURE_PARAMETER_DESC* params;
+ unsigned num_params = dxbc_parse_signature(sig, &params);
+
+ typedef std::unordered_map<std::pair<c_string, unsigned>, unsigned> semantic_to_idx_map_t;
+ semantic_to_idx_map_t semantic_to_idx_map;
+ for(unsigned i = 0; i < NumElements; ++i)
+ semantic_to_idx_map[std::make_pair(c_string(pInputElementDescs[i].SemanticName), pInputElementDescs[i].SemanticIndex)] = i;
+
+ struct pipe_vertex_element elements[D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT];
+
+ unsigned num_params_to_use = std::min(num_params, (unsigned)D3D11_IA_VERTEX_INPUT_STRUCTURE_ELEMENT_COUNT);
+ for(unsigned i = 0; i < num_params_to_use; ++i)
+ {
+ int idx = -1;
+ semantic_to_idx_map_t::iterator iter = semantic_to_idx_map.find(std::make_pair(c_string(params[i].SemanticName), params[i].SemanticIndex));
+ if(iter != semantic_to_idx_map.end())
+ idx = iter->second;
+
+ // TODO: I kind of doubt Gallium drivers will like null elements; should we do something about it, either here, in the interface, or in the drivers?
+ // TODO: also, in which cases should we return errors? (i.e. duplicate semantics in vs, duplicate semantics in layout, unmatched semantic in vs, unmatched semantic in layout)
+ memset(&elements[i], 0, sizeof(elements[i]));
+ if(idx >= 0)
+ {
+ elements[i].src_format = dxgi_to_pipe_format[pInputElementDescs[idx].Format];
+ elements[i].src_offset = pInputElementDescs[idx].AlignedByteOffset;
+ elements[i].vertex_buffer_index = pInputElementDescs[idx].InputSlot;
+ elements[i].instance_divisor = pInputElementDescs[idx].InstanceDataStepRate;
+ }
+ }
+
+ free(params);
+
+ if(!ppInputLayout)
+ return S_FALSE;
+
+ void* object = immediate_pipe->create_vertex_elements_state(immediate_pipe, num_params_to_use, elements);
+ if(!object)
+ return E_FAIL;
+
+ *ppInputLayout = new GalliumD3D11InputLayout(this, object);
+ return S_OK;
+ }
+
+ static unsigned d3d11_to_pipe_bind_flags(unsigned BindFlags)
+ {
+ unsigned bind = 0;
+ if(BindFlags & D3D11_BIND_VERTEX_BUFFER)
+ bind |= PIPE_BIND_VERTEX_BUFFER;
+ if(BindFlags & D3D11_BIND_INDEX_BUFFER)
+ bind |= PIPE_BIND_INDEX_BUFFER;
+ if(BindFlags & D3D11_BIND_CONSTANT_BUFFER)
+ bind |= PIPE_BIND_CONSTANT_BUFFER;
+ if(BindFlags & D3D11_BIND_SHADER_RESOURCE)
+ bind |= PIPE_BIND_SAMPLER_VIEW;
+ if(BindFlags & D3D11_BIND_STREAM_OUTPUT)
+ bind |= PIPE_BIND_STREAM_OUTPUT;
+ if(BindFlags & D3D11_BIND_RENDER_TARGET)
+ bind |= PIPE_BIND_RENDER_TARGET;
+ if(BindFlags & D3D11_BIND_DEPTH_STENCIL)
+ bind |= PIPE_BIND_DEPTH_STENCIL;
+ return bind;
+ }
+
+ inline HRESULT create_resource(
+ pipe_texture_target target,
+ unsigned Width,
+ unsigned Height,
+ unsigned Depth,
+ unsigned MipLevels,
+ unsigned ArraySize,
+ DXGI_FORMAT Format,
+ const DXGI_SAMPLE_DESC* SampleDesc,
+ D3D11_USAGE Usage,
+ unsigned BindFlags,
+ unsigned CPUAccessFlags,
+ unsigned MiscFlags,
+ const D3D11_SUBRESOURCE_DATA *pInitialData,
+ DXGI_USAGE dxgi_usage,
+ struct pipe_resource** ppresource
+ )
+ {
+ if(invalid(Format >= DXGI_FORMAT_COUNT))
+ return E_INVALIDARG;
+ if(MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE)
+ {
+ if(target != PIPE_TEXTURE_2D)
+ return E_INVALIDARG;
+ target = PIPE_TEXTURE_CUBE;
+
+ if(ArraySize != 6)
+ return E_NOTIMPL;
+ }
+ else
+ {
+ if(ArraySize > 1)
+ return E_NOTIMPL;
+ ArraySize = 1;
+ }
+ /* TODO: msaa */
+ struct pipe_resource templat;
+ memset(&templat, 0, sizeof(templat));
+ templat.target = target;
+ templat.width0 = Width;
+ templat.height0 = Height;
+ templat.depth0 = Depth;
+ templat.last_level = MipLevels ? (MipLevels - 1) : 0;
+ templat.format = dxgi_to_pipe_format[Format];
+ templat.bind = d3d11_to_pipe_bind_flags(BindFlags);
+ if(CPUAccessFlags & D3D11_CPU_ACCESS_READ)
+ templat.bind |= PIPE_BIND_TRANSFER_READ;
+ if(CPUAccessFlags & D3D11_CPU_ACCESS_WRITE)
+ templat.bind |= PIPE_BIND_TRANSFER_WRITE;
+ if(MiscFlags & D3D11_RESOURCE_MISC_SHARED)
+ templat.bind |= PIPE_BIND_SHARED;
+ if(MiscFlags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE)
+ templat.bind |= PIPE_BIND_TRANSFER_READ | PIPE_BIND_TRANSFER_WRITE;
+ if(dxgi_usage & DXGI_USAGE_BACK_BUFFER)
+ templat.bind |= PIPE_BIND_DISPLAY_TARGET;
+ templat.usage = d3d11_to_pipe_usage[Usage];
+ if(invalid(!templat.format))
+ return E_NOTIMPL;
+
+ if(!ppresource)
+ return S_FALSE;
+
+ struct pipe_resource* resource = screen->resource_create(screen, &templat);
+ if(!resource)
+ return E_FAIL;
+ if(pInitialData)
+ {
+ for(unsigned slice = 0; slice < ArraySize; ++slice)
+ {
+ for(unsigned level = 0; level <= templat.last_level; ++level)
+ {
+ struct pipe_subresource sr;
+ sr.level = level;
+ sr.face = slice;
+ struct pipe_box box;
+ box.x = box.y = box.z = 0;
+ box.width = u_minify(Width, level);
+ box.height = u_minify(Height, level);
+ box.depth = u_minify(Depth, level);
+ immediate_pipe->transfer_inline_write(immediate_pipe, resource, sr, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD | PIPE_TRANSFER_UNSYNCHRONIZED, &box, pInitialData->pSysMem, pInitialData->SysMemPitch, pInitialData->SysMemSlicePitch);
+ ++pInitialData;
+ }
+ }
+ }
+ *ppresource = resource;
+ return S_OK;
+ }
+
+ static unsigned d3d_to_dxgi_usage(unsigned bind, unsigned misc)
+ {
+ unsigned dxgi_usage = 0;
+ if(bind |= D3D11_BIND_RENDER_TARGET)
+ dxgi_usage |= DXGI_USAGE_RENDER_TARGET_OUTPUT;
+ if(bind & D3D11_BIND_SHADER_RESOURCE)
+ dxgi_usage |= DXGI_USAGE_SHADER_INPUT;
+#if API >= 11
+ if(bind & D3D11_BIND_UNORDERED_ACCESS)
+ dxgi_usage |= DXGI_USAGE_UNORDERED_ACCESS;
+#endif
+ if(misc & D3D11_RESOURCE_MISC_SHARED)
+ dxgi_usage |= DXGI_USAGE_SHARED;
+ return dxgi_usage;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateTexture1D(
+ __in const D3D11_TEXTURE1D_DESC *pDesc,
+ __in_xcount_opt(pDesc->MipLevels * pDesc->ArraySize) const D3D11_SUBRESOURCE_DATA *pInitialData,
+ __out_opt ID3D11Texture1D **ppTexture1D)
+ {
+ SYNCHRONIZED;
+
+ struct pipe_resource* resource;
+ DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(pDesc->BindFlags, pDesc->MiscFlags);
+ HRESULT hr = create_resource(PIPE_TEXTURE_1D, pDesc->Width, 1, 1, pDesc->MipLevels, pDesc->ArraySize, pDesc->Format, 0, pDesc->Usage, pDesc->BindFlags, pDesc->CPUAccessFlags, pDesc->MiscFlags, pInitialData, dxgi_usage, ppTexture1D ? &resource : 0);
+ if(hr != S_OK)
+ return hr;
+ *ppTexture1D = new GalliumD3D11Texture1D(this, resource, *pDesc, dxgi_usage);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateTexture2D(
+ __in const D3D11_TEXTURE2D_DESC *pDesc,
+ __in_xcount_opt(pDesc->MipLevels * pDesc->ArraySize) const D3D11_SUBRESOURCE_DATA *pInitialData,
+ __out_opt ID3D11Texture2D **ppTexture2D)
+ {
+ SYNCHRONIZED;
+
+ struct pipe_resource* resource;
+ DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(pDesc->BindFlags, pDesc->MiscFlags);
+ HRESULT hr = create_resource(PIPE_TEXTURE_2D, pDesc->Width, pDesc->Height, 1, pDesc->MipLevels, pDesc->ArraySize, pDesc->Format, &pDesc->SampleDesc, pDesc->Usage, pDesc->BindFlags, pDesc->CPUAccessFlags, pDesc->MiscFlags, pInitialData, dxgi_usage, ppTexture2D ? &resource : 0);
+ if(hr != S_OK)
+ return hr;
+ if(pDesc->MipLevels == 1 && pDesc->ArraySize == 1)
+ *ppTexture2D = new GalliumD3D11Surface(this, resource, *pDesc, dxgi_usage);
+ else
+ *ppTexture2D = new GalliumD3D11Texture2D(this, resource, *pDesc, dxgi_usage);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateTexture3D(
+ __in const D3D11_TEXTURE3D_DESC *pDesc,
+ __in_xcount_opt(pDesc->MipLevels) const D3D11_SUBRESOURCE_DATA *pInitialData,
+ __out_opt ID3D11Texture3D **ppTexture3D)
+ {
+ SYNCHRONIZED;
+
+ struct pipe_resource* resource;
+ DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(pDesc->BindFlags, pDesc->MiscFlags);
+ HRESULT hr = create_resource(PIPE_TEXTURE_3D, pDesc->Width, pDesc->Height, pDesc->Depth, pDesc->MipLevels, 1, pDesc->Format, 0, pDesc->Usage, pDesc->BindFlags, pDesc->CPUAccessFlags, pDesc->MiscFlags, pInitialData, dxgi_usage, ppTexture3D ? &resource : 0);
+ if(hr != S_OK)
+ return hr;
+ *ppTexture3D = new GalliumD3D11Texture3D(this, resource, *pDesc, dxgi_usage);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateBuffer(
+ __in const D3D11_BUFFER_DESC *pDesc,
+ __in_opt const D3D11_SUBRESOURCE_DATA *pInitialData,
+ __out_opt ID3D11Buffer **ppBuffer)
+ {
+ SYNCHRONIZED;
+
+#if API >= 11
+ if(pDesc->StructureByteStride > 1)
+ return E_NOTIMPL;
+#endif
+ struct pipe_resource* resource;
+ DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(pDesc->BindFlags, pDesc->MiscFlags);
+ HRESULT hr = create_resource(PIPE_BUFFER, pDesc->ByteWidth, 1, 1, 1, 1, DXGI_FORMAT_R8_UNORM, 0, pDesc->Usage, pDesc->BindFlags, pDesc->CPUAccessFlags, pDesc->MiscFlags, pInitialData, dxgi_usage, ppBuffer ? &resource : 0);
+ if(hr != S_OK)
+ return hr;
+ *ppBuffer = new GalliumD3D11Buffer(this, resource, *pDesc, dxgi_usage);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE OpenGalliumResource(
+ __in struct pipe_resource* resource,
+ __out IUnknown** dxgi_resource)
+ {
+ SYNCHRONIZED;
+
+ /* TODO: maybe support others */
+ assert(resource->target == PIPE_TEXTURE_2D);
+ *dxgi_resource = 0;
+ D3D11_TEXTURE2D_DESC desc;
+ memset(&desc, 0, sizeof(desc));
+ desc.Width = resource->width0;
+ desc.Height = resource->height0;
+ init_pipe_to_dxgi_format();
+ desc.Format = pipe_to_dxgi_format[resource->format];
+ desc.SampleDesc.Count = resource->nr_samples;
+ desc.SampleDesc.Quality = 0;
+ desc.ArraySize = 1;
+ desc.MipLevels = resource->last_level + 1;
+ desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
+ if(resource->bind & PIPE_BIND_RENDER_TARGET)
+ desc.BindFlags |= D3D11_BIND_RENDER_TARGET;
+ if(resource->bind & PIPE_BIND_DEPTH_STENCIL)
+ desc.BindFlags |= D3D11_BIND_DEPTH_STENCIL;
+ if(resource->bind & PIPE_BIND_SAMPLER_VIEW)
+ desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
+ if(resource->bind & PIPE_BIND_SHARED)
+ desc.MiscFlags |= D3D11_RESOURCE_MISC_SHARED;
+ DXGI_USAGE dxgi_usage = d3d_to_dxgi_usage(desc.BindFlags, desc.MiscFlags);
+ if(desc.MipLevels == 1 && desc.ArraySize == 1)
+ *dxgi_resource = (ID3D11Texture2D*)new GalliumD3D11Surface(this, resource, desc, dxgi_usage);
+ else
+ *dxgi_resource = (ID3D11Texture2D*)new GalliumD3D11Texture2D(this, resource, desc, dxgi_usage);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateSurface(
+ __in const DXGI_SURFACE_DESC *pDesc,
+ unsigned NumSurfaces,
+ DXGI_USAGE Usage,
+ __in_opt const DXGI_SHARED_RESOURCE *pSharedResource,
+ __out IDXGISurface **ppSurface)
+ {
+ SYNCHRONIZED;
+
+ D3D11_TEXTURE2D_DESC desc;
+ memset(&desc, 0, sizeof(desc));
+
+ struct pipe_resource* resource;
+ desc.Width = pDesc->Width;
+ desc.Height = pDesc->Height;
+ desc.Format = pDesc->Format;
+ desc.SampleDesc = pDesc->SampleDesc;
+ desc.ArraySize = NumSurfaces;
+ desc.MipLevels = 1;
+ desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
+ if(Usage & DXGI_USAGE_RENDER_TARGET_OUTPUT)
+ desc.BindFlags |= D3D11_BIND_RENDER_TARGET;
+ if(Usage & DXGI_USAGE_SHADER_INPUT)
+ desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
+#if API >= 11
+ if(Usage & DXGI_USAGE_UNORDERED_ACCESS)
+ desc.BindFlags |= D3D11_BIND_UNORDERED_ACCESS;
+#endif
+ if(Usage & DXGI_USAGE_SHARED)
+ desc.MiscFlags |= D3D11_RESOURCE_MISC_SHARED;
+ HRESULT hr = create_resource(PIPE_TEXTURE_2D, pDesc->Width, pDesc->Height, 1, 1, NumSurfaces, pDesc->Format, &pDesc->SampleDesc, D3D11_USAGE_DEFAULT, desc.BindFlags, D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE, desc.MiscFlags, 0, Usage, &resource);
+ if(hr != S_OK)
+ return hr;
+ *ppSurface = new GalliumD3D11Surface(this, resource, desc, Usage);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateShaderResourceView(
+ __in ID3D11Resource *pResource,
+ __in_opt const D3D11_SHADER_RESOURCE_VIEW_DESC *pDesc,
+ __out_opt ID3D11ShaderResourceView **ppSRView)
+ {
+#if API >= 11
+ D3D11_SHADER_RESOURCE_VIEW_DESC def_desc;
+#else
+ if(pDesc->ViewDimension == D3D10_1_SRV_DIMENSION_TEXTURECUBEARRAY)
+ return E_INVALIDARG;
+ D3D10_SHADER_RESOURCE_VIEW_DESC1 desc1;
+ memset(&desc1, 0, sizeof(desc1));
+ memcpy(&desc1, pDesc, sizeof(*pDesc));
+ return CreateShaderResourceView1(pResource, &desc1, (ID3D10ShaderResourceView1**)ppSRView);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateShaderResourceView1(
+ __in ID3D11Resource *pResource,
+ __in_opt const D3D10_SHADER_RESOURCE_VIEW_DESC1 *pDesc,
+ __out_opt ID3D10ShaderResourceView1 **ppSRView)
+ {
+ D3D10_SHADER_RESOURCE_VIEW_DESC1 def_desc;
+#endif
+ SYNCHRONIZED;
+
+ if(!pDesc)
+ {
+ struct pipe_resource* resource = ((GalliumD3D11Resource<>*)pResource)->resource;
+ init_pipe_to_dxgi_format();
+ memset(&def_desc, 0, sizeof(def_desc));
+ def_desc.Format = pipe_to_dxgi_format[resource->format];
+ switch(resource->target)
+ {
+ case PIPE_BUFFER:
+ def_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
+ def_desc.Buffer.ElementWidth = 1;
+#if API >= 11
+ def_desc.Buffer.NumElements = resource->width0;
+#endif
+ break;
+ case PIPE_TEXTURE_1D:
+ def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
+ def_desc.Texture1D.MipLevels = resource->last_level + 1;
+ break;
+ case PIPE_TEXTURE_2D:
+ case PIPE_TEXTURE_RECT:
+ def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+ def_desc.Texture2D.MipLevels = resource->last_level + 1;
+ break;
+ case PIPE_TEXTURE_3D:
+ def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
+ def_desc.Texture3D.MipLevels = resource->last_level + 1;
+ break;
+ case PIPE_TEXTURE_CUBE:
+ def_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
+ def_desc.TextureCube.MipLevels = resource->last_level + 1;
+ break;
+ default:
+ return E_INVALIDARG;
+ }
+ pDesc = &def_desc;
+ }
+
+ struct pipe_sampler_view templat;
+ memset(&templat, 0, sizeof(templat));
+ if(invalid(Format >= DXGI_FORMAT_COUNT))
+ return E_INVALIDARG;
+ templat.format = dxgi_to_pipe_format[pDesc->Format];
+ if(!templat.format)
+ return E_NOTIMPL;
+ templat.swizzle_r = PIPE_SWIZZLE_RED;
+ templat.swizzle_g = PIPE_SWIZZLE_GREEN;
+ templat.swizzle_b = PIPE_SWIZZLE_BLUE;
+ templat.swizzle_a = PIPE_SWIZZLE_ALPHA;
+
+ templat.texture = ((GalliumD3D11Resource<>*)pResource)->resource;
+ switch(pDesc->ViewDimension)
+ {
+ case D3D11_SRV_DIMENSION_TEXTURE1D:
+ case D3D11_SRV_DIMENSION_TEXTURE2D:
+ case D3D11_SRV_DIMENSION_TEXTURE3D:
+ case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
+ case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
+ /* yes, this works for all of these types (but TODO: texture arrays) */
+ templat.first_level = pDesc->Texture1D.MostDetailedMip;
+ templat.last_level = templat.first_level + pDesc->Texture1D.MipLevels - 1;
+ break;
+ case D3D11_SRV_DIMENSION_BUFFER:
+ case D3D11_SRV_DIMENSION_TEXTURE2DMS:
+ case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
+ return E_NOTIMPL;
+ default:
+ return E_INVALIDARG;
+ }
+
+ if(!ppSRView)
+ return S_FALSE;
+
+ struct pipe_sampler_view* view = immediate_pipe->create_sampler_view(immediate_pipe, templat.texture, &templat);
+ if(!view)
+ return E_FAIL;
+ *ppSRView = new GalliumD3D11ShaderResourceView(this, (GalliumD3D11Resource<>*)pResource, view, *pDesc);
+ return S_OK;
+ }
+
+#if API >= 11
+ virtual HRESULT STDMETHODCALLTYPE CreateUnorderedAccessView(
+ __in ID3D11Resource *pResource,
+ __in_opt const D3D11_UNORDERED_ACCESS_VIEW_DESC *pDesc,
+ __out_opt ID3D11UnorderedAccessView **ppUAView)
+ {
+ SYNCHRONIZED;
+
+ return E_NOTIMPL;
+
+ // remember to return S_FALSE and not crash if ppUAView == 0 and parameters are valid
+ }
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE CreateRenderTargetView(
+ __in ID3D11Resource *pResource,
+ __in_opt const D3D11_RENDER_TARGET_VIEW_DESC *pDesc,
+ __out_opt ID3D11RenderTargetView **ppRTView)
+ {
+ SYNCHRONIZED;
+
+ D3D11_RENDER_TARGET_VIEW_DESC def_desc;
+ if(!pDesc)
+ {
+ struct pipe_resource* resource = ((GalliumD3D11Resource<>*)pResource)->resource;
+ init_pipe_to_dxgi_format();
+ memset(&def_desc, 0, sizeof(def_desc));
+ def_desc.Format = pipe_to_dxgi_format[resource->format];
+ switch(resource->target)
+ {
+ case PIPE_BUFFER:
+ def_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
+ def_desc.Buffer.ElementWidth = 1;
+#if API >= 11
+ def_desc.Buffer.NumElements = resource->width0;
+#endif
+ break;
+ case PIPE_TEXTURE_1D:
+ def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
+ break;
+ case PIPE_TEXTURE_2D:
+ case PIPE_TEXTURE_RECT:
+ def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
+ break;
+ case PIPE_TEXTURE_3D:
+ def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
+ def_desc.Texture3D.WSize = resource->depth0;
+ break;
+ case PIPE_TEXTURE_CUBE:
+ def_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
+ def_desc.Texture2DArray.ArraySize = 6;
+ break;
+ default:
+ return E_INVALIDARG;
+ }
+ pDesc = &def_desc;
+ }
+
+ unsigned zslice = 0;
+ unsigned face = 0;
+ unsigned level;
+ enum pipe_format format;
+ if(invalid(pDesc->Format >= DXGI_FORMAT_COUNT))
+ return E_INVALIDARG;
+ format = dxgi_to_pipe_format[pDesc->Format];
+ if(!format)
+ return E_NOTIMPL;
+
+ switch(pDesc->ViewDimension)
+ {
+ case D3D11_RTV_DIMENSION_TEXTURE1D:
+ case D3D11_RTV_DIMENSION_TEXTURE2D:
+ level = pDesc->Texture1D.MipSlice;
+ break;
+ case D3D11_RTV_DIMENSION_TEXTURE3D:
+ level = pDesc->Texture3D.MipSlice;
+ zslice = pDesc->Texture3D.FirstWSlice;
+ break;
+ case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
+ case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
+ level = pDesc->Texture1DArray.MipSlice;
+ face = pDesc->Texture1DArray.FirstArraySlice;
+ break;
+ case D3D11_RTV_DIMENSION_BUFFER:
+ case D3D11_RTV_DIMENSION_TEXTURE2DMS:
+ case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
+ return E_NOTIMPL;
+ default:
+ return E_INVALIDARG;
+ }
+
+ if(!ppRTView)
+ return S_FALSE;
+
+ struct pipe_surface* surface = screen->get_tex_surface(screen,
+ ((GalliumD3D11Resource<>*)pResource)->resource,
+ face, level, zslice, PIPE_BIND_RENDER_TARGET);
+ if(!surface)
+ return E_FAIL;
+ /* muhahahahaha, let's hope this actually works */
+ surface->format = format;
+ *ppRTView = new GalliumD3D11RenderTargetView(this, (GalliumD3D11Resource<>*)pResource, surface, *pDesc);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreateDepthStencilView(
+ __in ID3D11Resource *pResource,
+ __in_opt const D3D11_DEPTH_STENCIL_VIEW_DESC *pDesc,
+ __out_opt ID3D11DepthStencilView **ppDepthStencilView)
+ {
+ SYNCHRONIZED;
+
+ D3D11_DEPTH_STENCIL_VIEW_DESC def_desc;
+ if(!pDesc)
+ {
+ struct pipe_resource* resource = ((GalliumD3D11Resource<>*)pResource)->resource;
+ init_pipe_to_dxgi_format();
+ memset(&def_desc, 0, sizeof(def_desc));
+ def_desc.Format = pipe_to_dxgi_format[resource->format];
+ switch(resource->target)
+ {
+ case PIPE_TEXTURE_1D:
+ def_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1D;
+ break;
+ case PIPE_TEXTURE_2D:
+ case PIPE_TEXTURE_RECT:
+ def_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
+ break;
+ case PIPE_TEXTURE_CUBE:
+ def_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
+ def_desc.Texture2DArray.ArraySize = 6;
+ break;
+ default:
+ return E_INVALIDARG;
+ }
+ pDesc = &def_desc;
+ }
+
+ unsigned zslice = 0;
+ unsigned face = 0;
+ unsigned level;
+ enum pipe_format format;
+ if(invalid(pDesc->Format >= DXGI_FORMAT_COUNT))
+ return E_INVALIDARG;
+ format = dxgi_to_pipe_format[pDesc->Format];
+ if(!format)
+ return E_NOTIMPL;
+
+ switch(pDesc->ViewDimension)
+ {
+ case D3D11_DSV_DIMENSION_TEXTURE1D:
+ case D3D11_DSV_DIMENSION_TEXTURE2D:
+ level = pDesc->Texture1D.MipSlice;
+ break;
+ case D3D11_DSV_DIMENSION_TEXTURE1DARRAY:
+ case D3D11_DSV_DIMENSION_TEXTURE2DARRAY:
+ level = pDesc->Texture1DArray.MipSlice;
+ face = pDesc->Texture1DArray.FirstArraySlice;
+ break;
+ case D3D11_DSV_DIMENSION_TEXTURE2DMS:
+ case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY:
+ return E_NOTIMPL;
+ default:
+ return E_INVALIDARG;
+ }
+
+ if(!ppDepthStencilView)
+ return S_FALSE;
+
+ struct pipe_surface* surface = screen->get_tex_surface(screen,
+ ((GalliumD3D11Resource<>*)pResource)->resource,
+ face, level, zslice, PIPE_BIND_DEPTH_STENCIL);
+ if(!surface)
+ return E_FAIL;
+ /* muhahahahaha, let's hope this actually works */
+ surface->format = format;
+ *ppDepthStencilView = new GalliumD3D11DepthStencilView(this, (GalliumD3D11Resource<>*)pResource, surface, *pDesc);
+ return S_OK;
+ }
+
+ GalliumD3D11Shader<>* create_stage_shader(unsigned type, const void *pShaderBytecode, SIZE_T BytecodeLength
+#if API >= 11
+ , __in_opt ID3D11ClassLinkage *pClassLinkage
+#endif
+ )
+ {
+ dxbc_chunk_header* tpf_chunk = dxbc_find_shader_bytecode(pShaderBytecode, BytecodeLength);
+ if(!tpf_chunk)
+ return 0;
+
+ std::auto_ptr<tpf_program> tpf(tpf_parse(tpf_chunk + 1, bswap_le32(tpf_chunk->size)));
+ if(!tpf.get())
+ return 0;
+
+ struct pipe_shader_state tgsi_shader;
+ memset(&tgsi_shader, 0, sizeof(tgsi_shader));
+ tgsi_shader.tokens = (const tgsi_token*)tpf_to_tgsi(*tpf);
+ if(!tgsi_shader.tokens)
+ return 0;
+
+ void* shader_cso;
+ GalliumD3D11Shader<>* shader;
+
+ switch(type)
+ {
+ case PIPE_SHADER_VERTEX:
+ shader_cso = immediate_pipe->create_vs_state(immediate_pipe, &tgsi_shader);
+ shader = (GalliumD3D11Shader<>*)new GalliumD3D11VertexShader(this, shader_cso);
+ break;
+ case PIPE_SHADER_FRAGMENT:
+ shader_cso = immediate_pipe->create_fs_state(immediate_pipe, &tgsi_shader);
+ shader = (GalliumD3D11Shader<>*)new GalliumD3D11PixelShader(this, shader_cso);
+ break;
+ case PIPE_SHADER_GEOMETRY:
+ shader_cso = immediate_pipe->create_gs_state(immediate_pipe, &tgsi_shader);
+ shader = (GalliumD3D11Shader<>*)new GalliumD3D11GeometryShader(this, shader_cso);
+ break;
+ default:
+ shader_cso = 0;
+ shader = 0;
+ break;
+ }
+
+ if(shader)
+ {
+ shader->slot_to_resource = tpf->slot_to_resource;
+ shader->slot_to_sampler = tpf->slot_to_sampler;
+ }
+
+ free((void*)tgsi_shader.tokens);
+ return shader;
+ }
+
+#if API >= 11
+#define CREATE_SHADER_ARGS \
+ __in const void *pShaderBytecode, \
+ __in SIZE_T BytecodeLength, \
+ __in_opt ID3D11ClassLinkage *pClassLinkage
+#define PASS_SHADER_ARGS pShaderBytecode, BytecodeLength, pClassLinkage
+#else
+#define CREATE_SHADER_ARGS \
+ __in const void *pShaderBytecode, \
+ __in SIZE_T BytecodeLength
+#define PASS_SHADER_ARGS pShaderBytecode, BytecodeLength
+#endif
+
+#define IMPLEMENT_CREATE_SHADER(Stage, GALLIUM) \
+ virtual HRESULT STDMETHODCALLTYPE Create##Stage##Shader( \
+ CREATE_SHADER_ARGS, \
+ __out_opt ID3D11##Stage##Shader **pp##Stage##Shader) \
+ { \
+ SYNCHRONIZED; \
+ GalliumD3D11##Stage##Shader* shader = (GalliumD3D11##Stage##Shader*)create_stage_shader(PIPE_SHADER_##GALLIUM, PASS_SHADER_ARGS); \
+ if(!shader) \
+ return E_FAIL; \
+ if(pp##Stage##Shader) \
+ { \
+ *pp##Stage##Shader = shader; \
+ return S_OK; \
+ } \
+ else \
+ { \
+ shader->Release(); \
+ return S_FALSE; \
+ } \
+ }
+
+#define IMPLEMENT_NOTIMPL_CREATE_SHADER(Stage) \
+ virtual HRESULT STDMETHODCALLTYPE Create##Stage##Shader( \
+ CREATE_SHADER_ARGS, \
+ __out_opt ID3D11##Stage##Shader **pp##Stage##Shader) \
+ { \
+ return E_NOTIMPL; \
+ }
+
+ IMPLEMENT_CREATE_SHADER(Vertex, VERTEX)
+ IMPLEMENT_CREATE_SHADER(Pixel, FRAGMENT)
+ IMPLEMENT_CREATE_SHADER(Geometry, GEOMETRY)
+#if API >= 11
+ IMPLEMENT_NOTIMPL_CREATE_SHADER(Hull)
+ IMPLEMENT_NOTIMPL_CREATE_SHADER(Domain)
+ IMPLEMENT_NOTIMPL_CREATE_SHADER(Compute)
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE CreateGeometryShaderWithStreamOutput(
+ __in const void *pShaderBytecode,
+ __in SIZE_T BytecodeLength,
+ __in_ecount_opt(NumEntries) const D3D11_SO_DECLARATION_ENTRY *pSODeclaration,
+ __in_range(0, D3D11_SO_STREAM_COUNT * D3D11_SO_OUTPUT_COMPONENT_COUNT) unsigned NumEntries,
+#if API >= 11
+ __in_ecount_opt(NumStrides) const unsigned *pBufferStrides,
+ __in_range(0, D3D11_SO_BUFFER_SLOT_COUNT) unsigned NumStrides,
+ __in unsigned RasterizedStream,
+ __in_opt ID3D11ClassLinkage *pClassLinkage,
+#else
+ __in UINT OutputStreamStride,
+#endif
+ __out_opt ID3D11GeometryShader **ppGeometryShader)
+ {
+ SYNCHRONIZED;
+
+ if(!ppGeometryShader)
+ return S_FALSE;
+
+ return E_NOTIMPL;
+
+ // remember to return S_FALSE if ppGeometyShader == NULL and the shader is OK
+ }
+
+#if API >= 11
+ virtual HRESULT STDMETHODCALLTYPE CreateClassLinkage(
+ __out ID3D11ClassLinkage **ppLinkage)
+ {
+ SYNCHRONIZED;
+
+ if(!ppLinkage)
+ return S_FALSE;
+
+ return E_NOTIMPL;
+ }
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE CreateQuery(
+ __in const D3D11_QUERY_DESC *pQueryDesc,
+ __out_opt ID3D11Query **ppQuery)
+ {
+ SYNCHRONIZED;
+
+ if(invalid(pQueryDesc->Query >= D3D11_QUERY_COUNT))
+ return E_INVALIDARG;
+ unsigned query_type = d3d11_to_pipe_query[pQueryDesc->Query];
+ if(!query_type)
+ return E_NOTIMPL;
+
+ if(ppQuery)
+ return S_FALSE;
+
+ struct pipe_query* query = immediate_pipe->create_query(immediate_pipe, query_type);
+ if(!query)
+ return E_FAIL;
+
+ *ppQuery = new GalliumD3D11Query(this, query, d3d11_query_size[pQueryDesc->Query], *pQueryDesc);
+ return S_OK;
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE CreatePredicate(
+ __in const D3D11_QUERY_DESC *pPredicateDesc,
+ __out_opt ID3D11Predicate **ppPredicate)
+ {
+ SYNCHRONIZED;
+
+ unsigned query_type;
+ switch(pPredicateDesc->Query)
+ {
+ case D3D11_QUERY_SO_OVERFLOW_PREDICATE:
+ return E_NOTIMPL;
+ case D3D11_QUERY_OCCLUSION_PREDICATE:
+ query_type = PIPE_QUERY_OCCLUSION_COUNTER;
+ break;
+ default:
+ return E_INVALIDARG;
+ }
+
+ if(ppPredicate)
+ return S_FALSE;
+
+ struct pipe_query* query = immediate_pipe->create_query(immediate_pipe, query_type);
+ if(!query)
+ return E_FAIL;
+
+ *ppPredicate = new GalliumD3D11Predicate(this, query, sizeof(BOOL), *pPredicateDesc);
+ return S_OK;
+ }
+
+
+ virtual HRESULT STDMETHODCALLTYPE CreateCounter(
+ __in const D3D11_COUNTER_DESC *pCounterDesc,
+ __out_opt ID3D11Counter **ppCounter)
+ {
+ SYNCHRONIZED;
+
+ return E_NOTIMPL;
+
+ // remember to return S_FALSE if ppCounter == NULL and everything is OK
+ }
+
+#if API >= 11
+ virtual HRESULT STDMETHODCALLTYPE CreateDeferredContext(
+ unsigned ContextFlags,
+ __out_opt ID3D11DeviceContext **ppDeferredContext)
+ {
+ SYNCHRONIZED;
+
+ // TODO: this will have to be implemented using a new Gallium util module
+ return E_NOTIMPL;
+
+ // remember to return S_FALSE if ppCounter == NULL and everything is OK
+ }
+#endif
+
+ virtual HRESULT STDMETHODCALLTYPE OpenSharedResource(
+ __in HANDLE hResource,
+ __in REFIID ReturnedInterface,
+ __out_opt void **ppResource)
+ {
+ SYNCHRONIZED;
+
+ // TODO: the problem here is that we need to communicate dimensions somehow
+ return E_NOTIMPL;
+
+ // remember to return S_FALSE if ppCounter == NULL and everything is OK
+#if 0
+ struct pipe_resou rce templat;
+ struct winsys_handle handle;
+ handle.stride = 0;
+ handle.handle = hResource;
+ handle.type = DRM_API_HANDLE_TYPE_SHARED;
+ screen->resource_from_handle(screen, &templat, &handle);
+#endif
+ }
+
+#if API < 11
+ /* these are documented as "Not implemented".
+ * According to the UMDDI documentation, they apparently turn on a
+ * (Width + 1) x (Height + 1) convolution filter for 1-bit textures.
+ * Probably nothing uses these, assuming it has ever been implemented anywhere.
+ */
+ void STDMETHODCALLTYPE SetTextFilterSize(
+ __in UINT Width,
+ __in UINT Height
+ )
+ {}
+
+ virtual void STDMETHODCALLTYPE GetTextFilterSize(
+ __in UINT *Width,
+ __in UINT *Height
+ )
+ {}
+#endif
+
+#if API >= 11
+ virtual void STDMETHODCALLTYPE RestoreGalliumState()
+ {
+ GalliumD3D11ImmediateDeviceContext_RestoreGalliumState(immediate_context);
+ }
+
+ virtual void STDMETHODCALLTYPE RestoreGalliumStateBlitOnly()
+ {
+ GalliumD3D11ImmediateDeviceContext_RestoreGalliumStateBlitOnly(immediate_context);
+ }
+#endif
+
+ virtual struct pipe_context* STDMETHODCALLTYPE GetGalliumContext(void)
+ {
+ return immediate_pipe;
+ }
+
+#undef SYNCHRONIZED
+};
diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/Makefile b/src/gallium/state_trackers/d3d1x/gd3d1x/Makefile
new file mode 100644
index 0000000..924b2f1
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d1x/Makefile
@@ -0,0 +1,6 @@
+LIBNAME=gd3d1x
+CPP_SOURCES=$(wildcard *.cpp)
+LIBRARY_INCLUDES=-Iinclude -I../gd3dapi -I../d3dapi -I../w32api -I../d3d1xstutil/include -I../d3d1xshader/include -I../../../include -I../../../auxiliary -I../../../state_trackers/egl/common
+PROGS=tools/dxbc2tgsi
+LIBS=libgd3d1x.a ../d3d1xshader/libd3d1xshader.a ../../../auxiliary/libgallium.a -ldl
+include ../Makefile.inc
diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/d3d1x_private.h b/src/gallium/state_trackers/d3d1x/gd3d1x/d3d1x_private.h
new file mode 100644
index 0000000..6756b21
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d1x/d3d1x_private.h
@@ -0,0 +1,101 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#ifndef D3D1X_PRIVATE_H_
+#define D3D1X_PRIVATE_H_
+
+#include <algorithm>
+#include <vector>
+#include <string>
+#include <float.h>
+
+#include "dxbc.h"
+#include "tpf.h"
+#include "tpf_to_tgsi.h"
+
+#include "d3d1xstutil.h"
+
+#include <d3d11.h>
+#include <d3d11shader.h>
+
+
+#include <specstrings.h>
+
+extern "C"
+{
+#include <pipe/p_defines.h>
+#include <pipe/p_screen.h>
+#include <pipe/p_context.h>
+#include <util/u_inlines.h>
+#include <util/u_format.h>
+#include <util/u_caps.h>
+#include <util/u_debug.h>
+#include <os/os_thread.h>
+}
+
+#include "galliumdxgi.h"
+#include "galliumd3d10_1.h"
+#include "galliumd3d11.h"
+
+#ifdef CHECK
+#define invalid(x) unlikely(x)
+#else
+#define invalid(x) (0)
+#endif
+
+#define D3D10_STAGE_VS 0
+#define D3D10_STAGE_PS 1
+#define D3D10_STAGE_GS 2
+#define D3D10_STAGES 3
+
+#define D3D11_STAGE_VS 0
+#define D3D11_STAGE_PS 1
+#define D3D11_STAGE_GS 2
+#define D3D11_STAGE_HS 3
+#define D3D11_STAGE_DS 4
+#define D3D11_STAGE_CS 5
+#define D3D11_STAGES 6
+
+#define D3D11_BLEND_COUNT 20
+extern unsigned d3d11_to_pipe_blend[D3D11_BLEND_COUNT];
+
+#define D3D11_USAGE_COUNT 4
+extern unsigned d3d11_to_pipe_usage[D3D11_USAGE_COUNT];
+
+#define D3D11_STENCIL_OP_COUNT 9
+extern unsigned d3d11_to_pipe_stencil_op[D3D11_STENCIL_OP_COUNT];
+
+#define D3D11_TEXTURE_ADDRESS_COUNT 6
+extern unsigned d3d11_to_pipe_wrap[D3D11_TEXTURE_ADDRESS_COUNT];
+
+#define D3D11_QUERY_COUNT 16
+extern unsigned d3d11_to_pipe_query[D3D11_QUERY_COUNT];
+extern unsigned d3d11_query_size[D3D11_QUERY_COUNT];
+
+#define D3D_PRIMITIVE_TOPOLOGY_COUNT 65
+extern unsigned d3d_to_pipe_prim[D3D_PRIMITIVE_TOPOLOGY_COUNT];
+
+#endif /* D3D1X_H_ */
diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/d3d_enums.cpp b/src/gallium/state_trackers/d3d1x/gd3d1x/d3d_enums.cpp
new file mode 100644
index 0000000..7932e43
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d1x/d3d_enums.cpp
@@ -0,0 +1,147 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "d3d1x_private.h"
+
+unsigned d3d11_to_pipe_blend[D3D11_BLEND_COUNT] =
+{
+ PIPE_BLENDFACTOR_ONE, /* absent in D3D11, but apparently accepted */
+ PIPE_BLENDFACTOR_ZERO,
+ PIPE_BLENDFACTOR_ONE,
+ PIPE_BLENDFACTOR_SRC_COLOR,
+ PIPE_BLENDFACTOR_INV_SRC_COLOR,
+ PIPE_BLENDFACTOR_SRC_ALPHA,
+ PIPE_BLENDFACTOR_INV_SRC_ALPHA,
+ PIPE_BLENDFACTOR_DST_ALPHA,
+ PIPE_BLENDFACTOR_INV_DST_ALPHA,
+ PIPE_BLENDFACTOR_DST_COLOR,
+ PIPE_BLENDFACTOR_INV_DST_COLOR,
+ PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE,
+ 0, /* absent in D3D11 */
+ 0, /* absent in D3D11 */
+ PIPE_BLENDFACTOR_CONST_COLOR,
+ PIPE_BLENDFACTOR_INV_CONST_COLOR,
+ PIPE_BLENDFACTOR_SRC1_COLOR,
+ PIPE_BLENDFACTOR_INV_SRC1_COLOR,
+ PIPE_BLENDFACTOR_SRC1_ALPHA,
+ PIPE_BLENDFACTOR_INV_SRC1_ALPHA
+};
+
+unsigned d3d11_to_pipe_usage[D3D11_USAGE_COUNT] =
+{
+ PIPE_USAGE_DEFAULT,
+ PIPE_USAGE_IMMUTABLE,
+ PIPE_USAGE_DYNAMIC,
+ PIPE_USAGE_STAGING
+};
+
+unsigned d3d11_to_pipe_stencil_op[D3D11_STENCIL_OP_COUNT] =
+{
+ PIPE_STENCIL_OP_KEEP,
+ PIPE_STENCIL_OP_KEEP,
+ PIPE_STENCIL_OP_ZERO,
+ PIPE_STENCIL_OP_REPLACE,
+ PIPE_STENCIL_OP_INCR,
+ PIPE_STENCIL_OP_DECR,
+ PIPE_STENCIL_OP_INVERT,
+ PIPE_STENCIL_OP_INCR_WRAP,
+ PIPE_STENCIL_OP_DECR_WRAP,
+};
+
+unsigned d3d11_to_pipe_wrap[D3D11_TEXTURE_ADDRESS_COUNT] =
+{
+ PIPE_TEX_WRAP_REPEAT,
+ PIPE_TEX_WRAP_REPEAT,
+ PIPE_TEX_WRAP_MIRROR_REPEAT,
+ PIPE_TEX_WRAP_CLAMP_TO_EDGE,
+ PIPE_TEX_WRAP_CLAMP_TO_BORDER,
+ PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE,
+};
+
+unsigned d3d11_to_pipe_query[D3D11_QUERY_COUNT] =
+{
+ PIPE_QUERY_GPU_FINISHED,
+ PIPE_QUERY_OCCLUSION_COUNTER,
+ PIPE_QUERY_TIME_ELAPSED,
+ PIPE_QUERY_TIMESTAMP_DISJOINT,
+ 0, /* D3D11_QUERY_PIPELINE_STATISTICS */
+ PIPE_QUERY_OCCLUSION_COUNTER,
+ PIPE_QUERY_SO_STATISTICS,
+ 0, /* D3D11_QUERY_SO_OVERFLOW_PREDICATE */
+ /* per-stream SO queries */
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+};
+
+unsigned d3d11_query_size[D3D11_QUERY_COUNT] =
+{
+ sizeof(BOOL),
+ sizeof(UINT64),
+ sizeof(UINT64),
+ sizeof(UINT64),
+ 0,
+ sizeof(BOOL),
+ sizeof(D3D11_QUERY_DATA_SO_STATISTICS),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+};
+
+unsigned d3d_to_pipe_prim[D3D_PRIMITIVE_TOPOLOGY_COUNT] =
+{
+ 0,
+ PIPE_PRIM_POINTS,
+ PIPE_PRIM_LINES,
+ PIPE_PRIM_LINE_STRIP,
+ PIPE_PRIM_TRIANGLES,
+ PIPE_PRIM_TRIANGLE_STRIP,
+ PIPE_PRIM_LINES_ADJACENCY,
+ PIPE_PRIM_LINE_STRIP_ADJACENCY,
+ PIPE_PRIM_TRIANGLES_ADJACENCY,
+ PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY,
+ /* gap */
+ 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0,
+ /* patches */
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+};
diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/tools/dxbc2tgsi.cpp b/src/gallium/state_trackers/d3d1x/gd3d1x/tools/dxbc2tgsi.cpp
new file mode 100644
index 0000000..2e5062f
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d1x/tools/dxbc2tgsi.cpp
@@ -0,0 +1,82 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "dxbc.h"
+#include "tpf.h"
+#include "../tpf_to_tgsi.h"
+#include "tgsi/tgsi_dump.h"
+#include <iostream>
+#include <fstream>
+
+void usage()
+{
+ std::cerr << "Gallium Direct3D10/11 Shader to TGSI converter\n";
+ std::cerr << "This program is free software, released under a MIT-like license\n";
+ std::cerr << "Not affiliated with or endorsed by Microsoft in any way\n";
+ std::cerr << "Latest version available from http://cgit.freedesktop.org/mesa/mesa/\n";
+ std::cerr << "\n";
+ std::cerr << "Usage: dxbc2tgsi FILE\n";
+ std::cerr << std::endl;
+}
+
+int main(int argc, char** argv)
+{
+ if(argc < 2)
+ {
+ usage();
+ return 1;
+ }
+
+ std::vector<char> data;
+ std::ifstream in(argv[1]);
+ char c;
+ in >> std::noskipws;
+ while(in >> c)
+ data.push_back(c);
+ in.close();
+
+ dxbc_container* dxbc = dxbc_parse(&data[0], data.size());
+ if(dxbc)
+ {
+ std::cout << *dxbc;
+ dxbc_chunk_header* tpf_chunk = dxbc_find_shader_bytecode(&data[0], data.size());
+ if(tpf_chunk)
+ {
+ tpf_program* tpf = tpf_parse(tpf_chunk + 1, bswap_le32(tpf_chunk->size));
+ if(tpf)
+ {
+ const struct tgsi_token* tokens = (const struct tgsi_token*)tpf_to_tgsi(*tpf);
+ if(tokens)
+ {
+ std::cout << *tpf;
+ std::cout << "\n# TGSI program: " << std::endl;
+ tgsi_dump(tokens, 0);
+ }
+ }
+ }
+ delete dxbc;
+ }
+}
diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.cpp b/src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.cpp
new file mode 100644
index 0000000..676c939
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.cpp
@@ -0,0 +1,832 @@
+/**************************************************************************
+ *
+ * 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.
+ *
+ **************************************************************************/
+
+#include "tpf.h"
+#include "tgsi/tgsi_ureg.h"
+#include <vector>
+
+#if 1
+#define check(x) assert(x)
+#define fail(x) assert(0 && (x))
+#else
+#define check(x) do {if(!(x)) throw(#x);} while(0)
+#define fail(x) throw(x)
+#endif
+
+static unsigned tpf_to_pipe_interpolation[] =
+{
+ TGSI_INTERPOLATE_PERSPECTIVE, /* UNDEFINED */
+ TGSI_INTERPOLATE_CONSTANT,
+ TGSI_INTERPOLATE_PERSPECTIVE, /* LINEAR */
+ TGSI_INTERPOLATE_PERSPECTIVE, /* LINEAR_CENTROID */
+ TGSI_INTERPOLATE_LINEAR, /* LINEAR_NOPERSPECTIVE */
+ TGSI_INTERPOLATE_LINEAR, /* LINEAR_NOPERSPECTIVE_CENTROID */
+
+ // Added in D3D10.1
+ TGSI_INTERPOLATE_PERSPECTIVE, /* LINEAR_SAMPLE */
+ TGSI_INTERPOLATE_LINEAR, /* LINEAR_NOPERSPECTIVE_SAMPLE */
+};
+
+static int tpf_to_pipe_sv[] =
+{
+ -1,
+ TGSI_SEMANTIC_POSITION,
+ -1, /*TGSI_SEMANTIC_CLIP_DISTANCE */
+ -1, /*TGSI_SEMANTIC_CULL_DISTANCE */
+ -1, /*TGSI_SEMANTIC_RENDER_TARGET_ARRAY_INDEX */
+ -1, /*TGSI_SEMANTIC_VIEWPORT_ARRAY_INDEX */
+ -1, /*TGSI_SEMANTIC_VERTEXID,*/
+ TGSI_SEMANTIC_PRIMID,
+ TGSI_SEMANTIC_INSTANCEID,
+ TGSI_SEMANTIC_FACE,
+ -1, /*TGSI_SEMANTIC_SAMPLE_INDEX*/
+};
+
+struct tpf_to_tgsi_converter
+{
+ struct ureg_program* ureg;
+ std::vector<struct ureg_dst> temps;
+ std::vector<struct ureg_dst> outputs;
+ std::vector<struct ureg_src> inputs;
+ std::vector<struct ureg_src> samplers;
+ std::vector<std::pair<unsigned, unsigned> > targets; // first is normal, second shadow/comparison
+ std::vector<unsigned> sampler_modes; // 0 = normal, 1 = shadow/comparison
+ std::vector<std::pair<unsigned, unsigned> > loops;
+ tpf_insn* insn;
+ struct tpf_program& program;
+ std::vector<unsigned> tpf_to_tgsi_insn_num;
+ std::vector<std::pair<unsigned, unsigned> > label_to_tpf_insn_num;
+ bool in_sub;
+ bool avoid_txf;
+ bool avoid_int;
+
+ tpf_to_tgsi_converter(struct tpf_program& program)
+ : program(program)
+ {
+ avoid_txf = true;
+ avoid_int = false;
+ }
+
+ struct ureg_dst _reg(tpf_op& op)
+ {
+ switch(op.file)
+ {
+ case TPF_FILE_NULL:
+ {
+ struct ureg_dst d;
+ memset(&d, 0, sizeof(d));
+ d.File = TGSI_FILE_NULL;
+ return d;
+ }
+ case TPF_FILE_TEMP:
+ check(op.has_simple_index());
+ check(op.indices[0].disp < temps.size());
+ return temps[op.indices[0].disp];
+ case TPF_FILE_OUTPUT:
+ check(op.has_simple_index());
+ check(op.indices[0].disp < outputs.size());
+ return outputs[op.indices[0].disp];
+ default:
+ check(0);
+ return ureg_dst_undef();
+ }
+ }
+
+ struct ureg_dst _dst(unsigned i = 0)
+ {
+ check(i < insn->num_ops);
+ tpf_op& op = *insn->ops[i];
+ check(op.mode == TPF_OPERAND_MODE_MASK || op.mode == TPF_OPERAND_MODE_SCALAR);
+ struct ureg_dst d = ureg_writemask(_reg(op), op.mask);
+ if(insn->insn.sat)
+ d = ureg_saturate(d);
+ return d;
+ }
+
+ struct ureg_src _src(unsigned i)
+ {
+ check(i < insn->num_ops);
+ tpf_op& op = *insn->ops[i];
+ struct ureg_src s;
+ switch(op.file)
+ {
+ case TPF_FILE_IMMEDIATE32:
+ s = ureg_imm4f(ureg, op.imm_values[0].f32, op.imm_values[1].f32, op.imm_values[2].f32, op.imm_values[3].f32);
+ break;
+ case TPF_FILE_INPUT:
+ check(op.has_simple_index());
+ check(op.indices[0].disp < inputs.size());
+ s = inputs[op.indices[0].disp];
+ break;
+ case TPF_FILE_CONSTANT_BUFFER:
+ // TODO: indirect addressing
+ check(op.num_indices == 2);
+ check(op.is_index_simple(0));
+ check(op.is_index_simple(1));
+ s = ureg_src_register(TGSI_FILE_CONSTANT, (unsigned)op.indices[1].disp);
+ s.Dimension = 1;
+ s.DimensionIndex = op.indices[0].disp;
+ break;
+ default:
+ s = ureg_src(_reg(op));
+ break;
+ }
+ if(op.mode == TPF_OPERAND_MODE_SWIZZLE || op.mode == TPF_OPERAND_MODE_SCALAR)
+ s = ureg_swizzle(s, op.swizzle[0], op.swizzle[1], op.swizzle[2], op.swizzle[3]);
+ else
+ {
+ /* immediates are masked to show needed values */
+ check(op.file == TPF_FILE_IMMEDIATE32 || op.file == TPF_FILE_IMMEDIATE64);
+ }
+ if(op.abs)
+ s = ureg_abs(s);
+ if(op.neg)
+ s = ureg_negate(s);
+ return s;
+ };
+
+ int _idx(tpf_file file, unsigned i = 0)
+ {
+ check(i < insn->num_ops);
+ tpf_op& op = *insn->ops[i];
+ check(op.file == file);
+ check(op.has_simple_index());
+ return (int)op.indices[0].disp;
+ }
+
+ int _texslot(bool have_sampler = true)
+ {
+ std::map<std::pair<int, int>, int>::iterator i;
+ i = program.resource_sampler_to_slot.find(std::make_pair(_idx(TPF_FILE_RESOURCE, 2), have_sampler ? _idx(TPF_FILE_SAMPLER, 3) : -1));
+ check(i != program.resource_sampler_to_slot.end());
+ return i->second;
+ }
+
+ unsigned tex_target(unsigned texslot)
+ {
+ unsigned mode = sampler_modes[program.slot_to_sampler[texslot]];
+ unsigned target;
+ if(mode)
+ target = targets[program.slot_to_resource[texslot]].second;
+ else
+ target = targets[program.slot_to_resource[texslot]].first;
+ check(target);
+ return target;
+ }
+
+ std::vector<struct ureg_dst> insn_tmps;
+
+ struct ureg_dst _tmp()
+ {
+ struct ureg_dst t = ureg_DECL_temporary(ureg);
+ insn_tmps.push_back(t);
+ return t;
+ }
+
+ struct ureg_dst _tmp(struct ureg_dst d)
+ {
+ if(d.File == TGSI_FILE_TEMPORARY)
+ return d;
+ else
+ return ureg_writemask(_tmp(), d.WriteMask);
+ }
+
+#define OP1_(d, g) case TPF_OPCODE_##d: ureg_##g(ureg, _dst(), _src(1)); break
+#define OP2_(d, g) case TPF_OPCODE_##d: ureg_##g(ureg, _dst(), _src(1), _src(2)); break
+#define OP3_(d, g) case TPF_OPCODE_##d: ureg_##g(ureg, _dst(), _src(1), _src(2), _src(3)); break
+#define OP1(n) OP1_(n, n)
+#define OP2(n) OP2_(n, n)
+#define OP3(n) OP3_(n, n)
+#define OP_CF(d, g) case TPF_OPCODE_##d: ureg_##g(ureg, &label); label_to_tpf_insn_num.push_back(std::make_pair(label, program.cf_insn_linked[insn_num])); break;
+
+ void translate_insns(unsigned begin, unsigned end)
+ {
+ for(unsigned insn_num = begin; insn_num < end; ++insn_num)
+ {
+ tpf_to_tgsi_insn_num[insn_num] = ureg_get_instruction_number(ureg);
+ unsigned label;
+ insn = program.insns[insn_num];
+ bool ok;
+ ok = true;
+ switch(insn->opcode)
+ {
+ // trivial instructions
+ case TPF_OPCODE_NOP:
+ break;
+ OP1(MOV);
+
+ // float
+ OP2(ADD);
+ OP2(MUL);
+ OP3(MAD);
+ OP2(DIV);
+ OP1(FRC);
+ OP1(RCP);
+ OP2(MIN);
+ OP2(MAX);
+ OP2_(LT, SLT);
+ OP2_(GE, SGE);
+ OP2_(EQ, SEQ);
+ OP2_(NE, SNE);
+
+ // bitwise
+ OP1(NOT);
+ OP2(AND);
+ OP2(OR);
+ OP2(XOR);
+
+ // special mathematical
+ OP2(DP2);
+ OP2(DP3);
+ OP2(DP4);
+ OP1(RSQ);
+ OP1_(LOG, LG2);
+ OP1_(EXP, EX2);
+
+ // rounding
+ OP1_(ROUND_NE, ROUND);
+ OP1_(ROUND_Z, TRUNC);
+ OP1_(ROUND_PI, CEIL);
+ OP1_(ROUND_NI, FLR);
+
+ // cross-thread
+ OP1_(DERIV_RTX, DDX);
+ OP1_(DERIV_RTX_COARSE, DDX);
+ OP1_(DERIV_RTX_FINE, DDX);
+ OP1_(DERIV_RTY, DDY);
+ OP1_(DERIV_RTY_COARSE, DDY);
+ OP1_(DERIV_RTY_FINE, DDY);
+ case TPF_OPCODE_EMIT:
+ ureg_EMIT(ureg);
+ break;
+ case TPF_OPCODE_CUT:
+ ureg_ENDPRIM(ureg);
+ break;
+ case TPF_OPCODE_EMITTHENCUT:
+ ureg_EMIT(ureg);
+ ureg_ENDPRIM(ureg);
+ break;
+
+ // non-trivial instructions
+ case TPF_OPCODE_MOVC:
+ /* CMP checks for < 0, but MOVC checks for != 0
+ * but fortunately, x != 0 is equivalent to -abs(x) < 0
+ * XXX: can test_nz apply to this?!
+ */
+ ureg_CMP(ureg, _dst(), ureg_negate(ureg_abs(_src(1))), _src(2), _src(3));
+ break;
+ case TPF_OPCODE_SQRT:
+ {
+ struct ureg_dst d = _dst();
+ struct ureg_dst t = _tmp(d);
+ ureg_RSQ(ureg, t, _src(1));
+ ureg_RCP(ureg, d, ureg_src(t));
+ break;
+ }
+ case TPF_OPCODE_SINCOS:
+ {
+ struct ureg_dst s = _dst(0);
+ struct ureg_dst c = _dst(1);
+ struct ureg_src v = _src(2);
+ if(s.File != TGSI_FILE_NULL)
+ ureg_SIN(ureg, s, v);
+ if(c.File != TGSI_FILE_NULL)
+ ureg_COS(ureg, c, v);
+ break;
+ }
+
+ // control flow
+ case TPF_OPCODE_DISCARD:
+ ureg_KIL(ureg, _src(0));
+ break;
+ OP_CF(LOOP, BGNLOOP);
+ OP_CF(ENDLOOP, ENDLOOP);
+ case TPF_OPCODE_BREAK:
+ ureg_BRK(ureg);
+ break;
+ case TPF_OPCODE_BREAKC:
+ // XXX: can test_nz apply to this?!
+ ureg_BREAKC(ureg, _src(0));
+ break;
+ case TPF_OPCODE_CONTINUE:
+ ureg_CONT(ureg);
+ break;
+ case TPF_OPCODE_CONTINUEC:
+ // XXX: can test_nz apply to this?!
+ ureg_IF(ureg, _src(0), &label);
+ ureg_CONT(ureg);
+ ureg_fixup_label(ureg, label, ureg_get_instruction_number(ureg));
+ ureg_ENDIF(ureg);
+ break;
+ case TPF_OPCODE_SWITCH:
+ ureg_SWITCH(ureg, _src(0));
+ break;
+ case TPF_OPCODE_CASE:
+ ureg_CASE(ureg, _src(0));
+ break;
+ case TPF_OPCODE_DEFAULT:
+ ureg_DEFAULT(ureg);
+ break;
+ case TPF_OPCODE_ENDSWITCH:
+ ureg_ENDSWITCH(ureg);
+ break;
+ case TPF_OPCODE_CALL:
+ ureg_CAL(ureg, &label);
+ label_to_tpf_insn_num.push_back(std::make_pair(label, program.label_to_insn_num[_idx(TPF_FILE_LABEL)]));
+ break;
+ case TPF_OPCODE_LABEL:
+ if(in_sub)
+ ureg_ENDSUB(ureg);
+ else
+ ureg_END(ureg);
+ ureg_BGNSUB(ureg);
+ in_sub = true;
+ break;
+ case TPF_OPCODE_RET:
+ if(in_sub || insn_num != (program.insns.size() - 1))
+ ureg_RET(ureg);
+ break;
+ case TPF_OPCODE_RETC:
+ ureg_IF(ureg, _src(0), &label);
+ if(insn->insn.test_nz)
+ ureg_RET(ureg);
+ ureg_fixup_label(ureg, label, ureg_get_instruction_number(ureg));
+ if(!insn->insn.test_nz)
+ {
+ ureg_ELSE(ureg, &label);
+ ureg_RET(ureg);
+ ureg_fixup_label(ureg, label, ureg_get_instruction_number(ureg));
+ }
+ ureg_ENDIF(ureg);
+ break;
+ OP_CF(ELSE, ELSE);
+ case TPF_OPCODE_ENDIF:
+ ureg_ENDIF(ureg);
+ break;
+ case TPF_OPCODE_IF:
+ if(insn->insn.test_nz)
+ {
+ ureg_IF(ureg, _src(0), &label);
+ label_to_tpf_insn_num.push_back(std::make_pair(label, program.cf_insn_linked[insn_num]));
+ }
+ else
+ {
+ unsigned linked = program.cf_insn_linked[insn_num];
+ if(program.insns[linked]->opcode == TPF_OPCODE_ENDIF)
+ {
+ ureg_IF(ureg, _src(0), &label);
+ ureg_fixup_label(ureg, label, ureg_get_instruction_number(ureg));
+ ureg_ELSE(ureg, &label);
+ label_to_tpf_insn_num.push_back(std::make_pair(label, linked));
+ }
+ else
+ {
+ /* we have to swap the branches in this case (fun!)
+ * TODO: maybe just emit a SEQ 0?
+ * */
+ unsigned endif = program.cf_insn_linked[linked];
+
+ ureg_IF(ureg, _src(0), &label);
+ label_to_tpf_insn_num.push_back(std::make_pair(label, linked));
+
+ translate_insns(linked + 1, endif);
+
+ tpf_to_tgsi_insn_num[linked] = ureg_get_instruction_number(ureg);
+ ureg_ELSE(ureg, &label);
+ label_to_tpf_insn_num.push_back(std::make_pair(label, endif));
+
+ translate_insns(insn_num + 1, linked);
+
+ insn_num = endif - 1;
+ goto next;
+ }
+ }
+ break;
+ case TPF_OPCODE_RESINFO:
+ {
+ std::map<int, int>::iterator i;
+ i = program.resource_to_slot.find(_idx(TPF_FILE_RESOURCE, 2));
+ check(i != program.resource_to_slot.end());
+ unsigned texslot = i->second;
+
+ // no driver actually provides this, unfortunately
+ ureg_TXQ(ureg, _dst(), tex_target(texslot), _src(1), samplers[texslot]);
+ break;
+ };
+ // TODO: sample offset, sample index
+ case TPF_OPCODE_LD: // dst, coord_int, res; mipmap level in last coord_int arg (ouch)
+ case TPF_OPCODE_LD_MS:
+ {
+ unsigned texslot = _texslot(false);
+ unsigned dim;
+ switch(targets[texslot].first)
+ {
+ case TGSI_TEXTURE_1D:
+ dim = 1;
+ break;
+ case TGSI_TEXTURE_2D:
+ case TGSI_TEXTURE_RECT:
+ dim = 2;
+ break;
+ case TGSI_TEXTURE_3D:
+ dim = 3;
+ break;
+ default:
+ check(0);
+ }
+ struct ureg_dst tmp = _tmp();
+ if(avoid_txf)
+ {
+ struct ureg_src texcoord;
+ if(!avoid_int)
+ {
+ ureg_I2F(ureg, tmp, _src(1));
+ texcoord = ureg_src(tmp);
+ }
+ else
+ texcoord = _src(1);
+
+ ureg_TXL(ureg, _dst(), tex_target(texslot), ureg_swizzle(texcoord, 0, 1, 2, dim), samplers[texslot]);
+ }
+ else
+ ureg_TXF(ureg, _dst(), tex_target(texslot), ureg_swizzle(_src(1), 0, 1, 2, dim), samplers[texslot]);
+ break;
+ }
+ case TPF_OPCODE_SAMPLE: // dst, coord, res, samp
+ {
+ unsigned texslot = _texslot();
+ ureg_TEX(ureg, _dst(), tex_target(texslot), _src(1), samplers[texslot]);
+ break;
+ }
+ case TPF_OPCODE_SAMPLE_B: // dst, coord, res, samp, bias.x
+ {
+ unsigned texslot = _texslot();
+ struct ureg_dst tmp = _tmp();
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_XYZ), _src(1));
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_W), ureg_swizzle(_src(4), 0, 0, 0, 0));
+ ureg_TXB(ureg, _dst(), tex_target(texslot), ureg_src(tmp), samplers[texslot]);
+ break;
+ }
+ case TPF_OPCODE_SAMPLE_C: // dst, coord, res, samp, comp.x
+ {
+ unsigned texslot = _texslot();
+ struct ureg_dst tmp = _tmp();
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_XY), _src(1));
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_Z), ureg_swizzle(_src(4), 0, 0, 0, 0));
+ ureg_TEX(ureg, _dst(), tex_target(texslot), ureg_src(tmp), samplers[texslot]);
+ break;
+ }
+ case TPF_OPCODE_SAMPLE_C_LZ: // dst, coord, res, samp, comp.x
+ {
+ unsigned texslot = _texslot();
+ struct ureg_dst tmp = _tmp();
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_XY), _src(1));
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_Z), ureg_swizzle(_src(4), 0, 0, 0, 0));
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_W), ureg_imm1f(ureg, 0.0));
+ ureg_TXL(ureg, _dst(), tex_target(texslot), ureg_src(tmp), samplers[texslot]);
+ break;
+ }
+ case TPF_OPCODE_SAMPLE_D: // dst, coord, res, samp, ddx, ddy
+ {
+ unsigned texslot = _texslot();
+ ureg_TXD(ureg, _dst(), tex_target(texslot), _src(1), samplers[texslot], _src(4), _src(5));
+ break;
+ }
+ case TPF_OPCODE_SAMPLE_L: // dst, coord, res, samp, bias.x
+ {
+ unsigned texslot = _texslot();
+ struct ureg_dst tmp = _tmp();
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_XYZ), _src(1));
+ ureg_MOV(ureg, ureg_writemask(tmp, TGSI_WRITEMASK_W), ureg_swizzle(_src(4), 0, 0, 0, 0));
+ ureg_TXL(ureg, _dst(), tex_target(texslot), ureg_src(tmp), samplers[texslot]);
+ break;
+ }
+ default:
+ ok = false;
+ break;
+ }
+
+ if(!ok && !avoid_int)
+ {
+ ok = true;
+ switch(insn->opcode)
+ {
+ // integer
+ OP1_(ITOF, I2F);
+ OP1_(FTOI, F2I);
+ OP2_(IADD, UADD);
+ OP1(INEG);
+ OP2_(IMUL, UMUL);
+ OP3_(IMAD, UMAD);
+ OP2_(ISHL, SHL);
+ OP2_(ISHR, ISHR);
+ OP2(IMIN);
+ OP2(IMAX);
+ OP2_(ILT, ISLT);
+ OP2_(IGE, ISGE);
+ OP2_(IEQ, USEQ);
+ OP2_(INE, USNE);
+
+ // unsigned
+ OP1_(UTOF, U2F);
+ OP1_(FTOU, F2U);
+ OP2(UMUL);
+ OP3(UMAD);
+ OP2(UMIN);
+ OP2(UMAX);
+ OP2_(ULT, USLT);
+ OP2_(UGE, USGE);
+ OP2(USHR);
+
+ case TPF_OPCODE_UDIV:
+ {
+ struct ureg_dst q = _dst(0);
+ struct ureg_dst r = _dst(1);
+ struct ureg_src a = _src(2);
+ struct ureg_src b = _src(3);
+ if(q.File != TGSI_FILE_NULL)
+ ureg_UDIV(ureg, q, a, b);
+ if(r.File != TGSI_FILE_NULL)
+ ureg_UMOD(ureg, r, a, b);
+ break;
+ }
+ default:
+ ok = false;
+ }
+ }
+
+ if(!ok && avoid_int)
+ {
+ ok = true;
+ switch(insn->opcode)
+ {
+ case TPF_OPCODE_ITOF:
+ case TPF_OPCODE_UTOF:
+ break;
+ OP1_(FTOI, TRUNC);
+ OP1_(FTOU, FLR);
+ // integer
+ OP2_(IADD, ADD);
+ OP2_(IMUL, MUL);
+ OP3_(IMAD, MAD);
+ OP2_(MIN, MIN);
+ OP2_(MAX, MAX);
+ OP2_(ILT, SLT);
+ OP2_(IGE, SGE);
+ OP2_(IEQ, SEQ);
+ OP2_(INE, SNE);
+
+ // unsigned
+ OP2_(UMUL, MUL);
+ OP3_(UMAD, MAD);
+ OP2_(UMIN, MIN);
+ OP2_(UMAX, MAX);
+ OP2_(ULT, SLT);
+ OP2_(UGE, SGE);
+
+ case TPF_OPCODE_INEG:
+ ureg_MOV(ureg, _dst(), ureg_negate(_src(1)));
+ break;
+ case TPF_OPCODE_ISHL:
+ {
+ struct ureg_dst d = _dst();
+ struct ureg_dst t = _tmp(d);
+ ureg_EX2(ureg, t, _src(2));
+ ureg_MUL(ureg, d, ureg_src(t), _src(1));
+ break;
+ }
+ case TPF_OPCODE_ISHR:
+ case TPF_OPCODE_USHR:
+ {
+ struct ureg_dst d = _dst();
+ struct ureg_dst t = _tmp(d);
+ ureg_EX2(ureg, t, ureg_negate(_src(2)));
+ ureg_MUL(ureg, t, ureg_src(t), _src(1));
+ ureg_FLR(ureg, d, ureg_src(t));
+ break;
+ }
+ case TPF_OPCODE_UDIV:
+ {
+ struct ureg_dst q = _dst(0);
+ struct ureg_dst r = _dst(1);
+ struct ureg_src a = _src(2);
+ struct ureg_src b = _src(3);
+ struct ureg_dst f = _tmp();
+ ureg_DIV(ureg, f, a, b);
+ if(q.File != TGSI_FILE_NULL)
+ ureg_FLR(ureg, q, ureg_src(f));
+ if(r.File != TGSI_FILE_NULL)
+ {
+ ureg_FRC(ureg, f, ureg_src(f));
+ ureg_MUL(ureg, r, ureg_src(f), b);
+ }
+ break;
+ }
+ default:
+ ok = false;
+ }
+ }
+
+ check(ok);
+
+ if(!insn_tmps.empty())
+ {
+ for(unsigned i = 0; i < insn_tmps.size(); ++i)
+ ureg_release_temporary(ureg, insn_tmps[i]);
+ insn_tmps.clear();
+ }
+next:;
+ }
+ }
+
+ void* do_translate()
+ {
+ unsigned processor;
+ switch(program.version.type)
+ {
+ case 0:
+ processor = TGSI_PROCESSOR_FRAGMENT;
+ break;
+ case 1:
+ processor = TGSI_PROCESSOR_VERTEX;
+ break;
+ case 2:
+ processor = TGSI_PROCESSOR_GEOMETRY;
+ break;
+ default:
+ fail("Tessellation and compute shaders not yet supported");
+ return 0;
+ }
+
+ if(!tpf_link_cf_insns(program))
+ fail("Malformed control flow");
+ if(!tpf_find_labels(program))
+ fail("Failed to locate labels");
+ if(!tpf_allocate_resource_sampler_pairs(program))
+ fail("Unsupported (indirect?) accesses to resources and/or samplers");
+
+ ureg = ureg_create(processor);
+
+ in_sub = false;
+
+ for(unsigned i = 0; i < program.slot_to_resource.size(); ++i)
+ samplers.push_back(ureg_DECL_sampler(ureg, i));
+
+ tpf_to_tgsi_insn_num.resize(program.insns.size());
+ for(unsigned insn_num = 0; insn_num < program.dcls.size(); ++insn_num)
+ {
+ tpf_dcl& dcl = *program.dcls[insn_num];
+ int idx = -1;
+ if(dcl.op.get() && dcl.op->has_simple_index())
+ idx = dcl.op->indices[0].disp;
+ switch(dcl.opcode)
+ {
+ case TPF_OPCODE_DCL_GLOBAL_FLAGS:
+ break;
+ case TPF_OPCODE_DCL_TEMPS:
+ for(unsigned i = 0; i < dcl.num; ++i)
+ temps.push_back(ureg_DECL_temporary(ureg));
+ break;
+ case TPF_OPCODE_DCL_INPUT:
+ check(idx >= 0);
+ if(inputs.size() <= (unsigned)idx)
+ inputs.resize(idx + 1);
+ if(processor == TGSI_PROCESSOR_VERTEX)
+ inputs[idx] = ureg_DECL_vs_input(ureg, idx);
+ else
+ check(0);
+ break;
+ case TPF_OPCODE_DCL_INPUT_PS:
+ check(idx >= 0);
+ if(inputs.size() <= (unsigned)idx)
+ inputs.resize(idx + 1);
+ inputs[idx] = ureg_DECL_fs_input(ureg, TGSI_SEMANTIC_GENERIC, idx, tpf_to_pipe_interpolation[dcl.dcl_input_ps.interpolation]);
+ break;
+ case TPF_OPCODE_DCL_OUTPUT:
+ check(idx >= 0);
+ if(outputs.size() <= (unsigned)idx)
+ outputs.resize(idx + 1);
+ if(processor == TGSI_PROCESSOR_FRAGMENT)
+ outputs[idx] = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, idx);
+ else
+ outputs[idx] = ureg_DECL_output(ureg, TGSI_SEMANTIC_GENERIC, idx);
+ break;
+ case TPF_OPCODE_DCL_INPUT_SIV:
+ case TPF_OPCODE_DCL_INPUT_SGV:
+ case TPF_OPCODE_DCL_INPUT_PS_SIV:
+ case TPF_OPCODE_DCL_INPUT_PS_SGV:
+ check(idx >= 0);
+ if(inputs.size() <= (unsigned)idx)
+ inputs.resize(idx + 1);
+ // TODO: is this correct?
+ inputs[idx] = ureg_DECL_system_value(ureg, idx, tpf_to_pipe_sv[dcl.sv], 0);
+ break;
+ case TPF_OPCODE_DCL_OUTPUT_SIV:
+ case TPF_OPCODE_DCL_OUTPUT_SGV:
+ check(idx >= 0);
+ if(outputs.size() <= (unsigned)idx)
+ outputs.resize(idx + 1);
+ check(tpf_to_pipe_sv[dcl.sv] >= 0);
+ outputs[idx] = ureg_DECL_output(ureg, tpf_to_pipe_sv[dcl.sv], 0);
+ break;
+ case TPF_OPCODE_DCL_RESOURCE:
+ check(idx >= 0);
+ if(targets.size() <= (unsigned)idx)
+ targets.resize(idx + 1);
+ switch(dcl.dcl_resource.target)
+ {
+ case TPF_TARGET_TEXTURE1D:
+ targets[idx].first = TGSI_TEXTURE_1D;
+ targets[idx].second = TGSI_TEXTURE_SHADOW1D;
+ break;
+ case TPF_TARGET_TEXTURE2D:
+ targets[idx].first = TGSI_TEXTURE_2D;
+ targets[idx].second = TGSI_TEXTURE_SHADOW2D;
+ break;
+ case TPF_TARGET_TEXTURE3D:
+ targets[idx].first = TGSI_TEXTURE_3D;
+ targets[idx].second = 0;
+ break;
+ case TPF_TARGET_TEXTURECUBE:
+ targets[idx].first = TGSI_TEXTURE_CUBE;
+ targets[idx].second = 0;
+ break;
+ default:
+ check(0);
+ }
+ break;
+ case TPF_OPCODE_DCL_SAMPLER:
+ check(idx >= 0);
+ if(sampler_modes.size() <= (unsigned)idx)
+ sampler_modes.resize(idx + 1);
+ check(!dcl.dcl_sampler.mono);
+ sampler_modes[idx] = dcl.dcl_sampler.shadow;
+ break;
+ case TPF_OPCODE_DCL_CONSTANT_BUFFER:
+ check(dcl.op->num_indices == 2);
+ check(dcl.op->is_index_simple(0));
+ check(dcl.op->is_index_simple(1));
+ idx = dcl.op->indices[0].disp;
+ ureg_DECL_constant2D(ureg, 0, (unsigned)dcl.op->indices[1].disp - 1, idx);
+ break;
+ default:
+ check(0);
+ }
+ }
+
+ translate_insns(0, program.insns.size());
+ tpf_to_tgsi_insn_num.push_back(ureg_get_instruction_number(ureg));
+ if(in_sub)
+ ureg_ENDSUB(ureg);
+ else
+ ureg_END(ureg);
+
+ for(unsigned i = 0; i < label_to_tpf_insn_num.size(); ++i)
+ ureg_fixup_label(ureg, label_to_tpf_insn_num[i].first, tpf_to_tgsi_insn_num[label_to_tpf_insn_num[i].second]);
+
+ const struct tgsi_token * tokens = ureg_get_tokens(ureg, 0);
+ ureg_destroy(ureg);
+ return (void*)tokens;
+ }
+
+ void* translate()
+ {
+ try
+ {
+ return do_translate();
+ }
+ catch(const char*)
+ {
+ return 0;
+ }
+ }
+};
+
+void* tpf_to_tgsi(struct tpf_program& program)
+{
+ tpf_to_tgsi_converter conv(program);
+ return conv.translate();
+}
diff --git a/src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.h b/src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.h
new file mode 100644
index 0000000..68a30d2
--- /dev/null
+++ b/src/gallium/state_trackers/d3d1x/gd3d1x/tpf_to_tgsi.h
@@ -0,0 +1,34 @@
+/**************************************************************************
+ *
+ * Copyright 2010 Luca Barbieri
+ *
+ * Permission is h