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.
This commit is contained in:
Luca Barbieri 2010-09-12 02:49:36 +02:00
parent 894a307a91
commit 92617aeac1
108 changed files with 26335 additions and 0 deletions

View File

@ -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:

View File

@ -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 $@ $<

View File

@ -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

View File

@ -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_ */

View File

@ -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_ */

View File

@ -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_ */

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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",
};

View File

@ -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_ */

View File

@ -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;
}
}

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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;
}
}

View File

@ -0,0 +1,4 @@
all: idl
include ../Makefile.inc

File diff suppressed because it is too large Load Diff

View File

@ -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
);

View File

@ -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__ */

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

@ -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
);
};

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -0,0 +1,4 @@
all: module_dependencies.svg module_dependencies.pdf
include ../Makefile.inc

View File

@ -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.

View File

@ -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
};

View File

@ -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

View File

@ -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

View File

@ -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;
}

File diff suppressed because it is too large Load Diff

View File

@ -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_ */

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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) $< > $@

View File

@ -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 $_;
}

View File

@ -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

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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;
}
};

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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_ */

View File

@ -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,
};

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -0,0 +1,34 @@
/**************************************************************************
*
* 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_TO_TGSI_H_
#define TPF_TO_TGSI_H_
#include "tpf.h"
void* tpf_to_tgsi(struct tpf_program& program);
#endif /* TPF_TO_TGSI_H_ */

View File

@ -0,0 +1,4 @@
all: idl
include ../Makefile.inc

View File

@ -0,0 +1,76 @@
/**************************************************************************
*
* Copyright 2010 Luca Barbieri
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/* Header for all COM-based Gallium APIs and state trackers */
import "oaidl.idl";
import "ocidl.idl";
[object, local, uuid("481c9372-795f-4630-bd5b-1f46d33cc28b")]
interface IGalliumAdapter : IUnknown
{
struct pipe_screen* GetGalliumScreen();
struct pipe_screen* GetGalliumReferenceSoftwareScreen();
struct pipe_screen* GetGalliumFastSoftwareScreen();
}
[object, local, uuid("2c0f7e72-d9fe-4e7b-9fee-d476695ad5d9")]
interface IGalliumDevice : IUnknown
{
// turn Gallium resource into API resource
HRESULT OpenGalliumResource(
[in] struct pipe_resource* resource,
[out] IUnknown** api_resource
);
/* returns the Gallium context used by the device
* can return NULL if the device uses multiple contexts or doesn't want to implement GetGalliumContext()
* we have this function because often using one context is faster than using more (or it's the only working option)
*/
struct pipe_context* GetGalliumContext();
// restore the context state after using the Gallium context for something else
// does nothing if GetGalliumContext returns null
void RestoreGalliumState();
/* like RestoreGalliumState, but ignores:
* - constant buffers
* - non-PS samplers and shader resource views
* - blend color, sample mask
* - scissor
* - index buffer
*
* This is intended to restore state after a blit-like operation.
*/
void RestoreGalliumStateBlitOnly();
};
[object, local, uuid("61934787-7aea-412c-8c72-8afe6a33d622")]
interface IGalliumResource : IUnknown
{
struct pipe_resource* GetGalliumResource();
};

View File

@ -0,0 +1,30 @@
/**************************************************************************
*
* Copyright 2010 Luca Barbieri
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
import "ocidl.idl";
import "d3d10_1.idl";
HRESULT GalliumD3D10DeviceCreate1(struct pipe_screen* screen, struct pipe_context* context, BOOL owns_context, unsigned creation_flags, IDXGIAdapter* adapter, ID3D10Device1** ppDevice);

View File

@ -0,0 +1,31 @@
/**************************************************************************
*
* Copyright 2010 Luca Barbieri
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
import "ocidl.idl";
import "d3d11.idl";
HRESULT GalliumD3D11DeviceCreate(struct pipe_screen* screen, struct pipe_context* context, BOOL owns_context, unsigned creation_flags, IDXGIAdapter* adapter, ID3D11Device** ppDevice);

View File

@ -0,0 +1,77 @@
/**************************************************************************
*
* Copyright 2010 Luca Barbieri
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/* Header for the Gallium extensions to DXGI */
import "galliumcom.idl";
import "../d3dapi/dxgi.idl";
/* These calls set the display system that will be associated
* to new DXGI factories created with CreateDXGIFactory and
* CreateDXGIFactory1 by the current thread.
*
* Existing factories and DXGI objects created from them are
* not affected.
*
* Gallium DXGI has both per-thread and per-process settings.
* If the per-thread display system has been set (i.e. a function
* of these was called, and the last one called was not UseNothing),
* it will be used.
* Otherwise, the per-process display system will be used if set, or
* and other the factory creation call may either fail, or use an
* user-specified default..
*
* The per-process setting can be altered by calling
* GalliumDXGIMakeDefault, which will set the per-process setting
* according to the current per-thread setting.
*
* GalliumDXGIUseNothing() is the initial state, which means that
* the per-process default should be used, and if that is "use nothing"
* too, the call will either fail or use a user-specified default.
*
* NOTE that setting the per-process default is NOT atomic and must
* not be done concurrently with other calls to GalliumDXGIMakeDefault,
* CreateDXGIFactory or CreateDXGIFactory1.
*
* The PFNHWNDRESOLVER function is passed HWNDs coming from
* the API user and must return window-system-specific values:
* - X11: Window*
* - GDI: HWND
*/
typedef struct _XDisplay Display;
typedef void* (*PFNHWNDRESOLVER)(void*, HWND);
void GalliumDXGIUseNothing();
/* only a subset of these may be available, depending on platform and compilation options */
void GalliumDXGIUseX11Display(Display* dpy, PFNHWNDRESOLVER resolver, void* resolver_cookie);
void GalliumDXGIUseDRMCard(int fd);
void GalliumDXGIUseFBDev(int fd);
void GalliumDXGIUseHDC(HDC hdc, PFNHWNDRESOLVER resolver, void* resolver_cookie);
void GalliumDXGIMakeDefault();

View File

@ -0,0 +1,73 @@
#!/bin/bash
ok=1
for i in fxc.exe D3DCompiler_43.dll d3dx9_43.dll d3dx10_43.dll d3dx11_43.dll; do
if ! test -e "$i"; then
ok=
fi
done
if test -n "$ok"; then
exit 0
fi
echo "To compile HLSL shaders, the Microsoft HLSL compiler needs to be downloaded."
echo
echo "Downloading Microsoft DirectX June 2010 SDK and extracting files..."
echo "Please wait, this will need to download and unpack a 600 MB file..."
echo
echo "The contribution of a free HLSL compiler would be greatly appreciated!"
echo
ok=1
if ! which wget >/dev/null; then
echo "Error: wget is required to download the files"
echo "On Debian or Ubuntu, run the following command to install it:"
echo "sudo apt-get install wget"
echo
ok=
fi
if ! which cabextract >/dev/null; then
echo "Error: cabextract is required to unpack the files"
echo "On Debian or Ubuntu, run the following command to install it:"
echo "sudo apt-get install cabextract"
echo
ok=
fi
if test -z "$ok"; then
exit 1
fi
dxsdk_file="DXSDK_Jun10.exe"
dxsdk_url="http://download.microsoft.com/download/A/E/7/AE743F1F-632B-4809-87A9-AA1BB3458E31/DXSDK_Jun10.exe"
dxsdk_size=599452800
fxc_path="DXSDK/Utilities/bin/x86/fxc.exe"
d3dcompiler_cab_path="DXSDK/Redist/Jun2010_D3DCompiler_43_x86.cab"
d3dx9_cab_path="DXSDK/Redist/Jun2010_d3dx9_43_x86.cab"
d3dx10_cab_path="DXSDK/Redist/Jun2010_d3dx10_43_x86.cab"
d3dx11_cab_path="DXSDK/Redist/Jun2010_d3dx11_43_x86.cab"
if test "$(stat -c '%s' "$dxsdk_file" 2>/dev/null)" != $dxsdk_size; then
wget --continue "$dxsdk_url"
if test "$(stat -c '%s' "$dxsdk_file" 2>/dev/null)" != $dxsdk_size; then
echo "Failed to download DirectX SDK: expected $dxsdk_file with size $dxsdk_size"
echo "Download manually from $dxsdk_url"
exit 1
fi
fi
for i in "$fxc_path" "$d3dcompiler_cab_path" "$d3dx9_cab_path" "$d3dx10_cab_path" "$d3dx11_cab_path"; do
if ! test -e "$i"; then
echo "Please wait, this may take several minutes because a 600 MB archive may need to be fully decompressed..."
cabextract -F "$i" "$dxsdk_file"
fi
done
for i in "$d3dcompiler_cab_path" "$d3dx9_cab_path" "$d3dx10_cab_path" "$d3dx11_cab_path"; do
cabextract -F "*.dll" "$i"
done
/bin/cp -dpf "$fxc_path" .

View File

@ -0,0 +1,32 @@
LIBRARY_INCLUDES = -Id3d10app -Id3d11app -I../gd3dapi -I../d3dapi -I../w32api
LIBS= \
../dxgi/libdxgi.a \
../gd3d1x/libgd3d1x.a \
../d3d1xshader/libd3d1xshader.a \
../d3d1xstutil/libd3d1xstutil.a \
../../egl/libegl.a \
../../../auxiliary/libgallium.a \
../../../winsys/sw/wrapper/libwsw.a \
../../../winsys/sw/xlib/libws_xlib.a \
../../../winsys/sw/dri/libswdri.a \
../../../winsys/sw/fbdev/libfbdev.a \
../../../../../lib/libEGL.so
LIBS_D3D10 = ../dxgid3d10/libdxgid3d10.a ../gd3d10/libgd3d10.a $(LIBS)
LIBS_D3D11 = ../dxgid3d11/libdxgid3d11.a ../gd3d11/libgd3d11.a $(LIBS)
LDADD=-lGL -lXext -lXfixes -lX11 -ldrm -ldl
all: bin/d3d10tri bin/d3d11tri bin/d3d11tex bin/d3d11gears
include ../Makefile.inc
bin/d3d10tri: d3d10app/d3d10x11main.o d3d10tri/d3d10tri.o $(LIBS_D3D10)
$(CXX) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D10) -Wl,--end-group $(LDADD)
bin/d3d11tri: d3d11app/d3d11x11main.o d3d11tri/d3d11tri.o $(LIBS_D3D11)
$(CXX) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D11) -Wl,--end-group $(LDADD)
bin/d3d11tex: d3d11app/d3d11x11main.o d3d11tex/d3d11tex.o $(LIBS_D3D11)
$(CXX) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D11) -Wl,--end-group $(LDADD)
bin/d3d11gears: d3d11app/d3d11x11main.o d3d11gears/d3d11gears.o $(LIBS_D3D11)
$(CXX) $(LDFLAGS) $(filter %.o,$^) -o $@ -Wl,--start-group $(LIBS_D3D11) -Wl,--end-group $(LDADD)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,51 @@
/**************************************************************************
*
* 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 D3D10APP_H
#define D3D10APP_H
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <objbase.h>
#include <d3d10_1.h>
#include <assert.h>
#include <stdio.h>
#include <float.h>
#define ensure(x) do {HRESULT __hr = (x); if(!SUCCEEDED(__hr)) {fprintf(stderr, "COM error %08x\n", __hr); abort();}} while(0)
struct d3d10_application
{
virtual ~d3d10_application() {}
virtual void draw(ID3D10Device* ctx, ID3D10RenderTargetView* rtv, unsigned width, unsigned height, double time) = 0;
virtual bool init(ID3D10Device* dev, int argc, char** argv) = 0;
};
/* this is the entry point you must provide */
extern "C" d3d10_application* d3d10_application_create();
#endif

View File

@ -0,0 +1,188 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
#define INITGUID
#include "d3d10app.h"
#include "stdio.h"
static d3d10_application* app;
static IDXGISwapChain* swap_chain;
static unsigned width, height;
static DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
static ID3D10Device* dev;
static ID3D10Device* ctx;
static int frames = 0;
static int buffer_count = 1;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SIZE:
width = lParam & 0xffff;
height = lParam >> 16;
swap_chain->ResizeBuffers(buffer_count, width, height, format, 0);
frames = 0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int main(int argc, char** argv)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDCLASSEXA wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = "d3d10";
wcex.hIconSm = 0;
RegisterClassExA(&wcex);
HWND hwnd = CreateWindowA("d3d10", "d3d10", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if(!hwnd)
return FALSE;
RECT rc;
GetClientRect(hwnd, &rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
swap_chain_desc.BufferDesc.Width = width;
swap_chain_desc.BufferDesc.Height = height;
swap_chain_desc.BufferDesc.Format = format;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.OutputWindow = hwnd;
swap_chain_desc.Windowed = TRUE;
swap_chain_desc.BufferCount = buffer_count;
swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_0;
HRESULT hr;
if(1)
{
hr = D3D10CreateDeviceAndSwapChain(
NULL,
D3D10_DRIVER_TYPE_HARDWARE,
NULL,
D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
D3D10_SDK_VERSION,
&swap_chain_desc,
&swap_chain,
&dev);
}
else
{
hr = D3D10CreateDeviceAndSwapChain1(
NULL,
D3D10_DRIVER_TYPE_HARDWARE,
NULL,
D3D10_CREATE_DEVICE_SINGLETHREADED, // | D3D10_CREATE_DEVICE_DEBUG,
feature_level,
D3D10_SDK_VERSION,
&swap_chain_desc,
&swap_chain,
(ID3D10Device1**)&dev);
}
if(!SUCCEEDED(hr))
{
fprintf(stderr, "Failed to create D3D10 device (hresult %08x)\n", hr);
return 1;
}
ctx = dev;
app = d3d10_application_create();
if(!app->init(dev, argc, argv))
return 1;
ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
double period = 1.0 / (double)freq.QuadPart;
LARGE_INTEGER ctime_li;
QueryPerformanceCounter(&ctime_li);
double start_time = ctime_li.QuadPart * period;
MSG msg;
for(;;)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else if(width && height)
{
ID3D10Texture2D* tex;
static ID3D10RenderTargetView* rtv;
ensure(swap_chain->GetBuffer(0, __uuidof(tex), (void**)&tex));
ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
QueryPerformanceCounter(&ctime_li);
double ctime = (double)ctime_li.QuadPart * period - start_time;
app->draw(ctx, rtv, width, height, ctime);
ctx->OMSetRenderTargets(0, 0, 0);
swap_chain->Present(0, 0);
rtv->Release();
tex->Release();
}
else
WaitMessage();
}
return (int) msg.wParam;
}

View File

@ -0,0 +1,164 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
#define INITGUID
#include "d3d10app.h"
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <galliumdxgi.h>
#include <sys/time.h>
static d3d10_application* app;
static IDXGISwapChain* swap_chain;
unsigned width, height;
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
static ID3D10Device* dev;
static ID3D10Device* ctx;
static int attributeList[] = {
GLX_RGBA,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None
};
double get_time()
{
struct timeval tv;
gettimeofday(&tv, 0);
return (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
}
int main(int argc, char** argv)
{
Display* dpy = XOpenDisplay(0);
XVisualInfo* vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
XSetWindowAttributes swa;
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = StructureNotifyMask;
width = 512;
height = 512;
Window win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap| CWEventMask, &swa);
XMapWindow(dpy, win);
GalliumDXGIUseX11Display(dpy, 0, 0);
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
swap_chain_desc.BufferDesc.Width = width;
swap_chain_desc.BufferDesc.Height = height;
swap_chain_desc.BufferDesc.Format = format;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.OutputWindow = (HWND)win;
swap_chain_desc.Windowed = TRUE;
swap_chain_desc.BufferCount = 3;
swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_0;
HRESULT hr;
if(0)
{
hr = D3D10CreateDeviceAndSwapChain(
NULL,
D3D10_DRIVER_TYPE_HARDWARE,
NULL,
D3D10_CREATE_DEVICE_SINGLETHREADED,
D3D10_SDK_VERSION,
&swap_chain_desc,
&swap_chain,
&dev);
}
else
{
hr = D3D10CreateDeviceAndSwapChain1(
NULL,
D3D10_DRIVER_TYPE_HARDWARE,
NULL,
D3D10_CREATE_DEVICE_SINGLETHREADED,
feature_level,
D3D10_SDK_VERSION,
&swap_chain_desc,
&swap_chain,
(ID3D10Device1**)&dev);
}
if(!SUCCEEDED(hr))
{
fprintf(stderr, "Failed to create D3D10 device (hresult %08x)\n", hr);
return 1;
}
ctx = dev;
app = d3d10_application_create();
if(!app->init(dev, argc, argv))
return 1;
double start_time = get_time();
MSG msg;
for(;;)
{
XEvent event;
if(XPending(dpy))
{
XNextEvent(dpy, &event);
if(event.type == DestroyNotify)
break;
switch(event.type)
{
case ConfigureNotify:
width = event.xconfigure.width;
height = event.xconfigure.height;
swap_chain->ResizeBuffers(3, width, height, format, 0);
break;
}
}
else if(width && height)
{
ID3D10Texture2D* tex;
ID3D10RenderTargetView* rtv;
ensure(swap_chain->GetBuffer(0, IID_ID3D10Texture2D, (void**)&tex));
ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
double ctime = get_time() - start_time;
app->draw(ctx, rtv, width, height, ctime);
ctx->OMSetRenderTargets(0, 0, 0);
tex->Release();
rtv->Release();
swap_chain->Present(0, 0);
}
else
XPeekEvent(dpy, &event);
}
return (int) msg.wParam;
}

View File

@ -0,0 +1,118 @@
/**************************************************************************
*
* 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 "d3d10app.h"
#include "d3d10tri.hlsl.ps.h"
#include "d3d10tri.hlsl.vs.h"
struct vertex {
float position[4];
float color[4];
};
static struct vertex vertices[3] =
{
{
{ 0.0f, 0.9f, 0.5f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f }
},
{
{ 0.9f, -0.9f, 0.5f, 1.0f },
{ 0.0f, 0.0f, 1.0f, 1.0f }
},
{
{ -0.9f, -0.9f, 0.5f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
};
struct d3d10tri : public d3d10_application
{
ID3D10PixelShader* ps;
ID3D10VertexShader* vs;
ID3D10InputLayout* layout;
ID3D10Buffer* vb;
virtual bool init(ID3D10Device* dev, int argc, char** argv)
{
ensure(dev->CreatePixelShader(g_ps, sizeof(g_ps), &ps));
ensure(dev->CreateVertexShader(g_vs, sizeof(g_vs), &vs));
D3D10_INPUT_ELEMENT_DESC elements[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D10_INPUT_PER_VERTEX_DATA, 0},
};
ensure(dev->CreateInputLayout(elements, sizeof(elements) / sizeof(elements[0]), g_vs, sizeof(g_vs), &layout));
D3D10_BUFFER_DESC bufferd;
bufferd.ByteWidth = sizeof(vertices);
bufferd.Usage = D3D10_USAGE_IMMUTABLE;
bufferd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bufferd.CPUAccessFlags = 0;
bufferd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA buffersd;
buffersd.pSysMem = vertices;
buffersd.SysMemPitch = sizeof(vertices);
buffersd.SysMemSlicePitch = sizeof(vertices);
ensure(dev->CreateBuffer(&bufferd, &buffersd, &vb));
return true;
}
virtual void draw(ID3D10Device* ctx, ID3D10RenderTargetView* rtv, unsigned width, unsigned height, double time)
{
float clear_color[4] = {1, 0, 1, 1};
D3D10_VIEWPORT vp;
memset(&vp, 0, sizeof(vp));
vp.Width = (unsigned)width;
vp.Height = (unsigned)height;
vp.MaxDepth = 1.0f;
ctx->OMSetRenderTargets(1, &rtv, 0);
ctx->RSSetViewports(1, &vp);
ctx->ClearRenderTargetView(rtv, clear_color);
ctx->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ctx->IASetInputLayout(layout);
unsigned stride = 2 * 4 * 4;
unsigned offset = 0;
ctx->IASetVertexBuffers(0, 1, &vb, &stride, &offset);
ctx->VSSetShader(vs);
ctx->PSSetShader(ps);
ctx->Draw(3, 0);
}
};
d3d10_application* d3d10_application_create()
{
return new d3d10tri();
}

View File

@ -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.
*
**************************************************************************/
struct IA2VS
{
float4 position : POSITION;
float4 color : COLOR;
};
struct VS2PS
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
VS2PS vs(IA2VS input)
{
VS2PS result;
result.position = input.position;
result.color = input.color;
return result;
}
float4 ps(VS2PS input) : SV_TARGET
{
return input.color;
}

