1 /**************************************************************************
3 * Copyright 2011-2012 VMware, Inc.
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 **************************************************************************/
31 #include "d3d8imports.hpp"
32 #include "d3dshader.hpp"
33 #include "d3dstate.hpp"
40 typedef HRESULT (STDMETHODCALLTYPE IDirect3DDevice8::*GetShaderFunctionMethod)(DWORD Handle, void* pData, DWORD* pSizeOfData);
43 struct VertexShaderGetter
45 HRESULT GetShader(IDirect3DDevice8 *pDevice, DWORD *pHandle) {
46 return pDevice->GetVertexShader(pHandle);
48 HRESULT GetShaderFunction(IDirect3DDevice8 *pDevice, DWORD Handle, void* pData, DWORD* pSizeOfData) {
49 return pDevice->GetVertexShaderFunction(Handle, pData, pSizeOfData);
53 struct PixelShaderGetter
55 HRESULT GetShader(IDirect3DDevice8 *pDevice, DWORD *pHandle) {
56 return pDevice->GetPixelShader(pHandle);
58 HRESULT GetShaderFunction(IDirect3DDevice8 *pDevice, DWORD Handle, void* pData, DWORD* pSizeOfData) {
59 return pDevice->GetPixelShaderFunction(Handle, pData, pSizeOfData);
63 template<class Getter>
65 dumpShader(JSONWriter &json, IDirect3DDevice8 *pDevice, const char *name) {
70 hr = getter.GetShader(pDevice, &dwShader);
71 if (FAILED(hr) || !dwShader) {
77 hr = getter.GetShaderFunction(pDevice, dwShader, NULL, &SizeOfData);
80 pData = malloc(SizeOfData);
82 hr = getter.GetShaderFunction(pDevice, dwShader, pData, &SizeOfData);
84 IDisassemblyBuffer *pDisassembly = NULL;
85 hr = DisassembleShader((const DWORD *)pData, &pDisassembly);
87 json.beginMember(name);
88 json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
90 pDisassembly->Release();
100 dumpShaders(JSONWriter &json, IDirect3DDevice8 *pDevice)
102 json.beginMember("shaders");
105 dumpShader<VertexShaderGetter>(json, pDevice, "vertex");
106 dumpShader<PixelShaderGetter>(json, pDevice, "pixel");
109 json.endMember(); // shaders
113 dumpDevice(std::ostream &os, IDirect3DDevice8 *pDevice)
118 json.beginMember("parameters");
121 json.endMember(); // parameters
123 dumpShaders(json, pDevice);
125 json.beginMember("textures");
128 json.endMember(); // textures
130 dumpFramebuffer(json, pDevice);
134 } /* namespace d3dstate */