[D3D12] Switch to DXBC shader translator (currently unusable)

This commit is contained in:
Triang3l
2018-08-30 20:42:22 +03:00
parent 8376918bb7
commit 8268825f3b
9 changed files with 59 additions and 133 deletions

View File

@@ -9,15 +9,10 @@
#include "xenia/gpu/d3d12/d3d12_shader.h"
#include <gflags/gflags.h>
#include "xenia/base/assert.h"
#include "xenia/base/logging.h"
#include "xenia/gpu/gpu_flags.h"
DEFINE_bool(d3d12_shader_disasm, false,
"Disassemble translated shaders after compilation.");
namespace xe {
namespace gpu {
namespace d3d12 {
@@ -32,6 +27,7 @@ D3D12Shader::~D3D12Shader() {
}
}
#if 0
void D3D12Shader::SetTexturesAndSamplers(
const HlslShaderTranslator::TextureSRV* texture_srvs,
uint32_t texture_srv_count, const uint32_t* sampler_fetch_constants,
@@ -52,93 +48,25 @@ void D3D12Shader::SetTexturesAndSamplers(
}
sampler_count_ = sampler_count;
}
#endif
bool D3D12Shader::Prepare() {
assert_null(blob_);
assert_true(is_valid());
const char* target;
switch (shader_type_) {
case ShaderType::kVertex:
target = "vs_5_1";
break;
case ShaderType::kPixel:
target = "ps_5_1";
break;
default:
assert_unhandled_case(shader_type_);
is_valid_ = false;
return false;
bool D3D12Shader::DisassembleDXBC() {
if (!host_disassembly_.empty()) {
return true;
}
// TODO(Triang3l): Choose the appropriate optimization level based on compile
// time and how invariance is handled in vertex shaders.
ID3DBlob* error_blob = nullptr;
bool compiled = SUCCEEDED(
D3DCompile(translated_binary_.data(), translated_binary_.size(), nullptr,
nullptr, nullptr, "main", target,
D3DCOMPILE_SKIP_OPTIMIZATION, 0, &blob_, &error_blob));
if (!compiled) {
XELOGE("%s shader %.16llX compilation failed!", target, ucode_data_hash());
}
if (error_blob != nullptr) {
const char* error_log =
reinterpret_cast<const char*>(error_blob->GetBufferPointer());
host_error_log_ = error_log;
if (compiled) {
XELOGW("%s shader %.16llX compiled with warnings!", target,
ucode_data_hash());
XELOGW("%s", error_log);
XELOGW("HLSL source:");
// The buffer isn't terminated.
translated_binary_.push_back(0);
XELOGW("%s", reinterpret_cast<const char*>(translated_binary_.data()));
translated_binary_.pop_back();
} else {
XELOGE("%s", error_log);
XELOGE("HLSL source:");
translated_binary_.push_back(0);
XELOGE("%s", reinterpret_cast<const char*>(translated_binary_.data()));
translated_binary_.pop_back();
}
error_blob->Release();
}
if (!compiled) {
is_valid_ = false;
ID3DBlob* blob;
if (FAILED(D3DDisassemble(translated_binary().data(),
translated_binary().size(),
D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING |
D3D_DISASM_ENABLE_INSTRUCTION_OFFSET,
nullptr, &blob))) {
return false;
}
if (FLAGS_d3d12_shader_disasm) {
ID3DBlob* disassembly_blob;
if (SUCCEEDED(D3DDisassemble(blob_->GetBufferPointer(),
blob_->GetBufferSize(),
D3D_DISASM_ENABLE_INSTRUCTION_NUMBERING |
D3D_DISASM_ENABLE_INSTRUCTION_OFFSET, nullptr,
&disassembly_blob))) {
host_disassembly_ =
reinterpret_cast<const char*>(disassembly_blob->GetBufferPointer());
disassembly_blob->Release();
} else {
XELOGE("Failed to disassemble DXBC for %s shader %.16llX", target,
ucode_data_hash());
}
}
host_disassembly_ = reinterpret_cast<const char*>(blob->GetBufferPointer());
blob->Release();
return true;
}
const uint8_t* D3D12Shader::GetDXBC() const {
assert_not_null(blob_);
return reinterpret_cast<const uint8_t*>(blob_->GetBufferPointer());
}
size_t D3D12Shader::GetDXBCSize() const {
assert_not_null(blob_);
return blob_->GetBufferSize();
}
} // namespace d3d12
} // namespace gpu
} // namespace xe