View File

@ -0,0 +1,112 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d10tri.hlsl.ps.h /Eps /Tps_4_0 d3d10tri.hlsl
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// COLOR 0 xyzw 1 NONE float xyzw
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_input_ps linear v1.xyzw
dcl_output o0.xyzw
mov o0.xyzw, v1.xyzw
ret
// Approximately 2 instruction slots used
#endif
const BYTE g_ps[] =
{
68, 88, 66, 67, 206, 120,
117, 238, 118, 127, 10, 87,
80, 75, 114, 198, 95, 2,
120, 102, 1, 0, 0, 0,
208, 1, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
140, 0, 0, 0, 224, 0,
0, 0, 20, 1, 0, 0,
84, 1, 0, 0, 82, 68,
69, 70, 80, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 1, 0, 0,
28, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
76, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
68, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 15, 15, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
67, 79, 76, 79, 82, 0,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 65, 82,
71, 69, 84, 0, 171, 171,
83, 72, 68, 82, 56, 0,
0, 0, 64, 0, 0, 0,
14, 0, 0, 0, 98, 16,
0, 3, 242, 16, 16, 0,
1, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
0, 0, 0, 0, 54, 0,
0, 5, 242, 32, 16, 0,
0, 0, 0, 0, 70, 30,
16, 0, 1, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 116, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0,
0, 0
};

View File

@ -0,0 +1,128 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d10tri.hlsl.vs.h /Evs /Tvs_4_0 d3d10tri.hlsl
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyzw 0 NONE float xyzw
// COLOR 0 xyzw 1 NONE float xyzw
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float xyzw
// COLOR 0 xyzw 1 NONE float xyzw
//
vs_4_0
dcl_input v0.xyzw
dcl_input v1.xyzw
dcl_output_siv o0.xyzw, position
dcl_output o1.xyzw
mov o0.xyzw, v0.xyzw
mov o1.xyzw, v1.xyzw
ret
// Approximately 3 instruction slots used
#endif
const BYTE g_vs[] =
{
68, 88, 66, 67, 190, 171,
186, 20, 44, 105, 95, 129,
137, 204, 223, 72, 251, 159,
126, 176, 1, 0, 0, 0,
28, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
140, 0, 0, 0, 220, 0,
0, 0, 48, 1, 0, 0,
160, 1, 0, 0, 82, 68,
69, 70, 80, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 0, 4,
254, 255, 0, 1, 0, 0,
28, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
72, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 15, 0, 0,
65, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 15, 15, 0, 0,
80, 79, 83, 73, 84, 73,
79, 78, 0, 67, 79, 76,
79, 82, 0, 171, 79, 83,
71, 78, 76, 0, 0, 0,
2, 0, 0, 0, 8, 0,
0, 0, 56, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 68, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
1, 0, 0, 0, 15, 0,
0, 0, 83, 86, 95, 80,
79, 83, 73, 84, 73, 79,
78, 0, 67, 79, 76, 79,
82, 0, 171, 171, 83, 72,
68, 82, 104, 0, 0, 0,
64, 0, 1, 0, 26, 0,
0, 0, 95, 0, 0, 3,
242, 16, 16, 0, 0, 0,
0, 0, 95, 0, 0, 3,
242, 16, 16, 0, 1, 0,
0, 0, 103, 0, 0, 4,
242, 32, 16, 0, 0, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 3, 242, 32,
16, 0, 1, 0, 0, 0,
54, 0, 0, 5, 242, 32,
16, 0, 0, 0, 0, 0,
70, 30, 16, 0, 0, 0,
0, 0, 54, 0, 0, 5,
242, 32, 16, 0, 1, 0,
0, 0, 70, 30, 16, 0,
1, 0, 0, 0, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 4, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 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, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 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, 0,
0, 0, 0, 0, 0, 0
};

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5366F4FD-0E6C-40CC-B2F2-CE3D350F0729}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>d3d10tri</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d10app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>d3d10.lib;d3d10_1.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d10app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>d3d10.lib;d3d10_1.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<CustomBuild Include="d3d10tri.hlsl">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).ps.h /Eps /Tps_4_0 %(Identity)
"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).vs.h /Evs /Tvs_4_0 %(Identity)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Identity).ps.h;%(Identity).vs.h;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\d3d10app\d3d10app.h" />
<ClInclude Include="d3d10tri.hlsl.ps.h" />
<ClInclude Include="d3d10tri.hlsl.vs.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\d3d10app\d3d10winmain.cpp" />
<ClCompile Include="d3d10tri.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,51 @@
/**************************************************************************
*
* 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 D3D11APP_H
#define D3D11APP_H
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <objbase.h>
#include <d3d11.h>
#include <assert.h>
#include <stdio.h>
#include <float.h>
#define ensure(x) do {HRESULT __hr = (x); if(!SUCCEEDED(__hr)) {fprintf(stderr, "COM error %08x\n", __hr); abort();}} while(0)
struct d3d11_application
{
virtual ~d3d11_application() {}
virtual void draw(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* rtv, unsigned width, unsigned height, double time) = 0;
virtual bool init(ID3D11Device* dev, int argc, char** argv) = 0;
};
/* this is the entry point you must provide */
extern "C" d3d11_application* d3d11_application_create();
#endif

View File

@ -0,0 +1,53 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
Texture2D tex;
sampler samp;
struct IA2VS
{
float4 position : POSITION;
float2 texcoord : TEXCOORD;
};
struct VS2PS
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
};
VS2PS vs_blit(IA2VS input)
{
VS2PS result;
result.position = input.position;
result.texcoord = input.texcoord;
return result;
}
float4 ps_blit(VS2PS input) : SV_TARGET
{
return tex.Sample(samp, input.texcoord);
}

View File

@ -0,0 +1,142 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11blit.hlsl.ps.h /Eps_blit /Tps_4_0 d3d11blit.hlsl
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samp sampler NA NA 0 1
// tex texture float4 2d 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xy 1 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v1.xy
dcl_output o0.xyzw
sample o0.xyzw, v1.xyxx, t0.xyzw, s0
ret
// Approximately 2 instruction slots used
#endif
const BYTE g_ps_blit[] =
{
68, 88, 66, 67, 183, 100,
39, 89, 244, 20, 241, 39,
36, 169, 159, 230, 234, 214,
114, 11, 1, 0, 0, 0,
72, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
212, 0, 0, 0, 44, 1,
0, 0, 96, 1, 0, 0,
204, 1, 0, 0, 82, 68,
69, 70, 152, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 1, 0, 0,
101, 0, 0, 0, 92, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
97, 0, 0, 0, 2, 0,
0, 0, 5, 0, 0, 0,
4, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
1, 0, 0, 0, 12, 0,
0, 0, 115, 97, 109, 112,
0, 116, 101, 120, 0, 77,
105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 57, 46,
50, 57, 46, 57, 53, 50,
46, 51, 49, 49, 49, 0,
171, 171, 73, 83, 71, 78,
80, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
68, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 3, 3, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
84, 69, 88, 67, 79, 79,
82, 68, 0, 171, 171, 171,
79, 83, 71, 78, 44, 0,
0, 0, 1, 0, 0, 0,
8, 0, 0, 0, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 83, 86,
95, 84, 65, 82, 71, 69,
84, 0, 171, 171, 83, 72,
68, 82, 100, 0, 0, 0,
64, 0, 0, 0, 25, 0,
0, 0, 90, 0, 0, 3,
0, 96, 16, 0, 0, 0,
0, 0, 88, 24, 0, 4,
0, 112, 16, 0, 0, 0,
0, 0, 85, 85, 0, 0,
98, 16, 0, 3, 50, 16,
16, 0, 1, 0, 0, 0,
101, 0, 0, 3, 242, 32,
16, 0, 0, 0, 0, 0,
69, 0, 0, 9, 242, 32,
16, 0, 0, 0, 0, 0,
70, 16, 16, 0, 1, 0,
0, 0, 70, 126, 16, 0,
0, 0, 0, 0, 0, 96,
16, 0, 0, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 116, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 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, 1, 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, 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
};

View File

@ -0,0 +1,130 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11blit.hlsl.vs.h /Evs_blit /Tvs_4_0 d3d11blit.hlsl
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyzw 0 NONE float xyzw
// TEXCOORD 0 xy 1 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float xyzw
// TEXCOORD 0 xy 1 NONE float xy
//
vs_4_0
dcl_input v0.xyzw
dcl_input v1.xy
dcl_output_siv o0.xyzw, position
dcl_output o1.xy
mov o0.xyzw, v0.xyzw
mov o1.xy, v1.xyxx
ret
// Approximately 3 instruction slots used
#endif
const BYTE g_vs_blit[] =
{
68, 88, 66, 67, 142, 11,
173, 22, 73, 47, 224, 51,
147, 83, 148, 177, 56, 17,
72, 237, 1, 0, 0, 0,
36, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
140, 0, 0, 0, 224, 0,
0, 0, 56, 1, 0, 0,
168, 1, 0, 0, 82, 68,
69, 70, 80, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 0, 4,
254, 255, 0, 1, 0, 0,
28, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
76, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 15, 0, 0,
65, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 3, 3, 0, 0,
80, 79, 83, 73, 84, 73,
79, 78, 0, 84, 69, 88,
67, 79, 79, 82, 68, 0,
171, 171, 79, 83, 71, 78,
80, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
68, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 3, 12, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
84, 69, 88, 67, 79, 79,
82, 68, 0, 171, 171, 171,
83, 72, 68, 82, 104, 0,
0, 0, 64, 0, 1, 0,
26, 0, 0, 0, 95, 0,
0, 3, 242, 16, 16, 0,
0, 0, 0, 0, 95, 0,
0, 3, 50, 16, 16, 0,
1, 0, 0, 0, 103, 0,
0, 4, 242, 32, 16, 0,
0, 0, 0, 0, 1, 0,
0, 0, 101, 0, 0, 3,
50, 32, 16, 0, 1, 0,
0, 0, 54, 0, 0, 5,
242, 32, 16, 0, 0, 0,
0, 0, 70, 30, 16, 0,
0, 0, 0, 0, 54, 0,
0, 5, 50, 32, 16, 0,
1, 0, 0, 0, 70, 16,
16, 0, 1, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 116, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 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, 0, 0, 0, 0, 0,
0, 0
};

View File

@ -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 <vector>
#include "d3d11blit.hlsl.ps.h"
#include "d3d11blit.hlsl.vs.h"
template<typename index_type = unsigned>
struct triangle_list_indices : public std::vector<index_type>
{
unsigned base;
bool flip;
triangle_list_indices()
: base(0), flip(false)
{}
void poly(unsigned a, unsigned b, unsigned c)
{
this->push_back(base + a);
this->push_back(base + (flip ? c : b));
this->push_back(base + (flip ? b : c));
}
void poly(unsigned a, unsigned b, unsigned c, unsigned d)
{
poly(a, b, c);
poly(a, c, d);
}
void poly(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e)
{
poly(a, b, c, d);
poly(a, d, e);
}
void poly(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f)
{
poly(a, b, c, d, e);
poly(a, e, f);
}
void poly(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f, unsigned g)
{
poly(a, b, c, d, e, f);
poly(a, f, g);
}
void poly(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f, unsigned g, unsigned h)
{
poly(a, b, c, d, e, f, g);
poly(a, g, h);
}
};
struct mesh
{
ID3D11InputLayout* layout;
ID3D11Buffer* buffer;
D3D11_PRIMITIVE_TOPOLOGY topology;
unsigned vertex_size;
unsigned draw_count;
DXGI_FORMAT index_format;
unsigned index_offset;
mesh(ID3D11Device* dev, D3D11_PRIMITIVE_TOPOLOGY topology,
const D3D11_INPUT_ELEMENT_DESC *elements, unsigned num_elements,
const void* vs, unsigned vs_size,
const void* vertices, unsigned vertex_size, unsigned num_vertices,
const void* indices = 0, unsigned index_size = 0, unsigned num_indices = 0)
: topology(topology), vertex_size(vertex_size), draw_count(index_size ? num_indices : num_vertices)
{
dev->CreateInputLayout(elements, num_elements, vs, vs_size, &layout);
if(index_size == 2)
index_format = DXGI_FORMAT_R16_UINT;
else if(index_size == 4)
index_format = DXGI_FORMAT_R32_UINT;
else
index_format = DXGI_FORMAT_UNKNOWN;
this->vertex_size = vertex_size;
index_offset = vertex_size * num_vertices;
D3D11_BUFFER_DESC bufferd;
memset(&bufferd, 0, sizeof(bufferd));
bufferd.Usage = D3D11_USAGE_IMMUTABLE;
bufferd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
if(index_format)
bufferd.BindFlags |= D3D11_BIND_INDEX_BUFFER;
bufferd.ByteWidth = index_offset + index_format * num_indices;
char* data = (char*)malloc(bufferd.ByteWidth);
memcpy(data, vertices, vertex_size * num_vertices);
memcpy(data + index_offset, indices, index_size * num_indices);
D3D11_SUBRESOURCE_DATA buffersd;
buffersd.pSysMem = data;
ensure(dev->CreateBuffer(&bufferd, &buffersd, &buffer));
free(data);
}
~mesh()
{
layout->Release();
buffer->Release();
}
void bind(ID3D11DeviceContext* ctx)
{
unsigned offset = 0;
ctx->IASetPrimitiveTopology(topology);
ctx->IASetInputLayout(layout);
if(index_format)
ctx->IASetIndexBuffer(buffer, index_format, index_offset);
ctx->IASetVertexBuffers(0, 1, &buffer, &vertex_size, &offset);
}
void draw_bound(ID3D11DeviceContext* ctx)
{
if(index_format)
ctx->DrawIndexed(draw_count, 0, 0);
else
ctx->Draw(draw_count, 0);
}
void bind_and_draw(ID3D11DeviceContext* ctx)
{
bind(ctx);
draw_bound(ctx);
}
};
mesh* create_tex_quad(ID3D11Device* dev, const BYTE* vs, unsigned vs_size)
{
float quad_data[] = {
-1, -1, 0, 1,
-1, 1, 0, 0,
1, -1, 1, 1,
1, 1, 1, 0,
};
D3D11_INPUT_ELEMENT_DESC elements[2] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
return new mesh(dev, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP,
elements, 2,
vs, vs_size,
quad_data, 4 * sizeof(float), 4,
0, 0, 0);
}
struct d3d11_blitter
{
mesh* quad;
ID3D11VertexShader* vs;
ID3D11PixelShader* ps;
ID3D11SamplerState* sampler[2];
d3d11_blitter(ID3D11Device* dev)
{
quad = create_tex_quad(dev, g_vs_blit, sizeof(g_vs_blit));
dev->CreateVertexShader(g_vs_blit, sizeof(g_vs_blit), 0, &vs);
dev->CreatePixelShader(g_ps_blit, sizeof(g_ps_blit), 0, &ps);
for(unsigned i = 0; i < 2; ++i)
{
D3D11_SAMPLER_DESC samplerd;
memset(&samplerd, 0, sizeof(samplerd));
samplerd.Filter = i ? D3D11_FILTER_MIN_MAG_MIP_LINEAR : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerd.AddressU = samplerd.AddressV = samplerd.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
dev->CreateSamplerState(&samplerd, &sampler[i]);
}
}
void bind(ID3D11DeviceContext* ctx, ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, float x, float y, float width, float height, bool linear)
{
D3D11_VIEWPORT vp;
vp.TopLeftX = x;
vp.TopLeftY = y;
vp.Width = width;
vp.Height = height;
vp.MinDepth = 0;
vp.MaxDepth = 1;
ctx->RSSetViewports(1, &vp);
ctx->RSSetState(0);
ctx->OMSetBlendState(0, 0, ~0);
ctx->OMSetDepthStencilState(0, 0);
ctx->OMSetRenderTargets(1, &rtv, 0);
ctx->VSSetShader(vs, 0, 0);
ctx->PSSetShader(ps, 0, 0);
ctx->PSSetShaderResources(0, 1, &srv);
ctx->PSSetSamplers(0, 1, &sampler[!!linear]);
quad->bind(ctx);
}
void draw_bound(ID3D11DeviceContext* ctx)
{
quad->draw_bound(ctx);
}
void bind_draw_and_unbind(ID3D11DeviceContext* ctx, ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, float x, float y, float width, float height, bool linear)
{
bind(ctx, srv, rtv, x, y, width, height, linear);
draw_bound(ctx);
unbind(ctx);
}
void unbind(ID3D11DeviceContext* ctx)
{
void* null = 0;
ctx->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&null);
ctx->PSSetSamplers(0, 1, (ID3D11SamplerState**)&null);
}
};
template<typename T, unsigned n>
struct vec_t
{
T v[n];
T& operator [](unsigned i)
{
return v[i];
}
const T& operator [](unsigned i) const
{
return v[i];
}
};
template<typename T, unsigned n>
vec_t<T, n> operator -(const vec_t<T, n> a)
{
vec_t<T, n> r;
for(unsigned i = 0; i < n; ++i)
r[i] = -a[i];
return r;
}
template<typename T, unsigned n>
vec_t<T, n> operator +(const vec_t<T, n>& a, const vec_t<T, n>& b)
{
vec_t<T, n> r;
for(unsigned i = 0; i < n; ++i)
r[i] = a[i] + b[i];
return r;
}
template<typename T, unsigned n>
vec_t<T, n>& operator +=(vec_t<T, n>& a, const vec_t<T, n>& b)
{
for(unsigned i = 0; i < n; ++i)
a[i] += b[i];
return a;
}
template<typename T, unsigned r, unsigned c>
struct mat_t : public vec_t<vec_t<T, r>, c>
{};
template<typename T, unsigned n>
vec_t<T, n> operator *(const vec_t<T, n>& a, const T& b)
{
vec_t<T, n> r;
for(unsigned i = 0; i < n; ++i)
r[i] = a[i] * b;
return r;
}
template<typename T, unsigned n>
vec_t<T, n> operator *(const T& b, const vec_t<T, n>& a)
{
vec_t<T, n> r;
for(unsigned i = 0; i < n; ++i)
r[i] = a[i] * b;
return r;
}
template<typename T, unsigned d, unsigned e>
vec_t<T, e> operator *(const mat_t<T, e, d>& m, const vec_t<T, d>& b)
{
vec_t<T, e> r;
r = m[0] * b[0];
for(unsigned i = 1; i < d; ++i)
r += m[i] * b[i];
return r;
}
template<typename T, unsigned d, unsigned e, unsigned f>
mat_t<T, e, f> operator *(const mat_t<T, e, d>& m, const mat_t<T, d, f>& b)
{
mat_t<T, e, f> r;
for(unsigned i = 0; i < d; ++i)
r[i] = m * b[i];
return r;
}
template<typename T>
vec_t<T, 3> vec(T a, T b, T c)
{
vec_t<T, 4> v;
v[0] = a;
v[1] = b;
v[2] = c;
return v;
}
template<typename T>
vec_t<T, 4> vec(T a, T b, T c, T d)
{
vec_t<T, 4> v;
v[0] = a;
v[1] = b;
v[2] = c;
v[3] = d;
return v;
}
typedef mat_t<float, 4, 4> float4x4;
typedef mat_t<float, 4, 3> float4x3;
typedef mat_t<float, 3, 4> float3x4;
typedef mat_t<float, 3, 3> float3x3;
typedef vec_t<float, 3> float3;
typedef vec_t<float, 4> float4;
template<typename T>
mat_t<T, 4, 4> mat4x4_frustum(T left, T right, T bottom, T top, T nearval, T farval)
{
T x = (2.0f * nearval) / (right - left);
T y = (2.0f * nearval) / (top - bottom);
T a = (right + left) / (right - left);
T b = (top + bottom) / (top - bottom);
T c = -(farval + nearval) / (farval - nearval);
T d = -(2.0f * farval * nearval) / (farval - nearval);
T _0 = (T)0;
mat_t<T, 4, 4> m;
m[0] = vec(x, _0, _0, _0);
m[1] = vec(_0, y, _0, _0);
m[2] = vec(a, b, c, (T)-1);
m[3] = vec(_0, _0, d, _0);
return m;
}
template<typename T>
mat_t<T, 3, 3> mat3x3_diag(T v)
{
mat_t<T, 3, 3> m;
T _0 = (T)0;
m[0] = vec(v, _0, _0);
m[1] = vec(_0, v, _0);
m[2] = vec(_0, _0, v);
return m;
}
template<typename T>
mat_t<T, 4, 4> mat4x4_diag(T v)
{
mat_t<T, 4, 4> m;
T _0 = (T)0;
m[0] = vec(v, _0, _0, _0);
m[1] = vec(_0, v, _0, _0);
m[2] = vec(_0, _0, v, _0);
m[3] = vec(_0, _0, _0, v);
return m;
}
template<typename T, unsigned n>
mat_t<T, n, n> mat_push_rotate(const mat_t<T, n, n>& m, unsigned axis, T angle)
{
T s = (T)sin(angle);
T c = (T)cos(angle);
mat_t<T, n, n> r = m;
unsigned a = (axis + 1) % 3;
unsigned b = (axis + 2) % 3;
r[a] = (m[a] * c) + (m[b] * s);
r[b] = -(m[a] * s) + (m[b] * c);
return r;
}
template<typename T, unsigned n>
mat_t<T, n, n> mat_push_translate(const mat_t<T, n, n>& m, float x, float y, float z)
{
mat_t<T, n, n> r = m;
vec_t<T, n> v;
v[0] = x;
v[1] = y;
v[2] = z;
if(n >= 4)
v[3] = (T)0;
r[3] += m * v;
return r;
}

View File

@ -0,0 +1,172 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
#define INITGUID
#include "d3d11app.h"
#include "stdio.h"
static d3d11_application* app;
static IDXGISwapChain* swap_chain;
static unsigned width, height;
static DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
static ID3D11Device* dev;
static ID3D11DeviceContext* ctx;
static int frames = 0;
static int buffer_count = 1;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SIZE:
width = lParam & 0xffff;
height = lParam >> 16;
swap_chain->ResizeBuffers(buffer_count, width, height, format, 0);
frames = 0;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int main(int argc, char** argv)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDCLASSEXA wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = "d3d11";
wcex.hIconSm = 0;
RegisterClassExA(&wcex);
HWND hwnd = CreateWindowA("d3d11", "d3d11", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if(!hwnd)
return FALSE;
RECT rc;
GetClientRect(hwnd, &rc );
width = rc.right - rc.left;
height = rc.bottom - rc.top;
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
swap_chain_desc.BufferDesc.Width = width;
swap_chain_desc.BufferDesc.Height = height;
swap_chain_desc.BufferDesc.Format = format;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.OutputWindow = hwnd;
swap_chain_desc.Windowed = TRUE;
swap_chain_desc.BufferCount = buffer_count;
swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
HRESULT hr = D3D11CreateDeviceAndSwapChain(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_SINGLETHREADED, // | D3D11_CREATE_DEVICE_DEBUG,
NULL,
0,
D3D11_SDK_VERSION,
&swap_chain_desc,
&swap_chain,
&dev,
&feature_level,
&ctx);
if(!SUCCEEDED(hr))
{
fprintf(stderr, "Failed to create D3D11 device (hresult %08x)\n", hr);
return 1;
}
app = d3d11_application_create();
if(!app->init(dev, argc, argv))
return 1;
ShowWindow(hwnd, SW_SHOWDEFAULT);
UpdateWindow(hwnd);
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
double period = 1.0 / (double)freq.QuadPart;
LARGE_INTEGER ctime_li;
QueryPerformanceCounter(&ctime_li);
double start_time = ctime_li.QuadPart * period;
MSG msg;
for(;;)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else if(width && height)
{
ID3D11Texture2D* tex;
static ID3D11RenderTargetView* rtv;
ensure(swap_chain->GetBuffer(0, __uuidof(tex), (void**)&tex));
ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
QueryPerformanceCounter(&ctime_li);
double ctime = (double)ctime_li.QuadPart * period - start_time;
app->draw(ctx, rtv, width, height, ctime);
ctx->OMSetRenderTargets(0, 0, 0);
swap_chain->Present(0, 0);
rtv->Release();
tex->Release();
}
else
WaitMessage();
}
return (int) msg.wParam;
}

View File

@ -0,0 +1,124 @@
#define INITGUID
#include "d3d11app.h"
#include <X11/Xlib.h>
#include <GL/glx.h>
#include <galliumdxgi.h>
#include <sys/time.h>
static d3d11_application* app;
static IDXGISwapChain* swap_chain;
unsigned width, height;
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
static ID3D11Device* dev;
static ID3D11DeviceContext* ctx;
static int attributeList[] = {
GLX_RGBA,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None
};
double get_time()
{
struct timeval tv;
gettimeofday(&tv, 0);
return (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
}
int main(int argc, char** argv)
{
Display* dpy = XOpenDisplay(0);
XVisualInfo* vi = glXChooseVisual(dpy, DefaultScreen(dpy), attributeList);
Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
XSetWindowAttributes swa;
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = StructureNotifyMask;
width = 512;
height = 512;
Window win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, width, height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap| CWEventMask, &swa);
XMapWindow(dpy, win);
GalliumDXGIUseX11Display(dpy, 0, 0);
DXGI_SWAP_CHAIN_DESC swap_chain_desc;
memset(&swap_chain_desc, 0, sizeof(swap_chain_desc));
swap_chain_desc.BufferDesc.Width = width;
swap_chain_desc.BufferDesc.Height = height;
swap_chain_desc.BufferDesc.Format = format;
swap_chain_desc.SampleDesc.Count = 1;
swap_chain_desc.SampleDesc.Quality = 0;
swap_chain_desc.OutputWindow = (HWND)win;
swap_chain_desc.Windowed = TRUE;
swap_chain_desc.BufferCount = 3;
swap_chain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
HRESULT hr =D3D11CreateDeviceAndSwapChain(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_SINGLETHREADED,
NULL,
0,
D3D11_SDK_VERSION,
&swap_chain_desc,
&swap_chain,
&dev,
&feature_level,
&ctx);
if(!SUCCEEDED(hr))
{
fprintf(stderr, "Failed to create D3D11 device (hresult %08x)\n", hr);
return 1;
}
app = d3d11_application_create();
if(!app->init(dev, argc, argv))
return 1;
double start_time = get_time();
MSG msg;
for(;;)
{
XEvent event;
if(XPending(dpy))
{
XNextEvent(dpy, &event);
if(event.type == DestroyNotify)
break;
switch(event.type)
{
case ConfigureNotify:
width = event.xconfigure.width;
height = event.xconfigure.height;
swap_chain->ResizeBuffers(3, width, height, format, 0);
break;
}
}
else if(width && height)
{
ID3D11Texture2D* tex;
ID3D11RenderTargetView* rtv;
ensure(swap_chain->GetBuffer(0, IID_ID3D11Texture2D, (void**)&tex));
ensure(dev->CreateRenderTargetView(tex, NULL, &rtv));
double ctime = get_time() - start_time;
app->draw(ctx, rtv, width, height, ctime);
ctx->OMSetRenderTargets(0, 0, 0);
tex->Release();
rtv->Release();
swap_chain->Present(0, 0);
}
else
XPeekEvent(dpy, &event);
}
return (int) msg.wParam;
}

View File

@ -0,0 +1,573 @@
/*
* Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
* Copyright (C) 2009-2010 Luca Barbieri All Rights Reserved.
*
* 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
* BRIAN PAUL 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.
*/
/*
* This is a port of the infamous "glxgears" demo to straight EGL
* Port by Dane Rushton 10 July 2005
*
* This a rewrite of the 'eglgears' demo in straight Gallium
* Port by Luca Barbieri
*
* This a port of the 'galliumgears' demo to Direct3D 11
* Port by Luca Barbieri
*/
#define _USE_MATH_DEFINES
#include "d3d11app.h"
#include "d3d11u.h"
#include "d3d11gears.hlsl.ps.h"
#include "d3d11gears.hlsl.vs.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
struct gear
{
struct mesh* mesh;
float x;
float y;
float t0;
float wmul;
float4 color;
};
struct cbuf_t
{
float4x4 projection;
float4x4 modelview;
float4 light;
float4 diffuse;
float4 specular;
float specular_power;
float padding[3];
};
struct gear gears[3];
struct vertex
{
float position[3];
float normal[3];
vertex(float x, float y, float z, float nx, float ny, float nz)
{
position[0] = x;
position[1] = y;
position[2] = z;
normal[0] = nx;
normal[1] = ny;
normal[2] = nz;
}
};
#define VERT(x, y, z) vertices.push_back(vertex((x), (y), (z), (nx), (ny), (nz)))
static mesh* build_gear(ID3D11Device* dev, int triangle_budget, float inner_radius, float outer_radius, float width, int teeth, float tooth_depth)
{
int i, j, k;
float r0, r1, r2;
float da;
float nx, ny, nz;
int face;
int segs = 4;
int base_triangles = teeth * segs * 2 * 2;
int divs0 = (triangle_budget / base_triangles) - 1;
int divs = (divs0 > 0) ? divs0 : 1;
float* c = (float*)malloc(teeth * segs * sizeof(float));
float* s = (float*)malloc(teeth * segs * sizeof(float));
float* dc = (float*)malloc(teeth * segs * divs * sizeof(float));
float* ds = (float*)malloc(teeth * segs * divs * sizeof(float));
int num_vertices = teeth * segs * 2 * (3 + 2 * divs);
int num_triangles = base_triangles * (1 + divs);
printf("Creating gear with %i teeth using %i vertices used in %i triangles\n", teeth, num_vertices, num_triangles);
triangle_list_indices<> indices;
std::vector<vertex> vertices;
r0 = inner_radius;
r1 = outer_radius - tooth_depth / 2.0f;
r2 = outer_radius + tooth_depth / 2.0f;
da = (float)(2.0 * M_PI / (teeth * segs * divs));
for(i = 0; i < teeth * segs * divs; ++i) {
float angle = da * i;
ds[i] = sin(angle);
dc[i] = cos(angle);
}
for(i = 0; i < teeth * segs; ++i) {
s[i] = ds[i * divs];
c[i] = dc[i * divs];
}
/* faces */
for(face = -1; face <= 1; face += 2) {
float z = width * face * 0.5f;
nx = 0.0f;
ny = 0.0f;
nz = (float)face;
indices.flip = face > 0;
assert(segs == 4);
for(i = 0; i < teeth; ++i) {
VERT(r1 * c[segs * i], r1 * s[segs * i], z);
VERT(r2 * c[segs * i + 1], r2 * s[segs * i + 1], z);
VERT(r2 * c[segs * i + 2], r2 * s[segs * i + 2], z);
VERT(r1 * c[segs * i + 3], r1 * s[segs * i + 3], z);
}
for(i = 0; i < teeth * segs * divs; ++i) {
VERT(r0 * dc[i], r0 * ds[i], z);
}
for(i = 0; i < teeth; ++i) {
for(j = i * segs; j < (i + 1) * segs; ++j) {
int nextj = j + 1;
if(nextj == teeth * segs)
nextj = 0;
for(k = j * divs; k < (j + 1) * divs; ++k) {
int nextk = k + 1;
if(nextk == teeth * segs * divs)
nextk = 0;
indices.poly(teeth * segs + k, j, teeth * segs + nextk);
}
indices.poly(teeth * segs + nextj * divs, j, nextj);
}
}
indices.base += teeth * segs * (1 + divs);
}
/* teeth faces */
indices.flip = true;
float z = width * 0.5f;
float* coords = (float*)malloc((segs + 1) * 2 * sizeof(float));
nz = 0;
for(i = 0; i < teeth; i++) {
int next = i + 1;
if(next == teeth)
next = 0;
coords[0] = r1 * c[segs * i];
coords[1] = r1 * s[segs * i];
coords[2] = r2 * c[segs * i + 1];
coords[3] = r2 * s[segs * i + 1];
coords[4] = r2 * c[segs * i + 2];
coords[5] = r2 * s[segs * i + 2];
coords[6] = r1 * c[segs * i + 3];
coords[7] = r1 * s[segs * i + 3];
coords[8] = r1 * c[segs * next];
coords[9] = r1 * s[segs * next];
for(int j = 0; j < segs; ++j) {
float dx = coords[j * 2] - coords[j * 2 + 2];
float dy = coords[j * 2 + 1] - coords[j * 2 + 3];
float len = hypotf(dx, dy);
nx = -dy / len;
ny = dx / len;
VERT(coords[j * 2], coords[j * 2 + 1], z);
VERT(coords[j * 2], coords[j * 2 + 1], -z);
VERT(coords[j * 2 + 2], coords[j * 2 + 3], z);
VERT(coords[j * 2 + 2], coords[j * 2 + 3], -z);
indices.poly(0, 1, 3, 2);
indices.base += 4;
}
}
free(coords);
/* inner part - simulate a cylinder */
indices.flip = true;
for(i = 0; i < teeth * segs * divs; i++) {
int next = i + 1;
if(next == teeth * segs * divs)
next = 0;
nx = -dc[i];
ny = -ds[i];
VERT(r0 * dc[i], r0 * ds[i], -width * 0.5f);
VERT(r0 * dc[i], r0 * ds[i], width * 0.5f);
indices.poly(i * 2, i * 2 + 1, next * 2 + 1, next * 2);
}
indices.base += teeth * segs * divs * 2;
free(c);
free(s);
free(dc);
free(ds);
D3D11_INPUT_ELEMENT_DESC elements[2] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
return new mesh(dev, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST,
elements, 2,
g_vs, sizeof(g_vs),
&vertices[0], sizeof(vertices[0]), vertices.size(),
&indices[0], sizeof(indices[0]), indices.size());
}
struct d3d11gears : public d3d11_application
{
float view_rotx;
float view_roty;
float view_rotz;
int wireframe;
int triangles;
float speed;
float period;
unsigned impressions;
bool blue_only;
float last_time;
int cur_width;
int cur_height;
ID3D11DepthStencilView* zsv;
ID3D11RenderTargetView* offscreen_rtv;
ID3D11ShaderResourceView* offscreen_srv;
ID3D11Device* dev;
ID3D11BlendState* blend;
ID3D11DepthStencilState* zsa;
ID3D11PixelShader* ps;
ID3D11VertexShader* vs;
ID3D11Buffer* cb;
d3d11_blitter* blitter;
d3d11gears()
: cur_width(-1), cur_height(-1), zsv(0), offscreen_rtv(0), offscreen_srv(0)
{
view_rotx = (float)(M_PI / 9.0);
view_roty = (float)(M_PI / 6.0);
view_rotz = 0.0f;
wireframe = 0;
triangles = 3200;
speed = 1.0f;
period = -1.0f;
impressions = 1;
blue_only = false;
}
void draw_one(ID3D11DeviceContext* ctx, cbuf_t& cbd, const float4x4& modelview, float angle)
{
for(unsigned i = blue_only ? 2 : 0; i < 3; ++i)
{
float4x4 m2 = modelview;
m2 = mat_push_translate(m2, gears[i].x, gears[i].y, 0.0f);
m2 = mat_push_rotate(m2, 2, angle * gears[i].wmul + gears[i].t0);
cbd.modelview = m2;
cbd.diffuse = gears[i].color;
cbd.specular = gears[i].color;
cbd.specular_power = 5.0f;
ctx->UpdateSubresource(cb, 0, 0, &cbd, 0, 0);
gears[i].mesh->bind_and_draw(ctx);
}
}
float get_angle(double time)
{
// designed so that 1 = original glxgears speed
float mod_speed = M_PI * 70.0f / 180.0f * speed;
if(period < 0)
return (float)(time * mod_speed);
else
return (float)(cos(time / period) * period * mod_speed);
}
void init_for_dimensions(unsigned width, unsigned height)
{
if(zsv)
zsv->Release();
ID3D11Texture2D* zsbuf;
D3D11_TEXTURE2D_DESC zsbufd;
memset(&zsbufd, 0, sizeof(zsbufd));
zsbufd.Width = width;
zsbufd.Height = height;
zsbufd.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
zsbufd.ArraySize = 1;
zsbufd.MipLevels = 1;
zsbufd.SampleDesc.Count = 1;
zsbufd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
ensure(dev->CreateTexture2D(&zsbufd, 0, &zsbuf));
ensure(dev->CreateDepthStencilView(zsbuf, 0, &zsv));
zsbuf->Release();
ID3D11Texture2D* offscreen;
if(offscreen_rtv)
{
offscreen_rtv->Release();
offscreen_srv->Release();
offscreen_rtv = 0;
offscreen_srv = 0;
}
if(impressions > 1)
{
DXGI_FORMAT formats[] = {
DXGI_FORMAT_R32G32B32A32_FLOAT,
DXGI_FORMAT_R16G16B16A16_UNORM,
DXGI_FORMAT_R16G16B16A16_FLOAT,
DXGI_FORMAT_R10G10B10A2_UNORM,
};
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM; // this won't work well at all
unsigned needed_support = D3D11_FORMAT_SUPPORT_RENDER_TARGET | D3D11_FORMAT_SUPPORT_BLENDABLE | D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
for(unsigned i = 0; i < sizeof(formats); ++i)
{
unsigned support;
dev->CheckFormatSupport(DXGI_FORMAT_R32G32B32A32_FLOAT, &support);
if((support & needed_support) == needed_support)
{
format = formats[i];
break;
}
}
D3D11_TEXTURE2D_DESC offscreend;
memset(&offscreend, 0, sizeof(offscreend));
offscreend.Width = width;
offscreend.Height = height;
offscreend.Format = format;
offscreend.MipLevels = 1;
offscreend.ArraySize = 1;
offscreend.SampleDesc.Count = 1;
offscreend.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
ensure(dev->CreateTexture2D(&offscreend, 0, &offscreen));
ensure(dev->CreateRenderTargetView(offscreen, 0, &offscreen_rtv));
ensure(dev->CreateShaderResourceView(offscreen, 0, &offscreen_srv));
offscreen->Release();
}
cur_width = width;
cur_height = height;
}
void draw(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* rtv, unsigned width, unsigned height, double time)
{
D3D11_VIEWPORT vp;
memset(&vp, 0, sizeof(vp));
vp.Width = (float)width;
vp.Height = (float)height;
vp.MaxDepth = 1.0f;
if((int)width != cur_width || (int)height != cur_height)
init_for_dimensions(width, height);
float4 lightpos = vec(5.0f, 5.0f, 10.0f, 0.0f);
float black[4] = {0.0, 0.0, 0.0, 0};
float4x4 proj;
float4x4 m;
float xr = (float)width / (float)height;
float yr = 1.0f;
if(xr < 1.0f) {
yr /= xr;
xr = 1.0f;
}
proj = mat4x4_frustum(-xr, xr, -yr, yr, 5.0f, 60.0f);
m = mat4x4_diag(1.0f);
m = mat_push_translate(m, 0.0f, 0.0f, -40.0f);
m = mat_push_rotate(m, 0, view_rotx);
m = mat_push_rotate(m, 1, view_roty);
m = mat_push_rotate(m, 2, view_rotz);
cbuf_t cbd;
cbd.projection = proj;
cbd.light = lightpos;
float blend_factor[4] = {1.0f / (float)impressions, 1.0f / (float)impressions, 1.0f / (float)impressions, 1.0f / (float)impressions};
ID3D11RenderTargetView* render_rtv;
if(impressions == 1)
render_rtv = rtv;
else
render_rtv = offscreen_rtv;
ctx->RSSetViewports(1, &vp);
ctx->ClearRenderTargetView(render_rtv, black);
ctx->PSSetShader(ps, 0, 0);
ctx->VSSetShader(vs, 0, 0);
ctx->PSSetConstantBuffers(0, 1, &cb);
ctx->VSSetConstantBuffers(0, 1, &cb);
if(impressions == 1)
{
ctx->OMSetBlendState(0, 0, ~0);
ctx->OMSetDepthStencilState(0, 0);
ctx->OMSetRenderTargets(1, &rtv, zsv);
ctx->ClearDepthStencilView(zsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0, 0);
draw_one(ctx, cbd, m, get_angle(time));
}
else
{
ctx->OMSetBlendState(blend, blend_factor, ~0);
float time_delta = (float)time - last_time;
float time_delta_per_impression = time_delta / impressions;
float base_time = last_time + time_delta_per_impression / 2;
for(unsigned impression = 0; impression < impressions; ++impression)
{
float impression_time = base_time + time_delta_per_impression * impression;
ctx->ClearDepthStencilView(zsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0, 0);
// do early z-pass since we must not write any pixel more than once due to blending
for(unsigned pass = 0; pass < 2; ++pass)
{
if(pass == 0)
{
ctx->OMSetRenderTargets(0, 0, zsv);
ctx->OMSetDepthStencilState(0, 0);
}
else
{
ctx->OMSetRenderTargets(1, &render_rtv, zsv);
ctx->OMSetDepthStencilState(zsa, 0);
}
draw_one(ctx, cbd, m, get_angle(impression_time));
}
}
blitter->bind_draw_and_unbind(ctx, offscreen_srv, rtv, 0, 0, (float)width, (float)height, false);
}
last_time = (float)time;
}
bool init(ID3D11Device* dev, int argc, char** argv)
{
this->dev = dev;
for(char** p = argv + 1; *p; ++p) {
if(!strcmp(*p, "-w"))
wireframe = 1;
else if(!strcmp(*p, "-b"))
blue_only = true;
else if(!strcmp(*p, "-t"))
triangles = atoi(*++p);
else if(!strcmp(*p, "-m"))
impressions = (float)atof(*++p);
else if(!strcmp(*p, "-p"))
period = (float)atof(*++p);
else if(!strcmp(*p, "-s"))
speed = (float)atof(*++p);
else {
fprintf(stderr, "Usage: d3d11gears [-v|-w] [-t TRIANGLES]\n");
fprintf(stderr, "d3d11gears is an enhanced port of glxgears to Direct3D 11\n");
fprintf(stderr, "\n");
//fprintf(stderr, "-v\t\tuse per-vertex diffuse-only lighting (classic glxgears look)\n");
fprintf(stderr, "-w\t\twireframe mode\n");
fprintf(stderr, "-t TRIANGLES\ttriangle budget (default is 3200)\n");
fprintf(stderr, "-m IMPRESSIONS\tmotion blur impressions (default is 1)\n");
fprintf(stderr, "-p PERIOD\tspeed reversal period (default is infinite)\n");
fprintf(stderr, "-s SPEED\tgear speed (default is 1.0)\n");
fprintf(stderr, "-b\tonly show blue gear (for faster motion blur)\n");
return false;
}
}
ensure(dev->CreatePixelShader(g_ps, sizeof(g_ps), NULL, &ps));
ensure(dev->CreateVertexShader(g_vs, sizeof(g_vs), NULL, &vs));
gears[0].color = vec(0.8f, 0.1f, 0.0f, 1.0f);
gears[1].color = vec(0.0f, 0.8f, 0.2f, 1.0f);
gears[2].color = vec(0.2f, 0.2f, 1.0f, 1.0f);
gears[0].mesh = build_gear(dev, triangles / 2, 1.0f, 4.0f, 1.0f, 20, 0.7f);
gears[1].mesh = build_gear(dev, triangles / 4, 0.5f, 2.0f, 2.0f, 10, 0.7f);
gears[2].mesh = build_gear(dev, triangles / 4, 1.3f, 2.0f, 0.5f, 10, 0.7f);
gears[0].x = -3.0f;
gears[0].y = -2.0f;
gears[0].wmul = 1.0f;
gears[0].t0 = 0.0 * M_PI / 180.0f;
gears[1].x = 3.1f;
gears[1].y = -2.0f;
gears[1].wmul = -2.0f;
gears[1].t0 = -9.0f * (float)M_PI / 180.0f;
gears[2].x = -3.1f;
gears[2].y = 4.2f;
gears[2].wmul = -2.0f;
gears[2].t0 = -25.0f * (float)M_PI / 180.0f;
D3D11_BUFFER_DESC bufferd;
memset(&bufferd, 0, sizeof(bufferd));
bufferd.ByteWidth = sizeof(cbuf_t);
bufferd.Usage = D3D11_USAGE_DEFAULT;
bufferd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
ensure(dev->CreateBuffer(&bufferd, 0, &cb));
if(impressions > 1)
{
D3D11_BLEND_DESC blendd;
memset(&blendd, 0, sizeof(blendd));
blendd.RenderTarget[0].BlendEnable = TRUE;
blendd.RenderTarget[0].BlendOp = blendd.RenderTarget[0].BlendOpAlpha
= D3D11_BLEND_OP_ADD;
blendd.RenderTarget[0].SrcBlend = blendd.RenderTarget[0].SrcBlendAlpha
= D3D11_BLEND_BLEND_FACTOR;
blendd.RenderTarget[0].DestBlend = blendd.RenderTarget[0].DestBlendAlpha
= D3D11_BLEND_ONE;
blendd.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
ensure(dev->CreateBlendState(&blendd, &blend));
D3D11_DEPTH_STENCIL_DESC zsad;
memset(&zsad, 0, sizeof(zsad));
zsad.DepthEnable = TRUE;
zsad.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
zsad.DepthFunc = D3D11_COMPARISON_EQUAL;
ensure(dev->CreateDepthStencilState(&zsad, &zsa));
blitter = new d3d11_blitter(dev);
}
return true;
}
};
d3d11_application* d3d11_application_create()
{
return new d3d11gears();
}

View File

@ -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.
*
**************************************************************************/
cbuffer cb
{
float4x4 proj;
float4x4 modelview;
float4 light;
float4 diffuse;
float4 specular;
float specular_power;
};
struct IA2VS
{
float4 position : POSITION;
float3 normal : NORMAL;
};
struct VS2PS
{
float4 position : SV_POSITION;
float3 normal : NORMAL;
float3 eye : EYE;
float3 light : LIGHT;
};
VS2PS vs(IA2VS input)
{
VS2PS result;
float3 view = mul((float3x4)modelview, input.position);
result.position = mul((float4x4)proj, float4(view, 1));
result.light = light - view;
result.eye = -view;
result.normal = mul((float3x3)modelview, input.normal);
return result;
}
float4 ps(VS2PS input) : SV_TARGET
{
float3 nlight = normalize(input.light);
float3 nnormal = normalize(input.normal);
float diffuse_c = saturate(dot(nnormal, nlight));
float specular_c = pow(saturate(dot(nnormal, normalize(normalize(input.eye) + nlight))), specular_power);
return diffuse * diffuse_c + specular * specular_c;
}

View File

@ -0,0 +1,309 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11gears.hlsl.ps.h /Eps /Tps_4_0 d3d11gears.hlsl
//
//
// Buffer Definitions:
//
// cbuffer cb
// {
//
// float4x4 proj; // Offset: 0 Size: 64 [unused]
// float4x4 modelview; // Offset: 64 Size: 64 [unused]
// float4 light; // Offset: 128 Size: 16 [unused]
// float4 diffuse; // Offset: 144 Size: 16
// float4 specular; // Offset: 160 Size: 16
// float specular_power; // Offset: 176 Size: 4
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// cb cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// NORMAL 0 xyz 1 NONE float xyz
// EYE 0 xyz 2 NONE float xyz
// LIGHT 0 xyz 3 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_constantbuffer cb0[12], immediateIndexed
dcl_input_ps linear v1.xyz
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xyz
dcl_output o0.xyzw
dcl_temps 3
dp3 r0.x, v2.xyzx, v2.xyzx
rsq r0.x, r0.x
dp3 r0.y, v3.xyzx, v3.xyzx
rsq r0.y, r0.y
mul r0.yzw, r0.yyyy, v3.xxyz
mad r1.xyz, v2.xyzx, r0.xxxx, r0.yzwy
dp3 r0.x, r1.xyzx, r1.xyzx
rsq r0.x, r0.x
mul r1.xyz, r0.xxxx, r1.xyzx
dp3 r0.x, v1.xyzx, v1.xyzx
rsq r0.x, r0.x
mul r2.xyz, r0.xxxx, v1.xyzx
dp3_sat r0.x, r2.xyzx, r1.xyzx
dp3_sat r0.y, r2.xyzx, r0.yzwy
log r0.x, r0.x
mul r0.x, r0.x, cb0[11].x
exp r0.x, r0.x
mul r1.xyzw, r0.xxxx, cb0[10].xyzw
mad o0.xyzw, cb0[9].xyzw, r0.yyyy, r1.xyzw
ret
// Approximately 20 instruction slots used
#endif
const BYTE g_ps[] =
{
68, 88, 66, 67, 91, 23,
206, 102, 23, 38, 122, 59,
55, 123, 215, 57, 98, 213,
215, 191, 1, 0, 0, 0,
92, 5, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
192, 1, 0, 0, 80, 2,
0, 0, 132, 2, 0, 0,
224, 4, 0, 0, 82, 68,
69, 70, 132, 1, 0, 0,
1, 0, 0, 0, 64, 0,
0, 0, 1, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 1, 0, 0,
80, 1, 0, 0, 60, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
99, 98, 0, 171, 60, 0,
0, 0, 6, 0, 0, 0,
88, 0, 0, 0, 192, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 232, 0,
0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 0, 0,
0, 0, 240, 0, 0, 0,
0, 0, 0, 0, 0, 1,
0, 0, 64, 0, 0, 0,
64, 0, 0, 0, 0, 0,
0, 0, 240, 0, 0, 0,
0, 0, 0, 0, 10, 1,
0, 0, 128, 0, 0, 0,
16, 0, 0, 0, 0, 0,
0, 0, 16, 1, 0, 0,
0, 0, 0, 0, 32, 1,
0, 0, 144, 0, 0, 0,
16, 0, 0, 0, 2, 0,
0, 0, 16, 1, 0, 0,
0, 0, 0, 0, 40, 1,
0, 0, 160, 0, 0, 0,
16, 0, 0, 0, 2, 0,
0, 0, 16, 1, 0, 0,
0, 0, 0, 0, 49, 1,
0, 0, 176, 0, 0, 0,
4, 0, 0, 0, 2, 0,
0, 0, 64, 1, 0, 0,
0, 0, 0, 0, 112, 114,
111, 106, 0, 171, 171, 171,
3, 0, 3, 0, 4, 0,
4, 0, 0, 0, 0, 0,
0, 0, 0, 0, 109, 111,
100, 101, 108, 118, 105, 101,
119, 0, 108, 105, 103, 104,
116, 0, 1, 0, 3, 0,
1, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0,
100, 105, 102, 102, 117, 115,
101, 0, 115, 112, 101, 99,
117, 108, 97, 114, 0, 115,
112, 101, 99, 117, 108, 97,
114, 95, 112, 111, 119, 101,
114, 0, 0, 0, 3, 0,
1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
77, 105, 99, 114, 111, 115,
111, 102, 116, 32, 40, 82,
41, 32, 72, 76, 83, 76,
32, 83, 104, 97, 100, 101,
114, 32, 67, 111, 109, 112,
105, 108, 101, 114, 32, 57,
46, 50, 57, 46, 57, 53,
50, 46, 51, 49, 49, 49,
0, 171, 171, 171, 73, 83,
71, 78, 136, 0, 0, 0,
4, 0, 0, 0, 8, 0,
0, 0, 104, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 116, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
1, 0, 0, 0, 7, 7,
0, 0, 123, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
2, 0, 0, 0, 7, 7,
0, 0, 127, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
3, 0, 0, 0, 7, 7,
0, 0, 83, 86, 95, 80,
79, 83, 73, 84, 73, 79,
78, 0, 78, 79, 82, 77,
65, 76, 0, 69, 89, 69,
0, 76, 73, 71, 72, 84,
0, 171, 171, 171, 79, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 0,
0, 0, 83, 86, 95, 84,
65, 82, 71, 69, 84, 0,
171, 171, 83, 72, 68, 82,
84, 2, 0, 0, 64, 0,
0, 0, 149, 0, 0, 0,
89, 0, 0, 4, 70, 142,
32, 0, 0, 0, 0, 0,
12, 0, 0, 0, 98, 16,
0, 3, 114, 16, 16, 0,
1, 0, 0, 0, 98, 16,
0, 3, 114, 16, 16, 0,
2, 0, 0, 0, 98, 16,
0, 3, 114, 16, 16, 0,
3, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
0, 0, 0, 0, 104, 0,
0, 2, 3, 0, 0, 0,
16, 0, 0, 7, 18, 0,
16, 0, 0, 0, 0, 0,
70, 18, 16, 0, 2, 0,
0, 0, 70, 18, 16, 0,
2, 0, 0, 0, 68, 0,
0, 5, 18, 0, 16, 0,
0, 0, 0, 0, 10, 0,
16, 0, 0, 0, 0, 0,
16, 0, 0, 7, 34, 0,
16, 0, 0, 0, 0, 0,
70, 18, 16, 0, 3, 0,
0, 0, 70, 18, 16, 0,
3, 0, 0, 0, 68, 0,
0, 5, 34, 0, 16, 0,
0, 0, 0, 0, 26, 0,
16, 0, 0, 0, 0, 0,
56, 0, 0, 7, 226, 0,
16, 0, 0, 0, 0, 0,
86, 5, 16, 0, 0, 0,
0, 0, 6, 25, 16, 0,
3, 0, 0, 0, 50, 0,
0, 9, 114, 0, 16, 0,
1, 0, 0, 0, 70, 18,
16, 0, 2, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 150, 7, 16, 0,
0, 0, 0, 0, 16, 0,
0, 7, 18, 0, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 1, 0,
0, 0, 68, 0, 0, 5,
18, 0, 16, 0, 0, 0,
0, 0, 10, 0, 16, 0,
0, 0, 0, 0, 56, 0,
0, 7, 114, 0, 16, 0,
1, 0, 0, 0, 6, 0,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 1, 0,
0, 0, 16, 0, 0, 7,
18, 0, 16, 0, 0, 0,
0, 0, 70, 18, 16, 0,
1, 0, 0, 0, 70, 18,
16, 0, 1, 0, 0, 0,
68, 0, 0, 5, 18, 0,
16, 0, 0, 0, 0, 0,
10, 0, 16, 0, 0, 0,
0, 0, 56, 0, 0, 7,
114, 0, 16, 0, 2, 0,
0, 0, 6, 0, 16, 0,
0, 0, 0, 0, 70, 18,
16, 0, 1, 0, 0, 0,
16, 32, 0, 7, 18, 0,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 2, 0,
0, 0, 70, 2, 16, 0,
1, 0, 0, 0, 16, 32,
0, 7, 34, 0, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 2, 0, 0, 0,
150, 7, 16, 0, 0, 0,
0, 0, 47, 0, 0, 5,
18, 0, 16, 0, 0, 0,
0, 0, 10, 0, 16, 0,
0, 0, 0, 0, 56, 0,
0, 8, 18, 0, 16, 0,
0, 0, 0, 0, 10, 0,
16, 0, 0, 0, 0, 0,
10, 128, 32, 0, 0, 0,
0, 0, 11, 0, 0, 0,
25, 0, 0, 5, 18, 0,
16, 0, 0, 0, 0, 0,
10, 0, 16, 0, 0, 0,
0, 0, 56, 0, 0, 8,
242, 0, 16, 0, 1, 0,
0, 0, 6, 0, 16, 0,
0, 0, 0, 0, 70, 142,
32, 0, 0, 0, 0, 0,
10, 0, 0, 0, 50, 0,
0, 10, 242, 32, 16, 0,
0, 0, 0, 0, 70, 142,
32, 0, 0, 0, 0, 0,
9, 0, 0, 0, 86, 5,
16, 0, 0, 0, 0, 0,
70, 14, 16, 0, 1, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 20, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 4, 0, 0, 0,
17, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 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, 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, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0
};

View File

