From a12748d79ea6f81d5b9aed24f5c748596ff9f1b7 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 8 Jan 2023 13:02:23 +0200 Subject: [PATCH] vk_shader_gen_spv: Emulate logic ops --- src/video_core/renderer_vulkan/vk_instance.h | 3 +- .../renderer_vulkan/vk_shader_gen_spv.cpp | 29 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_instance.h b/src/video_core/renderer_vulkan/vk_instance.h index d81714de6..260f106e8 100644 --- a/src/video_core/renderer_vulkan/vk_instance.h +++ b/src/video_core/renderer_vulkan/vk_instance.h @@ -87,7 +87,8 @@ public: /// Returns true if logic operations need shader emulation bool NeedsLogicOpEmulation() const { - return !features.logicOp; + return true; + //return !features.logicOp; } bool UseGeometryShaders() const { diff --git a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp index 2696f1dd0..edc75c878 100644 --- a/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_gen_spv.cpp @@ -4,7 +4,6 @@ #include "common/microprofile.h" #include "core/core.h" -#include "video_core/regs.h" #include "video_core/renderer_vulkan/vk_shader_gen_spv.h" #include "video_core/shader/shader_uniforms.h" @@ -75,8 +74,34 @@ void FragmentModule::Generate() { // do our own transformation according to PICA specification. WriteDepth(); + Id color{Byteround(last_tex_env_out, 4)}; + if (config.state.emulate_logic_op) { + switch (config.state.logic_op) { + case FramebufferRegs::LogicOp::Clear: + color = ConstF32(0.f, 0.f, 0.f, 0.f); + break; + case FramebufferRegs::LogicOp::Set: + color = ConstF32(1.f, 1.f, 1.f, 1.f); + break; + case FramebufferRegs::LogicOp::Copy: + // Take the color output as-is + break; + case FramebufferRegs::LogicOp::CopyInverted: + //out += "color = ~color;\n"; + break; + case FramebufferRegs::LogicOp::NoOp: + // We need to discard the color, but not necessarily the depth. This is not possible + // with fragment shader alone, so we emulate this behavior with the color mask. + break; + default: + LOG_CRITICAL(HW_GPU, "Unhandled logic_op {:x}", + static_cast(config.state.logic_op.Value())); + UNIMPLEMENTED(); + } + } + // Write output color - OpStore(color_id, Byteround(last_tex_env_out, 4)); + OpStore(color_id, color); OpReturn(); OpFunctionEnd(); }