José Fonseca | d63a361 | 2012-05-08 23:41:35 +0100 | [diff] [blame] | 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 | |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 27 | #include <stdio.h> |
| 28 | |
José Fonseca | d63a361 | 2012-05-08 23:41:35 +0100 | [diff] [blame] | 29 | #include <iostream> |
| 30 | |
José Fonseca | 1df5ed8 | 2014-06-13 10:45:46 +0100 | [diff] [blame^] | 31 | #include "json.hpp" |
| 32 | #include "com_ptr.hpp" |
José Fonseca | d63a361 | 2012-05-08 23:41:35 +0100 | [diff] [blame] | 33 | #include "d3d9imports.hpp" |
José Fonseca | 3b18682 | 2012-11-27 15:25:21 +0000 | [diff] [blame] | 34 | #include "d3dshader.hpp" |
José Fonseca | 9d8029d | 2012-12-05 12:00:37 +0000 | [diff] [blame] | 35 | #include "d3dstate.hpp" |
José Fonseca | d63a361 | 2012-05-08 23:41:35 +0100 | [diff] [blame] | 36 | |
| 37 | |
| 38 | namespace d3dstate { |
| 39 | |
| 40 | |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 41 | template< class T > |
| 42 | inline void |
| 43 | dumpShader(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é Fonseca | 1df5ed8 | 2014-06-13 10:45:46 +0100 | [diff] [blame^] | 59 | com_ptr<IDisassemblyBuffer> pDisassembly; |
José Fonseca | 3b18682 | 2012-11-27 15:25:21 +0000 | [diff] [blame] | 60 | hr = DisassembleShader((const DWORD *)pData, &pDisassembly); |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 61 | if (SUCCEEDED(hr)) { |
| 62 | json.beginMember(name); |
| 63 | json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */); |
| 64 | json.endMember(); |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | } |
| 68 | free(pData); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static void |
| 74 | dumpShaders(JSONWriter &json, IDirect3DDevice9 *pDevice) |
| 75 | { |
| 76 | json.beginMember("shaders"); |
| 77 | |
| 78 | HRESULT hr; |
| 79 | json.beginObject(); |
| 80 | |
José Fonseca | 1df5ed8 | 2014-06-13 10:45:46 +0100 | [diff] [blame^] | 81 | com_ptr<IDirect3DVertexShader9> pVertexShader; |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 82 | hr = pDevice->GetVertexShader(&pVertexShader); |
| 83 | if (SUCCEEDED(hr)) { |
José Fonseca | 1df5ed8 | 2014-06-13 10:45:46 +0100 | [diff] [blame^] | 84 | dumpShader<IDirect3DVertexShader9>(json, "vertex", pVertexShader); |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 85 | } |
| 86 | |
José Fonseca | 1df5ed8 | 2014-06-13 10:45:46 +0100 | [diff] [blame^] | 87 | com_ptr<IDirect3DPixelShader9> pPixelShader; |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 88 | hr = pDevice->GetPixelShader(&pPixelShader); |
| 89 | if (SUCCEEDED(hr)) { |
José Fonseca | 1df5ed8 | 2014-06-13 10:45:46 +0100 | [diff] [blame^] | 90 | dumpShader<IDirect3DPixelShader9>(json, "pixel", pPixelShader); |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | json.endObject(); |
| 94 | json.endMember(); // shaders |
| 95 | } |
| 96 | |
José Fonseca | d63a361 | 2012-05-08 23:41:35 +0100 | [diff] [blame] | 97 | void |
| 98 | dumpDevice(std::ostream &os, IDirect3DDevice9 *pDevice) |
| 99 | { |
| 100 | JSONWriter json(os); |
| 101 | |
José Fonseca | 9d8029d | 2012-12-05 12:00:37 +0000 | [diff] [blame] | 102 | /* TODO */ |
| 103 | json.beginMember("parameters"); |
| 104 | json.beginObject(); |
| 105 | json.endObject(); |
| 106 | json.endMember(); // parameters |
| 107 | |
José Fonseca | 3379d42 | 2012-09-20 12:29:16 +0100 | [diff] [blame] | 108 | dumpShaders(json, pDevice); |
| 109 | |
José Fonseca | 0386c03 | 2013-11-19 17:28:58 +0000 | [diff] [blame] | 110 | dumpTextures(json, pDevice); |
José Fonseca | 9d8029d | 2012-12-05 12:00:37 +0000 | [diff] [blame] | 111 | |
| 112 | dumpFramebuffer(json, pDevice); |
José Fonseca | d63a361 | 2012-05-08 23:41:35 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | |
| 116 | } /* namespace d3dstate */ |