@ -0,0 +1,308 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11gears.hlsl.vs.h /Evs /Tvs_4_0 d3d11gears.hlsl
//
//
// Buffer Definitions:
//
// cbuffer cb
// {
//
// float4x4 proj; // Offset: 0 Size: 64
// float4x4 modelview; // Offset: 64 Size: 64
// float4 light; // Offset: 128 Size: 16
// float4 diffuse; // Offset: 144 Size: 16 [unused]
// float4 specular; // Offset: 160 Size: 16 [unused]
// float specular_power; // Offset: 176 Size: 4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// cb cbuffer NA NA 0 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyzw 0 NONE float xyzw
// NORMAL 0 xyz 1 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float xyzw
// NORMAL 0 xyz 1 NONE float xyz
// EYE 0 xyz 2 NONE float xyz
// LIGHT 0 xyz 3 NONE float xyz
//
vs_4_0
dcl_constantbuffer cb0[9], immediateIndexed
dcl_input v0.xyzw
dcl_input v1.xyz
dcl_output_siv o0.xyzw, position
dcl_output o1.xyz
dcl_output o2.xyz
dcl_output o3.xyz
dcl_temps 2
mul r0.xyz, v0.yyyy, cb0[5].xyzx
mad r0.xyz, cb0[4].xyzx, v0.xxxx, r0.xyzx
mad r0.xyz, cb0[6].xyzx, v0.zzzz, r0.xyzx
mad r0.xyz, cb0[7].xyzx, v0.wwww, r0.xyzx
mul r1.xyzw, r0.yyyy, cb0[1].xyzw
mad r1.xyzw, cb0[0].xyzw, r0.xxxx, r1.xyzw
mad r1.xyzw, cb0[2].xyzw, r0.zzzz, r1.xyzw
add o0.xyzw, r1.xyzw, cb0[3].xyzw
mul r1.xyz, v1.yyyy, cb0[5].xyzx
mad r1.xyz, cb0[4].xyzx, v1.xxxx, r1.xyzx
mad o1.xyz, cb0[6].xyzx, v1.zzzz, r1.xyzx
mov o2.xyz, -r0.xyzx
add o3.xyz, -r0.xyzx, cb0[8].xyzx
ret
// Approximately 14 instruction slots used
#endif
const BYTE g_vs[] =
{
68, 88, 66, 67, 251, 82,
65, 114, 135, 66, 139, 83,
7, 10, 20, 121, 102, 38,
44, 36, 1, 0, 0, 0,
104, 5, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
192, 1, 0, 0, 16, 2,
0, 0, 160, 2, 0, 0,
236, 4, 0, 0, 82, 68,
69, 70, 132, 1, 0, 0,
1, 0, 0, 0, 64, 0,
0, 0, 1, 0, 0, 0,
28, 0, 0, 0, 0, 4,
254, 255, 0, 1, 0, 0,
80, 1, 0, 0, 60, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
99, 98, 0, 171, 60, 0,
0, 0, 6, 0, 0, 0,
88, 0, 0, 0, 192, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 232, 0,
0, 0, 0, 0, 0, 0,
64, 0, 0, 0, 2, 0,
0, 0, 240, 0, 0, 0,
0, 0, 0, 0, 0, 1,
0, 0, 64, 0, 0, 0,
64, 0, 0, 0, 2, 0,
0, 0, 240, 0, 0, 0,
0, 0, 0, 0, 10, 1,
0, 0, 128, 0, 0, 0,
16, 0, 0, 0, 2, 0,
0, 0, 16, 1, 0, 0,
0, 0, 0, 0, 32, 1,
0, 0, 144, 0, 0, 0,
16, 0, 0, 0, 0, 0,
0, 0, 16, 1, 0, 0,
0, 0, 0, 0, 40, 1,
0, 0, 160, 0, 0, 0,
16, 0, 0, 0, 0, 0,
0, 0, 16, 1, 0, 0,
0, 0, 0, 0, 49, 1,
0, 0, 176, 0, 0, 0,
4, 0, 0, 0, 0, 0,
0, 0, 64, 1, 0, 0,
0, 0, 0, 0, 112, 114,
111, 106, 0, 171, 171, 171,
3, 0, 3, 0, 4, 0,
4, 0, 0, 0, 0, 0,
0, 0, 0, 0, 109, 111,
100, 101, 108, 118, 105, 101,
119, 0, 108, 105, 103, 104,
116, 0, 1, 0, 3, 0,
1, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0,
100, 105, 102, 102, 117, 115,
101, 0, 115, 112, 101, 99,
117, 108, 97, 114, 0, 115,
112, 101, 99, 117, 108, 97,
114, 95, 112, 111, 119, 101,
114, 0, 0, 0, 3, 0,
1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
77, 105, 99, 114, 111, 115,
111, 102, 116, 32, 40, 82,
41, 32, 72, 76, 83, 76,
32, 83, 104, 97, 100, 101,
114, 32, 67, 111, 109, 112,
105, 108, 101, 114, 32, 57,
46, 50, 57, 46, 57, 53,
50, 46, 51, 49, 49, 49,
0, 171, 171, 171, 73, 83,
71, 78, 72, 0, 0, 0,
2, 0, 0, 0, 8, 0,
0, 0, 56, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 15, 15,
0, 0, 65, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
1, 0, 0, 0, 7, 7,
0, 0, 80, 79, 83, 73,
84, 73, 79, 78, 0, 78,
79, 82, 77, 65, 76, 0,
79, 83, 71, 78, 136, 0,
0, 0, 4, 0, 0, 0,
8, 0, 0, 0, 104, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 116, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
7, 8, 0, 0, 123, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 2, 0, 0, 0,
7, 8, 0, 0, 127, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 3, 0, 0, 0,
7, 8, 0, 0, 83, 86,
95, 80, 79, 83, 73, 84,
73, 79, 78, 0, 78, 79,
82, 77, 65, 76, 0, 69,
89, 69, 0, 76, 73, 71,
72, 84, 0, 171, 171, 171,
83, 72, 68, 82, 68, 2,
0, 0, 64, 0, 1, 0,
145, 0, 0, 0, 89, 0,
0, 4, 70, 142, 32, 0,
0, 0, 0, 0, 9, 0,
0, 0, 95, 0, 0, 3,
242, 16, 16, 0, 0, 0,
0, 0, 95, 0, 0, 3,
114, 16, 16, 0, 1, 0,
0, 0, 103, 0, 0, 4,
242, 32, 16, 0, 0, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 3, 114, 32,
16, 0, 1, 0, 0, 0,
101, 0, 0, 3, 114, 32,
16, 0, 2, 0, 0, 0,
101, 0, 0, 3, 114, 32,
16, 0, 3, 0, 0, 0,
104, 0, 0, 2, 2, 0,
0, 0, 56, 0, 0, 8,
114, 0, 16, 0, 0, 0,
0, 0, 86, 21, 16, 0,
0, 0, 0, 0, 70, 130,
32, 0, 0, 0, 0, 0,
5, 0, 0, 0, 50, 0,
0, 10, 114, 0, 16, 0,
0, 0, 0, 0, 70, 130,
32, 0, 0, 0, 0, 0,
4, 0, 0, 0, 6, 16,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 0, 0,
0, 0, 50, 0, 0, 10,
114, 0, 16, 0, 0, 0,
0, 0, 70, 130, 32, 0,
0, 0, 0, 0, 6, 0,
0, 0, 166, 26, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 0, 0, 0, 0,
50, 0, 0, 10, 114, 0,
16, 0, 0, 0, 0, 0,
70, 130, 32, 0, 0, 0,
0, 0, 7, 0, 0, 0,
246, 31, 16, 0, 0, 0,
0, 0, 70, 2, 16, 0,
0, 0, 0, 0, 56, 0,
0, 8, 242, 0, 16, 0,
1, 0, 0, 0, 86, 5,
16, 0, 0, 0, 0, 0,
70, 142, 32, 0, 0, 0,
0, 0, 1, 0, 0, 0,
50, 0, 0, 10, 242, 0,
16, 0, 1, 0, 0, 0,
70, 142, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 70, 14, 16, 0,
1, 0, 0, 0, 50, 0,
0, 10, 242, 0, 16, 0,
1, 0, 0, 0, 70, 142,
32, 0, 0, 0, 0, 0,
2, 0, 0, 0, 166, 10,
16, 0, 0, 0, 0, 0,
70, 14, 16, 0, 1, 0,
0, 0, 0, 0, 0, 8,
242, 32, 16, 0, 0, 0,
0, 0, 70, 14, 16, 0,
1, 0, 0, 0, 70, 142,
32, 0, 0, 0, 0, 0,
3, 0, 0, 0, 56, 0,
0, 8, 114, 0, 16, 0,
1, 0, 0, 0, 86, 21,
16, 0, 1, 0, 0, 0,
70, 130, 32, 0, 0, 0,
0, 0, 5, 0, 0, 0,
50, 0, 0, 10, 114, 0,
16, 0, 1, 0, 0, 0,
70, 130, 32, 0, 0, 0,
0, 0, 4, 0, 0, 0,
6, 16, 16, 0, 1, 0,
0, 0, 70, 2, 16, 0,
1, 0, 0, 0, 50, 0,
0, 10, 114, 32, 16, 0,
1, 0, 0, 0, 70, 130,
32, 0, 0, 0, 0, 0,
6, 0, 0, 0, 166, 26,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 1, 0,
0, 0, 54, 0, 0, 6,
114, 32, 16, 0, 2, 0,
0, 0, 70, 2, 16, 128,
65, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 9,
114, 32, 16, 0, 3, 0,
0, 0, 70, 2, 16, 128,
65, 0, 0, 0, 0, 0,
0, 0, 70, 130, 32, 0,
0, 0, 0, 0, 8, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 14, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 6, 0, 0, 0,
5, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 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, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 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, 0, 0, 0,
0, 0, 0, 0
};

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{706313AB-8F2C-48D2-9F67-31AA043F48C9}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>d3d11gears</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d11app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>d3d11.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d11app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>d3d11.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\d3d11app\d3d11winmain.cpp" />
<ClCompile Include="d3d11gears.cpp" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="d3d11gears.hlsl">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).ps.h /Eps /Tps_4_0 %(Identity)
"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).vs.h /Evs /Tvs_4_0 %(Identity)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Identity).ps.h;%(Identity).vs.h;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\d3d11app\d3d11app.h" />
<ClInclude Include="d3d11gears.hlsl.ps.h" />
<ClInclude Include="d3d11gears.hlsl.vs.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,227 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
#define _USE_MATH_DEFINES
#include "d3d11app.h"
#include "d3d11spikysphere.hlsl.vs.h"
#include "d3d11spikysphere.hlsl.hs.h"
#include "d3d11spikysphere.hlsl.ds.h"
#include "d3d11spikysphere.hlsl.ps.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <D3DX10math.h>
struct cb_frame_t
{
D3DXMATRIX model;
D3DXMATRIX view_proj;
float disp_scale;
float disp_freq;
float tess_factor;
};
static float vertex_data[] =
{
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
0.0, 1.0, 0.0,
-1.0, 0.0, 0.0,
0.0, 0.0, 1.0,
0.0, -1.0, 0.0,
1.0, 0.0, 0.0,
0.0, 0.0, 1.0,
-1.0, 0.0, 0.0,
0.0, -1.0, 0.0,
0.0, 0.0, 1.0,
0.0, 1.0, 0.0,
1.0, 0.0, 0.0,
0.0, 0.0, -1.0,
-1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, -1.0,
1.0, 0.0, 0.0,
0.0, -1.0, 0.0,
0.0, 0.0, -1.0,
0.0, -1.0, 0.0,
-1.0, 0.0, 0.0,
0.0, 0.0, -1.0,
};
struct d3d11spikysphere : public d3d11_application
{
ID3D11Device* dev;
ID3D11PixelShader* ps;
ID3D11DomainShader* ds;
ID3D11HullShader* hs;
ID3D11VertexShader* vs;
ID3D11InputLayout* layout;
ID3D11Buffer* vb;
ID3D11RenderTargetView* rtv;
ID3D11DepthStencilView* zsv;
ID3D11Buffer* cb_frame;
int cur_width;
int cur_height;
d3d11spikysphere()
: cur_width(-1), cur_height(-1), zsv(0)
{}
bool init(ID3D11Device* dev, int argc, char** argv)
{
this->dev = dev;
ensure(dev->CreateVertexShader(g_vs, sizeof(g_vs), NULL, &vs));
ensure(dev->CreateHullShader(g_hs, sizeof(g_hs), NULL, &hs));
ensure(dev->CreateDomainShader(g_ds, sizeof(g_ds), NULL, &ds));
ensure(dev->CreatePixelShader(g_ps, sizeof(g_ps), NULL, &ps));
D3D11_INPUT_ELEMENT_DESC elements[1] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,
0, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
ensure(dev->CreateInputLayout(elements, 1, g_vs, sizeof(g_vs), &layout));
D3D11_BUFFER_DESC bufferd;
bufferd.ByteWidth = sizeof(vertex_data);
bufferd.Usage = D3D11_USAGE_IMMUTABLE;
bufferd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferd.CPUAccessFlags = 0;
bufferd.MiscFlags = 0;
bufferd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA buffersd;
buffersd.pSysMem = vertex_data;
ensure(dev->CreateBuffer(&bufferd, &buffersd, &vb));
D3D11_BUFFER_DESC cbd;
cbd.ByteWidth = (sizeof(cb_frame_t) + 15) & ~15;
cbd.Usage = D3D11_USAGE_DYNAMIC;
cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
cbd.MiscFlags = 0;
cbd.StructureByteStride = 0;
ensure(dev->CreateBuffer(&cbd, NULL, &cb_frame));
return true;
}
void draw(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* rtv, unsigned width, unsigned height, double time)
{
D3D11_VIEWPORT vp;
memset(&vp, 0, sizeof(vp));
vp.Width = (float)width;
vp.Height = (float)height;
vp.MaxDepth = 1.0f;
if(width != cur_width || height != cur_height)
{
if(zsv)
zsv->Release();
ID3D11Texture2D* zsbuf;
D3D11_TEXTURE2D_DESC zsbufd;
memset(&zsbufd, 0, sizeof(zsbufd));
zsbufd.Width = width;
zsbufd.Height = height;
zsbufd.Format = DXGI_FORMAT_D32_FLOAT;
zsbufd.ArraySize = 1;
zsbufd.MipLevels = 1;
zsbufd.SampleDesc.Count = 1;
zsbufd.BindFlags = D3D11_BIND_DEPTH_STENCIL;
ensure(dev->CreateTexture2D(&zsbufd, 0, &zsbuf));
ensure(dev->CreateDepthStencilView(zsbuf, 0, &zsv));
zsbuf->Release();
}
float black[4] = {0, 0, 0, 0};
D3D11_MAPPED_SUBRESOURCE map;
ensure(ctx->Map(cb_frame, 0, D3D11_MAP_WRITE_DISCARD, 0, &map));
cb_frame_t* cb_frame_data = (cb_frame_t*)map.pData;
D3DXMatrixIdentity(&cb_frame_data->model);
D3DXMATRIX view;
D3DXVECTOR3 eye(2.0f * (float)sin(time), 0.0f, 2.0f * (float)cos(time));
D3DXVECTOR3 at(0, 0, 0);
D3DXVECTOR3 up(0, 1, 0);
D3DXMatrixLookAtLH(&view, &eye, &at, &up);
D3DXMATRIX proj;
D3DXMatrixPerspectiveLH(&proj, 1.1f, 1.1f, 1.0f, 3.0f);
cb_frame_data->view_proj = view * proj;
float min_tess_factor = 1.0f;
cb_frame_data->tess_factor = (1.0f - (float)cos(time)) * ((64.0f - min_tess_factor) / 2.0f) + min_tess_factor;
cb_frame_data->disp_scale = 0.9f;
//cb_frame_data->disp_scale = (sin(time) + 1.0) / 2.0;
cb_frame_data->disp_freq = 5.0f * (float)M_PI;
//cb_frame_data->disp_freq = (4.0 + 4.0 * cos(time / 5.0)) * PI;
ctx->Unmap(cb_frame, 0);
ctx->HSSetConstantBuffers(0, 1, &cb_frame);
ctx->DSSetConstantBuffers(0, 1, &cb_frame);
//ctx->OMSetBlendState(bs, black, ~0);
//ctx->OMSetDepthStencilState(dss, 0);
ctx->OMSetRenderTargets(1, &rtv, zsv);
//ctx->RSSetState(rs);
ctx->RSSetViewports(1, &vp);
ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST);
ctx->IASetInputLayout(layout);
unsigned stride = 3 * 4;
unsigned offset = 0;
ctx->IASetVertexBuffers(0, 1, &vb, &stride, &offset);
ctx->VSSetShader(vs, NULL, 0);
ctx->HSSetShader(hs, NULL, 0);
ctx->DSSetShader(ds, NULL, 0);
ctx->GSSetShader(NULL, NULL, 0);
ctx->PSSetShader(ps, NULL, 0);
ctx->ClearRenderTargetView(rtv, black);
ctx->ClearDepthStencilView(zsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
ctx->Draw(3 * 8, 0);
}
};
d3d11_application* d3d11_application_create()
{
return new d3d11spikysphere();
}

View File

@ -0,0 +1,193 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
#define INPUT_PATCH_SIZE 3
#define OUTPUT_PATCH_SIZE 3
static const float PI = 3.141592653589793238462643f;
cbuffer cb_frame
{
float4x4 model;
float4x4 view_proj;
float disp_scale;
float disp_freq;
float tess_factor;
};
struct IA2VS
{
float3 position : POSITION;
};
struct VS2HS
{
float3 position : POSITION;
};
VS2HS vs(IA2VS input)
{
VS2HS result;
result.position = input.position;
return result;
}
struct HS2DS_PATCH
{
float tessouter[3] : SV_TessFactor;
float tessinner[1] : SV_InsideTessFactor;
};
struct HS2DS
{
float3 position : POSITION;
};
HS2DS_PATCH hs_patch(InputPatch<VS2HS, INPUT_PATCH_SIZE> ip)
{
HS2DS_PATCH result;
result.tessouter[0] = result.tessouter[1] = result.tessouter[2]
= result.tessinner[0] = tess_factor;
return result;
}
[domain("tri")]
[partitioning("fractional_even")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(OUTPUT_PATCH_SIZE)]
[patchconstantfunc("hs_patch")]
HS2DS hs(InputPatch<VS2HS, INPUT_PATCH_SIZE> p, uint i : SV_OutputControlPointID)
{
HS2DS result;
result.position = p[i].position;
return result;
}
struct DS2PS
{
float4 position : SV_POSITION;
float3 objpos : OBJPOS;
// float3 worldpos : WORLDPOS;
float3 objnormal : OBJNORMAL;
float3 worldnormal : WORLDNORMAL;
};
float3 dnormf_dt(float3 f, float3 dfdt)
{
float ff = dot(f, f);
return (ff * dfdt - dot(f, dfdt) * f) / (ff * sqrt(ff));
}
float3 map(float3 p, float3 q, float3 r, float3 k)
{
return normalize(p * k.x + q * k.y + r * k.z);
}
float3 dmap_du(float3 p, float3 q, float3 r, float3 k)
{
return dnormf_dt(p * k.x + q * k.y + r * k.z, p);
}
float dispf(float v)
{
return cos(v * disp_freq);
}
float ddispf(float v)
{
return -sin(v * disp_freq) * disp_freq;
}
float disp(float3 k)
{
return dispf(k.x) * dispf(k.y) * dispf(k.z);
}
float ddisp_du(float3 k)
{
return ddispf(k.x) * dispf(k.y) * dispf(k.z);
}
float3 ddisp(float3 k)
{
float3 f = float3(dispf(k.x), dispf(k.y), dispf(k.z));
return float3(ddispf(k.x) * f.y * f.z, ddispf(k.y) * f.z * f.x, ddispf(k.z) * f.x * f.y);
}
[domain("tri")]
DS2PS ds(HS2DS_PATCH input,
float3 k : SV_DomainLocation,
const OutputPatch<HS2DS, OUTPUT_PATCH_SIZE> patch)
{
DS2PS result;
float3 s = map(patch[0].position, patch[1].position, patch[2].position, k);
float3 d = 1.0 + disp(s) * disp_scale;
result.objpos = s * d;
result.objpos /= (1.0 + disp_scale);
float3 worldpos = mul(model, float4(result.objpos, 1.0f));
result.position = mul(view_proj, float4(worldpos, 1.0f));
float3 dd = ddisp(s) * disp_scale;
/*
float3 ds_du = dmap_du(patch[0].position, patch[1].position, patch[2].position, k);
float3 ds_dv = dmap_du(patch[1].position, patch[2].position, patch[0].position, k.yzx);
float3 ds_dw = dmap_du(patch[2].position, patch[0].position, patch[1].position, k.zxy);
float3 ds_dU = ds_du - ds_dw;
float3 ds_dV = ds_dv - ds_dw;
float3 dc_dU = s * dot(dd, ds_dU) + ds_dU * d;
float3 dc_dV = s * dot(dd, ds_dV) + ds_dV * d;
*/
// this should be faster
float3 _u = normalize((abs(s.x) > abs(s.y)) ? float3(-s.z, 0, s.x) : float3(0, -s.z, s.y));
float3 _v = normalize(cross(s, _u));
float3 dc_dU = s * dot(dd, _u) + _u * d;
float3 dc_dV = s * dot(dd, _v) + _v * d;
result.objnormal = normalize(cross(dc_dU, dc_dV));
result.worldnormal = mul(model, result.objnormal);
return result;
}
float4 ps(DS2PS input) : SV_TARGET
{
float3 pseudoambient = float3(0.4, 0.4, 0.6);
float3 diffuse = float3(0.6, 0.6, 0.4);
float3 light = normalize(float3(0, 1, -1));
float4 r;
// r.xyz = normalize(input.objpos + 2 * input.objnormal);
r.xyz = pseudoambient * saturate(dot(normalize(input.objnormal), normalize(input.objpos)));
r.xyz += saturate(dot(light, normalize(input.worldnormal))) * diffuse;
r.w = 1;
return r;
}

View File

