[D3D12] Begin writing the DXBC translator
This commit is contained in:
parent
8ced574c6f
commit
945ced4996
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2018 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "xenia/gpu/dxbc_shader_translator.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "third_party/dxbc/DXBCChecksum.h"
|
||||
#include "third_party/dxbc/d3d12TokenizedProgramFormat.hpp"
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
using namespace ucode;
|
||||
|
||||
DxbcShaderTranslator::DxbcShaderTranslator() {}
|
||||
DxbcShaderTranslator::~DxbcShaderTranslator() = default;
|
||||
|
||||
void DxbcShaderTranslator::Reset() {
|
||||
ShaderTranslator::Reset();
|
||||
|
||||
shader_code_.clear();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> DxbcShaderTranslator::CompleteTranslation() {
|
||||
shader_object_.clear();
|
||||
|
||||
// Shader object header.
|
||||
shader_object_.push_back('CBXD');
|
||||
// Reserve space for the checksum.
|
||||
for (uint32_t i = 0; i < 4; ++i) {
|
||||
shader_object_.push_back(0);
|
||||
}
|
||||
shader_object_.push_back(1);
|
||||
// Reserve space for the size.
|
||||
shader_object_.push_back(0);
|
||||
// 5 chunks - RDEF, ISGN, OSGN, SHEX, STAT.
|
||||
shader_object_.push_back(5);
|
||||
|
||||
// Copy bytes out.
|
||||
// TODO(Triang3l): avoid copy?
|
||||
std::vector<uint8_t> shader_object_bytes;
|
||||
shader_object_bytes.resize(shader_object_.size() * sizeof(uint32_t));
|
||||
std::memcpy(shader_object_bytes.data(), shader_object_.data(),
|
||||
shader_object_bytes.size());
|
||||
return shader_object_bytes;
|
||||
}
|
||||
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2018 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef XENIA_GPU_DXBC_SHADER_TRANSLATOR_H_
|
||||
#define XENIA_GPU_DXBC_SHADER_TRANSLATOR_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "xenia/gpu/shader_translator.h"
|
||||
|
||||
namespace xe {
|
||||
namespace gpu {
|
||||
|
||||
// Generates shader model 5_1 byte code (for Direct3D 12).
|
||||
class DxbcShaderTranslator : public ShaderTranslator {
|
||||
public:
|
||||
DxbcShaderTranslator();
|
||||
~DxbcShaderTranslator() override;
|
||||
|
||||
protected:
|
||||
void Reset() override;
|
||||
|
||||
std::vector<uint8_t> CompleteTranslation() override;
|
||||
|
||||
private:
|
||||
// Executable instructions - generated during translation.
|
||||
std::vector<uint32_t> shader_code_;
|
||||
// Complete shader object, with all the needed chunks and dcl_ instructions -
|
||||
// generated in the end of translation.
|
||||
std::vector<uint32_t> shader_object_;
|
||||
};
|
||||
|
||||
} // namespace gpu
|
||||
} // namespace xe
|
||||
|
||||
#endif // XENIA_GPU_DXBC_SHADER_TRANSLATOR_H_
|
Loading…
Reference in New Issue