blob: c30114ea28df176365835c389c9db3251a045102 [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
José Fonseca1df5ed82014-06-13 10:45:46 +010031#include "json.hpp"
32#include "com_ptr.hpp"
José Fonsecad63a3612012-05-08 23:41:35 +010033#include "d3d9imports.hpp"
José Fonseca3b186822012-11-27 15:25:21 +000034#include "d3dshader.hpp"
José Fonseca9d8029d2012-12-05 12:00:37 +000035#include "d3dstate.hpp"
José Fonsecad63a3612012-05-08 23:41:35 +010036
37
38namespace d3dstate {
39
40
José Fonseca3379d422012-09-20 12:29:16 +010041template< class T >
42inline void
43dumpShader(JSONWriter &json, const char *name, T *pShader) {
44 if (!pShader) {
45 return;
46 }
47
48 HRESULT hr;
49
50 UINT SizeOfData = 0;
51
52 hr = pShader->GetFunction(NULL, &SizeOfData);
53 if (SUCCEEDED(hr)) {
54 void *pData;
55 pData = malloc(SizeOfData);
56 if (pData) {
57 hr = pShader->GetFunction(pData, &SizeOfData);
58 if (SUCCEEDED(hr)) {
José Fonseca1df5ed82014-06-13 10:45:46 +010059 com_ptr<IDisassemblyBuffer> pDisassembly;
José Fonseca3b186822012-11-27 15:25:21 +000060 hr = DisassembleShader((const DWORD *)pData, &pDisassembly);
José Fonseca3379d422012-09-20 12:29:16 +010061 if (SUCCEEDED(hr)) {
62 json.beginMember(name);
63 json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
64 json.endMember();
José Fonseca3379d422012-09-20 12:29:16 +010065 }
66
67 }
68 free(pData);
69 }
70 }
71}
72
73static void
74dumpShaders(JSONWriter &json, IDirect3DDevice9 *pDevice)
75{
76 json.beginMember("shaders");
77
78 HRESULT hr;
79 json.beginObject();
80
José Fonseca1df5ed82014-06-13 10:45:46 +010081 com_ptr<IDirect3DVertexShader9> pVertexShader;
José Fonseca3379d422012-09-20 12:29:16 +010082 hr = pDevice->GetVertexShader(&pVertexShader);
83 if (SUCCEEDED(hr)) {
José Fonseca1df5ed82014-06-13 10:45:46 +010084 dumpShader<IDirect3DVertexShader9>(json, "vertex", pVertexShader);
José Fonseca3379d422012-09-20 12:29:16 +010085 }
86
José Fonseca1df5ed82014-06-13 10:45:46 +010087 com_ptr<IDirect3DPixelShader9> pPixelShader;
José Fonseca3379d422012-09-20 12:29:16 +010088 hr = pDevice->GetPixelShader(&pPixelShader);
89 if (SUCCEEDED(hr)) {
José Fonseca1df5ed82014-06-13 10:45:46 +010090 dumpShader<IDirect3DPixelShader9>(json, "pixel", pPixelShader);
José Fonseca3379d422012-09-20 12:29:16 +010091 }
92
93 json.endObject();
94 json.endMember(); // shaders
95}
96
José Fonsecad63a3612012-05-08 23:41:35 +010097void
98dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice)
99{
100 JSONWriter json(os);
101
José Fonseca9d8029d2012-12-05 12:00:37 +0000102 /* TODO */
103 json.beginMember("parameters");
104 json.beginObject();
105 json.endObject();
106 json.endMember(); // parameters
107
José Fonseca3379d422012-09-20 12:29:16 +0100108 dumpShaders(json, pDevice);
109
José Fonseca0386c032013-11-19 17:28:58 +0000110 dumpTextures(json, pDevice);
José Fonseca9d8029d2012-12-05 12:00:37 +0000111
112 dumpFramebuffer(json, pDevice);
José Fonsecad63a3612012-05-08 23:41:35 +0100113}
114
115
116} /* namespace d3dstate */