]> git.cworth.org Git - apitrace/blob - d3dshader.cpp
Ignore assertion failure on Mac OS X.
[apitrace] / d3dshader.cpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
4  * Copyright 2008-2009 VMware, Inc.
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27
28 #include <stdio.h>
29
30 #include "trace_writer.hpp"
31 #include "d3d9imports.hpp"
32 #include "d3dshader.hpp"
33
34
35 typedef HRESULT
36 (WINAPI *PD3DXDISASSEMBLESHADER)(
37     CONST DWORD *pShader,
38     BOOL EnableColorCode,
39     LPCSTR pComments,
40     LPD3DXBUFFER *ppDisassembly
41 );
42
43
44 void DumpShader(const DWORD *tokens)
45 {
46     static BOOL firsttime = TRUE;
47     static HMODULE hD3DXModule = NULL;
48     static PD3DXDISASSEMBLESHADER pfnD3DXDisassembleShader = NULL;
49
50     if (firsttime) {
51         if (!hD3DXModule) {
52             unsigned release;
53             int version;
54             for (release = 0; release <= 1; ++release) {
55                 /* Version 41 corresponds to Mar 2009 version of DirectX Runtime / SDK */
56                 for (version = 41; version >= 0; --version) {
57                     char filename[256];
58                     _snprintf(filename, sizeof(filename),
59                               "d3dx9%s%s%u.dll", release ? "" : "d", version ? "_" : "", version);
60                     hD3DXModule = LoadLibraryA(filename);
61                     if (hD3DXModule)
62                         goto found;
63                 }
64             }
65 found:
66             ;
67         }
68
69         if (hD3DXModule) {
70             if (!pfnD3DXDisassembleShader) {
71                 pfnD3DXDisassembleShader = (PD3DXDISASSEMBLESHADER)GetProcAddress(hD3DXModule, "D3DXDisassembleShader");
72             }
73         }
74
75         firsttime = FALSE;
76     }
77
78     if (pfnD3DXDisassembleShader) {
79         LPD3DXBUFFER pDisassembly = NULL;
80         HRESULT hr;
81
82         hr = pfnD3DXDisassembleShader( (DWORD *)tokens, FALSE, NULL, &pDisassembly);
83         if (hr == D3D_OK) {
84             Trace::LiteralString((const char *)pDisassembly->GetBufferPointer());
85         }
86
87         if (pDisassembly) {
88             pDisassembly->Release();
89         }
90
91         if (hr == D3D_OK) {
92             return;
93         }
94     }
95
96     Trace::LiteralOpaque(tokens);
97 }