blob: 0717c1022ad1d53d5180b87519b25981e09e5bc6 [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
Jose Fonsecae8ba0792015-05-01 12:38:03 +010031#include "state_writer.hpp"
José Fonseca1df5ed82014-06-13 10:45:46 +010032#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
Jose Fonsecae8ba0792015-05-01 12:38:03 +010043dumpShader(StateWriter &writer, const char *name, T *pShader) {
José Fonseca3379d422012-09-20 12:29:16 +010044 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)) {
Jose Fonsecae8ba0792015-05-01 12:38:03 +010062 writer.beginMember(name);
63 writer.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
64 writer.endMember();
José Fonseca3379d422012-09-20 12:29:16 +010065 }
66
67 }
68 free(pData);
69 }
70 }
71}
72
73static void
Jose Fonsecae8ba0792015-05-01 12:38:03 +010074dumpShaders(StateWriter &writer, IDirect3DDevice9 *pDevice)
José Fonseca3379d422012-09-20 12:29:16 +010075{
Jose Fonsecae8ba0792015-05-01 12:38:03 +010076 writer.beginMember("shaders");
José Fonseca3379d422012-09-20 12:29:16 +010077
78 HRESULT hr;
Jose Fonsecae8ba0792015-05-01 12:38:03 +010079 writer.beginObject();
José Fonseca3379d422012-09-20 12:29:16 +010080
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)) {
Jose Fonsecae8ba0792015-05-01 12:38:03 +010084 dumpShader<IDirect3DVertexShader9>(writer, "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)) {
Jose Fonsecae8ba0792015-05-01 12:38:03 +010090 dumpShader<IDirect3DPixelShader9>(writer, "pixel", pPixelShader);
José Fonseca3379d422012-09-20 12:29:16 +010091 }
92
Jose Fonsecae8ba0792015-05-01 12:38:03 +010093 writer.endObject();
94 writer.endMember(); // shaders
José Fonseca3379d422012-09-20 12:29:16 +010095}
96
José Fonsecad63a3612012-05-08 23:41:35 +010097void
Jose Fonsecae8ba0792015-05-01 12:38:03 +010098dumpDevice(StateWriter &writer, IDirect3DDevice9 *pDevice)
José Fonsecad63a3612012-05-08 23:41:35 +010099{
José Fonseca9d8029d2012-12-05 12:00:37 +0000100 /* TODO */
Jose Fonsecae8ba0792015-05-01 12:38:03 +0100101 writer.beginMember("parameters");
102 writer.beginObject();
103 writer.endObject();
104 writer.endMember(); // parameters
José Fonseca9d8029d2012-12-05 12:00:37 +0000105
Jose Fonsecae8ba0792015-05-01 12:38:03 +0100106 dumpShaders(writer, pDevice);
José Fonseca3379d422012-09-20 12:29:16 +0100107
Jose Fonsecae8ba0792015-05-01 12:38:03 +0100108 dumpTextures(writer, pDevice);
José Fonseca9d8029d2012-12-05 12:00:37 +0000109
Jose Fonsecae8ba0792015-05-01 12:38:03 +0100110 dumpFramebuffer(writer, pDevice);
José Fonsecad63a3612012-05-08 23:41:35 +0100111}
112
Jose Fonsecae39d56e2015-07-16 12:31:10 +0100113void
114dumpDevice(StateWriter &writer, IDirect3DSwapChain9 *pSwapChain)
115{
116 com_ptr<IDirect3DDevice9> pDevice;
117 HRESULT hr = pSwapChain->GetDevice(&pDevice);
118 if (SUCCEEDED(hr)) {
119 dumpDevice(writer, pDevice);
120 }
121}
122
José Fonsecad63a3612012-05-08 23:41:35 +0100123
124} /* namespace d3dstate */