Skeleton SPIRV shader translator.

This commit is contained in:
Ben Vanik
2015-11-25 16:37:28 -08:00
parent 80c6e14cdc
commit 71b9995448
3 changed files with 88 additions and 9 deletions

View File

@@ -19,6 +19,18 @@
namespace xe {
namespace gpu {
TranslatedShader::TranslatedShader(ShaderType shader_type,
uint64_t ucode_data_hash,
const uint32_t* ucode_words,
size_t ucode_word_count)
: shader_type_(shader_type), ucode_data_hash_(ucode_data_hash_) {
ucode_data_.resize(ucode_word_count);
std::memcpy(ucode_data_.data(), ucode_words,
ucode_word_count * sizeof(uint32_t));
}
TranslatedShader::~TranslatedShader() = default;
ShaderTranslator::ShaderTranslator() {
// HACK(benvanik): in-progress test code just to make sure things compile.
const std::string spirv_source = R"(
@@ -41,6 +53,31 @@ OpFunctionEnd
auto disasm_result =
spirv_disasm.Disassemble(asm_result->words(), asm_result->word_count());
return;
}
std::unique_ptr<TranslatedShader> ShaderTranslator::Translate(
ShaderType shader_type, uint64_t ucode_data_hash,
const uint32_t* ucode_words, size_t ucode_word_count) {
auto translated_shader = std::make_unique<TranslatedShader>(
shader_type, ucode_data_hash, ucode_words, ucode_word_count);
// run over once to generate info:
// vertex fetch
// fetch constant
// unnormalized [0-1] or [-1,1] if signed
// signed (integer formats only)
// round index (vs. floor)
// exp adjust [-32, 31] - all data multiplied by 2^(adj)
// stride words
// offset words
// texture fetch
// fetch constant
// unnormalized (0-N) or (0-1)
// alloc/export types/counts
// vs: output (16), position, point size
// ps: color (4), depth
xe::ui::spirv::SpirvEmitter e;
auto glsl_std_450 = e.ImportExtendedInstructions("GLSL.std.450");
auto fn = e.MakeMainEntry();
@@ -50,12 +87,13 @@ OpFunctionEnd
static_cast<int>(spv::GLSLstd450::Acos), {{float_1_0}});
e.MakeReturn(true);
std::vector<uint32_t> words;
e.Serialize(words);
std::vector<uint32_t> spirv_words;
e.Serialize(spirv_words);
auto disasm_result2 = spirv_disasm.Disassemble(words.data(), words.size());
auto disasm_result = xe::ui::spirv::SpirvDisassembler().Disassemble(
spirv_words.data(), spirv_words.size());
return;
return translated_shader;
}
} // namespace gpu