diff options
| author | 2020-11-25 00:33:20 -0500 | |
|---|---|---|
| committer | 2020-11-25 00:33:20 -0500 | |
| commit | e87670ee48c896ba029a11ad590234e00260f875 (patch) | |
| tree | 1b0103029d678cf1d0bc20af94feadc10f9fe74d /src | |
| parent | Address PR feedback from Rein (diff) | |
| download | yuzu-e87670ee48c896ba029a11ad590234e00260f875.tar.gz yuzu-e87670ee48c896ba029a11ad590234e00260f875.tar.xz yuzu-e87670ee48c896ba029a11ad590234e00260f875.zip | |
Refactor MaxwellToSpirvComparison. Use Common::BitCast
Co-Authored-By: Rodrigo Locatti <reinuseslisp@airmail.cc>
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/fixed_pipeline_state.cpp | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | 56 |
3 files changed, 34 insertions, 31 deletions
diff --git a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp index 192828300..fffae528e 100644 --- a/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp +++ b/src/video_core/renderer_vulkan/fixed_pipeline_state.cpp | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | #include <boost/functional/hash.hpp> | 9 | #include <boost/functional/hash.hpp> |
| 10 | 10 | ||
| 11 | #include "common/bit_cast.h" | ||
| 11 | #include "common/cityhash.h" | 12 | #include "common/cityhash.h" |
| 12 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 13 | #include "video_core/renderer_vulkan/fixed_pipeline_state.h" | 14 | #include "video_core/renderer_vulkan/fixed_pipeline_state.h" |
| @@ -64,9 +65,9 @@ void FixedPipelineState::Fill(const Maxwell& regs, bool has_extended_dynamic_sta | |||
| 64 | const auto test_func = | 65 | const auto test_func = |
| 65 | regs.alpha_test_enabled == 1 ? regs.alpha_test_func : Maxwell::ComparisonOp::Always; | 66 | regs.alpha_test_enabled == 1 ? regs.alpha_test_func : Maxwell::ComparisonOp::Always; |
| 66 | alpha_test_func.Assign(PackComparisonOp(test_func)); | 67 | alpha_test_func.Assign(PackComparisonOp(test_func)); |
| 67 | std::memcpy(&alpha_test_ref, ®s.alpha_test_ref, sizeof(u32)); // TODO: C++20 std::bit_cast | 68 | alpha_test_ref = Common::BitCast<u32>(regs.alpha_test_ref); |
| 68 | 69 | ||
| 69 | std::memcpy(&point_size, ®s.point_size, sizeof(point_size)); // TODO: C++20 std::bit_cast | 70 | point_size = Common::BitCast<u32>(regs.point_size); |
| 70 | 71 | ||
| 71 | for (std::size_t index = 0; index < Maxwell::NumVertexArrays; ++index) { | 72 | for (std::size_t index = 0; index < Maxwell::NumVertexArrays; ++index) { |
| 72 | binding_divisors[index] = | 73 | binding_divisors[index] = |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index a66a841fb..f9efe526d 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <vector> | 8 | #include <vector> |
| 9 | 9 | ||
| 10 | #include "common/bit_cast.h" | ||
| 10 | #include "common/microprofile.h" | 11 | #include "common/microprofile.h" |
| 11 | #include "core/core.h" | 12 | #include "core/core.h" |
| 12 | #include "core/memory.h" | 13 | #include "core/memory.h" |
| @@ -347,8 +348,7 @@ VKPipelineCache::DecompileShaders(const FixedPipelineState& fixed_state) { | |||
| 347 | // Alpha test | 348 | // Alpha test |
| 348 | specialization.alpha_test_func = | 349 | specialization.alpha_test_func = |
| 349 | FixedPipelineState::UnpackComparisonOp(fixed_state.alpha_test_func.Value()); | 350 | FixedPipelineState::UnpackComparisonOp(fixed_state.alpha_test_func.Value()); |
| 350 | // memcpy from u32 to float TODO: C++20 std::bit_cast | 351 | specialization.alpha_test_ref = Common::BitCast<float>(fixed_state.alpha_test_ref); |
| 351 | std::memcpy(&specialization.alpha_test_ref, &fixed_state.alpha_test_ref, sizeof(float)); | ||
| 352 | 352 | ||
| 353 | SPIRVProgram program; | 353 | SPIRVProgram program; |
| 354 | std::vector<VkDescriptorSetLayoutBinding> bindings; | 354 | std::vector<VkDescriptorSetLayoutBinding> bindings; |
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp index 81550bc96..d6685cd12 100644 --- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | |||
| @@ -2075,47 +2075,49 @@ private: | |||
| 2075 | return {}; | 2075 | return {}; |
| 2076 | } | 2076 | } |
| 2077 | 2077 | ||
| 2078 | void AlphaTest(Id pointer) { | 2078 | Id MaxwellToSpirvComparison(Maxwell::ComparisonOp compare_op, Id operand_1, Id operand_2) { |
| 2079 | const Id true_label = OpLabel(); | ||
| 2080 | const Id skip_label = OpLabel(); | ||
| 2081 | const Id alpha_reference = Constant(t_float, specialization.alpha_test_ref); | ||
| 2082 | const Id alpha_value = OpLoad(t_float, pointer); | ||
| 2083 | Id condition; | ||
| 2084 | using Compare = Maxwell::ComparisonOp; | 2079 | using Compare = Maxwell::ComparisonOp; |
| 2085 | switch (specialization.alpha_test_func) { | 2080 | switch (compare_op) { |
| 2086 | case Compare::NeverOld: | 2081 | case Compare::NeverOld: |
| 2087 | condition = v_false; // Never true | 2082 | return v_false; // Never let the test pass |
| 2088 | break; | ||
| 2089 | case Compare::LessOld: | 2083 | case Compare::LessOld: |
| 2090 | condition = OpFOrdLessThan(t_bool, alpha_reference, alpha_value); | 2084 | return OpFOrdLessThan(t_bool, operand_1, operand_2); |
| 2091 | break; | ||
| 2092 | case Compare::EqualOld: | 2085 | case Compare::EqualOld: |
| 2093 | condition = OpFOrdEqual(t_bool, alpha_reference, alpha_value); | 2086 | // Note: not accurate when tested against a unit test |
| 2094 | break; | 2087 | // TODO: confirm if used by games |
| 2088 | return OpFOrdEqual(t_bool, operand_1, operand_2); | ||
| 2095 | case Compare::LessEqualOld: | 2089 | case Compare::LessEqualOld: |
| 2096 | condition = OpFOrdLessThanEqual(t_bool, alpha_reference, alpha_value); | 2090 | return OpFOrdLessThanEqual(t_bool, operand_1, operand_2); |
| 2097 | break; | ||
| 2098 | case Compare::GreaterOld: | 2091 | case Compare::GreaterOld: |
| 2099 | // Note: requires "Equal" to properly work for ssbu. perhaps a precision issue | 2092 | return OpFOrdGreaterThan(t_bool, operand_1, operand_2); |
| 2100 | condition = OpFOrdGreaterThanEqual(t_bool, alpha_reference, alpha_value); | ||
| 2101 | break; | ||
| 2102 | case Compare::NotEqualOld: | 2093 | case Compare::NotEqualOld: |
| 2103 | // Note: not accurate when tested against a unit test | 2094 | // Note: not accurate when tested against a unit test |
| 2104 | // TODO: confirm if used by games | 2095 | // TODO: confirm if used by games |
| 2105 | condition = OpFOrdNotEqual(t_bool, alpha_reference, alpha_value); | 2096 | return OpFOrdNotEqual(t_bool, operand_1, operand_2); |
| 2106 | break; | ||
| 2107 | case Compare::GreaterEqualOld: | 2097 | case Compare::GreaterEqualOld: |
| 2108 | condition = OpFOrdGreaterThanEqual(t_bool, alpha_reference, alpha_value); | 2098 | return OpFOrdGreaterThanEqual(t_bool, operand_1, operand_2); |
| 2109 | break; | ||
| 2110 | case Compare::AlwaysOld: | ||
| 2111 | return; | ||
| 2112 | default: | 2099 | default: |
| 2113 | UNREACHABLE(); | 2100 | UNREACHABLE(); |
| 2114 | } | 2101 | } |
| 2115 | OpBranchConditional(condition, true_label, skip_label); | 2102 | } |
| 2116 | AddLabel(true_label); | 2103 | |
| 2104 | void AlphaTest(Id pointer) { | ||
| 2105 | if (specialization.alpha_test_func == Maxwell::ComparisonOp::AlwaysOld) { | ||
| 2106 | return; | ||
| 2107 | } | ||
| 2108 | |||
| 2109 | const Id true_label = OpLabel(); | ||
| 2110 | const Id discard_label = OpLabel(); | ||
| 2111 | const Id alpha_reference = Constant(t_float, specialization.alpha_test_ref); | ||
| 2112 | const Id alpha_value = OpLoad(t_float, pointer); | ||
| 2113 | |||
| 2114 | const Id condition = | ||
| 2115 | MaxwellToSpirvComparison(specialization.alpha_test_func, alpha_value, alpha_reference); | ||
| 2116 | |||
| 2117 | OpBranchConditional(condition, true_label, discard_label); | ||
| 2118 | AddLabel(discard_label); | ||
| 2117 | OpKill(); | 2119 | OpKill(); |
| 2118 | AddLabel(skip_label); | 2120 | AddLabel(true_label); |
| 2119 | } | 2121 | } |
| 2120 | 2122 | ||
| 2121 | void PreExit() { | 2123 | void PreExit() { |