summaryrefslogtreecommitdiff
path: root/src/video_core/shader
diff options
context:
space:
mode:
authorGravatar bunnei2020-01-04 14:05:17 -0500
committerGravatar GitHub2020-01-04 14:05:17 -0500
commitcd0a7dfdbc3ed3ce83a2ad5bb143f46e4f92dfb8 (patch)
treee60c9786f929a2b35c7f23ee7a7dbebcc14eb7a7 /src/video_core/shader
parentMerge pull request #3247 from FernandoS27/remap-fix (diff)
parentShader_IR: Address Feedback (diff)
downloadyuzu-cd0a7dfdbc3ed3ce83a2ad5bb143f46e4f92dfb8.tar.gz
yuzu-cd0a7dfdbc3ed3ce83a2ad5bb143f46e4f92dfb8.tar.xz
yuzu-cd0a7dfdbc3ed3ce83a2ad5bb143f46e4f92dfb8.zip
Merge pull request #3258 from FernandoS27/shader-amend
Shader_IR: add the ability to amend code in the shader ir.
Diffstat (limited to 'src/video_core/shader')
-rw-r--r--src/video_core/shader/node.h26
-rw-r--r--src/video_core/shader/shader_ir.cpp6
-rw-r--r--src/video_core/shader/shader_ir.h8
3 files changed, 38 insertions, 2 deletions
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h
index 4d2f4d6a8..4e155542a 100644
--- a/src/video_core/shader/node.h
+++ b/src/video_core/shader/node.h
@@ -392,8 +392,30 @@ struct MetaImage {
392using Meta = 392using Meta =
393 std::variant<MetaArithmetic, MetaTexture, MetaImage, MetaStackClass, Tegra::Shader::HalfType>; 393 std::variant<MetaArithmetic, MetaTexture, MetaImage, MetaStackClass, Tegra::Shader::HalfType>;
394 394
395class AmendNode {
396public:
397 std::optional<std::size_t> GetAmendIndex() const {
398 if (amend_index == amend_null_index) {
399 return std::nullopt;
400 }
401 return {amend_index};
402 }
403
404 void SetAmendIndex(std::size_t index) {
405 amend_index = index;
406 }
407
408 void ClearAmend() {
409 amend_index = amend_null_index;
410 }
411
412private:
413 static constexpr std::size_t amend_null_index = 0xFFFFFFFFFFFFFFFFULL;
414 std::size_t amend_index{amend_null_index};
415};
416
395/// Holds any kind of operation that can be done in the IR 417/// Holds any kind of operation that can be done in the IR
396class OperationNode final { 418class OperationNode final : public AmendNode {
397public: 419public:
398 explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {} 420 explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {}
399 421
@@ -433,7 +455,7 @@ private:
433}; 455};
434 456
435/// Encloses inside any kind of node that returns a boolean conditionally-executed code 457/// Encloses inside any kind of node that returns a boolean conditionally-executed code
436class ConditionalNode final { 458class ConditionalNode final : public AmendNode {
437public: 459public:
438 explicit ConditionalNode(Node condition, std::vector<Node>&& code) 460 explicit ConditionalNode(Node condition, std::vector<Node>&& code)
439 : condition{std::move(condition)}, code{std::move(code)} {} 461 : condition{std::move(condition)}, code{std::move(code)} {}
diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp
index 1d9825c76..31eecb3f4 100644
--- a/src/video_core/shader/shader_ir.cpp
+++ b/src/video_core/shader/shader_ir.cpp
@@ -446,4 +446,10 @@ Node ShaderIR::BitfieldInsert(Node base, Node insert, u32 offset, u32 bits) {
446 Immediate(bits)); 446 Immediate(bits));
447} 447}
448 448
449std::size_t ShaderIR::DeclareAmend(Node new_amend) {
450 const std::size_t id = amend_code.size();
451 amend_code.push_back(new_amend);
452 return id;
453}
454
449} // namespace VideoCommon::Shader 455} // namespace VideoCommon::Shader
diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h
index baed06ccd..aacd0a0da 100644
--- a/src/video_core/shader/shader_ir.h
+++ b/src/video_core/shader/shader_ir.h
@@ -176,6 +176,10 @@ public:
176 /// Returns a condition code evaluated from internal flags 176 /// Returns a condition code evaluated from internal flags
177 Node GetConditionCode(Tegra::Shader::ConditionCode cc) const; 177 Node GetConditionCode(Tegra::Shader::ConditionCode cc) const;
178 178
179 const Node& GetAmendNode(std::size_t index) const {
180 return amend_code[index];
181 }
182
179private: 183private:
180 friend class ASTDecoder; 184 friend class ASTDecoder;
181 185
@@ -392,6 +396,9 @@ private:
392 Tegra::Shader::Instruction instr, 396 Tegra::Shader::Instruction instr,
393 bool is_write); 397 bool is_write);
394 398
399 /// Register new amending code and obtain the reference id.
400 std::size_t DeclareAmend(Node new_amend);
401
395 const ProgramCode& program_code; 402 const ProgramCode& program_code;
396 const u32 main_offset; 403 const u32 main_offset;
397 const CompilerSettings settings; 404 const CompilerSettings settings;
@@ -406,6 +413,7 @@ private:
406 std::map<u32, NodeBlock> basic_blocks; 413 std::map<u32, NodeBlock> basic_blocks;
407 NodeBlock global_code; 414 NodeBlock global_code;
408 ASTManager program_manager{true, true}; 415 ASTManager program_manager{true, true};
416 std::vector<Node> amend_code;
409 417
410 std::set<u32> used_registers; 418 std::set<u32> used_registers;
411 std::set<Tegra::Shader::Pred> used_predicates; 419 std::set<Tegra::Shader::Pred> used_predicates;