1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-30 22:24:15 +01:00
dxvk/tests/dxbc/test_dxbc_compiler.cpp
Philip Rebohle 98b8d41016
[dxbc] Write shader name to the generated SPIR-V
Might help identifying shaders in debugging tools such as Renderdoc.
2018-04-15 21:00:08 +02:00

53 lines
1.3 KiB
C++

#include <iterator>
#include <fstream>
#include <dxbc_module.h>
#include <dxvk_shader.h>
#include <shellapi.h>
#include <windows.h>
#include <windowsx.h>
namespace dxvk {
Logger Logger::s_instance("dxbc-compiler.log");
}
using namespace dxvk;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(
GetCommandLineW(), &argc);
if (argc < 3) {
Logger::err("Usage: dxbc-compiler input.dxbc output.spv");
return 1;
}
try {
std::string ifileName = str::fromws(argv[1]);
std::ifstream ifile(ifileName, std::ios::binary);
ifile.ignore(std::numeric_limits<std::streamsize>::max());
std::streamsize length = ifile.gcount();
ifile.clear();
ifile.seekg(0, std::ios_base::beg);
std::vector<char> dxbcCode(length);
ifile.read(dxbcCode.data(), length);
DxbcReader reader(dxbcCode.data(), dxbcCode.size());
DxbcModule module(reader);
Rc<DxvkShader> shader = module.compile(DxbcOptions(), ifileName);
std::ofstream ofile(str::fromws(argv[2]), std::ios::binary);
shader->dump(ofile);
return 0;
} catch (const DxvkError& e) {
Logger::err(e.message());
return 1;
}
}