committed by
ameerj
30 changed files with 255 additions and 108 deletions
-
14src/shader_recompiler/CMakeLists.txt
-
21src/shader_recompiler/backend/spirv/emit_spirv.h
-
5src/shader_recompiler/frontend/ir/basic_block.cpp
-
11src/shader_recompiler/frontend/ir/basic_block.h
-
12src/shader_recompiler/frontend/ir/function.h
-
2src/shader_recompiler/frontend/ir/microinstruction.h
-
4src/shader_recompiler/frontend/ir/opcodes.cpp
-
2src/shader_recompiler/frontend/ir/opcodes.h
-
0src/shader_recompiler/frontend/ir/opcodes.inc
-
38src/shader_recompiler/frontend/ir/program.cpp
-
21src/shader_recompiler/frontend/ir/program.h
-
2src/shader_recompiler/frontend/ir/value.cpp
-
2src/shader_recompiler/frontend/maxwell/control_flow.h
-
2src/shader_recompiler/frontend/maxwell/decode.cpp
-
2src/shader_recompiler/frontend/maxwell/decode.h
-
2src/shader_recompiler/frontend/maxwell/opcodes.cpp
-
0src/shader_recompiler/frontend/maxwell/opcodes.h
-
49src/shader_recompiler/frontend/maxwell/program.cpp
-
22src/shader_recompiler/frontend/maxwell/program.h
-
2src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp
-
2src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp
-
2src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp
-
2src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp
-
2src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp
-
2src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp
-
5src/shader_recompiler/frontend/maxwell/translate/translate.cpp
-
7src/shader_recompiler/frontend/maxwell/translate/translate.h
-
28src/shader_recompiler/ir_opt/ssa_rewrite_pass.cpp
-
11src/shader_recompiler/main.cpp
-
89src/shader_recompiler/object_pool.h
@ -0,0 +1,21 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "shader_recompiler/frontend/ir/microinstruction.h" |
||||
|
#include "shader_recompiler/frontend/ir/program.h" |
||||
|
|
||||
|
namespace Shader::Backend::SPIRV { |
||||
|
|
||||
|
class EmitSPIRV { |
||||
|
public: |
||||
|
private: |
||||
|
// Microinstruction emitters |
||||
|
#define OPCODE(name, result_type, ...) void Emit##name(EmitContext& ctx, IR::Inst* inst); |
||||
|
#include "shader_recompiler/frontend/ir/opcodes.inc" |
||||
|
#undef OPCODE |
||||
|
}; |
||||
|
|
||||
|
} // namespace Shader::Backend::SPIRV |
||||
@ -0,0 +1,38 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project
|
||||
|
// Licensed under GPLv2 or any later version
|
||||
|
// Refer to the license.txt file included.
|
||||
|
|
||||
|
#pragma once
|
||||
|
|
||||
|
#include <map>
|
||||
|
#include <string>
|
||||
|
|
||||
|
#include <fmt/format.h>
|
||||
|
|
||||
|
#include "shader_recompiler/frontend/ir/function.h"
|
||||
|
#include "shader_recompiler/frontend/ir/program.h"
|
||||
|
|
||||
|
namespace Shader::IR { |
||||
|
|
||||
|
std::string DumpProgram(const Program& program) { |
||||
|
size_t index{0}; |
||||
|
std::map<const IR::Inst*, size_t> inst_to_index; |
||||
|
std::map<const IR::Block*, size_t> block_to_index; |
||||
|
|
||||
|
for (const IR::Function& function : program.functions) { |
||||
|
for (const IR::Block* const block : function.blocks) { |
||||
|
block_to_index.emplace(block, index); |
||||
|
++index; |
||||
|
} |
||||
|
} |
||||
|
std::string ret; |
||||
|
for (const IR::Function& function : program.functions) { |
||||
|
ret += fmt::format("Function\n"); |
||||
|
for (const auto& block : function.blocks) { |
||||
|
ret += IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n'; |
||||
|
} |
||||
|
} |
||||
|
return ret; |
||||
|
} |
||||
|
|
||||
|
} // namespace Shader::IR
|
||||
@ -0,0 +1,21 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <string> |
||||
|
|
||||
|
#include <boost/container/small_vector.hpp> |
||||
|
|
||||
|
#include "shader_recompiler/frontend/ir/function.h" |
||||
|
|
||||
|
namespace Shader::IR { |
||||
|
|
||||
|
struct Program { |
||||
|
boost::container::small_vector<Function, 1> functions; |
||||
|
}; |
||||
|
|
||||
|
[[nodiscard]] std::string DumpProgram(const Program& program); |
||||
|
|
||||
|
} // namespace Shader::IR |
||||
@ -0,0 +1,89 @@ |
|||||
|
// Copyright 2021 yuzu Emulator Project |
||||
|
// Licensed under GPLv2 or any later version |
||||
|
// Refer to the license.txt file included. |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include <memory> |
||||
|
#include <type_traits> |
||||
|
|
||||
|
namespace Shader { |
||||
|
|
||||
|
template <typename T, size_t chunk_size = 8192> |
||||
|
requires std::is_destructible_v<T> class ObjectPool { |
||||
|
public: |
||||
|
~ObjectPool() { |
||||
|
std::unique_ptr<Chunk> tree_owner; |
||||
|
Chunk* chunk{&root}; |
||||
|
while (chunk) { |
||||
|
for (size_t obj_id = chunk->free_objects; obj_id < chunk_size; ++obj_id) { |
||||
|
chunk->storage[obj_id].object.~T(); |
||||
|
} |
||||
|
tree_owner = std::move(chunk->next); |
||||
|
chunk = tree_owner.get(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
template <typename... Args> |
||||
|
requires std::is_constructible_v<T, Args...> [[nodiscard]] T* Create(Args&&... args) { |
||||
|
return std::construct_at(Memory(), std::forward<Args>(args)...); |
||||
|
} |
||||
|
|
||||
|
void ReleaseContents() { |
||||
|
Chunk* chunk{&root}; |
||||
|
if (chunk) { |
||||
|
const size_t free_objects{chunk->free_objects}; |
||||
|
if (free_objects == chunk_size) { |
||||
|
break; |
||||
|
} |
||||
|
chunk->free_objects = chunk_size; |
||||
|
for (size_t obj_id = free_objects; obj_id < chunk_size; ++obj_id) { |
||||
|
chunk->storage[obj_id].object.~T(); |
||||
|
} |
||||
|
chunk = chunk->next.get(); |
||||
|
} |
||||
|
node = &root; |
||||
|
} |
||||
|
|
||||
|
private: |
||||
|
struct NonTrivialDummy { |
||||
|
NonTrivialDummy() noexcept {} |
||||
|
}; |
||||
|
|
||||
|
union Storage { |
||||
|
Storage() noexcept {} |
||||
|
~Storage() noexcept {} |
||||
|
|
||||
|
NonTrivialDummy dummy{}; |
||||
|
T object; |
||||
|
}; |
||||
|
|
||||
|
struct Chunk { |
||||
|
size_t free_objects = chunk_size; |
||||
|
std::array<Storage, chunk_size> storage; |
||||
|
std::unique_ptr<Chunk> next; |
||||
|
}; |
||||
|
|
||||
|
[[nodiscard]] T* Memory() { |
||||
|
Chunk* const chunk{FreeChunk()}; |
||||
|
return &chunk->storage[--chunk->free_objects].object; |
||||
|
} |
||||
|
|
||||
|
[[nodiscard]] Chunk* FreeChunk() { |
||||
|
if (node->free_objects > 0) { |
||||
|
return node; |
||||
|
} |
||||
|
if (node->next) { |
||||
|
node = node->next.get(); |
||||
|
return node; |
||||
|
} |
||||
|
node->next = std::make_unique<Chunk>(); |
||||
|
node = node->next.get(); |
||||
|
return node; |
||||
|
} |
||||
|
|
||||
|
Chunk* node{&root}; |
||||
|
Chunk root; |
||||
|
}; |
||||
|
|
||||
|
} // namespace Shader |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue