Skip to content

Commit

Permalink
Merge pull request #19134 from hrydgard/assorted-bugfixes
Browse files Browse the repository at this point in the history
Don't enable the Mali "never" workaround on all GPUs (oops). Minor fixes.
  • Loading branch information
hrydgard committed May 11, 2024
2 parents bdf86a4 + 336732a commit 5e6f5ea
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Common/GPU/Vulkan/VulkanRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,10 @@ class VulkanRenderManager {
void StartThreads();
void StopThreads();

size_t GetNumSteps() const {
return steps_.size();
}

private:
void EndCurRenderStep();

Expand Down
9 changes: 7 additions & 2 deletions Common/GPU/Vulkan/thin3d_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ class VKContext : public DrawContext {
VKContext(VulkanContext *vulkan, bool useRenderThread);
~VKContext();

BackendState GetCurrentBackendState() const override {
return BackendState{
(u32)renderManager_.GetNumSteps(),
true,
};
}

void DebugAnnotate(const char *annotation) override;
void Wait() override {
vkDeviceWaitIdle(vulkan_->GetDevice());
Expand Down Expand Up @@ -1047,8 +1054,6 @@ VKContext::VKContext(VulkanContext *vulkan, bool useRenderThread)
INFO_LOG(G3D, "KHR_depth_stencil_resolve not supported, disabling multisampling");
}

bugs_.Infest(Draw::Bugs::NO_DEPTH_CANNOT_DISCARD_STENCIL_MALI);

// We limit multisampling functionality to reasonably recent and known-good tiling GPUs.
if (multisampleAllowed) {
// Check for depth stencil resolve. Without it, depth textures won't work, and we don't want that mess
Expand Down
9 changes: 9 additions & 0 deletions Common/GPU/thin3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,11 @@ enum class DebugFlags {
};
ENUM_CLASS_BITOPS(DebugFlags);

struct BackendState {
u32 passes;
bool valid;
};

class DrawContext {
public:
virtual ~DrawContext();
Expand All @@ -705,6 +710,10 @@ class DrawContext {
virtual std::vector<std::string> GetPresentModeList(std::string_view currentMarkerString) const { return std::vector<std::string>(); }
virtual std::vector<std::string> GetSurfaceFormatList() const { return std::vector<std::string>(); }

virtual BackendState GetCurrentBackendState() const {
return BackendState{};
}

// Describes the primary shader language that this implementation prefers.
const ShaderLanguageDesc &GetShaderLanguageDesc() {
return shaderLanguageDesc_;
Expand Down
6 changes: 5 additions & 1 deletion Common/UI/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ ScreenRenderFlags ScreenManager::render() {
bool first = true;
do {
--iter;
if (!foundBackgroundScreen && iter->screen->canBeBackground(first)) {
ScreenRenderRole role = iter->screen->renderRole(first);
if (!foundBackgroundScreen && (role & ScreenRenderRole::CAN_BE_BACKGROUND)) {
// There still might be a screen that wants to be background - generally the EmuScreen if present.
layers.push_back(iter->screen);
foundBackgroundScreen = iter->screen;
Expand All @@ -198,6 +199,9 @@ ScreenRenderFlags ScreenManager::render() {
coveringScreen = iter->screen;
}
first = false;
if (role & ScreenRenderRole::MUST_BE_FIRST) {
break;
}
} while (iter != stack_.begin());

if (backgroundScreen_ && !foundBackgroundScreen) {
Expand Down
10 changes: 9 additions & 1 deletion Common/UI/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ enum class ScreenRenderFlags {
};
ENUM_CLASS_BITOPS(ScreenRenderFlags);


enum class ScreenRenderRole {
NONE = 0,
CAN_BE_BACKGROUND = 1,
MUST_BE_FIRST = 2,
};
ENUM_CLASS_BITOPS(ScreenRenderRole);

class Screen {
public:
Screen() : screenManager_(nullptr) { }
Expand All @@ -74,7 +82,7 @@ class Screen {
virtual void sendMessage(UIMessage message, const char *value) {}
virtual void deviceLost() {}
virtual void deviceRestored() {}
virtual bool canBeBackground(bool isTop) const { return false; }
virtual ScreenRenderRole renderRole(bool isTop) const { return ScreenRenderRole::NONE; }
virtual bool wantBrightBackground() const { return false; } // special hack for DisplayLayoutScreen.

virtual void focusChanged(ScreenFocusChange focusChange);
Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/VertexDecoderHandwritten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ void VtxDec_Tu16_C8888_Pfloat(const u8 *srcp, u8 *dstp, int count, const UVScale
float32x2_t finalUV = vadd_f32(vmul_f32(vcvt_f32_u32(fuv), uvScale), uvOff);
u32 normal = src[i].packed_normal;
uint32x4_t colpos = vld1q_u32((const u32 *)&src[i].col);
alphaMask = vandq_u32(alphaMask, colpos);
alphaMask = vandq_u32(alphaMask, colpos);
vst1_f32(&dst[i].u, finalUV);
dst[i].packed_normal = normal;
vst1q_u32(&dst[i].col, colpos);
}
alpha = vgetq_lane_u32(alphaMask, 0);
alpha = vgetq_lane_u32(alphaMask, 0);
#else
for (int i = 0; i < count; i++) {
float u = src[i].u * uscale + uoff;
Expand Down
32 changes: 23 additions & 9 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,17 +1279,25 @@ bool EmuScreen::checkPowerDown() {
return false;
}

bool EmuScreen::canBeBackground(bool isTop) const {
if (g_Config.bSkipBufferEffects) {
return isTop || (g_Config.bTransparentBackground && Core_ShouldRunBehind());
}
ScreenRenderRole EmuScreen::renderRole(bool isTop) const {
auto CanBeBackground = [&]() -> bool {
if (g_Config.bSkipBufferEffects) {
return isTop || (g_Config.bTransparentBackground && Core_ShouldRunBehind());
}

if (!g_Config.bTransparentBackground && !isTop) {
if (Core_ShouldRunBehind() || screenManager()->topScreen()->wantBrightBackground())
return true;
return false;
if (!g_Config.bTransparentBackground && !isTop) {
if (Core_ShouldRunBehind() || screenManager()->topScreen()->wantBrightBackground())
return true;
return false;
}
return true;
};

ScreenRenderRole role = ScreenRenderRole::MUST_BE_FIRST;
if (CanBeBackground()) {
role |= ScreenRenderRole::CAN_BE_BACKGROUND;
}
return true;
return role;
}

void EmuScreen::darken() {
Expand All @@ -1313,6 +1321,12 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
return flags; // shouldn't really happen but I've seen a suspicious stack trace..
}

// Sanity check
#ifdef _DEBUG
Draw::BackendState state = draw->GetCurrentBackendState();
_dbg_assert_(!state.valid || state.passes == 0);
#endif

GamepadUpdateOpacity();

bool skipBufferEffects = g_Config.bSkipBufferEffects;
Expand Down
2 changes: 1 addition & 1 deletion UI/EmuScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EmuScreen : public UIScreen {
void dialogFinished(const Screen *dialog, DialogResult result) override;
void sendMessage(UIMessage message, const char *value) override;
void resized() override;
bool canBeBackground(bool isTop) const override;
ScreenRenderRole renderRole(bool isTop) const override;

// Note: Unlike your average boring UIScreen, here we override the Unsync* functions
// to get minimal latency and full control. We forward to UIScreen when needed.
Expand Down

0 comments on commit 5e6f5ea

Please sign in to comment.