[D3D12] Switch from gflags to cvars

This commit is contained in:
Triang3l
2019-08-03 16:53:23 +03:00
127 changed files with 959 additions and 647 deletions

View File

@@ -7,13 +7,12 @@
******************************************************************************
*/
#include <gflags/gflags.h>
#include <cinttypes>
#include <cstring>
#include <string>
#include <vector>
#include "xenia/base/cvar.h"
#include "xenia/base/logging.h"
#include "xenia/base/main.h"
#include "xenia/base/platform.h"
@@ -24,46 +23,51 @@
#include "xenia/gpu/spirv_shader_translator.h"
#include "xenia/ui/spirv/spirv_disassembler.h"
<<<<<<< HEAD
// For D3DDisassemble:
#if XE_PLATFORM_WIN32
#include "xenia/ui/d3d12/d3d12_api.h"
#endif // XE_PLATFORM_WIN32
DEFINE_string(shader_input, "", "Input shader binary file path.");
DEFINE_string(shader_input, "", "Input shader binary file path.", "GPU");
DEFINE_string(shader_input_type, "",
"'vs', 'ps', or unspecified to infer from the given filename.");
DEFINE_string(shader_output, "", "Output shader file path.");
"'vs', 'ps', or unspecified to infer from the given filename.",
"GPU");
DEFINE_string(shader_output, "", "Output shader file path.", "GPU");
DEFINE_string(shader_output_type, "ucode",
"Translator to use: [ucode, glsl45, spirv, spirvtext, dxbc].");
"Translator to use: [ucode, glsl45, spirv, spirvtext, dxbc].",
"GPU");
DEFINE_string(shader_output_patch, "",
"Tessellation patch type in the generated tessellation "
"evaluation (domain) shader, or unspecified to produce a vertex "
"shader: [line, triangle, quad].");
"shader: [line, triangle, quad].",
"GPU");
DEFINE_bool(shader_output_dxbc_rov, false,
"Output ROV-based output-merger code in DXBC pixel shaders.");
"Output ROV-based output-merger code in DXBC pixel shaders.",
"GPU");
namespace xe {
namespace gpu {
int shader_compiler_main(const std::vector<std::wstring>& args) {
ShaderType shader_type;
if (!FLAGS_shader_input_type.empty()) {
if (FLAGS_shader_input_type == "vs") {
if (!cvars::shader_input_type.empty()) {
if (cvars::shader_input_type == "vs") {
shader_type = ShaderType::kVertex;
} else if (FLAGS_shader_input_type == "ps") {
} else if (cvars::shader_input_type == "ps") {
shader_type = ShaderType::kPixel;
} else {
XELOGE("Invalid --shader_input_type; must be 'vs' or 'ps'.");
return 1;
}
} else {
auto last_dot = FLAGS_shader_input.find_last_of('.');
auto last_dot = cvars::shader_input.find_last_of('.');
bool valid_type = false;
if (last_dot != std::string::npos) {
if (FLAGS_shader_input.substr(last_dot) == ".vs") {
if (cvars::shader_input.substr(last_dot) == ".vs") {
shader_type = ShaderType::kVertex;
valid_type = true;
} else if (FLAGS_shader_input.substr(last_dot) == ".ps") {
} else if (cvars::shader_input.substr(last_dot) == ".ps") {
shader_type = ShaderType::kPixel;
valid_type = true;
}
@@ -76,9 +80,9 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
}
}
auto input_file = fopen(FLAGS_shader_input.c_str(), "rb");
auto input_file = fopen(cvars::shader_input.c_str(), "rb");
if (!input_file) {
XELOGE("Unable to open input file: %s", FLAGS_shader_input.c_str());
XELOGE("Unable to open input file: %s", cvars::shader_input.c_str());
return 1;
}
fseek(input_file, 0, SEEK_END);
@@ -89,7 +93,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
fclose(input_file);
XELOGI("Opened %s as a %s shader, %" PRId64 " words (%" PRId64 " bytes).",
FLAGS_shader_input.c_str(),
cvars::shader_input.c_str(),
shader_type == ShaderType::kVertex ? "vertex" : "pixel",
ucode_dwords.size(), ucode_dwords.size() * 4);
@@ -99,26 +103,26 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
shader_type, ucode_data_hash, ucode_dwords.data(), ucode_dwords.size());
std::unique_ptr<ShaderTranslator> translator;
if (FLAGS_shader_output_type == "spirv" ||
FLAGS_shader_output_type == "spirvtext") {
if (cvars::shader_output_type == "spirv" ||
cvars::shader_output_type == "spirvtext") {
translator = std::make_unique<SpirvShaderTranslator>();
} else if (FLAGS_shader_output_type == "glsl45") {
} else if (cvars::shader_output_type == "glsl45") {
translator = std::make_unique<GlslShaderTranslator>(
GlslShaderTranslator::Dialect::kGL45);
} else if (FLAGS_shader_output_type == "dxbc") {
translator =
std::make_unique<DxbcShaderTranslator>(0, FLAGS_shader_output_dxbc_rov);
} else if (cvars::shader_output_type == "dxbc") {
translator = std::make_unique<DxbcShaderTranslator>(
0, cvars::shader_output_dxbc_rov);
} else {
translator = std::make_unique<UcodeShaderTranslator>();
}
PrimitiveType patch_primitive_type = PrimitiveType::kNone;
if (shader_type == ShaderType::kVertex) {
if (FLAGS_shader_output_patch == "line") {
if (cvars::shader_output_patch == "line") {
patch_primitive_type = PrimitiveType::kLinePatch;
} else if (FLAGS_shader_output_patch == "triangle") {
} else if (cvars::shader_output_patch == "triangle") {
patch_primitive_type = PrimitiveType::kTrianglePatch;
} else if (FLAGS_shader_output_patch == "quad") {
} else if (cvars::shader_output_patch == "quad") {
patch_primitive_type = PrimitiveType::kQuadPatch;
}
}
@@ -129,7 +133,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
size_t source_data_size = shader->translated_binary().size();
std::unique_ptr<xe::ui::spirv::SpirvDisassembler::Result> spirv_disasm_result;
if (FLAGS_shader_output_type == "spirvtext") {
if (cvars::shader_output_type == "spirvtext") {
// Disassemble SPIRV.
spirv_disasm_result = xe::ui::spirv::SpirvDisassembler().Disassemble(
reinterpret_cast<const uint32_t*>(source_data), source_data_size / 4);
@@ -138,7 +142,7 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
}
#if XE_PLATFORM_WIN32
ID3DBlob* dxbc_disasm_blob = nullptr;
if (FLAGS_shader_output_type == "dxbc") {
if (cvars::shader_output_type == "dxbc") {
HMODULE d3d_compiler = LoadLibrary(L"D3DCompiler_47.dll");
if (d3d_compiler != nullptr) {
pD3DDisassemble d3d_disassemble =
@@ -158,8 +162,8 @@ int shader_compiler_main(const std::vector<std::wstring>& args) {
}
#endif // XE_PLATFORM_WIN32
if (!FLAGS_shader_output.empty()) {
auto output_file = fopen(FLAGS_shader_output.c_str(), "wb");
if (!cvars::shader_output.empty()) {
auto output_file = fopen(cvars::shader_output.c_str(), "wb");
fwrite(source_data, 1, source_data_size, output_file);
fclose(output_file);
}