home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the 3D Game Programming Gurus / gurus.iso / DirectX / dx9sdkcp.exe / SDK (C++) / Include / d3dx9shader.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-04  |  33.8 KB  |  906 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Copyright (c) Microsoft Corporation.  All rights reserved.
  4. //
  5. //  File:       d3dx9shader.h
  6. //  Content:    D3DX Shader APIs
  7. //
  8. //////////////////////////////////////////////////////////////////////////////
  9.  
  10. #include "d3dx9.h"
  11.  
  12. #ifndef __D3DX9SHADER_H__
  13. #define __D3DX9SHADER_H__
  14.  
  15.  
  16. //---------------------------------------------------------------------------
  17. // D3DXTX_VERSION:
  18. // --------------
  19. // Version token used to create a procedural texture filler in effects
  20. // Used by D3DXFill[]TX functions
  21. //---------------------------------------------------------------------------
  22. #define D3DXTX_VERSION(_Major,_Minor) (('T' << 24) | ('X' << 16) | ((_Major) << 8) | (_Minor))
  23.  
  24.  
  25.  
  26. //----------------------------------------------------------------------------
  27. // D3DXSHADER flags:
  28. // -----------------
  29. // D3DXSHADER_DEBUG
  30. //   Insert debug file/line/type/symbol information.
  31. //
  32. // D3DXSHADER_SKIPVALIDATION
  33. //   Do not validate the generated code against known capabilities and
  34. //   constraints.  This option is only recommended when compiling shaders
  35. //   you KNOW will work.  (ie. have compiled before without this option.)
  36. //   Shaders are always validated by D3D before they are set to the device.
  37. //
  38. // D3DXSHADER_SKIPOPTIMIZATION (valid for D3DXCompileShader calls only)
  39. //   Instructs the compiler to skip optimization steps during code generation.
  40. //   Unless you are trying to isolate a problem in your code, and suspect the
  41. //   compiler, using this option is not recommended.
  42. //
  43. // D3DXSHADER_PACKMATRIX_ROWMAJOR
  44. //   Unless explicitly specified, matrices will be packed in row-major order
  45. //   on input and output from the shader.
  46. //
  47. // D3DXSHADER_PACKMATRIX_COLUMNMAJOR
  48. //   Unless explicitly specified, matrices will be packed in column-major 
  49. //   order on input and output from the shader.  This is generally more 
  50. //   efficient, since it allows vector-matrix multiplication to be performed
  51. //   using a series of dot-products.
  52. //----------------------------------------------------------------------------
  53.  
  54. #define D3DXSHADER_DEBUG                    (1 << 0)
  55. #define D3DXSHADER_SKIPVALIDATION           (1 << 2)
  56. #define D3DXSHADER_SKIPOPTIMIZATION         (1 << 3)
  57. #define D3DXSHADER_PACKMATRIX_ROWMAJOR      (1 << 4)
  58. #define D3DXSHADER_PACKMATRIX_COLUMNMAJOR   (1 << 5)
  59.  
  60.  
  61.  
  62. //----------------------------------------------------------------------------
  63. // D3DXHANDLE:
  64. // -----------
  65. // Handle values used to efficiently reference shader and effect parameters.
  66. // Strings can be used as handles.  However, handles are not always strings.
  67. //----------------------------------------------------------------------------
  68.  
  69. typedef LPCSTR D3DXHANDLE;
  70. typedef D3DXHANDLE *LPD3DXHANDLE;
  71.  
  72.  
  73. //----------------------------------------------------------------------------
  74. // D3DXMACRO:
  75. // ----------
  76. // Preprocessor macro definition.  The application pass in a NULL-terminated
  77. // array of this structure to various D3DX APIs.  This enables the application
  78. // to #define tokens at runtime, before the file is parsed.
  79. //----------------------------------------------------------------------------
  80.  
  81. typedef struct _D3DXMACRO
  82. {
  83.     LPCSTR Name;
  84.     LPCSTR Definition;
  85.  
  86. } D3DXMACRO, *LPD3DXMACRO;
  87.  
  88.  
  89. //----------------------------------------------------------------------------
  90. // D3DXSEMANTIC:
  91. //----------------------------------------------------------------------------
  92.  
  93. typedef struct _D3DXSEMANTIC
  94. {
  95.     UINT Usage;
  96.     UINT UsageIndex;
  97.  
  98. } D3DXSEMANTIC, *LPD3DXSEMANTIC;
  99.  
  100.  
  101.  
  102. //----------------------------------------------------------------------------
  103. // D3DXFRAGMENT_DESC:
  104. //----------------------------------------------------------------------------
  105.  
  106. typedef struct _D3DXFRAGMENT_DESC
  107. {
  108.     LPCSTR Name;
  109.     DWORD Target;
  110.  
  111. } D3DXFRAGMENT_DESC, *LPD3DXFRAGMENT_DESC;
  112.  
  113.  
  114. //----------------------------------------------------------------------------
  115. // D3DXREGISTER_SET:
  116. //----------------------------------------------------------------------------
  117.  
  118. typedef enum _D3DXREGISTER_SET
  119. {
  120.     D3DXRS_BOOL,
  121.     D3DXRS_INT4,
  122.     D3DXRS_FLOAT4,
  123.     D3DXRS_SAMPLER,
  124.  
  125.     // force 32-bit size enum
  126.     D3DXRS_FORCE_DWORD = 0x7fffffff
  127.  
  128. } D3DXREGISTER_SET, *LPD3DXREGISTER_SET;
  129.  
  130.  
  131. //----------------------------------------------------------------------------
  132. // D3DXPARAMETER_CLASS:
  133. //----------------------------------------------------------------------------
  134.  
  135. typedef enum _D3DXPARAMETER_CLASS
  136. {
  137.     D3DXPC_SCALAR,
  138.     D3DXPC_VECTOR,
  139.     D3DXPC_MATRIX_ROWS,
  140.     D3DXPC_MATRIX_COLUMNS,
  141.     D3DXPC_OBJECT,
  142.     D3DXPC_STRUCT,
  143.  
  144.     // force 32-bit size enum
  145.     D3DXPC_FORCE_DWORD = 0x7fffffff
  146.  
  147. } D3DXPARAMETER_CLASS, *LPD3DXPARAMETER_CLASS;
  148.  
  149.  
  150. //----------------------------------------------------------------------------
  151. // D3DXPARAMETER_TYPE:
  152. //----------------------------------------------------------------------------
  153.  
  154. typedef enum _D3DXPARAMETER_TYPE
  155. {
  156.     D3DXPT_VOID,
  157.     D3DXPT_BOOL,
  158.     D3DXPT_INT,
  159.     D3DXPT_FLOAT,
  160.     D3DXPT_STRING,
  161.     D3DXPT_TEXTURE,
  162.     D3DXPT_TEXTURE1D,
  163.     D3DXPT_TEXTURE2D,
  164.     D3DXPT_TEXTURE3D,
  165.     D3DXPT_TEXTURECUBE,
  166.     D3DXPT_SAMPLER,
  167.     D3DXPT_SAMPLER1D,
  168.     D3DXPT_SAMPLER2D,
  169.     D3DXPT_SAMPLER3D,
  170.     D3DXPT_SAMPLERCUBE,
  171.     D3DXPT_PIXELSHADER,
  172.     D3DXPT_VERTEXSHADER,
  173.     D3DXPT_PIXELFRAGMENT,
  174.     D3DXPT_VERTEXFRAGMENT,
  175.  
  176.     // force 32-bit size enum
  177.     D3DXPT_FORCE_DWORD = 0x7fffffff
  178.  
  179. } D3DXPARAMETER_TYPE, *LPD3DXPARAMETER_TYPE;
  180.  
  181.  
  182. //----------------------------------------------------------------------------
  183. // D3DXCONSTANTTABLE_DESC:
  184. //----------------------------------------------------------------------------
  185.  
  186. typedef struct _D3DXCONSTANTTABLE_DESC
  187. {
  188.     LPCSTR Creator;                     // Creator string
  189.     DWORD Version;                      // Shader version
  190.     UINT Constants;                     // Number of constants
  191.  
  192. } D3DXCONSTANTTABLE_DESC, *LPD3DXCONSTANTTABLE_DESC;
  193.  
  194.  
  195. //----------------------------------------------------------------------------
  196. // D3DXCONSTANT_DESC:
  197. //----------------------------------------------------------------------------
  198.  
  199. typedef struct _D3DXCONSTANT_DESC
  200. {
  201.     LPCSTR Name;                        // Constant name
  202.  
  203.     D3DXREGISTER_SET RegisterSet;       // Register set
  204.     UINT RegisterIndex;                 // Register index
  205.     UINT RegisterCount;                 // Number of registers occupied
  206.  
  207.     D3DXPARAMETER_CLASS Class;          // Class
  208.     D3DXPARAMETER_TYPE Type;            // Component type
  209.  
  210.     UINT Rows;                          // Number of rows
  211.     UINT Columns;                       // Number of columns
  212.     UINT Elements;                      // Number of array elements
  213.     UINT StructMembers;                 // Number of structure member sub-parameters
  214.  
  215.     UINT Bytes;                         // Data size, in bytes
  216.     LPCVOID DefaultValue;               // Pointer to default value
  217.  
  218. } D3DXCONSTANT_DESC, *LPD3DXCONSTANT_DESC;
  219.  
  220.  
  221.  
  222. //----------------------------------------------------------------------------
  223. // ID3DXConstantTable:
  224. //----------------------------------------------------------------------------
  225.  
  226. typedef interface ID3DXConstantTable ID3DXConstantTable;
  227. typedef interface ID3DXConstantTable *LPD3DXCONSTANTTABLE;
  228.  
  229. // {9DCA3190-38B9-4fc3-92E3-39C6DDFB358B}
  230. DEFINE_GUID( IID_ID3DXConstantTable,
  231. 0x9dca3190, 0x38b9, 0x4fc3, 0x92, 0xe3, 0x39, 0xc6, 0xdd, 0xfb, 0x35, 0x8b);
  232.  
  233.  
  234. #undef INTERFACE
  235. #define INTERFACE ID3DXConstantTable
  236.  
  237. DECLARE_INTERFACE_(ID3DXConstantTable, ID3DXBuffer)
  238. {
  239.     // IUnknown
  240.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  241.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  242.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  243.  
  244.     // ID3DXBuffer
  245.     STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE;
  246.     STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE;
  247.  
  248.     // Descs
  249.     STDMETHOD(GetDesc)(THIS_ D3DXCONSTANTTABLE_DESC *pDesc) PURE;
  250.     STDMETHOD(GetConstantDesc)(THIS_ D3DXHANDLE hConstant, D3DXCONSTANT_DESC *pConstantDesc, UINT *pCount) PURE;
  251.  
  252.     // Handle operations
  253.     STDMETHOD_(D3DXHANDLE, GetConstant)(THIS_ D3DXHANDLE hConstant, UINT Index) PURE;
  254.     STDMETHOD_(D3DXHANDLE, GetConstantByName)(THIS_ D3DXHANDLE hConstant, LPCSTR pName) PURE;
  255.     STDMETHOD_(D3DXHANDLE, GetConstantElement)(THIS_ D3DXHANDLE hConstant, UINT Index) PURE;
  256.  
  257.     // Set Constants
  258.     STDMETHOD(SetDefaults)(THIS_ LPDIRECT3DDEVICE9 pDevice) PURE;
  259.     STDMETHOD(SetValue)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, LPCVOID pData, UINT Bytes) PURE;
  260.     STDMETHOD(SetBool)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, BOOL b) PURE;
  261.     STDMETHOD(SetBoolArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST BOOL* pb, UINT Count) PURE;
  262.     STDMETHOD(SetInt)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, INT n) PURE;
  263.     STDMETHOD(SetIntArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST INT* pn, UINT Count) PURE;
  264.     STDMETHOD(SetFloat)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, FLOAT f) PURE;
  265.     STDMETHOD(SetFloatArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST FLOAT* pf, UINT Count) PURE;
  266.     STDMETHOD(SetVector)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXVECTOR4* pVector) PURE;
  267.     STDMETHOD(SetVectorArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXVECTOR4* pVector, UINT Count) PURE;
  268.     STDMETHOD(SetMatrix)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXMATRIX* pMatrix) PURE;
  269.     STDMETHOD(SetMatrixArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXMATRIX* pMatrix, UINT Count) PURE;
  270.     STDMETHOD(SetMatrixPointerArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXMATRIX** ppMatrix, UINT Count) PURE;
  271.     STDMETHOD(SetMatrixTranspose)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXMATRIX* pMatrix) PURE;
  272.     STDMETHOD(SetMatrixTransposeArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXMATRIX* pMatrix, UINT Count) PURE;
  273.     STDMETHOD(SetMatrixTransposePointerArray)(THIS_ LPDIRECT3DDEVICE9 pDevice, D3DXHANDLE hConstant, CONST D3DXMATRIX** ppMatrix, UINT Count) PURE;
  274. };
  275.  
  276.  
  277. //----------------------------------------------------------------------------
  278. // ID3DXFragmentLinker
  279. //----------------------------------------------------------------------------
  280.  
  281. #undef INTERFACE
  282. #define INTERFACE ID3DXFragmentLinker
  283.  
  284. // {D59D3777-C973-4a3c-B4B0-2A62CD3D8B40}
  285. DEFINE_GUID(IID_ID3DXFragmentLinker,
  286. 0xd59d3777, 0xc973, 0x4a3c, 0xb4, 0xb0, 0x2a, 0x62, 0xcd, 0x3d, 0x8b, 0x40);
  287.  
  288.  
  289. DECLARE_INTERFACE_(ID3DXFragmentLinker, IUnknown)
  290. {
  291.     // IUnknown
  292.     STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
  293.     STDMETHOD_(ULONG, AddRef)(THIS) PURE;
  294.     STDMETHOD_(ULONG, Release)(THIS) PURE;
  295.  
  296.     // ID3DXFragmentLinker
  297.  
  298.     // fragment access and information retrieval functions
  299.     STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
  300.     STDMETHOD_(UINT, GetNumberOfFragments)(THIS) PURE;
  301.  
  302.     STDMETHOD_(D3DXHANDLE, GetFragmentHandleByIndex)(THIS_ UINT Index) PURE;
  303.     STDMETHOD_(D3DXHANDLE, GetFragmentHandleByName)(THIS_ LPCSTR Name) PURE;
  304.     STDMETHOD(GetFragmentDesc)(THIS_ D3DXHANDLE Name, LPD3DXFRAGMENT_DESC FragDesc) PURE;
  305.  
  306.     // add the fragments in the buffer to the linker
  307.     STDMETHOD(AddFragments)(THIS_ CONST DWORD *Fragments) PURE;
  308.  
  309.     // Create a buffer containing the fragments.  Suitable for saving to disk
  310.     STDMETHOD(GetAllFragments)(THIS_ LPD3DXBUFFER *ppBuffer) PURE;
  311.     STDMETHOD(GetFragment)(THIS_ D3DXHANDLE Name, LPD3DXBUFFER *ppBuffer) PURE;
  312.  
  313.     STDMETHOD(LinkShader)(THIS_ LPCSTR pTarget, DWORD Flags, LPD3DXHANDLE rgFragmentHandles, UINT cFragments, LPD3DXBUFFER *ppBuffer, LPD3DXBUFFER *ppErrorMsgs) PURE;
  314.     STDMETHOD(LinkVertexShader)(THIS_ LPCSTR pTarget, DWORD Flags, LPD3DXHANDLE rgFragmentHandles, UINT cFragments, LPDIRECT3DVERTEXSHADER9 *pVShader, LPD3DXBUFFER *ppErrorMsgs) PURE;
  315.  
  316.     STDMETHOD(ClearCache)(THIS) PURE;
  317. };
  318.  
  319.  
  320. //----------------------------------------------------------------------------
  321. // D3DXINCLUDE_TYPE:
  322. //----------------------------------------------------------------------------
  323.  
  324. typedef enum _D3DXINCLUDE_TYPE
  325. {
  326.     D3DXINC_LOCAL,
  327.     D3DXINC_SYSTEM,
  328.  
  329.     // force 32-bit size enum
  330.     D3DXINC_FORCE_DWORD = 0x7fffffff
  331.  
  332. } D3DXINCLUDE_TYPE, *LPD3DXINCLUDE_TYPE;
  333.  
  334.  
  335. //----------------------------------------------------------------------------
  336. // ID3DXInclude:
  337. // -------------
  338. // This interface is intended to be implemented by the application, and can
  339. // be used by various D3DX APIs.  This enables application-specific handling
  340. // of #include directives in source files.
  341. //
  342. // Open()
  343. //    Opens an include file.  If successful, it should fill in ppData and
  344. //    pBytes.  The data pointer returned must remain valid until Close is
  345. //    subsequently called.
  346. // Close()
  347. //    Closes an include file.  If Open was successful, Close is guaranteed
  348. //    to be called before the API using this interface returns.
  349. //----------------------------------------------------------------------------
  350.  
  351. typedef interface ID3DXInclude ID3DXInclude;
  352. typedef interface ID3DXInclude *LPD3DXINCLUDE;
  353.  
  354. #undef INTERFACE
  355. #define INTERFACE ID3DXInclude
  356.  
  357. DECLARE_INTERFACE(ID3DXInclude)
  358. {
  359.     STDMETHOD(Open)(D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes) PURE;
  360.     STDMETHOD(Close)(LPCVOID pData) PURE;
  361. };
  362.  
  363.  
  364. //////////////////////////////////////////////////////////////////////////////
  365. // APIs //////////////////////////////////////////////////////////////////////
  366. //////////////////////////////////////////////////////////////////////////////
  367.  
  368. #ifdef __cplusplus
  369. extern "C" {
  370. #endif //__cplusplus
  371.  
  372.  
  373. //----------------------------------------------------------------------------
  374. // D3DXAssembleShader:
  375. // -------------------
  376. // Assembles a shader.
  377. //
  378. // Parameters:
  379. //  pSrcFile
  380. //      Source file name
  381. //  hSrcModule
  382. //      Module handle. if NULL, current module will be used
  383. //  pSrcResource
  384. //      Resource name in module
  385. //  pSrcData
  386. //      Pointer to source code
  387. //  SrcDataLen
  388. //      Size of source code, in bytes
  389. //  pDefines
  390. //      Optional NULL-terminated array of preprocessor macro definitions.
  391. //  pInclude
  392. //      Optional interface pointer to use for handling #include directives.
  393. //      If this parameter is NULL, #includes will be honored when assembling
  394. //      from file, and will error when assembling from resource or memory.
  395. //  Flags
  396. //      See D3DXSHADER_xxx flags
  397. //  ppShader
  398. //      Returns a buffer containing the created shader.  This buffer contains
  399. //      the assembled shader code, as well as any embedded debug info.
  400. //      (See D3DXGetShaderDebugInfo)
  401. //  ppErrorMsgs
  402. //      Returns a buffer containing a listing of errors and warnings that were
  403. //      encountered during assembly.  If you are running in a debugger,
  404. //      these are the same messages you will see in your debug output.
  405. //----------------------------------------------------------------------------
  406.  
  407.  
  408. HRESULT WINAPI
  409.     D3DXAssembleShaderFromFileA(
  410.         LPCSTR                          pSrcFile,
  411.         CONST D3DXMACRO*                pDefines,
  412.         LPD3DXINCLUDE                   pInclude,
  413.         DWORD                           Flags,
  414.         LPD3DXBUFFER*                   ppShader,
  415.         LPD3DXBUFFER*                   ppErrorMsgs);
  416.  
  417. HRESULT WINAPI
  418.     D3DXAssembleShaderFromFileW(
  419.         LPCWSTR                         pSrcFile,
  420.         CONST D3DXMACRO*                pDefines,
  421.         LPD3DXINCLUDE                   pInclude,
  422.         DWORD                           Flags,
  423.         LPD3DXBUFFER*                   ppShader,
  424.         LPD3DXBUFFER*                   ppErrorMsgs);
  425.  
  426. #ifdef UNICODE
  427. #define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileW
  428. #else
  429. #define D3DXAssembleShaderFromFile D3DXAssembleShaderFromFileA
  430. #endif
  431.  
  432.  
  433. HRESULT WINAPI
  434.     D3DXAssembleShaderFromResourceA(
  435.         HMODULE                         hSrcModule,
  436.         LPCSTR                          pSrcResource,
  437.         CONST D3DXMACRO*                pDefines,
  438.         LPD3DXINCLUDE                   pInclude,
  439.         DWORD                           Flags,
  440.         LPD3DXBUFFER*                   ppShader,
  441.         LPD3DXBUFFER*                   ppErrorMsgs);
  442.  
  443. HRESULT WINAPI
  444.     D3DXAssembleShaderFromResourceW(
  445.         HMODULE                         hSrcModule,
  446.         LPCWSTR                         pSrcResource,
  447.         CONST D3DXMACRO*                pDefines,
  448.         LPD3DXINCLUDE                   pInclude,
  449.         DWORD                           Flags,
  450.         LPD3DXBUFFER*                   ppShader,
  451.         LPD3DXBUFFER*                   ppErrorMsgs);
  452.  
  453. #ifdef UNICODE
  454. #define D3DXAssembleShaderFromResource D3DXAssembleShaderFromResourceW
  455. #else
  456. #define D3DXAssembleShaderFromResource D3DXAssembleShaderFromResourceA
  457. #endif
  458.  
  459.  
  460. HRESULT WINAPI
  461.     D3DXAssembleShader(
  462.         LPCSTR                          pSrcData,
  463.         UINT                            SrcDataLen,
  464.         CONST D3DXMACRO*                pDefines,
  465.         LPD3DXINCLUDE                   pInclude,
  466.         DWORD                           Flags,
  467.         LPD3DXBUFFER*                   ppShader,
  468.         LPD3DXBUFFER*                   ppErrorMsgs);
  469.  
  470.  
  471.  
  472. //----------------------------------------------------------------------------
  473. // D3DXCompileShader:
  474. // ------------------
  475. // Compiles a shader.
  476. //
  477. // Parameters:
  478. //  pSrcFile
  479. //      Source file name.
  480. //  hSrcModule
  481. //      Module handle. if NULL, current module will be used.
  482. //  pSrcResource
  483. //      Resource name in module.
  484. //  pSrcData
  485. //      Pointer to source code.
  486. //  SrcDataLen
  487. //      Size of source code, in bytes.
  488. //  pDefines
  489. //      Optional NULL-terminated array of preprocessor macro definitions.
  490. //  pInclude
  491. //      Optional interface pointer to use for handling #include directives.
  492. //      If this parameter is NULL, #includes will be honored when compiling
  493. //      from file, and will error when compiling from resource or memory.
  494. //  pFunctionName
  495. //      Name of the entrypoint function where execution should begin.
  496. //  pTarget
  497. //      Instruction set to be used when generating code.  Currently supported
  498. //      targets are "vs_1_1", "vs_2_0", "vs_2_sw", "ps_1_1", "ps_1_2", "ps_1_3", 
  499. //      "ps_1_4", "ps_2_0", "ps_2_sw", "tx_1_0"
  500. //  Flags
  501. //      See D3DXSHADER_xxx flags.
  502. //  ppShader
  503. //      Returns a buffer containing the created shader.  This buffer contains
  504. //      the compiled shader code, as well as any embedded debug and symbol
  505. //      table info.  (See D3DXGetShaderDebugInfo, D3DXGetShaderConstantTable)
  506. //  ppErrorMsgs
  507. //      Returns a buffer containing a listing of errors and warnings that were
  508. //      encountered during the compile.  If you are running in a debugger,
  509. //      these are the same messages you will see in your debug output.
  510. //  ppConstantTable
  511. //      Returns a ID3DXConstantTable object which can be used to set
  512. //      shader constants to the device.  Alternatively, an application can
  513. //      parse the D3DXSHADER_CONSTANTTABLE block embedded as a comment within
  514. //      the shader.
  515. //----------------------------------------------------------------------------
  516.  
  517. HRESULT WINAPI
  518.     D3DXCompileShaderFromFileA(
  519.         LPCSTR                          pSrcFile,
  520.         CONST D3DXMACRO*                pDefines,
  521.         LPD3DXINCLUDE                   pInclude,
  522.         LPCSTR                          pFunctionName,
  523.         LPCSTR                          pTarget,
  524.         DWORD                           Flags,
  525.         LPD3DXBUFFER*                   ppShader,
  526.         LPD3DXBUFFER*                   ppErrorMsgs,
  527.         LPD3DXCONSTANTTABLE*            ppConstantTable);
  528.  
  529. HRESULT WINAPI
  530.     D3DXCompileShaderFromFileW(
  531.         LPCWSTR                         pSrcFile,
  532.         CONST D3DXMACRO*                pDefines,
  533.         LPD3DXINCLUDE                   pInclude,
  534.         LPCSTR                          pFunctionName,
  535.         LPCSTR                          pTarget,
  536.         DWORD                           Flags,
  537.         LPD3DXBUFFER*                   ppShader,
  538.         LPD3DXBUFFER*                   ppErrorMsgs,
  539.         LPD3DXCONSTANTTABLE*            ppConstantTable);
  540.  
  541. #ifdef UNICODE
  542. #define D3DXCompileShaderFromFile D3DXCompileShaderFromFileW
  543. #else
  544. #define D3DXCompileShaderFromFile D3DXCompileShaderFromFileA
  545. #endif
  546.  
  547.  
  548. HRESULT WINAPI
  549.     D3DXCompileShaderFromResourceA(
  550.         HMODULE                         hSrcModule,
  551.         LPCSTR                          pSrcResource,
  552.         CONST D3DXMACRO*                pDefines,
  553.         LPD3DXINCLUDE                   pInclude,
  554.         LPCSTR                          pFunctionName,
  555.         LPCSTR                          pTarget,
  556.         DWORD                           Flags,
  557.         LPD3DXBUFFER*                   ppShader,
  558.         LPD3DXBUFFER*                   ppErrorMsgs,
  559.         LPD3DXCONSTANTTABLE*            ppConstantTable);
  560.  
  561. HRESULT WINAPI
  562.     D3DXCompileShaderFromResourceW(
  563.         HMODULE                         hSrcModule,
  564.         LPCWSTR                         pSrcResource,
  565.         CONST D3DXMACRO*                pDefines,
  566.         LPD3DXINCLUDE                   pInclude,
  567.         LPCSTR                          pFunctionName,
  568.         LPCSTR                          pTarget,
  569.         DWORD                           Flags,
  570.         LPD3DXBUFFER*                   ppShader,
  571.         LPD3DXBUFFER*                   ppErrorMsgs,
  572.         LPD3DXCONSTANTTABLE*            ppConstantTable);
  573.  
  574. #ifdef UNICODE
  575. #define D3DXCompileShaderFromResource D3DXCompileShaderFromResourceW
  576. #else
  577. #define D3DXCompileShaderFromResource D3DXCompileShaderFromResourceA
  578. #endif
  579.  
  580.  
  581. HRESULT WINAPI
  582.     D3DXCompileShader(
  583.         LPCSTR                          pSrcData,
  584.         UINT                            SrcDataLen,
  585.         CONST D3DXMACRO*                pDefines,
  586.         LPD3DXINCLUDE                   pInclude,
  587.         LPCSTR                          pFunctionName,
  588.         LPCSTR                          pTarget,
  589.         DWORD                           Flags,
  590.         LPD3DXBUFFER*                   ppShader,
  591.         LPD3DXBUFFER*                   ppErrorMsgs,
  592.         LPD3DXCONSTANTTABLE*            ppConstantTable);
  593.  
  594. //----------------------------------------------------------------------------
  595. // D3DXFindShaderComment:
  596. // ----------------------
  597. // Searches through a shader for a particular comment, denoted by a FourCC in
  598. // the first DWORD of the comment.  If the comment is not found, and no other
  599. // error has occurred, S_FALSE is returned.
  600. //
  601. // Parameters:
  602. //  pFunction
  603. //      Pointer to the function DWORD stream
  604. //  FourCC
  605. //      FourCC used to identify the desired comment block.
  606. //  ppData
  607. //      Returns a pointer to the comment data (not including comment token
  608. //      and FourCC).  Can be NULL.
  609. //  pSizeInBytes
  610. //      Returns the size of the comment data in bytes.  Can be NULL.
  611. //----------------------------------------------------------------------------
  612.  
  613. HRESULT WINAPI
  614.     D3DXFindShaderComment(
  615.         CONST DWORD*                    pFunction,
  616.         DWORD                           FourCC,
  617.         LPCVOID*                        ppData,
  618.         UINT*                           pSizeInBytes);
  619.  
  620.  
  621. //----------------------------------------------------------------------------
  622. // D3DXGetShaderSemantics:
  623. // -----------------------
  624. // Gets semantics for all input elements referenced inside a given shader.
  625. //
  626. // Parameters:
  627. //  pFunction
  628. //      Pointer to the function DWORD stream
  629. //  pSemantics
  630. //      Pointer to an array of D3DXSEMANTIC structures.  The function will
  631. //      fill this array with the semantics for each input element referenced
  632. //      inside the shader.  This array is assumed to contain at least
  633. //      MAXD3DDECLLENGTH elements.
  634. //  pCount
  635. //      Returns the number of elements referenced by the shader
  636. //----------------------------------------------------------------------------
  637.  
  638. HRESULT WINAPI
  639.     D3DXGetShaderInputSemantics(
  640.         CONST DWORD*                    pFunction,
  641.         D3DXSEMANTIC*                   pSemantics,
  642.         UINT*                           pCount);
  643.  
  644. HRESULT WINAPI
  645.     D3DXGetShaderOutputSemantics(
  646.         CONST DWORD*                    pFunction,
  647.         D3DXSEMANTIC*                   pSemantics,
  648.         UINT*                           pCount);
  649.  
  650.  
  651. //----------------------------------------------------------------------------
  652. // D3DXGetShaderSamplers:
  653. // ----------------------
  654. // Gets semantics for all input elements referenced inside a given shader.
  655. //
  656. // pFunction
  657. //      Pointer to the function DWORD stream
  658. // pSamplers
  659. //      Pointer to an array of LPCSTRs.  The function will fill this array
  660. //      with pointers to the sampler names contained within pFunction, for
  661. //      each sampler referenced inside the shader.  This array is assumed to
  662. //      contain at least 16 elements.
  663. // pCount
  664. //      Returns the number of samplers referenced by the shader
  665. //----------------------------------------------------------------------------
  666.  
  667. HRESULT WINAPI
  668.     D3DXGetShaderSamplers(
  669.         CONST DWORD*                    pFunction,
  670.         LPCSTR*                         pSamplers,
  671.         UINT*                           pCount);
  672.  
  673.  
  674. //----------------------------------------------------------------------------
  675. // D3DXGetShaderConstantTable:
  676. // ---------------------------
  677. // Gets shader constant table embedded inside shader.  A constant table is
  678. // generated by D3DXAssembleShader and D3DXCompileShader, and is embedded in
  679. // the body of the shader.
  680. //
  681. // Parameters:
  682. //  pFunction
  683. //      Pointer to the function DWORD stream
  684. //  ppConstantTable
  685. //      Returns a ID3DXConstantTable object which can be used to set
  686. //      shader constants to the device.  Alternatively, an application can
  687. //      parse the D3DXSHADER_CONSTANTTABLE block embedded as a comment within
  688. //      the shader.
  689. //----------------------------------------------------------------------------
  690.  
  691. HRESULT WINAPI
  692.     D3DXGetShaderConstantTable(
  693.         CONST DWORD*                    pFunction,
  694.         LPD3DXCONSTANTTABLE*            ppConstantTable);
  695.  
  696.  
  697. //----------------------------------------------------------------------------
  698. // D3DXGetShaderDebugInfo:
  699. // -----------------------
  700. // Gets shader debug info.  Debug info is generated D3DXAssembleShader and
  701. // D3DXCompileShader and is embedded the body of the shader.
  702. //
  703. // Parameters:
  704. //  pFunction
  705. //      Pointer to the function DWORD stream
  706. //  ppDebugInfo
  707. //      Buffer used to return debug info.  For information about the layout
  708. //      of this buffer, see definition of D3DXSHADER_DEBUGINFO above.
  709. //----------------------------------------------------------------------------
  710.  
  711. HRESULT WINAPI
  712.     D3DXGetShaderDebugInfo(
  713.         CONST DWORD*                    pFunction,
  714.         LPD3DXBUFFER*                   ppDebugInfo);
  715.  
  716.  
  717.  
  718. //----------------------------------------------------------------------------
  719. // D3DXGatherFragments:
  720. // -------------------
  721. // Assembles shader fragments into a buffer to be passed to a fragment linker.
  722. //   will generate shader fragments for all fragments in the file
  723. //
  724. // Parameters:
  725. //  pSrcFile
  726. //      Source file name
  727. //  hSrcModule
  728. //      Module handle. if NULL, current module will be used
  729. //  pSrcResource
  730. //      Resource name in module
  731. //  pSrcData
  732. //      Pointer to source code
  733. //  SrcDataLen
  734. //      Size of source code, in bytes
  735. //  pDefines
  736. //      Optional NULL-terminated array of preprocessor macro definitions.
  737. //  pInclude
  738. //      Optional interface pointer to use for handling #include directives.
  739. //      If this parameter is NULL, #includes will be honored when assembling
  740. //      from file, and will error when assembling from resource or memory.
  741. //  Flags
  742. //      See D3DXSHADER_xxx flags
  743. //  ppShader
  744. //      Returns a buffer containing the created shader fragments.  This buffer contains
  745. //      the assembled shader code, as well as any embedded debug info.
  746. //  ppErrorMsgs
  747. //      Returns a buffer containing a listing of errors and warnings that were
  748. //      encountered during assembly.  If you are running in a debugger,
  749. //      these are the same messages you will see in your debug output.
  750. //----------------------------------------------------------------------------
  751.  
  752.  
  753. HRESULT WINAPI
  754. D3DXGatherFragmentsFromFileA(
  755.         LPCSTR                          pSrcFile,
  756.         CONST D3DXMACRO*                pDefines,
  757.         LPD3DXINCLUDE                   pInclude,
  758.         DWORD                           Flags,
  759.         LPD3DXBUFFER*                   ppShader,
  760.         LPD3DXBUFFER*                   ppErrorMsgs);
  761.  
  762. HRESULT WINAPI
  763. D3DXGatherFragmentsFromFileW(
  764.         LPCWSTR                         pSrcFile,
  765.         CONST D3DXMACRO*                pDefines,
  766.         LPD3DXINCLUDE                   pInclude,
  767.         DWORD                           Flags,
  768.         LPD3DXBUFFER*                   ppShader,
  769.         LPD3DXBUFFER*                   ppErrorMsgs);
  770.  
  771. #ifdef UNICODE
  772. #define D3DXGatherFragmentsFromFile D3DXGatherFragmentsFromFileW
  773. #else
  774. #define D3DXGatherFragmentsFromFile D3DXGatherFragmentsFromFileA
  775. #endif
  776.  
  777. HRESULT WINAPI
  778.     D3DXGatherFragmentsFromResourceA(
  779.         HMODULE                         hSrcModule,
  780.         LPCSTR                          pSrcResource,
  781.         CONST D3DXMACRO*                pDefines,
  782.         LPD3DXINCLUDE                   pInclude,
  783.         DWORD                           Flags,
  784.         LPD3DXBUFFER*                   ppShader,
  785.         LPD3DXBUFFER*                   ppErrorMsgs);
  786.  
  787. HRESULT WINAPI
  788.     D3DXGatherFragmentsFromResourceW(
  789.         HMODULE                         hSrcModule,
  790.         LPCWSTR                         pSrcResource,
  791.         CONST D3DXMACRO*                pDefines,
  792.         LPD3DXINCLUDE                   pInclude,
  793.         DWORD                           Flags,
  794.         LPD3DXBUFFER*                   ppShader,
  795.         LPD3DXBUFFER*                   ppErrorMsgs);
  796.  
  797. #ifdef UNICODE
  798. #define D3DXGatherFragmentsFromResource D3DXGatherFragmentsFromResourceW
  799. #else
  800. #define D3DXGatherFragmentsFromResource D3DXGatherFragmentsFromResourceA
  801. #endif
  802.  
  803.  
  804. HRESULT WINAPI
  805.     D3DXGatherFragments(
  806.         LPCSTR                          pSrcData,
  807.         UINT                            SrcDataLen,
  808.         CONST D3DXMACRO*                pDefines,
  809.         LPD3DXINCLUDE                   pInclude,
  810.         DWORD                           Flags,
  811.         LPD3DXBUFFER*                   ppShader,
  812.         LPD3DXBUFFER*                   ppErrorMsgs);
  813.  
  814. typedef ID3DXFragmentLinker *LPD3DXFRAGMENTLINKER;
  815.  
  816.  
  817. //----------------------------------------------------------------------------
  818. // D3DXCreateFragmentLinker:
  819. // -------------------------
  820. // Creates a fragment linker with a given cache size.  The interface returned 
  821. // can be used to link together shader fragments.  (both HLSL & ASM fragements)
  822. //
  823. // Parameters:
  824. //  pDevice
  825. //      Pointer of the device on which to create the effect
  826. //  ShaderCacheSize
  827. //      Size of the shader cache
  828. //  ppFragmentLinker
  829. //      pointer to a memory location to put the created interface pointer
  830. //
  831. //----------------------------------------------------------------------------
  832.  
  833. HRESULT WINAPI
  834.     D3DXCreateFragmentLinker(
  835.         LPDIRECT3DDEVICE9               pDevice,
  836.         UINT                            ShaderCacheSize,
  837.         LPD3DXFRAGMENTLINKER*           ppFragmentLinker);
  838.  
  839.  
  840.  
  841. #ifdef __cplusplus
  842. }
  843. #endif //__cplusplus
  844.  
  845.  
  846. //////////////////////////////////////////////////////////////////////////////
  847. // Shader comment block layouts //////////////////////////////////////////////
  848. //////////////////////////////////////////////////////////////////////////////
  849.  
  850. //----------------------------------------------------------------------------
  851. // D3DXSHADER_CONSTANTTABLE:
  852. // -------------------------
  853. // Shader constant information; included as an CTAB comment block inside
  854. // shaders.  All offsets are BYTE offsets from start of CONSTANTTABLE struct.
  855. // Entries in the table are sorted by Name in ascending order.
  856. //----------------------------------------------------------------------------
  857.  
  858. typedef struct _D3DXSHADER_CONSTANTTABLE
  859. {
  860.     DWORD Size;             // sizeof(D3DXSHADER_CONSTANTTABLE)
  861.     DWORD Creator;          // LPCSTR offset
  862.     DWORD Version;          // shader version
  863.     DWORD Constants;        // number of constants
  864.     DWORD ConstantInfo;     // D3DXSHADER_CONSTANTINFO[Constants] offset
  865.  
  866. } D3DXSHADER_CONSTANTTABLE, *LPD3DXSHADER_CONSTANTTABLE;
  867.  
  868.  
  869. typedef struct _D3DXSHADER_CONSTANTINFO
  870. {
  871.     DWORD Name;             // LPCSTR offset
  872.     WORD  RegisterSet;      // D3DXREGISTER_SET
  873.     WORD  RegisterIndex;    // register number
  874.     WORD  RegisterCount;    // number of registers
  875.     WORD  Reserved;         // reserved
  876.     DWORD TypeInfo;         // D3DXSHADER_TYPEINFO offset
  877.     DWORD DefaultValue;     // offset of default value
  878.  
  879. } D3DXSHADER_CONSTANTINFO, *LPD3DXSHADER_CONSTANTINFO;
  880.  
  881.  
  882. typedef struct _D3DXSHADER_TYPEINFO
  883. {
  884.     WORD  Class;            // D3DXPARAMETER_CLASS
  885.     WORD  Type;             // D3DXPARAMETER_TYPE
  886.     WORD  Rows;             // number of rows (matrices)
  887.     WORD  Columns;          // number of columns (vectors and matrices)
  888.     WORD  Elements;         // array dimension
  889.     WORD  StructMembers;    // number of struct members
  890.     DWORD StructMemberInfo; // D3DXSHADER_STRUCTMEMBERINFO[Members] offset
  891.  
  892. } D3DXSHADER_TYPEINFO, *LPD3DXSHADER_TYPEINFO;
  893.  
  894.  
  895. typedef struct _D3DXSHADER_STRUCTMEMBERINFO
  896. {
  897.     DWORD Name;             // LPCSTR offset
  898.     DWORD TypeInfo;         // D3DXSHADER_TYPEINFO offset
  899.  
  900. } D3DXSHADER_STRUCTMEMBERINFO, *LPD3DXSHADER_STRUCTMEMBERINFO;
  901.  
  902.  
  903.  
  904. #endif //__D3DX9SHADER_H__
  905.  
  906.