1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-05 10:24:13 +01:00
dxvk/tests/dxbc/test_dxbc_disasm.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

#include <iostream>
2018-08-15 21:52:59 +02:00
#include <string>
2017-12-06 18:53:25 +01:00
#include <d3dcompiler.h>
#include <shellapi.h>
#include <windows.h>
#include <windowsx.h>
#include "../../src/util/com/com_pointer.h"
2017-12-06 18:53:25 +01:00
using namespace dxvk;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(
GetCommandLineW(), &argc);
if (argc < 2 || argc > 3) {
std::cerr << "Usage: dxbc-disasm input.dxbc [output]" << std::endl;
2017-12-06 18:53:25 +01:00
return 1;
}
2017-12-06 18:53:25 +01:00
Com<ID3DBlob> assembly;
Com<ID3DBlob> binary;
// input file
if (FAILED(D3DReadFileToBlob(argv[1], &binary))) {
std::cerr << "Failed to read shader" << std::endl;
return 1;
}
2017-12-06 18:53:25 +01:00
HRESULT hr = D3DDisassemble(
binary->GetBufferPointer(),
binary->GetBufferSize(),
2017-12-06 18:53:25 +01:00
D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING, nullptr,
&assembly);
2017-12-06 18:53:25 +01:00
if (FAILED(hr)) {
std::cerr << "Failed to disassemble shader" << std::endl;
return 1;
}
// output file variant
if (argc == 3 && FAILED(D3DWriteBlobToFile(assembly.ptr(), argv[2], 1))) {
std::cerr << "Failed to write shader" << std::endl;
return 1;
}
// stdout variant
if (argc == 2) {
std::string data((const char *)assembly->GetBufferPointer(), assembly->GetBufferSize());
std::cout << data;
}
2017-12-06 18:53:25 +01:00
return 0;
}