blob: 6b35529499e9ed84f9db485f2e404a6017322e28 [file] [log] [blame]
José Fonsecad63a3612012-05-08 23:41:35 +01001/**************************************************************************
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
José Fonseca3379d422012-09-20 12:29:16 +010027#include <stdio.h>
28
José Fonsecad63a3612012-05-08 23:41:35 +010029#include <iostream>
30
31#include "d3d9imports.hpp"
José Fonseca3b186822012-11-27 15:25:21 +000032#include "d3dshader.hpp"
José Fonseca9d8029d2012-12-05 12:00:37 +000033#include "d3dstate.hpp"
José Fonsecad63a3612012-05-08 23:41:35 +010034#include "json.hpp"
35
36
37namespace d3dstate {
38
39
José Fonseca3379d422012-09-20 12:29:16 +010040template< class T >
41inline void
42dumpShader(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)) {
José Fonseca3b186822012-11-27 15:25:21 +000058 IDisassemblyBuffer *pDisassembly = NULL;
59 hr = DisassembleShader((const DWORD *)pData, &pDisassembly);
José Fonseca3379d422012-09-20 12:29:16 +010060 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 }
José Fonseca61a25342012-11-27 20:01:29 +000071
72 pShader->Release();
José Fonseca3379d422012-09-20 12:29:16 +010073}
74
75static void
76dumpShaders(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
José Fonsecad63a3612012-05-08 23:41:35 +010099void
100dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice)
101{
102 JSONWriter json(os);
103
José Fonseca9d8029d2012-12-05 12:00:37 +0000104 /* TODO */
105 json.beginMember("parameters");
106 json.beginObject();
107 json.endObject();
108 json.endMember(); // parameters
109
José Fonseca3379d422012-09-20 12:29:16 +0100110 dumpShaders(json, pDevice);
111
José Fonseca0386c032013-11-19 17:28:58 +0000112 dumpTextures(json, pDevice);
José Fonseca9d8029d2012-12-05 12:00:37 +0000113
114 dumpFramebuffer(json, pDevice);
José Fonsecad63a3612012-05-08 23:41:35 +0100115}
116
117
118} /* namespace d3dstate */