@ -0,0 +1,623 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11spikysphere.hlsl.ds.h /Eds /Tds_5_0 d3d11spikysphere.hlsl
//
//
// Buffer Definitions:
//
// cbuffer cb_frame
// {
//
// float4x4 model; // Offset: 0 Size: 64
// float4x4 view_proj; // Offset: 64 Size: 64
// float disp_scale; // Offset: 128 Size: 4
// float disp_freq; // Offset: 132 Size: 4
// float tess_factor; // Offset: 136 Size: 4 [unused]
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// cb_frame cbuffer NA NA 0 1
//
//
//
// Patch Constant signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TessFactor 0 x 0 TRIEDGE float
// SV_TessFactor 1 x 1 TRIEDGE float
// SV_TessFactor 2 x 2 TRIEDGE float
// SV_InsideTessFactor 0 x 3 TRIINT float
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyz 0 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float xyzw
// OBJPOS 0 xyz 1 NONE float xyz
// OBJNORMAL 0 xyz 2 NONE float xyz
// WORLDNORMAL 0 xyz 3 NONE float xyz
//
// Tessellation Domain # of control points
// -------------------- --------------------
// Triangle 3
//
ds_5_0
dcl_input_control_point_count 3
dcl_tessellator_domain domain_tri
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[9], immediateIndexed
dcl_input vDomain.xyz
dcl_input vicp[3][0].xyz
dcl_output_siv o0.xyzw, position
dcl_output o1.xyz
dcl_output o2.xyz
dcl_output o3.xyz
dcl_temps 5
add r0.x, cb0[8].x, l(1.000000)
mul r0.yzw, vDomain.yyyy, vicp[1][0].yyzx
mad r0.yzw, vicp[0][0].yyzx, vDomain.xxxx, r0.yyzw
mad r0.yzw, vicp[2][0].yyzx, vDomain.zzzz, r0.yyzw
dp3 r1.x, r0.yzwy, r0.yzwy
rsq r1.x, r1.x
mul r0.yzw, r0.yyzw, r1.xxxx
mul r1.xyz, r0.wyzw, cb0[8].yyyy
sincos null, r2.xyz, r1.zxyz
sincos r1.xyz, null, -r1.xyzx
mul r1.xyz, r1.xyzx, cb0[8].yyyy
mul r1.xyz, r2.zxyz, r1.xyzx
mul r1.xyz, r2.xyzx, r1.xyzx
mul r1.xyz, r1.xyzx, cb0[8].xxxx
mul r1.w, r2.z, r2.y
mul r1.w, r2.x, r1.w
mad r1.w, r1.w, cb0[8].x, l(1.000000)
mul r2.xyz, r0.wyzw, r1.wwww
div r2.xyz, r2.xyzx, r0.xxxx
mul r3.xyz, r2.yyyy, cb0[1].xyzx
mad r3.xyz, cb0[0].xyzx, r2.xxxx, r3.xyzx
mad r3.xyz, cb0[2].xyzx, r2.zzzz, r3.xyzx
mov o1.xyz, r2.xyzx
add r2.xyz, r3.xyzx, cb0[3].xyzx
mul r3.xyzw, r2.yyyy, cb0[5].xyzw
mad r3.xyzw, cb0[4].xyzw, r2.xxxx, r3.xyzw
mad r2.xyzw, cb0[6].xyzw, r2.zzzz, r3.xyzw
add o0.xyzw, r2.xyzw, cb0[7].xyzw
mov r2.y, l(0)
lt r0.x, |r0.y|, |r0.w|
mul r2.xz, r0.zzwz, l(-1.000000, 0.000000, 1.000000, 0.000000)
mov r2.w, r0.y
movc r2.xyz, r0.xxxx, r2.zxyz, r2.wyxw
dp3 r0.x, r2.xyzx, r2.xyzx
rsq r0.x, r0.x
mul r2.xyz, r0.xxxx, r2.xyzx
mul r3.xyz, r0.wyzw, r2.xyzx
mad r3.xyz, r0.zwyz, r2.yzxy, -r3.xyzx
dp3 r0.x, r3.xyzx, r3.xyzx
rsq r0.x, r0.x
mul r3.xyz, r0.xxxx, r3.xyzx
dp3 r0.x, r1.yzxy, r3.xyzx
mul r3.xyz, r1.wwww, r3.xyzx
mul r4.xyz, r1.wwww, r2.xyzx
dp3 r1.x, r1.zxyz, r2.xyzx
mad r1.xyz, r0.zwyz, r1.xxxx, r4.xyzx
mad r0.xyz, r0.yzwy, r0.xxxx, r3.xyzx
mul r2.xyz, r0.xyzx, r1.xyzx
mad r0.xyz, r1.zxyz, r0.yzxy, -r2.xyzx
dp3 r0.w, r0.xyzx, r0.xyzx
rsq r0.w, r0.w
mul r0.xyz, r0.wwww, r0.xyzx
mov o2.xyz, r0.xyzx
mul r1.xyz, r0.yyyy, cb0[1].xyzx
mad r0.xyw, cb0[0].xyxz, r0.xxxx, r1.xyxz
mad o3.xyz, cb0[2].xyzx, r0.zzzz, r0.xywx
ret
// Approximately 57 instruction slots used
#endif
const BYTE g_ds[] =
{
68, 88, 66, 67, 0, 128,
111, 5, 170, 61, 238, 30,
169, 104, 139, 245, 182, 233,
180, 255, 1, 0, 0, 0,
112, 11, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
68, 2, 0, 0, 120, 2,
0, 0, 12, 3, 0, 0,
168, 3, 0, 0, 212, 10,
0, 0, 82, 68, 69, 70,
4, 2, 0, 0, 1, 0,
0, 0, 104, 0, 0, 0,
1, 0, 0, 0, 60, 0,
0, 0, 0, 5, 83, 68,
0, 1, 0, 0, 210, 1,
0, 0, 82, 68, 49, 49,
60, 0, 0, 0, 24, 0,
0, 0, 32, 0, 0, 0,
40, 0, 0, 0, 36, 0,
0, 0, 12, 0, 0, 0,
0, 0, 0, 0, 92, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
99, 98, 95, 102, 114, 97,
109, 101, 0, 171, 171, 171,
92, 0, 0, 0, 5, 0,
0, 0, 128, 0, 0, 0,
144, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
72, 1, 0, 0, 0, 0,
0, 0, 64, 0, 0, 0,
2, 0, 0, 0, 88, 1,
0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 255, 255, 255, 255,
0, 0, 0, 0, 124, 1,
0, 0, 64, 0, 0, 0,
64, 0, 0, 0, 2, 0,
0, 0, 88, 1, 0, 0,
0, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 134, 1, 0, 0,
128, 0, 0, 0, 4, 0,
0, 0, 2, 0, 0, 0,
152, 1, 0, 0, 0, 0,
0, 0, 255, 255, 255, 255,
0, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
188, 1, 0, 0, 132, 0,
0, 0, 4, 0, 0, 0,
2, 0, 0, 0, 152, 1,
0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 255, 255, 255, 255,
0, 0, 0, 0, 198, 1,
0, 0, 136, 0, 0, 0,
4, 0, 0, 0, 0, 0,
0, 0, 152, 1, 0, 0,
0, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 109, 111, 100, 101,
108, 0, 102, 108, 111, 97,
116, 52, 120, 52, 0, 171,
3, 0, 3, 0, 4, 0,
4, 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, 78, 1, 0, 0,
118, 105, 101, 119, 95, 112,
114, 111, 106, 0, 100, 105,
115, 112, 95, 115, 99, 97,
108, 101, 0, 102, 108, 111,
97, 116, 0, 171, 0, 0,
3, 0, 1, 0, 1, 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,
145, 1, 0, 0, 100, 105,
115, 112, 95, 102, 114, 101,
113, 0, 116, 101, 115, 115,
95, 102, 97, 99, 116, 111,
114, 0, 77, 105, 99, 114,
111, 115, 111, 102, 116, 32,
40, 82, 41, 32, 72, 76,
83, 76, 32, 83, 104, 97,
100, 101, 114, 32, 67, 111,
109, 112, 105, 108, 101, 114,
32, 57, 46, 50, 57, 46,
57, 53, 50, 46, 51, 49,
49, 49, 0, 171, 73, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 7, 7,
0, 0, 80, 79, 83, 73,
84, 73, 79, 78, 0, 171,
171, 171, 80, 67, 83, 71,
140, 0, 0, 0, 4, 0,
0, 0, 8, 0, 0, 0,
104, 0, 0, 0, 0, 0,
0, 0, 13, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
104, 0, 0, 0, 1, 0,
0, 0, 13, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 1, 0, 0, 0,
104, 0, 0, 0, 2, 0,
0, 0, 13, 0, 0, 0,
3, 0, 0, 0, 2, 0,
0, 0, 1, 0, 0, 0,
118, 0, 0, 0, 0, 0,
0, 0, 14, 0, 0, 0,
3, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
83, 86, 95, 84, 101, 115,
115, 70, 97, 99, 116, 111,
114, 0, 83, 86, 95, 73,
110, 115, 105, 100, 101, 84,
101, 115, 115, 70, 97, 99,
116, 111, 114, 0, 171, 171,
79, 83, 71, 78, 148, 0,
0, 0, 4, 0, 0, 0,
8, 0, 0, 0, 104, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 116, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
7, 8, 0, 0, 123, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 2, 0, 0, 0,
7, 8, 0, 0, 133, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 3, 0, 0, 0,
7, 8, 0, 0, 83, 86,
95, 80, 79, 83, 73, 84,
73, 79, 78, 0, 79, 66,
74, 80, 79, 83, 0, 79,
66, 74, 78, 79, 82, 77,
65, 76, 0, 87, 79, 82,
76, 68, 78, 79, 82, 77,
65, 76, 0, 171, 171, 171,
83, 72, 69, 88, 36, 7,
0, 0, 80, 0, 4, 0,
201, 1, 0, 0, 147, 24,
0, 1, 149, 16, 0, 1,
106, 8, 0, 1, 89, 0,
0, 4, 70, 142, 32, 0,
0, 0, 0, 0, 9, 0,
0, 0, 95, 0, 0, 2,
114, 192, 1, 0, 95, 0,
0, 4, 114, 144, 33, 0,
3, 0, 0, 0, 0, 0,
0, 0, 103, 0, 0, 4,
242, 32, 16, 0, 0, 0,
0, 0, 1, 0, 0, 0,
101, 0, 0, 3, 114, 32,
16, 0, 1, 0, 0, 0,
101, 0, 0, 3, 114, 32,
16, 0, 2, 0, 0, 0,
101, 0, 0, 3, 114, 32,
16, 0, 3, 0, 0, 0,
104, 0, 0, 2, 5, 0,
0, 0, 0, 0, 0, 8,
18, 0, 16, 0, 0, 0,
0, 0, 10, 128, 32, 0,
0, 0, 0, 0, 8, 0,
0, 0, 1, 64, 0, 0,
0, 0, 128, 63, 56, 0,
0, 7, 226, 0, 16, 0,
0, 0, 0, 0, 86, 197,
1, 0, 86, 146, 33, 0,
1, 0, 0, 0, 0, 0,
0, 0, 50, 0, 0, 9,
226, 0, 16, 0, 0, 0,
0, 0, 86, 146, 33, 0,
0, 0, 0, 0, 0, 0,
0, 0, 6, 192, 1, 0,
86, 14, 16, 0, 0, 0,
0, 0, 50, 0, 0, 9,
226, 0, 16, 0, 0, 0,
0, 0, 86, 146, 33, 0,
2, 0, 0, 0, 0, 0,
0, 0, 166, 202, 1, 0,
86, 14, 16, 0, 0, 0,
0, 0, 16, 0, 0, 7,
18, 0, 16, 0, 1, 0,
0, 0, 150, 7, 16, 0,
0, 0, 0, 0, 150, 7,
16, 0, 0, 0, 0, 0,
68, 0, 0, 5, 18, 0,
16, 0, 1, 0, 0, 0,
10, 0, 16, 0, 1, 0,
0, 0, 56, 0, 0, 7,
226, 0, 16, 0, 0, 0,
0, 0, 86, 14, 16, 0,
0, 0, 0, 0, 6, 0,
16, 0, 1, 0, 0, 0,
56, 0, 0, 8, 114, 0,
16, 0, 1, 0, 0, 0,
118, 14, 16, 0, 0, 0,
0, 0, 86, 133, 32, 0,
0, 0, 0, 0, 8, 0,
0, 0, 77, 0, 0, 6,
0, 208, 0, 0, 114, 0,
16, 0, 2, 0, 0, 0,
38, 9, 16, 0, 1, 0,
0, 0, 77, 0, 0, 7,
114, 0, 16, 0, 1, 0,
0, 0, 0, 208, 0, 0,
70, 2, 16, 128, 65, 0,
0, 0, 1, 0, 0, 0,
56, 0, 0, 8, 114, 0,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 1, 0,
0, 0, 86, 133, 32, 0,
0, 0, 0, 0, 8, 0,
0, 0, 56, 0, 0, 7,
114, 0, 16, 0, 1, 0,
0, 0, 38, 9, 16, 0,
2, 0, 0, 0, 70, 2,
16, 0, 1, 0, 0, 0,
56, 0, 0, 7, 114, 0,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 2, 0,
0, 0, 70, 2, 16, 0,
1, 0, 0, 0, 56, 0,
0, 8, 114, 0, 16, 0,
1, 0, 0, 0, 70, 2,
16, 0, 1, 0, 0, 0,
6, 128, 32, 0, 0, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 7, 130, 0,
16, 0, 1, 0, 0, 0,
42, 0, 16, 0, 2, 0,
0, 0, 26, 0, 16, 0,
2, 0, 0, 0, 56, 0,
0, 7, 130, 0, 16, 0,
1, 0, 0, 0, 10, 0,
16, 0, 2, 0, 0, 0,
58, 0, 16, 0, 1, 0,
0, 0, 50, 0, 0, 10,
130, 0, 16, 0, 1, 0,
0, 0, 58, 0, 16, 0,
1, 0, 0, 0, 10, 128,
32, 0, 0, 0, 0, 0,
8, 0, 0, 0, 1, 64,
0, 0, 0, 0, 128, 63,
56, 0, 0, 7, 114, 0,
16, 0, 2, 0, 0, 0,
118, 14, 16, 0, 0, 0,
0, 0, 246, 15, 16, 0,
1, 0, 0, 0, 14, 0,
0, 7, 114, 0, 16, 0,
2, 0, 0, 0, 70, 2,
16, 0, 2, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 56, 0, 0, 8,
114, 0, 16, 0, 3, 0,
0, 0, 86, 5, 16, 0,
2, 0, 0, 0, 70, 130,
32, 0, 0, 0, 0, 0,
1, 0, 0, 0, 50, 0,
0, 10, 114, 0, 16, 0,
3, 0, 0, 0, 70, 130,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 6, 0,
16, 0, 2, 0, 0, 0,
70, 2, 16, 0, 3, 0,
0, 0, 50, 0, 0, 10,
114, 0, 16, 0, 3, 0,
0, 0, 70, 130, 32, 0,
0, 0, 0, 0, 2, 0,
0, 0, 166, 10, 16, 0,
2, 0, 0, 0, 70, 2,
16, 0, 3, 0, 0, 0,
54, 0, 0, 5, 114, 32,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 2, 0,
0, 0, 0, 0, 0, 8,
114, 0, 16, 0, 2, 0,
0, 0, 70, 2, 16, 0,
3, 0, 0, 0, 70, 130,
32, 0, 0, 0, 0, 0,
3, 0, 0, 0, 56, 0,
0, 8, 242, 0, 16, 0,
3, 0, 0, 0, 86, 5,
16, 0, 2, 0, 0, 0,
70, 142, 32, 0, 0, 0,
0, 0, 5, 0, 0, 0,
50, 0, 0, 10, 242, 0,
16, 0, 3, 0, 0, 0,
70, 142, 32, 0, 0, 0,
0, 0, 4, 0, 0, 0,
6, 0, 16, 0, 2, 0,
0, 0, 70, 14, 16, 0,
3, 0, 0, 0, 50, 0,
0, 10, 242, 0, 16, 0,
2, 0, 0, 0, 70, 142,
32, 0, 0, 0, 0, 0,
6, 0, 0, 0, 166, 10,
16, 0, 2, 0, 0, 0,
70, 14, 16, 0, 3, 0,
0, 0, 0, 0, 0, 8,
242, 32, 16, 0, 0, 0,
0, 0, 70, 14, 16, 0,
2, 0, 0, 0, 70, 142,
32, 0, 0, 0, 0, 0,
7, 0, 0, 0, 54, 0,
0, 5, 34, 0, 16, 0,
2, 0, 0, 0, 1, 64,
0, 0, 0, 0, 0, 0,
49, 0, 0, 9, 18, 0,
16, 0, 0, 0, 0, 0,
26, 0, 16, 128, 129, 0,
0, 0, 0, 0, 0, 0,
58, 0, 16, 128, 129, 0,
0, 0, 0, 0, 0, 0,
56, 0, 0, 10, 82, 0,
16, 0, 2, 0, 0, 0,
166, 11, 16, 0, 0, 0,
0, 0, 2, 64, 0, 0,
0, 0, 128, 191, 0, 0,
0, 0, 0, 0, 128, 63,
0, 0, 0, 0, 54, 0,
0, 5, 130, 0, 16, 0,
2, 0, 0, 0, 26, 0,
16, 0, 0, 0, 0, 0,
55, 0, 0, 9, 114, 0,
16, 0, 2, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 38, 9, 16, 0,
2, 0, 0, 0, 118, 12,
16, 0, 2, 0, 0, 0,
16, 0, 0, 7, 18, 0,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 2, 0,
0, 0, 70, 2, 16, 0,
2, 0, 0, 0, 68, 0,
0, 5, 18, 0, 16, 0,
0, 0, 0, 0, 10, 0,
16, 0, 0, 0, 0, 0,
56, 0, 0, 7, 114, 0,
16, 0, 2, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 70, 2, 16, 0,
2, 0, 0, 0, 56, 0,
0, 7, 114, 0, 16, 0,
3, 0, 0, 0, 118, 14,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 2, 0,
0, 0, 50, 0, 0, 10,
114, 0, 16, 0, 3, 0,
0, 0, 230, 9, 16, 0,
0, 0, 0, 0, 150, 4,
16, 0, 2, 0, 0, 0,
70, 2, 16, 128, 65, 0,
0, 0, 3, 0, 0, 0,
16, 0, 0, 7, 18, 0,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 3, 0,
0, 0, 70, 2, 16, 0,
3, 0, 0, 0, 68, 0,
0, 5, 18, 0, 16, 0,
0, 0, 0, 0, 10, 0,
16, 0, 0, 0, 0, 0,
56, 0, 0, 7, 114, 0,
16, 0, 3, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 70, 2, 16, 0,
3, 0, 0, 0, 16, 0,
0, 7, 18, 0, 16, 0,
0, 0, 0, 0, 150, 4,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 3, 0,
0, 0, 56, 0, 0, 7,
114, 0, 16, 0, 3, 0,
0, 0, 246, 15, 16, 0,
1, 0, 0, 0, 70, 2,
16, 0, 3, 0, 0, 0,
56, 0, 0, 7, 114, 0,
16, 0, 4, 0, 0, 0,
246, 15, 16, 0, 1, 0,
0, 0, 70, 2, 16, 0,
2, 0, 0, 0, 16, 0,
0, 7, 18, 0, 16, 0,
1, 0, 0, 0, 38, 9,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 2, 0,
0, 0, 50, 0, 0, 9,
114, 0, 16, 0, 1, 0,
0, 0, 230, 9, 16, 0,
0, 0, 0, 0, 6, 0,
16, 0, 1, 0, 0, 0,
70, 2, 16, 0, 4, 0,
0, 0, 50, 0, 0, 9,
114, 0, 16, 0, 0, 0,
0, 0, 150, 7, 16, 0,
0, 0, 0, 0, 6, 0,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 3, 0,
0, 0, 56, 0, 0, 7,
114, 0, 16, 0, 2, 0,
0, 0, 70, 2, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 1, 0, 0, 0,
50, 0, 0, 10, 114, 0,
16, 0, 0, 0, 0, 0,
38, 9, 16, 0, 1, 0,
0, 0, 150, 4, 16, 0,
0, 0, 0, 0, 70, 2,
16, 128, 65, 0, 0, 0,
2, 0, 0, 0, 16, 0,
0, 7, 130, 0, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 0, 0,
0, 0, 68, 0, 0, 5,
130, 0, 16, 0, 0, 0,
0, 0, 58, 0, 16, 0,
0, 0, 0, 0, 56, 0,
0, 7, 114, 0, 16, 0,
0, 0, 0, 0, 246, 15,
16, 0, 0, 0, 0, 0,
70, 2, 16, 0, 0, 0,
0, 0, 54, 0, 0, 5,
114, 32, 16, 0, 2, 0,
0, 0, 70, 2, 16, 0,
0, 0, 0, 0, 56, 0,
0, 8, 114, 0, 16, 0,
1, 0, 0, 0, 86, 5,
16, 0, 0, 0, 0, 0,
70, 130, 32, 0, 0, 0,
0, 0, 1, 0, 0, 0,
50, 0, 0, 10, 178, 0,
16, 0, 0, 0, 0, 0,
70, 136, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 70, 8, 16, 0,
1, 0, 0, 0, 50, 0,
0, 10, 114, 32, 16, 0,
3, 0, 0, 0, 70, 130,
32, 0, 0, 0, 0, 0,
2, 0, 0, 0, 166, 10,
16, 0, 0, 0, 0, 0,
70, 3, 16, 0, 0, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 148, 0,
0, 0, 57, 0, 0, 0,
5, 0, 0, 0, 0, 0,
0, 0, 6, 0, 0, 0,
38, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 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, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
4, 0, 0, 0, 1, 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, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};

