]> git.cworth.org Git - apitrace/blob - d3dshader.py
Make autogenerated dump functions static.
[apitrace] / d3dshader.py
1 #############################################################################
2 #
3 # Copyright 2009 VMware, Inc.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published
7 # by the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 #############################################################################
19
20
21 from base import Type
22
23
24 class D3DShader(Type):
25
26     def __init__(self, version):
27         self.version = version
28         Type.__init__(self, "const DWORD *")
29
30     def decl(self):
31         print '#include <d3dx9.h>'
32         print '#include <stdio.h>'
33         print 
34         print 'void Dump%s(const DWORD *tokens);' % (self.id)
35     
36     def impl(self):
37         print '''
38 typedef HRESULT 
39 (WINAPI *PD3DXDISASSEMBLESHADER)(
40    CONST DWORD *pShader,
41    BOOL EnableColorCode,
42    LPCSTR pComments,
43    LPD3DXBUFFER *ppDisassembly
44 );
45         '''
46         print 'void Dump%s(const DWORD *tokens)' % (self.id)
47         print '''{
48     static BOOL firsttime = TRUE;
49     static HMODULE hD3DXModule = NULL; 
50     static PD3DXDISASSEMBLESHADER pfnD3DXDisassembleShader = NULL;
51
52     if(firsttime) {
53         if(!hD3DXModule) {
54             unsigned release;
55             unsigned version;
56             for(release = 0; release <= 1; ++release) {
57                 /* Version 41 corresponds to Mar 2009 version of DirectX Runtime / SDK */ 
58                 for(version = 41; version >= 24; --version) {
59                     char filename[256];
60                     _snprintf(filename, sizeof(filename), 
61                               "d3dx9%s_%u.dll", release ? "" : "d", version);
62                     hD3DXModule = LoadLibraryA(filename);
63                     if(hD3DXModule)
64                         goto found;
65                 }
66             }
67 found:
68             ;
69         }
70
71         if (hD3DXModule)
72             if(!pfnD3DXDisassembleShader)
73                 pfnD3DXDisassembleShader = (PD3DXDISASSEMBLESHADER)GetProcAddress(hD3DXModule, "D3DXDisassembleShader");
74
75         firsttime = FALSE;
76     }
77    
78     if(pfnD3DXDisassembleShader) {
79         LPD3DXBUFFER pDisassembly = NULL;
80    
81         if (pfnD3DXDisassembleShader( (DWORD *)tokens, FALSE, NULL, &pDisassembly) == D3D_OK)
82             Log::DumpString((char *)pDisassembly->GetBufferPointer());
83
84         if(pDisassembly)
85             pDisassembly->Release();
86     }
87 }
88 '''
89     
90     def dump(self, instance):
91         print '    Dump%s(%s);' % (self.id, instance)