From 28b56aac2b4ab63b6c09bbd6903198f7bbdd380d Mon Sep 17 00:00:00 2001 From: Triang3l Date: Thu, 30 Aug 2018 15:12:27 +0300 Subject: [PATCH] [D3D12] DXBC SHEX writing --- src/xenia/gpu/dxbc_shader_translator.cc | 36 ++++++++++++++++++++++++- src/xenia/gpu/dxbc_shader_translator.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/xenia/gpu/dxbc_shader_translator.cc b/src/xenia/gpu/dxbc_shader_translator.cc index c555aa7e8..aa3ffa6de 100644 --- a/src/xenia/gpu/dxbc_shader_translator.cc +++ b/src/xenia/gpu/dxbc_shader_translator.cc @@ -87,7 +87,15 @@ std::vector DxbcShaderTranslator::CompleteTranslation() { (uint32_t(shader_object_.size()) - chunk_position_dwords - 2) * sizeof(uint32_t); - // TODO(Triang3l): Write SHEX. + // Write SHader EXtended. + chunk_position_dwords = uint32_t(shader_object_.size()); + shader_object_[11] = chunk_position_dwords * sizeof(uint32_t); + shader_object_.push_back('XEHS'); + shader_object_.push_back(0); + WriteShaderCode(); + shader_object_[chunk_position_dwords + 1] = + (uint32_t(shader_object_.size()) - chunk_position_dwords - 2) * + sizeof(uint32_t); // Write STATistics. chunk_position_dwords = uint32_t(shader_object_.size()); @@ -600,5 +608,31 @@ void DxbcShaderTranslator::WriteOutputSignature() { } } +void DxbcShaderTranslator::WriteShaderCode() { + uint32_t chunk_position_dwords = uint32_t(shader_object_.size()); + + // vs_5_1 or ps_5_1. + D3D10_SB_TOKENIZED_PROGRAM_TYPE program_type = + is_vertex_shader() ? D3D10_SB_VERTEX_SHADER : D3D10_SB_PIXEL_SHADER; + shader_object_.push_back((program_type << 16) | 0x51); + // Reserve space for the length. + shader_object_.push_back(0); + + // TODO(Triang3l): Declarations. + + // Write the translated shader code. + size_t code_size_dwords = shader_code_.size(); + // So [] won't crash in case the size is zero somehow. + if (code_size_dwords != 0) { + shader_object_.resize(shader_object_.size() + code_size_dwords); + std::memcpy(&shader_object_[shader_object_.size() - code_size_dwords], + shader_code_.data(), code_size_dwords * sizeof(uint32_t)); + } + + // Write the length. + shader_object_[chunk_position_dwords + 1] = + uint32_t(shader_object_.size()) - chunk_position_dwords; +} + } // namespace gpu } // namespace xe diff --git a/src/xenia/gpu/dxbc_shader_translator.h b/src/xenia/gpu/dxbc_shader_translator.h index db1e156d3..e6c626650 100644 --- a/src/xenia/gpu/dxbc_shader_translator.h +++ b/src/xenia/gpu/dxbc_shader_translator.h @@ -101,6 +101,7 @@ class DxbcShaderTranslator : public ShaderTranslator { void WriteResourceDefinitions(); void WriteInputSignature(); void WriteOutputSignature(); + void WriteShaderCode(); // Executable instructions - generated during translation. std::vector shader_code_;