View File

@ -0,0 +1,297 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11spikysphere.hlsl.hs.h /Ehs /Ths_5_0 d3d11spikysphere.hlsl
//
//
// Buffer Definitions:
//
// cbuffer cb_frame
// {
//
// float4x4 model; // Offset: 0 Size: 64 [unused]
// float4x4 view_proj; // Offset: 64 Size: 64 [unused]
// float disp_scale; // Offset: 128 Size: 4 [unused]
// float disp_freq; // Offset: 132 Size: 4 [unused]
// float tess_factor; // Offset: 136 Size: 4
//
// }
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// cb_frame cbuffer NA NA 0 1
//
//
//
// Patch Constant signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TessFactor 0 x 0 TRIEDGE float x
// SV_TessFactor 1 x 1 TRIEDGE float x
// SV_TessFactor 2 x 2 TRIEDGE float x
// SV_InsideTessFactor 0 x 3 TRIINT float x
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyz 0 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyz 0 NONE float xyz
//
// Tessellation Domain # of control points
// -------------------- --------------------
// Triangle 3
//
// Tessellation Output Primitive Partitioning Type
// ------------------------------ ------------------
// Clockwise Triangles Even Fractional
//
hs_5_0
hs_decls
dcl_input_control_point_count 3
dcl_output_control_point_count 3
dcl_tessellator_domain domain_tri
dcl_tessellator_partitioning partitioning_fractional_even
dcl_tessellator_output_primitive output_triangle_cw
dcl_globalFlags refactoringAllowed
dcl_constantbuffer cb0[9], immediateIndexed
hs_fork_phase
dcl_hs_fork_phase_instance_count 3
dcl_input vForkInstanceID
dcl_output_siv o0.x, finalTriUeq0EdgeTessFactor
dcl_output_siv o1.x, finalTriVeq0EdgeTessFactor
dcl_output_siv o2.x, finalTriWeq0EdgeTessFactor
dcl_temps 1
dcl_indexrange o0.x 3
mov r0.x, vForkInstanceID.x
mov o[r0.x + 0].x, cb0[8].z
ret
hs_fork_phase
dcl_output_siv o3.x, finalTriInsideTessFactor
mov o3.x, cb0[8].z
ret
// Approximately 5 instruction slots used
#endif
const BYTE g_hs[] =
{
68, 88, 66, 67, 174, 23,
253, 184, 171, 234, 181, 122,
114, 17, 23, 172, 69, 130,
17, 19, 1, 0, 0, 0,
212, 4, 0, 0, 6, 0,
0, 0, 56, 0, 0, 0,
68, 2, 0, 0, 120, 2,
0, 0, 172, 2, 0, 0,
64, 3, 0, 0, 56, 4,
0, 0, 82, 68, 69, 70,
4, 2, 0, 0, 1, 0,
0, 0, 104, 0, 0, 0,
1, 0, 0, 0, 60, 0,
0, 0, 0, 5, 83, 72,
0, 1, 0, 0, 210, 1,
0, 0, 82, 68, 49, 49,
60, 0, 0, 0, 24, 0,
0, 0, 32, 0, 0, 0,
40, 0, 0, 0, 36, 0,
0, 0, 12, 0, 0, 0,
0, 0, 0, 0, 92, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
99, 98, 95, 102, 114, 97,
109, 101, 0, 171, 171, 171,
92, 0, 0, 0, 5, 0,
0, 0, 128, 0, 0, 0,
144, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
72, 1, 0, 0, 0, 0,
0, 0, 64, 0, 0, 0,
0, 0, 0, 0, 88, 1,
0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 255, 255, 255, 255,
0, 0, 0, 0, 124, 1,
0, 0, 64, 0, 0, 0,
64, 0, 0, 0, 0, 0,
0, 0, 88, 1, 0, 0,
0, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 134, 1, 0, 0,
128, 0, 0, 0, 4, 0,
0, 0, 0, 0, 0, 0,
152, 1, 0, 0, 0, 0,
0, 0, 255, 255, 255, 255,
0, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
188, 1, 0, 0, 132, 0,
0, 0, 4, 0, 0, 0,
0, 0, 0, 0, 152, 1,
0, 0, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 255, 255, 255, 255,
0, 0, 0, 0, 198, 1,
0, 0, 136, 0, 0, 0,
4, 0, 0, 0, 2, 0,
0, 0, 152, 1, 0, 0,
0, 0, 0, 0, 255, 255,
255, 255, 0, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 109, 111, 100, 101,
108, 0, 102, 108, 111, 97,
116, 52, 120, 52, 0, 171,
3, 0, 3, 0, 4, 0,
4, 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, 78, 1, 0, 0,
118, 105, 101, 119, 95, 112,
114, 111, 106, 0, 100, 105,
115, 112, 95, 115, 99, 97,
108, 101, 0, 102, 108, 111,
97, 116, 0, 171, 0, 0,
3, 0, 1, 0, 1, 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,
145, 1, 0, 0, 100, 105,
115, 112, 95, 102, 114, 101,
113, 0, 116, 101, 115, 115,
95, 102, 97, 99, 116, 111,
114, 0, 77, 105, 99, 114,
111, 115, 111, 102, 116, 32,
40, 82, 41, 32, 72, 76,
83, 76, 32, 83, 104, 97,
100, 101, 114, 32, 67, 111,
109, 112, 105, 108, 101, 114,
32, 57, 46, 50, 57, 46,
57, 53, 50, 46, 51, 49,
49, 49, 0, 171, 73, 83,
71, 78, 44, 0, 0, 0,
1, 0, 0, 0, 8, 0,
0, 0, 32, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 7, 7,
0, 0, 80, 79, 83, 73,
84, 73, 79, 78, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 7, 8, 0, 0,
80, 79, 83, 73, 84, 73,
79, 78, 0, 171, 171, 171,
80, 67, 83, 71, 140, 0,
0, 0, 4, 0, 0, 0,
8, 0, 0, 0, 104, 0,
0, 0, 0, 0, 0, 0,
13, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
1, 14, 0, 0, 104, 0,
0, 0, 1, 0, 0, 0,
13, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
1, 14, 0, 0, 104, 0,
0, 0, 2, 0, 0, 0,
13, 0, 0, 0, 3, 0,
0, 0, 2, 0, 0, 0,
1, 14, 0, 0, 118, 0,
0, 0, 0, 0, 0, 0,
14, 0, 0, 0, 3, 0,
0, 0, 3, 0, 0, 0,
1, 14, 0, 0, 83, 86,
95, 84, 101, 115, 115, 70,
97, 99, 116, 111, 114, 0,
83, 86, 95, 73, 110, 115,
105, 100, 101, 84, 101, 115,
115, 70, 97, 99, 116, 111,
114, 0, 171, 171, 83, 72,
69, 88, 240, 0, 0, 0,
80, 0, 3, 0, 60, 0,
0, 0, 113, 0, 0, 1,
147, 24, 0, 1, 148, 24,
0, 1, 149, 16, 0, 1,
150, 32, 0, 1, 151, 24,
0, 1, 106, 8, 0, 1,
89, 0, 0, 4, 70, 142,
32, 0, 0, 0, 0, 0,
9, 0, 0, 0, 115, 0,
0, 1, 153, 0, 0, 2,
3, 0, 0, 0, 95, 0,
0, 2, 0, 112, 1, 0,
103, 0, 0, 4, 18, 32,
16, 0, 0, 0, 0, 0,
17, 0, 0, 0, 103, 0,
0, 4, 18, 32, 16, 0,
1, 0, 0, 0, 18, 0,
0, 0, 103, 0, 0, 4,
18, 32, 16, 0, 2, 0,
0, 0, 19, 0, 0, 0,
104, 0, 0, 2, 1, 0,
0, 0, 91, 0, 0, 4,
18, 32, 16, 0, 0, 0,
0, 0, 3, 0, 0, 0,
54, 0, 0, 4, 18, 0,
16, 0, 0, 0, 0, 0,
10, 112, 1, 0, 54, 0,
0, 7, 18, 32, 144, 0,
10, 0, 16, 0, 0, 0,
0, 0, 42, 128, 32, 0,
0, 0, 0, 0, 8, 0,
0, 0, 62, 0, 0, 1,
115, 0, 0, 1, 103, 0,
0, 4, 18, 32, 16, 0,
3, 0, 0, 0, 20, 0,
0, 0, 54, 0, 0, 6,
18, 32, 16, 0, 3, 0,
0, 0, 42, 128, 32, 0,
0, 0, 0, 0, 8, 0,
0, 0, 62, 0, 0, 1,
83, 84, 65, 84, 148, 0,
0, 0, 5, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 4, 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, 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, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 10, 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, 3, 0, 0, 0,
3, 0, 0, 0, 4, 0,
0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
};

View File

@ -0,0 +1,211 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11spikysphere.hlsl.ps.h /Eps /Tps_4_0 d3d11spikysphere.hlsl
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// OBJPOS 0 xyz 1 NONE float xyz
// OBJNORMAL 0 xyz 2 NONE float xyz
// WORLDNORMAL 0 xyz 3 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_input_ps linear v1.xyz
dcl_input_ps linear v2.xyz
dcl_input_ps linear v3.xyz
dcl_output o0.xyzw
dcl_temps 2
dp3 r0.x, v2.xyzx, v2.xyzx
rsq r0.x, r0.x
mul r0.xyz, r0.xxxx, v2.xyzx
dp3 r0.w, v1.xyzx, v1.xyzx
rsq r0.w, r0.w
mul r1.xyz, r0.wwww, v1.xyzx
dp3_sat r0.x, r0.xyzx, r1.xyzx
dp3 r0.y, v3.xyzx, v3.xyzx
rsq r0.y, r0.y
mul r0.yz, r0.yyyy, v3.yyzy
dp2_sat r0.y, l(0.707107, -0.707107, 0.000000, 0.000000), r0.yzyy
mul r0.yzw, r0.yyyy, l(0.000000, 0.600000, 0.600000, 0.400000)
mad o0.xyz, r0.xxxx, l(0.400000, 0.400000, 0.600000, 0.000000), r0.yzwy
mov o0.w, l(1.000000)
ret
// Approximately 15 instruction slots used
#endif
const BYTE g_ps[] =
{
68, 88, 66, 67, 211, 117,
143, 38, 226, 40, 181, 77,
39, 255, 33, 137, 74, 241,
40, 100, 1, 0, 0, 0,
184, 3, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
140, 0, 0, 0, 40, 1,
0, 0, 92, 1, 0, 0,
60, 3, 0, 0, 82, 68,
69, 70, 80, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 1, 0, 0,
28, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
148, 0, 0, 0, 4, 0,
0, 0, 8, 0, 0, 0,
104, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
116, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 7, 7, 0, 0,
123, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 2, 0,
0, 0, 7, 7, 0, 0,
133, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 3, 0,
0, 0, 7, 7, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
79, 66, 74, 80, 79, 83,
0, 79, 66, 74, 78, 79,
82, 77, 65, 76, 0, 87,
79, 82, 76, 68, 78, 79,
82, 77, 65, 76, 0, 171,
171, 171, 79, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 84, 65, 82,
71, 69, 84, 0, 171, 171,
83, 72, 68, 82, 216, 1,
0, 0, 64, 0, 0, 0,
118, 0, 0, 0, 98, 16,
0, 3, 114, 16, 16, 0,
1, 0, 0, 0, 98, 16,
0, 3, 114, 16, 16, 0,
2, 0, 0, 0, 98, 16,
0, 3, 114, 16, 16, 0,
3, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
0, 0, 0, 0, 104, 0,
0, 2, 2, 0, 0, 0,
16, 0, 0, 7, 18, 0,
16, 0, 0, 0, 0, 0,
70, 18, 16, 0, 2, 0,
0, 0, 70, 18, 16, 0,
2, 0, 0, 0, 68, 0,
0, 5, 18, 0, 16, 0,
0, 0, 0, 0, 10, 0,
16, 0, 0, 0, 0, 0,
56, 0, 0, 7, 114, 0,
16, 0, 0, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 70, 18, 16, 0,
2, 0, 0, 0, 16, 0,
0, 7, 130, 0, 16, 0,
0, 0, 0, 0, 70, 18,
16, 0, 1, 0, 0, 0,
70, 18, 16, 0, 1, 0,
0, 0, 68, 0, 0, 5,
130, 0, 16, 0, 0, 0,
0, 0, 58, 0, 16, 0,
0, 0, 0, 0, 56, 0,
0, 7, 114, 0, 16, 0,
1, 0, 0, 0, 246, 15,
16, 0, 0, 0, 0, 0,
70, 18, 16, 0, 1, 0,
0, 0, 16, 32, 0, 7,
18, 0, 16, 0, 0, 0,
0, 0, 70, 2, 16, 0,
0, 0, 0, 0, 70, 2,
16, 0, 1, 0, 0, 0,
16, 0, 0, 7, 34, 0,
16, 0, 0, 0, 0, 0,
70, 18, 16, 0, 3, 0,
0, 0, 70, 18, 16, 0,
3, 0, 0, 0, 68, 0,
0, 5, 34, 0, 16, 0,
0, 0, 0, 0, 26, 0,
16, 0, 0, 0, 0, 0,
56, 0, 0, 7, 98, 0,
16, 0, 0, 0, 0, 0,
86, 5, 16, 0, 0, 0,
0, 0, 86, 22, 16, 0,
3, 0, 0, 0, 15, 32,
0, 10, 34, 0, 16, 0,
0, 0, 0, 0, 2, 64,
0, 0, 243, 4, 53, 63,
243, 4, 53, 191, 0, 0,
0, 0, 0, 0, 0, 0,
150, 5, 16, 0, 0, 0,
0, 0, 56, 0, 0, 10,
226, 0, 16, 0, 0, 0,
0, 0, 86, 5, 16, 0,
0, 0, 0, 0, 2, 64,
0, 0, 0, 0, 0, 0,
154, 153, 25, 63, 154, 153,
25, 63, 205, 204, 204, 62,
50, 0, 0, 12, 114, 32,
16, 0, 0, 0, 0, 0,
6, 0, 16, 0, 0, 0,
0, 0, 2, 64, 0, 0,
205, 204, 204, 62, 205, 204,
204, 62, 154, 153, 25, 63,
0, 0, 0, 0, 150, 7,
16, 0, 0, 0, 0, 0,
54, 0, 0, 5, 130, 32,
16, 0, 0, 0, 0, 0,
1, 64, 0, 0, 0, 0,
128, 63, 62, 0, 0, 1,
83, 84, 65, 84, 116, 0,
0, 0, 15, 0, 0, 0,
2, 0, 0, 0, 0, 0,
0, 0, 4, 0, 0, 0,
12, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 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, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
1, 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, 0, 0, 0,
0, 0, 0, 0
};

View File

