]> git.cworth.org Git - apitrace/blob - retrace/d3d9state.cpp
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / retrace / d3d9state.cpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26
27 #include <stdio.h>
28
29 #include <iostream>
30
31 #include "d3d9imports.hpp"
32 #include "d3dshader.hpp"
33 #include "d3dstate.hpp"
34 #include "json.hpp"
35
36
37 namespace d3dstate {
38
39
40 template< class T >
41 inline void
42 dumpShader(JSONWriter &json, const char *name, T *pShader) {
43     if (!pShader) {
44         return;
45     }
46
47     HRESULT hr;
48
49     UINT SizeOfData = 0;
50
51     hr = pShader->GetFunction(NULL, &SizeOfData);
52     if (SUCCEEDED(hr)) {
53         void *pData;
54         pData = malloc(SizeOfData);
55         if (pData) {
56             hr = pShader->GetFunction(pData, &SizeOfData);
57             if (SUCCEEDED(hr)) {
58                 IDisassemblyBuffer *pDisassembly = NULL;
59                 hr = DisassembleShader((const DWORD *)pData, &pDisassembly);
60                 if (SUCCEEDED(hr)) {
61                     json.beginMember(name);
62                     json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
63                     json.endMember();
64                     pDisassembly->Release();
65                 }
66
67             }
68             free(pData);
69         }
70     }
71
72     pShader->Release();
73 }
74
75 static void
76 dumpShaders(JSONWriter &json, IDirect3DDevice9 *pDevice)
77 {
78     json.beginMember("shaders");
79
80     HRESULT hr;
81     json.beginObject();
82
83     IDirect3DVertexShader9 *pVertexShader = NULL;
84     hr = pDevice->GetVertexShader(&pVertexShader);
85     if (SUCCEEDED(hr)) {
86         dumpShader(json, "vertex", pVertexShader);
87     }
88
89     IDirect3DPixelShader9 *pPixelShader = NULL;
90     hr = pDevice->GetPixelShader(&pPixelShader);
91     if (SUCCEEDED(hr)) {
92         dumpShader(json, "pixel", pPixelShader);
93     }
94
95     json.endObject();
96     json.endMember(); // shaders
97 }
98
99 void
100 dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice)
101 {
102     JSONWriter json(os);
103
104     /* TODO */
105     json.beginMember("parameters");
106     json.beginObject();
107     json.endObject();
108     json.endMember(); // parameters
109
110     dumpShaders(json, pDevice);
111
112     json.beginMember("textures");
113     json.beginObject();
114     json.endObject();
115     json.endMember(); // textures
116
117     dumpFramebuffer(json, pDevice);
118 }
119
120
121 } /* namespace d3dstate */