From 285de2a52165d63847ea41cded8cf421c2be0bea Mon Sep 17 00:00:00 2001 From: Triang3l Date: Mon, 27 Aug 2018 16:53:59 +0300 Subject: [PATCH] [D3D12] DXBC string append --- src/xenia/gpu/dxbc_shader_translator.cc | 14 ++++++++++++++ src/xenia/gpu/dxbc_shader_translator.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/xenia/gpu/dxbc_shader_translator.cc b/src/xenia/gpu/dxbc_shader_translator.cc index bcbdb233e..bfbf95f41 100644 --- a/src/xenia/gpu/dxbc_shader_translator.cc +++ b/src/xenia/gpu/dxbc_shader_translator.cc @@ -14,6 +14,8 @@ #include "third_party/dxbc/DXBCChecksum.h" #include "third_party/dxbc/d3d12TokenizedProgramFormat.hpp" +#include "xenia/base/math.h" + namespace xe { namespace gpu { using namespace ucode; @@ -58,5 +60,17 @@ std::vector DxbcShaderTranslator::CompleteTranslation() { return shader_object_bytes; } +uint32_t DxbcShaderTranslator::AppendString(std::vector& dest, + const char* source) { + size_t size = std::strlen(source) + 1; + size_t size_aligned = xe::align(size_aligned, sizeof(uint32_t)); + size_t dest_pos = dest.size(); + dest.resize(dest_pos + size_aligned / sizeof(uint32_t)); + std::memcpy(&dest[dest_pos], source, size); + std::memset(reinterpret_cast(&dest[dest_pos]) + size, 0xAB, + size_aligned - size); + return uint32_t(size_aligned); +} + } // namespace gpu } // namespace xe diff --git a/src/xenia/gpu/dxbc_shader_translator.h b/src/xenia/gpu/dxbc_shader_translator.h index 5f8f144c8..b8d3ad381 100644 --- a/src/xenia/gpu/dxbc_shader_translator.h +++ b/src/xenia/gpu/dxbc_shader_translator.h @@ -29,6 +29,9 @@ class DxbcShaderTranslator : public ShaderTranslator { std::vector CompleteTranslation() override; private: + // Appends a string to a DWORD stream, returns the DWORD-aligned length. + static uint32_t AppendString(std::vector& dest, const char* source); + // Executable instructions - generated during translation. std::vector shader_code_; // Complete shader object, with all the needed chunks and dcl_ instructions -