@ -0,0 +1,105 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11spikysphere.hlsl.vs.h /Evs /Tvs_4_0 d3d11spikysphere.hlsl
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyz 0 NONE float xyz
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyz 0 NONE float xyz
//
vs_4_0
dcl_input v0.xyz
dcl_output o0.xyz
mov o0.xyz, v0.xyzx
ret
// Approximately 2 instruction slots used
#endif
const BYTE g_vs[] =
{
68, 88, 66, 67, 71, 140,
219, 201, 207, 71, 236, 3,
158, 208, 157, 229, 54, 227,
221, 132, 1, 0, 0, 0,
176, 1, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
140, 0, 0, 0, 192, 0,
0, 0, 244, 0, 0, 0,
52, 1, 0, 0, 82, 68,
69, 70, 80, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 0, 4,
254, 255, 0, 1, 0, 0,
28, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
44, 0, 0, 0, 1, 0,
0, 0, 8, 0, 0, 0,
32, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 7, 7, 0, 0,
80, 79, 83, 73, 84, 73,
79, 78, 0, 171, 171, 171,
79, 83, 71, 78, 44, 0,
0, 0, 1, 0, 0, 0,
8, 0, 0, 0, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
7, 8, 0, 0, 80, 79,
83, 73, 84, 73, 79, 78,
0, 171, 171, 171, 83, 72,
68, 82, 56, 0, 0, 0,
64, 0, 1, 0, 14, 0,
0, 0, 95, 0, 0, 3,
114, 16, 16, 0, 0, 0,
0, 0, 101, 0, 0, 3,
114, 32, 16, 0, 0, 0,
0, 0, 54, 0, 0, 5,
114, 32, 16, 0, 0, 0,
0, 0, 70, 18, 16, 0,
0, 0, 0, 0, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 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, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 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, 0,
0, 0, 0, 0, 0, 0
};

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{64988608-72A3-4125-8A31-45E1EACE8F0A}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>d3d11spikysphere</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d11app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>d3d11.lib;d3dx10.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d11app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>d3d11.lib;d3dx10.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\d3d11app\d3d11winmain.cpp" />
<ClCompile Include="d3d11spikysphere.cpp" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="d3d11spikysphere.hlsl">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).ps.h /Eps /Tps_4_0 %(Identity)
"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).vs.h /Evs /Tvs_4_0 %(Identity)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Identity).ps.h;%(Identity).vs.h;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\d3d11app\d3d11app.h" />
<ClInclude Include="d3d11spikysphere.hlsl.ds.h" />
<ClInclude Include="d3d11spikysphere.hlsl.hs.h" />
<ClInclude Include="d3d11spikysphere.hlsl.ps.h" />
<ClInclude Include="d3d11spikysphere.hlsl.vs.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,116 @@
/**************************************************************************
*
* 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 "d3d11app.h"
#include "d3d11u.h"
#include "d3d11tex.hlsl.ps.h"
#include "d3d11tex.hlsl.vs.h"
#include "../data/cornell_box_image.h"
#include "../data/tux_image.h"
struct d3d11tex : public d3d11_application
{
ID3D11PixelShader* ps;
ID3D11VertexShader* vs;
mesh* quad;
ID3D11ShaderResourceView* srv[2];
ID3D11SamplerState* samp[2];
virtual bool init(ID3D11Device* dev, int argc, char** argv)
{
ensure(dev->CreatePixelShader(g_ps, sizeof(g_ps), NULL, &ps));
ensure(dev->CreateVertexShader(g_vs, sizeof(g_vs), NULL, &vs));
quad = create_tex_quad(dev, g_vs, sizeof(g_vs));
D3D11_TEXTURE2D_DESC texd;
memset(&texd, 0, sizeof(texd));
texd.BindFlags = D3D11_BIND_SHADER_RESOURCE;
texd.Usage = D3D11_USAGE_IMMUTABLE;
texd.SampleDesc.Count = 1;
texd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texd.Width = 32;
texd.Height = 32;
texd.ArraySize = 1;
texd.MipLevels = 1;
D3D11_SUBRESOURCE_DATA texsd;
texsd.SysMemPitch = 32 * 4;
texsd.SysMemSlicePitch = 32 * 32 * 4;
ID3D11Texture2D* tex;
texsd.pSysMem = g_cornell_box_image;
ensure(dev->CreateTexture2D(&texd, &texsd, &tex));
ensure(dev->CreateShaderResourceView(tex, 0, &srv[0]));
tex->Release();
texsd.pSysMem = g_tux_image;
ensure(dev->CreateTexture2D(&texd, &texsd, &tex));
ensure(dev->CreateShaderResourceView(tex, 0, &srv[1]));
tex->Release();
D3D11_SAMPLER_DESC sampd;
memset(&sampd, 0, sizeof(sampd));
sampd.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampd.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
sampd.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
sampd.MinLOD = -FLT_MAX;
sampd.MaxLOD = FLT_MAX;
sampd.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
dev->CreateSamplerState(&sampd, &samp[0]);
sampd.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
dev->CreateSamplerState(&sampd, &samp[1]);
return true;
}
virtual void draw(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* rtv, unsigned width, unsigned height, double time)
{
D3D11_VIEWPORT vp;
memset(&vp, 0, sizeof(vp));
vp.Width = (float)width;
vp.Height = (float)height;
vp.MaxDepth = 1.0f;
ctx->OMSetRenderTargets(1, &rtv, 0);
ctx->RSSetViewports(1, &vp);
ctx->VSSetShader(vs, NULL, 0);
ctx->PSSetShader(ps, NULL, 0);
ctx->PSSetShaderResources(0, 2, srv);
ctx->PSSetSamplers(0, 2, samp);
quad->bind_and_draw(ctx);
}
};
d3d11_application* d3d11_application_create()
{
return new d3d11tex();
}

View File

@ -0,0 +1,66 @@
/**************************************************************************
*
* 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.
*
**************************************************************************/
Texture2D tex0;
Texture2D tex1;
sampler samp0;
sampler samp1;
struct IA2VS
{
float4 position : POSITION;
float2 texcoord : TEXCOORD;
};
struct VS2PS
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
float4 factors : FACTORS;
};
VS2PS vs(IA2VS input)
{
VS2PS result;
result.position = input.position;
result.texcoord = input.texcoord * 8;
result.factors.xy = input.texcoord;
result.factors.zw = 1 - input.texcoord;
return result;
}
float4 ps(VS2PS input) : SV_TARGET
{
float4 a0 = tex0.Sample(samp0, input.texcoord);
float4 a1 = tex0.Sample(samp1, input.texcoord);
float4 a = a0 * input.factors.z + a1 * input.factors.x;
float4 b0 = tex1.Sample(samp0, input.texcoord);
float4 b1 = tex1.Sample(samp1, input.texcoord);
float4 b = b0 * input.factors.z + b1 * input.factors.x;
return a * input.factors.w + b * input.factors.y;
}

View File

@ -0,0 +1,234 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11tex.hlsl.ps.h /Eps /Tps_4_0 d3d11tex.hlsl
//
//
// Resource Bindings:
//
// Name Type Format Dim Slot Elements
// ------------------------------ ---------- ------- ----------- ---- --------
// samp0 sampler NA NA 0 1
// samp1 sampler NA NA 1 1
// tex0 texture float4 2d 0 1
// tex1 texture float4 2d 1 1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float
// TEXCOORD 0 xy 1 NONE float xy
// FACTORS 0 xyzw 2 NONE float xyzw
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_TARGET 0 xyzw 0 TARGET float xyzw
//
ps_4_0
dcl_sampler s0, mode_default
dcl_sampler s1, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_resource_texture2d (float,float,float,float) t1
dcl_input_ps linear v1.xy
dcl_input_ps linear v2.xyzw
dcl_output o0.xyzw
dcl_temps 3
sample r0.xyzw, v1.xyxx, t1.xyzw, s1
mul r0.xyzw, r0.xyzw, v2.xxxx
sample r1.xyzw, v1.xyxx, t1.xyzw, s0
mad r0.xyzw, r1.xyzw, v2.zzzz, r0.xyzw
mul r0.xyzw, r0.xyzw, v2.yyyy
sample r1.xyzw, v1.xyxx, t0.xyzw, s1
mul r1.xyzw, r1.xyzw, v2.xxxx
sample r2.xyzw, v1.xyxx, t0.xyzw, s0
mad r1.xyzw, r2.xyzw, v2.zzzz, r1.xyzw
mad o0.xyzw, r1.xyzw, v2.wwww, r0.xyzw
ret
// Approximately 11 instruction slots used
#endif
const BYTE g_ps[] =
{
68, 88, 66, 67, 139, 203,
114, 37, 104, 101, 201, 12,
197, 147, 116, 98, 80, 214,
173, 207, 1, 0, 0, 0,
16, 4, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
32, 1, 0, 0, 152, 1,
0, 0, 204, 1, 0, 0,
148, 3, 0, 0, 82, 68,
69, 70, 228, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 4, 0, 0, 0,
28, 0, 0, 0, 0, 4,
255, 255, 0, 1, 0, 0,
178, 0, 0, 0, 156, 0,
0, 0, 3, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0,
162, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
1, 0, 0, 0, 0, 0,
0, 0, 168, 0, 0, 0,
2, 0, 0, 0, 5, 0,
0, 0, 4, 0, 0, 0,
255, 255, 255, 255, 0, 0,
0, 0, 1, 0, 0, 0,
12, 0, 0, 0, 173, 0,
0, 0, 2, 0, 0, 0,
5, 0, 0, 0, 4, 0,
0, 0, 255, 255, 255, 255,
1, 0, 0, 0, 1, 0,
0, 0, 12, 0, 0, 0,
115, 97, 109, 112, 48, 0,
115, 97, 109, 112, 49, 0,
116, 101, 120, 48, 0, 116,
101, 120, 49, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
73, 83, 71, 78, 112, 0,
0, 0, 3, 0, 0, 0,
8, 0, 0, 0, 80, 0,
0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 92, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0,
3, 3, 0, 0, 101, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 2, 0, 0, 0,
15, 15, 0, 0, 83, 86,
95, 80, 79, 83, 73, 84,
73, 79, 78, 0, 84, 69,
88, 67, 79, 79, 82, 68,
0, 70, 65, 67, 84, 79,
82, 83, 0, 171, 171, 171,
79, 83, 71, 78, 44, 0,
0, 0, 1, 0, 0, 0,
8, 0, 0, 0, 32, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 83, 86,
95, 84, 65, 82, 71, 69,
84, 0, 171, 171, 83, 72,
68, 82, 192, 1, 0, 0,
64, 0, 0, 0, 112, 0,
0, 0, 90, 0, 0, 3,
0, 96, 16, 0, 0, 0,
0, 0, 90, 0, 0, 3,
0, 96, 16, 0, 1, 0,
0, 0, 88, 24, 0, 4,
0, 112, 16, 0, 0, 0,
0, 0, 85, 85, 0, 0,
88, 24, 0, 4, 0, 112,
16, 0, 1, 0, 0, 0,
85, 85, 0, 0, 98, 16,
0, 3, 50, 16, 16, 0,
1, 0, 0, 0, 98, 16,
0, 3, 242, 16, 16, 0,
2, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
0, 0, 0, 0, 104, 0,
0, 2, 3, 0, 0, 0,
69, 0, 0, 9, 242, 0,
16, 0, 0, 0, 0, 0,
70, 16, 16, 0, 1, 0,
0, 0, 70, 126, 16, 0,
1, 0, 0, 0, 0, 96,
16, 0, 1, 0, 0, 0,
56, 0, 0, 7, 242, 0,
16, 0, 0, 0, 0, 0,
70, 14, 16, 0, 0, 0,
0, 0, 6, 16, 16, 0,
2, 0, 0, 0, 69, 0,
0, 9, 242, 0, 16, 0,
1, 0, 0, 0, 70, 16,
16, 0, 1, 0, 0, 0,
70, 126, 16, 0, 1, 0,
0, 0, 0, 96, 16, 0,
0, 0, 0, 0, 50, 0,
0, 9, 242, 0, 16, 0,
0, 0, 0, 0, 70, 14,
16, 0, 1, 0, 0, 0,
166, 26, 16, 0, 2, 0,
0, 0, 70, 14, 16, 0,
0, 0, 0, 0, 56, 0,
0, 7, 242, 0, 16, 0,
0, 0, 0, 0, 70, 14,
16, 0, 0, 0, 0, 0,
86, 21, 16, 0, 2, 0,
0, 0, 69, 0, 0, 9,
242, 0, 16, 0, 1, 0,
0, 0, 70, 16, 16, 0,
1, 0, 0, 0, 70, 126,
16, 0, 0, 0, 0, 0,
0, 96, 16, 0, 1, 0,
0, 0, 56, 0, 0, 7,
242, 0, 16, 0, 1, 0,
0, 0, 70, 14, 16, 0,
1, 0, 0, 0, 6, 16,
16, 0, 2, 0, 0, 0,
69, 0, 0, 9, 242, 0,
16, 0, 2, 0, 0, 0,
70, 16, 16, 0, 1, 0,
0, 0, 70, 126, 16, 0,
0, 0, 0, 0, 0, 96,
16, 0, 0, 0, 0, 0,
50, 0, 0, 9, 242, 0,
16, 0, 1, 0, 0, 0,
70, 14, 16, 0, 2, 0,
0, 0, 166, 26, 16, 0,
2, 0, 0, 0, 70, 14,
16, 0, 1, 0, 0, 0,
50, 0, 0, 9, 242, 32,
16, 0, 0, 0, 0, 0,
70, 14, 16, 0, 1, 0,
0, 0, 246, 31, 16, 0,
2, 0, 0, 0, 70, 14,
16, 0, 0, 0, 0, 0,
62, 0, 0, 1, 83, 84,
65, 84, 116, 0, 0, 0,
11, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 3, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 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, 4, 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, 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
};

View File

@ -0,0 +1,153 @@
#if 0
//
// Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111
//
//
// fxc /Fhd3d11tex.hlsl.vs.h /Evs /Tvs_4_0 d3d11tex.hlsl
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// POSITION 0 xyzw 0 NONE float xyzw
// TEXCOORD 0 xy 1 NONE float xy
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------ ------
// SV_POSITION 0 xyzw 0 POS float xyzw
// TEXCOORD 0 xy 1 NONE float xy
// FACTORS 0 xyzw 2 NONE float xyzw
//
vs_4_0
dcl_input v0.xyzw
dcl_input v1.xy
dcl_output_siv o0.xyzw, position
dcl_output o1.xy
dcl_output o2.xyzw
mov o0.xyzw, v0.xyzw
mul o1.xy, v1.xyxx, l(8.000000, 8.000000, 0.000000, 0.000000)
mad o2.xyzw, v1.xyxy, l(1.000000, 1.000000, -1.000000, -1.000000), l(0.000000, 0.000000, 1.000000, 1.000000)
ret
// Approximately 4 instruction slots used
#endif
const BYTE g_vs[] =
{
68, 88, 66, 67, 129, 141,
49, 0, 46, 132, 26, 20,
64, 38, 200, 86, 119, 202,
172, 121, 1, 0, 0, 0,
160, 2, 0, 0, 5, 0,
0, 0, 52, 0, 0, 0,
140, 0, 0, 0, 224, 0,
0, 0, 88, 1, 0, 0,
36, 2, 0, 0, 82, 68,
69, 70, 80, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
28, 0, 0, 0, 0, 4,
254, 255, 0, 1, 0, 0,
28, 0, 0, 0, 77, 105,
99, 114, 111, 115, 111, 102,
116, 32, 40, 82, 41, 32,
72, 76, 83, 76, 32, 83,
104, 97, 100, 101, 114, 32,
67, 111, 109, 112, 105, 108,
101, 114, 32, 57, 46, 50,
57, 46, 57, 53, 50, 46,
51, 49, 49, 49, 0, 171,
171, 171, 73, 83, 71, 78,
76, 0, 0, 0, 2, 0,
0, 0, 8, 0, 0, 0,
56, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 15, 0, 0,
65, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 3, 3, 0, 0,
80, 79, 83, 73, 84, 73,
79, 78, 0, 84, 69, 88,
67, 79, 79, 82, 68, 0,
171, 171, 79, 83, 71, 78,
112, 0, 0, 0, 3, 0,
0, 0, 8, 0, 0, 0,
80, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0,
3, 0, 0, 0, 0, 0,
0, 0, 15, 0, 0, 0,
92, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 1, 0,
0, 0, 3, 12, 0, 0,
101, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
3, 0, 0, 0, 2, 0,
0, 0, 15, 0, 0, 0,
83, 86, 95, 80, 79, 83,
73, 84, 73, 79, 78, 0,
84, 69, 88, 67, 79, 79,
82, 68, 0, 70, 65, 67,
84, 79, 82, 83, 0, 171,
171, 171, 83, 72, 68, 82,
196, 0, 0, 0, 64, 0,
1, 0, 49, 0, 0, 0,
95, 0, 0, 3, 242, 16,
16, 0, 0, 0, 0, 0,
95, 0, 0, 3, 50, 16,
16, 0, 1, 0, 0, 0,
103, 0, 0, 4, 242, 32,
16, 0, 0, 0, 0, 0,
1, 0, 0, 0, 101, 0,
0, 3, 50, 32, 16, 0,
1, 0, 0, 0, 101, 0,
0, 3, 242, 32, 16, 0,
2, 0, 0, 0, 54, 0,
0, 5, 242, 32, 16, 0,
0, 0, 0, 0, 70, 30,
16, 0, 0, 0, 0, 0,
56, 0, 0, 10, 50, 32,
16, 0, 1, 0, 0, 0,
70, 16, 16, 0, 1, 0,
0, 0, 2, 64, 0, 0,
0, 0, 0, 65, 0, 0,
0, 65, 0, 0, 0, 0,
0, 0, 0, 0, 50, 0,
0, 15, 242, 32, 16, 0,
2, 0, 0, 0, 70, 20,
16, 0, 1, 0, 0, 0,
2, 64, 0, 0, 0, 0,
128, 63, 0, 0, 128, 63,
0, 0, 128, 191, 0, 0,
128, 191, 2, 64, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 128, 63,
0, 0, 128, 63, 62, 0,
0, 1, 83, 84, 65, 84,
116, 0, 0, 0, 4, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 5, 0,
0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 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, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 1, 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, 0,
0, 0, 0, 0, 0, 0
};

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{14F73B97-2DC6-423E-97D9-64E3368713DC}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>d3d11tex</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d11app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>d3d11.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(SolutionDir)\d3d11app</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>d3d11.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<CustomBuild Include="d3d11tex.hlsl">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).ps.h /Eps /Tps_4_0 %(Identity)
"$(DXSDK_DIR)\Utilities\bin\x86\fxc.exe" /Fh%(Identity).vs.h /Evs /Tvs_4_0 %(Identity)</Command>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(Identity).ps.h;%(Identity).vs.h;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\d3d11app\d3d11app.h" />
<ClInclude Include="d3d11tex.hlsl.ps.h" />
<ClInclude Include="d3d11tex.hlsl.vs.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\d3d11app\d3d11winmain.cpp" />
<ClCompile Include="d3d11tex.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,120 @@
/**************************************************************************
*
* 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 "d3d11app.h"
#include "d3d11tri.hlsl.ps.h"
#include "d3d11tri.hlsl.vs.h"
struct vertex {
float position[4];
float color[4];
};
static struct vertex vertices[3] =
{
{
{ 0.0f, 0.9f, 0.5f, 1.0f },
{ 1.0f, 0.0f, 0.0f, 1.0f }
},
{
{ 0.9f, -0.9f, 0.5f, 1.0f },
{ 0.0f, 0.0f, 1.0f, 1.0f }
},
{
{ -0.9f, -0.9f, 0.5f, 1.0f },
{ 0.0f, 1.0f, 0.0f, 1.0f }
},
};
struct d3d11tri : public d3d11_application
{
ID3D11PixelShader* ps;
ID3D11VertexShader* vs;
ID3D11InputLayout* layout;
ID3D11Buffer* vb;
virtual bool init(ID3D11Device* dev, int argc, char** argv)
{
ensure(dev->CreatePixelShader(g_ps, sizeof(g_ps), NULL, &ps));
ensure(dev->CreateVertexShader(g_vs, sizeof(g_vs), NULL, &vs));
D3D11_INPUT_ELEMENT_DESC elements[] =
{
// inverse order to make sure the implementation can properly parse the vertex shader signature
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
ensure(dev->CreateInputLayout(elements, sizeof(elements) / sizeof(elements[0]), g_vs, sizeof(g_vs), &layout));
D3D11_BUFFER_DESC bufferd;
bufferd.ByteWidth = sizeof(vertices);
bufferd.Usage = D3D11_USAGE_IMMUTABLE;
bufferd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufferd.CPUAccessFlags = 0;
bufferd.MiscFlags = 0;
bufferd.StructureByteStride = 0;
D3D11_SUBRESOURCE_DATA buffersd;
buffersd.pSysMem = vertices;
buffersd.SysMemPitch = sizeof(vertices);
buffersd.SysMemSlicePitch = sizeof(vertices);
ensure(dev->CreateBuffer(&bufferd, &buffersd, &vb));
return true;
}
virtual void draw(ID3D11DeviceContext* ctx, ID3D11RenderTargetView* rtv, unsigned width, unsigned height, double time)
{
float clear_color[4] = {1, 0, 1, 1};
D3D11_VIEWPORT vp;
memset(&vp, 0, sizeof(vp));
vp.Width = (float)width;
vp.Height = (float)height;
vp.MaxDepth = 1.0f;
ctx->OMSetRenderTargets(1, &rtv, 0);
ctx->RSSetViewports(1, &vp);
ctx->ClearRenderTargetView(rtv, clear_color);
ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
ctx->IASetInputLayout(layout);
unsigned stride = 2 * 4 * 4;
unsigned offset = 0;
ctx->IASetVertexBuffers(0, 1, &vb, &stride, &offset);
ctx->VSSetShader(vs, NULL, 0);
ctx->PSSetShader(ps, NULL, 0);
ctx->Draw(3, 0);
}
};
d3d11_application* d3d11_application_create()
{
return new d3d11tri();
}

View File

@ -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.
*
**************************************************************************/
struct IA2VS
{
float4 position : POSITION;
float4 color : COLOR;
};
struct VS2PS
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
VS2PS vs(IA2VS input)
{
VS2PS result;
result.position = input.position;
result.color = input.color;
return result;
}
float4 ps(VS2PS input) : SV_TARGET
{
return input.color;
}

Some files were not shown because too many files have changed in this diff Show More