1 | #include <iostream>
|
---|
2 | #include <string>
|
---|
3 |
|
---|
4 | #include <d3dcompiler.h>
|
---|
5 |
|
---|
6 | #include <shellapi.h>
|
---|
7 | #include <windows.h>
|
---|
8 | #include <windowsx.h>
|
---|
9 |
|
---|
10 | #include "../../src/util/com/com_pointer.h"
|
---|
11 |
|
---|
12 | using namespace dxvk;
|
---|
13 |
|
---|
14 | int WINAPI WinMain(HINSTANCE hInstance,
|
---|
15 | HINSTANCE hPrevInstance,
|
---|
16 | LPSTR lpCmdLine,
|
---|
17 | int nCmdShow) {
|
---|
18 | int argc = 0;
|
---|
19 | LPWSTR* argv = CommandLineToArgvW(
|
---|
20 | GetCommandLineW(), &argc);
|
---|
21 |
|
---|
22 | if (argc < 2 || argc > 3) {
|
---|
23 | std::cerr << "Usage: dxbc-disasm input.dxbc [output]" << std::endl;
|
---|
24 | return 1;
|
---|
25 | }
|
---|
26 |
|
---|
27 | Com<ID3DBlob> assembly;
|
---|
28 | Com<ID3DBlob> binary;
|
---|
29 |
|
---|
30 | // input file
|
---|
31 | if (FAILED(D3DReadFileToBlob(argv[1], &binary))) {
|
---|
32 | std::cerr << "Failed to read shader" << std::endl;
|
---|
33 | return 1;
|
---|
34 | }
|
---|
35 |
|
---|
36 | HRESULT hr = D3DDisassemble(
|
---|
37 | binary->GetBufferPointer(),
|
---|
38 | binary->GetBufferSize(),
|
---|
39 | D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING, nullptr,
|
---|
40 | &assembly);
|
---|
41 |
|
---|
42 | if (FAILED(hr)) {
|
---|
43 | std::cerr << "Failed to disassemble shader" << std::endl;
|
---|
44 | return 1;
|
---|
45 | }
|
---|
46 |
|
---|
47 | // output file variant
|
---|
48 | if (argc == 3 && FAILED(D3DWriteBlobToFile(assembly.ptr(), argv[2], 1))) {
|
---|
49 | std::cerr << "Failed to write shader" << std::endl;
|
---|
50 | return 1;
|
---|
51 | }
|
---|
52 |
|
---|
53 | // stdout variant
|
---|
54 | if (argc == 2) {
|
---|
55 | std::string data((const char *)assembly->GetBufferPointer(), assembly->GetBufferSize());
|
---|
56 | std::cout << data;
|
---|
57 | }
|
---|
58 |
|
---|
59 | return 0;
|
---|
60 | }
|
---|