-template< class T >
-inline void
-dumpShader(JSONWriter &json, const char *name, T *pShader) {
- if (!pShader) {
- return;
- }
-
- HRESULT hr;
-
- /*
- * There is no method to get the shader byte code, so the creator is supposed to
- * attach it via the SetPrivateData method.
- */
- UINT BytecodeLength = 0;
- char dummy;
- hr = pShader->GetPrivateData(GUID_D3DSTATE, &BytecodeLength, &dummy);
- if (hr != DXGI_ERROR_MORE_DATA) {
- return;
- }
-
- void *pShaderBytecode = malloc(BytecodeLength);
- if (!pShaderBytecode) {
- return;
- }
-
- hr = pShader->GetPrivateData(GUID_D3DSTATE, &BytecodeLength, pShaderBytecode);
- if (SUCCEEDED(hr)) {
- IDisassemblyBuffer *pDisassembly = NULL;
- hr = DisassembleShader(pShaderBytecode, BytecodeLength, &pDisassembly);
- if (SUCCEEDED(hr)) {
- json.beginMember(name);
- json.writeString((const char *)pDisassembly->GetBufferPointer() /*, pDisassembly->GetBufferSize() */);
- json.endMember();
- pDisassembly->Release();
- }
- }
-
- free(pShaderBytecode);
-}
-